Index: ddraw/ddraw.vcxproj |
— | — | @@ -171,6 +171,7 @@ |
172 | 172 | <ClInclude Include="glDirectDrawPalette.h" />
|
173 | 173 | <ClInclude Include="glDirectDrawSurface.h" />
|
174 | 174 | <ClInclude Include="glExtensions.h" />
|
| 175 | + <ClInclude Include="glutil.h" />
|
175 | 176 | <ClInclude Include="include\d3d.h" />
|
176 | 177 | <ClInclude Include="include\d3dcaps.h" />
|
177 | 178 | <ClInclude Include="include\d3dtypes.h" />
|
— | — | @@ -211,6 +212,7 @@ |
212 | 213 | <ClCompile Include="glDirectDrawPalette.cpp" />
|
213 | 214 | <ClCompile Include="glDirectDrawSurface.cpp" />
|
214 | 215 | <ClCompile Include="glExtensions.cpp" />
|
| 216 | + <ClCompile Include="glutil.cpp" />
|
215 | 217 | <ClCompile Include="precomp.cpp">
|
216 | 218 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
|
217 | 219 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
Index: ddraw/ddraw.vcxproj.filters |
— | — | @@ -86,6 +86,9 @@ |
87 | 87 | <ClInclude Include="glDirect3DLight.h">
|
88 | 88 | <Filter>Header Files</Filter>
|
89 | 89 | </ClInclude>
|
| 90 | + <ClInclude Include="glutil.h">
|
| 91 | + <Filter>Header Files</Filter>
|
| 92 | + </ClInclude>
|
90 | 93 | </ItemGroup>
|
91 | 94 | <ItemGroup>
|
92 | 95 | <ClCompile Include="ddraw.cpp">
|
— | — | @@ -133,6 +136,9 @@ |
134 | 137 | <ClCompile Include="glDirect3DLight.cpp">
|
135 | 138 | <Filter>Source Files</Filter>
|
136 | 139 | </ClCompile>
|
| 140 | + <ClCompile Include="glutil.cpp">
|
| 141 | + <Filter>Source Files</Filter>
|
| 142 | + </ClCompile>
|
137 | 143 | </ItemGroup>
|
138 | 144 | <ItemGroup>
|
139 | 145 | <ResourceCompile Include="ddraw.rc">
|
Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -20,7 +20,16 @@ |
21 | 21 | #include "glDirectDrawSurface.h"
|
22 | 22 | #include "glDirect3DDevice.h"
|
23 | 23 | #include "glDirect3DLight.h"
|
| 24 | +#include "glutil.h"
|
24 | 25 |
|
| 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 | +
|
25 | 34 | const DWORD renderstate_default[153] = {0, // 0
|
26 | 35 | NULL, //texturehandle
|
27 | 36 | D3DANTIALIAS_NONE, //antialias
|
— | — | @@ -128,6 +137,7 @@ |
129 | 138 | identity._41 = identity._42 = identity._43 = 0.0;
|
130 | 139 | matWorld = matView = matProjection = identity;
|
131 | 140 | refcount = 1;
|
| 141 | + inscene = false;
|
132 | 142 | this->glD3D7 = glD3D7;
|
133 | 143 | glD3D7->AddRef();
|
134 | 144 | this->glDDS7 = glDDS7;
|
— | — | @@ -190,8 +200,9 @@ |
191 | 201 | }
|
192 | 202 | HRESULT WINAPI glDirect3DDevice7::BeginScene()
|
193 | 203 | {
|
194 | | - FIXME("glDirect3DDevice7::BeginScene: stub");
|
195 | | - ERR(DDERR_GENERIC);
|
| 204 | + if(inscene) return D3DERR_SCENE_IN_SCENE;
|
| 205 | + inscene = true;
|
| 206 | + return D3D_OK;
|
196 | 207 | }
|
197 | 208 | HRESULT WINAPI glDirect3DDevice7::BeginStateBlock()
|
198 | 209 | {
|
— | — | @@ -210,8 +221,29 @@ |
211 | 222 | }
|
212 | 223 | HRESULT WINAPI glDirect3DDevice7::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
|
213 | 224 | {
|
214 | | - FIXME("glDirect3DDevice7::Clear: stub");
|
215 | | - ERR(DDERR_GENERIC);
|
| 225 | + if(dwCount && !lpRects) return DDERR_INVALIDPARAMS;
|
| 226 | + if(dwCount) ERR(DDERR_INVALIDPARAMS);
|
| 227 | + GLfloat color[4];
|
| 228 | + dwordto4float(dwColor,color);
|
| 229 | + SetFBO(glDDS7->texture,glDDS7->GetZBuffer()->texture,glDDS7->GetZBuffer()->hasstencil);
|
| 230 | + int clearbits = 0;
|
| 231 | + if(D3DCLEAR_TARGET)
|
| 232 | + {
|
| 233 | + clearbits |= GL_COLOR_BUFFER_BIT;
|
| 234 | + glClearColor(color[0],color[1],color[2],color[3]);
|
| 235 | + }
|
| 236 | + if(D3DCLEAR_ZBUFFER)
|
| 237 | + {
|
| 238 | + clearbits |= GL_DEPTH_BUFFER_BIT;
|
| 239 | + glClearDepth(dvZ);
|
| 240 | + }
|
| 241 | + if(D3DCLEAR_STENCIL)
|
| 242 | + {
|
| 243 | + clearbits |= GL_STENCIL_BUFFER_BIT;
|
| 244 | + glClearStencil(dwStencil);
|
| 245 | + }
|
| 246 | + glClear(clearbits);
|
| 247 | + return D3D_OK;
|
216 | 248 | }
|
217 | 249 | HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
|
218 | 250 | DWORD dwFlags, LPDWORD lpdwReturnValues)
|
— | — | @@ -262,8 +294,10 @@ |
263 | 295 | }
|
264 | 296 | HRESULT WINAPI glDirect3DDevice7::EndScene()
|
265 | 297 | {
|
266 | | - FIXME("glDirect3DDevice7::EndScene: stub");
|
267 | | - ERR(DDERR_GENERIC);
|
| 298 | + if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
| 299 | + inscene = false;
|
| 300 | + glFlush();
|
| 301 | + return D3D_OK;
|
268 | 302 | }
|
269 | 303 | HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
|
270 | 304 | {
|
— | — | @@ -456,14 +490,6 @@ |
457 | 491 | return D3D_OK;
|
458 | 492 | }
|
459 | 493 |
|
460 | | -inline void dwordto4float(DWORD in, GLfloat *out)
|
461 | | -{
|
462 | | - out[0] = (GLfloat)((in>>16) & 0xff) / 255.0f;
|
463 | | - out[1] = (GLfloat)((in>>8) & 0xff) / 255.0f;
|
464 | | - out[2] = (GLfloat)(in& 0xff) / 255.0f;
|
465 | | - out[3] = (GLfloat)((in>>24) & 0xff) / 255.0f;
|
466 | | -}
|
467 | | -
|
468 | 494 | HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
|
469 | 495 | {
|
470 | 496 | GLfloat floats[4];
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -97,6 +97,7 @@ |
98 | 98 | glDirect3DLight **lights;
|
99 | 99 | int gllights[8];
|
100 | 100 | DWORD lightsmax;
|
| 101 | + bool inscene;
|
101 | 102 | };
|
102 | 103 |
|
103 | 104 | #endif //__GLDIRECT3DDEVICE_H |
\ No newline at end of file |
Index: ddraw/glDirectDraw.cpp |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | #include "glDirectDrawClipper.h"
|
25 | 25 | #include "glDirectDrawSurface.h"
|
26 | 26 | #include "glDirectDrawPalette.h"
|
| 27 | +#include "glutil.h"
|
27 | 28 |
|
28 | 29 | bool directdraw_created = false; // emulate only one ddraw device
|
29 | 30 | bool wndclasscreated = false;
|
— | — | @@ -1373,24 +1374,7 @@ |
1374 | 1375 | }
|
1375 | 1376 | else gl_caps.ShaderVer = 0;
|
1376 | 1377 | CompileShaders();
|
1377 | | - if(GLEXT_ARB_framebuffer_object)
|
1378 | | - {
|
1379 | | - glGenFramebuffers(1,&fbo);
|
1380 | | - glGenRenderbuffers(1,&depthbuffer);
|
1381 | | - glBindRenderbuffer(GL_RENDERBUFFER,depthbuffer);
|
1382 | | - //glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height);
|
1383 | | - //glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depthbuffer);
|
1384 | | - glBindRenderbuffer(GL_RENDERBUFFER,0);
|
1385 | | - }
|
1386 | | - else if(GLEXT_EXT_framebuffer_object)
|
1387 | | - {
|
1388 | | - glGenFramebuffersEXT(1,&fbo);
|
1389 | | - glGenRenderbuffersEXT(1,&depthbuffer);
|
1390 | | - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,depthbuffer);
|
1391 | | - //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT,width,height);
|
1392 | | - //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depthbuffer);
|
1393 | | - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,0);
|
1394 | | - }
|
| 1378 | + InitFBO();
|
1395 | 1379 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
1396 | 1380 | glClear(GL_COLOR_BUFFER_BIT);
|
1397 | 1381 | glFlush();
|
Index: ddraw/glDirectDraw.h |
— | — | @@ -93,9 +93,6 @@ |
94 | 94 | DWORD internalx,internaly,internalrefresh,internalbpp;
|
95 | 95 | DWORD primaryx,primaryy,primaryrefresh,primarybpp;
|
96 | 96 | bool GetFullscreen(){return fullscreen;};
|
97 | | - GLuint fbo;
|
98 | | - GLuint pbo;
|
99 | | - GLuint depthbuffer;
|
100 | 97 | void GetHandles(HWND *hwnd, HWND *hrender);
|
101 | 98 | glDirectDrawSurface7 *primary;
|
102 | 99 | private:
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | #include "glDirectDrawSurface.h"
|
25 | 25 | #include "glDirectDrawPalette.h"
|
26 | 26 | #include "glDirectDrawClipper.h"
|
| 27 | +#include "glutil.h"
|
27 | 28 |
|
28 | 29 | int swapinterval = 0;
|
29 | 30 | inline void SetSwap(int swap)
|
— | — | @@ -118,6 +119,7 @@ |
119 | 120 | // DDRAW7 routines
|
120 | 121 | glDirectDrawSurface7::glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 *lplpDDSurface7, HRESULT *error, bool copysurface, glDirectDrawPalette *palettein)
|
121 | 122 | {
|
| 123 | + hasstencil = false;
|
122 | 124 | dirty = 2;
|
123 | 125 | locked = 0;
|
124 | 126 | pagelocked = 0;
|
— | — | @@ -329,6 +331,7 @@ |
330 | 332 | texformat = GL_DEPTH_STENCIL;
|
331 | 333 | texformat2 = GL_UNSIGNED_INT_24_8;
|
332 | 334 | texformat3 = GL_DEPTH24_STENCIL8;
|
| 335 | + hasstencil = true;
|
333 | 336 | break;
|
334 | 337 | }
|
335 | 338 | else
|
— | — | @@ -584,18 +587,7 @@ |
585 | 588 | LONG sizes[6];
|
586 | 589 | ddInterface->GetSizes(sizes);
|
587 | 590 | int error;
|
588 | | - if(GLEXT_ARB_framebuffer_object)
|
589 | | - {
|
590 | | - glBindFramebuffer(GL_FRAMEBUFFER,ddInterface->fbo);
|
591 | | - glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture,0);
|
592 | | - error = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
593 | | - }
|
594 | | - else if(GLEXT_EXT_framebuffer_object)
|
595 | | - {
|
596 | | - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,ddInterface->fbo);
|
597 | | - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,texture,0);
|
598 | | - error = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
599 | | - }
|
| 591 | + error = SetFBO(texture,0,false);
|
600 | 592 | glPushAttrib(GL_VIEWPORT_BIT);
|
601 | 593 | glViewport(0,0,fakex,fakey);
|
602 | 594 | RECT destrect;
|
— | — | @@ -713,14 +705,7 @@ |
714 | 706 | glColor3f(1.0,1.0,1.0);
|
715 | 707 | glUseProgram(0);
|
716 | 708 | glDisable(GL_TEXTURE_2D);
|
717 | | - if(GLEXT_ARB_framebuffer_object)
|
718 | | - {
|
719 | | - glBindFramebuffer(GL_FRAMEBUFFER,0);
|
720 | | - }
|
721 | | - else if(GLEXT_EXT_framebuffer_object)
|
722 | | - {
|
723 | | - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
|
724 | | - }
|
| 709 | + SetFBO(0,0,false);
|
725 | 710 | glPopAttrib();
|
726 | 711 | if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
|
727 | 712 | (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -119,6 +119,7 @@ |
120 | 120 | // 2 - Texture was written to by ddraw
|
121 | 121 | CKEY colorkey[4];
|
122 | 122 | GLuint texture;
|
| 123 | + bool hasstencil;
|
123 | 124 | private:
|
124 | 125 | ULONG refcount;
|
125 | 126 | int locked;
|
Index: ddraw/glutil.cpp |
— | — | @@ -0,0 +1,89 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#include "common.h"
|
| 20 | +#include "glutil.h"
|
| 21 | +
|
| 22 | +GLuint fbcolor = 0;
|
| 23 | +GLuint fbz = 0;
|
| 24 | +GLuint fbo = 0;
|
| 25 | +bool stencil = false;
|
| 26 | +
|
| 27 | +
|
| 28 | +void InitFBO()
|
| 29 | +{
|
| 30 | + if(GLEXT_ARB_framebuffer_object)
|
| 31 | + {
|
| 32 | + glGenFramebuffers(1,&fbo);
|
| 33 | +}
|
| 34 | + else if(GLEXT_EXT_framebuffer_object)
|
| 35 | + {
|
| 36 | + glGenFramebuffersEXT(1,&fbo);
|
| 37 | + }
|
| 38 | +}
|
| 39 | +
|
| 40 | +GLenum SetFBO(GLint color, GLint z, bool stencil)
|
| 41 | +{
|
| 42 | + GLenum error;
|
| 43 | + if((fbcolor == color) && (fbz == z)) return 0;
|
| 44 | + fbcolor = color;
|
| 45 | + fbz = z;
|
| 46 | + if(GLEXT_ARB_framebuffer_object)
|
| 47 | + {
|
| 48 | + if(!color)
|
| 49 | + {
|
| 50 | + glBindFramebuffer(GL_FRAMEBUFFER,0);
|
| 51 | + return 0;
|
| 52 | + }
|
| 53 | + else glBindFramebuffer(GL_FRAMEBUFFER,fbo);
|
| 54 | + glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
|
| 55 | + if(stencil)
|
| 56 | + {
|
| 57 | + if(!::stencil) glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
|
| 58 | + glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z,0);
|
| 59 | + }
|
| 60 | + else
|
| 61 | + {
|
| 62 | + if(::stencil) glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
|
| 63 | + glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z,0);
|
| 64 | + }
|
| 65 | + error = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
| 66 | + }
|
| 67 | + else if(GLEXT_EXT_framebuffer_object)
|
| 68 | + {
|
| 69 | + if(!color)
|
| 70 | + {
|
| 71 | + glBindFramebufferEXT(GL_FRAMEBUFFER,0);
|
| 72 | + return 0;
|
| 73 | + }
|
| 74 | + else glBindFramebufferEXT(GL_FRAMEBUFFER,fbo);
|
| 75 | + glFramebufferTexture2DEXT(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
|
| 76 | + if(stencil)
|
| 77 | + {
|
| 78 | + if(!::stencil) glFramebufferTexture2DEXT(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
|
| 79 | + glFramebufferTexture2DEXT(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z,0);
|
| 80 | + }
|
| 81 | + else
|
| 82 | + {
|
| 83 | + if(::stencil) glFramebufferTexture2DEXT(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
|
| 84 | + glFramebufferTexture2DEXT(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z,0);
|
| 85 | + }
|
| 86 | + error = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
|
| 87 | + }
|
| 88 | + ::stencil = stencil;
|
| 89 | + return error;
|
| 90 | +}
|
Index: ddraw/glutil.h |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#pragma once
|
| 20 | +#ifndef _GLUTIL_H
|
| 21 | +#define _GLUTIL_H
|
| 22 | +
|
| 23 | +extern GLuint fbcolor,fbz;
|
| 24 | +extern GLuint fbo;
|
| 25 | +extern bool stencil;
|
| 26 | +
|
| 27 | +void InitFBO();
|
| 28 | +GLenum SetFBO(GLint color, GLint z, bool stencil);
|
| 29 | +
|
| 30 | +#endif //_GLUTIL_H |
\ No newline at end of file |