DXGL r100 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r99‎ | r100 | r101 >
Date:21:56, 12 February 2012
Author:admin
Status:new
Tags:
Comment:
Validate more parameters.
Move some D3D code to render thread
Remove legacy OpenGL lighting calls (were not implemented anyway)
Modified paths:
  • /ddraw/common.h (modified) (history)
  • /ddraw/glDirect3D.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DLight.cpp (modified) (history)
  • /ddraw/glDirect3DLight.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)

Diff [purge]

Index: ddraw/common.h
@@ -82,6 +82,14 @@
8383 static inline int NextMultipleOf8(int number){return ((number+7) & (~7));}
8484 static inline int NextMultipleOf4(int number){return ((number+3) & (~3));}
8585 static inline int NextMultipleOf2(int number){return ((number+1) & (~1));}
 86+static inline void dwordto4float(DWORD in, GLfloat *out)
 87+{
 88+ out[0] = (GLfloat)((in>>16) & 0xff) / 255.0f;
 89+ out[1] = (GLfloat)((in>>8) & 0xff) / 255.0f;
 90+ out[2] = (GLfloat)(in& 0xff) / 255.0f;
 91+ out[3] = (GLfloat)((in>>24) & 0xff) / 255.0f;
 92+}
 93+
8694 #ifdef _M_X64
8795 #define NextMultipleOfWord NextMultipleOf8
8896 #else
Index: ddraw/glDirect3D.h
@@ -34,8 +34,8 @@
3535 HRESULT WINAPI EnumDevices(LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback, LPVOID lpUserArg);
3636 HRESULT WINAPI EnumZBufferFormats(REFCLSID riidDevice, LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback, LPVOID lpContext);
3737 HRESULT WINAPI EvictManagedTextures();
 38+ glDirectDraw7 *glDD7;
3839 private:
39 - glDirectDraw7 *glDD7;
4040 ULONG refcount;
4141 };
4242
Index: ddraw/glDirect3DDevice.cpp
@@ -17,19 +17,13 @@
1818
1919 #include "common.h"
2020 #include "glDirect3D.h"
 21+#include "glDirectDraw.h"
2122 #include "glDirectDrawSurface.h"
2223 #include "glDirect3DDevice.h"
2324 #include "glDirect3DLight.h"
 25+#include "glRenderer.h"
