DXGL r685 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r684‎ | r685 | r686 >
Date:21:17, 18 September 2016
Author:admin
Status:new
Tags:
Comment:
Isolate glRenderer_DrawPrimitives from DDraw stuctures.
Possibly fix a slight D3D bug regarding Z-buffer miplevel.
More planning work on 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
@@ -920,6 +920,7 @@
921921 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
922922 LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
923923 {
 924+ RenderTarget target;
924925 TRACE_ENTER(8,9,d3dptPrimitiveType,9,dwVertexTypeDesc,14,lpvVertices,8,dwVertexCount,14,lpwIndices,8,dwIndexCount,9,dwFlags);
925926 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
926927 if(!inscene) TRACE_RET(HRESULT,23,D3DERR_SCENE_NOT_IN_SCENE);
@@ -927,7 +928,21 @@
928929 if(lpwIndices) AddStats(d3dptPrimitiveType,dwIndexCount,&stats);
929930 else AddStats(d3dptPrimitiveType,dwVertexCount,&stats);
930931 if(err != D3D_OK) TRACE_RET(HRESULT,23,err);
931 - TRACE_RET(HRESULT,23,glRenderer_DrawPrimitives(renderer,this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
 932+ target.target = glDDS7->texture;
 933+ target.level = glDDS7->miplevel;
 934+ target.mulx = glDDS7->mulx;
 935+ target.muly = glDDS7->muly;
 936+ if (glDDS7->zbuffer)
 937+ {
 938+ target.zbuffer = glDDS7->zbuffer->texture;
 939+ target.zlevel = glDDS7->zbuffer->miplevel;
 940+ }
 941+ else
 942+ {
 943+ target.zbuffer = NULL;
 944+ target.zlevel = 0;
 945+ }
 946+ TRACE_RET(HRESULT,23,glRenderer_DrawPrimitives(renderer,&target,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
932947 dwVertexCount,lpwIndices,dwIndexCount,dwFlags));
933948 }
934949 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
Index: ddraw/glRenderer.cpp
@@ -21,10 +21,8 @@
2222 #include "glUtil.h"
2323 #include "timer.h"
2424 #include "glDirectDraw.h"
25 -#include "glDirectDrawSurface.h"
2625 #include "glRenderWindow.h"
2726 #include "glRenderer.h"
28 -#include "glDirect3DDevice.h"
2927 #include "ddraw.h"
3028 #include "ShaderGen3D.h"
3129 #include "matrix.h"
@@ -254,10 +252,11 @@
255253 // Generate vertices
256254 // Write vertices to VBO
257255 // Write Palette Draw command to buffer
258 - error = DDERR_UNSUPPORTED;
 256+ error = DDERR_CURRENTLYNOTAVAIL;
259257 break;
260258 case OP_INITD3D: // Initialize renderer for Direct3D rendering.
261259 // Set initial viewport
 260+ // Initialize texture stages 0 through 7
262261 // Post InitD3D command
263262 error = DDERR_CURRENTLYNOTAVAIL;
264263 break;
@@ -265,7 +264,8 @@
266265 // Size should hold number of rects plus each rect, or 0 for screen.
267266 error = DDERR_CURRENTLYNOTAVAIL;
268267 break;
269 - case OP_FLUSH: // Probably should consider retiring this one. Flip buffers if called.
 268+ case OP_FLUSH: // Probably should consider retiring this one. Flip buffers if called
 269+ // to ensure the renderer gets flushed.
270270 error = DDERR_CURRENTLYNOTAVAIL;
271271 break;
272272 case OP_DRAWPRIMITIVES: // Add primitives to the render buffer, check and adjust buffer
@@ -308,7 +308,10 @@
309309 case OP_DXGLBREAK: // Breakpoint command, flip buffers and wait or just add to command stream?
310310 error = DDERR_CURRENTLYNOTAVAIL;
311311 break;
312 - case OP_SETMODE2D: // Set up renderer for 2D DirectDraw commands.
 312+ case OP_ENDCOMMAND: // Not for this section.
 313+ error = DDERR_INVALIDPARAMS;
 314+ break;
 315+ case OP_INITTEXTURESTAGE: // Initializes a texture stage.
313316 error = DDERR_CURRENTLYNOTAVAIL;
314317 break;
315318 default:
@@ -837,8 +840,8 @@
838841 * Draws one or more primitives to the currently selected render target.
839842 * @param This
840843 * Pointer to glRenderer object
841 - * @param device
842 - * glDirect3DDevice7 interface to use for drawing
 844+ * @param target
 845+ * Textures and mip levels of the current render target
843846 * @param mode
844847 * OpenGL primitive drawing mode to use
845848 * @param vertices
@@ -861,11 +864,10 @@
862865 * D3D_OK if the call succeeds, or D3DERR_INVALIDVERTEXTYPE if the vertex format
863866 * has no position coordinates.
864867 */
865 -HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
 868+HRESULT glRenderer_DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
866869 DWORD indexcount, DWORD flags)
867870 {
868871 EnterCriticalSection(&This->cs);
869 - This->inputs[0] = device;
870872 This->inputs[1] = (void*)mode;
871873 This->inputs[2] = vertices;
872874 This->inputs[3] = texformats;
@@ -873,6 +875,7 @@
874876 This->inputs[5] = indices;
875877 This->inputs[6] = (void*)indexcount;
876878 This->inputs[7] = (void*)flags;
 879+ memcpy(&This->inputs[8], target, sizeof(RenderTarget));
877880 This->opcode = OP_DRAWPRIMITIVES;
878881 SetEvent(This->start);
879882 WaitForSingleObject(This->busy,INFINITE);
@@ -1276,7 +1279,7 @@
12771280 glRenderer__Flush(This);
12781281 break;
12791282 case OP_DRAWPRIMITIVES:
1280 - glRenderer__DrawPrimitives(This,(glDirect3DDevice7*)This->inputs[0],(GLenum)This->inputs[1],
 1283+ glRenderer__DrawPrimitives(This,(RenderTarget*)&This->inputs[8],(GLenum)This->inputs[1],
12811284 (GLVERTEX*)This->inputs[2],(int*)This->inputs[3],(DWORD)This->inputs[4],(LPWORD)This->inputs[5],
12821285 (DWORD)This->inputs[6],(DWORD)This->inputs[7]);
12831286 break;
@@ -2505,7 +2508,7 @@
25062509 glUtil_BlendFunc(This->util, glsrc, gldest);
25072510 }
25082511
2509 -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
 2512+void glRenderer__DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
25102513 DWORD indexcount, DWORD flags)
25112514 {
25122515 bool transformed;
@@ -2516,10 +2519,10 @@
25172520 int i;
25182521 glTexture *ztexture = NULL;
25192522 GLint zlevel = 0;
2520 - if (device->glDDS7->zbuffer)
 2523+ if (target->zbuffer)
25212524 {
2522 - ztexture = device->glDDS7->zbuffer->texture;
2523 - zlevel = device->glDDS7->zbuffer->miplevel;
 2525+ ztexture = target->zbuffer;
 2526+ zlevel = target->zlevel;
25242527 }
25252528 if(vertices[1].data) transformed = true;
25262529 else transformed = false;
@@ -2720,21 +2723,21 @@
27212724 if(prog->uniforms[139]!= -1) This->ext->glUniform1f(prog->uniforms[139],This->viewport.dwX);
27222725 if(prog->uniforms[140]!= -1) This->ext->glUniform1f(prog->uniforms[140],This->viewport.dwY);
27232726 if(prog->uniforms[141]!= -1) This->ext->glUniform1i(prog->uniforms[141],This->renderstate[D3DRENDERSTATE_ALPHAREF]);
2724 - if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
 2727+ if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)target->target->colorbits);
