some device and pipeline fixes

This commit is contained in:
aap 2018-01-03 18:02:02 +01:00
parent ddca04fdc2
commit 1872c235ab
17 changed files with 220 additions and 52 deletions

View File

@ -152,9 +152,9 @@ ImGui_ImplRW_NewFrame(float timeDelta)
io.DisplaySize = ImVec2(sk::globals.width, sk::globals.height); io.DisplaySize = ImVec2(sk::globals.width, sk::globals.height);
io.DeltaTime = timeDelta; io.DeltaTime = timeDelta;
io.KeyCtrl = false; //io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL]; io.KeyCtrl = io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL];
io.KeyShift = false; //io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT]; io.KeyShift = io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT];
io.KeyAlt = false; //io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT]; io.KeyAlt = io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT];
io.KeySuper = false; io.KeySuper = false;
if(io.WantMoveMouse) if(io.WantMoveMouse)

View File

@ -217,11 +217,12 @@ int WINAPI
WinMain(HINSTANCE instance, HINSTANCE, WinMain(HINSTANCE instance, HINSTANCE,
PSTR cmdLine, int showCmd) PSTR cmdLine, int showCmd)
{ {
/*
AllocConsole(); AllocConsole();
freopen("CONIN$", "r", stdin); freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr); freopen("CONOUT$", "w", stderr);
*/
INT64 ticks; INT64 ticks;
INT64 ticksPerSecond; INT64 ticksPerSecond;

View File

@ -139,6 +139,64 @@ V3d::transformVectors(V3d *out, V3d *in, int32 n, Matrix *m)
} }
} }
//
// RawMatrix
//
void
RawMatrix::mult(RawMatrix *dst, RawMatrix *src1, RawMatrix *src2)
{
dst->right.x = src1->right.x*src2->right.x + src1->right.y*src2->up.x + src1->right.z*src2->at.x + src1->rightw*src2->pos.x;
dst->right.y = src1->right.x*src2->right.y + src1->right.y*src2->up.y + src1->right.z*src2->at.y + src1->rightw*src2->pos.y;
dst->right.z = src1->right.x*src2->right.z + src1->right.y*src2->up.z + src1->right.z*src2->at.z + src1->rightw*src2->pos.z;
dst->rightw = src1->right.x*src2->rightw + src1->right.y*src2->upw + src1->right.z*src2->atw + src1->rightw*src2->posw;
dst->up.x = src1->up.x*src2->right.x + src1->up.y*src2->up.x + src1->up.z*src2->at.x + src1->upw*src2->pos.x;
dst->up.y = src1->up.x*src2->right.y + src1->up.y*src2->up.y + src1->up.z*src2->at.y + src1->upw*src2->pos.y;
dst->up.z = src1->up.x*src2->right.z + src1->up.y*src2->up.z + src1->up.z*src2->at.z + src1->upw*src2->pos.z;
dst->upw = src1->up.x*src2->rightw + src1->up.y*src2->upw + src1->up.z*src2->atw + src1->upw*src2->posw;
dst->at.x = src1->at.x*src2->right.x + src1->at.y*src2->up.x + src1->at.z*src2->at.x + src1->atw*src2->pos.x;
dst->at.y = src1->at.x*src2->right.y + src1->at.y*src2->up.y + src1->at.z*src2->at.y + src1->atw*src2->pos.y;
dst->at.z = src1->at.x*src2->right.z + src1->at.y*src2->up.z + src1->at.z*src2->at.z + src1->atw*src2->pos.z;
dst->atw = src1->at.x*src2->rightw + src1->at.y*src2->upw + src1->at.z*src2->atw + src1->atw*src2->posw;
dst->pos.x = src1->pos.x*src2->right.x + src1->pos.y*src2->up.x + src1->pos.z*src2->at.x + src1->posw*src2->pos.x;
dst->pos.y = src1->pos.x*src2->right.y + src1->pos.y*src2->up.y + src1->pos.z*src2->at.y + src1->posw*src2->pos.y;
dst->pos.z = src1->pos.x*src2->right.z + src1->pos.y*src2->up.z + src1->pos.z*src2->at.z + src1->posw*src2->pos.z;
dst->posw = src1->pos.x*src2->rightw + src1->pos.y*src2->upw + src1->pos.z*src2->atw + src1->posw*src2->posw;
}
void
RawMatrix::transpose(RawMatrix *dst, RawMatrix *src)
{
dst->right.x = src->right.x;
dst->up.x = src->right.y;
dst->at.x = src->right.z;
dst->pos.x = src->rightw;
dst->right.y = src->up.x;
dst->up.y = src->up.y;
dst->at.y = src->up.z;
dst->pos.y = src->upw;
dst->right.z = src->at.x;
dst->up.z = src->at.y;
dst->at.z = src->at.z;
dst->pos.z = src->atw;
dst->rightw = src->pos.x;
dst->upw = src->pos.y;
dst->atw = src->pos.z;
dst->posw = src->posw;
}
void
RawMatrix::setIdentity(RawMatrix *dst)
{
static RawMatrix identity = {
{ 1.0f, 0.0f, 0.0f }, 0.0f,
{ 0.0f, 1.0f, 0.0f }, 0.0f,
{ 0.0f, 0.0f, 1.0f }, 0.0f,
{ 0.0f, 0.0f, 0.0f }, 1.0f
};
*dst = identity;
}
// //
// Matrix // Matrix
// //

