DXGL r689 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r688‎ | r689 | r690 >
Date:02:00, 12 November 2016
Author:admin
Status:new
Tags:
Comment:
Progress towards new renderer "Blt" frontend command.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/struct_command.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -141,12 +141,19 @@
142142 * First DWORD: Command ID, see glRenderer.h
143143 * Second DWORD: Size of command data, rounded up to nearest DWORD
144144 * Third DWORD and beyond: command data
 145+ * @param inner
 146+ * TRUE if called from within this function.
 147+ * @param wait
 148+ * TRUE to force the queue to wait until completion
145149 * @return
146150 * Return value specific to command, DD_OK if succeeded.
147151 */
148 -HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner)
 152+HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner, BOOL wait)
149153 {
150154 HRESULT error;
 155+ QueueCmd tmp_cmd;
 156+ RECT r1, r2;
 157+ int i;
151158 // Command specific variables
152159 RECT wndrect;
153160 int screenx, screeny;
@@ -213,6 +220,10 @@
214221 !comp_bltfx(&This->state.last_cmd.Blt.cmd.bltfx, &cmd->Blt.cmd.bltfx, cmd->Blt.cmd.flags))
215222 restart_cmd = FALSE;
216223 else restart_cmd = TRUE;
 224+ if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
 225+ {
 226+ if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) restart_cmd = TRUE;
 227+ }
217228 if(!restart_cmd)
218229 {
219230 // Generate vertices
@@ -234,13 +245,78 @@
235246 // Run backbuffer if using dest
236247 if (usedest)
237248 {
238 -
 249+ r1.left = r1.top = 0;
 250+ if (memcmp(&cmd->Blt.cmd.destrect, &nullrect, sizeof(RECT)))
 251+ {
 252+ r1.right = cmd->Blt.cmd.destrect.right - cmd->Blt.cmd.destrect.left;
 253+ r1.bottom = cmd->Blt.cmd.destrect.bottom - cmd->Blt.cmd.destrect.top;
 254+ }
 255+ else
 256+ {
 257+ r1.right = cmd->Blt.cmd.dest->levels[0].ddsd.dwWidth;
 258+ r1.bottom = cmd->Blt.cmd.dest->levels[0].ddsd.dwHeight;
 259+ }
 260+ // Check backbuffer size and resize
 261+ if((This->backbuffer->levels[0].ddsd.dwWidth < r1.right) ||
 262+ (This->backbuffer->levels[0].ddsd.dwHeight < r1.bottom))
 263+ {
 264+ DDSURFACEDESC2 newdesc = This->backbuffer->levels[0].ddsd;
 265+ if (newdesc.dwWidth < r1.right) newdesc.dwWidth = r1.right;
 266+ if (newdesc.dwHeight < r1.bottom) newdesc.dwHeight = r1.bottom;
 267+ tmp_cmd.SetTextureSurfaceDesc.opcode = OP_SETTEXTURESURFACEDESC;
 268+ tmp_cmd.SetTextureSurfaceDesc.size = sizeof(SetTextureSurfaceDescCmd);
 269+ tmp_cmd.SetTextureSurfaceDesc.level = 0;
 270+ tmp_cmd.SetTextureSurfaceDesc.desc = newdesc;
 271+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, TRUE);
 272+ }
 273+ tmp_cmd.Blt.opcode = OP_BLT;
 274+ tmp_cmd.Blt.size = sizeof(BltCmd);
 275+ tmp_cmd.Blt.cmd.flags = 0;
 276+ tmp_cmd.Blt.cmd.destrect = r1;
 277+ tmp_cmd.Blt.cmd.srcrect = cmd->Blt.cmd.destrect;
 278+ tmp_cmd.Blt.cmd.src = cmd->Blt.cmd.dest;
 279+ tmp_cmd.Blt.cmd.dest = This->backbuffer;
 280+ tmp_cmd.Blt.cmd.srclevel = cmd->Blt.cmd.srclevel;
 281+ tmp_cmd.Blt.cmd.destlevel = 0;
 282+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
239283 }
 284+ i = 0;
 285+ tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
 286+ tmp_cmd.SetTexture.size = sizeof(SetTextureCmd);
240287 // Set Src texture (Unit 8)
 288+ if (cmd->Blt.cmd.src)
 289+ {
 290+ tmp_cmd.SetTexture.texstage[i].stage = 8;
 291+ tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.src;
 292+ tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 293+ i++;
 294+ }