27252728 do
27262729 {
2727 - if (glUtil_SetFBOSurface(This->util, device->glDDS7->texture, ztexture,
2728 - device->glDDS7->miplevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
2729 - if (!device->glDDS7->texture->internalformats[1]) break;
2730 - glTexture__Repair(device->glDDS7->texture, TRUE);
 2730+ if (glUtil_SetFBOSurface(This->util, target->target, ztexture,
 2731+ target->level, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
 2732+ if (!target->target->internalformats[1]) break;
 2733+ glTexture__Repair(target->target, TRUE);
27312734 glUtil_SetFBO(This->util, NULL);
2732 - device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbcolor = NULL;
2733 - device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbz = NULL;
 2735+ target->target->levels[target->level].fbo.fbcolor = NULL;
 2736+ target->target->levels[target->level].fbo.fbz = NULL;
27342737 } while (1);
2735 - glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*device->glDDS7->mulx),
2736 - (int)((float)This->viewport.dwY*device->glDDS7->muly),
2737 - (int)((float)This->viewport.dwWidth*device->glDDS7->mulx),
2738 - (int)((float)This->viewport.dwHeight*device->glDDS7->muly));
 2738+ glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*target->mulx),
 2739+ (int)((float)This->viewport.dwY*target->muly),
 2740+ (int)((float)This->viewport.dwWidth*target->mulx),
 2741+ (int)((float)This->viewport.dwHeight*target->muly));
