Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011-2015 William Feely
|
| 3 | +// Copyright (C) 2011-2016 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -376,7 +376,7 @@ |
377 | 377 | if(lights[i]) delete lights[i];
|
378 | 378 | free(lights);
|
379 | 379 | 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();
|
381 | 381 | for(int i = 0; i < materialcount; i++)
|
382 | 382 | {
|
383 | 383 | if(materials[i])
|
— | — | @@ -784,9 +784,9 @@ |
785 | 785 | if(renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
|
786 | 786 | {
|
787 | 787 | 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))
|
791 | 791 | noalpha = true;
|
792 | 792 | if(noalpha) texstages[0].alphaop = D3DTOP_SELECTARG2;
|
793 | 793 | else texstages[0].alphaop = D3DTOP_MODULATE;
|
— | — | @@ -819,10 +819,10 @@ |
820 | 820 | if(texstages[i].textransform & D3DTTFF_PROJECTED) texstages[i].shaderid |= 1i64 << 53;
|
821 | 821 | texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex&7) << 54;
|
822 | 822 | texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex>>16)&3) << 57;
|
823 | | - if(texstages[i].texture)
|
| 823 | + if(texstages[i].surface)
|
824 | 824 | {
|
825 | 825 | 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;
|
827 | 827 | }
|
828 | 828 | }
|
829 | 829 | TRACE_EXIT(10,&shader);
|
— | — | @@ -1129,9 +1129,9 @@ |
1130 | 1130 | if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
|
1131 | 1131 | if(!lplpTexture) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
|
1132 | 1132 | 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();
|
1136 | 1136 | TRACE_VAR("*lplpTexture",14,*lplpTexture);
|
1137 | 1137 | TRACE_EXIT(23,D3D_OK);
|
1138 | 1138 | return D3D_OK;
|
— | — | @@ -1460,9 +1460,9 @@ |
1461 | 1461 | SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
|
1462 | 1462 | SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
|
1463 | 1463 | 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))
|
1467 | 1467 | noalpha = TRUE;
|
1468 | 1468 | if (noalpha) SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
|
1469 | 1469 | else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
— | — | @@ -1532,16 +1532,17 @@ |
1533 | 1533 | TRACE_ENTER(3,14,this,8,dwStage,14,lpTexture);
|
1534 | 1534 | if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
|
1535 | 1535 | 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;
|
1538 | 1538 | 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);
|
1540 | 1541 | if (renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
|
1541 | 1542 | {
|
1542 | 1543 | 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))
|
1546 | 1547 | noalpha = true;
|
1547 | 1548 | if (noalpha) SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
|
1548 | 1549 | else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011-2015 William Feely
|
| 3 | +// Copyright (C) 2011-2016 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -696,9 +696,9 @@ |
697 | 697 | * @param dwStage
|
698 | 698 | * Texture stage to bind
|
699 | 699 | * @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
|
701 | 701 | */
|
702 | | -void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
|
| 702 | +void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glTexture *Texture)
|
703 | 703 | {
|
704 | 704 | EnterCriticalSection(&This->cs);
|
705 | 705 | This->inputs[0] = (void*)dwStage;
|
— | — | @@ -990,7 +990,7 @@ |
991 | 991 | glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)(DWORD)This->inputs[0], (DWORD)This->inputs[1]);
|
992 | 992 | break;
|
993 | 993 | 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]);
|
995 | 995 | break;
|
996 | 996 | case OP_SETTEXTURESTAGESTATE:
|
997 | 997 | glRenderer__SetTextureStageState(This, (DWORD)This->inputs[0], (D3DTEXTURESTAGESTATETYPE)(DWORD)This->inputs[1],
|
— | — | @@ -1871,7 +1871,7 @@ |
1872 | 1872 | bool noalpha = false;;
|
1873 | 1873 | if (!texstages[0].texture) noalpha = true;
|
1874 | 1874 | 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))
|
1876 | 1876 | noalpha = true;
|
1877 | 1877 | if (noalpha) texstages[0].alphaop = D3DTOP_SELECTARG2;
|
1878 | 1878 | else texstages[0].alphaop = D3DTOP_MODULATE;
|
— | — | @@ -1906,7 +1906,7 @@ |
1907 | 1907 | if (texstages[i].texture)
|
1908 | 1908 | {
|
1909 | 1909 | 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;
|
1911 | 1911 | }
|
1912 | 1912 | }
|
1913 | 1913 | return shader;
|
— | — | @@ -2352,13 +2352,13 @@ |
2353 | 2353 | if(This->texstages[i].colorop == D3DTOP_DISABLE) break;
|
2354 | 2354 | if(This->texstages[i].texture)
|
2355 | 2355 | {
|
2356 | | - if(This->texstages[i].texture->texture->levels[0].dirty & 1)
|
| 2356 | + if(This->texstages[i].texture->levels[0].dirty & 1)
|
2357 | 2357 | {
|
2358 | | - glTexture__Upload(This->texstages[i].texture->texture, 0);
|
| 2358 | + glTexture__Upload(This->texstages[i].texture, 0);
|
2359 | 2359 | }
|
2360 | 2360 | 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);
|
2363 | 2363 | glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu);
|
2364 | 2364 | glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv);
|
2365 | 2365 | }
|
— | — | @@ -2366,15 +2366,15 @@ |
2367 | 2367 | This->ext->glUniform1i(prog->uniforms[128+i],i);
|
2368 | 2368 | if(This->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && This->texstages[i].texture && (prog->uniforms[142+i] != -1))
|
2369 | 2369 | {
|
2370 | | - if(This->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
|
| 2370 | + if(This->texstages[i].texture->levels[0].ddsd.dwFlags & DDSD_CKSRCBLT)
|
2371 | 2371 | {
|
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]);
|
2379 | 2379 | }
|
2380 | 2380 | }
|
2381 | 2381 | }
|
— | — | @@ -2623,8 +2623,21 @@ |
2624 | 2624 | }
|
2625 | 2625 | }
|
2626 | 2626 |
|
2627 | | -void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
|
| 2627 | +void glRenderer__RemoveTextureFromD3D(glRenderer *This, glTexture *texture)
|
2628 | 2628 | {
|
| 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 | +{
|
2629 | 2642 | if (This->texstages[dwStage].texture == Texture)
|
2630 | 2643 | {
|
2631 | 2644 | SetEvent(This->busy);
|
— | — | @@ -2634,7 +2647,7 @@ |
2635 | 2648 | if (Texture)
|
2636 | 2649 | {
|
2637 | 2650 | 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;
|
2639 | 2652 | else This->shaderstate3d.texstageid[dwStage] &= 0xEFFFFFFFFFFFFFFFi64;
|
2640 | 2653 | }
|
2641 | 2654 | else This->shaderstate3d.texstageid[dwStage] &= 0xE7FFFFFFFFFFFFFFi64;
|
Index: ddraw/glRenderer.h |
— | — | @@ -75,7 +75,10 @@ |
76 | 76 | D3DVALUE bumpenvlscale;
|
77 | 77 | D3DVALUE bumpenvloffset;
|
78 | 78 | D3DTEXTURETRANSFORMFLAGS textransform;
|
79 | | - glDirectDrawSurface7 *texture;
|
| 79 | + union {
|
| 80 | + glTexture *texture;
|
| 81 | + glDirectDrawSurface7 *surface;
|
| 82 | + } DUMMYUNIONNAME1;
|
80 | 83 | GLint glmagfilter;
|
81 | 84 | GLint glminfilter;
|
82 | 85 | } TEXTURESTAGE;
|
— | — | @@ -177,7 +180,7 @@ |
178 | 181 | unsigned int glRenderer_GetScanLine(glRenderer *This);
|
179 | 182 | HRESULT glRenderer_DepthFill(glRenderer *This, BltCommand *cmd, glTexture *parent, GLint parentlevel);
|
180 | 183 | 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);
|
182 | 185 | void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
|
183 | 186 | void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
|
184 | 187 | void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
|
— | — | @@ -214,7 +217,8 @@ |
215 | 218 | void glRenderer__SetSwap(glRenderer *This, int swap);
|
216 | 219 | void glRenderer__SetBlend(glRenderer *This, DWORD src, DWORD dest);
|
217 | 220 | 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);
|
219 | 223 | void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
|
220 | 224 | void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
|
221 | 225 | void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
|
Index: ddraw/glTexture.cpp |
— | — | @@ -1050,6 +1050,7 @@ |
1051 | 1051 | }
|
1052 | 1052 | void glTexture__Destroy(glTexture *This)
|
1053 | 1053 | {
|
| 1054 | + glRenderer__RemoveTextureFromD3D(This->renderer, This);
|
1054 | 1055 | glDeleteTextures(1, &This->id);
|
1055 | 1056 | free(This);
|
1056 | 1057 | }
|