Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -146,6 +146,7 @@ |
147 | 147 | lights = (glDirect3DLight**) malloc(16*sizeof(glDirect3DLight*));
|
148 | 148 | ZeroMemory(lights,16*sizeof(glDirect3DLight*));
|
149 | 149 | memset(gllights,0xff,8*sizeof(int));
|
| 150 | + memset(gltextures,0,8*sizeof(GLuint));
|
150 | 151 | glD3D7->glDD7->renderer->InitD3D(zbuffer);
|
151 | 152 | }
|
152 | 153 | glDirect3DDevice7::~glDirect3DDevice7()
|
— | — | @@ -268,6 +269,62 @@ |
269 | 270 | else if(size > maxarray) normals = (GLfloat*)realloc(normals,size*4*sizeof(GLfloat));
|
270 | 271 | }
|
271 | 272 |
|
| 273 | +__int64 glDirect3DDevice7::SelectShader(DWORD VertexType)
|
| 274 | +{
|
| 275 | + int i;
|
| 276 | + __int64 shader = 0;
|
| 277 | + switch(renderstate[D3DRENDERSTATE_SHADEMODE])
|
| 278 | + {
|
| 279 | + case D3DSHADE_FLAT:
|
| 280 | + default:
|
| 281 | + break;
|
| 282 | + case D3DSHADE_GOURAUD:
|
| 283 | + shader |= 1;
|
| 284 | + break;
|
| 285 | + case D3DSHADE_PHONG:
|
| 286 | + shader |= 3;
|
| 287 | + break;
|
| 288 | + }
|
| 289 | + if(renderstate[D3DRENDERSTATE_ALPHATESTENABLE]) shader |= 4;
|
| 290 | + shader |= (((renderstate[D3DRENDERSTATE_ALPHAFUNC]-1) & 7) << 3);
|
| 291 | + shader |= ((renderstate[D3DRENDERSTATE_FOGTABLEMODE] & 3) << 6);
|
| 292 | + shader |= ((renderstate[D3DRENDERSTATE_FOGVERTEXMODE] & 3) << 8);
|
| 293 | + if(renderstate[D3DRENDERSTATE_RANGEFOGENABLE]) shader |= (1 << 10);
|
| 294 | + if(renderstate[D3DRENDERSTATE_SPECULARENABLE]) shader |= (1 << 11);
|
| 295 | + if(renderstate[D3DRENDERSTATE_STIPPLEDALPHA]) shader |= (1 << 12);
|
| 296 | + if(renderstate[D3DRENDERSTATE_COLORKEYENABLE]) shader |= (1 << 13);
|
| 297 | + shader |= ((renderstate[D3DRENDERSTATE_ZBIAS] & 15) << 14);
|
| 298 | + int numlights = 0;
|
| 299 | + for(i = 0; i < 8; i++)
|
| 300 | + if(gllights[i] != -1) numlights++;
|
| 301 | + shader |= numlights << 18;
|
| 302 | + if(renderstate[D3DRENDERSTATE_LOCALVIEWER]) shader |= (1 << 21);
|
| 303 | + if(renderstate[D3DRENDERSTATE_COLORKEYBLENDENABLE]) shader |= (1 << 22);
|
| 304 | + shader |= ((renderstate[D3DRENDERSTATE_DIFFUSEMATERIALSOURCE] & 3) << 23);
|
| 305 | + shader |= ((renderstate[D3DRENDERSTATE_SPECULARMATERIALSOURCE] & 3) << 25);
|
| 306 | + shader |= ((renderstate[D3DRENDERSTATE_AMBIENTMATERIALSOURCE] & 3) << 27);
|
| 307 | + shader |= ((renderstate[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE] & 3) << 29);
|
| 308 | + int numtextures = (VertexType & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
|
| 309 | + shader |= (__int64)numtextures << 31;
|
| 310 | + if(VertexType & D3DFVF_XYZRHW) shader |= (1i64 << 34);
|
| 311 | + if((VertexType & D3DFVF_DIFFUSE) && (VertexType & D3DFVF_SPECULAR)) shader |= (1i64<<35);
|
| 312 | + for(i = 0; i < numtextures; i++)
|
| 313 | + shader |= (__int64)((VertexType >> (16+(2*i))) & 3) << (36 + (2*i));
|
| 314 | + if(VertexType & D3DFVF_NORMAL) shader |= (1i64 << 52);
|
| 315 | + int lightindex = 0;
|
| 316 | + for(i = 0; i < 8; i++)
|
| 317 | + {
|
| 318 | + if(gllights[i] != -1)
|
| 319 | + {
|
| 320 | + if(lights[gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
|
| 321 | + shader |= (1i64 << (53+lightindex));
|
| 322 | + lightindex++;
|
| 323 | + }
|
| 324 | + }
|
| 325 | + if(((VertexType >> 1) & 7) >= 3) shader |= (__int64)(((VertexType >> 1) & 7) - 2) << 61;
|
| 326 | + return shader;
|
| 327 | +}
|
| 328 | +
|
272 | 329 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
273 | 330 | LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
274 | 331 | {
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -88,6 +88,7 @@ |
89 | 89 | void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
|
90 | 90 |
|
91 | 91 | private:
|
| 92 | + __int64 SelectShader(DWORD VertexType);
|
92 | 93 | D3DMATRIX matWorld,matView,matProjection;
|
93 | 94 | glDirect3D7 *glD3D7;
|
94 | 95 | glDirectDrawSurface7 *glDDS7;
|
— | — | @@ -97,6 +98,7 @@ |
98 | 99 | D3DMATERIAL7 material;
|
99 | 100 | glDirect3DLight **lights;
|
100 | 101 | int gllights[8];
|
| 102 | + GLuint gltextures[8];
|
101 | 103 | DWORD lightsmax;
|
102 | 104 | bool inscene;
|
103 | 105 | DWORD maxarray;
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -592,7 +592,7 @@ |
593 | 593 | glClear(GL_DEPTH_BUFFER_BIT);
|
594 | 594 | if(dwFlags & DDBLT_COLORFILL)
|
595 | 595 | {
|
596 | | - SetShader(PROG_FILL,1);
|
| 596 | + SetShader(PROG_FILL,NULL,true);
|
597 | 597 | glDisable(GL_TEXTURE_2D);
|
598 | 598 | glDisable(GL_ALPHA_TEST);
|
599 | 599 | switch(ddInterface->GetBPP())
|
— | — | @@ -638,7 +638,7 @@ |
639 | 639 | if(src) glBindTexture(GL_TEXTURE_2D,src->GetTexture());
|
640 | 640 | if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
|
641 | 641 | {
|
642 | | - SetShader(PROG_CKEY,1);
|
| 642 | + SetShader(PROG_CKEY,NULL,true);
|
643 | 643 | GLint keyloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"keyIn");
|
644 | 644 | switch(ddInterface->GetBPP())
|
645 | 645 | {
|
— | — | @@ -669,7 +669,7 @@ |
670 | 670 | }
|
671 | 671 | else if(!(dwFlags & DDBLT_COLORFILL))
|
672 | 672 | {
|
673 | | - SetShader(PROG_TEXTURE,1);
|
| 673 | + SetShader(PROG_TEXTURE,NULL,true);
|
674 | 674 | GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
|
675 | 675 | glUniform1i(texloc,0);
|
676 | 676 | }
|
— | — | @@ -820,7 +820,7 @@ |
821 | 821 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
822 | 822 | if(ddInterface->GetBPP() == 8)
|
823 | 823 | {
|
824 | | - SetShader(PROG_PAL256,true);
|
| 824 | + SetShader(PROG_PAL256,NULL,true);
|
825 | 825 | glBindTexture(GL_TEXTURE_2D,paltex);
|
826 | 826 | glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,1,0,GL_RGBA,GL_UNSIGNED_BYTE,dest->palette->GetPalette(NULL));
|
827 | 827 | GLint palloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"ColorTable");
|
— | — | @@ -835,7 +835,7 @@ |
836 | 836 | if(dxglcfg.scalingfilter)
|
837 | 837 | {
|
838 | 838 | _DrawBackbuffer(&texture,dest->fakex,dest->fakey);
|
839 | | - SetShader(PROG_TEXTURE,true);
|
| 839 | + SetShader(PROG_TEXTURE,NULL,true);
|
840 | 840 | glEnable(GL_TEXTURE_2D);
|
841 | 841 | glBindTexture(GL_TEXTURE_2D,texture);
|
842 | 842 | GLuint prog = GetProgram() & 0xFFFFFFFF;
|
— | — | @@ -845,7 +845,7 @@ |
846 | 846 | }
|
847 | 847 | else
|
848 | 848 | {
|
849 | | - SetShader(PROG_TEXTURE,true);
|
| 849 | + SetShader(PROG_TEXTURE,NULL,true);
|
850 | 850 | glEnable(GL_TEXTURE_2D);
|
851 | 851 | glBindTexture(GL_TEXTURE_2D,texture);
|
852 | 852 | GLuint prog = GetProgram() & 0xFFFFFFFF;
|
Index: ddraw/shadergen.cpp |
— | — | @@ -55,21 +55,27 @@ |
56 | 56 | Bit 11 - Specular highlights
|
57 | 57 | Bit 12 - Stippled alpha
|
58 | 58 | Bit 13 - Color key transparency
|
59 | | -Bit 14 - Enable Z bias
|
60 | | -Bits 15-17 - Number of lights
|
61 | | -Bit 18 - Camera relative specular highlights
|
62 | | -Bit 19 - Alpha blended color key
|
63 | | -Bits 20-21 - Diffuse material source
|
64 | | -Bits 22-23 - Specular material source
|
65 | | -Bits 24-25 - Ambient material source
|
66 | | -Bits 26-27 - Emissive material source
|
67 | | -Bits 28-30 - Number of textures
|
68 | | -Bit 31 - RGB or RGBA color
|
69 | | -Bits 32-33 - Vertex format
|
70 | | -Bits 34-49 - Texture coordinate format
|
71 | | -Bit 50 - Enable normals
|
72 | | -Bits 51-58 - Light types
|
| 59 | +Bit 14-17 - Z bias
|
| 60 | +Bits 18-20 - Number of lights
|
| 61 | +Bit 21 - Camera relative specular highlights
|
| 62 | +Bit 22 - Alpha blended color key
|
| 63 | +Bits 23-24 - Diffuse material source
|
| 64 | +Bits 25-26 - Specular material source
|
| 65 | +Bits 27-28 - Ambient material source
|
| 66 | +Bits 29-30 - Emissive material source
|
| 67 | +Bits 31-33 - Number of textures
|
| 68 | +Bit 34 - Use transformed vertices
|
| 69 | +Bit 35 - Use secondary color
|
| 70 | +Bits 36-51 - Texture coordinate format:
|
| 71 | +00=2dim 01=3dim 10=4dim 11=1dim
|
| 72 | +Bit 52 - Enable normals
|
| 73 | +Bits 53-60 - Light types
|
| 74 | +Bits 61-63 - Number of blending weights
|
73 | 75 | */
|
| 76 | +
|
| 77 | +/* Bits in Texture Stage ID:
|
| 78 | +
|
| 79 | +*/
|
74 | 80 | void ZeroShaderArray()
|
75 | 81 | {
|
76 | 82 | ZeroMemory(genshaders,256*sizeof(GenShader));
|
— | — | @@ -77,7 +83,7 @@ |
78 | 84 | isbuiltin = true;
|
79 | 85 | }
|
80 | 86 |
|
81 | | -void SetShader(__int64 id, bool builtin)
|
| 87 | +void SetShader(__int64 id, TexState *texstate, bool builtin)
|
82 | 88 | {
|
83 | 89 | int shaderindex = -1;
|
84 | 90 | if(builtin)
|
Index: ddraw/shadergen.h |
— | — | @@ -18,8 +18,19 @@ |
19 | 19 | #ifndef _SHADERGEN_H
|
20 | 20 | #define _SHADERGEN_H
|
21 | 21 |
|
| 22 | +typedef struct
|
| 23 | +{
|
| 24 | + __int64 TEX0;
|
| 25 | + __int64 TEX1;
|
| 26 | + __int64 TEX2;
|
| 27 | + __int64 TEX3;
|
| 28 | + __int64 TEX4;
|
| 29 | + __int64 TEX5;
|
| 30 | + __int64 TEX6;
|
| 31 | + __int64 TEX7;
|
| 32 | +} TexState;
|
22 | 33 |
|
23 | | -void SetShader(__int64 id, bool builtin);
|
| 34 | +void SetShader(__int64 id, TexState *texstate, bool builtin);
|
24 | 35 | GLuint GetProgram();
|
25 | 36 | void ZeroShaderArray();
|
26 | 37 | void CreateShader(int index, __int64 id);
|