View File

@ -562,7 +562,7 @@ rasterToImage(Raster *raster)
switch(natras->format){ switch(natras->format){
case D3DFMT_DXT1: case D3DFMT_DXT1:
image->setPixelsDXT(1, pix); image->setPixelsDXT(1, pix);
if((raster->format & 0xF00) == Raster::C555) if((raster->format & 0xF00) == Raster::C565)
image->removeMask(); image->removeMask();
break; break;
case D3DFMT_DXT3: case D3DFMT_DXT3:

View File

@ -19,6 +19,8 @@ using namespace d3d;
void defaultRenderCB(Atomic*, InstanceDataHeader*) {} void defaultRenderCB(Atomic*, InstanceDataHeader*) {}
#else #else
// This is a bit abandoned, use d3d9 instead
void void
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
{ {
@ -36,7 +38,9 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
d3d::setTexture(0, inst->material->texture); d3d::setTexture(0, inst->material->texture);
d3d::setMaterial(inst->material); d3d::setMaterial(inst->material->surfaceProps, inst->material->color);
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
if(geo->flags & Geometry::PRELIT) if(geo->flags & Geometry::PRELIT)

View File

@ -498,11 +498,17 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
if(isPrelit){ if(isPrelit){
for(i = 0; dcl[i].usage != D3DDECLUSAGE_COLOR || dcl[i].usageIndex != 0; i++) for(i = 0; dcl[i].usage != D3DDECLUSAGE_COLOR || dcl[i].usageIndex != 0; i++)
; ;
// TODO: vertex alpha (instance per mesh) InstanceData *inst = header->inst;
instColor(vertFormatMap[dcl[i].type], verts + dcl[i].offset, uint32 n = header->numMeshes;
geo->colors, while(n--){
header->totalNumVertex, uint32 stride = header->vertexStream[dcl[i].stream].stride;
header->vertexStream[dcl[i].stream].stride); inst->vertexAlpha = instColor(vertFormatMap[dcl[i].type],
verts + dcl[i].offset + stride*inst->minVert,
geo->colors + inst->minVert,
inst->numVertices,
stride);
inst++;
}
} }
for(int32 n = 0; n < geo->numTexCoordSets; n++){ for(int32 n = 0; n < geo->numTexCoordSets; n++){

View File

@ -8,6 +8,7 @@
#include "../rwpipeline.h" #include "../rwpipeline.h"
#include "../rwobjects.h" #include "../rwobjects.h"
#include "../rwengine.h" #include "../rwengine.h"
#include "../rwrender.h"
#include "rwd3d.h" #include "rwd3d.h"
#include "rwd3d9.h" #include "rwd3d9.h"
@ -44,6 +45,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
// Texture
d3d::setTexture(0, inst->material->texture); d3d::setTexture(0, inst->material->texture);
d3d::setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); d3d::setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
d3d::setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT); d3d::setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
@ -52,14 +54,27 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
d3d::setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT); d3d::setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
d3d::setTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); d3d::setTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
d3d::setMaterial(inst->material); SetRenderState(VERTEXALPHA, inst->vertexAlpha || inst->material->color.alpha != 255);
// Material colour
const rw::RGBA *col = &inst->material->color;
d3d::setTextureStageState(1, D3DTSS_CONSTANT, D3DCOLOR_ARGB(col->alpha,col->red,col->green,col->blue));
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
d3d::setTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
d3d::setTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CONSTANT);
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
d3d::setTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
d3d::setTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);
const static rw::RGBA white = { 255, 255, 255, 255 };
d3d::setMaterial(inst->material->surfaceProps, white);
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
if(geo->flags & Geometry::PRELIT) if(geo->flags & Geometry::PRELIT)
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);
else else
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, inst->vertexAlpha ? D3DMCS_COLOR1 : D3DMCS_MATERIAL);
d3d::flushCache(); d3d::flushCache();
d3ddevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex, d3ddevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex,
@ -67,6 +82,8 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
inst->startIndex, inst->numPrimitives); inst->startIndex, inst->numPrimitives);
inst++; inst++;
} }
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
} }
#endif #endif

