DXGL r690 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r689‎ | r690 | r691 >
Date:02:32, 15 November 2016
Author:admin
Status:new
Tags:
Comment:
Remove a redundant set of variables backx and backy from glRenderer.
More work towards new rendering engine.
Modified paths:
  • /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/glRenderer.cpp
@@ -237,6 +237,7 @@
238238 {
239239 BOOL usedest = FALSE;
240240 BOOL usepattern = FALSE;
 241+ BOOL usetexture = FALSE;
241242 if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
242243 {
243244 if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
@@ -280,24 +281,33 @@
281282 tmp_cmd.Blt.cmd.destlevel = 0;
282283 glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
283284 }
284 - i = 0;
 285+ // Set Src texture (Unit 8)
 286+ i = -1;
285287 tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
286 - tmp_cmd.SetTexture.size = sizeof(SetTextureCmd);
287 - // Set Src texture (Unit 8)
 288+ tmp_cmd.SetTexture.size = sizeof(SetTextureCmd) - (sizeof(DWORD) + sizeof(glTexture*));
288289 if (cmd->Blt.cmd.src)
289290 {
 291+ tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 292+ i++;
 293+ usetexture = TRUE;
290294 tmp_cmd.SetTexture.texstage[i].stage = 8;
291295 tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.src;
 296+ }
 297+ // Set Dest texture (Unit 9) - reads from temporary buffer
 298+ if (usedest)
 299+ {
292300 tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
293301 i++;
 302+ usetexture = TRUE;
 303+ tmp_cmd.SetTexture.texstage[i].stage = 9;
 304+ tmp_cmd.SetTexture.texstage[i].texture = This->backbuffer;
294305 }
295 - // Set Dest texture (Unit 9)
296 - tmp_cmd.SetTexture.texstage[i].stage = 9;
297 - tmp_cmd.SetTexture.texstage[i].texture = tmp_cmd.Blt.cmd.dest;
298306 // Set Pattern texture (Unit 10)
299307 if (usepattern)
300308 {
301309 tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 310+ i++;
 311+ usetexture = TRUE;
302312 tmp_cmd.SetTexture.texstage[i].stage = 10;
303313 tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.pattern;
304314 }
@@ -305,10 +315,12 @@
306316 if (cmd->Blt.cmd.dest->stencil)
307317 {
308318 tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 319+ i++;
 320+ usetexture = TRUE;
309321 tmp_cmd.SetTexture.texstage[i].stage = 11;
310322 tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.dest->stencil;
311323 }
312 - glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 324+ if(usetexture) glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
313325 // Set shader mode and params
314326 tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
315327 tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd);
@@ -318,8 +330,58 @@
319331 else tmp_cmd.SetShader2D.id = cmd->Blt.cmd.flags & 0xF2FAADFF;
320332 glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
321333 // Set render target
 334+ if ((This->state.target.target != cmd->Blt.cmd.dest)
 335+ || (This->state.target.level != cmd->Blt.cmd.destlevel))
 336+ {
 337+ tmp_cmd.SetRenderTarget.opcode = OP_SETRENDERTARGET;
 338+ tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd);
 339+ tmp_cmd.SetRenderTarget.target.target = cmd->Blt.cmd.dest;
 340+ tmp_cmd.SetRenderTarget.target.level = cmd->Blt.cmd.destlevel;
 341+ tmp_cmd.SetRenderTarget.target.zbuffer = NULL;
 342+ tmp_cmd.SetRenderTarget.target.zlevel = 0;
 343+ if (cmd->Blt.cmd.destlevel == 0 && (cmd->Blt.cmd.dest->levels[0].ddsd.dwWidth != cmd->Blt.cmd.dest->bigwidth) ||
 344+ (cmd->Blt.cmd.dest->levels[0].ddsd.dwHeight != cmd->Blt.cmd.dest->bigheight))
 345+ {
 346+ tmp_cmd.SetRenderTarget.target.mulx = (GLfloat)cmd->Blt.cmd.dest->bigwidth / (GLfloat)cmd->Blt.cmd.dest->levels[0].ddsd.dwWidth;
 347+ tmp_cmd.SetRenderTarget.target.muly = (GLfloat)cmd->Blt.cmd.dest->bigheight / (GLfloat)cmd->Blt.cmd.dest->levels[0].ddsd.dwHeight;
 348+ }
 349+ else tmp_cmd.SetRenderTarget.target.mulx = tmp_cmd.SetRenderTarget.target.muly = 1.0f;
 350+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 351+ }
