DXGL r322 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r321‎ | r322 | r323 >
Date:18:36, 9 February 2013
Author:admin
Status:new
Tags:
Comment:
Add execute buffer creation.
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DExecuteBuffer.cpp (added) (history)
  • /ddraw/glDirect3DExecuteBuffer.h (added) (history)
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.h (modified) (history)

Diff [purge]

Index: ddraw/ddraw.vcxproj
@@ -232,6 +232,7 @@
233233 <ClInclude Include="glClassFactory.h" />
234234 <ClInclude Include="glDirect3D.h" />
235235 <ClInclude Include="glDirect3DDevice.h" />
 236+ <ClInclude Include="glDirect3DExecuteBuffer.h" />
236237 <ClInclude Include="glDirect3DLight.h" />
237238 <ClInclude Include="glDirect3DMaterial.h" />
238239 <ClInclude Include="glDirect3DTexture.h" />
@@ -289,6 +290,7 @@
290291 </ClCompile>
291292 <ClCompile Include="glDirect3D.cpp" />
292293 <ClCompile Include="glDirect3DDevice.cpp" />
 294+ <ClCompile Include="glDirect3DExecuteBuffer.cpp" />
293295 <ClCompile Include="glDirect3DLight.cpp" />
294296 <ClCompile Include="glDirect3DMaterial.cpp" />
295297 <ClCompile Include="glDirect3DTexture.cpp" />
Index: ddraw/ddraw.vcxproj.filters
@@ -122,6 +122,9 @@
123123 <ClInclude Include="fog.h">
124124 <Filter>Header Files</Filter>
125125 </ClInclude>
 126+ <ClInclude Include="glDirect3DExecuteBuffer.h">
 127+ <Filter>Header Files</Filter>
 128+ </ClInclude>
126129 </ItemGroup>
127130 <ItemGroup>
128131 <ClCompile Include="ddraw.cpp">
@@ -202,6 +205,9 @@
203206 <ClCompile Include="fog.cpp">
204207 <Filter>Source Files</Filter>
205208 </ClCompile>
 209+ <ClCompile Include="glDirect3DExecuteBuffer.cpp">
 210+ <Filter>Source Files</Filter>
 211+ </ClCompile>
206212 </ItemGroup>
207213 <ItemGroup>
208214 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirect3DDevice.cpp
@@ -28,6 +28,7 @@
2929 #include "glDirect3DVertexBuffer.h"
3030 #include "glDirect3DDevice.h"
3131 #include "glDirect3DLight.h"
 32+#include "glDirect3DExecuteBuffer.h"
3233 #include <string>
3334 using namespace std;
3435 #include "shadergen.h"
@@ -1905,8 +1906,11 @@
19061907 if(!lpDesc) return DDERR_INVALIDPARAMS;
19071908 if(!lplpDirect3DExecuteBuffer) return DDERR_INVALIDPARAMS;
19081909 if(pUnkOuter) return DDERR_INVALIDPARAMS;
1909 - FIXME("glDirect3DDevice1::CreateExecuteBuffer: stub");
1910 - ERR(DDERR_GENERIC);
 1910+ if(lpDesc->dwSize != sizeof(D3DEXECUTEBUFFERDESC)) return DDERR_INVALIDPARAMS;
 1911+ if(!(lpDesc->dwFlags & D3DDEB_BUFSIZE)) return DDERR_INVALIDPARAMS;
 1912+ *lplpDirect3DExecuteBuffer = new glDirect3DExecuteBuffer(lpDesc);
 1913+ if(!*lplpDirect3DExecuteBuffer) return DDERR_OUTOFMEMORY;
 1914+ return D3D_OK;