View File

@ -35,6 +35,7 @@ static uint32 zwrite;
static uint32 ztest; static uint32 ztest;
static uint32 fogenable; static uint32 fogenable;
static RGBA fogcolor; static RGBA fogcolor;
static uint32 cullmode;
static uint32 alphafunc; static uint32 alphafunc;
static uint32 alpharef; static uint32 alpharef;
@ -208,6 +209,12 @@ uint32 alphafuncMap[] = {
D3DCMP_LESS D3DCMP_LESS
}; };
uint32 cullmodeMap[] = {
D3DCULL_NONE,
D3DCULL_CW,
D3DCULL_CCW
};
static void static void
setRwRenderState(int32 state, uint32 value) setRwRenderState(int32 state, uint32 value)
{ {
@ -252,6 +259,12 @@ setRwRenderState(int32 state, uint32 value)
fogcolor = c; fogcolor = c;
setRenderState(D3DRS_FOGCOLOR, D3DCOLOR_RGBA(c.red, c.green, c.blue, c.alpha)); setRenderState(D3DRS_FOGCOLOR, D3DCOLOR_RGBA(c.red, c.green, c.blue, c.alpha));
}} break; }} break;
case CULLMODE:
if(cullmode != value){
cullmode = value;
setRenderState(D3DRS_CULLMODE, cullmodeMap[value]);
}
break;
case ALPHATESTFUNC: case ALPHATESTFUNC:
if(alphafunc != value){ if(alphafunc != value){
alphafunc = value; alphafunc = value;
@ -285,6 +298,8 @@ getRwRenderState(int32 state)
return fogenable; return fogenable;
case FOGCOLOR: case FOGCOLOR:
return *(uint32*)&fogcolor; return *(uint32*)&fogcolor;
case CULLMODE:
return cullmode;
case ALPHATESTFUNC: case ALPHATESTFUNC:
return alphafunc; return alphafunc;
case ALPHATESTREF: case ALPHATESTREF:
@ -372,20 +387,20 @@ setD3dMaterial(D3DMATERIAL9 *mat9)
} }
void void
setMaterial(Material *mat) setMaterial(SurfaceProperties surfProps, rw::RGBA color)
{ {
D3DMATERIAL9 mat9; D3DMATERIAL9 mat9;
D3DCOLORVALUE black = { 0, 0, 0, 0 }; D3DCOLORVALUE black = { 0, 0, 0, 0 };
float ambmult = mat->surfaceProps.ambient/255.0f; float ambmult = surfProps.ambient/255.0f;
float diffmult = mat->surfaceProps.diffuse/255.0f; float diffmult = surfProps.diffuse/255.0f;
mat9.Ambient.r = mat->color.red*ambmult; mat9.Ambient.r = color.red*ambmult;
mat9.Ambient.g = mat->color.green*ambmult; mat9.Ambient.g = color.green*ambmult;
mat9.Ambient.b = mat->color.blue*ambmult; mat9.Ambient.b = color.blue*ambmult;
mat9.Ambient.a = mat->color.alpha*ambmult; mat9.Ambient.a = color.alpha*ambmult;
mat9.Diffuse.r = mat->color.red*diffmult; mat9.Diffuse.r = color.red*diffmult;
mat9.Diffuse.g = mat->color.green*diffmult; mat9.Diffuse.g = color.green*diffmult;
mat9.Diffuse.b = mat->color.blue*diffmult; mat9.Diffuse.b = color.blue*diffmult;
mat9.Diffuse.a = mat->color.alpha*diffmult; mat9.Diffuse.a = color.alpha*diffmult;
mat9.Power = 0.0f; mat9.Power = 0.0f;
mat9.Emissive = black; mat9.Emissive = black;
mat9.Specular = black; mat9.Specular = black;
@ -628,6 +643,7 @@ initD3D(void)
// TODO: more fog stuff // TODO: more fog stuff
d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
cullmode = CULLNONE;
d3ddevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); d3ddevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

View File

@ -176,6 +176,12 @@ im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices)
d3ddevice->SetIndices(im3dindbuf); d3ddevice->SetIndices(im3dindbuf);
d3d::setTexture(0, engine->imtexture); d3d::setTexture(0, engine->imtexture);
setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
setTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
setTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
setTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
d3d::flushCache(); d3d::flushCache();
uint32 primCount = 0; uint32 primCount = 0;