27392742 glUtil_SetDepthRange(This->util, This->viewport.dvMinZ, This->viewport.dvMaxZ);
27402743 if (This->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) glUtil_BlendEnable(This->util, TRUE);
27412744 else glUtil_BlendEnable(This->util, FALSE);
@@ -2748,8 +2751,8 @@
27492752 glUtil_SetShadeMode(This->util, (D3DSHADEMODE)This->renderstate[D3DRENDERSTATE_SHADEMODE]);
27502753 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
27512754 else glDrawArrays(mode,0,count);
2752 - if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->texture->levels[device->glDDS7->miplevel].dirty |= 2;
2753 - device->glDDS7->texture->levels[device->glDDS7->miplevel].dirty |= 2;
 2755+ if(target->zbuffer) target->zbuffer->levels[target->zlevel].dirty |= 2;
 2756+ target->target->levels[target->level].dirty |= 2;
27542757 if(flags & D3DDP_WAIT) glFlush();
27552758 This->outputs[0] = (void*)D3D_OK;
27562759 SetEvent(This->busy);
Index: ddraw/glRenderer.h
@@ -109,7 +109,7 @@
110110 #define OP_SETTEXTURECOLORKEY 23
111111 #define OP_MAKETEXTUREPRIMARY 24
112112 #define OP_ENDCOMMAND 25
113 -#define OP_SETMODE2D 26
 113+#define OP_INITTEXTURESTAGE 26
114114
115115 extern const DWORD renderstate_default[153];
116116 extern const TEXTURESTAGE texstagedefault0;
@@ -158,6 +158,7 @@
159159 D3DMATRIX transform[24];
160160 D3DVIEWPORT7 viewport;
161161 CommandBuffer cmd1, cmd2;
 162+ float mulx, muly;
162163 RenderState state;
163164 size_t scenesize, scenesizevertex, scenesizeindex;
164165 } glRenderer;
@@ -177,7 +178,7 @@
178179 void glRenderer_Flush(glRenderer *This);
179180 void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd);
180181 HRESULT glRenderer_Clear(glRenderer *This, ClearCommand *cmd);
181 -HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
 182+HRESULT glRenderer_DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
182183 DWORD indexcount, DWORD flags);
183184 //void glRenderer_UpdateClipper(glRenderer *This, glTexture *stencil, GLushort *indices, BltVertex *vertices,
184185 void glRenderer_UpdateClipper(glRenderer *This, glTexture *stencil, GLushort *indices, BltVertex *vertices,
@@ -210,7 +211,7 @@
211212 void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, int progtype);
212213 void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
213214 void glRenderer__Clear(glRenderer *This, ClearCommand *cmd);
214 -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
 215+void glRenderer__DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
215216 DWORD indexcount, DWORD flags);
216217 void glRenderer__Flush(glRenderer *This);
217218 void glRenderer__SetWnd(glRenderer *This, int width, int height, int fullscreen, int bpp, unsigned int frequency, HWND newwnd, BOOL devwnd);
Index: ddraw/struct.h
@@ -455,4 +455,14 @@
456456 BltCommand last_blt;
457457 } RenderState;
458458
 459+typedef struct RenderTarget
 460+{
 461+ glTexture *target;
 462+ glTexture *zbuffer;
 463+ GLint level;
 464+ GLint zlevel;
 465+ float mulx;
 466+ float muly;
 467+} RenderTarget;
 468+
459469 #endif //__STRUCT_H
\ No newline at end of file
Index: ddraw/struct_command.h
@@ -62,7 +62,7 @@
6363 glTexture *paltex;
6464 GLint vsync;
6565 glTexture *previous;
66 -};
 66+} DrawScreenCmd;
6767 typedef struct InitD3DCmd
6868 {
6969 DWORD opcode;
@@ -70,11 +70,22 @@
7171 int zbuffer;
7272 int x;
7373 int y;
74 -};
 74+} InitD3DCmd;
7575 typedef struct ClearCmd
7676 {
7777 DWORD opcode;
7878 DWORD size;
7979 ClearCommand cmd;
80 -};
 80+} ClearCmd;
 81+typedef struct FlushCmd
 82+{
 83+ DWORD opcode;
 84+ DWORD size;
 85+} FlushCmd;
 86+typedef struct DrawPrimitivesCmd
 87+{
 88+ DWORD opcode;
 89+ DWORD size;
 90+ // Add params
 91+} DrawPrimitivesCmd;
8192 #endif //__STRUCT_COMMAND_H
\ No newline at end of file