19111915 }
19121916
19131917 HRESULT glDirect3DDevice7::Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags)
Index: ddraw/glDirect3DExecuteBuffer.cpp
@@ -0,0 +1,158 @@
 2+// DXGL
 3+// Copyright (C) 2013 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 "glDirect3DExecuteBuffer.h"
 21+
 22+glDirect3DExecuteBuffer::glDirect3DExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc)
 23+{
 24+ locked = false;
 25+ inuse = false;
 26+ data = NULL;
 27+ desc = *lpDesc;
 28+ if(!(desc.dwFlags & D3DDEB_CAPS))
 29+ {
 30+ desc.dwFlags |= D3DDEB_CAPS;
 31+ desc.dwCaps = D3DDEBCAPS_MEM;
 32+ }
 33+ ZeroMemory(&datadesc,sizeof(D3DEXECUTEDATA));
 34+ datadesc.dwSize = sizeof(D3DEXECUTEDATA);
 35+}
 36+glDirect3DExecuteBuffer::~glDirect3DExecuteBuffer()
 37+{
 38+ if(data) free(data);
 39+}
 40+
 41+HRESULT WINAPI glDirect3DExecuteBuffer::QueryInterface(REFIID riid, void** ppvObj)
 42+{
 43+ if(!this) return DDERR_INVALIDOBJECT;
 44+ if((riid == IID_IUnknown) || (riid == IID_IDirect3DExecuteBuffer))
 45+ {
 46+ this->AddRef();
 47+ *ppvObj = this;
 48+ return D3D_OK;
 49+ }
 50+ return E_NOINTERFACE;
 51+}
 52+
 53+ULONG WINAPI glDirect3DExecuteBuffer::AddRef()
 54+{
 55+ if(!this) return 0;
 56+ refcount++;
 57+ return refcount;
 58+}
 59+
 60+ULONG WINAPI glDirect3DExecuteBuffer::Release()
 61+{
 62+ if(!this) return 0;
 63+ ULONG ret;
 64+ refcount--;
 65+ ret = refcount;
 66+ if(refcount == 0) delete this;
 67+ return ret;
 68+}
 69+
 70+HRESULT WINAPI glDirect3DExecuteBuffer::GetExecuteData(LPD3DEXECUTEDATA lpData)
 71+{
 72+ if(!this) return DDERR_INVALIDOBJECT;
 73+ if(!lpData) return DDERR_INVALIDPARAMS;
 74+ if(locked) return D3DERR_EXECUTE_LOCKED;
 75+ if(lpData->dwSize < sizeof(D3DEXECUTEDATA)) return DDERR_INVALIDPARAMS;
 76+ memcpy(lpData,&datadesc,sizeof(D3DEXECUTEDATA));
 77+ return D3D_OK;
 78+}
 79+
 80+HRESULT WINAPI glDirect3DExecuteBuffer::Initialize(LPDIRECT3DDEVICE lpDirect3DDevice,
 81+ LPD3DEXECUTEBUFFERDESC lpDesc)
 82+{
 83+ if(!this) return DDERR_INVALIDOBJECT;
 84+ return DDERR_ALREADYINITIALIZED;
 85+}
 86+
 87+HRESULT WINAPI glDirect3DExecuteBuffer::Lock(LPD3DEXECUTEBUFFERDESC lpDesc)
 88+{
 89+ if(!this) return DDERR_INVALIDOBJECT;
 90+ if(!lpDesc) return DDERR_INVALIDPARAMS;
 91+ if(lpDesc->dwSize < sizeof(D3DEXECUTEBUFFERDESC)) return DDERR_INVALIDPARAMS;
 92+ if(inuse) return DDERR_WASSTILLDRAWING;
 93+ if(locked) return D3DERR_EXECUTE_LOCKED;
 94+ desc.dwCaps = lpDesc->dwCaps;
 95+ desc.dwFlags |= D3DDEB_LPDATA;
 96+ if(!data)
 97+ {
 98+ data = (unsigned char *)malloc(desc.dwBufferSize);
 99+ if(!data) return DDERR_OUTOFMEMORY;
 100+ }
 101+ desc.lpData = data;
 102+ memcpy(lpDesc,&desc,sizeof(D3DEXECUTEBUFFERDESC));
 103+ locked = true;
 104+ return D3D_OK;
 105+}
 106+
 107+HRESULT WINAPI glDirect3DExecuteBuffer::Optimize(DWORD dwDummy)
 108+{
 109+ if(!this) return DDERR_INVALIDOBJECT;
 110+ return DDERR_UNSUPPORTED;
 111+}
 112+
 113+HRESULT WINAPI glDirect3DExecuteBuffer::SetExecuteData(LPD3DEXECUTEDATA lpData)
 114+{
 115+ if(!this) return DDERR_INVALIDOBJECT;
 116+ if(!lpData) return DDERR_INVALIDPARAMS;
 117+ if(lpData->dwSize != sizeof(D3DEXECUTEDATA)) return DDERR_INVALIDPARAMS;
 118+ memcpy(&data,lpData,sizeof(D3DEXECUTEDATA));
 119+ return D3D_OK;
 120+}
 121+
 122+HRESULT WINAPI glDirect3DExecuteBuffer::Unlock()
 123+{
 124+ if(!this) return DDERR_INVALIDOBJECT;
 125+ if(inuse) return D3DERR_EXECUTE_NOT_LOCKED;
 126+ if(!locked) return D3DERR_EXECUTE_NOT_LOCKED;
 127+ locked = false;
 128+ return D3D_OK;
 129+}
 130+
 131+HRESULT glDirect3DExecuteBuffer::ExecuteLock(LPD3DEXECUTEBUFFERDESC lpDesc,LPD3DEXECUTEDATA lpData)
 132+{
 133+ if(!this) return DDERR_INVALIDOBJECT;
 134+ if(inuse) return DDERR_WASSTILLDRAWING;
 135+ if(locked) return D3DERR_EXECUTE_LOCKED;
 136+ if(!lpDesc) return DDERR_INVALIDPARAMS;
 137+ if(!lpData) return DDERR_INVALIDPARAMS;
 138+ desc.dwFlags |= D3DDEB_LPDATA;
 139+ if(!data)
 140+ {
 141+ data = (unsigned char *)malloc(desc.dwBufferSize);
 142+ if(!data) return DDERR_OUTOFMEMORY;
 143+ }
 144+ desc.lpData = data;
 145+ memcpy(lpDesc,&desc,sizeof(D3DEXECUTEBUFFERDESC));
 146+ memcpy(lpData,&datadesc,sizeof(D3DEXECUTEDATA));
 147+ locked = true;
 148+ inuse = true;
 149+ return D3D_OK;
 150+}
 151+
 152+HRESULT glDirect3DExecuteBuffer::ExecuteUnlock()
 153+{
 154+ if(!this) return DDERR_INVALIDOBJECT;
 155+ if(!inuse) return D3DERR_EXECUTE_NOT_LOCKED;
 156+ inuse = false;
 157+ locked = false;
 158+ return D3D_OK;
 159+}
