DXGL r124 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r123‎ | r124 | r125 >
Date:01:20, 13 March 2012
Author:admin
Status:new
Tags:
Comment:
Generate Texture Stage shader IDs.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)
  • /ddraw/shadergen.h (modified) (history)
  • /ddraw/shaders.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -389,6 +389,29 @@
390390 if(VertexType[i+2].data) blendweights++;
391391 shader |= (__int64)blendweights << 46;
392392 //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+ }
393416 return shader;
394417 }
395418
Index: ddraw/glDirect3DDevice.h
@@ -19,6 +19,9 @@
2020 #ifndef __GLDIRECT3DDEVICE_H
2121 #define __GLDIRECT3DDEVICE_H
2222
 23+class glDirectDrawSurface7;
 24+class glDirect3D7;
 25+
2326 struct TEXTURESTAGE
2427 {
2528 D3DTEXTUREOP colorop;
Index: ddraw/glDirectDrawSurface.cpp
@@ -17,14 +17,16 @@
1818
1919 #include "common.h"
2020 #include "scalers.h"
21 -#include "shaders.h"
22 -#include "shadergen.h"
2321 #include "ddraw.h"
 22+#include "glRenderer.h"
 23+#include "glDirect3DDevice.h"
2424 #include "glDirectDraw.h"
2525 #include "glDirectDrawSurface.h"
2626 #include "glDirectDrawPalette.h"
2727 #include "glDirectDrawClipper.h"
2828 #include "glRenderer.h"
 29+#include "shadergen.h"
 30+#include "shaders.h"
2931 #include "glutil.h"
3032
3133
Index: ddraw/glRenderer.cpp
@@ -624,7 +624,7 @@
625625 if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
626626 if(dwFlags & DDBLT_COLORFILL)
627627 {
628 - SetShader(PROG_FILL,NULL,true);
 628+ SetShader(PROG_FILL,NULL,NULL,true);
629629 glDisable(GL_TEXTURE_2D);
630630 glDisable(GL_ALPHA_TEST);
631631 switch(ddInterface->GetBPP())
@@ -669,7 +669,7 @@
670670 }
671671 if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
672672 {
673 - SetShader(PROG_CKEY,NULL,true);
 673+ SetShader(PROG_CKEY,NULL,NULL,true);
674674 GLint keyloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"keyIn");
675675 switch(ddInterface->GetBPP())
676676 {
@@ -700,7 +700,7 @@
701701 }
702702 else if(!(dwFlags & DDBLT_COLORFILL))
703703 {
704 - SetShader(PROG_TEXTURE,NULL,true);
 704+ SetShader(PROG_TEXTURE,NULL,NULL,true);
705705 GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
706706 glUniform1i(texloc,0);
707707 }
@@ -853,7 +853,7 @@
854854 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
855855 if(ddInterface->GetBPP() == 8)
856856 {
857 - SetShader(PROG_PAL256,NULL,true);
 857+ SetShader(PROG_PAL256,NULL,NULL,true);
858858 glBindTexture(GL_TEXTURE_2D,paltex);
859859 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,1,0,GL_RGBA,GL_UNSIGNED_BYTE,dest->palette->GetPalette(NULL));
860860 GLint palloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"ColorTable");
@@ -868,7 +868,7 @@
869869 if(dxglcfg.scalingfilter)
870870 {
871871 _DrawBackbuffer(&texture,dest->fakex,dest->fakey);
872 - SetShader(PROG_TEXTURE,NULL,true);
 872+ SetShader(PROG_TEXTURE,NULL,NULL,true);
873873 glEnable(GL_TEXTURE_2D);
874874 glBindTexture(GL_TEXTURE_2D,texture);
875875 GLuint prog = GetProgram() & 0xFFFFFFFF;
@@ -878,7 +878,7 @@
879879 }
880880 else
881881 {
882 - SetShader(PROG_TEXTURE,NULL,true);
 882+ SetShader(PROG_TEXTURE,NULL,NULL,true);
883883 glEnable(GL_TEXTURE_2D);
884884 glBindTexture(GL_TEXTURE_2D,texture);
885885 GLuint prog = GetProgram() & 0xFFFFFFFF;
@@ -1028,10 +1028,8 @@
10291029 wndbusy = false;
10301030 return;
10311031 }
1032 - TexState texstage;
1033 - ZeroMemory(&texstage,sizeof(TexState));
10341032 __int64 shader = device->SelectShader(vertices);
1035 - SetShader(shader,&texstage,0);
 1033+ SetShader(shader,device->texstages,texformats,0);
10361034 GLuint prog = GetProgram();
10371035 GLint xyzloc = glGetAttribLocation(prog,"xyz");
10381036 glEnableVertexAttribArray(xyzloc);
Index: ddraw/shadergen.cpp
@@ -16,6 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "glRenderer.h"
 21+#include "glDirect3DDevice.h"
2022 #include "shadergen.h"
2123 #include "shaders.h"
2224 #include <string>
@@ -79,19 +81,20 @@
8082 Bits 0-4: Texture color operation
8183 Bits 5-10: Texture color argument 1
8284 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:
9699 00=2dim 01=3dim 10=4dim 11=1dim
97100 */
98101 void ZeroShaderArray()
@@ -118,7 +121,7 @@
119122 genindex = 0;
120123 }
121124
122 -void SetShader(__int64 id, TexState *texstate, bool builtin)
 125+void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin)
123126 {
124127 int shaderindex = -1;
125128 if(builtin)
@@ -161,7 +164,7 @@
162165 delete genshaders[shaderindex].shader.fsrc;
163166 ZeroMemory(&genshaders[shaderindex],sizeof(GenShader));
164167 }
165 - CreateShader(genindex,id,texstate);
 168+ CreateShader(genindex,id,texstate,texcoords);
166169 shaderindex = genindex;
167170 genindex++;
168171 if(genindex == 256) genindex = 0;
@@ -233,6 +236,7 @@
234237 };\n";
235238 static const char unif_light[] = "uniform Light lightX;\n";
236239 static const char unif_ambient[] = "uniform vec4 ambientcolor;\n";
 240+static const char unif_tex[] = "uniform sampler2d texX;\n";
237241 // Variables
238242 static const char var_colors[] = "vec4 diffuse;\n\
239243 vec4 specular;\n\
@@ -274,7 +278,7 @@
275279 }\n\
276280 }\n";
277281
278 -void CreateShader(int index, __int64 id, TexState *texstate)
 282+void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
279283 {
280284 string tmp;
281285 int i;
Index: ddraw/shadergen.h
@@ -18,22 +18,10 @@
1919 #ifndef _SHADERGEN_H
2020 #define _SHADERGEN_H
2121
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 -
3422 void ClearShaders();
35 -void SetShader(__int64 id, TexState *texstate, bool builtin);
 23+void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin);
3624 GLuint GetProgram();
3725 void ZeroShaderArray();
38 -void CreateShader(int index, __int64 id, TexState *texstate);
 26+void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
3927
4028 #endif
\ No newline at end of file
Index: ddraw/shaders.cpp
@@ -16,6 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "glRenderer.h"
 21+#include "glDirect3DDevice.h"
2022 #include "shaders.h"
2123 #include "shadergen.h"
2224