241295 // 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;
242298 // Set Pattern texture (Unit 10)
 299+ if (usepattern)
 300+ {
 301+ tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 302+ tmp_cmd.SetTexture.texstage[i].stage = 10;
 303+ tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.pattern;
 304+ }
243305 // Set clipper texture (Unit 11)
 306+ if (cmd->Blt.cmd.dest->stencil)
 307+ {
 308+ tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 309+ tmp_cmd.SetTexture.texstage[i].stage = 11;
 310+ tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.dest->stencil;
 311+ }
 312+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
244313 // Set shader mode and params
 314+ tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
 315+ tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd);
 316+ tmp_cmd.SetShader2D.type = 1;
 317+ if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
 318+ tmp_cmd.SetShader2D.id = PackROPBits(cmd->Blt.cmd.bltfx.dwROP, cmd->Blt.cmd.flags);
 319+ else tmp_cmd.SetShader2D.id = cmd->Blt.cmd.flags & 0xF2FAADFF;
 320+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
245321 // Set render target
246322 // Set viewport
247323 // Generate vertices
@@ -338,6 +414,15 @@
339415 case OP_INITTEXTURESTAGE: // Initializes a texture stage.
340416 error = DDERR_CURRENTLYNOTAVAIL;
341417 break;
 418+ case OP_SETTEXTURESURFACEDESC:
 419+ error = DDERR_CURRENTLYNOTAVAIL;
 420+ break;
 421+ case OP_SETSHADER2D:
 422+ error = DDERR_CURRENTLYNOTAVAIL;
 423+ break;
 424+ case OP_SETSHADER:
 425+ error = DDERR_CURRENTLYNOTAVAIL;
 426+ break;
342427 default:
343428 error = DDERR_INVALIDPARAMS;
344429 break;
Index: ddraw/glRenderer.h
@@ -92,6 +92,9 @@
9393 #define OP_MAKETEXTUREPRIMARY 25
9494 #define OP_ENDCOMMAND 26
9595 #define OP_INITTEXTURESTAGE 27
 96+#define OP_SETTEXTURESURFACEDESC 28
 97+#define OP_SETSHADER2D 29
 98+#define OP_SETSHADER 30
9699
97100 extern const DWORD renderstate_default[153];
98101 extern const TEXTURESTAGE texstagedefault0;
@@ -145,7 +148,7 @@
146149 size_t scenesize, scenesizevertex, scenesizeindex;
147150 } glRenderer;
148151
149 -HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *command, BOOL inner);
 152+HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *command, BOOL inner, BOOL wait);
150153 void glRenderer_Init(glRenderer *This, int width, int height, int bpp, BOOL fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
151154 void glRenderer_Delete(glRenderer *This);
152155 DWORD glRenderer_GetBPP(glRenderer *This);
Index: ddraw/struct_command.h
@@ -223,6 +223,28 @@
224224 DWORD count;
225225 DWORD stage[1];
226226 } InitTextureStageCmd;
 227+typedef struct SetTextureSurfaceDescCmd
 228+{
 229+ DWORD opcode;
 230+ DWORD size;
 231+ GLint level;
 232+ DDSURFACEDESC2 desc;
 233+} SetTextureSurfaceDescCmd;
 234+typedef struct SetShader2DCmd
 235+{
 236+ DWORD opcode;
 237+ DWORD size;
 238+ int type; // 0 for builtin, 1 for 2D, 2 for 3D (INVALID, use full command)
 239+ __int64 id;
 240+};
 241+typedef struct SetShaderCmd
 242+{
 243+ DWORD opcode;
 244+ DWORD size;
 245+ int type; // 0 for builtin, 1 for 2D, 2 for 3D
 246+ __int64 id;
 247+ __int64 texstate[8];
 248+};
227249
228250 typedef struct MIN_STORAGE_Cmd
229251 {
@@ -256,6 +278,9 @@
257279 MakeTexturePrimaryCmd MakeTexturePrimary;
258280 DXGLBreakCmd DXGLBreak;
259281 InitTextureStageCmd InitTextureStage;
 282+ SetTextureSurfaceDescCmd SetTextureSurfaceDesc;
 283+ SetShader2DCmd SetShader2D;
 284+ SetShaderCmd SetShader;
260285 MIN_STORAGE_CMD MIN_STORAGE;
261286 } QueueCmd;
262287