mirror of https://github.com/aap/librw.git
more d3d caching, better d3d raster locking
This commit is contained in:
parent
e21cf250a2
commit
113d76cfaa
|
@ -363,33 +363,6 @@ destroyTexture(void *texture)
|
|||
#endif
|
||||
}
|
||||
|
||||
uint8*
|
||||
lockTexture(void *texture, int32 level, int32 lockMode)
|
||||
{
|
||||
// TODO: don't ignore this
|
||||
(void)lockMode;
|
||||
#ifdef RW_D3D9
|
||||
IDirect3DTexture9 *tex = (IDirect3DTexture9*)texture;
|
||||
D3DLOCKED_RECT lr;
|
||||
tex->LockRect(level, &lr, 0, D3DLOCK_NOSYSLOCK);
|
||||
return (uint8*)lr.pBits;
|
||||
#else
|
||||
RasterLevels *levels = (RasterLevels*)texture;
|
||||
return levels->levels[level].data;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
unlockTexture(void *texture, int32 level)
|
||||
{
|
||||
(void)texture;
|
||||
(void)level;
|
||||
#ifdef RW_D3D9
|
||||
IDirect3DTexture9 *tex = (IDirect3DTexture9*)texture;
|
||||
tex->UnlockRect(level);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Native Raster
|
||||
|
||||
int32 nativeRasterOffset;
|
||||
|
@ -531,6 +504,12 @@ rasterSetFormat(Raster *raster)
|
|||
natras->bpp = raster->depth/8;
|
||||
natras->hasAlpha = formatInfoRW[(raster->format >> 8) & 0xF].hasAlpha;
|
||||
raster->stride = raster->width*natras->bpp;
|
||||
|
||||
raster->pixels = nil;
|
||||
raster->originalWidth = raster->width;
|
||||
raster->originalHeight = raster->height;
|
||||
raster->originalStride = raster->stride;
|
||||
raster->originalPixels = raster->pixels;
|
||||
}
|
||||
|
||||
static Raster*
|
||||
|
@ -589,8 +568,8 @@ rasterCreateCamera(Raster *raster)
|
|||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
raster->originalWidth = raster->width;
|
||||
raster->originalHeight = raster->height;
|
||||
raster->stride = 0;
|
||||
raster->pixels = nil;
|
||||
raster->originalStride = raster->stride = 0;
|
||||
raster->originalPixels = raster->pixels = nil;
|
||||
|
||||
natras->format = d3d9Globals.present.BackBufferFormat;
|
||||
raster->depth = findFormatDepth(natras->format);
|
||||
|
@ -605,8 +584,8 @@ rasterCreateZbuffer(Raster *raster)
|
|||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
raster->originalWidth = raster->width;
|
||||
raster->originalHeight = raster->height;
|
||||
raster->stride = 0;
|
||||
raster->pixels = nil;
|
||||
raster->originalStride = raster->stride = 0;
|
||||
raster->originalPixels = raster->pixels = nil;
|
||||
|
||||
// TODO: allow other formats
|
||||
natras->format = d3d9Globals.present.AutoDepthStencilFormat;
|
||||
|
@ -671,14 +650,65 @@ uint8*
|
|||
rasterLock(Raster *raster, int32 level, int32 lockMode)
|
||||
{
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
return lockTexture(natras->texture, level, lockMode);
|
||||
|
||||
// check if already locked
|
||||
if(raster->privateFlags & (Raster::PRIVATELOCK_READ|Raster::PRIVATELOCK_WRITE))
|
||||
return nil;
|
||||
|
||||
#ifdef RW_D3D9
|
||||
DWORD flags = D3DLOCK_NOSYSLOCK;
|
||||
if(lockMode & Raster::LOCKREAD)
|
||||
flags |= D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE;
|
||||
IDirect3DTexture9 *tex = (IDirect3DTexture9*)natras->texture;
|
||||
IDirect3DSurface9 *surf;
|
||||
D3DLOCKED_RECT lr;
|
||||
|
||||
switch(raster->type){
|
||||
case Raster::NORMAL:
|
||||
case Raster::TEXTURE: {
|
||||
tex->GetSurfaceLevel(level, &surf);
|
||||
natras->lockedSurf = surf;
|
||||
surf->LockRect(&lr, 0, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(0 && "can't lock this raster type (yet)");
|
||||
}
|
||||
|
||||
raster->pixels = (uint8*)lr.pBits;
|
||||
raster->width >>= level;
|
||||
raster->height >>= level;
|
||||
raster->stride = lr.Pitch;
|
||||
if(raster->width == 0) raster->width = 1;
|
||||
if(raster->height == 0) raster->height = 1;
|
||||
|
||||
if(lockMode & Raster::LOCKREAD) raster->privateFlags |= Raster::PRIVATELOCK_READ;
|
||||
if(lockMode & Raster::LOCKWRITE) raster->privateFlags |= Raster::PRIVATELOCK_WRITE;
|
||||
|
||||
return raster->pixels;
|
||||
#else
|
||||
RasterLevels *levels = (RasterLevels*)natras->texture;
|
||||
return levels->levels[level].data;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
rasterUnlock(Raster *raster, int32 level)
|
||||
{
|
||||
#if RW_D3D9
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
unlockTexture(natras->texture, level);
|
||||
IDirect3DSurface9 *surf = (IDirect3DSurface9*)natras->lockedSurf;
|
||||
surf->UnlockRect();
|
||||
surf->Release();
|
||||
natras->lockedSurf = nil;
|
||||
#endif
|
||||
raster->width = raster->originalWidth;
|
||||
raster->height = raster->originalHeight;
|
||||
raster->stride = raster->originalStride;
|
||||
raster->pixels = raster->originalPixels;
|
||||
|
||||
raster->privateFlags &= ~(Raster::PRIVATELOCK_READ|Raster::PRIVATELOCK_WRITE);
|
||||
}
|
||||
|
||||
int32
|
||||
|
@ -1012,6 +1042,7 @@ createNativeRaster(void *object, int32 offset, int32)
|
|||
D3dRaster *raster = PLUGINOFFSET(D3dRaster, object, offset);
|
||||
raster->texture = nil;
|
||||
raster->palette = nil;
|
||||
raster->lockedSurf = nil;
|
||||
raster->format = 0;
|
||||
raster->hasAlpha = 0;
|
||||
raster->customFormat = 0;
|
||||
|
@ -1056,6 +1087,7 @@ copyNativeRaster(void *dst, void *, int32 offset, int32)
|
|||
D3dRaster *raster = PLUGINOFFSET(D3dRaster, dst, offset);
|
||||
raster->texture = nil;
|
||||
raster->palette = nil;
|
||||
raster->lockedSurf = nil;
|
||||
raster->format = 0;
|
||||
raster->hasAlpha = 0;
|
||||
raster->customFormat = 0;
|
||||
|
|
|
@ -39,7 +39,7 @@ 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->surfaceProps, inst->material->color);
|
||||
d3d::setMaterial(inst->material->color, inst->material->surfaceProps);
|
||||
|
||||
|
||||
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
|
|
|
@ -159,26 +159,13 @@ matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
|||
vsBits = lightingCB_Shader(atomic);
|
||||
uploadMatrices(atomic->getFrame()->getLTM());
|
||||
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_fogData, (float*)&d3dShaderState.fogData, 1);
|
||||
d3ddevice->SetPixelShaderConstantF(PSLOC_fogColor, (float*)&d3dShaderState.fogColor, 1);
|
||||
|
||||
bool normals = !!(atomic->geometry->flags & Geometry::NORMALS);
|
||||
|
||||
float surfProps[4];
|
||||
surfProps[3] = 0.0f;
|
||||
|
||||
InstanceData *inst = header->inst;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
Material *m = inst->material;
|
||||
|
||||
rw::RGBAf col;
|
||||
convColor(&col, &inst->material->color);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_matColor, (float*)&col, 1);
|
||||
|
||||
surfProps[0] = m->surfaceProps.ambient;
|
||||
surfProps[1] = m->surfaceProps.specular;
|
||||
surfProps[2] = m->surfaceProps.diffuse;
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_surfProps, surfProps, 1);
|
||||
setMaterial(m->color, m->surfaceProps);
|
||||
|
||||
MatFX *matfx = MatFX::get(m);
|
||||
if(matfx == nil)
|
||||
|
|
|
@ -73,6 +73,7 @@ drawInst(d3d9::InstanceDataHeader *header, d3d9::InstanceData *inst)
|
|||
drawInst_simple(header, inst);
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
defaultRenderCB_Fix(Atomic *atomic, InstanceDataHeader *header)
|
||||
{
|
||||
|
@ -97,7 +98,7 @@ defaultRenderCB_Fix(Atomic *atomic, InstanceDataHeader *header)
|
|||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
SetRenderState(VERTEXALPHA, inst->vertexAlpha || inst->material->color.alpha != 255);
|
||||
const static rw::RGBA white = { 255, 255, 255, 255 };
|
||||
d3d::setMaterial(inst->material->surfaceProps, white);
|
||||
d3d::setMaterial(white, inst->material->surfaceProps);
|
||||
|
||||
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
if(geo->flags & Geometry::PRELIT)
|
||||
|
@ -138,7 +139,7 @@ defaultRenderCB_Fix(Atomic *atomic, InstanceDataHeader *header)
|
|||
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void
|
||||
defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
||||
|
@ -151,9 +152,6 @@ defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
|||
vsBits = lightingCB_Shader(atomic);
|
||||
uploadMatrices(atomic->getFrame()->getLTM());
|
||||
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_fogData, (float*)&d3dShaderState.fogData, 1);
|
||||
d3ddevice->SetPixelShaderConstantF(PSLOC_fogColor, (float*)&d3dShaderState.fogColor, 1);
|
||||
|
||||
// Pick a shader
|
||||
if((vsBits & VSLIGHT_MASK) == 0)
|
||||
setVertexShader(default_amb_VS);
|
||||
|
@ -162,23 +160,13 @@ defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
|||
else
|
||||
setVertexShader(default_all_VS);
|
||||
|
||||
float surfProps[4];
|
||||
surfProps[3] = 0.0f;
|
||||
|
||||
InstanceData *inst = header->inst;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
Material *m = inst->material;
|
||||
|
||||
SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255);
|
||||
|
||||
rw::RGBAf col;
|
||||
convColor(&col, &inst->material->color);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_matColor, (float*)&col, 1);
|
||||
|
||||
surfProps[0] = m->surfaceProps.ambient;
|
||||
surfProps[1] = m->surfaceProps.specular;
|
||||
surfProps[2] = m->surfaceProps.diffuse;
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_surfProps, surfProps, 1);
|
||||
setMaterial(m->color, m->surfaceProps);
|
||||
|
||||
if(inst->material->texture){
|
||||
d3d::setTexture(0, m->texture);
|
||||
|
|
|
@ -276,9 +276,6 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
|
||||
uploadSkinMatrices(atomic);
|
||||
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_fogData, (float*)&d3dShaderState.fogData, 1);
|
||||
d3ddevice->SetPixelShaderConstantF(PSLOC_fogColor, (float*)&d3dShaderState.fogColor, 1);
|
||||
|
||||
// Pick a shader
|
||||
if((vsBits & VSLIGHT_MASK) == 0)
|
||||
setVertexShader(skin_amb_VS);
|
||||
|
@ -287,23 +284,13 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
else
|
||||
setVertexShader(skin_all_VS);
|
||||
|
||||
float surfProps[4];
|
||||
surfProps[3] = 0.0f;
|
||||
|
||||
InstanceData *inst = header->inst;
|
||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||
Material *m = inst->material;
|
||||
|
||||
SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255);
|
||||
|
||||
rw::RGBAf col;
|
||||
convColor(&col, &inst->material->color);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_matColor, (float*)&col, 1);
|
||||
|
||||
surfProps[0] = m->surfaceProps.ambient;
|
||||
surfProps[1] = m->surfaceProps.specular;
|
||||
surfProps[2] = m->surfaceProps.diffuse;
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_surfProps, surfProps, 1);
|
||||
setMaterial(m->color, m->surfaceProps);
|
||||
|
||||
if(inst->material->texture){
|
||||
d3d::setTexture(0, m->texture);
|
||||
|
|
|
@ -265,6 +265,12 @@ flushCache(void)
|
|||
}
|
||||
}
|
||||
numDirtyTextureStageStates = 0;
|
||||
|
||||
if(d3dShaderState.fogDirty){
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_fogData, (float*)&d3dShaderState.fogData, 1);
|
||||
d3ddevice->SetPixelShaderConstantF(PSLOC_fogColor, (float*)&d3dShaderState.fogColor, 1);
|
||||
d3dShaderState.fogDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -489,7 +495,7 @@ setD3dMaterial(D3DMATERIAL9 *mat9)
|
|||
}
|
||||
|
||||
void
|
||||
setMaterial(SurfaceProperties surfProps, rw::RGBA color)
|
||||
setMaterial_fix(const RGBA &color, const SurfaceProperties &surfProps)
|
||||
{
|
||||
D3DMATERIAL9 mat9;
|
||||
D3DCOLORVALUE black = { 0, 0, 0, 0 };
|
||||
|
@ -509,6 +515,30 @@ setMaterial(SurfaceProperties surfProps, rw::RGBA color)
|
|||
setD3dMaterial(&mat9);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops)
|
||||
{
|
||||
if(!equal(d3dShaderState.matColor, color)){
|
||||
rw::RGBAf col;
|
||||
convColor(&col, &color);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_matColor, (float*)&col, 1);
|
||||
d3dShaderState.matColor = color;
|
||||
}
|
||||
|
||||
if(d3dShaderState.surfProps.ambient != surfaceprops.ambient ||
|
||||
d3dShaderState.surfProps.specular != surfaceprops.specular ||
|
||||
d3dShaderState.surfProps.diffuse != surfaceprops.diffuse){
|
||||
float surfProps[4];
|
||||
surfProps[0] = surfaceprops.ambient;
|
||||
surfProps[1] = surfaceprops.specular;
|
||||
surfProps[2] = surfaceprops.diffuse;
|
||||
surfProps[3] = 0.0f;
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_surfProps, surfProps, 1);
|
||||
d3dShaderState.surfProps = surfaceprops;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setRwRenderState(int32 state, void *pvalue)
|
||||
{
|
||||
|
@ -557,6 +587,7 @@ setRwRenderState(int32 state, void *pvalue)
|
|||
rwStateCache.fogenable = bval;
|
||||
// setRenderState(D3DRS_FOGENABLE, rwStateCache.fogenable);
|
||||
d3dShaderState.fogData.disable = bval ? 0.0f : 1.0f;
|
||||
d3dShaderState.fogDirty = true;
|
||||
};
|
||||
break;
|
||||
case FOGCOLOR:{
|
||||
|
@ -569,6 +600,7 @@ setRwRenderState(int32 state, void *pvalue)
|
|||
rwStateCache.fogcolor = c;
|
||||
setRenderState(D3DRS_FOGCOLOR, D3DCOLOR_RGBA(c.red, c.green, c.blue, c.alpha));
|
||||
convColor(&d3dShaderState.fogColor, &c);
|
||||
d3dShaderState.fogDirty = true;
|
||||
}} break;
|
||||
case CULLMODE:
|
||||
if(rwStateCache.cullmode != value){
|
||||
|
@ -861,6 +893,7 @@ beginUpdate(Camera *cam)
|
|||
d3dShaderState.fogDisable.end = 0.0f;
|
||||
d3dShaderState.fogDisable.range = 0.0f;
|
||||
d3dShaderState.fogDisable.disable = 1.0f;
|
||||
d3dShaderState.fogDirty = true;
|
||||
|
||||
setRenderSurfaces(cam);
|
||||
|
||||
|
|
|
@ -262,12 +262,9 @@ im3DTransform(void *vertices, int32 numVertices, Matrix *world, uint32 flags)
|
|||
if((flags & im3d::VERTEXUV) == 0)
|
||||
SetRenderStatePtr(TEXTURERASTER, nil);
|
||||
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_fogData, (float*)&d3dShaderState.fogData, 1);
|
||||
d3ddevice->SetPixelShaderConstantF(PSLOC_fogColor, (float*)&d3dShaderState.fogColor, 1);
|
||||
static float surfprops[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
static float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_surfProps, surfprops, 1);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_matColor, white, 1);
|
||||
static RGBA white = { 255, 255, 255, 255 };
|
||||
static SurfaceProperties surfprops = { 0.0f, 0.0f, 0.0f };
|
||||
setMaterial(white, surfprops);
|
||||
|
||||
uint8 *lockedvertices = lockVertices(im3dvertbuf, 0, numVertices*sizeof(Im3DVertex), D3DLOCK_DISCARD);
|
||||
memcpy(lockedvertices, vertices, numVertices*sizeof(Im3DVertex));
|
||||
|
|
|
@ -218,12 +218,34 @@ struct LightVS
|
|||
V3d direction; float param2;
|
||||
};
|
||||
|
||||
void
|
||||
setAmbient(const RGBAf &color)
|
||||
{
|
||||
if(!equal(d3dShaderState.ambient, color)){
|
||||
d3dShaderState.ambient = color;
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_ambLight, (float*)&color, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
setNumLights(int numDir, int numPoint, int numSpot)
|
||||
{
|
||||
static int32 numLights[4*3];
|
||||
if(d3dShaderState.numDir != numDir ||
|
||||
d3dShaderState.numPoint != numPoint ||
|
||||
d3dShaderState.numSpot != numSpot){
|
||||
numLights[0] = d3dShaderState.numDir = numDir;
|
||||
numLights[4] = d3dShaderState.numPoint = numPoint;
|
||||
numLights[8] = d3dShaderState.numSpot = numSpot;
|
||||
d3ddevice->SetVertexShaderConstantI(VSLOC_numLights, numLights, 3);
|
||||
}
|
||||
}
|
||||
|
||||
int32
|
||||
uploadLights(WorldLights *lightData)
|
||||
{
|
||||
int i;
|
||||
int bits = 0;
|
||||
int32 numLights[4*3];
|
||||
float32 firstLight[4];
|
||||
firstLight[0] = 0; // directional
|
||||
firstLight[1] = 0; // point
|
||||
|
@ -281,26 +303,33 @@ uploadLights(WorldLights *lightData)
|
|||
}
|
||||
|
||||
firstLight[0] = 0;
|
||||
numLights[0] = lightData->numDirectionals;
|
||||
firstLight[1] = numLights[0] + firstLight[0];
|
||||
numLights[4] = np;
|
||||
firstLight[2] = numLights[4] + firstLight[1];
|
||||
numLights[8] = ns;
|
||||
int numDir = lightData->numDirectionals;
|
||||
firstLight[1] = numDir + firstLight[0];
|
||||
int numPoint = np;
|
||||
firstLight[2] = numPoint + firstLight[1];
|
||||
int numSpot = ns;
|
||||
|
||||
d3ddevice->SetVertexShaderConstantI(VSLOC_numLights, numLights, 3);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_lightOffset, firstLight, 1);
|
||||
setNumLights(numDir, numPoint, numSpot);
|
||||
if(d3dShaderState.lightOffset[0] != firstLight[0] ||
|
||||
d3dShaderState.lightOffset[1] != firstLight[1] ||
|
||||
d3dShaderState.lightOffset[2] != firstLight[2]){
|
||||
d3dShaderState.lightOffset[0] = firstLight[0];
|
||||
d3dShaderState.lightOffset[1] = firstLight[1];
|
||||
d3dShaderState.lightOffset[2] = firstLight[2];
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_lightOffset, firstLight, 1);
|
||||
}
|
||||
|
||||
int32 off = VSLOC_lights;
|
||||
if(numLights[0])
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&directionals, numLights[0]*3);
|
||||
off += numLights[0]*3;
|
||||
if(numDir)
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&directionals, numDir*3);
|
||||
off += numDir*3;
|
||||
|
||||
if(numLights[4])
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&points, numLights[4]*3);
|
||||
off += numLights[4]*3;
|
||||
if(numPoint)
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&points, numPoint*3);
|
||||
off += numPoint*3;
|
||||
|
||||
if(numLights[8])
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&spots, numLights[8]*3);
|
||||
if(numSpot)
|
||||
d3ddevice->SetVertexShaderConstantF(off, (float*)&spots, numSpot*3);
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
@ -318,7 +347,7 @@ lightingCB_Shader(Atomic *atomic)
|
|||
|
||||
if(atomic->geometry->flags & rw::Geometry::LIGHT){
|
||||
((World*)engine->currentWorld)->enumerateLights(atomic, &lightData);
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_ambLight, (float*)&lightData.ambient, 1);
|
||||
setAmbient(lightData.ambient);
|
||||
if((atomic->geometry->flags & rw::Geometry::NORMALS) == 0){
|
||||
// Get rid of lights that need normals when we don't have any
|
||||
lightData.numDirectionals = 0;
|
||||
|
@ -326,10 +355,9 @@ lightingCB_Shader(Atomic *atomic)
|
|||
}
|
||||
return uploadLights(&lightData);
|
||||
}else{
|
||||
static const float zeroF[4];
|
||||
static const int32 zeroI[4];
|
||||
d3ddevice->SetVertexShaderConstantF(VSLOC_ambLight, zeroF, 1);
|
||||
d3ddevice->SetVertexShaderConstantI(VSLOC_numLights, zeroI, 1);
|
||||
static const RGBAf black = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
setAmbient(black);
|
||||
setNumLights(0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,7 @@ struct D3dRaster
|
|||
{
|
||||
void *texture;
|
||||
void *palette;
|
||||
void *lockedSurf;
|
||||
uint32 format;
|
||||
uint32 bpp; // bytes per pixel
|
||||
bool32 hasAlpha;
|
||||
|
@ -186,7 +187,7 @@ void getSamplerState(uint32 stage, uint32 type, uint32 *value);
|
|||
void flushCache(void);
|
||||
|
||||
void setTexture(uint32 stage, Texture *tex);
|
||||
void setMaterial(SurfaceProperties surfProps, rw::RGBA color);
|
||||
void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops);
|
||||
|
||||
void setVertexShader(void *vs);
|
||||
void setPixelShader(void *ps);
|
||||
|
@ -213,6 +214,7 @@ struct VertexConstantData
|
|||
};
|
||||
extern void *constantVertexStream;
|
||||
|
||||
// TODO: figure out why this even still exists...
|
||||
struct D3dShaderState
|
||||
{
|
||||
// for VS
|
||||
|
@ -222,8 +224,15 @@ struct D3dShaderState
|
|||
float32 range; // 1/(start-end)
|
||||
float32 disable; // lower clamp
|
||||
} fogData, fogDisable;
|
||||
RGBA matColor;
|
||||
SurfaceProperties surfProps;
|
||||
float lightOffset[3];
|
||||
int32 numDir, numPoint, numSpot;
|
||||
RGBAf ambient;
|
||||
// for PS
|
||||
RGBAf fogColor;
|
||||
|
||||
bool fogDirty;
|
||||
};
|
||||
extern D3dShaderState d3dShaderState;
|
||||
|
||||
|
|
|
@ -19,15 +19,6 @@
|
|||
namespace rw {
|
||||
namespace ps2 {
|
||||
|
||||
enum
|
||||
{
|
||||
// from RW
|
||||
PS2LOCK_READ = 0x02,
|
||||
PS2LOCK_WRITE = 0x04,
|
||||
PS2LOCK_READ_PALETTE = 0x08,
|
||||
PS2LOCK_WRITE_PALETTE = 0x10,
|
||||
};
|
||||
|
||||
int32 nativeRasterOffset;
|
||||
|
||||
#define MAXLEVEL(r) ((r)->tex1low >> 2)
|
||||
|
@ -1491,8 +1482,8 @@ rasterLock(Raster *raster, int32 level, int32 lockMode)
|
|||
|
||||
if((lockMode & Raster::LOCKNOFETCH) == 0)
|
||||
unswizzleRaster(raster);
|
||||
if(lockMode & Raster::LOCKREAD) raster->privateFlags |= PS2LOCK_READ;
|
||||
if(lockMode & Raster::LOCKWRITE) raster->privateFlags |= PS2LOCK_WRITE;
|
||||
if(lockMode & Raster::LOCKREAD) raster->privateFlags |= Raster::PRIVATELOCK_READ;
|
||||
if(lockMode & Raster::LOCKWRITE) raster->privateFlags |= Raster::PRIVATELOCK_WRITE;
|
||||
return raster->pixels;
|
||||
}
|
||||
|
||||
|
@ -1510,7 +1501,7 @@ rasterUnlock(Raster *raster, int32 level)
|
|||
if(natras->flags & Ps2Raster::NEWSTYLE)
|
||||
raster->pixels = ((Ps2Raster::PixelPtr*)raster->pixels)->pixels + 0x50;
|
||||
|
||||
raster->privateFlags &= ~(PS2LOCK_READ|PS2LOCK_WRITE);
|
||||
raster->privateFlags &= ~(Raster::PRIVATELOCK_READ|Raster::PRIVATELOCK_WRITE);
|
||||
// TODO: generate mipmaps
|
||||
}
|
||||
|
||||
|
@ -1563,8 +1554,8 @@ rasterLockPalette(Raster *raster, int32 lockMode)
|
|||
return nil;
|
||||
if((lockMode & Raster::LOCKNOFETCH) == 0)
|
||||
convertPalette(raster);
|
||||
if(lockMode & Raster::LOCKREAD) raster->privateFlags |= PS2LOCK_READ_PALETTE;
|
||||
if(lockMode & Raster::LOCKWRITE) raster->privateFlags |= PS2LOCK_WRITE_PALETTE;
|
||||
if(lockMode & Raster::LOCKREAD) raster->privateFlags |= Raster::PRIVATELOCK_READ_PALETTE;
|
||||
if(lockMode & Raster::LOCKWRITE) raster->privateFlags |= Raster::PRIVATELOCK_WRITE_PALETTE;
|
||||
return raster->palette;
|
||||
}
|
||||
|
||||
|
@ -1573,7 +1564,7 @@ rasterUnlockPalette(Raster *raster)
|
|||
{
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8))
|
||||
convertPalette(raster);
|
||||
raster->privateFlags &= ~(PS2LOCK_READ_PALETTE|PS2LOCK_WRITE_PALETTE);
|
||||
raster->privateFlags &= ~(Raster::PRIVATELOCK_READ_PALETTE|Raster::PRIVATELOCK_WRITE_PALETTE);
|
||||
}
|
||||
|
||||
// Almost the same as d3d9 and gl3 function
|
||||
|
|
|
@ -178,7 +178,7 @@ inline void clamp(RGBAf *a) {
|
|||
if(a->alpha < 0.0f) a->alpha = 0.0f;
|
||||
}
|
||||
|
||||
inline void convColor(RGBA *i, RGBAf *f){
|
||||
inline void convColor(RGBA *i, const RGBAf *f){
|
||||
int32 c;
|
||||
c = (int32)(f->red*255.0f + 0.5f);
|
||||
i->red = (uint8)c;
|
||||
|
@ -190,7 +190,7 @@ inline void convColor(RGBA *i, RGBAf *f){
|
|||
i->alpha = (uint8)c;
|
||||
}
|
||||
|
||||
inline void convColor(RGBAf *f, RGBA *i){
|
||||
inline void convColor(RGBAf *f, const RGBA *i){
|
||||
f->red = i->red/255.0f;
|
||||
f->green = i->green/255.0f;
|
||||
f->blue = i->blue/255.0f;
|
||||
|
|
|
@ -303,6 +303,15 @@ struct Raster
|
|||
LOCKNOFETCH = 4, // don't fetch pixel data
|
||||
LOCKRAW = 8,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
// from RW
|
||||
PRIVATELOCK_READ = 0x02,
|
||||
PRIVATELOCK_WRITE = 0x04,
|
||||
PRIVATELOCK_READ_PALETTE = 0x08,
|
||||
PRIVATELOCK_WRITE_PALETTE = 0x10,
|
||||
};
|
||||
};
|
||||
|
||||
void conv_RGBA8888_from_RGBA8888(uint8 *out, uint8 *in);
|
||||
|
|
Loading…
Reference in New Issue