322352 // Set viewport
 353+ if (!cmd->Blt.cmd.destlevel)
 354+ {
 355+ r2.right = cmd->Blt.cmd.dest->bigwidth;
 356+ r2.bottom = cmd->Blt.cmd.dest->bigheight;
 357+ }
 358+ else
 359+ {
 360+ r2.right = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 361+ r2.bottom = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 362+ }
 363+ if (This->state.viewport.x || This->state.viewport.y ||
 364+ (This->state.viewport.width != r2.right) || (This->state.viewport.hieght != r2.bottom))
 365+ {
 366+ tmp_cmd.SetViewport.opcode = OP_SETVIEWPORT;
 367+ tmp_cmd.SetViewport.size = sizeof(SetViewportCmd);
 368+ tmp_cmd.SetViewport.viewport.x = tmp_cmd.SetViewport.viewport.y = 0;
 369+ tmp_cmd.SetViewport.viewport.width = r2.right;
 370+ tmp_cmd.SetViewport.viewport.hieght = r2.bottom;
 371+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 372+ }
323373 // Generate vertices
 374+ /*tmp_cmd.BltVertex_STORAGE.vertex*/
 375+ if (usedest)
 376+ {
 377+ tmp_cmd.BltVertex_STORAGE.vertex[1].dests =
 378+ tmp_cmd.BltVertex_STORAGE.vertex[3].dests = 0.;
 379+ tmp_cmd.BltVertex_STORAGE.vertex[0].dests =
 380+ tmp_cmd.BltVertex_STORAGE.vertex[2].dests = (GLfloat)(r1.right - r1.left) / (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
 381+ tmp_cmd.BltVertex_STORAGE.vertex[0].destt =
 382+ tmp_cmd.BltVertex_STORAGE.vertex[1].destt = 1.;
 383+ tmp_cmd.BltVertex_STORAGE.vertex[2].destt =
 384+ tmp_cmd.BltVertex_STORAGE.vertex[3].destt = 1.0 - ((GLfloat)(r1.bottom - r1.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
 385+ }
324386 // Rotate vertices if necessary
325387 // Write vertices to VBO
326388 // Write command to buffer
@@ -423,6 +485,12 @@
424486 case OP_SETSHADER:
425487 error = DDERR_CURRENTLYNOTAVAIL;
426488 break;
 489+ case OP_SETRENDERTARGET:
 490+ error = DDERR_CURRENTLYNOTAVAIL;
 491+ break;
 492+ case OP_SETVIEWPORT:
 493+ error = DDERR_CURRENTLYNOTAVAIL;
 494+ break;
427495 default:
428496 error = DDERR_INVALIDPARAMS;
429497 break;
@@ -1347,8 +1415,6 @@
13481416 {
13491417 glTexture_Release(This->backbuffer, TRUE);
13501418 This->backbuffer = NULL;
1351 - This->backx = 0;
1352 - This->backy = 0;
13531419 }
13541420 glRenderer__DeleteCommandBuffer(&This->cmd1);
13551421 glRenderer__DeleteCommandBuffer(&This->cmd2);
@@ -1870,9 +1936,9 @@
18711937 ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
18721938 glRenderer__DrawBackbufferRect(This, cmd->dest, destrect, PROG_TEXTURE);
18731939 This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
1874 - This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
 1940+ This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
18751941 This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
1876 - This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
 1942+ This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
18771943 }
18781944 ShaderManager_SetShader(This->shaders, shaderid, NULL, 1);
18791945 GenShader2D *shader = (GenShader2D*)This->shaders->gen3d->current_genshader;
@@ -2034,10 +2100,8 @@
20352101 ddsd.lPitch = x * 4;
20362102 ddsd.dwHeight = y;
20372103 glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
2038 - This->backx = x;
2039 - This->backy = y;
20402104 }
2041 - if((This->backx != x) || (This->backy != y))
 2105+ if((This->backbuffer->levels[0].ddsd.dwWidth != x) || (This->backbuffer->levels[0].ddsd.dwHeight != y))
20422106 {
20432107 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
20442108 ddsd.dwSize = sizeof(DDSURFACEDESC2);
@@ -2045,8 +2109,6 @@
20462110 ddsd.dwHeight = y;
20472111 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
20482112 glTexture__SetSurfaceDesc(This->backbuffer, &ddsd);
2049 - This->backx = x;
2050 - This->backy = y;
20512113 }
20522114 glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,NULL,0,0,FALSE);
20532115 view[0] = view[2] = 0;
@@ -2089,10 +2151,10 @@
20902152 ddsd.dwHeight = y;
20912153 glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
20922154 }
2093 - if ((This->backx < x) || (This->backy < y))
 2155+ if ((This->backbuffer->levels[0].ddsd.dwWidth < x) || (This->backbuffer->levels[0].ddsd.dwHeight < y))
