DXGL r686 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r685‎ | r686 | r687 >
Date:00:46, 19 September 2016
Author:admin
Status:new
Tags:
Comment:
Use separate commands for setting and removing D3D light states.
More planning for the new renderer.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /ddraw/struct_command.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -1284,7 +1284,7 @@
12851285 {
12861286 foundlight = true;
12871287 gllights[i] = dwLightIndex;
1288 - glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light, FALSE);
 1288+ glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light);
12891289 break;
12901290 }
12911291 }
@@ -1297,7 +1297,7 @@
12981298 if(gllights[i] == dwLightIndex)
12991299 {
13001300 gllights[i] = -1;
1301 - glRenderer_SetLight(renderer, i, NULL, TRUE);
 1301+ glRenderer_RemoveLight(renderer, i);
13021302 }
13031303 }
13041304 TRACE_EXIT(23,D3D_OK);
@@ -1363,7 +1363,7 @@
13641364 lights[dwLightIndex]->SetLight7(lpLight);
13651365 for (int i = 0; i < 8; i++)
13661366 {
1367 - if (gllights[i] == dwLightIndex) glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light, FALSE);
 1367+ if (gllights[i] == dwLightIndex) glRenderer_SetLight(renderer, i, &lights[gllights[i]]->light);
13681368 }
13691369 TRACE_EXIT(23,D3D_OK);
13701370 return D3D_OK;
Index: ddraw/glRenderer.cpp
@@ -979,7 +979,7 @@
980980 * @param This
981981 * Pointer to glRenderer object
982982 * @param dwStage
983 - * Texture stage to bind
 983+ * Texture stage to bind (8 through 11 are reserved for 2D drawing)
984984 * @param Texture
985985 * Texture to bind to the stage; NULL to unbind
986986 */
@@ -1062,16 +1062,13 @@
10631063 * Index of light to set
10641064 * @param light
10651065 * Pointer to light to change, ignored if remove is TRUE
1066 - * @param remove
1067 - * TRUE to clear a light from the renderer.
10681066 */
10691067
1070 -void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
 1068+void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light)
