DXGL r589 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r588‎ | r589 | r590 >
Date:15:31, 27 January 2015
Author:admin
Status:new
Tags:
Comment:
Track render states backend-side. Note that this commit causes major slowdown which will be fixed once the FIFO is implemented.
Temporarily disable a fog state in the 3D shader, to make Rogue Squadron display graphics.
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)
  • /ddraw/ShaderGen3D.h (modified) (history)
  • /ddraw/ShaderManager.cpp (modified) (history)
  • /ddraw/ShaderManager.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -61,7 +61,7 @@
6262 Bit 11 - Specular highlights VS/FS
6363 Bit 12 - Stippled alpha FS
6464 Bit 13 - Color key transparency FS
65 -Bit 14-17 - Z bias FS
 65+Bit 14-17 - Reserved
6666 Bits 18-20 - Number of lights VS/FS
6767 Bit 21 - Camera relative specular highlights VS/FS
6868 Bit 22 - Alpha blended color key FS
@@ -93,6 +93,9 @@
9494 Bits 28-33: Texture alpha argument 2 FS
9595 Bits 34-36: Texture coordinate index VS
9696 Bits 37-38: Texture coordinate flags VS
 97+ Bits in flags:
 98+ 00=passthru 01=cameraspacenormal
 99+ 10=cameraspaceposition 11=cameraspacereflectionvector
97100 Bits 39-40: U Texture address GL
98101 Bits 41-42: V Texture address GL
99102 Bits 43-45: Texture magnification filter GL/FS?
@@ -103,11 +106,7 @@
104107 Bit 53: Projected texcoord VS
105108 Bits in texcoord ID:
106109 00=2dim 01=3dim 10=4dim 11=1dim
107 -Bits 54-56: Texture coordinate index VS
108 -Bits 57-58: Texture coordinate flags VS
109 -Bits in flags:
110 -00=passthru 01=cameraspacenormal
111 -10=cameraspaceposition 11=cameraspacereflectionvector
 110+Bits 54-58: Reserved
112111 Bit 59: Texture image enabled
113112 Bit 60: Texture has color key
114113 */
@@ -145,7 +144,7 @@
146145 * @param id
147146 * 64-bit value containing current render states
148147 * @param texstate
149 - * Pointer to the texture stage state array, containing 8 64-bit state values
 148+ * Pointer to the texture state ID.
150149 * @param texcoords
151150 * Pointer to number of texture coordinates in each texture stage
152151 * @param type
@@ -154,7 +153,7 @@
155154 * 1 for generated 2D
156155 * 2 for generated 3D
157156 */
158 -void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d)
 157+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int *texcoords, int type, ShaderGen2D *gen2d)
159158 {
160159 int shaderindex = -1;
161160 switch(type)
@@ -215,7 +214,7 @@
216215 {
217216 bool texidmatch = true;
218217 for(int j = 0; j < 8; j++)
219 - if(This->genshaders[i].texids[j] != texstate[j].shaderid) texidmatch = false;
 218+ if(This->genshaders[i].texids[j] != texstate[j]) texidmatch = false;
220219 if(texidmatch)
221220 {
222221 if(!memcmp(This->genshaders[i].texcoords,texcoords,8*sizeof(int)))
@@ -247,7 +246,7 @@
248247 }
249248 This->genshaders[shaderindex].id = id;
250249 for(int i = 0; i < 8; i++)
251 - This->genshaders[shaderindex].texids[i] = texstate[i].shaderid;
 250+ This->genshaders[shaderindex].texids[i] = texstate[i];
252251 memcpy(This->genshaders[shaderindex].texcoords,texcoords,8*sizeof(int));
253252 This->ext->glUseProgram(This->genshaders[shaderindex].shader.prog);
254253 This->current_prog = This->genshaders[shaderindex].shader.prog;
@@ -485,7 +484,7 @@
486485 * @param texcoords
487486 * Pointer to number of texture coordinates in each texture stage
488487 */
489 -void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
 488+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate, int *texcoords)
490489 {
491490 STRING tmp;
492491 ZeroMemory(&tmp, sizeof(STRING));
@@ -684,7 +683,7 @@
685684 int texindex;
686685 for(i = 0; i < 8; i++)
687686 {
688 - if((texstate[i].shaderid>>50)&1)
 687+ if((texstate[i]>>50)&1)
689688 {
690689 FIXME("Support texture coordinate transform");
691690 }
@@ -693,7 +692,7 @@
694693 String_Assign(&tmp,op_texpassthru1);
695694 tmp.ptr[12] = *(_itoa(i,idstring,10));
696695 String_Append(vsrc, tmp.ptr);
697 - texindex = (texstate[i].shaderid>>54)&3;
 696+ texindex = (texstate[i]>>34)&3;
698697 switch(texcoords[texindex])
699698 {
700699 case -1: // No texcoords
@@ -785,7 +784,7 @@
786785 // Uniforms
787786 for(i = 0; i < 8; i++)
788787 {
789 - if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
 788+ if((texstate[i] & 31) == D3DTOP_DISABLE)break;
790789 String_Assign(&tmp, unif_tex);
791790 tmp.ptr[21] = *(_itoa(i,idstring,10));
792791 String_Append(fsrc, tmp.ptr);
@@ -794,7 +793,7 @@
795794 {
796795 for(i = 0; i < 8; i++)
797796 {
798 - if((texstate[i].shaderid>>60)&1)
 797+ if((texstate[i]>>60)&1)
799798 {
800799 String_Assign(&tmp, unif_key);
801800 tmp.ptr[17] = *(_itoa(i,idstring,10));
@@ -833,19 +832,19 @@
834833 if((id>>13)&1) usecolorkey = true;
835834 for(i = 0; i < 8; i++)
836835 {
837 - if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
838 - args[0] = (texstate[i].shaderid>>5)&63;
839 - args[1] = (texstate[i].shaderid>>11)&63;
840 - args[2] = (texstate[i].shaderid>>22)&63;
841 - args[3] = (texstate[i].shaderid>>28)&63;
 836+ if((texstate[i] & 31) == D3DTOP_DISABLE)break;
 837+ args[0] = (texstate[i]>>5)&63;
 838+ args[1] = (texstate[i]>>11)&63;
 839+ args[2] = (texstate[i]>>22)&63;
 840+ args[3] = (texstate[i]>>28)&63;
842841 // Color key
843842 if(usecolorkey)
844843 {
845 - if((texstate[i].shaderid>>60)&1)
 844+ if((texstate[i]>>60)&1)
846845 {
847846 String_Assign(&arg1, op_colorkeyin);
848847 arg1.ptr[33] = *(_itoa(i, idstring, 10));
849 - arg1.ptr[47] = *(_itoa((texstate[i].shaderid >> 54) & 7, idstring, 10));
 848+ arg1.ptr[47] = *(_itoa((texstate[i] >> 34) & 7, idstring, 10));
850849 arg1.ptr[63] = *(_itoa(i, idstring, 10));
851850 String_Append(fsrc, arg1.ptr);
852851 String_Assign(&arg1, op_colorkey);
@@ -865,11 +864,11 @@
866865 String_Assign(&arg1, blendargs[1]);
867866 break;
868867 case D3DTA_TEXTURE:
869 - if((texstate[i].shaderid >> 59)&1)
 868+ if((texstate[i] >> 59)&1)
870869 {
871870 String_Assign(&arg1, blendargs[2]);
872871 arg1.ptr[17] = *(_itoa(i,idstring,10));
873 - arg1.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 872+ arg1.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
874873 }
875874 else texfail = true;
876875 break;
@@ -901,11 +900,11 @@
902901 String_Assign(&arg2, blendargs[1]);
903902 break;
904903 case D3DTA_TEXTURE:
905 - if((texstate[i].shaderid >> 59)&1)
 904+ if((texstate[i] >> 59)&1)
906905 {
907906 String_Assign(&arg2, blendargs[2]);
908907 arg2.ptr[17] = *(_itoa(i,idstring,10));
909 - arg2.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 908+ arg2.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
910909 }
911910 else texfail = true;
912911 break;
@@ -927,7 +926,7 @@
928927 }
929928 if (args[1] & D3DTA_ALPHAREPLICATE) String_Append(&arg2, blendargs[10]);
930929 else String_Append(&arg2, blendargs[8]);
931 - if(!texfail) switch(texstate[i].shaderid & 31)
 930+ if(!texfail) switch(texstate[i] & 31)
932931 {
933932 case D3DTOP_DISABLE:
934933 default:
@@ -1012,7 +1011,7 @@
10131012 case D3DTOP_BLENDTEXTUREALPHA:
10141013 String_Assign(&texarg, blendargs[2]);
10151014 texarg.ptr[17] = *(_itoa(i,idstring,10));
1016 - texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1015+ texarg.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
10171016 String_Append(fsrc, "color.rgb = ");
10181017 String_Append(fsrc, arg1.ptr);
10191018 String_Append(fsrc, " * ");
@@ -1033,7 +1032,7 @@
10341033 case D3DTOP_BLENDTEXTUREALPHAPM:
10351034 String_Assign(&texarg, blendargs[2]);
10361035 texarg.ptr[17] = *(_itoa(i,idstring,10));
1037 - texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1036+ texarg.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
10381037 String_Append(fsrc, "color.rgb = ");
10391038 String_Append(fsrc, arg1.ptr);
10401039 String_Append(fsrc, " + ");
@@ -1050,7 +1049,7 @@
10511050 String_Append(fsrc, " * (1.0-color.a);\n");
10521051 break;
10531052 }
1054 - if(((texstate[i].shaderid>>17) & 31) == D3DTOP_DISABLE)alphadisabled = true;
 1053+ if(((texstate[i]>>17) & 31) == D3DTOP_DISABLE)alphadisabled = true;
10551054 if(alphadisabled) continue;
10561055 // Alpha stage
10571056 texfail = false;
@@ -1066,12 +1065,12 @@
10671066 String_Append(&arg1, blendargs[9]);
10681067 break;
10691068 case D3DTA_TEXTURE:
1070 - if((texstate[i].shaderid >> 59)&1)
 1069+ if((texstate[i] >> 59)&1)
10711070 {
10721071 String_Assign(&arg1, blendargs[2]);
10731072 String_Append(&arg1, blendargs[9]);
10741073 arg1.ptr[17] = *(_itoa(i,idstring,10));
1075 - arg1.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1074+ arg1.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
10761075 }
10771076 else texfail = true;
10781077 break;
@@ -1105,12 +1104,12 @@
11061105 String_Append(&arg2, blendargs[9]);
11071106 break;
11081107 case D3DTA_TEXTURE:
1109 - if((texstate[i].shaderid >> 59)&1)
 1108+ if((texstate[i] >> 59)&1)
11101109 {
11111110 String_Assign(&arg2, blendargs[2]);
11121111 String_Append(&arg2, blendargs[9]);
11131112 arg2.ptr[17] = *(_itoa(i,idstring,10));
1114 - arg2.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1113+ arg2.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
11151114 }
11161115 else texfail = true;
11171116 break;
@@ -1132,7 +1131,7 @@
11331132 String_Append(&tmp, ")");
11341133 String_Assign(&arg2, tmp.ptr);
11351134 }
1136 - if (!texfail) switch ((texstate[i].shaderid >> 17) & 31)
 1135+ if (!texfail) switch ((texstate[i] >> 17) & 31)
11371136 {
11381137 case D3DTOP_DISABLE:
11391138 default:
@@ -1217,7 +1216,7 @@
12181217 case D3DTOP_BLENDTEXTUREALPHA:
12191218 String_Assign(&texarg, blendargs[2]);
12201219 texarg.ptr[17] = *(_itoa(i,idstring,10));
1221 - texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1220+ texarg.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
12221221 String_Append(fsrc, "color.a = ");
12231222 String_Append(fsrc, arg1.ptr);
12241223 String_Append(fsrc, " * ");
@@ -1238,7 +1237,7 @@
12391238 case D3DTOP_BLENDTEXTUREALPHAPM:
12401239 String_Assign(&texarg, blendargs[2]);
12411240 texarg.ptr[17] = *(_itoa(i,idstring,10));
1242 - texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1241+ texarg.ptr[31] = *(_itoa((texstate[i]>>34)&7,idstring,10));
12431242 String_Append(fsrc, "color.a = ");
12441243 String_Append(fsrc, arg1.ptr);
12451244 String_Append(fsrc, " + ");
@@ -1305,7 +1304,7 @@
13061305 String_Append(fsrc, op_fogclamp);
13071306 String_Append(fsrc, op_fogblend);
13081307 }
1309 - if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
 1308+ //if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
13101309 if (dither) String_Append(fsrc,op_dither);
13111310 String_Append(fsrc, op_colorfragout);
13121311 String_Append(fsrc, mainend);
Index: ddraw/ShaderGen3D.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2014 William Feely
 3+// Copyright (C) 2012-2015 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
@@ -64,10 +64,10 @@
6565 void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen);
6666 void ShaderGen3D_Delete(ShaderGen3D *This);
6767 void ShaderGen3D_ClearShaders(ShaderGen3D *This);
68 -void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d);
 68+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, __int64 *texstate, int *texcoords, int type, ShaderGen2D *gen2d);
6969 GLuint ShaderGen3D_GetProgram(ShaderGen3D *This);
7070 void ShaderGen3D_ZeroShaderArray(ShaderGen3D *This);
71 -void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
 71+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, __int64 *texstate, int *texcoords);
7272
7373 #ifdef __cplusplus
7474 }
Index: ddraw/ShaderManager.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 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
@@ -204,7 +204,7 @@
205205 free(This->gen3d);
206206 }
207207
208 -void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
 208+void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int *texcoords, int type)
209209 {
210210 ShaderGen3D_SetShader(This->gen3d, id, texstate, texcoords, type, This->gen2d);
211211 }
Index: ddraw/ShaderManager.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 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
@@ -61,7 +61,7 @@
6262
6363 void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman);
6464 void ShaderManager_Delete(ShaderManager *This);
65 -void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type);
 65+void ShaderManager_SetShader(ShaderManager *This, __int64 id, __int64 *texstate, int *texcoords, int type);
