DXGL r693 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r692‎ | r693 | r694 >
Date:03:54, 15 January 2017
Author:admin
Status:new
Tags:
Comment:
Change depth test and depth write functions from BOOL to DWORD to simplify interpretation of render states.
More work on new renderer frontend.
Begin describing new renderer OP_DRAWPRIMITIVES
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glUtil.cpp (modified) (history)
  • /ddraw/glUtil.h (modified) (history)
  • /ddraw/struct_command.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -601,6 +601,9 @@
602602 BOOL restart_cmd = FALSE;
603603 __int64 shaderid;
604604 BltVertex *vertex;
 605+ BOOL flip;
 606+ if (wait) flip = TRUE;
 607+ else flip = FALSE;
605608 if (!inner) EnterCriticalSection(&This->cs);
606609 switch (cmd->Generic.opcode)
607610 {
@@ -1397,20 +1400,64 @@
13981401 break;
13991402 case OP_INITD3D: // Initialize renderer for Direct3D rendering.
14001403 // Set initial viewport
 1404+ tmp_cmd.SetD3DViewport.opcode = OP_SETD3DVIEWPORT;
 1405+ tmp_cmd.SetD3DViewport.size = sizeof(SetD3DViewportCmd) - 8;
 1406+ tmp_cmd.SetD3DViewport.viewport.dwX = 0;
 1407+ tmp_cmd.SetD3DViewport.viewport.dwY = 0;
 1408+ tmp_cmd.SetD3DViewport.viewport.dwWidth = cmd->InitD3D.x;
 1409+ tmp_cmd.SetD3DViewport.viewport.dwHeight = cmd->InitD3D.y;
 1410+ tmp_cmd.SetD3DViewport.viewport.dvMinZ = 0.0f;
 1411+ tmp_cmd.SetD3DViewport.viewport.dvMaxZ = 1.0f;
 1412+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
14011413 // Initialize texture stages 0 through 7
 1414+ tmp_cmd.InitTextureStage.opcode = OP_INITTEXTURESTAGE;
 1415+ tmp_cmd.InitTextureStage.size = sizeof(InitTextureStageCmd) - 8 + (7 * sizeof(DWORD));
 1416+ tmp_cmd.InitTextureStage.count = 8;
 1417+ for (i = 0; i < 8; i++)
 1418+ tmp_cmd.InitTextureStage.stage[i] = i;
 1419+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
14021420 // Post InitD3D command
1403 - error = DDERR_CURRENTLYNOTAVAIL;
 1421+ CheckCmdBuffer(This, cmd->InitD3D.size + 8, 0, 0, 0);
 1422+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->InitD3D.size + 8);
 1423+ This->state.cmd->write_ptr_cmd += (cmd->InitD3D.size + 8);
 1424+ error = DD_OK;
14041425 break;
14051426 case OP_CLEAR: // Clears full renderbuffer or one or more rects.
14061427 // Size should hold number of rects plus each rect, or 0 for screen.
1407 - error = DDERR_CURRENTLYNOTAVAIL;
 1428+ CheckCmdBuffer(This, cmd->Clear.size + 8, 0, 0, 0);
 1429+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->Clear.size + 8);
 1430+ This->state.cmd->write_ptr_cmd += (cmd->Clear.size + 8);
 1431+ error = DD_OK;
14081432 break;
14091433 case OP_FLUSH: // Probably should consider retiring this one. Flip buffers if called
14101434 // to ensure the renderer gets flushed.
 1435+ CheckCmdBuffer(This, cmd->Flush.size + 8, 0, 0, 0);
 1436+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->Flush.size + 8);
 1437+ This->state.cmd->write_ptr_cmd += (cmd->Flush.size + 8);
14111438 error = DDERR_CURRENTLYNOTAVAIL;
 1439+ flip = TRUE;
14121440 break;
14131441 case OP_DRAWPRIMITIVES: // Add primitives to the render buffer, check and adjust buffer
14141442 // state.
 1443+
 1444+ /*Description of old DrawPrimitives:
 1445+ check for zbuffer on target
 1446+ check if transformed
 1447+ if no vertex positions fail
 1448+ AND shaderstate with 0xFFFA3FF87FFFFFFFi64
 1449+ AND all texstage ids with 0xFFE7FFFFFFFFFFFFi64
 1450+ Set bit 51 of texture id for each texture stage in vertices
 1451+ add number of textures to shaderstate bits 31-33
 1452+ If more than 0 textures used set bit 34 of shaderstate
 1453+ Set bits 46-48 of shaderstate to number of blendweights
 1454+ Set bit 50 of shaderstate if vertices are pre-transformed
 1455+ Set bit 35 of shaderstate if diffuse color is in vertices
 1456+ Set bit 36 of shaderstate if specular color is in vertices
 1457+ Set bit 37 of shaderstate if vertices have normals
 1458+ Set shader program
 1459+ Tell renderer to set depth compare mode, depth test, and depth write
 1460+
 1461+ */
14151462 error = DDERR_CURRENTLYNOTAVAIL;
14161463 break;
14171464 case OP_UPDATECLIPPER: // Add pre-processed vertices to update the clipper.
@@ -1473,6 +1520,9 @@
14741521 case OP_VERTEX2D:
14751522 error = DDERR_CURRENTLYNOTAVAIL;
14761523 break;
 1524+ case OP_SETD3DDEPTHMODE:
 1525+ error = DDERR_CURRENTLYNOTAVAIL;
 1526+ break;