2426 #include "glutil.h"
2527
26 -inline void dwordto4float(DWORD in, GLfloat *out)
27 -{
28 - out[0] = (GLfloat)((in>>16) & 0xff) / 255.0f;
29 - out[1] = (GLfloat)((in>>8) & 0xff) / 255.0f;
30 - out[2] = (GLfloat)(in& 0xff) / 255.0f;
31 - out[3] = (GLfloat)((in>>24) & 0xff) / 255.0f;
32 -}
33 -
3428 const DWORD renderstate_default[153] = {0, // 0
3529 NULL, //texturehandle
3630 D3DANTIALIAS_NONE, //antialias
@@ -128,11 +122,11 @@
129123
130124 glDirect3DDevice7::glDirect3DDevice7(glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
131125 {
 126+ int zbuffer = 0;
132127 vertices = normals = NULL;
133128 diffuse = specular = NULL;
134129 ZeroMemory(texcoords,8*sizeof(GLfloat*));
135130 memcpy(renderstate,renderstate_default,153*sizeof(DWORD));
136 - GLfloat ambient[] = {0.0,0.0,0.0,0.0};
137131 identity._11 = identity._22 = identity._33 = identity._44 = 1.0;
138132 identity._12 = identity._13 = identity._14 =
139133 identity._21 = identity._23 = identity._24 =
@@ -146,18 +140,13 @@
147141 this->glDDS7 = glDDS7;
148142 glDDS7->AddRef();
149143 ZeroMemory(&viewport,sizeof(D3DVIEWPORT7));
150 - glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
151 - if(glDDS7->GetZBuffer()) glEnable(GL_DEPTH_TEST);
152 - glDepthFunc(GL_LEQUAL);
153 - glDisable(GL_DITHER);
154 - glEnable(GL_LIGHTING);
155 - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
 144+ if(glDDS7->GetZBuffer()) zbuffer = 1;
156145 ZeroMemory(&material,sizeof(D3DMATERIAL7));
157146 lightsmax = 16;
158147 lights = (glDirect3DLight**) malloc(16*sizeof(glDirect3DLight*));
159148 ZeroMemory(lights,16*sizeof(glDirect3DLight*));
160149 memset(gllights,0xff,8*sizeof(int));
161 -
 150+ glD3D7->glDD7->renderer->InitD3D(zbuffer);
162151 }
163152 glDirect3DDevice7::~glDirect3DDevice7()
164153 {
@@ -235,28 +224,7 @@
236225 {
237226 if(!this) return DDERR_INVALIDPARAMS;
238227 if(dwCount && !lpRects) return DDERR_INVALIDPARAMS;
239 - if(dwCount) ERR(DDERR_INVALIDPARAMS);
240 - GLfloat color[4];
241 - dwordto4float(dwColor,color);
242 - SetFBO(glDDS7->texture,glDDS7->GetZBuffer()->texture,glDDS7->GetZBuffer()->hasstencil);
243 - int clearbits = 0;
244 - if(D3DCLEAR_TARGET)
245 - {
246 - clearbits |= GL_COLOR_BUFFER_BIT;
247 - glClearColor(color[0],color[1],color[2],color[3]);
248 - }
249 - if(D3DCLEAR_ZBUFFER)
250 - {
251 - clearbits |= GL_DEPTH_BUFFER_BIT;
252 - glClearDepth(dvZ);
253 - }
254 - if(D3DCLEAR_STENCIL)
255 - {
256 - clearbits |= GL_STENCIL_BUFFER_BIT;
257 - glClearStencil(dwStencil);
258 - }
259 - glClear(clearbits);
260 - return D3D_OK;
 228+ return glD3D7->glDD7->renderer->Clear(glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil);
261229 }
262230 HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
263231 DWORD dwFlags, LPDWORD lpdwReturnValues)
@@ -353,7 +321,7 @@
354322 if(!this) return DDERR_INVALIDPARAMS;
355323 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
356324 inscene = false;
357 - glFlush();
 325+ glD3D7->glDD7->renderer->Flush();
358326 return D3D_OK;
359327 }
360328 HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
@@ -500,7 +468,6 @@
501469 }
502470 }
503471 if(!foundlight) return D3DERR_LIGHT_SET_FAILED;
504 - lights[dwLightIndex]->SetGLLight(i);
505472 }
506473 else
507474 {
@@ -508,7 +475,6 @@
509476 {
510477 if(gllights[i] == dwLightIndex)
511478 {
512 - lights[dwLightIndex]->SetGLLight(-1);
513479 gllights[i] = -1;
514480 }
515481 }
@@ -570,43 +536,10 @@
571537 HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
572538 {
573539 if(!this) return DDERR_INVALIDPARAMS;
574 - GLfloat floats[4];
575540 if(dwRendStateType > 152) return DDERR_INVALIDPARAMS;
576541 if(dwRendStateType < 0) return DDERR_INVALIDPARAMS;
577542 renderstate[dwRendStateType] = dwRenderState;
578 - switch(dwRendStateType)
579 - {
580 - case D3DRENDERSTATE_ANTIALIAS:
581 - if(dwRenderState == 0) glDisable(GL_MULTISAMPLE);
582 - else glEnable(GL_MULTISAMPLE);
583 - return D3D_OK;
584 - case D3DRENDERSTATE_TEXTUREPERSPECTIVE:
585 - if(dwRenderState) glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
586 - else glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
587 - return D3D_OK;
588 - case D3DRENDERSTATE_ZENABLE:
589 - switch(dwRenderState)
590 - {
591 - case D3DZB_FALSE:
592 - glDisable(GL_DEPTH_TEST);
593 - break;
594 - case D3DZB_TRUE:
595 - default:
596 - case D3DZB_USEW:
597 - glEnable(GL_DEPTH_TEST);
598 - }
599 - return D3D_OK;
600 - case D3DRENDERSTATE_LIGHTING:
601 - if(dwRenderState) glEnable(GL_LIGHTING);
602 - else glDisable(GL_LIGHTING);
603 - return D3D_OK;
604 - case D3DRENDERSTATE_AMBIENT:
605 - dwordto4float(dwRenderState,floats);
606 - glLightModelfv(GL_LIGHT_MODEL_AMBIENT,floats);
607 - return D3D_OK;
608 - default:
609 - ERR(DDERR_INVALIDPARAMS);
610 - }
 543+ return D3D_OK;
611544 }
612545 HRESULT WINAPI glDirect3DDevice7::SetRenderTarget(LPDIRECTDRAWSURFACE7 lpNewRenderTarget, DWORD dwFlags)
613546 {
Index: ddraw/glDirect3DLight.cpp
@@ -25,7 +25,6 @@
2626 glDirect3DLight::glDirect3DLight()
2727 {
2828 refcount=1;
29 - gllight = -1;
3029 ZeroMemory(&light,sizeof(D3DLIGHT7));
3130 light.dltType = D3DLIGHT_DIRECTIONAL;
3231 light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = 1.0f;
@@ -34,14 +33,11 @@
3534 glDirect3DLight::glDirect3DLight(D3DLIGHT7 *light_in)
3635 {
3736 refcount=1;
38 - gllight = -1;
3937 memcpy(&light,light_in,sizeof(D3DLIGHT7));
4038 }
4139
4240 glDirect3DLight::~glDirect3DLight()
4341 {
44 - if(gllight != -1)
45 - glDisable(GL_LIGHT0+gllight);
4642 }
4743
4844 ULONG WINAPI glDirect3DLight::AddRef()
@@ -80,7 +76,6 @@
8177 void glDirect3DLight::SetLight7(LPD3DLIGHT7 lpLight7)
8278 {
8379 memcpy(&light,lpLight7,sizeof(D3DLIGHT7));
84 - if(gllight != -1) SetGLLight(gllight);
8580 }
8681
8782 HRESULT WINAPI glDirect3DLight::GetLight(LPD3DLIGHT lpLight)
@@ -94,37 +89,4 @@
9590 if(!this) return DDERR_INVALIDPARAMS;
9691 FIXME("glDirect3DLight::SetLight: stub");
9792 ERR(DDERR_GENERIC);
98 -}
99 -
100 -void glDirect3DLight::SetGLLight(int gllightin)
101 -{
102 - const float angle_dx_gl = 90.0f / (float)M_PI;
103 - if(gllightin != -1)
104 - {
105 - if(gllightin != gllight) glDisable(GL_LIGHT0+gllight);
106 - GLfloat ambient[] = {light.dcvAmbient.r,light.dcvAmbient.g,light.dcvAmbient.b,light.dcvAmbient.a};
107 - glLightfv(GL_LIGHT0+gllightin,GL_AMBIENT,ambient);
108 - GLfloat diffuse[] = {light.dcvDiffuse.r,light.dcvDiffuse.g,light.dcvDiffuse.b,light.dcvDiffuse.a};
109 - glLightfv(GL_LIGHT0+gllightin,GL_DIFFUSE,diffuse);
110 - GLfloat specular[] = {light.dcvSpecular.r,light.dcvSpecular.g,light.dcvSpecular.b,light.dcvSpecular.a};
111 - glLightfv(GL_LIGHT0+gllightin,GL_DIFFUSE,specular);
112 - if(light.dltType == D3DLIGHT_DIRECTIONAL)
113 - GLfloat position[] = {light.dvPosition.x,light.dvPosition.y,light.dvPosition.z,0.};
114 - else GLfloat position[] = {light.dvPosition.x,light.dvPosition.y,light.dvPosition.z,1.};
115 - glLightfv(GL_LIGHT0+gllightin,GL_POSITION,specular);
116 - GLfloat direction[] = {light.dvDirection.x,light.dvDirection.y,light.dvDirection.z};
117 - glLightfv(GL_LIGHT0+gllightin,GL_SPOT_DIRECTION,specular);
118 - if(light.dltType == D3DLIGHT_SPOT)
119 - glLightf(GL_LIGHT0+gllightin,GL_SPOT_CUTOFF,angle_dx_gl*light.dvPhi);
120 - else glLightf(GL_LIGHT0+gllightin,GL_SPOT_CUTOFF,180.0);
121 - glLightf(GL_LIGHT0+gllightin,GL_CONSTANT_ATTENUATION,light.dvAttenuation0);
122 - glLightf(GL_LIGHT0+gllightin,GL_LINEAR_ATTENUATION,light.dvAttenuation1);
123 - glLightf(GL_LIGHT0+gllightin,GL_QUADRATIC_ATTENUATION,light.dvAttenuation2);
124 - glEnable(GL_LIGHT0+gllightin);
125 - }
126 - else
127 - {
128 - glDisable(GL_LIGHT0+gllightin);
129 - }
130 - gllight = gllightin;
13193 }
\ No newline at end of file
Index: ddraw/glDirect3DLight.h
@@ -34,13 +34,10 @@
3535 HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
3636 HRESULT WINAPI SetLight(LPD3DLIGHT lpLight);
3737 void SetLight7(LPD3DLIGHT7 lpLight7);
38 - void SetGLLight(int gllightin);
39 - void GetGLLight(int *gllightout){*gllightout=gllight;};
4038 D3DLIGHT7 light;
4139 private:
4240 ULONG refcount;
4341 D3DLIGHT2 convert;
44 - int gllight;
4542 };
4643
4744 #endif //__GLDIRECT3DLIGHT_H
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -530,6 +530,7 @@
531531 HRESULT WINAPI glDirectDrawSurface7::AddAttachedSurface(LPDIRECTDRAWSURFACE7 lpDDSAttachedSurface)
532532 {
533533 if(!this) return DDERR_INVALIDPARAMS;
 534+ if(!lpDDSAttachedSurface) return DDERR_INVALIDPARAMS;
534535 if(zbuffer) ERR(DDERR_SURFACEALREADYATTACHED);
535536 glDirectDrawSurface7 *attached = (glDirectDrawSurface7 *)lpDDSAttachedSurface;
536537 DDSURFACEDESC2 ddsd;
@@ -726,7 +727,7 @@
727728 backbuffer->AddRef();
728729 return DD_OK;
729730 }
730 - else
 731+ else if(zbuffer)
731732 {
732733 zbuffer->GetCaps(&ddsComp);
733734 memcpy(&comp1,lpDDSCaps,sizeof(unsigned __int64));
@@ -737,8 +738,8 @@
738739 zbuffer->AddRef();
739740 return DD_OK;
740741 }
741 - ERR(DDERR_NOTFOUND);
742742 }
 743+ ERR(DDERR_NOTFOUND);