View File

@ -151,7 +151,7 @@ void getSamplerState(uint32 stage, uint32 type, uint32 *value);
void flushCache(void); void flushCache(void);
void setTexture(uint32 stage, Texture *tex); void setTexture(uint32 stage, Texture *tex);
void setMaterial(Material *mat); void setMaterial(SurfaceProperties surfProps, rw::RGBA color);
} }
} }

View File

@ -85,10 +85,13 @@ static bool32 objectDirty = 1;
// cached render states // cached render states
static bool32 vertexAlpha; static bool32 vertexAlpha;
static uint32 alphaTestEnable;
static uint32 alphaFunc;
static bool32 textureAlpha; static bool32 textureAlpha;
static uint32 srcblend, destblend; static uint32 srcblend, destblend;
static uint32 zwrite; static uint32 zwrite;
static uint32 ztest; static uint32 ztest;
static uint32 cullmode;
static int32 activeTexture; static int32 activeTexture;
@ -106,17 +109,43 @@ static uint32 blendMap[] = {
GL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA_SATURATE,
}; };
static void
setAlphaTest(bool32 enable)
{
uint32 shaderfunc;
if(alphaTestEnable != enable){
alphaTestEnable = enable;
shaderfunc = alphaTestEnable ? alphaFunc : ALPHAALWAYS;
if(uniformState.alphaFunc != shaderfunc){
uniformState.alphaFunc = shaderfunc;
stateDirty = 1;
}
}
}
static void
setAlphaTestFunction(uint32 function)
{
uint32 shaderfunc;
if(alphaFunc != function){
alphaFunc = function;
shaderfunc = alphaTestEnable ? alphaFunc : ALPHAALWAYS;
if(uniformState.alphaFunc != shaderfunc){
uniformState.alphaFunc = shaderfunc;
stateDirty = 1;
}
}
}
static void static void
setVertexAlpha(bool32 enable) setVertexAlpha(bool32 enable)
{ {
if(vertexAlpha != enable){ if(vertexAlpha != enable){
vertexAlpha = enable;
if(!textureAlpha){ if(!textureAlpha){
if(enable) (enable ? glEnable : glDisable)(GL_BLEND);
glEnable(GL_BLEND); setAlphaTest(enable);
else
glDisable(GL_BLEND);
} }
vertexAlpha = enable;
} }
} }
@ -165,12 +194,20 @@ setRenderState(int32 state, uint32 value)
convColor(&uniformState.fogColor, (RGBA*)&value); convColor(&uniformState.fogColor, (RGBA*)&value);
stateDirty = 1; stateDirty = 1;
break; break;
case CULLMODE:
if(cullmode != value){
cullmode = value;
if(cullmode == CULLNONE)
glDisable(GL_CULL_FACE);
else{
glEnable(GL_CULL_FACE);
glCullFace(cullmode == CULLBACK ? GL_BACK : GL_FRONT);
}
}
break;
case ALPHATESTFUNC: case ALPHATESTFUNC:
if(uniformState.alphaFunc != value){ setAlphaTestFunction(value);
uniformState.alphaFunc = value;
stateDirty = 1;
}
break; break;
case ALPHATESTREF: case ALPHATESTREF:
if(uniformState.alphaRef != value/255.0f){ if(uniformState.alphaRef != value/255.0f){
@ -201,9 +238,11 @@ getRenderState(int32 state)
case FOGCOLOR: case FOGCOLOR:
convColor(&rgba, &uniformState.fogColor); convColor(&rgba, &uniformState.fogColor);
return *(uint32*)&rgba; return *(uint32*)&rgba;
case CULLMODE:
return cullmode;
case ALPHATESTFUNC: case ALPHATESTFUNC:
return uniformState.alphaFunc; return alphaFunc;
case ALPHATESTREF: case ALPHATESTREF:
return (uint32)(uniformState.alphaRef*255.0f); return (uint32)(uniformState.alphaRef*255.0f);
} }
@ -213,7 +252,8 @@ getRenderState(int32 state)
static void static void
resetRenderState(void) resetRenderState(void)
{ {
uniformState.alphaFunc = ALPHAGREATEREQUAL; alphaFunc = ALPHAGREATEREQUAL;
uniformState.alphaFunc = 0;
uniformState.alphaRef = 10.0f/255.0f; uniformState.alphaRef = 10.0f/255.0f;
uniformState.fogEnable = 0; uniformState.fogEnable = 0;
uniformState.fogStart = 0.0f; uniformState.fogStart = 0.0f;
@ -223,6 +263,7 @@ resetRenderState(void)
vertexAlpha = 0; vertexAlpha = 0;
textureAlpha = 0; textureAlpha = 0;
glDisable(GL_BLEND); glDisable(GL_BLEND);
alphaTestEnable = 0;
srcblend = BLENDSRCALPHA; srcblend = BLENDSRCALPHA;
destblend = BLENDINVSRCALPHA; destblend = BLENDINVSRCALPHA;
@ -235,6 +276,9 @@ resetRenderState(void)
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
cullmode = CULLNONE;
glDisable(GL_CULL_FACE);
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
glActiveTexture(GL_TEXTURE0+i); glActiveTexture(GL_TEXTURE0+i);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
@ -323,7 +367,8 @@ setTexture(int32 n, Texture *tex)
}; };
bool32 alpha; bool32 alpha;
setActiveTexture(GL_TEXTURE0+n); setActiveTexture(GL_TEXTURE0+n);
if(tex == nil || tex->raster->platform != PLATFORM_GL3 || if(tex == nil || tex->raster == nil ||
tex->raster->platform != PLATFORM_GL3 ||
tex->raster->width == 0){ tex->raster->width == 0){
glBindTexture(GL_TEXTURE_2D, whitetex); glBindTexture(GL_TEXTURE_2D, whitetex);
alpha = 0; alpha = 0;
@ -345,10 +390,8 @@ setTexture(int32 n, Texture *tex)
if(alpha != textureAlpha){ if(alpha != textureAlpha){
textureAlpha = alpha; textureAlpha = alpha;
if(!vertexAlpha){ if(!vertexAlpha){
if(alpha) (alpha ? glEnable : glDisable)(GL_BLEND);
glEnable(GL_BLEND); setAlphaTest(alpha);
else
glDisable(GL_BLEND);
} }
} }
} }

