DXGL r675 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r674‎ | r675 | r676 >
Date:01:49, 27 July 2016
Author:admin
Status:new
Tags:
Comment:
Isolate backend texture stages from frontend.
Ensure when texture is deleted it is removed from texture stages.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2015 William Feely
 3+// Copyright (C) 2011-2016 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -376,7 +376,7 @@
377377 if(lights[i]) delete lights[i];
378378 free(lights);
379379 for(int i = 0; i < 8; i++)
380 - if(texstages[i].texture) texstages[i].texture->Release();
 380+ if(texstages[i].surface) texstages[i].surface->Release();
381381 for(int i = 0; i < materialcount; i++)
382382 {
383383 if(materials[i])
@@ -784,9 +784,9 @@
785785 if(renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
786786 {
787787 bool noalpha = false;
788 - if(!texstages[0].texture) noalpha = true;
789 - if(texstages[0].texture)
790 - if(!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 788+ if(!texstages[0].surface) noalpha = true;
 789+ if(texstages[0].surface)
 790+ if(!(texstages[0].surface->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
791791 noalpha = true;
792792 if(noalpha) texstages[0].alphaop = D3DTOP_SELECTARG2;
793793 else texstages[0].alphaop = D3DTOP_MODULATE;
@@ -819,10 +819,10 @@
820820 if(texstages[i].textransform & D3DTTFF_PROJECTED) texstages[i].shaderid |= 1i64 << 53;
821821 texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
822822 texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
823 - if(texstages[i].texture)
 823+ if(texstages[i].surface)
824824 {
825825 texstages[i].shaderid |= 1i64 << 59;
826 - if(texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT) texstages[i].shaderid |= 1i64 << 60;
 826+ if(texstages[i].surface->ddsd.dwFlags & DDSD_CKSRCBLT) texstages[i].shaderid |= 1i64 << 60;
827827 }
828828 }
829829 TRACE_EXIT(10,&shader);
@@ -1129,9 +1129,9 @@
11301130 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
11311131 if(!lplpTexture) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
11321132 if(dwStage > 7) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1133 - if(!texstages[dwStage].texture) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1134 - *lplpTexture = texstages[dwStage].texture;
1135 - texstages[dwStage].texture->AddRef();
 1133+ if(!texstages[dwStage].surface) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 1134+ *lplpTexture = texstages[dwStage].surface;
 1135+ texstages[dwStage].surface->AddRef();
11361136 TRACE_VAR("*lplpTexture",14,*lplpTexture);
11371137 TRACE_EXIT(23,D3D_OK);
11381138 return D3D_OK;
@@ -1460,9 +1460,9 @@
14611461 SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
14621462 SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
14631463 SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
1464 - if (!texstages[0].texture) noalpha = TRUE;
1465 - if (texstages[0].texture)
1466 - if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1464+ if (!texstages[0].surface) noalpha = TRUE;
 1465+ if (texstages[0].surface)
 1466+ if (!(texstages[0].surface->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
14671467 noalpha = TRUE;
14681468 if (noalpha) SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
14691469 else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
@@ -1532,16 +1532,17 @@
15331533 TRACE_ENTER(3,14,this,8,dwStage,14,lpTexture);
15341534 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
15351535 if(dwStage > 7) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1536 - if(texstages[dwStage].texture) texstages[dwStage].texture->Release();
1537 - texstages[dwStage].texture = (glDirectDrawSurface7*)lpTexture;
 1536+ if(texstages[dwStage].surface) texstages[dwStage].surface->Release();
 1537+ texstages[dwStage].surface = (glDirectDrawSurface7*)lpTexture;
15381538 if(lpTexture) lpTexture->AddRef();
1539 - glRenderer_SetTexture(renderer, dwStage, texstages[dwStage].texture);
 1539+ if(texstages[dwStage].surface) glRenderer_SetTexture(renderer, dwStage, texstages[dwStage].surface->texture);
 1540+ else glRenderer_SetTexture(renderer, dwStage, NULL);
15401541 if (renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
15411542 {
15421543 bool noalpha = false;
1543 - if (!texstages[0].texture) noalpha = true;
1544 - if (texstages[0].texture)
1545 - if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1544+ if (!texstages[0].surface) noalpha = true;
 1545+ if (texstages[0].surface)
 1546+ if (!(texstages[0].surface->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
15461547 noalpha = true;
15471548 if (noalpha) SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
15481549 else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
Index: ddraw/glDirect3DDevice.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2015 William Feely
 3+// Copyright (C) 2011-2016 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/glRenderer.cpp
@@ -696,9 +696,9 @@
697697 * @param dwStage
698698 * Texture stage to bind
699699 * @param Texture
700 - * Texture to bind to the stage; old texture will be released; NULL to unbind
 700+ * Texture to bind to the stage; NULL to unbind
701701 */
702 -void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
 702+void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glTexture *Texture)
703703 {
704704 EnterCriticalSection(&This->cs);
705705 This->inputs[0] = (void*)dwStage;
@@ -990,7 +990,7 @@
991991 glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)(DWORD)This->inputs[0], (DWORD)This->inputs[1]);
992992 break;
993993 case OP_SETTEXTURE:
994 - glRenderer__SetTexture(This, (DWORD)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1]);
 994+ glRenderer__SetTexture(This, (DWORD)This->inputs[0], (glTexture*)This->inputs[1]);
995995 break;
996996 case OP_SETTEXTURESTAGESTATE:
997997 glRenderer__SetTextureStageState(This, (DWORD)This->inputs[0], (D3DTEXTURESTAGESTATETYPE)(DWORD)This->inputs[1],
@@ -1871,7 +1871,7 @@
18721872 bool noalpha = false;;
18731873 if (!texstages[0].texture) noalpha = true;
18741874 if (texstages[0].texture)
1875 - if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1875+ if (!(texstages[0].texture->levels[0].ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
18761876 noalpha = true;
18771877 if (noalpha) texstages[0].alphaop = D3DTOP_SELECTARG2;
18781878 else texstages[0].alphaop = D3DTOP_MODULATE;
@@ -1906,7 +1906,7 @@
19071907 if (texstages[i].texture)
19081908 {
19091909 renderer->shaderstate3d.texstageid[i] |= 1i64 << 59;
1910 - if (texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT) renderer->shaderstate3d.texstageid[i] |= 1i64 << 60;
 1910+ if (texstages[i].texture->levels[0].ddsd.dwFlags & DDSD_CKSRCBLT) renderer->shaderstate3d.texstageid[i] |= 1i64 << 60;
19111911 }
19121912 }
19131913 return shader;
@@ -2352,13 +2352,13 @@
23532353 if(This->texstages[i].colorop == D3DTOP_DISABLE) break;
23542354 if(This->texstages[i].texture)
23552355 {
2356 - if(This->texstages[i].texture->texture->levels[0].dirty & 1)
 2356+ if(This->texstages[i].texture->levels[0].dirty & 1)
23572357 {
2358 - glTexture__Upload(This->texstages[i].texture->texture, 0);
 2358+ glTexture__Upload(This->texstages[i].texture, 0);
23592359 }
23602360 if (This->texstages[i].texture)
2361 - glTexture__SetFilter(This->texstages[i].texture->texture, i, This->texstages[i].glmagfilter, This->texstages[i].glminfilter, This);
2362 - glUtil_SetTexture(This->util,i,This->texstages[i].texture->texture);
 2361+ glTexture__SetFilter(This->texstages[i].texture, i, This->texstages[i].glmagfilter, This->texstages[i].glminfilter, This);
 2362+ glUtil_SetTexture(This->util,i,This->texstages[i].texture);
23632363 glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu);
23642364 glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv);
23652365 }
@@ -2366,15 +2366,15 @@
23672367 This->ext->glUniform1i(prog->uniforms[128+i],i);
23682368 if(This->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && This->texstages[i].texture && (prog->uniforms[142+i] != -1))
23692369 {
2370 - if(This->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
 2370+ if(This->texstages[i].texture->levels[0].ddsd.dwFlags & DDSD_CKSRCBLT)
23712371 {
2372 - SetColorKeyUniform(This->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,
2373 - This->texstages[i].texture->texture->colorsizes, This->texstages[i].texture->texture->colororder,
2374 - prog->uniforms[142 + i], This->texstages[i].texture->texture->colorbits, This->ext);
2375 - This->ext->glUniform4i(prog->uniforms[153+i], This->texstages[i].texture->texture->colorsizes[0],
2376 - This->texstages[i].texture->texture->colorsizes[1],
2377 - This->texstages[i].texture->texture->colorsizes[2],
2378 - This->texstages[i].texture->texture->colorsizes[3]);
 2372+ SetColorKeyUniform(This->texstages[i].texture->levels[0].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue,
 2373+ This->texstages[i].texture->colorsizes, This->texstages[i].texture->colororder,
 2374+ prog->uniforms[142 + i], This->texstages[i].texture->colorbits, This->ext);
 2375+ This->ext->glUniform4i(prog->uniforms[153+i], This->texstages[i].texture->colorsizes[0],
 2376+ This->texstages[i].texture->colorsizes[1],
 2377+ This->texstages[i].texture->colorsizes[2],
 2378+ This->texstages[i].texture->colorsizes[3]);
23792379 }
23802380 }
23812381 }
@@ -2623,8 +2623,21 @@
26242624 }
26252625 }
26262626
2627 -void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
 2627+void glRenderer__RemoveTextureFromD3D(glRenderer *This, glTexture *texture)
26282628 {
 2629+ int i;
 2630+ for (i = 0; i < 8; i++)
 2631+ {
 2632+ if (This->texstages[i].texture == texture)
 2633+ {
 2634+ This->texstages[i].texture = NULL;
 2635+ This->shaderstate3d.texstageid[i] &= 0xE7FFFFFFFFFFFFFFi64;
 2636+ }
 2637+ }
 2638+}
 2639+
 2640+void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glTexture *Texture)
 2641+{
26292642 if (This->texstages[dwStage].texture == Texture)
26302643 {
26312644 SetEvent(This->busy);
@@ -2634,7 +2647,7 @@
26352648 if (Texture)
26362649 {
26372650 This->shaderstate3d.texstageid[dwStage] |= 1i64 << 59;
2638 - if (Texture->ddsd.dwFlags & DDSD_CKSRCBLT) This->shaderstate3d.texstageid[dwStage] |= 1i64 << 60;
 2651+ if (Texture->levels[0].ddsd.dwFlags & DDSD_CKSRCBLT) This->shaderstate3d.texstageid[dwStage] |= 1i64 << 60;
26392652 else This->shaderstate3d.texstageid[dwStage] &= 0xEFFFFFFFFFFFFFFFi64;
26402653 }
26412654 else This->shaderstate3d.texstageid[dwStage] &= 0xE7FFFFFFFFFFFFFFi64;
Index: ddraw/glRenderer.h
@@ -75,7 +75,10 @@
7676 D3DVALUE bumpenvlscale;
7777 D3DVALUE bumpenvloffset;
7878 D3DTEXTURETRANSFORMFLAGS textransform;
79 - glDirectDrawSurface7 *texture;
 79+ union {
 80+ glTexture *texture;
 81+ glDirectDrawSurface7 *surface;
 82+ } DUMMYUNIONNAME1;
8083 GLint glmagfilter;
8184 GLint glminfilter;
8285 } TEXTURESTAGE;
@@ -177,7 +180,7 @@
178181 unsigned int glRenderer_GetScanLine(glRenderer *This);
179182 HRESULT glRenderer_DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel);
180183 void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
181 -void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
 184+void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glTexture *Texture);
182185 void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
183186 void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
184187 void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
@@ -214,7 +217,8 @@
215218 void glRenderer__SetSwap(glRenderer *This, int swap);
216219 void glRenderer__SetBlend(glRenderer *This, DWORD src, DWORD dest);
217220 void glRenderer__SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
218 -void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
 221+void glRenderer__RemoveTextureFromD3D(glRenderer *This, glTexture *texture);
 222+void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glTexture *Texture);
219223 void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
220224 void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
221225 void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
Index: ddraw/glTexture.cpp
@@ -1050,6 +1050,7 @@
10511051 }
10521052 void glTexture__Destroy(glTexture *This)
10531053 {
 1054+ glRenderer__RemoveTextureFromD3D(This->renderer, This);
10541055 glDeleteTextures(1, &This->id);
10551056 free(This);
10561057 }