743744 }
744745 HRESULT WINAPI glDirectDrawSurface7::GetBltStatus(DWORD dwFlags)
745746 {
@@ -749,6 +750,7 @@
750751 HRESULT WINAPI glDirectDrawSurface7::GetCaps(LPDDSCAPS2 lpDDSCaps)
751752 {
752753 if(!this) return DDERR_INVALIDPARAMS;
 754+ if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
753755 memcpy(lpDDSCaps,&ddsd.ddsCaps,sizeof(DDSCAPS2));
754756 return DD_OK;
755757 }
@@ -761,6 +763,7 @@
762764 HRESULT WINAPI glDirectDrawSurface7::GetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey)
763765 {
764766 if(!this) return DDERR_INVALIDPARAMS;
 767+ if(!lpDDColorKey) return DDERR_INVALIDPARAMS;
765768 if(dwFlags == DDCKEY_SRCBLT)
766769 {
767770 if(colorkey[0].enabled)
@@ -802,6 +805,7 @@
803806 HRESULT WINAPI glDirectDrawSurface7::GetDC(HDC FAR *lphDC)
804807 {
805808 if(!this) return DDERR_INVALIDPARAMS;
 809+ if(!lphDC) return DDERR_INVALIDPARAMS;
806810 if(hdc) ERR(DDERR_DCALREADYCREATED);
807811 glDirectDrawPalette *pal;
808812 DWORD colors[256];
@@ -862,6 +866,7 @@
863867 HRESULT WINAPI glDirectDrawSurface7::GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat)
864868 {
865869 if(!this) return DDERR_INVALIDPARAMS;
 870+ if(!lpDDPixelFormat) return DDERR_INVALIDPARAMS;
866871 *lpDDPixelFormat = ddsd.ddpfPixelFormat;
867872 return DD_OK;
868873 }
@@ -868,7 +873,7 @@
869874 HRESULT WINAPI glDirectDrawSurface7::GetSurfaceDesc(LPDDSURFACEDESC2 lpDDSurfaceDesc)
870875 {
871876 if(!this) return DDERR_INVALIDPARAMS;
872 - if(!lpDDSurfaceDesc) ERR(DDERR_INVALIDPARAMS);
 877+ if(!lpDDSurfaceDesc) return DDERR_INVALIDPARAMS;
873878 memcpy(lpDDSurfaceDesc,&ddsd,lpDDSurfaceDesc->dwSize);
874879 return DD_OK;
875880 }
@@ -1024,6 +1029,7 @@
10251030 HRESULT WINAPI glDirectDrawSurface7::SetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey)
10261031 {
10271032 if(!this) return DDERR_INVALIDPARAMS;
 1033+ if(!lpDDColorKey) ERR(DDERR_GENERIC);
10281034 CKEY key;
10291035 key.enabled = true;
10301036 if(dwFlags & DDCKEY_COLORSPACE) key.colorspace = true;
@@ -1263,6 +1269,7 @@
12641270 HRESULT WINAPI glDirectDrawSurface1::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE FAR *lplpDDAttachedSurface)
12651271 {
12661272 if(!this) return DDERR_INVALIDPARAMS;
 1273+ if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
12671274 HRESULT error;
12681275 glDirectDrawSurface7 *attachedsurface;
12691276 glDirectDrawSurface1 *attached1;
@@ -1286,6 +1293,7 @@
12871294 HRESULT WINAPI glDirectDrawSurface1::GetCaps(LPDDSCAPS lpDDSCaps)
12881295 {
12891296 if(!this) return DDERR_INVALIDPARAMS;
 1297+ if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
12901298 HRESULT error;
12911299 DDSCAPS2 ddsCaps1;
12921300 error = glDDS7->GetCaps(&ddsCaps1);
@@ -1504,6 +1512,7 @@
15051513 HRESULT WINAPI glDirectDrawSurface2::GetCaps(LPDDSCAPS lpDDSCaps)
15061514 {
15071515 if(!this) return DDERR_INVALIDPARAMS;
 1516+ if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
15081517 HRESULT error;
15091518 DDSCAPS2 ddsCaps1;
15101519 error = glDDS7->GetCaps(&ddsCaps1);
@@ -1737,6 +1746,7 @@
17381747 HRESULT WINAPI glDirectDrawSurface3::GetCaps(LPDDSCAPS lpDDSCaps)
17391748 {
17401749 if(!this) return DDERR_INVALIDPARAMS;
 1750+ if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
17411751 HRESULT error;
17421752 DDSCAPS2 ddsCaps1;
17431753 error = glDDS7->GetCaps(&ddsCaps1);
Index: ddraw/glRenderer.cpp
@@ -324,6 +324,69 @@
325325 LeaveCriticalSection(&cs);
326326 }
327327
 328+void glRenderer::InitD3D(int zbuffer)
 329+{
 330+ MSG Msg;
 331+ EnterCriticalSection(&cs);
 332+ wndbusy = true;
 333+ inputs[0] = (void*)zbuffer;
 334+ SendMessage(hRenderWnd,GLEVENT_INITD3D,0,0);
 335+ while(wndbusy)
 336+ {
 337+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 338+ {
 339+ TranslateMessage(&Msg);
 340+ DispatchMessage(&Msg);
 341+ }
 342+ Sleep(0);
 343+ }
 344+ LeaveCriticalSection(&cs);
 345+}
 346+
 347+HRESULT glRenderer::Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
 348+{
 349+ MSG Msg;
 350+ EnterCriticalSection(&cs);
 351+ wndbusy = true;
 352+ inputs[0] = target;
 353+ inputs[1] = (void*)dwCount;
 354+ inputs[2] = lpRects;
 355+ inputs[3] = (void*)dwFlags;
 356+ inputs[4] = (void*)dwColor;
 357+ memcpy(&inputs[5],&dvZ,4);
 358+ inputs[6] = (void*)dwStencil;
 359+ SendMessage(hRenderWnd,GLEVENT_CLEAR,0,0);
 360+ while(wndbusy)
 361+ {
 362+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 363+ {
 364+ TranslateMessage(&Msg);
 365+ DispatchMessage(&Msg);
 366+ }
 367+ Sleep(0);
 368+ }
 369+ LeaveCriticalSection(&cs);
 370+ return (HRESULT)outputs[0];
 371+}
 372+
 373+void glRenderer::Flush()
 374+{
 375+ MSG Msg;
 376+ EnterCriticalSection(&cs);
 377+ wndbusy = true;
 378+ SendMessage(hRenderWnd,GLEVENT_FLUSH,0,0);
 379+ while(wndbusy)
 380+ {
 381+ while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
 382+ {
 383+ TranslateMessage(&Msg);
 384+ DispatchMessage(&Msg);
 385+ }
 386+ Sleep(0);
 387+ }
 388+ LeaveCriticalSection(&cs);
 389+}
 390+
328391 DWORD glRenderer::_Entry()
329392 {
330393 MSG Msg;
@@ -855,10 +918,62 @@
856919 glDeleteTextures(1,&texture);
857920 }
858921
 922+void glRenderer::_InitD3D(int zbuffer)
 923+{
 924+ wndbusy = false;
 925+ glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
 926+ GLfloat ambient[] = {0.0,0.0,0.0,0.0};
 927+ if(zbuffer) glEnable(GL_DEPTH_TEST);
 928+ glDepthFunc(GL_LEQUAL);
 929+ glDisable(GL_DITHER);
 930+ glEnable(GL_LIGHTING);
 931+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
 932+}
 933+
 934+void glRenderer::_Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
 935+{
 936+ if(dwCount)
 937+ {
 938+ outputs[0] = (void*)DDERR_INVALIDPARAMS;
 939+ FIXME("glDirect3DDevice7::Clear: Cannot clear rects yet.");
 940+ wndbusy = false;
 941+ return;
 942+ }
 943+ outputs[0] = (void*)D3D_OK;
 944+ wndbusy = false;
 945+ GLfloat color[4];
 946+ dwordto4float(dwColor,color);
 947+ SetFBO(target->texture,target->GetZBuffer()->texture,target->GetZBuffer()->hasstencil);
 948+ int clearbits = 0;
 949+ if(D3DCLEAR_TARGET)
 950+ {
 951+ clearbits |= GL_COLOR_BUFFER_BIT;
 952+ glClearColor(color[0],color[1],color[2],color[3]);
 953+ }
 954+ if(D3DCLEAR_ZBUFFER)
 955+ {
 956+ clearbits |= GL_DEPTH_BUFFER_BIT;
 957+ glClearDepth(dvZ);
 958+ }
 959+ if(D3DCLEAR_STENCIL)
 960+ {
 961+ clearbits |= GL_STENCIL_BUFFER_BIT;
 962+ glClearStencil(dwStencil);
 963+ }
 964+ glClear(clearbits);
 965+}
 966+
 967+void glRenderer::_Flush()
 968+{
 969+ wndbusy = false;
 970+ glFlush();
 971+}
 972+
859973 LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
860974 {
861975 int oldx,oldy;
862976 float mulx, muly;
 977+ float tmpfloats[16];
863978 int translatex, translatey;
864979 LPARAM newpos;
865980 HWND hParent;
@@ -973,6 +1088,17 @@
9741089 case GLEVENT_DRAWSCREEN:
9751090 _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
9761091 return 0;
 1092+ case GLEVENT_INITD3D:
 1093+ _InitD3D((int)inputs[0]);
 1094+ return 0;
 1095+ case GLEVENT_CLEAR:
 1096+ memcpy(&tmpfloats[0],&inputs[5],4);
 1097+ _Clear((glDirectDrawSurface7*)inputs[0],(DWORD)inputs[1],(LPD3DRECT)inputs[2],(DWORD)inputs[3],(DWORD)inputs[4],
 1098+ tmpfloats[0],(DWORD)inputs[6]);
 1099+ return 0;
 1100+ case GLEVENT_FLUSH:
 1101+ _Flush();
 1102+ return 0;
9771103 }
9781104 return DefWindowProc(hwnd,msg,wParam,lParam);
9791105 }
Index: ddraw/glRenderer.h
@@ -59,6 +59,9 @@
6060 #define GLEVENT_DELETETEX WM_USER+5
6161 #define GLEVENT_BLT WM_USER+6
6262 #define GLEVENT_DRAWSCREEN WM_USER+7
 63+#define GLEVENT_INITD3D WM_USER+8
 64+#define GLEVENT_CLEAR WM_USER+9
 65+#define GLEVENT_FLUSH WM_USER+10
6366
6467 extern int swapinterval;
6568 extern inline void SetSwap(int swap);
@@ -76,6 +79,9 @@
7780 GLuint MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
7881 void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
7982 void DeleteTexture(GLuint texture);
 83+ void InitD3D(int zbuffer);
 84+ void Flush();
 85+ HRESULT Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
8086 HGLRC hRC;
8187 LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
8288 private:
@@ -90,7 +96,10 @@
9197 void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
9298 void _DeleteTexture(GLuint texture);
9399 void _DrawBackbuffer(GLuint *texture, int x, int y);
 100+ void _InitD3D(int zbuffer);
 101+ void _Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
94102 glDirectDraw7 *ddInterface;
 103+ void _Flush();
95104 void* inputs[32];
96105 void* outputs[32];
97106 HANDLE hThread;