6666
6767 #ifdef __cplusplus
6868 }
Index: ddraw/glDirect3DDevice.cpp
@@ -191,8 +191,6 @@
192192 0,
193193 D3DTTFF_DISABLE,
194194 NULL,
195 - false,
196 - 0,
197195 GL_NEAREST,
198196 GL_NEAREST
199197 };
@@ -219,8 +217,6 @@
220218 0,
221219 D3DTTFF_DISABLE,
222220 NULL,
223 - false,
224 - 0,
225221 GL_NEAREST,
226222 GL_NEAREST
227223 };
@@ -365,7 +361,7 @@
366362 d3ddesc3.dwMaxTextureRepeat = d3ddesc3.dwMaxTextureAspectRatio = renderer->gl_caps.TextureMax;
367363 scalex = scaley = 0;
368364 mhWorld = mhView = mhProjection = 0;
369 - glRenderer_InitD3D(renderer,zbuffer);
 365+ glRenderer_InitD3D(renderer,zbuffer,glDDS7->ddsd.dwWidth,glDDS7->ddsd.dwHeight);
370366 glD3DDev3 = new glDirect3DDevice3(this);
371367 glD3DDev2 = new glDirect3DDevice2(this);
372368 glD3DDev1 = new glDirect3DDevice1(this);
@@ -378,7 +374,7 @@
379375 TRACE_ENTER(1,14,this);
380376 for(int i = 0; i < lightsmax; i++)
381377 if(lights[i]) delete lights[i];
382 - delete lights;
 378+ free(lights);
383379 for(int i = 0; i < 8; i++)
384380 if(texstages[i].texture) texstages[i].texture->Release();
385381 for(int i = 0; i < materialcount; i++)
@@ -705,7 +701,7 @@
706702 TRACE_EXIT(0,0);
707703 }
708704
709 -__int64 glDirect3DDevice7::SelectShader(GLVERTEX *VertexType)
 705+/*__int64 glDirect3DDevice7::SelectShader(GLVERTEX *VertexType)
710706 {
711707 TRACE_ENTER(2,14,this,14,VertexType);
712708 int i;
@@ -730,7 +726,7 @@
731727 if(renderstate[D3DRENDERSTATE_SPECULARENABLE]) shader |= (1i64 << 11);
732728 if(renderstate[D3DRENDERSTATE_STIPPLEDALPHA]) shader |= (1i64 << 12);
733729 if(renderstate[D3DRENDERSTATE_COLORKEYENABLE]) shader |= (1i64 << 13);
734 - shader |= (((__int64)renderstate[D3DRENDERSTATE_ZBIAS] & 15) << 14);
 730+ //shader |= (((__int64)renderstate[D3DRENDERSTATE_ZBIAS] & 15) << 14);
735731 int numlights = 0;
736732 for(i = 0; i < 8; i++)
737733 if(gllights[i] != -1) numlights++;
@@ -768,7 +764,7 @@
769765 if(VertexType[1].data) shader |= (1i64 << 50);
770766 if(renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
771767 {
772 - bool noalpha = false;;
 768+ bool noalpha = false;
773769 if(!texstages[0].texture) noalpha = true;
774770 if(texstages[0].texture)
775771 if(!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
@@ -812,7 +808,7 @@
813809 }
814810 TRACE_EXIT(10,&shader);
815811 return shader;
816 -}
 812+}*/
817813
818814 HRESULT glDirect3DDevice7::fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr)
819815 {
@@ -1246,6 +1242,7 @@
12471243 {
12481244 foundlight = true;
12491245 gllights[i] = dwLightIndex;
 1246+ glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light, FALSE);
12501247 break;
12511248 }
12521249 }
@@ -1258,6 +1255,7 @@
12591256 if(gllights[i] == dwLightIndex)
12601257 {
12611258 gllights[i] = -1;
 1259+ glRenderer_SetLight(renderer, i, NULL, TRUE);
12621260 }
12631261 }
12641262 TRACE_EXIT(23,D3D_OK);
@@ -1321,6 +1319,10 @@
13221320 }
13231321 if(!lights[dwLightIndex]) lights[dwLightIndex] = new glDirect3DLight;
13241322 lights[dwLightIndex]->SetLight7(lpLight);
 1323+ for (int i = 0; i < 8; i++)
 1324+ {
 1325+ if (gllights[i] == dwLightIndex) glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light, FALSE);
 1326+ }
13251327 TRACE_EXIT(23,D3D_OK);
13261328 return D3D_OK;
13271329 }
@@ -1330,6 +1332,7 @@
13311333 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
13321334 if(!lpMaterial) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
13331335 memcpy(&material,lpMaterial,sizeof(D3DMATERIAL7));
 1336+ glRenderer_SetMaterial(renderer, lpMaterial);
