Index: ddraw/common.h |
— | — | @@ -82,6 +82,14 @@ |
83 | 83 | static inline int NextMultipleOf8(int number){return ((number+7) & (~7));}
|
84 | 84 | static inline int NextMultipleOf4(int number){return ((number+3) & (~3));}
|
85 | 85 | 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 | +
|
86 | 94 | #ifdef _M_X64
|
87 | 95 | #define NextMultipleOfWord NextMultipleOf8
|
88 | 96 | #else
|
Index: ddraw/glDirect3D.h |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | HRESULT WINAPI EnumDevices(LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback, LPVOID lpUserArg);
|
36 | 36 | HRESULT WINAPI EnumZBufferFormats(REFCLSID riidDevice, LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback, LPVOID lpContext);
|
37 | 37 | HRESULT WINAPI EvictManagedTextures();
|
| 38 | + glDirectDraw7 *glDD7;
|
38 | 39 | private:
|
39 | | - glDirectDraw7 *glDD7;
|
40 | 40 | ULONG refcount;
|
41 | 41 | };
|
42 | 42 |
|
Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -17,19 +17,13 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "glDirect3D.h"
|
| 21 | +#include "glDirectDraw.h"
|
21 | 22 | #include "glDirectDrawSurface.h"
|
22 | 23 | #include "glDirect3DDevice.h"
|
23 | 24 | #include "glDirect3DLight.h"
|
| 25 | +#include "glRenderer.h"
|
24 | 26 | #include "glutil.h"
|
25 | 27 |
|
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 | | -
|
34 | 28 | const DWORD renderstate_default[153] = {0, // 0
|
35 | 29 | NULL, //texturehandle
|
36 | 30 | D3DANTIALIAS_NONE, //antialias
|
— | — | @@ -128,11 +122,11 @@ |
129 | 123 |
|
130 | 124 | glDirect3DDevice7::glDirect3DDevice7(glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
|
131 | 125 | {
|
| 126 | + int zbuffer = 0;
|
132 | 127 | vertices = normals = NULL;
|
133 | 128 | diffuse = specular = NULL;
|
134 | 129 | ZeroMemory(texcoords,8*sizeof(GLfloat*));
|
135 | 130 | memcpy(renderstate,renderstate_default,153*sizeof(DWORD));
|
136 | | - GLfloat ambient[] = {0.0,0.0,0.0,0.0};
|
137 | 131 | identity._11 = identity._22 = identity._33 = identity._44 = 1.0;
|
138 | 132 | identity._12 = identity._13 = identity._14 =
|
139 | 133 | identity._21 = identity._23 = identity._24 =
|
— | — | @@ -146,18 +140,13 @@ |
147 | 141 | this->glDDS7 = glDDS7;
|
148 | 142 | glDDS7->AddRef();
|
149 | 143 | 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;
|
156 | 145 | ZeroMemory(&material,sizeof(D3DMATERIAL7));
|
157 | 146 | lightsmax = 16;
|
158 | 147 | lights = (glDirect3DLight**) malloc(16*sizeof(glDirect3DLight*));
|
159 | 148 | ZeroMemory(lights,16*sizeof(glDirect3DLight*));
|
160 | 149 | memset(gllights,0xff,8*sizeof(int));
|
161 | | -
|
| 150 | + glD3D7->glDD7->renderer->InitD3D(zbuffer);
|
162 | 151 | }
|
163 | 152 | glDirect3DDevice7::~glDirect3DDevice7()
|
164 | 153 | {
|
— | — | @@ -235,28 +224,7 @@ |
236 | 225 | {
|
237 | 226 | if(!this) return DDERR_INVALIDPARAMS;
|
238 | 227 | 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);
|
261 | 229 | }
|
262 | 230 | HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
|
263 | 231 | DWORD dwFlags, LPDWORD lpdwReturnValues)
|
— | — | @@ -353,7 +321,7 @@ |
354 | 322 | if(!this) return DDERR_INVALIDPARAMS;
|
355 | 323 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
356 | 324 | inscene = false;
|
357 | | - glFlush();
|
| 325 | + glD3D7->glDD7->renderer->Flush();
|
358 | 326 | return D3D_OK;
|
359 | 327 | }
|
360 | 328 | HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
|
— | — | @@ -500,7 +468,6 @@ |
501 | 469 | }
|
502 | 470 | }
|
503 | 471 | if(!foundlight) return D3DERR_LIGHT_SET_FAILED;
|
504 | | - lights[dwLightIndex]->SetGLLight(i);
|
505 | 472 | }
|
506 | 473 | else
|
507 | 474 | {
|
— | — | @@ -508,7 +475,6 @@ |
509 | 476 | {
|
510 | 477 | if(gllights[i] == dwLightIndex)
|
511 | 478 | {
|
512 | | - lights[dwLightIndex]->SetGLLight(-1);
|
513 | 479 | gllights[i] = -1;
|
514 | 480 | }
|
515 | 481 | }
|
— | — | @@ -570,43 +536,10 @@ |
571 | 537 | HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
|
572 | 538 | {
|
573 | 539 | if(!this) return DDERR_INVALIDPARAMS;
|
574 | | - GLfloat floats[4];
|
575 | 540 | if(dwRendStateType > 152) return DDERR_INVALIDPARAMS;
|
576 | 541 | if(dwRendStateType < 0) return DDERR_INVALIDPARAMS;
|
577 | 542 | 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;
|
611 | 544 | }
|
612 | 545 | HRESULT WINAPI glDirect3DDevice7::SetRenderTarget(LPDIRECTDRAWSURFACE7 lpNewRenderTarget, DWORD dwFlags)
|
613 | 546 | {
|
Index: ddraw/glDirect3DLight.cpp |
— | — | @@ -25,7 +25,6 @@ |
26 | 26 | glDirect3DLight::glDirect3DLight()
|
27 | 27 | {
|
28 | 28 | refcount=1;
|
29 | | - gllight = -1;
|
30 | 29 | ZeroMemory(&light,sizeof(D3DLIGHT7));
|
31 | 30 | light.dltType = D3DLIGHT_DIRECTIONAL;
|
32 | 31 | light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = 1.0f;
|
— | — | @@ -34,14 +33,11 @@ |
35 | 34 | glDirect3DLight::glDirect3DLight(D3DLIGHT7 *light_in)
|
36 | 35 | {
|
37 | 36 | refcount=1;
|
38 | | - gllight = -1;
|
39 | 37 | memcpy(&light,light_in,sizeof(D3DLIGHT7));
|
40 | 38 | }
|
41 | 39 |
|
42 | 40 | glDirect3DLight::~glDirect3DLight()
|
43 | 41 | {
|
44 | | - if(gllight != -1)
|
45 | | - glDisable(GL_LIGHT0+gllight);
|
46 | 42 | }
|
47 | 43 |
|
48 | 44 | ULONG WINAPI glDirect3DLight::AddRef()
|
— | — | @@ -80,7 +76,6 @@ |
81 | 77 | void glDirect3DLight::SetLight7(LPD3DLIGHT7 lpLight7)
|
82 | 78 | {
|
83 | 79 | memcpy(&light,lpLight7,sizeof(D3DLIGHT7));
|
84 | | - if(gllight != -1) SetGLLight(gllight);
|
85 | 80 | }
|
86 | 81 |
|
87 | 82 | HRESULT WINAPI glDirect3DLight::GetLight(LPD3DLIGHT lpLight)
|
— | — | @@ -94,37 +89,4 @@ |
95 | 90 | if(!this) return DDERR_INVALIDPARAMS;
|
96 | 91 | FIXME("glDirect3DLight::SetLight: stub");
|
97 | 92 | 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;
|
131 | 93 | } |
\ No newline at end of file |
Index: ddraw/glDirect3DLight.h |
— | — | @@ -34,13 +34,10 @@ |
35 | 35 | HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
|
36 | 36 | HRESULT WINAPI SetLight(LPD3DLIGHT lpLight);
|
37 | 37 | void SetLight7(LPD3DLIGHT7 lpLight7);
|
38 | | - void SetGLLight(int gllightin);
|
39 | | - void GetGLLight(int *gllightout){*gllightout=gllight;};
|
40 | 38 | D3DLIGHT7 light;
|
41 | 39 | private:
|
42 | 40 | ULONG refcount;
|
43 | 41 | D3DLIGHT2 convert;
|
44 | | - int gllight;
|
45 | 42 | };
|
46 | 43 |
|
47 | 44 | #endif //__GLDIRECT3DLIGHT_H |
\ No newline at end of file |
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -530,6 +530,7 @@ |
531 | 531 | HRESULT WINAPI glDirectDrawSurface7::AddAttachedSurface(LPDIRECTDRAWSURFACE7 lpDDSAttachedSurface)
|
532 | 532 | {
|
533 | 533 | if(!this) return DDERR_INVALIDPARAMS;
|
| 534 | + if(!lpDDSAttachedSurface) return DDERR_INVALIDPARAMS;
|
534 | 535 | if(zbuffer) ERR(DDERR_SURFACEALREADYATTACHED);
|
535 | 536 | glDirectDrawSurface7 *attached = (glDirectDrawSurface7 *)lpDDSAttachedSurface;
|
536 | 537 | DDSURFACEDESC2 ddsd;
|
— | — | @@ -726,7 +727,7 @@ |
727 | 728 | backbuffer->AddRef();
|
728 | 729 | return DD_OK;
|
729 | 730 | }
|
730 | | - else
|
| 731 | + else if(zbuffer)
|
731 | 732 | {
|
732 | 733 | zbuffer->GetCaps(&ddsComp);
|
733 | 734 | memcpy(&comp1,lpDDSCaps,sizeof(unsigned __int64));
|
— | — | @@ -737,8 +738,8 @@ |
738 | 739 | zbuffer->AddRef();
|
739 | 740 | return DD_OK;
|
740 | 741 | }
|
741 | | - ERR(DDERR_NOTFOUND);
|
742 | 742 | }
|
| 743 | + ERR(DDERR_NOTFOUND);
|
743 | 744 | }
|
744 | 745 | HRESULT WINAPI glDirectDrawSurface7::GetBltStatus(DWORD dwFlags)
|
745 | 746 | {
|
— | — | @@ -749,6 +750,7 @@ |
750 | 751 | HRESULT WINAPI glDirectDrawSurface7::GetCaps(LPDDSCAPS2 lpDDSCaps)
|
751 | 752 | {
|
752 | 753 | if(!this) return DDERR_INVALIDPARAMS;
|
| 754 | + if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
|
753 | 755 | memcpy(lpDDSCaps,&ddsd.ddsCaps,sizeof(DDSCAPS2));
|
754 | 756 | return DD_OK;
|
755 | 757 | }
|
— | — | @@ -761,6 +763,7 @@ |
762 | 764 | HRESULT WINAPI glDirectDrawSurface7::GetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey)
|
763 | 765 | {
|
764 | 766 | if(!this) return DDERR_INVALIDPARAMS;
|
| 767 | + if(!lpDDColorKey) return DDERR_INVALIDPARAMS;
|
765 | 768 | if(dwFlags == DDCKEY_SRCBLT)
|
766 | 769 | {
|
767 | 770 | if(colorkey[0].enabled)
|
— | — | @@ -802,6 +805,7 @@ |
803 | 806 | HRESULT WINAPI glDirectDrawSurface7::GetDC(HDC FAR *lphDC)
|
804 | 807 | {
|
805 | 808 | if(!this) return DDERR_INVALIDPARAMS;
|
| 809 | + if(!lphDC) return DDERR_INVALIDPARAMS;
|
806 | 810 | if(hdc) ERR(DDERR_DCALREADYCREATED);
|
807 | 811 | glDirectDrawPalette *pal;
|
808 | 812 | DWORD colors[256];
|
— | — | @@ -862,6 +866,7 @@ |
863 | 867 | HRESULT WINAPI glDirectDrawSurface7::GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat)
|
864 | 868 | {
|
865 | 869 | if(!this) return DDERR_INVALIDPARAMS;
|
| 870 | + if(!lpDDPixelFormat) return DDERR_INVALIDPARAMS;
|
866 | 871 | *lpDDPixelFormat = ddsd.ddpfPixelFormat;
|
867 | 872 | return DD_OK;
|
868 | 873 | }
|
— | — | @@ -868,7 +873,7 @@ |
869 | 874 | HRESULT WINAPI glDirectDrawSurface7::GetSurfaceDesc(LPDDSURFACEDESC2 lpDDSurfaceDesc)
|
870 | 875 | {
|
871 | 876 | if(!this) return DDERR_INVALIDPARAMS;
|
872 | | - if(!lpDDSurfaceDesc) ERR(DDERR_INVALIDPARAMS);
|
| 877 | + if(!lpDDSurfaceDesc) return DDERR_INVALIDPARAMS;
|
873 | 878 | memcpy(lpDDSurfaceDesc,&ddsd,lpDDSurfaceDesc->dwSize);
|
874 | 879 | return DD_OK;
|
875 | 880 | }
|
— | — | @@ -1024,6 +1029,7 @@ |
1025 | 1030 | HRESULT WINAPI glDirectDrawSurface7::SetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey)
|
1026 | 1031 | {
|
1027 | 1032 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1033 | + if(!lpDDColorKey) ERR(DDERR_GENERIC);
|
1028 | 1034 | CKEY key;
|
1029 | 1035 | key.enabled = true;
|
1030 | 1036 | if(dwFlags & DDCKEY_COLORSPACE) key.colorspace = true;
|
— | — | @@ -1263,6 +1269,7 @@ |
1264 | 1270 | HRESULT WINAPI glDirectDrawSurface1::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE FAR *lplpDDAttachedSurface)
|
1265 | 1271 | {
|
1266 | 1272 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1273 | + if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
|
1267 | 1274 | HRESULT error;
|
1268 | 1275 | glDirectDrawSurface7 *attachedsurface;
|
1269 | 1276 | glDirectDrawSurface1 *attached1;
|
— | — | @@ -1286,6 +1293,7 @@ |
1287 | 1294 | HRESULT WINAPI glDirectDrawSurface1::GetCaps(LPDDSCAPS lpDDSCaps)
|
1288 | 1295 | {
|
1289 | 1296 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1297 | + if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
|
1290 | 1298 | HRESULT error;
|
1291 | 1299 | DDSCAPS2 ddsCaps1;
|
1292 | 1300 | error = glDDS7->GetCaps(&ddsCaps1);
|
— | — | @@ -1504,6 +1512,7 @@ |
1505 | 1513 | HRESULT WINAPI glDirectDrawSurface2::GetCaps(LPDDSCAPS lpDDSCaps)
|
1506 | 1514 | {
|
1507 | 1515 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1516 | + if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
|
1508 | 1517 | HRESULT error;
|
1509 | 1518 | DDSCAPS2 ddsCaps1;
|
1510 | 1519 | error = glDDS7->GetCaps(&ddsCaps1);
|
— | — | @@ -1737,6 +1746,7 @@ |
1738 | 1747 | HRESULT WINAPI glDirectDrawSurface3::GetCaps(LPDDSCAPS lpDDSCaps)
|
1739 | 1748 | {
|
1740 | 1749 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1750 | + if(!lpDDSCaps) return DDERR_INVALIDPARAMS;
|
1741 | 1751 | HRESULT error;
|
1742 | 1752 | DDSCAPS2 ddsCaps1;
|
1743 | 1753 | error = glDDS7->GetCaps(&ddsCaps1);
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -324,6 +324,69 @@ |
325 | 325 | LeaveCriticalSection(&cs);
|
326 | 326 | }
|
327 | 327 |
|
| 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 | +
|
328 | 391 | DWORD glRenderer::_Entry()
|
329 | 392 | {
|
330 | 393 | MSG Msg;
|
— | — | @@ -855,10 +918,62 @@ |
856 | 919 | glDeleteTextures(1,&texture);
|
857 | 920 | }
|
858 | 921 |
|
| 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 | +
|
859 | 973 | LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
860 | 974 | {
|
861 | 975 | int oldx,oldy;
|
862 | 976 | float mulx, muly;
|
| 977 | + float tmpfloats[16];
|
863 | 978 | int translatex, translatey;
|
864 | 979 | LPARAM newpos;
|
865 | 980 | HWND hParent;
|
— | — | @@ -973,6 +1088,17 @@ |
974 | 1089 | case GLEVENT_DRAWSCREEN:
|
975 | 1090 | _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
|
976 | 1091 | 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;
|
977 | 1103 | }
|
978 | 1104 | return DefWindowProc(hwnd,msg,wParam,lParam);
|
979 | 1105 | }
|
Index: ddraw/glRenderer.h |
— | — | @@ -59,6 +59,9 @@ |
60 | 60 | #define GLEVENT_DELETETEX WM_USER+5
|
61 | 61 | #define GLEVENT_BLT WM_USER+6
|
62 | 62 | #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
|
63 | 66 |
|
64 | 67 | extern int swapinterval;
|
65 | 68 | extern inline void SetSwap(int swap);
|
— | — | @@ -76,6 +79,9 @@ |
77 | 80 | GLuint MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
|
78 | 81 | void DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
79 | 82 | 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);
|
80 | 86 | HGLRC hRC;
|
81 | 87 | LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
82 | 88 | private:
|
— | — | @@ -90,7 +96,10 @@ |
91 | 97 | void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
92 | 98 | void _DeleteTexture(GLuint texture);
|
93 | 99 | 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);
|
94 | 102 | glDirectDraw7 *ddInterface;
|
| 103 | + void _Flush();
|
95 | 104 | void* inputs[32];
|
96 | 105 | void* outputs[32];
|
97 | 106 | HANDLE hThread;
|