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