mirror of https://github.com/aap/librw.git
some device and pipeline fixes
This commit is contained in:
parent
ddca04fdc2
commit
1872c235ab
|
@ -152,9 +152,9 @@ ImGui_ImplRW_NewFrame(float timeDelta)
|
|||
io.DisplaySize = ImVec2(sk::globals.width, sk::globals.height);
|
||||
io.DeltaTime = timeDelta;
|
||||
|
||||
io.KeyCtrl = false; //io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL];
|
||||
io.KeyShift = false; //io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT];
|
||||
io.KeyAlt = false; //io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT];
|
||||
io.KeyCtrl = io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL];
|
||||
io.KeyShift = io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT];
|
||||
io.KeyAlt = io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT];
|
||||
io.KeySuper = false;
|
||||
|
||||
if(io.WantMoveMouse)
|
||||
|
|
|
@ -217,11 +217,12 @@ int WINAPI
|
|||
WinMain(HINSTANCE instance, HINSTANCE,
|
||||
PSTR cmdLine, int showCmd)
|
||||
{
|
||||
|
||||
/*
|
||||
AllocConsole();
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
*/
|
||||
|
||||
INT64 ticks;
|
||||
INT64 ticksPerSecond;
|
||||
|
|
58
src/base.cpp
58
src/base.cpp
|
@ -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
|
||||
//
|
||||
|
|
|
@ -562,7 +562,7 @@ rasterToImage(Raster *raster)
|
|||
switch(natras->format){
|
||||
case D3DFMT_DXT1:
|
||||
image->setPixelsDXT(1, pix);
|
||||
if((raster->format & 0xF00) == Raster::C555)
|
||||
if((raster->format & 0xF00) == Raster::C565)
|
||||
image->removeMask();
|
||||
break;
|
||||
case D3DFMT_DXT3:
|
||||
|
|
|
@ -19,6 +19,8 @@ using namespace d3d;
|
|||
void defaultRenderCB(Atomic*, InstanceDataHeader*) {}
|
||||
#else
|
||||
|
||||
// This is a bit abandoned, use d3d9 instead
|
||||
|
||||
void
|
||||
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||
{
|
||||
|
@ -36,7 +38,9 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
InstanceData *inst = header->inst;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
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_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
if(geo->flags & Geometry::PRELIT)
|
||||
|
|
|
@ -498,11 +498,17 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
|||
if(isPrelit){
|
||||
for(i = 0; dcl[i].usage != D3DDECLUSAGE_COLOR || dcl[i].usageIndex != 0; i++)
|
||||
;
|
||||
// TODO: vertex alpha (instance per mesh)
|
||||
instColor(vertFormatMap[dcl[i].type], verts + dcl[i].offset,
|
||||
geo->colors,
|
||||
header->totalNumVertex,
|
||||
header->vertexStream[dcl[i].stream].stride);
|
||||
InstanceData *inst = header->inst;
|
||||
uint32 n = header->numMeshes;
|
||||
while(n--){
|
||||
uint32 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++){
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "../rwpipeline.h"
|
||||
#include "../rwobjects.h"
|
||||
#include "../rwengine.h"
|
||||
#include "../rwrender.h"
|
||||
#include "rwd3d.h"
|
||||
#include "rwd3d9.h"
|
||||
|
||||
|
@ -44,6 +45,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
|
||||
InstanceData *inst = header->inst;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
// Texture
|
||||
d3d::setTexture(0, inst->material->texture);
|
||||
d3d::setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
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_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_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
if(geo->flags & Geometry::PRELIT)
|
||||
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);
|
||||
else
|
||||
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, inst->vertexAlpha ? D3DMCS_COLOR1 : D3DMCS_MATERIAL);
|
||||
|
||||
d3d::flushCache();
|
||||
d3ddevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex,
|
||||
|
@ -67,6 +82,8 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
inst->startIndex, inst->numPrimitives);
|
||||
inst++;
|
||||
}
|
||||
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,7 @@ static uint32 zwrite;
|
|||
static uint32 ztest;
|
||||
static uint32 fogenable;
|
||||
static RGBA fogcolor;
|
||||
static uint32 cullmode;
|
||||
static uint32 alphafunc;
|
||||
static uint32 alpharef;
|
||||
|
||||
|
@ -208,6 +209,12 @@ uint32 alphafuncMap[] = {
|
|||
D3DCMP_LESS
|
||||
};
|
||||
|
||||
uint32 cullmodeMap[] = {
|
||||
D3DCULL_NONE,
|
||||
D3DCULL_CW,
|
||||
D3DCULL_CCW
|
||||
};
|
||||
|
||||
static void
|
||||
setRwRenderState(int32 state, uint32 value)
|
||||
{
|
||||
|
@ -252,6 +259,12 @@ setRwRenderState(int32 state, uint32 value)
|
|||
fogcolor = c;
|
||||
setRenderState(D3DRS_FOGCOLOR, D3DCOLOR_RGBA(c.red, c.green, c.blue, c.alpha));
|
||||
}} break;
|
||||
case CULLMODE:
|
||||
if(cullmode != value){
|
||||
cullmode = value;
|
||||
setRenderState(D3DRS_CULLMODE, cullmodeMap[value]);
|
||||
}
|
||||
break;
|
||||
case ALPHATESTFUNC:
|
||||
if(alphafunc != value){
|
||||
alphafunc = value;
|
||||
|
@ -285,6 +298,8 @@ getRwRenderState(int32 state)
|
|||
return fogenable;
|
||||
case FOGCOLOR:
|
||||
return *(uint32*)&fogcolor;
|
||||
case CULLMODE:
|
||||
return cullmode;
|
||||
case ALPHATESTFUNC:
|
||||
return alphafunc;
|
||||
case ALPHATESTREF:
|
||||
|
@ -372,20 +387,20 @@ setD3dMaterial(D3DMATERIAL9 *mat9)
|
|||
}
|
||||
|
||||
void
|
||||
setMaterial(Material *mat)
|
||||
setMaterial(SurfaceProperties surfProps, rw::RGBA color)
|
||||
{
|
||||
D3DMATERIAL9 mat9;
|
||||
D3DCOLORVALUE black = { 0, 0, 0, 0 };
|
||||
float ambmult = mat->surfaceProps.ambient/255.0f;
|
||||
float diffmult = mat->surfaceProps.diffuse/255.0f;
|
||||
mat9.Ambient.r = mat->color.red*ambmult;
|
||||
mat9.Ambient.g = mat->color.green*ambmult;
|
||||
mat9.Ambient.b = mat->color.blue*ambmult;
|
||||
mat9.Ambient.a = mat->color.alpha*ambmult;
|
||||
mat9.Diffuse.r = mat->color.red*diffmult;
|
||||
mat9.Diffuse.g = mat->color.green*diffmult;
|
||||
mat9.Diffuse.b = mat->color.blue*diffmult;
|
||||
mat9.Diffuse.a = mat->color.alpha*diffmult;
|
||||
float ambmult = surfProps.ambient/255.0f;
|
||||
float diffmult = surfProps.diffuse/255.0f;
|
||||
mat9.Ambient.r = color.red*ambmult;
|
||||
mat9.Ambient.g = color.green*ambmult;
|
||||
mat9.Ambient.b = color.blue*ambmult;
|
||||
mat9.Ambient.a = color.alpha*ambmult;
|
||||
mat9.Diffuse.r = color.red*diffmult;
|
||||
mat9.Diffuse.g = color.green*diffmult;
|
||||
mat9.Diffuse.b = color.blue*diffmult;
|
||||
mat9.Diffuse.a = color.alpha*diffmult;
|
||||
mat9.Power = 0.0f;
|
||||
mat9.Emissive = black;
|
||||
mat9.Specular = black;
|
||||
|
@ -628,6 +643,7 @@ initD3D(void)
|
|||
// TODO: more fog stuff
|
||||
|
||||
d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
cullmode = CULLNONE;
|
||||
|
||||
d3ddevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
||||
d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
|
|
|
@ -176,6 +176,12 @@ im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices)
|
|||
|
||||
d3ddevice->SetIndices(im3dindbuf);
|
||||
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();
|
||||
|
||||
uint32 primCount = 0;
|
||||
|
|
|
@ -151,7 +151,7 @@ void getSamplerState(uint32 stage, uint32 type, uint32 *value);
|
|||
void flushCache(void);
|
||||
|
||||
void setTexture(uint32 stage, Texture *tex);
|
||||
void setMaterial(Material *mat);
|
||||
void setMaterial(SurfaceProperties surfProps, rw::RGBA color);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,10 +85,13 @@ static bool32 objectDirty = 1;
|
|||
|
||||
// cached render states
|
||||
static bool32 vertexAlpha;
|
||||
static uint32 alphaTestEnable;
|
||||
static uint32 alphaFunc;
|
||||
static bool32 textureAlpha;
|
||||
static uint32 srcblend, destblend;
|
||||
static uint32 zwrite;
|
||||
static uint32 ztest;
|
||||
static uint32 cullmode;
|
||||
|
||||
static int32 activeTexture;
|
||||
|
||||
|
@ -106,17 +109,43 @@ static uint32 blendMap[] = {
|
|||
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
|
||||
setVertexAlpha(bool32 enable)
|
||||
{
|
||||
if(vertexAlpha != enable){
|
||||
vertexAlpha = enable;
|
||||
if(!textureAlpha){
|
||||
if(enable)
|
||||
glEnable(GL_BLEND);
|
||||
else
|
||||
glDisable(GL_BLEND);
|
||||
(enable ? glEnable : glDisable)(GL_BLEND);
|
||||
setAlphaTest(enable);
|
||||
}
|
||||
vertexAlpha = enable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,12 +194,20 @@ setRenderState(int32 state, uint32 value)
|
|||
convColor(&uniformState.fogColor, (RGBA*)&value);
|
||||
stateDirty = 1;
|
||||
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:
|
||||
if(uniformState.alphaFunc != value){
|
||||
uniformState.alphaFunc = value;
|
||||
stateDirty = 1;
|
||||
}
|
||||
setAlphaTestFunction(value);
|
||||
break;
|
||||
case ALPHATESTREF:
|
||||
if(uniformState.alphaRef != value/255.0f){
|
||||
|
@ -201,9 +238,11 @@ getRenderState(int32 state)
|
|||
case FOGCOLOR:
|
||||
convColor(&rgba, &uniformState.fogColor);
|
||||
return *(uint32*)&rgba;
|
||||
case CULLMODE:
|
||||
return cullmode;
|
||||
|
||||
case ALPHATESTFUNC:
|
||||
return uniformState.alphaFunc;
|
||||
return alphaFunc;
|
||||
case ALPHATESTREF:
|
||||
return (uint32)(uniformState.alphaRef*255.0f);
|
||||
}
|
||||
|
@ -213,7 +252,8 @@ getRenderState(int32 state)
|
|||
static void
|
||||
resetRenderState(void)
|
||||
{
|
||||
uniformState.alphaFunc = ALPHAGREATEREQUAL;
|
||||
alphaFunc = ALPHAGREATEREQUAL;
|
||||
uniformState.alphaFunc = 0;
|
||||
uniformState.alphaRef = 10.0f/255.0f;
|
||||
uniformState.fogEnable = 0;
|
||||
uniformState.fogStart = 0.0f;
|
||||
|
@ -223,6 +263,7 @@ resetRenderState(void)
|
|||
vertexAlpha = 0;
|
||||
textureAlpha = 0;
|
||||
glDisable(GL_BLEND);
|
||||
alphaTestEnable = 0;
|
||||
|
||||
srcblend = BLENDSRCALPHA;
|
||||
destblend = BLENDINVSRCALPHA;
|
||||
|
@ -235,6 +276,9 @@ resetRenderState(void)
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
cullmode = CULLNONE;
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
glActiveTexture(GL_TEXTURE0+i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
@ -323,7 +367,8 @@ setTexture(int32 n, Texture *tex)
|
|||
};
|
||||
bool32 alpha;
|
||||
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){
|
||||
glBindTexture(GL_TEXTURE_2D, whitetex);
|
||||
alpha = 0;
|
||||
|
@ -345,10 +390,8 @@ setTexture(int32 n, Texture *tex)
|
|||
if(alpha != textureAlpha){
|
||||
textureAlpha = alpha;
|
||||
if(!vertexAlpha){
|
||||
if(alpha)
|
||||
glEnable(GL_BLEND);
|
||||
else
|
||||
glDisable(GL_BLEND);
|
||||
(alpha ? glEnable : glDisable)(GL_BLEND);
|
||||
setAlphaTest(alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
|
|||
uint32 offset = 0;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
findMinVertAndNumVertices(mesh->indices, mesh->numIndices,
|
||||
&inst->minVert, nil);
|
||||
&inst->minVert, &inst->numVertices);
|
||||
inst->numIndex = mesh->numIndices;
|
||||
inst->material = mesh->material;
|
||||
inst->vertexAlpha = 0;
|
||||
|
@ -197,9 +197,15 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
|
|||
if(isPrelit){
|
||||
for(a = attribs; a->index != ATTRIB_COLOR; a++)
|
||||
;
|
||||
instColor(VERT_RGBA, verts + a->offset,
|
||||
geo->colors,
|
||||
header->totalNumVertex, a->stride);
|
||||
int n = header->numMeshes;
|
||||
InstanceData *inst = header->inst;
|
||||
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
|
||||
|
|
|
@ -54,6 +54,7 @@ struct InstanceData
|
|||
{
|
||||
uint32 numIndex;
|
||||
uint32 minVert; // not used for rendering
|
||||
int32 numVertices; //
|
||||
Material *material;
|
||||
bool32 vertexAlpha;
|
||||
uint32 program;
|
||||
|
|
|
@ -140,15 +140,14 @@ uninstTexCoords(int type, TexCoords *dst, uint8 *src, uint32 numVertices, uint32
|
|||
bool32
|
||||
instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride)
|
||||
{
|
||||
bool32 hasAlpha = 0;
|
||||
uint8 alpha = 0xFF;
|
||||
if(type == VERT_ARGB){
|
||||
for(uint32 i = 0; i < numVertices; i++){
|
||||
dst[0] = src->blue;
|
||||
dst[1] = src->green;
|
||||
dst[2] = src->red;
|
||||
dst[3] = src->alpha;
|
||||
if(dst[3] != 0xFF)
|
||||
hasAlpha = 1;
|
||||
alpha &= src->alpha;
|
||||
dst += stride;
|
||||
src++;
|
||||
}
|
||||
|
@ -158,14 +157,13 @@ instColor(int type, uint8 *dst, RGBA *src, uint32 numVertices, uint32 stride)
|
|||
dst[1] = src->green;
|
||||
dst[2] = src->blue;
|
||||
dst[3] = src->alpha;
|
||||
if(dst[3] != 0xFF)
|
||||
hasAlpha = 1;
|
||||
alpha &= src->alpha;
|
||||
dst += stride;
|
||||
src++;
|
||||
}
|
||||
}else
|
||||
assert(0 && "unsupported color type");
|
||||
return hasAlpha;
|
||||
return alpha != 0xFF;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -978,6 +978,7 @@ createTexRaster(Raster *raster)
|
|||
|
||||
// calculate buffer width in units of pixels/64
|
||||
bufferBase[0] = 0;
|
||||
trxpos_hi[0] = 0;
|
||||
bufferWidth[0] = nPagW*pageWidth / 64;
|
||||
|
||||
// calculate whole buffer size in words
|
||||
|
|
|
@ -280,6 +280,9 @@ struct RawMatrix
|
|||
V3d pos;
|
||||
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
|
||||
|
@ -483,6 +486,7 @@ enum Platform
|
|||
};
|
||||
|
||||
#define MAKEPLUGINID(v, id) (((v & 0xFFFFFF) << 8) | (id & 0xFF))
|
||||
#define MAKEPIPEID(v, id) (((v & 0xFFFF) << 16) | (id & 0xFFFF))
|
||||
|
||||
enum VendorID
|
||||
{
|
||||
|
|
|
@ -11,9 +11,9 @@ enum RenderState
|
|||
ZWRITEENABLE,
|
||||
FOGENABLE,
|
||||
FOGCOLOR,
|
||||
CULLMODE,
|
||||
// TODO:
|
||||
// fog type, density ?
|
||||
// ? cullmode
|
||||
// ? shademode
|
||||
// ???? stencil
|
||||
|
||||
|
@ -29,6 +29,13 @@ enum AlphaTestFunc
|
|||
ALPHALESS
|
||||
};
|
||||
|
||||
enum CullMode
|
||||
{
|
||||
CULLNONE,
|
||||
CULLBACK,
|
||||
CULLFRONT
|
||||
};
|
||||
|
||||
enum BlendFunction
|
||||
{
|
||||
BLENDZERO = 0,
|
||||
|
|
Loading…
Reference in New Issue