DXGL r380 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r379‎ | r380 | r381 >
Date:17:37, 26 May 2013
Author:admin
Status:new
Tags:
Comment:
Improve writing to primary surface after calling WaitForVerticalBlank
Move vsync variable to client side and pass to renderer when drawing the screen. This will aid in future asynchronous rendering.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1088,6 +1088,7 @@
10891089 glDD4 = NULL;
10901090 renderer = NULL;
10911091 primary = NULL;
 1092+ lastsync = false;
10921093 fullscreen = false;
10931094 fpupreserve = false;
10941095 fpusetup = false;
@@ -1479,9 +1480,8 @@
14801481 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
14811482 if(dwFlags & DDWAITVB_BLOCKBEGINEVENT)
14821483 TRACE_RET(HRESULT,23,DDERR_UNSUPPORTED);
1483 - swapinterval=1;
1484 - primary->RenderScreen(primary->texture,primary);
1485 - swapinterval=0;
 1484+ if(!lastsync) lastsync = true;
 1485+ else primary->RenderScreen(primary->texture,primary,1);
14861486 TRACE_EXIT(23,DD_OK);
14871487 return DD_OK;
14881488 }
Index: ddraw/glDirectDraw.h
@@ -84,6 +84,7 @@
8585 void DeleteClipper(glDirectDrawClipper *clipper);
8686 glDirectDrawSurface7 *primary;
8787 bool primarylost;
 88+ bool lastsync;
8889 glDirectDraw1 *glDD1;
8990 glDirectDraw2 *glDD2;
9091 glDirectDraw4 *glDD4;
Index: ddraw/glDirectDrawSurface.cpp
@@ -687,7 +687,15 @@
688688 TRACE_ENTER(3,14,this,14,lpDDSurfaceTargetOverride,9,dwFlags);
689689 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
690690 HRESULT ret = Flip2(lpDDSurfaceTargetOverride,dwFlags);
691 - if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) RenderScreen(texture,this);
 691+ if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
 692+ {
 693+ if(ddInterface->lastsync)
 694+ {
 695+ swapinterval++;
 696+ ddInterface->lastsync = false;
 697+ }
 698+ RenderScreen(texture,this,swapinterval);
 699+ }
692700 TRACE_EXIT(23,ret);
693701 return ret;
694702 }
@@ -1213,8 +1221,12 @@
12141222 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
12151223 !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))
12161224 {
1217 - swapinterval = 0;
1218 - RenderScreen(texture,this);
 1225+ if(ddInterface->lastsync)
 1226+ {
 1227+ RenderScreen(texture,this,1);
 1228+ ddInterface->lastsync = false;
 1229+ }
 1230+ else RenderScreen(texture,this,0);
12191231 }
12201232 TRACE_EXIT(23,DD_OK);
12211233 return DD_OK;
@@ -1244,10 +1256,10 @@
12451257 ERR(DDERR_GENERIC);
12461258 }
12471259
1248 -void glDirectDrawSurface7::RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface)
 1260+void glDirectDrawSurface7::RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface, int vsync)
12491261 {
12501262 TRACE_ENTER(3,14,this,14,texture,14,surface);
1251 - renderer->DrawScreen(texture,paltex,this,surface);
 1263+ renderer->DrawScreen(texture,paltex,this,surface,vsync);
12521264 TRACE_EXIT(0,0);
12531265 }
12541266 // ddraw 2+ api
Index: ddraw/glDirectDrawSurface.h
@@ -105,7 +105,7 @@
106106 void SetTexture(TEXTURE *newtexture){texture = newtexture;};
107107 glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
108108 glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
109 - void RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface);
 109+ void RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface, int vsync);
110110 // Special ddraw2->ddraw7 api
111111 HRESULT WINAPI Unlock2(LPVOID lpSurfaceData);
112112 HRESULT GetHandle(glDirect3DDevice7 *glD3DDev7, LPD3DTEXTUREHANDLE lpHandle);
@@ -136,6 +136,7 @@
137137 D3DMATERIALHANDLE handle;
138138 FBO fbo;
139139 private:
 140+ int swapinterval;
140141 ULONG refcount;
141142 int locked;
142143 HDC hdc;
Index: ddraw/glRenderer.cpp
@@ -64,7 +64,6 @@
6565 }
6666
6767 int oldswap = 0;
68 -int swapinterval = 0;
6968
7069 /**
7170 * Sets the Windows OpenGL swap interval
@@ -439,8 +438,10 @@
440439 * Destination surface to be updated
441440 * @param src
442441 * Source surface to be updated
 442+ * @param vsync
 443+ * Vertical sync count
443444 */
444 -void glRenderer::DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
 445+void glRenderer::DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync)
445446 {
446447 EnterCriticalSection(&cs);
447448 inputs[0] = texture;
@@ -447,6 +448,7 @@
448449 inputs[1] = paltex;
449450 inputs[2] = dest;
450451 inputs[3] = src;
 452+ inputs[4] = (void*)vsync;
451453 opcode = OP_DRAWSCREEN;
452454 SetEvent(start);
453455 WaitForSingleObject(busy,INFINITE);
@@ -681,7 +683,7 @@
682684 (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
683685 break;
684686 case OP_DRAWSCREEN:
685 - _DrawScreen((TEXTURE*)inputs[0],(TEXTURE*)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3],true);
 687+ _DrawScreen((TEXTURE*)inputs[0],(TEXTURE*)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3],(GLint)inputs[4],true);
686688 break;
687689 case OP_INITD3D:
688690 _InitD3D((int)inputs[0]);
@@ -983,7 +985,7 @@
984986 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
985987 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
986988 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
987 - !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest,false);
 989+ !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest,0,false);
988990 outputs[0] = DD_OK;
989991 SetEvent(busy);
990992 }
@@ -1042,7 +1044,7 @@
10431045 SetFBO((FBO*)NULL);
10441046 }
10451047
1046 -void glRenderer::_DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, bool setsync)
 1048+void glRenderer::_DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync)
10471049 {
10481050 int progtype;
10491051 RECT r,r2;
@@ -1056,7 +1058,7 @@
10571059 }
10581060 DepthTest(false);
10591061 RECT *viewrect = &r2;
1060 - SetSwap(swapinterval);
 1062+ SetSwap(vsync);
10611063 LONG sizes[6];
10621064 GLfloat view[4];
10631065 GLint viewport[4];
Index: ddraw/glRenderer.h
@@ -77,7 +77,6 @@
7878 #define OP_DELETEFBO 13
7979
8080
81 -extern int swapinterval;
8281 extern inline void SetSwap(int swap);
8382
8483 class glDirectDraw7;
@@ -99,7 +98,7 @@
10099 HRESULT Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
101100 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
102101 void MakeTexture(TEXTURE *texture, DWORD width, DWORD height);
103 - void DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
 102+ void DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync);
104103 void DeleteTexture(TEXTURE *texture);
105104 void InitD3D(int zbuffer);
106105 void Flush();
@@ -119,7 +118,7 @@
120119 void _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
121120 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
122121 void _MakeTexture(TEXTURE *texture, DWORD width, DWORD height);
123 - void _DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, bool setsync);
 122+ void _DrawScreen(TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync);
124123 void _DeleteTexture(TEXTURE *texture);
125124 void _DrawBackbuffer(TEXTURE **texture, int x, int y, int progtype);
126125 void _InitD3D(int zbuffer);