DXGL r672 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r671‎ | r672 | r673 >
Date:23:19, 23 July 2016
Author:admin
Status:new
Tags:
Comment:
Isolate glRenderer__Clear from DDraw surface structure.
Make glRenderer__Clear support high-resolution primary and fix flipped clear rects.
Fix a small regression in glRenderer__Clear.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/struct.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -575,10 +575,29 @@
576576 }
577577 HRESULT WINAPI glDirect3DDevice7::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
578578 {
 579+ ClearCommand cmd;
579580 TRACE_ENTER(7,14,this,8,dwCount,14,lpRects,9,dwFlags,9,dwColor,19,&dvZ,9,dwStencil);
580581 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
581582 if(dwCount && !lpRects) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
582 - TRACE_RET(HRESULT,23,glRenderer_Clear(renderer,glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil));
 583+ cmd.dwCount = dwCount;
 584+ cmd.lpRects = lpRects;
 585+ cmd.dwFlags = dwFlags;
 586+ cmd.dwColor = dwColor;
 587+ cmd.dvZ = dvZ;
 588+ cmd.dwStencil = dwStencil;
 589+ cmd.target = glDDS7->texture;
 590+ cmd.targetlevel = glDDS7->miplevel;
 591+ if (glDDS7->zbuffer)
 592+ {
 593+ cmd.zbuffer = glDDS7->zbuffer->texture;
 594+ cmd.zlevel = glDDS7->zbuffer->miplevel;
 595+ }
 596+ else
 597+ {
 598+ cmd.zbuffer = NULL;
 599+ cmd.zlevel = 0;
 600+ }
 601+ TRACE_RET(HRESULT,23,glRenderer_Clear(renderer,&cmd));
583602 }
584603
585604 // ComputeSphereVisibility based on modified code from the Wine project, subject
Index: ddraw/glRenderer.cpp
@@ -424,33 +424,15 @@
425425 * Clears the viewport.
426426 * @param This
427427 * Pointer to glRenderer object
428 - * @param target
429 - * Surface to be cleared
430 - * @param dwCount
431 - * Number of rects to use to clear the buffer, or 0 to clear the entire buffer.
432 - * @param lpRects
433 - * Pointer to rects to clear.
434 - * @param dwFlags
435 - * Flags to determine which surfaces to clear.
436 - * @param dwColor
437 - * Color value to fill the surface with.
438 - * @param dvZ
439 - * Value to fill the Z buffer with.
440 - * @param dwStencil
441 - * Value to fill the stencil buffer with.
 428+ * @param cmd
 429+ * Pointer to structure contaning all paramaters for a Clear operation.
442430 * @return
443431 * Returns D3D_OK
444432 */
445 -HRESULT glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
 433+HRESULT glRenderer_Clear(glRenderer *This, ClearCommand *cmd)
446434 {
447435 EnterCriticalSection(&This->cs);
448 - This->inputs[0] = target;
449 - This->inputs[1] = (void*)dwCount;
450 - This->inputs[2] = lpRects;
451 - This->inputs[3] = (void*)dwFlags;
452 - This->inputs[4] = (void*)dwColor;
453 - memcpy(&This->inputs[5],&dvZ,4);
454 - This->inputs[6] = (void*)dwStencil;
 436+ This->inputs[0] = cmd;
455437 This->opcode = OP_CLEAR;
456438 SetEvent(This->start);
457439 WaitForSingleObject(This->busy,INFINITE);
@@ -460,7 +442,7 @@
461443
462444 /**
463445 * Instructs the OpenGL driver to send all queued commands to the GPU.
464 - * @param This
 446+ * @param Thisf
465447 * Pointer to glRenderer object
466448 */
467449 void glRenderer_Flush(glRenderer *This)
@@ -971,9 +953,7 @@
972954 glRenderer__InitD3D(This,(int)This->inputs[0],(int)This->inputs[1],(int)This->inputs[2]);
973955 break;
974956 case OP_CLEAR:
975 - memcpy(&tmpfloats[0],&This->inputs[5],4);
976 - glRenderer__Clear(This,(glDirectDrawSurface7*)This->inputs[0],(DWORD)This->inputs[1],
977 - (LPD3DRECT)This->inputs[2],(DWORD)This->inputs[3],(DWORD)This->inputs[4],tmpfloats[0],(DWORD)This->inputs[6]);
 957+ glRenderer__Clear(This,(ClearCommand*)This->inputs[0]);
978958 break;
979959 case OP_FLUSH:
980960 glRenderer__Flush(This);
@@ -1949,57 +1929,77 @@
19501930 This->shaderstate3d.stateid = InitShaderState(This, This->renderstate, This->texstages, This->lights);
19511931 }
19521932
1953 -void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
 1933+void glRenderer__Clear(glRenderer *This, ClearCommand *cmd)
