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

@@ -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:

View File

@@ -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)

View File

@@ -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++){

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
}
}