13341337 TRACE_EXIT(23,D3D_OK);
13351338 return D3D_OK;
13361339 }
@@ -1336,11 +1339,14 @@
13371340
13381341 HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
13391342 {
1340 - TRACE_ENTER(3,14,this,27,dwRendStateType,9,dwRenderState);
 1343+ BOOL devstate = TRUE;
 1344+ BOOL noalpha = FALSE;
 1345+ TRACE_ENTER(3, 14, this, 27, dwRendStateType, 9, dwRenderState);
13411346 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
13421347 switch(dwRendStateType)
13431348 {
13441349 case D3DRENDERSTATE_TEXTUREHANDLE:
 1350+ devstate = FALSE;
13451351 if(dwRenderState > texturecount-1) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
13461352 if(dwRenderState)
13471353 {
@@ -1350,18 +1356,24 @@
13511357 else SetTexture(0,NULL);
13521358 break;
13531359 case D3DRENDERSTATE_TEXTUREADDRESS:
 1360+ devstate = FALSE;
13541361 SetRenderState(D3DRENDERSTATE_TEXTUREADDRESSU,dwRenderState);
13551362 SetRenderState(D3DRENDERSTATE_TEXTUREADDRESSV,dwRenderState);
13561363 break;
13571364 case D3DRENDERSTATE_WRAPU:
 1365+ devstate = FALSE;
13581366 if(dwRenderState) renderstate[D3DRENDERSTATE_WRAP0] |= D3DWRAP_U;
13591367 else renderstate[D3DRENDERSTATE_WRAP0] &= ~D3DWRAP_U;
 1368+ SetRenderState(D3DRENDERSTATE_WRAP0, renderstate[D3DRENDERSTATE_WRAP0]);
13601369 break;
13611370 case D3DRENDERSTATE_WRAPV:
1362 - if(dwRenderState) renderstate[D3DRENDERSTATE_WRAP0] |= D3DWRAP_V;
 1371+ devstate = FALSE;
 1372+ if (dwRenderState) renderstate[D3DRENDERSTATE_WRAP0] |= D3DWRAP_V;
13631373 else renderstate[D3DRENDERSTATE_WRAP0] &= ~D3DWRAP_V;
 1374+ SetRenderState(D3DRENDERSTATE_WRAP0, renderstate[D3DRENDERSTATE_WRAP0]);
13641375 break;
13651376 case D3DRENDERSTATE_TEXTUREMAG:
 1377+ devstate = FALSE;
13661378 switch(dwRenderState)
13671379 {
13681380 case D3DFILTER_NEAREST:
@@ -1373,6 +1385,7 @@
13741386 }
13751387 break;
13761388 case D3DRENDERSTATE_TEXTUREMIN:
 1389+ devstate = FALSE;
13771390 switch(dwRenderState)
13781391 {
13791392 case D3DFILTER_NEAREST:
@@ -1420,7 +1433,13 @@
14211434 SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
14221435 SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
14231436 SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
1424 - break; // Automatically selected based on texture
 1437+ if (!texstages[0].texture) noalpha = TRUE;
 1438+ if (texstages[0].texture)
 1439+ if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1440+ noalpha = TRUE;
 1441+ if (noalpha) SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
 1442+ else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
 1443+ break;
14251444 case D3DTBLEND_DECALALPHA:
14261445 SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
14271446 SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_CURRENT);
@@ -1453,6 +1472,7 @@
14541473 if(dwRendStateType > 152) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
14551474 if(dwRendStateType < 0) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
14561475 renderstate[dwRendStateType] = dwRenderState;
 1476+ if (devstate) glRenderer_SetRenderState(renderer, dwRendStateType, dwRenderState);
14571477 TRACE_EXIT(23,D3D_OK);
14581478 return D3D_OK;
14591479 }
@@ -1487,13 +1507,24 @@
14881508 if(dwStage > 7) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
14891509 if(texstages[dwStage].texture) texstages[dwStage].texture->Release();
14901510 texstages[dwStage].texture = (glDirectDrawSurface7*)lpTexture;
1491 - texstages[dwStage].dirty = true;
14921511 if(lpTexture) lpTexture->AddRef();
 1512+ glRenderer_SetTexture(renderer, dwStage, texstages[dwStage].texture);
 1513+ if (renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
 1514+ {
 1515+ bool noalpha = false;
 1516+ if (!texstages[0].texture) noalpha = true;
 1517+ if (texstages[0].texture)
 1518+ if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1519+ noalpha = true;
 1520+ if (noalpha) SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
 1521+ else SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
 1522+ }
14931523 TRACE_EXIT(23,D3D_OK);
14941524 return D3D_OK;
14951525 }
14961526 HRESULT WINAPI glDirect3DDevice7::SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
14971527 {
 1528+ BOOL devstate = TRUE;
14981529 TRACE_ENTER(4,14,this,8,dwStage,28,dwState,9,dwValue);
14991530 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
15001531 if(dwStage > 7) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
@@ -1501,238 +1532,107 @@
15021533 {
15031534 case D3DTSS_COLOROP:
15041535 if(!dwValue || (dwValue > 24)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1505 - if(dwStage == 0)renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] = 0;
 1536+ if (dwStage == 0)SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, 0);
15061537 texstages[dwStage].colorop = (D3DTEXTUREOP)dwValue;
1507 - texstages[dwStage].dirty = true;
1508 - TRACE_EXIT(23,D3D_OK);
1509 - return D3D_OK;
 1538+ break;
15101539 case D3DTSS_COLORARG1:
15111540 if((dwValue & D3DTA_SELECTMASK) > 4) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15121541 if(dwValue > 0x34) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15131542 texstages[dwStage].colorarg1 = dwValue;
1514 - texstages[dwStage].dirty = true;
1515 - TRACE_EXIT(23,D3D_OK);
1516 - return D3D_OK;
 1543+ break;
15171544 case D3DTSS_COLORARG2:
15181545 if((dwValue & D3DTA_SELECTMASK) > 4) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15191546 if(dwValue > 0x34) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15201547 texstages[dwStage].colorarg2 = dwValue;
1521 - texstages[dwStage].dirty = true;
1522 - TRACE_EXIT(23,D3D_OK);
1523 - return D3D_OK;
 1548+ break;
15241549 case D3DTSS_ALPHAOP:
15251550 if(!dwValue || (dwValue > 24)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1526 - if(dwStage == 0)renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] = 0;
1527 - texstages[dwStage].alphaop = (D3DTEXTUREOP )dwValue;
1528 - texstages[dwStage].dirty = true;
1529 - TRACE_EXIT(23,D3D_OK);
1530 - return D3D_OK;
 1551+ if (dwStage == 0)SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, 0);
 1552+ texstages[dwStage].alphaop = (D3DTEXTUREOP)dwValue;
 1553+ break;
15311554 case D3DTSS_ALPHAARG1:
15321555 if((dwValue & D3DTA_SELECTMASK) > 4) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15331556 if(dwValue > 0x34) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15341557 texstages[dwStage].alphaarg1 = dwValue;
1535 - texstages[dwStage].dirty = true;
1536 - TRACE_RET(HRESULT,23,D3D_OK);
1537 - return D3D_OK;
 1558+ break;
15381559 case D3DTSS_ALPHAARG2:
15391560 if((dwValue & D3DTA_SELECTMASK) > 4) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15401561 if(dwValue > 0x34) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15411562 texstages[dwStage].alphaarg2 = dwValue;
1542 - texstages[dwStage].dirty = true;
1543 - TRACE_EXIT(23,D3D_OK);
1544 - return D3D_OK;
 1563+ break;
15451564 case D3DTSS_BUMPENVMAT00:
15461565 memcpy(&texstages[dwStage].bumpenv00,&dwValue,sizeof(D3DVALUE));
1547 - texstages[dwStage].dirty = true;
1548 - TRACE_EXIT(23,D3D_OK);
1549 - return D3D_OK;
 1566+ break;
15501567 case D3DTSS_BUMPENVMAT01:
15511568 memcpy(&texstages[dwStage].bumpenv01,&dwValue,sizeof(D3DVALUE));
1552 - texstages[dwStage].dirty = true;
1553 - TRACE_EXIT(23,D3D_OK);
1554 - return D3D_OK;
 1569+ break;
15551570 case D3DTSS_BUMPENVMAT10:
15561571 memcpy(&texstages[dwStage].bumpenv10,&dwValue,sizeof(D3DVALUE));
1557 - texstages[dwStage].dirty = true;
1558 - TRACE_EXIT(23,D3D_OK);
1559 - return D3D_OK;
 1572+ break;
15601573 case D3DTSS_BUMPENVMAT11:
15611574 memcpy(&texstages[dwStage].bumpenv11,&dwValue,sizeof(D3DVALUE));
1562 - texstages[dwStage].dirty = true;
1563 - TRACE_EXIT(23,D3D_OK);
1564 - return D3D_OK;
 1575+ break;
15651576 case D3DTSS_TEXCOORDINDEX:
15661577 if((dwValue & 0xFFFF) > 7) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15671578 if((dwValue >> 16) > 3) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15681579 texstages[dwStage].texcoordindex = dwValue;
1569 - texstages[dwStage].dirty = true;
1570 - TRACE_EXIT(23,D3D_OK);
1571 - return D3D_OK;
 1580+ break;
15721581 case D3DTSS_ADDRESS:
15731582 if(!dwValue || (dwValue > 4)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1574 - texstages[dwStage].addressu = (D3DTEXTUREADDRESS)dwValue;
1575 - texstages[dwStage].addressv = (D3DTEXTUREADDRESS)dwValue;
1576 - texstages[dwStage].dirty = true;
1577 - TRACE_EXIT(23,D3D_OK);
1578 - return D3D_OK;
 1583+ devstate = FALSE;
 1584+ SetTextureStageState(dwStage, D3DTSS_ADDRESSU, dwValue);
 1585+ SetTextureStageState(dwStage, D3DTSS_ADDRESSV, dwValue);
 1586+ break;
15791587 case D3DTSS_ADDRESSU:
15801588 if(!dwValue || (dwValue > 4)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15811589 texstages[dwStage].addressu = (D3DTEXTUREADDRESS)dwValue;
1582 - texstages[dwStage].dirty = true;
1583 - TRACE_EXIT(23,D3D_OK);
1584 - return D3D_OK;
 1590+ break;
15851591 case D3DTSS_ADDRESSV:
15861592 if(!dwValue || (dwValue > 4)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15871593 texstages[dwStage].addressv = (D3DTEXTUREADDRESS)dwValue;
1588 - texstages[dwStage].dirty = true;
1589 - TRACE_EXIT(23,D3D_OK);
1590 - return D3D_OK;
 1594+ break;
15911595 case D3DTSS_BORDERCOLOR:
15921596 texstages[dwStage].bordercolor = dwValue;
1593 - texstages[dwStage].dirty = true;
1594 - TRACE_EXIT(23,D3D_OK);
1595 - return D3D_OK;
 1597+ break;
15961598 case D3DTSS_MAGFILTER:
15971599 if(!dwValue || (dwValue > 5)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
15981600 texstages[dwStage].magfilter = (D3DTEXTUREMAGFILTER)dwValue;
1599 - texstages[dwStage].dirty = true;
1600 - switch(texstages[dwStage].magfilter)
1601 - {
1602 - case 1:
1603 - default:
1604 - texstages[dwStage].glmagfilter = GL_NEAREST;
1605 - break;
1606 - case 2:
1607 - case 3:
1608 - case 4:
1609 - case 5:
1610 - texstages[dwStage].glmagfilter = GL_LINEAR;
1611 - break;
1612 - }
1613 - TRACE_EXIT(23,D3D_OK);
1614 - return D3D_OK;
 1601+ break;
16151602 case D3DTSS_MINFILTER:
16161603 if(!dwValue || (dwValue > 3)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
16171604 texstages[dwStage].minfilter = (D3DTEXTUREMINFILTER)dwValue;
1618 - texstages[dwStage].dirty = true;
1619 - switch(texstages[dwStage].minfilter)
1620 - {
1621 - case 1:
1622 - default:
1623 - switch(texstages[dwStage].mipfilter)
1624 - {
1625 - case 1:
1626 - default:
1627 - texstages[dwStage].glminfilter = GL_NEAREST;
1628 - break;
1629 - case 2:
1630 - texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
1631 - break;
1632 - case 3:
1633 - texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
1634 - break;
1635 - }
1636 - break;
1637 - case 2:
1638 - case 3:
1639 - switch(texstages[dwStage].mipfilter)
1640 - {
1641 - case 1:
1642 - default:
1643 - texstages[dwStage].glminfilter = GL_LINEAR;
1644 - break;
1645 - case 2:
1646 - texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
1647 - break;
1648 - case 3:
1649 - texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
1650 - break;
1651 - }
1652 - break;
1653 - }
1654 - TRACE_EXIT(23,D3D_OK);
1655 - return D3D_OK;
 1605+ break;
16561606 case D3DTSS_MIPFILTER:
16571607 if(!dwValue || (dwValue > 3)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
16581608 texstages[dwStage].mipfilter = (D3DTEXTUREMIPFILTER)dwValue;
1659 - texstages[dwStage].dirty = true;
1660 - switch(texstages[dwStage].mipfilter)
1661 - {
1662 - case 1:
1663 - default:
1664 - switch(texstages[dwStage].minfilter)
1665 - {
1666 - case 1:
1667 - default:
1668 - texstages[dwStage].glminfilter = GL_NEAREST;
1669 - case 2:
1670 - case 3:
1671 - texstages[dwStage].glminfilter = GL_LINEAR;
1672 - }
1673 - break;
1674 - case 2:
1675 - switch(texstages[dwStage].minfilter)
1676 - {
1677 - case 1:
1678 - default:
1679 - texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
1680 - case 2:
1681 - case 3:
1682 - texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
1683 - }
1684 - break;
1685 - case 3:
1686 - switch(texstages[dwStage].minfilter)
1687 - {
1688 - case 1:
1689 - default:
1690 - texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
1691 - case 2:
1692 - case 3:
1693 - texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
1694 - }
1695 - break;
1696 - }
1697 - TRACE_EXIT(23,D3D_OK);
1698 - return D3D_OK;
 1609+ break;
16991610 case D3DTSS_MIPMAPLODBIAS:
17001611 memcpy(&texstages[dwStage].lodbias,&dwValue,sizeof(D3DVALUE));
1701 - texstages[dwStage].dirty = true;
1702 - TRACE_EXIT(23,D3D_OK);
1703 - return D3D_OK;
 1612+ break;
17041613 case D3DTSS_MAXMIPLEVEL:
17051614 texstages[dwStage].miplevel = dwValue;
1706 - texstages[dwStage].dirty = true;
1707 - TRACE_EXIT(23,D3D_OK);
1708 - return D3D_OK;
 1615+ break;
17091616 case D3DTSS_MAXANISOTROPY:
17101617 texstages[dwStage].anisotropy = dwValue;
1711 - texstages[dwStage].dirty = true;
1712 - TRACE_EXIT(23,D3D_OK);
1713 - return D3D_OK;
 1618+ break;
17141619 case D3DTSS_BUMPENVLSCALE:
17151620 memcpy(&texstages[dwStage].bumpenvlscale,&dwValue,sizeof(D3DVALUE));
1716 - texstages[dwStage].dirty = true;
1717 - TRACE_EXIT(23,D3D_OK);
1718 - return D3D_OK;
 1621+ break;
17191622 case D3DTSS_BUMPENVLOFFSET:
17201623 memcpy(&texstages[dwStage].bumpenvloffset,&dwValue,sizeof(D3DVALUE));
1721 - texstages[dwStage].dirty = true;
1722 - TRACE_EXIT(23,D3D_OK);
1723 - return D3D_OK;
 1624+ break;
17241625 case D3DTSS_TEXTURETRANSFORMFLAGS:
17251626 if((dwValue & 0xFF) > 4) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
17261627 if((dwValue >> 8) > 1) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
17271628 texstages[dwStage].textransform = (D3DTEXTURETRANSFORMFLAGS)dwValue;
1728 - texstages[dwStage].dirty = true;
1729 - TRACE_EXIT(23,D3D_OK);
1730 - return D3D_OK;
 1629+ break;
17311630 default:
17321631 TRACE_EXIT(23,DDERR_INVALIDPARAMS);
17331632 return DDERR_INVALIDPARAMS;
17341633 }
1735 - TRACE_RET(HRESULT,23,DDERR_GENERIC);
1736 - ERR(DDERR_GENERIC);
 1634+ if (devstate) glRenderer_SetTextureStageState(renderer, dwStage, dwState, dwValue);
 1635+ TRACE_EXIT(23, D3D_OK);
 1636+ return D3D_OK;
17371637 }
17381638 HRESULT WINAPI glDirect3DDevice7::SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
17391639 {
@@ -1744,25 +1644,23 @@
17451645 memcpy(&matWorld,lpD3DMatrix,sizeof(D3DMATRIX));
17461646 modelview_dirty = true;
17471647 transform_dirty = true;
1748 - TRACE_EXIT(23,D3D_OK);
1749 - return D3D_OK;
 1648+ break;
17501649 case D3DTRANSFORMSTATE_VIEW:
17511650 memcpy(&matView,lpD3DMatrix,sizeof(D3DMATRIX));
17521651 modelview_dirty = true;
17531652 transform_dirty = true;
1754 - TRACE_EXIT(23,D3D_OK);
1755 - return D3D_OK;
 1653+ break;
17561654 case D3DTRANSFORMSTATE_PROJECTION:
17571655 memcpy(&matProjection,lpD3DMatrix,sizeof(D3DMATRIX));
17581656 projection_dirty = true;
17591657 transform_dirty = true;
1760 - TRACE_EXIT(23,D3D_OK);
1761 - return D3D_OK;
 1658+ break;
17621659 default:
17631660 TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
17641661 }
1765 - TRACE_EXIT(23,DDERR_GENERIC);
1766 - return DDERR_GENERIC;
 1662+ glRenderer_SetTransform(renderer, dtstTransformStateType, lpD3DMatrix);
 1663+ TRACE_EXIT(23, D3D_OK);
 1664+ return D3D_OK;
17671665 }
17681666 HRESULT WINAPI glDirect3DDevice7::SetViewport(LPD3DVIEWPORT7 lpViewport)
17691667 {
@@ -1770,6 +1668,7 @@
17711669 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
17721670 memcpy(&viewport,lpViewport,sizeof(D3DVIEWPORT7));
17731671 transform_dirty = true;
 1672+ glRenderer_SetViewport(renderer, lpViewport);
17741673 TRACE_EXIT(23,D3D_OK);
17751674 return D3D_OK;
17761675 }
@@ -1831,39 +1730,6 @@
18321731 return D3D_OK;
18331732 }
18341733
1835 -void glDirect3DDevice7::SetDepthComp(glUtil *util)
1836 -{
1837 - TRACE_ENTER(1,14,this,14,util);
1838 - switch(renderstate[D3DRENDERSTATE_ZFUNC])
1839 - {
1840 - case D3DCMP_NEVER:
1841 - util->SetDepthComp(GL_NEVER);
1842 - break;
1843 - case D3DCMP_LESS:
1844 - util->SetDepthComp(GL_LESS);
1845 - break;
1846 - case D3DCMP_EQUAL:
1847 - util->SetDepthComp(GL_EQUAL);
1848 - break;
1849 - case D3DCMP_LESSEQUAL:
1850 - util->SetDepthComp(GL_LEQUAL);
1851 - break;
1852 - case D3DCMP_GREATER:
1853 - util->SetDepthComp(GL_GREATER);
1854 - break;
1855 - case D3DCMP_NOTEQUAL:
1856 - util->SetDepthComp(GL_NOTEQUAL);
1857 - break;
1858 - case D3DCMP_GREATEREQUAL:
1859 - util->SetDepthComp(GL_GEQUAL);
1860 - break;
1861 - case D3DCMP_ALWAYS:
1862 - default:
1863 - util->SetDepthComp(GL_ALWAYS);
1864 - break;
1865 - }
1866 - TRACE_EXIT(0,0);
1867 -}
18681734
18691735 D3DMATERIALHANDLE glDirect3DDevice7::AddMaterial(glDirect3DMaterial3 *material)
18701736 {
Index: ddraw/glDirect3DDevice.h
@@ -22,38 +22,6 @@
2323 class glDirectDrawSurface7;
2424 class glDirect3D7;
2525
26 -struct TEXTURESTAGE
27 -{
28 - D3DTEXTUREOP colorop;
29 - DWORD colorarg1;
30 - DWORD colorarg2;
31 - D3DTEXTUREOP alphaop;
32 - DWORD alphaarg1;
33 - DWORD alphaarg2;
34 - D3DVALUE bumpenv00;
35 - D3DVALUE bumpenv01;
36 - D3DVALUE bumpenv10;
37 - D3DVALUE bumpenv11;
38 - DWORD texcoordindex;
39 - D3DTEXTUREADDRESS addressu;
40 - D3DTEXTUREADDRESS addressv;
41 - DWORD bordercolor;
42 - D3DTEXTUREMAGFILTER magfilter;
43 - D3DTEXTUREMINFILTER minfilter;
44 - D3DTEXTUREMIPFILTER mipfilter;
45 - D3DVALUE lodbias;
46 - DWORD miplevel;
47 - DWORD anisotropy;
48 - D3DVALUE bumpenvlscale;
49 - D3DVALUE bumpenvloffset;
50 - D3DTEXTURETRANSFORMFLAGS textransform;
51 - glDirectDrawSurface7 *texture;
52 - bool dirty;
53 - __int64 shaderid;
54 - GLint glmagfilter;
55 - GLint glminfilter;
56 -};
57 -
5826 struct D3D1MATRIX
5927 {
6028 BOOL active;
@@ -133,7 +101,6 @@
134102 HRESULT WINAPI ValidateDevice(LPDWORD lpdwPasses);
135103 HRESULT err() {return error;}
136104 void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
137 - void SetDepthComp(glUtil *util);
138105 D3DMATERIALHANDLE AddMaterial(glDirect3DMaterial3* material);
139106 D3DTEXTUREHANDLE AddTexture(glDirectDrawSurface7* texture);
140107 HRESULT AddViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport);
@@ -169,7 +136,7 @@
170137 void UpdateTransform();
171138 void InitDX2();
172139 void InitDX5();
173 - __int64 SelectShader(GLVERTEX *VertexType);
 140+ //__int64 SelectShader(GLVERTEX *VertexType);
174141 void SetScale(D3DVALUE x, D3DVALUE y){scalex = x; scaley = y;}
175142 ULONG AddRefInternal();
176143 ULONG ReleaseInternal();
Index: ddraw/glRenderer.cpp
@@ -502,9 +502,12 @@
503503 * @param zbuffer
504504 * Nonzero if a Z buffer is present.
505505 */
506 -void glRenderer_InitD3D(glRenderer *This, int zbuffer)
 506+void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y)
507507 {
508508 EnterCriticalSection(&This->cs);
 509+ This->inputs[0] = (void*)zbuffer;
 510+ This->inputs[1] = (void*)x;
 511+ This->inputs[2] = (void*)y;
509512 This->opcode = OP_INITD3D;
510513 SetEvent(This->start);
511514 WaitForSingleObject(This->busy,INFINITE);
@@ -713,8 +716,148 @@
714717 return (HRESULT)This->outputs[0];
715718 }
716719
 720+/**
 721+* Sets a render state within the renderer.
 722+* @param This
 723+* Pointer to glRenderer object
 724+* @param dwRendStateType
 725+* Render state to change
 726+* @param dwRenderState
 727+* New render state value
 728+*/
 729+void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
 730+{
 731+ EnterCriticalSection(&This->cs);
 732+ This->inputs[0] = (void*)dwRendStateType;
 733+ This->inputs[1] = (void*)dwRenderState;
 734+ This->opcode = OP_SETRENDERSTATE;
 735+ SetEvent(This->start);
 736+ WaitForSingleObject(This->busy, INFINITE);
 737+ LeaveCriticalSection(&This->cs);
 738+}
717739
718740 /**
 741+* Binds a surface to a texture stage in the renderer.
 742+* @param This
 743+* Pointer to glRenderer object
 744+* @param dwStage
 745+* Texture stage to bind
 746+* @param Texture
 747+* Texture to bind to the stage; old texture will be released; NULL to unbind
 748+*/
 749+void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
 750+{
 751+ EnterCriticalSection(&This->cs);
 752+ This->inputs[0] = (void*)dwStage;
 753+ This->inputs[1] = Texture;
 754+ This->opcode = OP_SETTEXTURE;
 755+ SetEvent(This->start);
 756+ WaitForSingleObject(This->busy, INFINITE);
 757+ LeaveCriticalSection(&This->cs);
 758+}
 759+
 760+/**
 761+* Sets a texture stage state within the renderer.
 762+* @param This
 763+* Pointer to glRenderer object
 764+* @param dwStage
 765+* Texture stage to modify
 766+* @param dwState
 767+* Texture stage state to modify
 768+* @param dwValue
 769+* New value for texture stage state.
 770+*/
 771+void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
 772+{
 773+ EnterCriticalSection(&This->cs);
 774+ This->inputs[0] = (void*)dwStage;
 775+ This->inputs[1] = (void*)dwState;
 776+ This->inputs[2] = (void*)dwValue;
 777+ This->opcode = OP_SETTEXTURESTAGESTATE;
 778+ SetEvent(This->start);
 779+ WaitForSingleObject(This->busy, INFINITE);
 780+ LeaveCriticalSection(&This->cs);
 781+}
 782+
 783+/**
 784+* Sets a transform matrix in the renderer.
 785+* @param This
 786+* Pointer to glRenderer object
 787+* @param dtstTransformStateType
 788+* Transform matrix to replace
 789+* @param lpD3DMatrix
 790+* New transform matrix
 791+*/
 792+void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
 793+{
 794+ EnterCriticalSection(&This->cs);
 795+ This->inputs[0] = (void*)dtstTransformStateType;
 796+ This->inputs[1] = lpD3DMatrix;
 797+ This->opcode = OP_SETTRANSFORM;
 798+ SetEvent(This->start);
 799+ WaitForSingleObject(This->busy, INFINITE);
 800+ LeaveCriticalSection(&This->cs);
 801+}
 802+
 803+/**
 804+* Sets the material in the renderer.
 805+* @param This
 806+* Pointer to glRenderer object
 807+* @param lpMaterial
 808+* New material parameters
 809+*/
 810+void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial)
 811+{
 812+ EnterCriticalSection(&This->cs);
 813+ This->inputs[0] = lpMaterial;
 814+ This->opcode = OP_SETMATERIAL;
 815+ SetEvent(This->start);
 816+ WaitForSingleObject(This->busy, INFINITE);
 817+ LeaveCriticalSection(&This->cs);
 818+}
 819+
 820+/**
 821+* Sets a light in the renderer.
 822+* @param This
 823+* Pointer to glRenderer object
 824+* @param index
 825+* Index of light to set
 826+* @param light
 827+* Pointer to light to change, ignored if remove is TRUE
 828+* @param remove
 829+* TRUE to clear a light from the renderer.
 830+*/
 831+
 832+void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
 833+{
 834+ EnterCriticalSection(&This->cs);
 835+ This->inputs[0] = (void*)index;
 836+ This->inputs[1] = light;
 837+ This->inputs[2] = (void*)remove;
 838+ This->opcode = OP_SETLIGHT;
 839+ SetEvent(This->start);
 840+ WaitForSingleObject(This->busy, INFINITE);
 841+ LeaveCriticalSection(&This->cs);
 842+}
 843+
 844+/**
 845+* Sets the viewport for the renderer.
 846+* @param This
 847+* Pointer to glRenderer object
 848+* @param lpViewport
 849+* New viewport parameters for renderer.
 850+*/
 851+void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport)
 852+{
 853+ EnterCriticalSection(&This->cs);
 854+ This->inputs[0] = lpViewport;
 855+ This->opcode = OP_SETVIEWPORT;
 856+ SetEvent(This->start);
 857+ WaitForSingleObject(This->busy, INFINITE);
 858+ LeaveCriticalSection(&This->cs);
 859+}
 860+
 861+/**
719862 * Main loop for glRenderer class
720863 * @param This
721864 * Pointer to glRenderer object
@@ -809,7 +952,7 @@
810953 (glDirectDrawSurface7*)This->inputs[2],(glDirectDrawSurface7*)This->inputs[3],(GLint)This->inputs[4],true);
811954 break;
812955 case OP_INITD3D:
813 - glRenderer__InitD3D(This,(int)This->inputs[0]);
 956+ glRenderer__InitD3D(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2]);
814957 break;
815958 case OP_CLEAR:
816959 memcpy(&tmpfloats[0],&This->inputs[5],4);
@@ -834,6 +977,28 @@
835978 glRenderer__DepthFill(This, (LPRECT)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1],
836979 (LPDDBLTFX)This->inputs[2]);
837980 break;
 981+ case OP_SETRENDERSTATE:
 982+ glRenderer__SetRenderState(This, (D3DRENDERSTATETYPE)(DWORD)This->inputs[0], (DWORD)This->inputs[1]);
 983+ break;
 984+ case OP_SETTEXTURE:
 985+ glRenderer__SetTexture(This, (DWORD)This->inputs[0], (glDirectDrawSurface7*)This->inputs[1]);
 986+ break;
 987+ case OP_SETTEXTURESTAGESTATE:
 988+ glRenderer__SetTextureStageState(This, (DWORD)This->inputs[0], (D3DTEXTURESTAGESTATETYPE)(DWORD)This->inputs[1],
 989+ (DWORD)This->inputs[2]);
 990+ break;
 991+ case OP_SETTRANSFORM:
 992+ glRenderer__SetTransform(This, (D3DTRANSFORMSTATETYPE)(DWORD)This->inputs[0], (LPD3DMATRIX)This->inputs[1]);
 993+ break;
 994+ case OP_SETMATERIAL:
 995+ glRenderer__SetMaterial(This, (LPD3DMATERIAL7)This->inputs[0]);
 996+ break;
 997+ case OP_SETLIGHT:
 998+ glRenderer__SetLight(This, (DWORD)This->inputs[0], (LPD3DLIGHT7)This->inputs[1], (BOOL)This->inputs[2]);
 999+ break;
 1000+ case OP_SETVIEWPORT:
 1001+ glRenderer__SetViewport(This, (LPD3DVIEWPORT7)This->inputs[0]);
 1002+ break;
8381003 }
8391004 }
8401005 return 0;
@@ -1632,8 +1797,102 @@
16331798 SetEvent(This->busy);
16341799 }
16351800
1636 -void glRenderer__InitD3D(glRenderer *This, int zbuffer)
 1801+__int64 InitShaderState(glRenderer *renderer, DWORD *renderstate, TEXTURESTAGE *texstages, D3DLIGHT7 *lights)
16371802 {
 1803+ int i;
 1804+ __int64 shader = 0;
 1805+ switch (renderstate[D3DRENDERSTATE_SHADEMODE])
 1806+ {
 1807+ case D3DSHADE_FLAT:
 1808+ default:
 1809+ break;
 1810+ case D3DSHADE_GOURAUD:
 1811+ shader |= 1;
 1812+ break;
 1813+ case D3DSHADE_PHONG:
 1814+ shader |= 3;
 1815+ break;
 1816+ }
 1817+ if (renderstate[D3DRENDERSTATE_ALPHATESTENABLE]) shader |= 4;
 1818+ shader |= ((((__int64)renderstate[D3DRENDERSTATE_ALPHAFUNC] - 1) & 7) << 3);
 1819+ shader |= (((__int64)renderstate[D3DRENDERSTATE_FOGTABLEMODE] & 3) << 6);
 1820+ shader |= (((__int64)renderstate[D3DRENDERSTATE_FOGVERTEXMODE] & 3) << 8);
 1821+ if (renderstate[D3DRENDERSTATE_RANGEFOGENABLE]) shader |= (1i64 << 10);
 1822+ if (renderstate[D3DRENDERSTATE_SPECULARENABLE]) shader |= (1i64 << 11);
 1823+ if (renderstate[D3DRENDERSTATE_STIPPLEDALPHA]) shader |= (1i64 << 12);
 1824+ if (renderstate[D3DRENDERSTATE_COLORKEYENABLE]) shader |= (1i64 << 13);
 1825+ shader |= (((__int64)renderstate[D3DRENDERSTATE_ZBIAS] & 15) << 14);
 1826+ int numlights = 0;
 1827+ for (i = 0; i < 8; i++)
 1828+ if (lights[i].dltType) numlights++;
 1829+ shader |= (__int64)numlights << 18;
 1830+ if (renderstate[D3DRENDERSTATE_LOCALVIEWER]) shader |= (1i64 << 21);
 1831+ if (renderstate[D3DRENDERSTATE_COLORKEYBLENDENABLE]) shader |= (1i64 << 22);
 1832+ shader |= (((__int64)renderstate[D3DRENDERSTATE_DIFFUSEMATERIALSOURCE] & 3) << 23);
 1833+ shader |= (((__int64)renderstate[D3DRENDERSTATE_SPECULARMATERIALSOURCE] & 3) << 25);
 1834+ shader |= (((__int64)renderstate[D3DRENDERSTATE_AMBIENTMATERIALSOURCE] & 3) << 27);
 1835+ shader |= (((__int64)renderstate[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE] & 3) << 29);
 1836+ int lightindex = 0;
 1837+ for (i = 0; i < 8; i++)
 1838+ {
 1839+ if (lights[i].dltType)
 1840+ {
 1841+ if (lights[i].dltType != D3DLIGHT_DIRECTIONAL)
 1842+ shader |= (1i64 << (38 + lightindex));
 1843+ if (lights[i].dltType == D3DLIGHT_SPOT)
 1844+ shader |= (1i64 << (51 + lightindex));
 1845+ lightindex++;
 1846+ }
 1847+ }
 1848+ if (renderstate[D3DRENDERSTATE_NORMALIZENORMALS]) shader |= (1i64 << 49);
 1849+ if (renderstate[D3DRENDERSTATE_TEXTUREMAPBLEND] == D3DTBLEND_MODULATE)
 1850+ {
 1851+ bool noalpha = false;;
 1852+ if (!texstages[0].texture) noalpha = true;
 1853+ if (texstages[0].texture)
 1854+ if (!(texstages[0].texture->ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS))
 1855+ noalpha = true;
 1856+ if (noalpha) texstages[0].alphaop = D3DTOP_SELECTARG2;
 1857+ else texstages[0].alphaop = D3DTOP_MODULATE;
 1858+ }
 1859+ if (renderstate[D3DRENDERSTATE_LIGHTING]) shader |= (1i64 << 59);
 1860+ if (renderstate[D3DRENDERSTATE_COLORVERTEX]) shader |= (1i64 << 60);
 1861+ if (renderstate[D3DRENDERSTATE_FOGENABLE]) shader |= (1i64 << 61);
 1862+ if (renderstate[D3DRENDERSTATE_DITHERENABLE]) shader |= (1i64 << 62);
 1863+ for (i = 0; i < 8; i++)
 1864+ {
 1865+ renderer->shaderstate3d.texstageid[i] = texstages[i].colorop & 31;
 1866+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].colorarg1 & 63) << 5;
 1867+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].colorarg2 & 63) << 11;
 1868+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].alphaop & 31) << 17;
 1869+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].alphaarg1 & 63) << 22;
 1870+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].alphaarg2 & 63) << 28;
 1871+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].texcoordindex & 7) << 34;
 1872+ renderer->shaderstate3d.texstageid[i] |= (__int64)((texstages[i].texcoordindex >> 16) & 3) << 37;
 1873+ renderer->shaderstate3d.texstageid[i] |= (__int64)((texstages[i].addressu - 1) & 3) << 39;
 1874+ renderer->shaderstate3d.texstageid[i] |= (__int64)((texstages[i].addressv - 1) & 3) << 41;
 1875+ //renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].magfilter & 7) << 43;
 1876+ //renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].minfilter & 3) << 46;
 1877+ //renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].mipfilter & 3) << 48;
 1878+ if (texstages[i].textransform & 7)
 1879+ {
 1880+ renderer->shaderstate3d.texstageid[i] |= 1i64 << 50;
 1881+ renderer->shaderstate3d.texstageid[i] |= (__int64)(((texstages[i].textransform & 7) - 1) & 3) << 51;
 1882+ }
 1883+ if (texstages[i].textransform & D3DTTFF_PROJECTED) renderer->shaderstate3d.texstageid[i] |= 1i64 << 53;
 1884+ renderer->shaderstate3d.texstageid[i] |= (__int64)(texstages[i].texcoordindex & 7) << 54;
 1885+ renderer->shaderstate3d.texstageid[i] |= (__int64)((texstages[i].texcoordindex >> 16) & 3) << 57;
 1886+ if (texstages[i].texture)
 1887+ {
 1888+ renderer->shaderstate3d.texstageid[i] |= 1i64 << 59;
 1889+ if (texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT) renderer->shaderstate3d.texstageid[i] |= 1i64 << 60;
 1890+ }
 1891+ }
 1892+ return shader;
 1893+}
 1894+
 1895+void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y)
 1896+{
16381897 SetEvent(This->busy);
16391898 glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
16401899 GLfloat ambient[] = {0.0,0.0,0.0,0.0};
@@ -1643,9 +1902,24 @@
16441903 __gluMakeIdentityf(identity);
16451904 This->util->SetMatrix(GL_MODELVIEW,identity,identity,NULL);
16461905 This->util->SetMatrix(GL_PROJECTION,identity,NULL,NULL);
 1906+ for (int i = 0; i < 24; i++)
 1907+ memcpy(&This->transform[i], identity, sizeof(D3DMATRIX));
16471908 GLfloat one[4] = {1,1,1,1};
16481909 GLfloat zero[4] = {0,0,0,1};
16491910 This->util->SetMaterial(one,one,zero,zero,0);
 1911+ ZeroMemory(&This->material, sizeof(D3DMATERIAL7));
 1912+ ZeroMemory(&This->lights, 8 * sizeof(D3DLIGHT7));
 1913+ memcpy(&This->renderstate, &renderstate_default, 153 * sizeof(DWORD));
 1914+ This->texstages[0] = texstagedefault0;
 1915+ This->texstages[1] = This->texstages[2] = This->texstages[3] = This->texstages[4] =
 1916+ This->texstages[5] = This->texstages[6] = This->texstages[7] = texstagedefault1;
 1917+ This->viewport.dwX = 0;
 1918+ This->viewport.dwY = 0;
 1919+ This->viewport.dwWidth = x;
 1920+ This->viewport.dwHeight = y;
 1921+ This->viewport.dvMinZ = 0.0f;
 1922+ This->viewport.dvMaxZ = 1.0f;
 1923+ This->shaderstate3d.stateid = InitShaderState(This, This->renderstate, This->texstages, This->lights);
16501924 }
16511925
16521926 void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
@@ -1861,22 +2135,34 @@
18622136 SetEvent(This->busy);
18632137 return;
18642138 }
1865 - __int64 shader = device->SelectShader(vertices);
1866 - ShaderManager_SetShader(This->shaders,shader,device->texstages,texformats,2);
1867 - device->SetDepthComp(This->util);
1868 - if(device->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
 2139+ This->shaderstate3d.stateid &= 0xFFFA3FFC7FFFFFFFi64;
 2140+ int numtextures = 0;
 2141+ for (i = 0; i < 8; i++)
 2142+ if (vertices[i + 10].data) numtextures++;
 2143+ This->shaderstate3d.stateid |= (__int64)numtextures << 31;
 2144+ int blendweights = 0;
 2145+ for (i = 0; i < 5; i++)
 2146+ if (vertices[i + 2].data) blendweights++;
 2147+ This->shaderstate3d.stateid |= (__int64)blendweights << 46;
 2148+ if (vertices[1].data) This->shaderstate3d.stateid |= (1i64 << 50);
 2149+ if (vertices[8].data) This->shaderstate3d.stateid |= (1i64 << 35);
 2150+ if (vertices[9].data) This->shaderstate3d.stateid |= (1i64 << 36);
 2151+ if (vertices[7].data) This->shaderstate3d.stateid |= (1i64 << 37);
 2152+ ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,texformats,2);
 2153+ glRenderer__SetDepthComp(This);
 2154+ if(This->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
18692155 else This->util->DepthTest(false);
1870 - if(device->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) This->util->DepthWrite(true);
 2156+ if(This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) This->util->DepthWrite(true);
18712157 else This->util->DepthWrite(false);
1872 - _GENSHADER prog = This->shaders->gen3d->genshaders[This->shaders->gen3d->current_genshader].shader;
1873 - This->util->EnableArray(prog.attribs[0],true);
1874 - This->ext->glVertexAttribPointer(prog.attribs[0],3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
 2158+ _GENSHADER *prog = &This->shaders->gen3d->genshaders[This->shaders->gen3d->current_genshader].shader;
 2159+ This->util->EnableArray(prog->attribs[0],true);
 2160+ This->ext->glVertexAttribPointer(prog->attribs[0],3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
18752161 if(transformed)
18762162 {
1877 - if(prog.attribs[1] != -1)
 2163+ if(prog->attribs[1] != -1)
18782164 {
1879 - This->util->EnableArray(prog.attribs[1],true);
1880 - This->ext->glVertexAttribPointer(prog.attribs[1],4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
 2165+ This->util->EnableArray(prog->attribs[1],true);
 2166+ This->ext->glVertexAttribPointer(prog->attribs[1],4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
18812167 }
18822168 }
18832169 for(i = 0; i < 5; i++)
@@ -1883,19 +2169,19 @@
18842170 {
18852171 if(vertices[i+2].data)
18862172 {
1887 - if(prog.attribs[i+2] != -1)
 2173+ if(prog->attribs[i+2] != -1)
18882174 {
1889 - This->util->EnableArray(prog.attribs[i+2],true);
1890 - This->ext->glVertexAttribPointer(prog.attribs[i+2],1,GL_FLOAT,false,vertices[i+2].stride,vertices[i+2].data);
 2175+ This->util->EnableArray(prog->attribs[i+2],true);
 2176+ This->ext->glVertexAttribPointer(prog->attribs[i+2],1,GL_FLOAT,false,vertices[i+2].stride,vertices[i+2].data);
18912177 }
18922178 }
18932179 }
18942180 if(vertices[7].data)
18952181 {
1896 - if(prog.attribs[7] != -1)
 2182+ if(prog->attribs[7] != -1)
18972183 {
1898 - This->util->EnableArray(prog.attribs[7],true);
1899 - This->ext->glVertexAttribPointer(prog.attribs[7],3,GL_FLOAT,false,vertices[7].stride,vertices[7].data);
 2184+ This->util->EnableArray(prog->attribs[7],true);
 2185+ This->ext->glVertexAttribPointer(prog->attribs[7],3,GL_FLOAT,false,vertices[7].stride,vertices[7].data);
19002186 }
19012187 }
19022188 for(i = 0; i < 2; i++)
@@ -1902,10 +2188,10 @@
19032189 {
19042190 if(vertices[i+8].data)
19052191 {
1906 - if(prog.attribs[8+i] != -1)
 2192+ if(prog->attribs[8+i] != -1)
19072193 {
1908 - This->util->EnableArray(prog.attribs[8+i],true);
1909 - This->ext->glVertexAttribPointer(prog.attribs[8+i],4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
 2194+ This->util->EnableArray(prog->attribs[8+i],true);
 2195+ This->ext->glVertexAttribPointer(prog->attribs[8+i],4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
19102196 }
19112197 }
19122198 }
@@ -1917,31 +2203,31 @@
19182204 case -1: // Null
19192205 break;
19202206 case 0: // st
1921 - if(prog.attribs[i+18] != -1)
 2207+ if(prog->attribs[i+18] != -1)
19222208 {
1923 - This->util->EnableArray(prog.attribs[i+18],true);
1924 - This->ext->glVertexAttribPointer(prog.attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2209+ This->util->EnableArray(prog->attribs[i+18],true);
 2210+ This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
19252211 }
19262212 break;
19272213 case 1: // str
1928 - if(prog.attribs[i+26] != -1)
 2214+ if(prog->attribs[i+26] != -1)
19292215 {
1930 - This->util->EnableArray(prog.attribs[i+26],true);
1931 - This->ext->glVertexAttribPointer(prog.attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2216+ This->util->EnableArray(prog->attribs[i+26],true);
 2217+ This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
19322218 }
19332219 break;
19342220 case 2: // strq
1935 - if(prog.attribs[i+34] != -1)
 2221+ if(prog->attribs[i+34] != -1)
19362222 {
1937 - This->util->EnableArray(prog.attribs[i+34],true);
1938 - This->ext->glVertexAttribPointer(prog.attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2223+ This->util->EnableArray(prog->attribs[i+34],true);
 2224+ This->ext->glVertexAttribPointer(prog->attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
19392225 }
19402226 break;
19412227 case 3: // s
1942 - if(prog.attribs[i+10] != -1)
 2228+ if(prog->attribs[i+10] != -1)
19432229 {
1944 - This->util->EnableArray(prog.attribs[i+10],true);
1945 - This->ext->glVertexAttribPointer(prog.attribs[i+10],1,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2230+ This->util->EnableArray(prog->attribs[i+10],true);
 2231+ This->ext->glVertexAttribPointer(prog->attribs[i+10],1,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
19462232 }
19472233 break;
19482234 }
@@ -1948,98 +2234,100 @@
19492235
19502236 }
19512237 }
1952 - if (device->modelview_dirty) This->util->SetMatrix(GL_MODELVIEW, device->matView, device->matWorld, &device->modelview_dirty);
1953 - if (device->projection_dirty) This->util->SetMatrix(GL_PROJECTION, device->matProjection, NULL, &device->projection_dirty);
 2238+ This->util->SetMatrix(GL_MODELVIEW, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_VIEW],
 2239+ (GLfloat*)&This->transform[D3DTRANSFORMSTATE_WORLD],NULL);
 2240+ This->util->SetMatrix(GL_PROJECTION, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_PROJECTION], NULL, NULL);
19542241
1955 - This->util->SetMaterial((GLfloat*)&device->material.ambient,(GLfloat*)&device->material.diffuse,(GLfloat*)&device->material.specular,
1956 - (GLfloat*)&device->material.emissive,device->material.power);
 2242+ This->util->SetMaterial((GLfloat*)&This->material.ambient,(GLfloat*)&This->material.diffuse,(GLfloat*)&This->material.specular,
 2243+ (GLfloat*)&This->material.emissive,This->material.power);
19572244
19582245 int lightindex = 0;
19592246 char lightname[] = "lightX.xxxxxxxxxxxxxxxx";
19602247 for(i = 0; i < 8; i++)
19612248 {
1962 - if(device->gllights[i] != -1)
 2249+ if(This->lights[i].dltType)
19632250 {
1964 - if(prog.uniforms[0] != -1) This->ext->glUniformMatrix4fv(prog.uniforms[0],1,false,device->matWorld);
1965 - if(prog.uniforms[20+(i*12)] != -1)
1966 - This->ext->glUniform4fv(prog.uniforms[20+(i*12)],1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvDiffuse);
1967 - if(prog.uniforms[21+(i*12)] != -1)
1968 - This->ext->glUniform4fv(prog.uniforms[21+(i*12)],1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvSpecular);
1969 - if(prog.uniforms[22+(i*12)] != -1)
1970 - This->ext->glUniform4fv(prog.uniforms[22+(i*12)],1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvAmbient);
1971 - if(prog.uniforms[24+(i*12)] != -1)
1972 - This->ext->glUniform3fv(prog.uniforms[24+(i*12)],1,(GLfloat*)&device->lights[device->gllights[i]]->light.dvDirection);
1973 - if(device->lights[device->gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
 2251+ if(prog->uniforms[0] != -1) This->ext->glUniformMatrix4fv(prog->uniforms[0],1,false,
 2252+ (GLfloat*)&This->transform[D3DTRANSFORMSTATE_WORLD]);
 2253+ if(prog->uniforms[20+(i*12)] != -1)
 2254+ This->ext->glUniform4fv(prog->uniforms[20+(i*12)],1,(GLfloat*)&This->lights[i].dcvDiffuse);
 2255+ if(prog->uniforms[21+(i*12)] != -1)
 2256+ This->ext->glUniform4fv(prog->uniforms[21+(i*12)],1,(GLfloat*)&This->lights[i].dcvSpecular);
 2257+ if(prog->uniforms[22+(i*12)] != -1)
 2258+ This->ext->glUniform4fv(prog->uniforms[22+(i*12)],1,(GLfloat*)&This->lights[i].dcvAmbient);
 2259+ if(prog->uniforms[24+(i*12)] != -1)
 2260+ This->ext->glUniform3fv(prog->uniforms[24+(i*12)],1,(GLfloat*)&This->lights[i].dvDirection);
 2261+ if(This->lights[i].dltType != D3DLIGHT_DIRECTIONAL)
19742262 {
1975 - if(prog.uniforms[23+(i*12)] != -1)
1976 - This->ext->glUniform3fv(prog.uniforms[23+(i*12)],1,(GLfloat*)&device->lights[device->gllights[i]]->light.dvPosition);
1977 - if(prog.uniforms[25+(i*12)] != -1)
1978 - This->ext->glUniform1f(prog.uniforms[25+(i*12)],device->lights[device->gllights[i]]->light.dvRange);
1979 - if(prog.uniforms[26+(i*12)] != -1)
1980 - This->ext->glUniform1f(prog.uniforms[26+(i*12)],device->lights[device->gllights[i]]->light.dvFalloff);
1981 - if(prog.uniforms[27+(i*12)] != -1)
1982 - This->ext->glUniform1f(prog.uniforms[27+(i*12)],device->lights[device->gllights[i]]->light.dvAttenuation0);
1983 - if(prog.uniforms[28+(i*12)] != -1)
1984 - This->ext->glUniform1f(prog.uniforms[28+(i*12)],device->lights[device->gllights[i]]->light.dvAttenuation1);
1985 - if(prog.uniforms[29+(i*12)] != -1)
1986 - This->ext->glUniform1f(prog.uniforms[29+(i*12)],device->lights[device->gllights[i]]->light.dvAttenuation2);
1987 - if(prog.uniforms[30+(i*12)] != -1)
1988 - This->ext->glUniform1f(prog.uniforms[30+(i*12)],device->lights[device->gllights[i]]->light.dvTheta);
1989 - if(prog.uniforms[31+(i*12)] != -1)
1990 - This->ext->glUniform1f(prog.uniforms[31+(i*12)],device->lights[device->gllights[i]]->light.dvPhi);
 2263+ if(prog->uniforms[23+(i*12)] != -1)
 2264+ This->ext->glUniform3fv(prog->uniforms[23+(i*12)],1,(GLfloat*)&This->lights[i].dvPosition);
 2265+ if(prog->uniforms[25+(i*12)] != -1)
 2266+ This->ext->glUniform1f(prog->uniforms[25+(i*12)],This->lights[i].dvRange);
 2267+ if(prog->uniforms[26+(i*12)] != -1)
 2268+ This->ext->glUniform1f(prog->uniforms[26+(i*12)],This->lights[i].dvFalloff);
 2269+ if(prog->uniforms[27+(i*12)] != -1)
 2270+ This->ext->glUniform1f(prog->uniforms[27+(i*12)],This->lights[i].dvAttenuation0);
 2271+ if(prog->uniforms[28+(i*12)] != -1)
 2272+ This->ext->glUniform1f(prog->uniforms[28+(i*12)],This->lights[i].dvAttenuation1);
 2273+ if(prog->uniforms[29+(i*12)] != -1)
 2274+ This->ext->glUniform1f(prog->uniforms[29+(i*12)],This->lights[i].dvAttenuation2);
 2275+ if(prog->uniforms[30+(i*12)] != -1)
 2276+ This->ext->glUniform1f(prog->uniforms[30+(i*12)],This->lights[i].dvTheta);
 2277+ if(prog->uniforms[31+(i*12)] != -1)
 2278+ This->ext->glUniform1f(prog->uniforms[31+(i*12)],This->lights[i].dvPhi);
19912279 }
19922280 }
19932281 lightindex++;
19942282 }
19952283
1996 - DWORD ambient = device->renderstate[D3DRENDERSTATE_AMBIENT];
1997 - if(prog.uniforms[136] != -1)
1998 - This->ext->glUniform4f(prog.uniforms[136],RGBA_GETRED(ambient),RGBA_GETGREEN(ambient),
 2284+ DWORD ambient = This->renderstate[D3DRENDERSTATE_AMBIENT];
 2285+ if(prog->uniforms[136] != -1)
 2286+ This->ext->glUniform4f(prog->uniforms[136],RGBA_GETRED(ambient),RGBA_GETGREEN(ambient),
19992287 RGBA_GETBLUE(ambient),RGBA_GETALPHA(ambient));
20002288 GLint keycolor[4];
20012289 for(i = 0; i < 8; i++)
20022290 {
2003 - if(device->texstages[i].colorop == D3DTOP_DISABLE) break;
2004 - if(device->texstages[i].texture)
 2291+ if(This->texstages[i].colorop == D3DTOP_DISABLE) break;
 2292+ if(This->texstages[i].texture)
20052293 {
2006 - if(device->texstages[i].texture->dirty & 1)
 2294+ if(This->texstages[i].texture->dirty & 1)
20072295 {
2008 - glRenderer__UploadTexture(This,device->texstages[i].texture->buffer,device->texstages[i].texture->bigbuffer,
2009 - device->texstages[i].texture->texture,device->texstages[i].texture->ddsd.dwWidth,
2010 - device->texstages[i].texture->ddsd.dwHeight,device->texstages[i].texture->fakex,
2011 - device->texstages[i].texture->fakey,device->texstages[i].texture->ddsd.lPitch,
2012 - (device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount/8*device->texstages[i].texture->fakex),
2013 - device->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount, device->texstages[i].texture->miplevel);
2014 - device->texstages[i].texture->dirty &= ~1;
 2296+ glRenderer__UploadTexture(This,This->texstages[i].texture->buffer,This->texstages[i].texture->bigbuffer,
 2297+ This->texstages[i].texture->texture,This->texstages[i].texture->ddsd.dwWidth,
 2298+ This->texstages[i].texture->ddsd.dwHeight,This->texstages[i].texture->fakex,
 2299+ This->texstages[i].texture->fakey,This->texstages[i].texture->ddsd.lPitch,
 2300+ (This->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount/8*This->texstages[i].texture->fakex),
 2301+ This->texstages[i].texture->ddsd.ddpfPixelFormat.dwRGBBitCount, This->texstages[i].texture->miplevel);
 2302+ This->texstages[i].texture->dirty &= ~1;
20152303 }
2016 - if(device->texstages[i].texture)
2017 - device->texstages[i].texture->SetFilter(i,device->texstages[i].glmagfilter,device->texstages[i].glminfilter,This->ext,This->texman);
2018 - TextureManager_SetTexture(This->texman,i,device->texstages[i].texture->texture);
2019 - This->util->SetWrap(i,0,device->texstages[i].addressu,This->texman);
2020 - This->util->SetWrap(i,1,device->texstages[i].addressv,This->texman);
 2304+ if(This->texstages[i].texture)
 2305+ This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->texman);
 2306+ TextureManager_SetTexture(This->texman,i,This->texstages[i].texture->texture);
 2307+ This->util->SetWrap(i,0,This->texstages[i].addressu,This->texman);
 2308+ This->util->SetWrap(i,1,This->texstages[i].addressv,This->texman);
20212309 }
20222310 TextureManager_SetTexture(This->texman,i,0);
2023 - This->ext->glUniform1i(prog.uniforms[128+i],i);
2024 - if(device->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && device->texstages[i].texture && (prog.uniforms[142+i] != -1))
 2311+ This->ext->glUniform1i(prog->uniforms[128+i],i);
 2312+ if(This->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && This->texstages[i].texture && (prog->uniforms[142+i] != -1))
20252313 {
2026 - if(device->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
 2314+ if(This->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
20272315 {
2028 - SetColorKeyUniform(device->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,
2029 - device->texstages[i].texture->texture->colorsizes, device->texstages[i].texture->texture->colororder,
2030 - prog.uniforms[142 + i], device->texstages[i].texture->texture->colorbits, This->ext);
2031 - This->ext->glUniform4i(prog.uniforms[153+i], device->texstages[i].texture->texture->colorsizes[0],
2032 - device->texstages[i].texture->texture->colorsizes[1],
2033 - device->texstages[i].texture->texture->colorsizes[2],
2034 - device->texstages[i].texture->texture->colorsizes[3]);
 2316+ SetColorKeyUniform(This->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,
 2317+ This->texstages[i].texture->texture->colorsizes, This->texstages[i].texture->texture->colororder,
 2318+ prog->uniforms[142 + i], This->texstages[i].texture->texture->colorbits, This->ext);
 2319+ This->ext->glUniform4i(prog->uniforms[153+i], This->texstages[i].texture->texture->colorsizes[0],
 2320+ This->texstages[i].texture->texture->colorsizes[1],
 2321+ This->texstages[i].texture->texture->colorsizes[2],
 2322+ This->texstages[i].texture->texture->colorsizes[3]);
20352323 }
20362324 }
20372325 }
2038 - if(prog.uniforms[137]!= -1) This->ext->glUniform1f(prog.uniforms[137],device->viewport.dwWidth);
2039 - if(prog.uniforms[138]!= -1) This->ext->glUniform1f(prog.uniforms[138],device->viewport.dwHeight);
2040 - if(prog.uniforms[139]!= -1) This->ext->glUniform1f(prog.uniforms[139],device->viewport.dwX);
2041 - if(prog.uniforms[140]!= -1) This->ext->glUniform1f(prog.uniforms[140],device->viewport.dwY);
2042 - if(prog.uniforms[141]!= -1) This->ext->glUniform1i(prog.uniforms[141],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
2043 - if(prog.uniforms[150]!= -1) This->ext->glUniform4iv(prog.uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
 2326+ if(prog->uniforms[137]!= -1) This->ext->glUniform1f(prog->uniforms[137],This->viewport.dwWidth);
 2327+ if(prog->uniforms[138]!= -1) This->ext->glUniform1f(prog->uniforms[138],This->viewport.dwHeight);
 2328+ if(prog->uniforms[139]!= -1) This->ext->glUniform1f(prog->uniforms[139],This->viewport.dwX);
 2329+ if(prog->uniforms[140]!= -1) This->ext->glUniform1f(prog->uniforms[140],This->viewport.dwY);
 2330+ if(prog->uniforms[141]!= -1) This->ext->glUniform1i(prog->uniforms[141],This->renderstate[D3DRENDERSTATE_ALPHAREF]);
 2331+ if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
20442332 do
20452333 {
20462334 if (This->util->SetFBO(device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
@@ -2050,21 +2338,21 @@
20512339 device->glDDS7->fbo.fbcolor = NULL;
20522340 device->glDDS7->fbo.fbz = NULL;
20532341 } while (1);
2054 - This->util->SetViewport((int)((float)device->viewport.dwX*device->glDDS7->mulx),
2055 - (int)((float)device->viewport.dwY*device->glDDS7->muly),
2056 - (int)((float)device->viewport.dwWidth*device->glDDS7->mulx),
2057 - (int)((float)device->viewport.dwHeight*device->glDDS7->muly));
2058 - This->util->SetDepthRange(device->viewport.dvMinZ,device->viewport.dvMaxZ);
2059 - if(device->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) This->util->BlendEnable(true);
 2342+ This->util->SetViewport((int)((float)This->viewport.dwX*device->glDDS7->mulx),
 2343+ (int)((float)This->viewport.dwY*device->glDDS7->muly),
 2344+ (int)((float)This->viewport.dwWidth*device->glDDS7->mulx),
 2345+ (int)((float)This->viewport.dwHeight*device->glDDS7->muly));
 2346+ This->util->SetDepthRange(This->viewport.dvMinZ,This->viewport.dvMaxZ);
 2347+ if(This->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) This->util->BlendEnable(true);
20602348 else This->util->BlendEnable(false);
2061 - glRenderer__SetBlend(This,device->renderstate[D3DRENDERSTATE_SRCBLEND],device->renderstate[D3DRENDERSTATE_DESTBLEND]);
2062 - This->util->SetCull((D3DCULL)device->renderstate[D3DRENDERSTATE_CULLMODE]);
2063 - glRenderer__SetFogColor(This,device->renderstate[D3DRENDERSTATE_FOGCOLOR]);
2064 - glRenderer__SetFogStart(This,*(GLfloat*)(&device->renderstate[D3DRENDERSTATE_FOGSTART]));
2065 - glRenderer__SetFogEnd(This,*(GLfloat*)(&device->renderstate[D3DRENDERSTATE_FOGEND]));
2066 - glRenderer__SetFogDensity(This,*(GLfloat*)(&device->renderstate[D3DRENDERSTATE_FOGDENSITY]));
2067 - This->util->SetPolyMode((D3DFILLMODE)device->renderstate[D3DRENDERSTATE_FILLMODE]);
2068 - This->util->SetShadeMode((D3DSHADEMODE)device->renderstate[D3DRENDERSTATE_SHADEMODE]);
 2349+ glRenderer__SetBlend(This,This->renderstate[D3DRENDERSTATE_SRCBLEND],This->renderstate[D3DRENDERSTATE_DESTBLEND]);
 2350+ This->util->SetCull((D3DCULL)This->renderstate[D3DRENDERSTATE_CULLMODE]);
 2351+ glRenderer__SetFogColor(This,This->renderstate[D3DRENDERSTATE_FOGCOLOR]);
 2352+ glRenderer__SetFogStart(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGSTART]));
 2353+ glRenderer__SetFogEnd(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGEND]));
 2354+ glRenderer__SetFogDensity(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGDENSITY]));
 2355+ This->util->SetPolyMode((D3DFILLMODE)This->renderstate[D3DRENDERSTATE_FILLMODE]);
 2356+ This->util->SetShadeMode((D3DSHADEMODE)This->renderstate[D3DRENDERSTATE_SHADEMODE]);
20692357 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
20702358 else glDrawArrays(mode,0,count);
20712359 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
@@ -2182,6 +2470,371 @@
21832471 SetEvent(This->busy);
21842472 }
21852473
 2474+void glRenderer__SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
 2475+{
 2476+ SetEvent(This->busy);
 2477+ if (This->renderstate[dwRendStateType] == dwRenderState) return;
 2478+ This->renderstate[dwRendStateType] = dwRenderState;
 2479+ switch (dwRendStateType)
 2480+ {
 2481+ case D3DRENDERSTATE_SHADEMODE:
 2482+ This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFFFCi64;
 2483+ switch (dwRenderState)
 2484+ {
 2485+ case D3DSHADE_FLAT:
 2486+ default:
 2487+ break;
 2488+ case D3DSHADE_GOURAUD:
 2489+ This->shaderstate3d.stateid |= 1;
 2490+ break;
 2491+ case D3DSHADE_PHONG:
 2492+ This->shaderstate3d.stateid |= 3;
 2493+ break;
 2494+ }
 2495+ break;
 2496+ case D3DRENDERSTATE_ALPHATESTENABLE:
 2497+ if (dwRenderState) This->shaderstate3d.stateid |= 4;
 2498+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFFFBi64;
 2499+ break;
 2500+ case D3DRENDERSTATE_ALPHAFUNC:
 2501+ This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFFC7i64;
 2502+ This->shaderstate3d.stateid |= ((((__int64)dwRenderState - 1) & 7) << 3);
 2503+ break;
 2504+ case D3DRENDERSTATE_FOGTABLEMODE:
 2505+ This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFF3Fi64;
 2506+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 6);
 2507+ break;
 2508+ case D3DRENDERSTATE_FOGVERTEXMODE:
 2509+ This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFCFFi64;
 2510+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 8);
 2511+ break;
 2512+ case D3DRENDERSTATE_RANGEFOGENABLE:
 2513+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 10);
 2514+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFFBFFi64;
 2515+ break;
 2516+ case D3DRENDERSTATE_SPECULARENABLE:
 2517+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 11);
 2518+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFF7FFi64;
 2519+ break;
 2520+ case D3DRENDERSTATE_STIPPLEDALPHA:
 2521+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 12);
 2522+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFEFFFi64;
 2523+ break;
 2524+ case D3DRENDERSTATE_COLORKEYENABLE:
 2525+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 13);
 2526+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFFFDFFFi64;
 2527+ break;
 2528+ case D3DRENDERSTATE_LOCALVIEWER:
 2529+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 21);
 2530+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFDFFFFFi64;
 2531+ break;
 2532+ case D3DRENDERSTATE_COLORKEYBLENDENABLE:
 2533+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 22);
 2534+ else This->shaderstate3d.stateid &= 0xFFFFFFFFFFBFFFFFi64;
 2535+ break;
 2536+ case D3DRENDERSTATE_DIFFUSEMATERIALSOURCE:
 2537+ This->shaderstate3d.stateid &= 0xFFFFFFFFFE7FFFFFi64;
 2538+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 23);
 2539+ break;
 2540+ case D3DRENDERSTATE_SPECULARMATERIALSOURCE:
 2541+ This->shaderstate3d.stateid &= 0xFFFFFFFFF9FFFFFFi64;
 2542+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 25);
 2543+ break;
 2544+ case D3DRENDERSTATE_AMBIENTMATERIALSOURCE:
 2545+ This->shaderstate3d.stateid &= 0xFFFFFFFFE7FFFFFFi64;
 2546+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 27);
 2547+ break;
 2548+ case D3DRENDERSTATE_EMISSIVEMATERIALSOURCE:
 2549+ This->shaderstate3d.stateid &= 0xFFFFFFFFBFFFFFFFi64;
 2550+ This->shaderstate3d.stateid |= (((__int64)dwRenderState & 3) << 29);
 2551+ break;
 2552+ case D3DRENDERSTATE_NORMALIZENORMALS:
 2553+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 49);
 2554+ else This->shaderstate3d.stateid &= 0xFFFDFFFFFFFFFFFFi64;
 2555+ break;
 2556+ case D3DRENDERSTATE_LIGHTING:
 2557+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 59);
 2558+ else This->shaderstate3d.stateid &= 0xF7FFFFFFFFFFFFFFi64;
 2559+ break;
 2560+ case D3DRENDERSTATE_COLORVERTEX:
 2561+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 60);
 2562+ else This->shaderstate3d.stateid &= 0xEFFFFFFFFFFFFFFFi64;
 2563+ break;
 2564+ case D3DRENDERSTATE_FOGENABLE:
 2565+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 61);
 2566+ else This->shaderstate3d.stateid &= 0xDFFFFFFFFFFFFFFFi64;
 2567+ break;
 2568+ case D3DRENDERSTATE_DITHERENABLE:
 2569+ if (dwRenderState) This->shaderstate3d.stateid |= (1i64 << 62);
 2570+ else This->shaderstate3d.stateid &= 0xBFFFFFFFFFFFFFFFi64;
 2571+ break;
 2572+ default:
 2573+ break;
 2574+ }
 2575+}
 2576+
 2577+void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture)
 2578+{
 2579+ if (This->texstages[dwStage].texture == Texture)
 2580+ {
 2581+ SetEvent(This->busy);
 2582+ return;
 2583+ }
 2584+ This->texstages[dwStage].texture = Texture;
 2585+ if (Texture)
 2586+ {
 2587+ This->shaderstate3d.texstageid[dwStage] |= 1i64 << 59;
 2588+ if (Texture->ddsd.dwFlags & DDSD_CKSRCBLT) This->shaderstate3d.texstageid[dwStage] |= 1i64 << 60;
 2589+ else This->shaderstate3d.texstageid[dwStage] &= 0xEFFFFFFFFFFFFFFFi64;
 2590+ }
 2591+ else This->shaderstate3d.texstageid[dwStage] &= 0xE7FFFFFFFFFFFFFFi64;
 2592+ SetEvent(This->busy);
 2593+}
 2594+
 2595+void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
 2596+{
 2597+ SetEvent(This->busy);
 2598+ switch (dwState)
 2599+ {
 2600+ case D3DTSS_COLOROP:
 2601+ This->texstages[dwStage].colorop = (D3DTEXTUREOP)dwValue;
 2602+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFFFFFFFFE0i64;
 2603+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)dwValue & 31);
 2604+ break;
 2605+ case D3DTSS_COLORARG1:
 2606+ This->texstages[dwStage].colorarg1 = dwValue;
 2607+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFFFFFFF81Fi64;
 2608+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 63) << 5);
 2609+ break;
 2610+ case D3DTSS_COLORARG2:
 2611+ This->texstages[dwStage].colorarg2 = dwValue;
 2612+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFFFFFE07FFi64;
 2613+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 63) << 11);
 2614+ break;
 2615+ case D3DTSS_ALPHAOP:
 2616+ This->texstages[dwStage].alphaop = (D3DTEXTUREOP)dwValue;
 2617+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFFFFC1FFFFi64;
 2618+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 31) << 17);
 2619+ break;
 2620+ case D3DTSS_ALPHAARG1:
 2621+ This->texstages[dwStage].alphaarg1 = dwValue;
 2622+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFFF03FFFFFi64;
 2623+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 63) << 22);
 2624+ break;
 2625+ case D3DTSS_ALPHAARG2:
 2626+ This->texstages[dwStage].alphaarg2 = dwValue;
 2627+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFFFC0FFFFFFFi64;
 2628+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 63) << 28);
 2629+ break;
 2630+ case D3DTSS_BUMPENVMAT00:
 2631+ This->texstages[dwStage].bumpenv00 = dwValue;
 2632+ break;
 2633+ case D3DTSS_BUMPENVMAT01:
 2634+ This->texstages[dwStage].bumpenv01 = dwValue;
 2635+ break;
 2636+ case D3DTSS_BUMPENVMAT10:
 2637+ This->texstages[dwStage].bumpenv10 = dwValue;
 2638+ break;
 2639+ case D3DTSS_BUMPENVMAT11:
 2640+ This->texstages[dwStage].bumpenv11 = dwValue;
 2641+ break;
 2642+ case D3DTSS_TEXCOORDINDEX:
 2643+ This->texstages[dwStage].texcoordindex = dwValue;
 2644+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFF83FFFFFFFFi64;
 2645+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 7) << 34);
 2646+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)((dwValue>>16) & 7) << 37);
 2647+ break;
 2648+ case D3DTSS_ADDRESSU:
 2649+ This->texstages[dwStage].addressu = (D3DTEXTUREADDRESS)dwValue;
 2650+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFFE7FFFFFFFFFi64;
 2651+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 3) << 39);
 2652+ break;
 2653+ case D3DTSS_ADDRESSV:
 2654+ This->texstages[dwStage].addressv = (D3DTEXTUREADDRESS)dwValue;
 2655+ This->shaderstate3d.texstageid[dwStage] &= 0xFFFFF9FFFFFFFFFFi64;
 2656+ This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 3) << 41);
 2657+ break;
 2658+ case D3DTSS_BORDERCOLOR:
 2659+ This->texstages[dwStage].bordercolor = dwValue;
 2660+ break;
 2661+ case D3DTSS_MAGFILTER:
 2662+ This->texstages[dwStage].magfilter = (D3DTEXTUREMAGFILTER)dwValue;
 2663+ //This->shaderstate3d.texstageid[dwStage] &= 0xFFFFC7FFFFFFFFFFi64;
 2664+ //This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 7) << 43);
 2665+ switch (This->texstages[dwStage].magfilter)
 2666+ {
 2667+ case 1:
 2668+ default:
 2669+ This->texstages[dwStage].glmagfilter = GL_NEAREST;
 2670+ break;
 2671+ case 2:
 2672+ case 3:
 2673+ case 4:
 2674+ case 5:
 2675+ This->texstages[dwStage].glmagfilter = GL_LINEAR;
 2676+ break;
 2677+ }
 2678+ break;
 2679+ case D3DTSS_MINFILTER:
 2680+ This->texstages[dwStage].minfilter = (D3DTEXTUREMINFILTER)dwValue;
 2681+ //This->shaderstate3d.texstageid[dwStage] &= 0xFFFF3FFFFFFFFFFFi64;
 2682+ //This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 7) << 46);
 2683+ switch (This->texstages[dwStage].minfilter)
 2684+ {
 2685+ case 1:
 2686+ default:
 2687+ switch (This->texstages[dwStage].mipfilter)
 2688+ {
 2689+ case 1:
 2690+ default:
 2691+ This->texstages[dwStage].glminfilter = GL_NEAREST;
 2692+ break;
 2693+ case 2:
 2694+ This->texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
 2695+ break;
 2696+ case 3:
 2697+ This->texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
 2698+ break;
 2699+ }
 2700+ break;
 2701+ case 2:
 2702+ case 3:
 2703+ switch (This->texstages[dwStage].mipfilter)
 2704+ {
 2705+ case 1:
 2706+ default:
 2707+ This->texstages[dwStage].glminfilter = GL_LINEAR;
 2708+ break;
 2709+ case 2:
 2710+ This->texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
 2711+ break;
 2712+ case 3:
 2713+ This->texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
 2714+ break;
 2715+ }
 2716+ break;
 2717+ }
 2718+ break;
 2719+ case D3DTSS_MIPFILTER:
 2720+ This->texstages[dwStage].mipfilter = (D3DTEXTUREMIPFILTER)dwValue;
 2721+ //This->shaderstate3d.texstageid[dwStage] &= 0xFFFCFFFFFFFFFFFFi64;
 2722+ //This->shaderstate3d.texstageid[dwStage] |= ((__int64)(dwValue & 7) << 48);
 2723+ switch (This->texstages[dwStage].mipfilter)
 2724+ {
 2725+ case 1:
 2726+ default:
 2727+ switch (This->texstages[dwStage].minfilter)
 2728+ {
 2729+ case 1:
 2730+ default:
 2731+ This->texstages[dwStage].glminfilter = GL_NEAREST;
 2732+ case 2:
 2733+ case 3:
 2734+ This->texstages[dwStage].glminfilter = GL_LINEAR;
 2735+ }
 2736+ break;
 2737+ case 2:
 2738+ switch (This->texstages[dwStage].minfilter)
 2739+ {
 2740+ case 1:
 2741+ default:
 2742+ This->texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_NEAREST;
 2743+ case 2:
 2744+ case 3:
 2745+ This->texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_NEAREST;
 2746+ }
 2747+ break;
 2748+ case 3:
 2749+ switch (This->texstages[dwStage].minfilter)
 2750+ {
 2751+ case 1:
 2752+ default:
 2753+ This->texstages[dwStage].glminfilter = GL_NEAREST_MIPMAP_LINEAR;
 2754+ case 2:
 2755+ case 3:
 2756+ This->texstages[dwStage].glminfilter = GL_LINEAR_MIPMAP_LINEAR;
 2757+ }
 2758+ break;
 2759+ }
 2760+ break;
 2761+ case D3DTSS_MIPMAPLODBIAS:
 2762+ memcpy(&This->texstages[dwStage].lodbias, &dwValue, sizeof(D3DVALUE));
 2763+ break;
 2764+ case D3DTSS_MAXMIPLEVEL:
 2765+ This->texstages[dwStage].miplevel = dwValue;
 2766+ break;
 2767+ case D3DTSS_MAXANISOTROPY:
 2768+ This->texstages[dwStage].anisotropy = dwValue;
 2769+ break;
 2770+ case D3DTSS_BUMPENVLSCALE:
 2771+ memcpy(&This->texstages[dwStage].bumpenvlscale, &dwValue, sizeof(D3DVALUE));
 2772+ break;
 2773+ case D3DTSS_BUMPENVLOFFSET:
 2774+ memcpy(&This->texstages[dwStage].bumpenvloffset, &dwValue, sizeof(D3DVALUE));
 2775+ break;
 2776+ case D3DTSS_TEXTURETRANSFORMFLAGS:
 2777+ This->texstages[dwStage].textransform = (D3DTEXTURETRANSFORMFLAGS)dwValue;
 2778+ This->shaderstate3d.texstageid[dwStage] &= 0xFFC3FFFFFFFFFFFFi64;
 2779+ if (dwValue & 7)
 2780+ {
 2781+ This->shaderstate3d.texstageid[dwStage] |= 1i64 << 50;
 2782+ This->shaderstate3d.texstageid[dwStage] |= (__int64)(((dwValue & 7) - 1) & 3) << 51;
 2783+ }
 2784+ if (dwValue & D3DTTFF_PROJECTED) This->shaderstate3d.texstageid[dwStage] |= 1i64 << 53;
 2785+ break;
 2786+ default:
 2787+ break;
 2788+ }
 2789+}
 2790+
 2791+void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
 2792+{
 2793+ if (dtstTransformStateType > 23)
 2794+ {
 2795+ SetEvent(This->busy);
 2796+ return;
 2797+ }
 2798+ memcpy(&This->transform[dtstTransformStateType], lpD3DMatrix, sizeof(D3DMATRIX));
 2799+ SetEvent(This->busy);
 2800+}
 2801+
 2802+void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial)
 2803+{
 2804+ memcpy(&This->material, lpMaterial, sizeof(D3DMATERIAL));
 2805+ SetEvent(This->busy);
 2806+}
 2807+
 2808+void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
 2809+{
 2810+ int numlights = 0;
 2811+ int lightindex = 0;
 2812+ if(!remove)memcpy(&This->lights[index], light, sizeof(D3DLIGHT7));
 2813+ else ZeroMemory(&This->lights[index], sizeof(D3DLIGHT7));
 2814+ SetEvent(This->busy);
 2815+ for (int i = 0; i < 8; i++)
 2816+ if (This->lights[i].dltType) numlights++;
 2817+ This->shaderstate3d.stateid &= 0xF807C03FFFE3FFFFi64;
 2818+ This->shaderstate3d.stateid |= ((__int64)numlights << 18);
 2819+ for (int i = 0; i < 8; i++)
 2820+ {
 2821+ if (This->lights[i].dltType != 1)
 2822+ {
 2823+ if (This->lights[i].dltType != D3DLIGHT_DIRECTIONAL)
 2824+ This->shaderstate3d.stateid |= (1i64 << (38 + lightindex));
 2825+ if (This->lights[i].dltType == D3DLIGHT_SPOT)
 2826+ This->shaderstate3d.stateid |= (1i64 << (51 + lightindex));
 2827+ lightindex++;
 2828+ }
 2829+ }
 2830+
 2831+}
 2832+
 2833+void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport)
 2834+{
 2835+ memcpy(&This->viewport, lpViewport, sizeof(D3DVIEWPORT7));
 2836+ SetEvent(This->busy);
 2837+}
 2838+
21862839 void glRenderer__SetFogColor(glRenderer *This, DWORD color)
21872840 {
21882841 if (color == This->fogcolor) return;
@@ -2215,4 +2868,36 @@
22162869 glFogf(GL_FOG_DENSITY, density);
22172870 }
22182871
 2872+void glRenderer__SetDepthComp(glRenderer *This)
 2873+{
 2874+ switch (This->renderstate[D3DRENDERSTATE_ZFUNC])
 2875+ {
 2876+ case D3DCMP_NEVER:
 2877+ This->util->SetDepthComp(GL_NEVER);
 2878+ break;
 2879+ case D3DCMP_LESS:
 2880+ This->util->SetDepthComp(GL_LESS);
 2881+ break;
 2882+ case D3DCMP_EQUAL:
 2883+ This->util->SetDepthComp(GL_EQUAL);
 2884+ break;
 2885+ case D3DCMP_LESSEQUAL:
 2886+ This->util->SetDepthComp(GL_LEQUAL);
 2887+ break;
 2888+ case D3DCMP_GREATER:
 2889+ This->util->SetDepthComp(GL_GREATER);
 2890+ break;
 2891+ case D3DCMP_NOTEQUAL:
 2892+ This->util->SetDepthComp(GL_NOTEQUAL);
 2893+ break;
 2894+ case D3DCMP_GREATEREQUAL:
 2895+ This->util->SetDepthComp(GL_GEQUAL);
 2896+ break;
 2897+ case D3DCMP_ALWAYS:
 2898+ default:
 2899+ This->util->SetDepthComp(GL_ALWAYS);
 2900+ break;
 2901+ }
 2902+}
 2903+
22192904 }
\ No newline at end of file
Index: ddraw/glRenderer.h
@@ -51,6 +51,42 @@
5252 int stride;
5353 } GLVERTEX;
5454
 55+typedef struct
 56+{
 57+ __int64 stateid;
 58+ __int64 texstageid[8];
 59+} SHADERSTATE;
 60+
 61+struct TEXTURESTAGE
 62+{
 63+ D3DTEXTUREOP colorop;
 64+ DWORD colorarg1;
 65+ DWORD colorarg2;
 66+ D3DTEXTUREOP alphaop;
 67+ DWORD alphaarg1;
 68+ DWORD alphaarg2;
 69+ D3DVALUE bumpenv00;
 70+ D3DVALUE bumpenv01;
 71+ D3DVALUE bumpenv10;
 72+ D3DVALUE bumpenv11;
 73+ DWORD texcoordindex;
 74+ D3DTEXTUREADDRESS addressu;
 75+ D3DTEXTUREADDRESS addressv;
 76+ DWORD bordercolor;
 77+ D3DTEXTUREMAGFILTER magfilter;
 78+ D3DTEXTUREMINFILTER minfilter;
 79+ D3DTEXTUREMIPFILTER mipfilter;
 80+ D3DVALUE lodbias;
 81+ DWORD miplevel;
 82+ DWORD anisotropy;
 83+ D3DVALUE bumpenvlscale;
 84+ D3DVALUE bumpenvloffset;
 85+ D3DTEXTURETRANSFORMFLAGS textransform;
 86+ glDirectDrawSurface7 *texture;
 87+ GLint glmagfilter;
 88+ GLint glminfilter;
 89+};
 90+
5591 #define OP_NULL 0
5692 #define OP_SETWND 1
5793 #define OP_DELETE 2
@@ -67,7 +103,18 @@
68104 #define OP_DELETEFBO 13
69105 #define OP_UPDATECLIPPER 14
70106 #define OP_DEPTHFILL 15
 107+#define OP_SETRENDERSTATE 16
 108+#define OP_SETTEXTURE 17
 109+#define OP_SETTEXTURESTAGESTATE 18
 110+#define OP_SETTRANSFORM 19
 111+#define OP_SETMATERIAL 20
 112+#define OP_SETLIGHT 21
 113+#define OP_SETVIEWPORT 22
71114
 115+extern const DWORD renderstate_default[153];
 116+extern const TEXTURESTAGE texstagedefault0;
 117+extern const TEXTURESTAGE texstagedefault1;
 118+
72119 #ifdef __cplusplus
73120 class glDirectDraw7;
74121 class glDirect3DDevice7;
@@ -117,6 +164,13 @@
118165 TextureManager *texman;
119166 glUtil *util;
120167 ShaderManager *shaders;
 168+ DWORD renderstate[153];
 169+ SHADERSTATE shaderstate3d;
 170+ TEXTURESTAGE texstages[8];
 171+ D3DMATERIAL7 material;
 172+ D3DLIGHT7 lights[8];
 173+ D3DMATRIX transform[24];
 174+ D3DVIEWPORT7 viewport;
121175 } glRenderer;
122176
123177 void glRenderer_Init(glRenderer *This, int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
@@ -129,7 +183,7 @@
130184 void glRenderer_MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height);
131185 void glRenderer_DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync);
132186 void glRenderer_DeleteTexture(glRenderer *This, TEXTURE *texture);
133 -void glRenderer_InitD3D(glRenderer *This, int zbuffer);
 187+void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y);
134188 void glRenderer_Flush(glRenderer *This);
135189 void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd);
136190 HRESULT glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
@@ -139,6 +193,13 @@
140194 void glRenderer_UpdateClipper(glRenderer *This, glDirectDrawSurface7 *surface);
141195 unsigned int glRenderer_GetScanLine(glRenderer *This);
142196 HRESULT glRenderer_DepthFill(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *dest, LPDDBLTFX lpDDBltFx);
 197+void glRenderer_SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
 198+void glRenderer_SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
 199+void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
 200+void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
 201+void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
 202+void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
 203+void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
143204 // In-thread APIs
144205 DWORD glRenderer__Entry(glRenderer *This);
145206 BOOL glRenderer__InitGL(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7);
@@ -151,7 +212,7 @@
152213 void glRenderer__DeleteTexture(glRenderer *This, TEXTURE *texture);
153214 void glRenderer__DrawBackbuffer(glRenderer *This, TEXTURE **texture, int x, int y, int progtype);
154215 void glRenderer__DrawBackbufferRect(glRenderer *This, TEXTURE *texture, RECT srcrect, int progtype);
155 -void glRenderer__InitD3D(glRenderer *This, int zbuffer);
 216+void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
156217 void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
157218 void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
158219 DWORD indexcount, DWORD flags);
@@ -166,6 +227,14 @@
167228 void glRenderer__SetFogDensity(glRenderer *This, GLfloat density);
168229 inline void glRenderer__SetSwap(glRenderer *This, int swap);
169230 void glRenderer__SetBlend(glRenderer *This, DWORD src, DWORD dest);
 231+void glRenderer__SetRenderState(glRenderer *This, D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState);
 232+void glRenderer__SetTexture(glRenderer *This, DWORD dwStage, glDirectDrawSurface7 *Texture);
 233+void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
 234+void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
 235+void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
 236+void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
 237+void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
 238+void glRenderer__SetDepthComp(glRenderer *This);
170239
171240 #ifdef __cplusplus
172241 }