\ No newline at end of file
Index: ddraw/glDirect3DExecuteBuffer.h
@@ -0,0 +1,43 @@
 2+// DXGL
 3+// Copyright (C) 2013 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+class glDirect3DExecuteBuffer : public IDirect3DExecuteBuffer
 20+
 21+{
 22+public:
 23+ glDirect3DExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc);
 24+ virtual ~glDirect3DExecuteBuffer();
 25+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 26+ ULONG WINAPI AddRef();
 27+ ULONG WINAPI Release();
 28+ HRESULT WINAPI GetExecuteData(LPD3DEXECUTEDATA lpData);
 29+ HRESULT WINAPI Initialize(LPDIRECT3DDEVICE lpDirect3DDevice, LPD3DEXECUTEBUFFERDESC lpDesc);
 30+ HRESULT WINAPI Lock(LPD3DEXECUTEBUFFERDESC lpDesc);
 31+ HRESULT WINAPI Optimize(DWORD dwDummy);
 32+ HRESULT WINAPI SetExecuteData(LPD3DEXECUTEDATA lpData);
 33+ HRESULT WINAPI Unlock();
 34+ HRESULT WINAPI Validate(LPDWORD lpdwOffset, LPD3DVALIDATECALLBACK lpFunc, LPVOID lpUserArg, DWORD dwReserved);
 35+ HRESULT ExecuteLock(LPD3DEXECUTEBUFFERDESC lpDesc,LPD3DEXECUTEDATA lpData);
 36+ HRESULT ExecuteUnlock();
 37+private:
 38+ ULONG refcount;
 39+ D3DEXECUTEBUFFERDESC desc;
 40+ D3DEXECUTEDATA datadesc;
 41+ unsigned char *data;
 42+ bool locked;
 43+ bool inuse;
 44+};
\ No newline at end of file
Index: ddraw/glDirect3DViewport.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2012 William Feely
 3+// Copyright (C) 2011-2013 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
Index: ddraw/glDirect3DViewport.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2012 William Feely
 3+// Copyright (C) 2011-2013 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