View File

@ -48,7 +48,7 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
uint32 offset = 0; uint32 offset = 0;
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
findMinVertAndNumVertices(mesh->indices, mesh->numIndices, findMinVertAndNumVertices(mesh->indices, mesh->numIndices,
&inst->minVert, nil); &inst->minVert, &inst->numVertices);
inst->numIndex = mesh->numIndices; inst->numIndex = mesh->numIndices;
inst->material = mesh->material; inst->material = mesh->material;
inst->vertexAlpha = 0; inst->vertexAlpha = 0;
@ -197,9 +197,15 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
if(isPrelit){ if(isPrelit){
for(a = attribs; a->index != ATTRIB_COLOR; a++) for(a = attribs; a->index != ATTRIB_COLOR; a++)
; ;
instColor(VERT_RGBA, verts + a->offset, int n = header->numMeshes;
geo->colors, InstanceData *inst = header->inst;
header->totalNumVertex, a->stride); while(n--){
inst->vertexAlpha = instColor(VERT_RGBA,
verts + a->offset + a->stride*inst->minVert,
geo->colors + inst->minVert,
inst->numVertices, a->stride);
inst++;
}
} }
// Texture coordinates // Texture coordinates

View File

@ -54,6 +54,7 @@ struct InstanceData
{ {
uint32 numIndex; uint32 numIndex;
uint32 minVert; // not used for rendering uint32 minVert; // not used for rendering
int32 numVertices; //
Material *material; Material *material;
bool32 vertexAlpha; bool32 vertexAlpha;
uint32 program; uint32 program;

View File

@ -140,15 +140,14 @@ uninstTexCoords(int type, TexCoords *dst, uint8 *src, uint32 numVertices, uint32
bool32 bool32
instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride) instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride)
{ {
bool32 hasAlpha = 0; uint8 alpha = 0xFF;
if(type == VERT_ARGB){ if(type == VERT_ARGB){
for(uint32 i = 0; i < numVertices; i++){ for(uint32 i = 0; i < numVertices; i++){
dst[0] = src->blue; dst[0] = src->blue;
dst[1] = src->green; dst[1] = src->green;
dst[2] = src->red; dst[2] = src->red;
dst[3] = src->alpha; dst[3] = src->alpha;
if(dst[3] != 0xFF) alpha &= src->alpha;
hasAlpha = 1;
dst += stride; dst += stride;
src++; src++;
} }
@ -158,14 +157,13 @@ instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride)
dst[1] = src->green; dst[1] = src->green;
dst[2] = src->blue; dst[2] = src->blue;
dst[3] = src->alpha; dst[3] = src->alpha;
if(dst[3] != 0xFF) alpha &= src->alpha;
hasAlpha = 1;
dst += stride; dst += stride;
src++; src++;
} }
}else }else
assert(0 && "unsupported color type"); assert(0 && "unsupported color type");
return hasAlpha; return alpha != 0xFF;
} }
void void