19541934 {
19551935 This->outputs[0] = (void*)D3D_OK;
19561936 GLfloat color[4];
19571937 glTexture *ztexture = NULL;
19581938 GLint zlevel = 0;
1959 - if (target->zbuffer)
 1939+ GLfloat mulx, muly;
 1940+ if (cmd->zbuffer)
19601941 {
1961 - ztexture = target->zbuffer->texture;
1962 - zlevel = target->zbuffer->miplevel;
 1942+ ztexture = cmd->zbuffer;
 1943+ zlevel = cmd->zlevel;
19631944 }
1964 - dwordto4float(dwColor,color);
 1945+ dwordto4float(cmd->dwColor,color);
19651946 do
19661947 {
1967 - if (glUtil_SetFBOSurface(This->util, target->texture, ztexture,
1968 - target->zbuffer->miplevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
1969 - if (!target->texture->internalformats[1]) break;
1970 - glTexture__Repair(target->texture, TRUE);
 1948+ if (glUtil_SetFBOSurface(This->util, cmd->target, ztexture,
 1949+ cmd->targetlevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
 1950+ if (!cmd->target->internalformats[1]) break;
 1951+ glTexture__Repair(cmd->target, TRUE);
19711952 glUtil_SetFBO(This->util, NULL);
1972 - target->texture->levels[target->miplevel].fbo.fbcolor = NULL;
1973 - target->texture->levels[target->miplevel].fbo.fbz = NULL;
 1953+ cmd->target->levels[cmd->targetlevel].fbo.fbcolor = NULL;
 1954+ cmd->target->levels[cmd->targetlevel].fbo.fbz = NULL;
19741955 } while (1);
19751956 int clearbits = 0;
1976 - if(dwFlags & D3DCLEAR_TARGET)
 1957+ if(cmd->dwFlags & D3DCLEAR_TARGET)
19771958 {
19781959 clearbits |= GL_COLOR_BUFFER_BIT;
19791960 glUtil_ClearColor(This->util, color[0], color[1], color[2], color[3]);
19801961 }
1981 - if(dwFlags & D3DCLEAR_ZBUFFER)
 1962+ if(cmd->dwFlags & D3DCLEAR_ZBUFFER)
19821963 {
19831964 clearbits |= GL_DEPTH_BUFFER_BIT;
1984 - glUtil_ClearDepth(This->util, dvZ);
 1965+ glUtil_ClearDepth(This->util, cmd->dvZ);
19851966 glUtil_DepthWrite(This->util, TRUE);
19861967 }
1987 - if(dwFlags & D3DCLEAR_STENCIL)
 1968+ if(cmd->dwFlags & D3DCLEAR_STENCIL)
19881969 {
19891970 clearbits |= GL_STENCIL_BUFFER_BIT;
1990 - glUtil_ClearStencil(This->util, dwStencil);
 1971+ glUtil_ClearStencil(This->util, cmd->dwStencil);
19911972 }
1992 - if(dwCount)
 1973+ if(cmd->dwCount)
19931974 {
1994 - for(DWORD i = 0; i < dwCount; i++)
 1975+ if (cmd->targetlevel == 0 && (cmd->target->levels[0].ddsd.dwWidth != cmd->target->bigwidth) ||
 1976+ (cmd->target->levels[0].ddsd.dwHeight != cmd->target->bigheight))
19951977 {
1996 - glUtil_SetScissor(This->util, TRUE, lpRects[i].x1, lpRects[i].y1, lpRects[i].x2, lpRects[i].y2);
1997 - glClear(clearbits);
 1978+ mulx = cmd->target->bigwidth / cmd->target->levels[0].ddsd.dwWidth;
 1979+ muly = cmd->target->bigheight / cmd->target->levels[0].ddsd.dwHeight;
 1980+ for (DWORD i = 0; i < cmd->dwCount; i++)
 1981+ {
 1982+ glUtil_SetScissor(This->util, TRUE, cmd->lpRects[i].x1*mulx,
 1983+ (cmd->target->bigheight - (GLsizei)((GLfloat)cmd->lpRects[i].y1*muly)),
 1984+ cmd->lpRects[i].x2*mulx, (cmd->target->bigheight - ((GLfloat)cmd->lpRects[i].y2*muly)));
 1985+ glClear(clearbits);
 1986+ }
19981987 }
 1988+ else
 1989+ {
 1990+ for (DWORD i = 0; i < cmd->dwCount; i++)
 1991+ {
 1992+ glUtil_SetScissor(This->util, TRUE, cmd->lpRects[i].x1,
 1993+ cmd->target->levels[cmd->targetlevel].ddsd.dwHeight - cmd->lpRects[i].y1,
 1994+ cmd->lpRects[i].x2,
 1995+ cmd->target->levels[cmd->targetlevel].ddsd.dwHeight - cmd->lpRects[i].y2);
 1996+ glClear(clearbits);
 1997+ }
 1998+ }
19991999 glUtil_SetScissor(This->util, false, 0, 0, 0, 0);
20002000 }
20012001 else glClear(clearbits);
2002 - if(target->zbuffer) target->zbuffer->texture->levels[target->zbuffer->miplevel].dirty |= 2;
2003 - target->texture->levels[target->miplevel].dirty |= 2;
 2002+ if(cmd->zbuffer) cmd->zbuffer->levels[zlevel].dirty |= 2;
 2003+ cmd->target->levels[cmd->targetlevel].dirty |= 2;
20042004 SetEvent(This->busy);
20052005 }
20062006
Index: ddraw/glRenderer.h
@@ -168,7 +168,7 @@
169169 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y);
170170 void glRenderer_Flush(glRenderer *This);
171171 void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd);
172 -HRESULT glRenderer_Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
 172+HRESULT glRenderer_Clear(glRenderer *This, ClearCommand *cmd);
173173 HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
174174 DWORD indexcount, DWORD flags);
175175 void glRenderer_DeleteFBO(glRenderer *This, FBO *fbo);
@@ -197,7 +197,7 @@
198198 void glRenderer__DrawBackbuffer(glRenderer *This, glTexture **texture, int x, int y, int progtype);
199199 void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, int progtype);
200200 void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
201 -void glRenderer__Clear(glRenderer *This, glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
 201+void glRenderer__Clear(glRenderer *This, ClearCommand *cmd);
202202 void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
203203 DWORD indexcount, DWORD flags);
204204 void glRenderer__Flush(glRenderer *This);
Index: ddraw/struct.h
@@ -376,6 +376,20 @@
377377 GLint patternlevel;
378378 }BltCommand;
379379
 380+typedef struct ClearCommand
 381+{
 382+ DWORD dwCount;
 383+ LPD3DRECT lpRects;
 384+ DWORD dwFlags;
 385+ DWORD dwColor;
 386+ D3DVALUE dvZ;
 387+ DWORD dwStencil;
 388+ glTexture *target;
 389+ glTexture *zbuffer;
 390+ GLint targetlevel;
 391+ GLint zlevel;
 392+}ClearCommand;
 393+
380394 struct glDirectDrawPaletteVtbl;
381395
382396 // Structure for glDirectDrawPalette, emulates IDirectDrawPalette

Follow-up revisions

RevisionCommit summaryAuthorDate
r673Fix regression from r672, wasn't supposed to be flipped in the first place.admin00:26, 24 July 2016