Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -389,6 +389,29 @@ |
390 | 390 | if(VertexType[i+2].data) blendweights++;
|
391 | 391 | shader |= (__int64)blendweights << 46;
|
392 | 392 | //TODO: Implement texture stages.
|
| 393 | + for(i = 0; i < 8; i++)
|
| 394 | + {
|
| 395 | + if(!texstages[i].dirty) continue;
|
| 396 | + texstages[i].shaderid = texstages[i].colorop & 31;
|
| 397 | + texstages[i].shaderid |= (texstages[i].colorarg1 & 63) << 5;
|
| 398 | + texstages[i].shaderid |= (texstages[i].colorarg2 & 63) << 11;
|
| 399 | + texstages[i].shaderid |= (texstages[i].alphaop & 31) << 17;
|
| 400 | + texstages[i].shaderid |= (texstages[i].alphaarg1 & 63) << 22;
|
| 401 | + texstages[i].shaderid |= (__int64)(texstages[i].alphaarg2 & 63) << 28;
|
| 402 | + texstages[i].shaderid |= (__int64)(texstages[i].texcoordindex & 7) << 34;
|
| 403 | + texstages[i].shaderid |= (__int64)((texstages[i].texcoordindex >> 16) & 3) << 37;
|
| 404 | + texstages[i].shaderid |= (__int64)((texstages[i].addressu - 1) & 3) << 39;
|
| 405 | + texstages[i].shaderid |= (__int64)((texstages[i].addressv - 1) & 3) << 41;
|
| 406 | + texstages[i].shaderid |= (__int64)(texstages[i].magfilter & 7) << 43;
|
| 407 | + texstages[i].shaderid |= (__int64)(texstages[i].minfilter & 3) << 46;
|
| 408 | + texstages[i].shaderid |= (__int64)(texstages[i].mipfilter & 3) << 48;
|
| 409 | + if(texstages[i].textransform & 7)
|
| 410 | + {
|
| 411 | + texstages[i].shaderid |= 1i64 << 50;
|
| 412 | + texstages[i].shaderid |= (__int64)(((texstages[i].textransform & 7) - 1)& 3) << 51;
|
| 413 | + }
|
| 414 | + if(texstages[i].textransform & D3DTTFF_PROJECTED) texstages[i].shaderid |= 1i64 << 53;
|
| 415 | + }
|
393 | 416 | return shader;
|
394 | 417 | }
|
395 | 418 |
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -19,6 +19,9 @@ |
20 | 20 | #ifndef __GLDIRECT3DDEVICE_H
|
21 | 21 | #define __GLDIRECT3DDEVICE_H
|
22 | 22 |
|
| 23 | +class glDirectDrawSurface7;
|
| 24 | +class glDirect3D7;
|
| 25 | +
|
23 | 26 | struct TEXTURESTAGE
|
24 | 27 | {
|
25 | 28 | D3DTEXTUREOP colorop;
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -17,14 +17,16 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "scalers.h"
|
21 | | -#include "shaders.h"
|
22 | | -#include "shadergen.h"
|
23 | 21 | #include "ddraw.h"
|
| 22 | +#include "glRenderer.h"
|
| 23 | +#include "glDirect3DDevice.h"
|
24 | 24 | #include "glDirectDraw.h"
|
25 | 25 | #include "glDirectDrawSurface.h"
|
26 | 26 | #include "glDirectDrawPalette.h"
|
27 | 27 | #include "glDirectDrawClipper.h"
|
28 | 28 | #include "glRenderer.h"
|
| 29 | +#include "shadergen.h"
|
| 30 | +#include "shaders.h"
|
29 | 31 | #include "glutil.h"
|
30 | 32 |
|
31 | 33 |
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -624,7 +624,7 @@ |
625 | 625 | if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
|
626 | 626 | if(dwFlags & DDBLT_COLORFILL)
|
627 | 627 | {
|
628 | | - SetShader(PROG_FILL,NULL,true);
|
| 628 | + SetShader(PROG_FILL,NULL,NULL,true);
|
629 | 629 | glDisable(GL_TEXTURE_2D);
|
630 | 630 | glDisable(GL_ALPHA_TEST);
|
631 | 631 | switch(ddInterface->GetBPP())
|
— | — | @@ -669,7 +669,7 @@ |
670 | 670 | }
|
671 | 671 | if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
|
672 | 672 | {
|
673 | | - SetShader(PROG_CKEY,NULL,true);
|
| 673 | + SetShader(PROG_CKEY,NULL,NULL,true);
|
674 | 674 | GLint keyloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"keyIn");
|
675 | 675 | switch(ddInterface->GetBPP())
|
676 | 676 | {
|
— | — | @@ -700,7 +700,7 @@ |
701 | 701 | }
|
702 | 702 | else if(!(dwFlags & DDBLT_COLORFILL))
|
703 | 703 | {
|
704 | | - SetShader(PROG_TEXTURE,NULL,true);
|
| 704 | + SetShader(PROG_TEXTURE,NULL,NULL,true);
|
705 | 705 | GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
|
706 | 706 | glUniform1i(texloc,0);
|
707 | 707 | }
|
— | — | @@ -853,7 +853,7 @@ |
854 | 854 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
855 | 855 | if(ddInterface->GetBPP() == 8)
|
856 | 856 | {
|
857 | | - SetShader(PROG_PAL256,NULL,true);
|
| 857 | + SetShader(PROG_PAL256,NULL,NULL,true);
|
858 | 858 | glBindTexture(GL_TEXTURE_2D,paltex);
|
859 | 859 | glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,1,0,GL_RGBA,GL_UNSIGNED_BYTE,dest->palette->GetPalette(NULL));
|
860 | 860 | GLint palloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"ColorTable");
|
— | — | @@ -868,7 +868,7 @@ |
869 | 869 | if(dxglcfg.scalingfilter)
|
870 | 870 | {
|
871 | 871 | _DrawBackbuffer(&texture,dest->fakex,dest->fakey);
|
872 | | - SetShader(PROG_TEXTURE,NULL,true);
|
| 872 | + SetShader(PROG_TEXTURE,NULL,NULL,true);
|
873 | 873 | glEnable(GL_TEXTURE_2D);
|
874 | 874 | glBindTexture(GL_TEXTURE_2D,texture);
|
875 | 875 | GLuint prog = GetProgram() & 0xFFFFFFFF;
|
— | — | @@ -878,7 +878,7 @@ |
879 | 879 | }
|
880 | 880 | else
|
881 | 881 | {
|
882 | | - SetShader(PROG_TEXTURE,NULL,true);
|
| 882 | + SetShader(PROG_TEXTURE,NULL,NULL,true);
|
883 | 883 | glEnable(GL_TEXTURE_2D);
|
884 | 884 | glBindTexture(GL_TEXTURE_2D,texture);
|
885 | 885 | GLuint prog = GetProgram() & 0xFFFFFFFF;
|
— | — | @@ -1028,10 +1028,8 @@ |
1029 | 1029 | wndbusy = false;
|
1030 | 1030 | return;
|
1031 | 1031 | }
|
1032 | | - TexState texstage;
|
1033 | | - ZeroMemory(&texstage,sizeof(TexState));
|
1034 | 1032 | __int64 shader = device->SelectShader(vertices);
|
1035 | | - SetShader(shader,&texstage,0);
|
| 1033 | + SetShader(shader,device->texstages,texformats,0);
|
1036 | 1034 | GLuint prog = GetProgram();
|
1037 | 1035 | GLint xyzloc = glGetAttribLocation(prog,"xyz");
|
1038 | 1036 | glEnableVertexAttribArray(xyzloc);
|
Index: ddraw/shadergen.cpp |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #include "common.h"
|
| 20 | +#include "glRenderer.h"
|
| 21 | +#include "glDirect3DDevice.h"
|
20 | 22 | #include "shadergen.h"
|
21 | 23 | #include "shaders.h"
|
22 | 24 | #include <string>
|
— | — | @@ -79,19 +81,20 @@ |
80 | 82 | Bits 0-4: Texture color operation
|
81 | 83 | Bits 5-10: Texture color argument 1
|
82 | 84 | Bits 11-16: Texture color argument 2
|
83 | | -Bits 17-20: Texture alpha operation
|
84 | | -Bits 21-26: Texture alpha argument 1
|
85 | | -Bits 27-32: Texture alpha argument 2
|
86 | | -Bits 33-35: Texture coordinate index
|
87 | | -Bits 36-37: Texture coordinate flags
|
88 | | -Bits 38-39: U Texture address
|
89 | | -Bits 40-41: V Texture address
|
90 | | -Bits 42-44: Texture magnification filter
|
91 | | -Bits 45-46: Texture minification filter
|
92 | | -Bit 47: Enable texture coordinate transform
|
93 | | -Bits 48-49: Number of texcoord dimensions
|
94 | | -Bit 50: Projected texcoord
|
95 | | -Bits 51-52: Texture coordinate format:
|
| 85 | +Bits 17-21: Texture alpha operation
|
| 86 | +Bits 22-27: Texture alpha argument 1
|
| 87 | +Bits 28-33: Texture alpha argument 2
|
| 88 | +Bits 34-36: Texture coordinate index
|
| 89 | +Bits 37-38: Texture coordinate flags
|
| 90 | +Bits 39-40: U Texture address
|
| 91 | +Bits 41-42: V Texture address
|
| 92 | +Bits 43-45: Texture magnification filter
|
| 93 | +Bits 46-47: Texture minification filter
|
| 94 | +Bits 48-49: Texture mip filter
|
| 95 | +Bit 50: Enable texture coordinate transform
|
| 96 | +Bits 51-52: Number of texcoord dimensions
|
| 97 | +Bit 53: Projected texcoord
|
| 98 | +Bits in texcoord ID:
|
96 | 99 | 00=2dim 01=3dim 10=4dim 11=1dim
|
97 | 100 | */
|
98 | 101 | void ZeroShaderArray()
|
— | — | @@ -118,7 +121,7 @@ |
119 | 122 | genindex = 0;
|
120 | 123 | }
|
121 | 124 |
|
122 | | -void SetShader(__int64 id, TexState *texstate, bool builtin)
|
| 125 | +void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin)
|
123 | 126 | {
|
124 | 127 | int shaderindex = -1;
|
125 | 128 | if(builtin)
|
— | — | @@ -161,7 +164,7 @@ |
162 | 165 | delete genshaders[shaderindex].shader.fsrc;
|
163 | 166 | ZeroMemory(&genshaders[shaderindex],sizeof(GenShader));
|
164 | 167 | }
|
165 | | - CreateShader(genindex,id,texstate);
|
| 168 | + CreateShader(genindex,id,texstate,texcoords);
|
166 | 169 | shaderindex = genindex;
|
167 | 170 | genindex++;
|
168 | 171 | if(genindex == 256) genindex = 0;
|
— | — | @@ -233,6 +236,7 @@ |
234 | 237 | };\n";
|
235 | 238 | static const char unif_light[] = "uniform Light lightX;\n";
|
236 | 239 | static const char unif_ambient[] = "uniform vec4 ambientcolor;\n";
|
| 240 | +static const char unif_tex[] = "uniform sampler2d texX;\n";
|
237 | 241 | // Variables
|
238 | 242 | static const char var_colors[] = "vec4 diffuse;\n\
|
239 | 243 | vec4 specular;\n\
|
— | — | @@ -274,7 +278,7 @@ |
275 | 279 | }\n\
|
276 | 280 | }\n";
|
277 | 281 |
|
278 | | -void CreateShader(int index, __int64 id, TexState *texstate)
|
| 282 | +void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
|
279 | 283 | {
|
280 | 284 | string tmp;
|
281 | 285 | int i;
|
Index: ddraw/shadergen.h |
— | — | @@ -18,22 +18,10 @@ |
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;
|
33 | | -
|
34 | 22 | void ClearShaders();
|
35 | | -void SetShader(__int64 id, TexState *texstate, bool builtin);
|
| 23 | +void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin);
|
36 | 24 | GLuint GetProgram();
|
37 | 25 | void ZeroShaderArray();
|
38 | | -void CreateShader(int index, __int64 id, TexState *texstate);
|
| 26 | +void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
|
39 | 27 |
|
40 | 28 | #endif |
\ No newline at end of file |
Index: ddraw/shaders.cpp |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #include "common.h"
|
| 20 | +#include "glRenderer.h"
|
| 21 | +#include "glDirect3DDevice.h"
|
20 | 22 | #include "shaders.h"
|
21 | 23 | #include "shadergen.h"
|
22 | 24 |
|