14771527 case OP_SETDEPTHTEST:
14781528 error = DDERR_CURRENTLYNOTAVAIL;
14791529 break;
@@ -3742,10 +3792,8 @@
37433793 if (vertices[7].data) This->shaderstate3d.stateid |= (1i64 << 37);
37443794 ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,2);
37453795 glRenderer__SetDepthComp(This);
3746 - if(This->renderstate[D3DRENDERSTATE_ZENABLE]) glUtil_DepthTest(This->util, TRUE);
3747 - else glUtil_DepthTest(This->util, FALSE);
3748 - if (This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) glUtil_DepthWrite(This->util, TRUE);
3749 - else glUtil_DepthWrite(This->util, FALSE);
 3796+ glUtil_DepthTest(This->util, This->renderstate[D3DRENDERSTATE_ZENABLE]);
 3797+ glUtil_DepthWrite(This->util, This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]);
37503798 _GENSHADER *prog = &This->shaders->gen3d->current_genshader->shader;
37513799 glUtil_EnableArray(This->util, prog->attribs[0], TRUE);
37523800 This->ext->glVertexAttribPointer(prog->attribs[0],3,GL_FLOAT,GL_FALSE,vertices[0].stride,vertices[0].data);
Index: ddraw/glRenderer.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2016 William Feely
 3+// Copyright (C) 2012-2017 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
@@ -98,12 +98,13 @@
9999 #define OP_SETRENDERTARGET 31
100100 #define OP_SETVIEWPORT 32
101101 #define OP_VERTEX2D 33
102 -#define OP_SETDEPTHTEST 34
103 -#define OP_SETFRONTBUFFERBITS 35
104 -#define OP_SETSWAP 36
105 -#define OP_SWAPBUFFERS 37
106 -#define OP_SETUNIFORM 38
107 -#define OP_SETATTRIB 39
 102+#define OP_SETD3DDEPTHMODE 34
 103+#define OP_SETDEPTHTEST 35
 104+#define OP_SETFRONTBUFFERBITS 36
 105+#define OP_SETSWAP 37
 106+#define OP_SWAPBUFFERS 38
 107+#define OP_SETUNIFORM 39
 108+#define OP_SETATTRIB 40
108109
109110 extern const DWORD renderstate_default[153];
110111 extern const TEXTURESTAGE texstagedefault0;
Index: ddraw/glUtil.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2016 William Feely
 3+// Copyright (C) 2012-2017 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
@@ -329,20 +329,26 @@
330330 }
331331 }
332332
333 -void glUtil_DepthWrite(glUtil *This, BOOL enabled)
 333+void glUtil_DepthWrite(glUtil *This, DWORD enabled)
334334 {
335 - if (enabled != This->depthwrite)
 335+ BOOL enabled_bool;
 336+ if (enabled) enabled_bool = TRUE;
 337+ else enabled_bool = FALSE;
 338+ if (enabled_bool != This->depthwrite)
336339 {
337 - This->depthwrite = enabled;
 340+ This->depthwrite = enabled_bool;
338341 if (This->depthwrite) glDepthMask(GL_TRUE);
339342 else glDepthMask(GL_FALSE);
340343 }
341344 }
342 -void glUtil_DepthTest(glUtil *This, BOOL enabled)
 345+void glUtil_DepthTest(glUtil *This, DWORD enabled)
343346 {
344 - if (enabled != This->depthtest)
 347+ BOOL enabled_bool;
 348+ if (enabled) enabled_bool = TRUE;
 349+ else enabled_bool = FALSE;
 350+ if (enabled_bool != This->depthtest)
345351 {
346 - This->depthtest = enabled;
 352+ This->depthtest = enabled_bool;
347353 if (This->depthtest) glEnable(GL_DEPTH_TEST);
348354 else glDisable(GL_DEPTH_TEST);
349355 }
Index: ddraw/glUtil.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2016 William Feely
 3+// Copyright (C) 2012-2017 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
@@ -40,8 +40,8 @@
4141 GLenum glUtil_SetFBO(glUtil *This, FBO *fbo);
4242 GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, glTexture *color, glTexture *z, GLint level, GLint zlevel, BOOL stencil);
4343 void glUtil_SetDepthComp(glUtil *This, GLenum comp);
44 -void glUtil_DepthWrite(glUtil *This, BOOL enabled);
45 -void glUtil_DepthTest(glUtil *This, BOOL enabled);
 44+void glUtil_DepthWrite(glUtil *This, DWORD enabled);
 45+void glUtil_DepthTest(glUtil *This, DWORD enabled);
4646 void glUtil_SetScissor(glUtil *This, BOOL enabled, GLint x, GLint y, GLsizei width, GLsizei height);
4747 void glUtil_SetMatrix(glUtil *This, GLenum mode, GLfloat *mat1, GLfloat *mat2, BOOL *dirty);
4848 void glUtil_MatrixMode(glUtil *This, GLenum mode);
Index: ddraw/struct_command.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2016 William Feely
 3+// Copyright (C) 2016-2017 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
@@ -267,6 +267,11 @@
268268 size_t offset;
269269 size_t indexoffset;
270270 } Vertex2DCmd;
 271+typedef struct SetD3DDepthModeCmd
 272+{
 273+ DWORD opcode;
 274+ DWORD size;
 275+} SetD3DDepthModeCmd;
271276 typedef struct SetDepthTestCmd
272277 {
273278 DWORD opcode;
@@ -398,6 +403,7 @@
399404 SetRenderTargetCmd SetRenderTarget;
400405 SetViewportCmd SetViewport;
401406 Vertex2DCmd Vertex2D;
 407+ SetD3DDepthModeCmd SetD3DDepthMode;
402408 SetDepthTestCmd SetDepthTest;
403409 SetFrontBufferBitsCmd SetFrontBufferBits;
404410 SetSwapCmd SetSwap;