20942156 {
2095 - if (This->backx > x) x = This->backx;
2096 - if (This->backx > y) y = This->backx;
 2157+ if (This->backbuffer->levels[0].ddsd.dwWidth > x) x = This->backbuffer->levels[0].ddsd.dwWidth;
 2158+ if (This->backbuffer->levels[0].ddsd.dwHeight > y) y = This->backbuffer->levels[0].ddsd.dwHeight;
20972159 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
20982160 ddsd.dwSize = sizeof(DDSURFACEDESC2);
20992161 ddsd.dwWidth = x;
@@ -2099,15 +2161,13 @@
21002162 ddsd.dwHeight = y;
21012163 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
21022164 glTexture__SetSurfaceDesc(This->backbuffer, &ddsd);
2103 - This->backx = x;
2104 - This->backy = y;
21052165 }
21062166 glUtil_SetFBOTextures(This->util, &This->fbo, This->backbuffer, NULL, 0, 0, FALSE);
21072167 view[0] = view[2] = 0;
2108 - view[1] = (GLfloat)This->backx;
2109 - view[3] = (GLfloat)This->backy;
2110 - glUtil_SetViewport(This->util, 0, 0, This->backx, This->backy);
2111 - glUtil_SetScissor(This->util, TRUE, 0, 0, This->backx, This->backy);
 2168+ view[1] = (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
 2169+ view[3] = (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight;
 2170+ glUtil_SetViewport(This->util, 0, 0, This->backbuffer->levels[0].ddsd.dwWidth, This->backbuffer->levels[0].ddsd.dwHeight);
 2171+ glUtil_SetScissor(This->util, TRUE, 0, 0, This->backbuffer->levels[0].ddsd.dwWidth, This->backbuffer->levels[0].ddsd.dwHeight);
21122172 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
21132173 glUtil_SetScissor(This->util, FALSE, 0, 0, 0, 0);
21142174 glUtil_SetTexture(This->util, 0, texture);
Index: ddraw/glRenderer.h
@@ -95,6 +95,8 @@
9696 #define OP_SETTEXTURESURFACEDESC 28
9797 #define OP_SETSHADER2D 29
9898 #define OP_SETSHADER 30
 99+#define OP_SETRENDERTARGET 31
 100+#define OP_SETVIEWPORT 32
99101
100102 extern const DWORD renderstate_default[153];
101103 extern const TEXTURESTAGE texstagedefault0;
@@ -125,8 +127,6 @@
126128 unsigned int frequency;
127129 DXGLTimer timer;
128130 glTexture *backbuffer;
129 - int backx;
130 - int backy;
131131 DWORD fogcolor;
132132 GLfloat fogstart;
133133 GLfloat fogend;
Index: ddraw/struct.h
@@ -453,8 +453,8 @@
454454 glTexture *zbuffer;
455455 GLint level;
456456 GLint zlevel;
457 - float mulx;
458 - float muly;
 457+ GLfloat mulx;
 458+ GLfloat muly;
459459 } RenderTarget;
460460
461461 typedef struct GLCAPS
@@ -476,4 +476,12 @@
477477 __int64 texstageid[8];
478478 } SHADERSTATE;
479479
 480+typedef struct VIEWPORT
 481+{
 482+ GLint x;
 483+ GLint y;
 484+ GLsizei width;
 485+ GLsizei hieght;
 486+} VIEWPORT;
 487+
480488 #endif //__STRUCT_H
\ No newline at end of file
Index: ddraw/struct_command.h
@@ -236,7 +236,7 @@
237237 DWORD size;
238238 int type; // 0 for builtin, 1 for 2D, 2 for 3D (INVALID, use full command)
239239 __int64 id;
240 -};
 240+} SetShader2DCmd;
241241 typedef struct SetShaderCmd
242242 {
243243 DWORD opcode;
@@ -244,8 +244,25 @@
245245 int type; // 0 for builtin, 1 for 2D, 2 for 3D
246246 __int64 id;
247247 __int64 texstate[8];
248 -};
 248+} SetShaderCmd;
 249+typedef struct SetRenderTargetCmd
 250+{
 251+ DWORD opcode;
 252+ DWORD size;
 253+ RenderTarget target;
 254+} SetRenderTargetCmd;
 255+typedef struct SetViewportCmd
 256+{
 257+ DWORD opcode;
 258+ DWORD size;
 259+ VIEWPORT viewport;
 260+} SetViewportCmd;
249261
 262+typedef struct BltVertex_STORAGE_Cmd // Store vertices in stack for Blt()
 263+{
 264+ BltVertex vertex[4];
 265+ WORD index[64];
 266+} BltVertex_STORAGE_Cmd;
250267 typedef struct MIN_STORAGE_Cmd
251268 {
252269 BYTE data[256];
@@ -281,6 +298,9 @@
282299 SetTextureSurfaceDescCmd SetTextureSurfaceDesc;
283300 SetShader2DCmd SetShader2D;
284301 SetShaderCmd SetShader;
 302+ SetRenderTargetCmd SetRenderTarget;
 303+ SetViewportCmd SetViewport;
 304+ BltVertex_STORAGE_Cmd BltVertex_STORAGE;
285305 MIN_STORAGE_CMD MIN_STORAGE;
286306 } QueueCmd;
287307
@@ -289,6 +309,8 @@
290310 CommandBuffer *cmd;
291311 QueueCmd last_cmd;
292312 BYTE *last_cmd_start;
 313+ RenderTarget target;
 314+ VIEWPORT viewport;
293315 } RenderState;
294316
295317 #endif //__STRUCT_COMMAND_H
\ No newline at end of file