DXGL r74 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r73‎ | r74 | r75 >
Date:17:51, 8 January 2012
Author:admin
Status:new
Tags:
Comment:
Add Clear, BeginScene, and EndScene
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glutil.cpp (added) (history)
  • /ddraw/glutil.h (added) (history)

Diff [purge]

Index: ddraw/ddraw.vcxproj
@@ -171,6 +171,7 @@
172172 <ClInclude Include="glDirectDrawPalette.h" />
173173 <ClInclude Include="glDirectDrawSurface.h" />
174174 <ClInclude Include="glExtensions.h" />
 175+ <ClInclude Include="glutil.h" />
175176 <ClInclude Include="include\d3d.h" />
176177 <ClInclude Include="include\d3dcaps.h" />
177178 <ClInclude Include="include\d3dtypes.h" />
@@ -211,6 +212,7 @@
212213 <ClCompile Include="glDirectDrawPalette.cpp" />
213214 <ClCompile Include="glDirectDrawSurface.cpp" />
214215 <ClCompile Include="glExtensions.cpp" />
 216+ <ClCompile Include="glutil.cpp" />
215217 <ClCompile Include="precomp.cpp">
216218 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
217219 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Index: ddraw/ddraw.vcxproj.filters
@@ -86,6 +86,9 @@
8787 <ClInclude Include="glDirect3DLight.h">
8888 <Filter>Header Files</Filter>
8989 </ClInclude>
 90+ <ClInclude Include="glutil.h">
 91+ <Filter>Header Files</Filter>
 92+ </ClInclude>
9093 </ItemGroup>
9194 <ItemGroup>
9295 <ClCompile Include="ddraw.cpp">
@@ -133,6 +136,9 @@
134137 <ClCompile Include="glDirect3DLight.cpp">
135138 <Filter>Source Files</Filter>
136139 </ClCompile>
 140+ <ClCompile Include="glutil.cpp">
 141+ <Filter>Source Files</Filter>
 142+ </ClCompile>
137143 </ItemGroup>
138144 <ItemGroup>
139145 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirect3DDevice.cpp
@@ -20,7 +20,16 @@
2121 #include "glDirectDrawSurface.h"
2222 #include "glDirect3DDevice.h"
2323 #include "glDirect3DLight.h"
 24+#include "glutil.h"
2425
 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+
2534 const DWORD renderstate_default[153] = {0, // 0
2635 NULL, //texturehandle
2736 D3DANTIALIAS_NONE, //antialias
@@ -128,6 +137,7 @@
129138 identity._41 = identity._42 = identity._43 = 0.0;
130139 matWorld = matView = matProjection = identity;
131140 refcount = 1;
 141+ inscene = false;
132142 this->glD3D7 = glD3D7;
133143 glD3D7->AddRef();
134144 this->glDDS7 = glDDS7;
@@ -190,8 +200,9 @@
191201 }
192202 HRESULT WINAPI glDirect3DDevice7::BeginScene()
193203 {
194 - FIXME("glDirect3DDevice7::BeginScene: stub");
195 - ERR(DDERR_GENERIC);
 204+ if(inscene) return D3DERR_SCENE_IN_SCENE;
 205+ inscene = true;
 206+ return D3D_OK;
196207 }
197208 HRESULT WINAPI glDirect3DDevice7::BeginStateBlock()
198209 {
@@ -210,8 +221,29 @@
211222 }
212223 HRESULT WINAPI glDirect3DDevice7::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
213224 {
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;
216248 }
217249 HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
218250 DWORD dwFlags, LPDWORD lpdwReturnValues)
@@ -262,8 +294,10 @@
263295 }
264296 HRESULT WINAPI glDirect3DDevice7::EndScene()
265297 {
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;
268302 }
269303 HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
270304 {
@@ -456,14 +490,6 @@
457491 return D3D_OK;
458492 }
459493
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 -
468494 HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
469495 {
470496 GLfloat floats[4];
Index: ddraw/glDirect3DDevice.h
@@ -97,6 +97,7 @@
9898 glDirect3DLight **lights;
9999 int gllights[8];
100100 DWORD lightsmax;
 101+ bool inscene;
101102 };
102103
103104 #endif //__GLDIRECT3DDEVICE_H
\ No newline at end of file
Index: ddraw/glDirectDraw.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-2012 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,7 @@
2424 #include "glDirectDrawClipper.h"
2525 #include "glDirectDrawSurface.h"
2626 #include "glDirectDrawPalette.h"
 27+#include "glutil.h"
2728
2829 bool directdraw_created = false; // emulate only one ddraw device
2930 bool wndclasscreated = false;
@@ -1373,24 +1374,7 @@
13741375 }
13751376 else gl_caps.ShaderVer = 0;
13761377 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();
13951379 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
13961380 glClear(GL_COLOR_BUFFER_BIT);
13971381 glFlush();
Index: ddraw/glDirectDraw.h
@@ -93,9 +93,6 @@
9494 DWORD internalx,internaly,internalrefresh,internalbpp;
9595 DWORD primaryx,primaryy,primaryrefresh,primarybpp;
9696 bool GetFullscreen(){return fullscreen;};
97 - GLuint fbo;
98 - GLuint pbo;
99 - GLuint depthbuffer;
10097 void GetHandles(HWND *hwnd, HWND *hrender);
10198 glDirectDrawSurface7 *primary;
10299 private:
Index: ddraw/glDirectDrawSurface.cpp
@@ -23,6 +23,7 @@
2424 #include "glDirectDrawSurface.h"
2525 #include "glDirectDrawPalette.h"
2626 #include "glDirectDrawClipper.h"
 27+#include "glutil.h"
2728
2829 int swapinterval = 0;
2930 inline void SetSwap(int swap)
@@ -118,6 +119,7 @@
119120 // DDRAW7 routines
120121 glDirectDrawSurface7::glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 *lplpDDSurface7, HRESULT *error, bool copysurface, glDirectDrawPalette *palettein)
121122 {
 123+ hasstencil = false;
122124 dirty = 2;
123125 locked = 0;
124126 pagelocked = 0;
@@ -329,6 +331,7 @@
330332 texformat = GL_DEPTH_STENCIL;
331333 texformat2 = GL_UNSIGNED_INT_24_8;
332334 texformat3 = GL_DEPTH24_STENCIL8;
 335+ hasstencil = true;
333336 break;
334337 }
335338 else
@@ -584,18 +587,7 @@
585588 LONG sizes[6];
586589 ddInterface->GetSizes(sizes);
587590 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);
600592 glPushAttrib(GL_VIEWPORT_BIT);
601593 glViewport(0,0,fakex,fakey);
602594 RECT destrect;
@@ -713,14 +705,7 @@
714706 glColor3f(1.0,1.0,1.0);
715707 glUseProgram(0);
716708 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);
725710 glPopAttrib();
726711 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
727712 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
Index: ddraw/glDirectDrawSurface.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-2012 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -119,6 +119,7 @@
120120 // 2 - Texture was written to by ddraw
121121 CKEY colorkey[4];
122122 GLuint texture;
 123+ bool hasstencil;
123124 private:
124125 ULONG refcount;
125126 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