10711069 {
10721070 EnterCriticalSection(&This->cs);
10731071 This->inputs[0] = (void*)index;
10741072 This->inputs[1] = light;
1075 - This->inputs[2] = (void*)remove;
10761073 This->opcode = OP_SETLIGHT;
10771074 SetEvent(This->start);
10781075 WaitForSingleObject(This->busy, INFINITE);
@@ -1079,6 +1076,23 @@
10801077 }
10811078
10821079 /**
 1080+ * Removes a light from the renderer.
 1081+ * @param This
 1082+ * Pointer to glRenderer object
 1083+ * @param index
 1084+ * Index of light to remove
 1085+ */
 1086+void glRenderer_RemoveLight(glRenderer *This, DWORD index)
 1087+{
 1088+ EnterCriticalSection(&This->cs);
 1089+ This->inputs[0] = (void*)index;
 1090+ This->opcode = OP_REMOVELIGHT;
 1091+ SetEvent(This->start);
 1092+ WaitForSingleObject(This->busy, INFINITE);
 1093+ LeaveCriticalSection(&This->cs);
 1094+}
 1095+
 1096+/**
10831097 * Sets the viewport for the renderer.
10841098 * @param This
10851099 * Pointer to glRenderer object
@@ -1307,8 +1321,11 @@
13081322 glRenderer__SetMaterial(This, (LPD3DMATERIAL7)This->inputs[0]);
13091323 break;
13101324 case OP_SETLIGHT:
1311 - glRenderer__SetLight(This, (DWORD)This->inputs[0], (LPD3DLIGHT7)This->inputs[1], (BOOL)This->inputs[2]);
 1325+ glRenderer__SetLight(This, (DWORD)This->inputs[0], (LPD3DLIGHT7)This->inputs[1]);
13121326 break;
 1327+ case OP_REMOVELIGHT:
 1328+ glRenderer__RemoveLight(This, (DWORD)This->inputs[0]);
 1329+ break;
13131330 case OP_SETVIEWPORT:
13141331 glRenderer__SetViewport(This, (LPD3DVIEWPORT7)This->inputs[0]);
13151332 break;
@@ -3207,12 +3224,11 @@
32083225 SetEvent(This->busy);
32093226 }
32103227
3211 -void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove)
 3228+void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light)
32123229 {
32133230 int numlights = 0;
32143231 int lightindex = 0;
3215 - if(!remove)memcpy(&This->lights[index], light, sizeof(D3DLIGHT7));
3216 - else ZeroMemory(&This->lights[index], sizeof(D3DLIGHT7));
 3232+ memcpy(&This->lights[index], light, sizeof(D3DLIGHT7));
32173233 SetEvent(This->busy);
32183234 for (int i = 0; i < 8; i++)
32193235 if (This->lights[i].dltType) numlights++;
@@ -3232,6 +3248,29 @@
32333249
32343250 }
32353251
 3252+void glRenderer__RemoveLight(glRenderer *This, DWORD index)
 3253+{
 3254+ int numlights = 0;
 3255+ int lightindex = 0;
 3256+ ZeroMemory(&This->lights[index], sizeof(D3DLIGHT7));
 3257+ SetEvent(This->busy);
 3258+ for (int i = 0; i < 8; i++)
 3259+ if (This->lights[i].dltType) numlights++;
 3260+ This->shaderstate3d.stateid &= 0xF807C03FFFE3FFFFi64;
 3261+ This->shaderstate3d.stateid |= ((__int64)numlights << 18);
 3262+ for (int i = 0; i < 8; i++)
 3263+ {
 3264+ if (This->lights[i].dltType != 1)
 3265+ {
 3266+ if (This->lights[i].dltType != D3DLIGHT_DIRECTIONAL)
 3267+ This->shaderstate3d.stateid |= (1i64 << (38 + lightindex));
 3268+ if (This->lights[i].dltType == D3DLIGHT_SPOT)
 3269+ This->shaderstate3d.stateid |= (1i64 << (51 + lightindex));
 3270+ lightindex++;
 3271+ }
 3272+ }
 3273+}
 3274+
32363275 void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport)
32373276 {
32383277 memcpy(&This->viewport, lpViewport, sizeof(D3DVIEWPORT7));
Index: ddraw/glRenderer.h
@@ -18,25 +18,6 @@
1919 #ifndef _GLRENDERER_H
2020 #define _GLRENDERER_H
2121
22 -typedef struct
23 -{
24 - float Version;
25 - float ShaderVer;
26 - GLint TextureMax;
27 -} GLCAPS;
28 -
29 -typedef struct
30 -{
31 - void *data;
32 - int stride;
33 -} GLVERTEX;
34 -
35 -typedef struct
36 -{
37 - __int64 stateid;
38 - __int64 texstageid[8];
39 -} SHADERSTATE;
40 -
4122 #ifdef __cplusplus
4223 class glDirectDraw7;
4324 class glDirect3DDevice7;
@@ -104,12 +85,13 @@
10586 #define OP_SETTRANSFORM 18
10687 #define OP_SETMATERIAL 19
10788 #define OP_SETLIGHT 20
108 -#define OP_SETVIEWPORT 21
109 -#define OP_DXGLBREAK 22
110 -#define OP_SETTEXTURECOLORKEY 23
111 -#define OP_MAKETEXTUREPRIMARY 24
112 -#define OP_ENDCOMMAND 25
113 -#define OP_INITTEXTURESTAGE 26
 89+#define OP_REMOVELIGHT 21
 90+#define OP_SETVIEWPORT 22
 91+#define OP_DXGLBREAK 23
 92+#define OP_SETTEXTURECOLORKEY 24
 93+#define OP_MAKETEXTUREPRIMARY 25
 94+#define OP_ENDCOMMAND 26
 95+#define OP_INITTEXTURESTAGE 27
11496
11597 extern const DWORD renderstate_default[153];
11698 extern const TEXTURESTAGE texstagedefault0;
@@ -190,7 +172,8 @@
191173 void glRenderer_SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
192174 void glRenderer_SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
193175 void glRenderer_SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
194 -void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
 176+void glRenderer_SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light);
 177+void glRenderer_RemoveLight(glRenderer *This, DWORD index);
195178 void glRenderer_SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
196179 void glRenderer_SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level);
197180 void glRenderer_MakeTexturePrimary(glRenderer *This, glTexture *texture, glTexture *parent, BOOL primary);
@@ -231,7 +214,8 @@
232215 void glRenderer__SetTextureStageState(glRenderer *This, DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
233216 void glRenderer__SetTransform(glRenderer *This, D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
234217 void glRenderer__SetMaterial(glRenderer *This, LPD3DMATERIAL7 lpMaterial);
235 -void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light, BOOL remove);
 218+void glRenderer__SetLight(glRenderer *This, DWORD index, LPD3DLIGHT7 light);
 219+void glRenderer__RemoveLight(glRenderer *This, DWORD index);
236220 void glRenderer__SetViewport(glRenderer *This, LPD3DVIEWPORT7 lpViewport);
237221 void glRenderer__SetTextureColorKey(glRenderer *This, glTexture *texture, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey, GLint level);
238222 void glRenderer__MakeTexturePrimary(glRenderer *This, glTexture *texture, glTexture *parent, BOOL primary);
Index: ddraw/struct.h
@@ -465,4 +465,23 @@
466466 float muly;
467467 } RenderTarget;
468468
 469+typedef struct GLCAPS
 470+{
 471+ float Version;
 472+ float ShaderVer;
 473+ GLint TextureMax;
 474+} GLCAPS;
 475+
 476+typedef struct GLVERTEX
 477+{
 478+ void *data;
 479+ int stride;
 480+} GLVERTEX;
 481+
 482+typedef struct SHADERSTATE
 483+{
 484+ __int64 stateid;
 485+ __int64 texstageid[8];
 486+} SHADERSTATE;
 487+
469488 #endif //__STRUCT_H
\ No newline at end of file
Index: ddraw/struct_command.h
@@ -86,6 +86,88 @@
8787 {
8888 DWORD opcode;
8989 DWORD size;
90 - // Add params
 90+ RenderTarget *target;
 91+ GLenum mode;
 92+ GLVERTEX *vertices;
 93+ int *texformats;
 94+ DWORD count;
 95+ LPWORD indices;
9196 } DrawPrimitivesCmd;
 97+typedef struct UpdateClipperCmd
 98+{
 99+ DWORD opcode;
 100+ DWORD size;
 101+ glTexture *stencil;
 102+ GLushort *indices;
 103+ BltVertex *vertices;
 104+ GLsizei count;
 105+ GLsizei width;
 106+ GLsizei height;
 107+} UpdateClipperCmd;
 108+typedef struct DepthFillCmd
 109+{
 110+ DWORD opcode;
 111+ DWORD size;
 112+ BltCommand cmd;
 113+ glTexture *parent;
 114+ GLint parentlevel;
 115+} DepthFillCmd;
 116+typedef struct SetRenderStateCmd
 117+{
 118+ DWORD opcode;
 119+ DWORD size;
 120+ DWORD count;
 121+ D3DRENDERSTATETYPE dwRendStateType;
 122+ DWORD dwRenderState;
 123+ // For count over 1, use additional pairs to store state changes.
 124+} SetRenderStateCmd;
 125+typedef struct SetTextureCmd
 126+{
 127+ DWORD opcode;
 128+ DWORD size;
 129+ DWORD count;
 130+ DWORD stage;
 131+ glTexture *texture;
 132+ // For count over 1, use additional pairs to store texture changes.
 133+} SetTextureCmd;
 134+typedef struct SetTextureStageStateCmd
 135+{
 136+ DWORD opcode;
 137+ DWORD size;
 138+ DWORD count;
 139+ DWORD dwStage;
 140+ D3DTEXTURESTAGESTATETYPE dwState;
 141+ DWORD dwValue;
 142+ // For count over 1, use additional sets to store texture state changes.
 143+} SetTextureStageStateCmd;
 144+typedef struct SetTransformCmd
 145+{
 146+ DWORD opcode;
 147+ DWORD size;
 148+ D3DTRANSFORMSTATETYPE dtstTransformStateType;
 149+ D3DMATRIX matrix;
 150+} SetTransformCmd;
 151+typedef struct SetMaterialCmd
 152+{
 153+ DWORD opcode;
 154+ DWORD size;
 155+ D3DMATERIAL7 material;
 156+} SetMaterialCmd;
 157+typedef struct SetLightCmd
 158+{
 159+ DWORD opcode;
 160+ DWORD size;
 161+ DWORD count;
 162+ DWORD index;
 163+ D3DLIGHT7 light;
 164+ // For count over 1, use additional pairs to store lights
 165+} SetLightCmd;
 166+typedef struct RemoveLightCmd
 167+{
 168+ DWORD opcode;
 169+ DWORD size;
 170+ DWORD count;
 171+ DWORD index;
 172+ // For count over 1, use additional indices
 173+} RemoveLightCmd;
92174 #endif //__STRUCT_COMMAND_H
\ No newline at end of file