View File

@ -978,6 +978,7 @@ createTexRaster(Raster *raster)
// calculate buffer width in units of pixels/64 // calculate buffer width in units of pixels/64
bufferBase[0] = 0; bufferBase[0] = 0;
trxpos_hi[0] = 0;
bufferWidth[0] = nPagW*pageWidth / 64; bufferWidth[0] = nPagW*pageWidth / 64;
// calculate whole buffer size in words // calculate whole buffer size in words

View File

@ -280,6 +280,9 @@ struct RawMatrix
V3d pos; V3d pos;
float32 posw;; float32 posw;;
static void mult(RawMatrix *dst, RawMatrix *src1, RawMatrix *src2);
static void transpose(RawMatrix *dst, RawMatrix *src);
static void setIdentity(RawMatrix *dst);
}; };
struct Matrix struct Matrix
@ -483,6 +486,7 @@ enum Platform
}; };
#define MAKEPLUGINID(v, id) (((v & 0xFFFFFF) << 8) | (id & 0xFF)) #define MAKEPLUGINID(v, id) (((v & 0xFFFFFF) << 8) | (id & 0xFF))
#define MAKEPIPEID(v, id) (((v & 0xFFFF) << 16) | (id & 0xFFFF))
enum VendorID enum VendorID
{ {

View File

@ -11,9 +11,9 @@ enum RenderState
ZWRITEENABLE, ZWRITEENABLE,
FOGENABLE, FOGENABLE,
FOGCOLOR, FOGCOLOR,
CULLMODE,
// TODO: // TODO:
// fog type, density ? // fog type, density ?
// ? cullmode
// ? shademode // ? shademode
// ???? stencil // ???? stencil
@ -29,6 +29,13 @@ enum AlphaTestFunc
ALPHALESS ALPHALESS
}; };
enum CullMode
{
CULLNONE,
CULLBACK,
CULLFRONT
};
enum BlendFunction enum BlendFunction
{ {
BLENDZERO = 0, BLENDZERO = 0,