DXGL r315 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r314‎ | r315 | r316 >
Date:23:47, 3 February 2013
Author:admin
Status:new
Tags:
Comment:
Add IDirect3DMaterial, IDirect3D, and partial IDirect3DDevice.
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glDirect3D.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirect3DMaterial.cpp (modified) (history)
  • /ddraw/glDirect3DMaterial.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -197,6 +197,7 @@
198198 glDD7->AddRef();
199199 glD3D3 = NULL;
200200 glD3D2 = NULL;
 201+ glD3D1 = NULL;
201202 }
202203
203204 glDirect3D7::~glDirect3D7()
@@ -264,6 +265,22 @@
265266 return D3D_OK;
266267 }
267268 }
 269+ if(riid == IID_IDirect3D)
 270+ {
 271+ if(glD3D1)
 272+ {
 273+ *ppvObj = glD3D1;
 274+ glD3D1->AddRef();
 275+ return D3D_OK;
 276+ }
 277+ else
 278+ {
 279+ this->AddRef();
 280+ *ppvObj = new glDirect3D1(this);
 281+ glD3D1 = (glDirect3D1*)*ppvObj;
 282+ return D3D_OK;
 283+ }
 284+ }
268285 return E_NOINTERFACE;
269286 }
270287
@@ -490,6 +507,7 @@
491508 glDirect3D3::~glDirect3D3()
492509 {
493510 glD3D7->Release();
 511+ glD3D7->glD3D3 = NULL;
494512 }
495513
496514 HRESULT WINAPI glDirect3D3::QueryInterface(REFIID riid, void** ppvObj)
@@ -598,6 +616,7 @@
599617 glDirect3D2::~glDirect3D2()
600618 {
601619 glD3D7->Release();
 620+ glD3D7->glD3D2 = NULL;
602621 }
603622
604623 HRESULT WINAPI glDirect3D2::QueryInterface(REFIID riid, void** ppvObj)
@@ -684,3 +703,92 @@
685704 if(!this) return DDERR_INVALIDPARAMS;
686705 return glD3D7->FindDevice(lpD3DFDS,lpD3DFDR);
687706 }
 707+
 708+glDirect3D1::glDirect3D1(glDirect3D7 *glD3D7)
 709+{
 710+ this->glD3D7 = glD3D7;
 711+ refcount = 1;
 712+}
 713+
 714+glDirect3D1::~glDirect3D1()
 715+{
 716+ glD3D7->Release();
 717+ glD3D7->glD3D1 = NULL;
 718+}
 719+
 720+HRESULT WINAPI glDirect3D1::QueryInterface(REFIID riid, void** ppvObj)
 721+{
 722+ if(!this) return DDERR_INVALIDPARAMS;
 723+ if(riid == IID_IUnknown)
 724+ {
 725+ this->AddRef();
 726+ *ppvObj = this;
 727+ return DD_OK;
 728+ }
 729+ return glD3D7->QueryInterface(riid,ppvObj);
 730+}
 731+
 732+ULONG WINAPI glDirect3D1::AddRef()
 733+{
 734+ if(!this) return 0;
 735+ refcount++;
 736+ return refcount;
 737+}
 738+
 739+ULONG WINAPI glDirect3D1::Release()
 740+{
 741+ if(!this) return 0;
 742+ ULONG ret;
 743+ refcount--;
 744+ ret = refcount;
 745+ if(refcount == 0) delete this;
 746+ return ret;
 747+}
 748+
 749+HRESULT WINAPI glDirect3D1::CreateLight(LPDIRECT3DLIGHT* lplpDirect3DLight, IUnknown* pUnkOuter)
 750+{
 751+ if(!this) return DDERR_INVALIDPARAMS;
 752+ return glD3D7->CreateLight(lplpDirect3DLight,pUnkOuter);
 753+}
 754+
 755+HRESULT WINAPI glDirect3D1::CreateMaterial(LPDIRECT3DMATERIAL* lplpDirect3DMaterial, IUnknown* pUnkOuter)
 756+{
 757+ if(!this) return DDERR_INVALIDPARAMS;
 758+ if(!lplpDirect3DMaterial) return DDERR_INVALIDPARAMS;
 759+ glDirect3DMaterial3 *glD3DM3;
 760+ HRESULT error = glD3D7->CreateMaterial((LPDIRECT3DMATERIAL3*)&glD3DM3,pUnkOuter);
 761+ if(FAILED(error)) return error;
 762+ glD3DM3->QueryInterface(IID_IDirect3DMaterial,(void**)lplpDirect3DMaterial);
 763+ glD3DM3->Release();
 764+ return D3D_OK;
 765+}
 766+
 767+HRESULT WINAPI glDirect3D1::CreateViewport(LPDIRECT3DVIEWPORT* lplpD3DViewport, IUnknown* pUnkOuter)
 768+{
 769+ if(!this) return DDERR_INVALIDPARAMS;
 770+ if(!lplpD3DViewport) return DDERR_INVALIDPARAMS;
 771+ glDirect3DMaterial3 *glD3DV3;
 772+ HRESULT error = glD3D7->CreateViewport((LPDIRECT3DVIEWPORT3*)&glD3DV3,pUnkOuter);
 773+ if(FAILED(error)) return error;
 774+ glD3DV3->QueryInterface(IID_IDirect3DViewport,(void**)lplpD3DViewport);
 775+ glD3DV3->Release();
 776+ return D3D_OK;
 777+}
 778+
 779+HRESULT WINAPI glDirect3D1::EnumDevices(LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback, LPVOID lpUserArg)
 780+{
 781+ if(!this) return DDERR_INVALIDPARAMS;
 782+ return glD3D7->EnumDevices3(lpEnumDevicesCallback,lpUserArg);
 783+}
 784+
 785+HRESULT WINAPI glDirect3D1::FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR)
 786+{
 787+ if(!this) return DDERR_INVALIDPARAMS;
 788+ return glD3D7->FindDevice(lpD3DFDS,lpD3DFDR);
 789+}
 790+
 791+HRESULT WINAPI glDirect3D1::Initialize(REFIID lpREFIID)
 792+{
 793+ if(!this) return DDERR_INVALIDPARAMS;
 794+ return DDERR_ALREADYINITIALIZED;
 795+}
Index: ddraw/glDirect3D.h
@@ -25,6 +25,7 @@
2626
2727 class glDirect3D3;
2828 class glDirect3D2;
 29+class glDirect3D1;
2930 class glDirect3D7 : public IDirect3D7
3031 {
3132 public:
@@ -44,10 +45,11 @@
4546 HRESULT WINAPI EvictManagedTextures();
4647 HRESULT WINAPI FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR);
4748 glDirectDraw7 *glDD7;
 49+ glDirect3D3 *glD3D3;
 50+ glDirect3D2 *glD3D2;
 51+ glDirect3D1 *glD3D1;
4852 private:
4953 ULONG refcount;
50 - glDirect3D3 *glD3D3;
51 - glDirect3D2 *glD3D2;
5254 };
5355
5456 class glDirect3D3 : public IDirect3D3
@@ -91,4 +93,23 @@
9294 glDirect3D7 *glD3D7;
9395 };
9496
 97+class glDirect3D1 : public IDirect3D
 98+{
 99+public:
 100+ glDirect3D1(glDirect3D7 *glD3D7);
 101+ virtual ~glDirect3D1();
 102+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 103+ ULONG WINAPI AddRef();
 104+ ULONG WINAPI Release();
 105+ HRESULT WINAPI CreateLight(LPDIRECT3DLIGHT* lplpDirect3DLight, IUnknown* pUnkOuter);
 106+ HRESULT WINAPI CreateMaterial(LPDIRECT3DMATERIAL* lplpDirect3DMaterial, IUnknown* pUnkOuter);
 107+ HRESULT WINAPI CreateViewport(LPDIRECT3DVIEWPORT* lplpD3DViewport, IUnknown* pUnkOuter);
 108+ HRESULT WINAPI EnumDevices(LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback, LPVOID lpUserArg);
 109+ HRESULT WINAPI FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR);
 110+ HRESULT WINAPI Initialize(REFIID lpREFIID);
 111+private:
 112+ ULONG refcount;
 113+ glDirect3D7 *glD3D7;
 114+};
 115+
95116 #endif //__GLDIRECT3D_H
\ No newline at end of file
Index: ddraw/glDirect3DDevice.cpp
@@ -34,6 +34,43 @@
3535 #include "glutil.h"
3636 #include "matrix.h"
3737
 38+typedef struct _D3DDeviceDesc1 {
 39+ DWORD dwSize;
 40+ DWORD dwFlags;
 41+ D3DCOLORMODEL dcmColorModel;
 42+ DWORD dwDevCaps;
 43+ D3DTRANSFORMCAPS dtcTransformCaps;
 44+ BOOL bClipping;
 45+ D3DLIGHTINGCAPS dlcLightingCaps;
 46+ D3DPRIMCAPS dpcLineCaps;
 47+ D3DPRIMCAPS dpcTriCaps;
 48+ DWORD dwDeviceRenderBitDepth;
 49+ DWORD dwDeviceZBufferBitDepth;
 50+ DWORD dwMaxBufferSize;
 51+ DWORD dwMaxVertexCount;
 52+} D3DDEVICEDESC1,*LPD3DDEVICEDESC1;
 53+
 54+typedef struct _D3DDeviceDesc2 {
 55+ DWORD dwSize;
 56+ DWORD dwFlags;
 57+ D3DCOLORMODEL dcmColorModel;
 58+ DWORD dwDevCaps;
 59+ D3DTRANSFORMCAPS dtcTransformCaps;
 60+ BOOL bClipping;
 61+ D3DLIGHTINGCAPS dlcLightingCaps;
 62+ D3DPRIMCAPS dpcLineCaps;
 63+ D3DPRIMCAPS dpcTriCaps;
 64+ DWORD dwDeviceRenderBitDepth;
 65+ DWORD dwDeviceZBufferBitDepth;
 66+ DWORD dwMaxBufferSize;
 67+ DWORD dwMaxVertexCount;
 68+
 69+ DWORD dwMinTextureWidth,dwMinTextureHeight;
 70+ DWORD dwMaxTextureWidth,dwMaxTextureHeight;
 71+ DWORD dwMinStippleWidth,dwMaxStippleWidth;
 72+ DWORD dwMinStippleHeight,dwMaxStippleHeight;
 73+} D3DDEVICEDESC2,*LPD3DDEVICEDESC2;
 74+
3875 extern D3DDEVICEDESC7 d3ddesc;
3976
4077 const DWORD renderstate_default[153] = {0, // 0
@@ -214,6 +251,7 @@
215252 int zbuffer = 0;
216253 glD3DDev3 = NULL;
217254 glD3DDev2 = NULL;
 255+ glD3DDev1 = NULL;
218256 maxmaterials = 32;
219257 materials = (glDirect3DMaterial3**)malloc(32*sizeof(glDirect3DMaterial3*));
220258 if(!materials)
@@ -253,6 +291,8 @@
254292 __gluMakeIdentityf(matWorld);
255293 __gluMakeIdentityf(matView);
256294 __gluMakeIdentityf(matProjection);
 295+ matrices = NULL;
 296+ matrixcount = 0;
257297 texstages[0] = texstagedefault0;
258298 texstages[1] = texstages[2] = texstages[3] = texstages[4] =
259299 texstages[5] = texstages[6] = texstages[7] = texstagedefault1;
@@ -313,6 +353,7 @@
314354 }
315355 free(viewports);
316356 free(materials);
 357+ if(matrices) free(matrices);
317358 glD3D7->Release();
318359 glDDS7->Release();
319360 }
@@ -1661,14 +1702,18 @@
16621703 D3DDEVICEDESC desc = d3ddesc3;
16631704 if(lpD3DHELDevDesc)
16641705 {
1665 - if(lpD3DHELDevDesc->dwSize < sizeof(D3DDEVICEDESC)) return DDERR_INVALIDPARAMS;
1666 - memcpy(lpD3DHELDevDesc, &desc, sizeof(D3DDEVICEDESC));
 1706+ desc.dwSize = lpD3DHELDevDesc->dwSize;
 1707+ if(desc.dwSize < sizeof(D3DDEVICEDESC1)) return DDERR_INVALIDPARAMS;
 1708+ if(desc.dwSize > sizeof(D3DDEVICEDESC1)) desc.dwSize = sizeof(D3DDEVICEDESC);
 1709+ memcpy(lpD3DHELDevDesc, &desc, desc.dwSize);
16671710 }
16681711 desc.dwDevCaps |= D3DDEVCAPS_HWRASTERIZATION;
16691712 if(lpD3DHWDevDesc)
16701713 {
1671 - if(lpD3DHWDevDesc->dwSize < sizeof(D3DDEVICEDESC)) return DDERR_INVALIDPARAMS;
1672 - memcpy(lpD3DHWDevDesc, &desc, sizeof(D3DDEVICEDESC));
 1714+ desc.dwSize = lpD3DHWDevDesc->dwSize;
 1715+ if(desc.dwSize < sizeof(D3DDEVICEDESC1)) return DDERR_INVALIDPARAMS;
 1716+ if(desc.dwSize > sizeof(D3DDEVICEDESC1)) desc.dwSize = sizeof(D3DDEVICEDESC);
 1717+ memcpy(lpD3DHWDevDesc, &desc, desc.dwSize);
16731718 }
16741719 return D3D_OK;
16751720 }
@@ -1768,6 +1813,113 @@
17691814 SetRenderState(D3DRENDERSTATE_SPECULARENABLE,TRUE);
17701815 }
17711816
 1817+HRESULT glDirect3DDevice7::CreateMatrix(LPD3DMATRIXHANDLE lpD3DMatHandle)
 1818+{
 1819+ if(!this) return DDERR_INVALIDOBJECT;
 1820+ if(!lpD3DMatHandle) return DDERR_INVALIDPARAMS;
 1821+ int foundslot = 0;
 1822+ if(!matrices)
 1823+ {
 1824+ matrices = (D3D1MATRIX*)malloc(16*sizeof(D3D1MATRIX));
 1825+ if(!matrices) return DDERR_OUTOFMEMORY;
 1826+ ZeroMemory(matrices,16*sizeof(D3D1MATRIX));
 1827+ matrixcount = 16;
 1828+ }
 1829+ for(int i = 0; i < matrixcount; i++)
 1830+ {
 1831+ if(i == 0) continue;
 1832+ if(!matrices[i].active)
 1833+ {
 1834+ foundslot = i;
 1835+ break;
 1836+ }
 1837+ }
 1838+ if(!foundslot)
 1839+ {
 1840+ int newcount;
 1841+ D3D1MATRIX *newmatrices;
 1842+ newcount = matrixcount + 16;
 1843+ newmatrices = (D3D1MATRIX*)realloc(matrices,newcount*sizeof(D3D1MATRIX));
 1844+ if(!newmatrices) return DDERR_OUTOFMEMORY;
 1845+ ZeroMemory(&newmatrices[matrixcount],16*sizeof(D3D1MATRIX));
 1846+ matrices = newmatrices;
 1847+ foundslot = matrixcount;
 1848+ matrixcount = newcount;
 1849+ }
 1850+ *lpD3DMatHandle = foundslot;
 1851+ __gluMakeIdentityf((GLfloat*)&matrices[foundslot].matrix);
 1852+ matrices[foundslot].active = TRUE;
 1853+ return D3D_OK;
 1854+}
 1855+
 1856+HRESULT glDirect3DDevice7::DeleteMatrix(D3DMATRIXHANDLE d3dMatHandle)
 1857+{
 1858+ if(!this) return DDERR_INVALIDOBJECT;
 1859+ if(!d3dMatHandle) return DDERR_INVALIDPARAMS;
 1860+ if(d3dMatHandle >= matrixcount) return DDERR_INVALIDPARAMS;
 1861+ if(!matrices[d3dMatHandle].active) return D3DERR_MATRIX_DESTROY_FAILED;
 1862+ matrices[d3dMatHandle].active = FALSE;
 1863+ return D3D_OK;
 1864+}
 1865+
 1866+HRESULT glDirect3DDevice7::GetMatrix(D3DMATRIXHANDLE lpD3DMatHandle, LPD3DMATRIX lpD3DMatrix)
 1867+{
 1868+ if(!this) return DDERR_INVALIDOBJECT;
 1869+ if(!lpD3DMatHandle) return DDERR_INVALIDPARAMS;
 1870+ if(lpD3DMatHandle >= matrixcount) return DDERR_INVALIDPARAMS;
 1871+ if(!matrices[lpD3DMatHandle].active) return D3DERR_MATRIX_GETDATA_FAILED;
 1872+ memcpy(lpD3DMatrix,&matrices[lpD3DMatHandle].matrix,sizeof(D3DMATRIX));
 1873+ return D3D_OK;
 1874+}
 1875+
 1876+HRESULT glDirect3DDevice7::SetMatrix(D3DMATRIXHANDLE d3dMatHandle, LPD3DMATRIX lpD3DMatrix)
 1877+{
 1878+ if(!this) return DDERR_INVALIDOBJECT;
 1879+ if(!d3dMatHandle) return DDERR_INVALIDPARAMS;
 1880+ if(d3dMatHandle >= matrixcount) return DDERR_INVALIDPARAMS;
 1881+ if(!matrices[d3dMatHandle].active) return D3DERR_MATRIX_SETDATA_FAILED;
 1882+ memcpy(&matrices[d3dMatHandle],lpD3DMatrix,sizeof(D3DMATRIX));
 1883+ return D3D_OK;
 1884+}
 1885+
 1886+HRESULT glDirect3DDevice7::CreateExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc, LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer,
 1887+ IUnknown* pUnkOuter)
 1888+{
 1889+ if(!this) return DDERR_INVALIDOBJECT;
 1890+ if(!lpDesc) return DDERR_INVALIDPARAMS;
 1891+ if(!lplpDirect3DExecuteBuffer) return DDERR_INVALIDPARAMS;
 1892+ if(pUnkOuter) return DDERR_INVALIDPARAMS;
 1893+ FIXME("glDirect3DDevice1::CreateExecuteBuffer: stub");
 1894+ ERR(DDERR_GENERIC);
 1895+}
 1896+
 1897+HRESULT glDirect3DDevice7::Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags)
 1898+{
 1899+ if(!this) return DDERR_INVALIDOBJECT;
 1900+ if(!lpDirect3DExecuteBuffer) return DDERR_INVALIDPARAMS;
 1901+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 1902+ FIXME("glDirect3DDevice1::Execute: stub");
 1903+ ERR(DDERR_GENERIC);
 1904+}
 1905+
 1906+HRESULT glDirect3DDevice7::GetPickRecords(LPDWORD lpCount, LPD3DPICKRECORD lpD3DPickRec)
 1907+{
 1908+ if(!this) return DDERR_INVALIDOBJECT;
 1909+ if(!lpCount) return DDERR_INVALIDOBJECT;
 1910+ FIXME("glDirect3DDevice1::GetPickRecords: stub");
 1911+ ERR(DDERR_GENERIC);
 1912+}
 1913+
 1914+HRESULT glDirect3DDevice7::Pick(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags,
 1915+ LPD3DRECT lpRect)
 1916+{
 1917+ if(!this) return DDERR_INVALIDOBJECT;
 1918+ if(lpDirect3DExecuteBuffer) return DDERR_INVALIDPARAMS;
 1919+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 1920+ if(!lpRect) return DDERR_INVALIDPARAMS;
 1921+ FIXME("glDirect3DDevice1::Pick: stub");
 1922+}
 1923+
17721924 // IDirect3DDevice3 wrapper
17731925 glDirect3DDevice3::glDirect3DDevice3(glDirect3DDevice7 *glD3DDev7)
17741926 {
@@ -2366,3 +2518,178 @@
23672519 if(!this) return DDERR_INVALIDOBJECT;
23682520 return glD3DDev7->Vertex(lpVertexType);
23692521 }
 2522+
 2523+// IDirect3DDevice wrapper
 2524+glDirect3DDevice1::glDirect3DDevice1(glDirect3DDevice7 *glD3DDev7)
 2525+{
 2526+ this->glD3DDev7 = glD3DDev7;
 2527+ glD3DDev7->InitDX5();
 2528+ refcount = 1;
 2529+}
 2530+
 2531+glDirect3DDevice1::~glDirect3DDevice1()
 2532+{
 2533+ glD3DDev7->glD3DDev1 = NULL;
 2534+ glD3DDev7->Release();
 2535+}
 2536+
 2537+HRESULT WINAPI glDirect3DDevice1::QueryInterface(REFIID riid, void** ppvObj)
 2538+{
 2539+ if(!this) return DDERR_INVALIDOBJECT;
 2540+ if(riid == IID_IUnknown)
 2541+ {
 2542+ this->AddRef();
 2543+ *ppvObj = this;
 2544+ return DD_OK;
 2545+ }
 2546+ return glD3DDev7->QueryInterface(riid,ppvObj);
 2547+}
 2548+
 2549+ULONG WINAPI glDirect3DDevice1::AddRef()
 2550+{
 2551+ if(!this) return 0;
 2552+ refcount++;
 2553+ return refcount;
 2554+}
 2555+
 2556+ULONG WINAPI glDirect3DDevice1::Release()
 2557+{
 2558+ if(!this) return 0;
 2559+ ULONG ret;
 2560+ refcount--;
 2561+ ret = refcount;
 2562+ if(refcount == 0) delete this;
 2563+ return ret;
 2564+}
 2565+
 2566+HRESULT WINAPI glDirect3DDevice1::AddViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport)
 2567+{
 2568+ if(!this) return DDERR_INVALIDOBJECT;
 2569+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 2570+ glDirect3DViewport3 *glD3DV3;
 2571+ lpDirect3DViewport->QueryInterface(IID_IDirect3DViewport3,(void**)&glD3DV3);
 2572+ HRESULT ret = glD3DDev7->AddViewport(glD3DV3);
 2573+ glD3DV3->Release();
 2574+ return ret;
 2575+}
 2576+HRESULT WINAPI glDirect3DDevice1::BeginScene()
 2577+{
 2578+ if(!this) return DDERR_INVALIDOBJECT;
 2579+ return glD3DDev7->BeginScene();
 2580+}
 2581+HRESULT WINAPI glDirect3DDevice1::CreateExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc,
 2582+ LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer, IUnknown* pUnkOuter)
 2583+{
 2584+ if(!this) return DDERR_INVALIDOBJECT;
 2585+ return glD3DDev7->CreateExecuteBuffer(lpDesc,lplpDirect3DExecuteBuffer,pUnkOuter);
 2586+}
 2587+HRESULT WINAPI glDirect3DDevice1::CreateMatrix(LPD3DMATRIXHANDLE lpD3DMatHandle)
 2588+{
 2589+ if(!this) return DDERR_INVALIDOBJECT;
 2590+ return glD3DDev7->CreateMatrix(lpD3DMatHandle);
 2591+}
 2592+HRESULT WINAPI glDirect3DDevice1::DeleteMatrix(D3DMATRIXHANDLE d3dMatHandle)
 2593+{
 2594+ if(!this) return DDERR_INVALIDOBJECT;
 2595+ return glD3DDev7->DeleteMatrix(d3dMatHandle);
 2596+}
 2597+HRESULT WINAPI glDirect3DDevice1::DeleteViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport)
 2598+{
 2599+ if(!this) return DDERR_INVALIDOBJECT;
 2600+ glDirect3DViewport3 *glD3DV3;
 2601+ lpDirect3DViewport->QueryInterface(IID_IDirect3DViewport3,(void**)&glD3DV3);
 2602+ HRESULT ret = glD3DDev7->DeleteViewport(glD3DV3);
 2603+ glD3DV3->Release();
 2604+ return ret;
 2605+}
 2606+HRESULT WINAPI glDirect3DDevice1::EndScene()
 2607+{
 2608+ if(!this) return DDERR_INVALIDOBJECT;
 2609+ return glD3DDev7->EndScene();
 2610+}
 2611+HRESULT WINAPI glDirect3DDevice1::EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg)
 2612+{
 2613+ if(!this) return DDERR_INVALIDOBJECT;
 2614+ LPVOID context[2];
 2615+ context[0] = (LPVOID)lpd3dEnumTextureProc;
 2616+ context[1] = lpArg;
 2617+ return glD3DDev7->EnumTextureFormats(EnumTex2,&context);
 2618+}
 2619+HRESULT WINAPI glDirect3DDevice1::Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags)
 2620+{
 2621+ if(!this) return DDERR_INVALIDOBJECT;
 2622+ return glD3DDev7->Execute(lpDirect3DExecuteBuffer,lpDirect3DViewport,dwFlags);
 2623+}
 2624+HRESULT WINAPI glDirect3DDevice1::GetCaps(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc)
 2625+{
 2626+ if(!this) return DDERR_INVALIDOBJECT;
 2627+ return glD3DDev7->GetCaps3(lpD3DHWDevDesc,lpD3DHELDevDesc);
 2628+}
 2629+HRESULT WINAPI glDirect3DDevice1::GetDirect3D(LPDIRECT3D* lpD3D)
 2630+{
 2631+ if(!this) return DDERR_INVALIDOBJECT;
 2632+ LPDIRECT3D7 d3d7;
 2633+ HRESULT err = glD3DDev7->GetDirect3D(&d3d7);
 2634+ if(!d3d7) return err;
 2635+ d3d7->QueryInterface(IID_IDirect3D,(void**)lpD3D);
 2636+ d3d7->Release();
 2637+ return err;
 2638+}
 2639+
 2640+HRESULT WINAPI glDirect3DDevice1::GetMatrix(D3DMATRIXHANDLE lpD3DMatHandle, LPD3DMATRIX lpD3DMatrix)
 2641+{
 2642+ if(!this) return DDERR_INVALIDPARAMS;
 2643+ return glD3DDev7->GetMatrix(lpD3DMatHandle,lpD3DMatrix);
 2644+}
 2645+
 2646+HRESULT WINAPI glDirect3DDevice1::GetPickRecords(LPDWORD lpCount, LPD3DPICKRECORD lpD3DPickRec)
 2647+{
 2648+ if(!this) return DDERR_INVALIDPARAMS;
 2649+ return glD3DDev7->GetPickRecords(lpCount,lpD3DPickRec);
 2650+}
 2651+
 2652+HRESULT WINAPI glDirect3DDevice1::GetStats(LPD3DSTATS lpD3DStats)
 2653+{
 2654+ if(!this) return DDERR_INVALIDPARAMS;
 2655+ return glD3DDev7->GetStats(lpD3DStats);
 2656+}
 2657+
 2658+HRESULT WINAPI glDirect3DDevice1::Initialize(LPDIRECT3D lpd3d, LPGUID lpGUID, LPD3DDEVICEDESC lpd3ddvdesc)
 2659+{
 2660+ if(!this) return DDERR_INVALIDPARAMS;
 2661+ return DDERR_ALREADYINITIALIZED;
 2662+}
 2663+HRESULT WINAPI glDirect3DDevice1::NextViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport, LPDIRECT3DVIEWPORT *lplpDirect3DViewport, DWORD dwFlags)
 2664+{
 2665+ if(!this) return DDERR_INVALIDOBJECT;
 2666+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 2667+ if(!lplpDirect3DViewport) return DDERR_INVALIDPARAMS;
 2668+ FIXME("glDirect3DDevice1::NextViewport: stub");
 2669+ ERR(DDERR_GENERIC);
 2670+}
 2671+HRESULT WINAPI glDirect3DDevice1::Pick(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport,
 2672+ DWORD dwFlags, LPD3DRECT lpRect)
 2673+{
 2674+ if(!this) return DDERR_INVALIDOBJECT;
 2675+ return glD3DDev7->Pick(lpDirect3DExecuteBuffer, lpDirect3DViewport, dwFlags, lpRect);
 2676+}
 2677+
 2678+HRESULT WINAPI glDirect3DDevice1::SetMatrix(D3DMATRIXHANDLE d3dMatHandle, LPD3DMATRIX lpD3DMatrix)
 2679+{
 2680+ if(!this) return DDERR_INVALIDOBJECT;
 2681+ return glD3DDev7->SetMatrix(d3dMatHandle,lpD3DMatrix);
 2682+}
 2683+
 2684+HRESULT WINAPI glDirect3DDevice1::SwapTextureHandles(LPDIRECT3DTEXTURE lpD3DTex1, LPDIRECT3DTEXTURE lpD3DTex2)
 2685+{
 2686+ if(!this) return DDERR_INVALIDOBJECT;
 2687+ if(!lpD3DTex1) return DDERR_INVALIDPARAMS;
 2688+ if(!lpD3DTex2) return DDERR_INVALIDPARAMS;
 2689+ LPDIRECT3DTEXTURE2 tex1, tex2;
 2690+ lpD3DTex1->QueryInterface(IID_IDirect3DTexture2,(void**)&tex1);
 2691+ lpD3DTex2->QueryInterface(IID_IDirect3DTexture2,(void**)&tex2);
 2692+ HRESULT ret = glD3DDev7->SwapTextureHandles(tex1,tex2);
 2693+ tex2->Release();
 2694+ tex1->Release();
 2695+ return ret;
 2696+}
\ No newline at end of file
Index: ddraw/glDirect3DDevice.h
@@ -54,6 +54,12 @@
5555 GLint glminfilter;
5656 };
5757
 58+struct D3D1MATRIX
 59+{
 60+ BOOL active;
 61+ D3DMATRIX matrix;
 62+};
 63+
5864 class glDirect3DLight;
5965 class glDirectDrawSurface7;
6066 class glDirect3DMaterial3;
@@ -60,6 +66,7 @@
6167 class glDirect3DViewport3;
6268 class glDirect3DDevice3;
6369 class glDirect3DDevice2;
 70+class glDirect3DDevice1;
6471 class glDirect3DDevice7 : public IDirect3DDevice7
6572 {
6673 public:
@@ -145,11 +152,23 @@
146153 HRESULT SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState);
147154 HRESULT GetStats(LPD3DSTATS lpD3DStats);
148155 HRESULT SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2);
 156+ HRESULT CreateExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc, LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer,
 157+ IUnknown* pUnkOuter);
 158+ HRESULT Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags);
 159+ HRESULT CreateMatrix(LPD3DMATRIXHANDLE lpD3DMatHandle);
 160+ HRESULT DeleteMatrix(D3DMATRIXHANDLE d3dMatHandle);
 161+ HRESULT GetMatrix(D3DMATRIXHANDLE lpD3DMatHandle, LPD3DMATRIX lpD3DMatrix);
 162+ HRESULT SetMatrix(D3DMATRIXHANDLE d3dMatHandle, LPD3DMATRIX lpD3DMatrix);
 163+ HRESULT GetPickRecords(LPDWORD lpCount, LPD3DPICKRECORD lpD3DPickRec);
 164+ HRESULT Pick(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags,
 165+ LPD3DRECT lpRect);
149166 void InitDX5();
150167 __int64 SelectShader(GLVERTEX *VertexType);
151168 GLfloat matWorld[16];
152169 GLfloat matView[16];
153170 GLfloat matProjection[16];
 171+ D3D1MATRIX *matrices;
 172+ int matrixcount;
154173 D3DMATERIAL7 material;
155174 D3DVIEWPORT7 viewport;
156175 glDirect3DLight **lights;
@@ -167,6 +186,7 @@
168187 bool projection_dirty;
169188 glDirect3DDevice3 *glD3DDev3;
170189 glDirect3DDevice2 *glD3DDev2;
 190+ glDirect3DDevice1 *glD3DDev1;
171191 private:
172192 HRESULT error;
173193 HRESULT fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr);
@@ -298,4 +318,38 @@
299319 private:
300320 glDirect3DDevice7 *glD3DDev7;
301321 ULONG refcount;
 322+};
 323+
 324+class glDirect3DDevice1 : public IDirect3DDevice
 325+{
 326+public:
 327+ glDirect3DDevice1(glDirect3DDevice7 *glD3DDev7);
 328+ virtual ~glDirect3DDevice1();
 329+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 330+ ULONG WINAPI AddRef();
 331+ ULONG WINAPI Release();
 332+ HRESULT WINAPI AddViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport);
 333+ HRESULT WINAPI BeginScene();
 334+ HRESULT WINAPI CreateExecuteBuffer(LPD3DEXECUTEBUFFERDESC lpDesc, LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer,
 335+ IUnknown* pUnkOuter);
 336+ HRESULT WINAPI CreateMatrix(LPD3DMATRIXHANDLE lpD3DMatHandle);
 337+ HRESULT WINAPI DeleteMatrix(D3DMATRIXHANDLE d3dMatHandle);
 338+ HRESULT WINAPI DeleteViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport);
 339+ HRESULT WINAPI EndScene();
 340+ HRESULT WINAPI EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg);
 341+ HRESULT WINAPI Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags);
 342+ HRESULT WINAPI GetCaps(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc);
 343+ HRESULT WINAPI GetDirect3D(LPDIRECT3D* lpD3D);
 344+ HRESULT WINAPI GetMatrix(D3DMATRIXHANDLE lpD3DMatHandle, LPD3DMATRIX lpD3DMatrix);
 345+ HRESULT WINAPI GetPickRecords(LPDWORD lpCount, LPD3DPICKRECORD lpD3DPickRec);
 346+ HRESULT WINAPI GetStats(LPD3DSTATS lpD3DStats);
 347+ HRESULT WINAPI Initialize(LPDIRECT3D lpd3d, LPGUID lpGUID, LPD3DDEVICEDESC lpd3ddvdesc);
 348+ HRESULT WINAPI NextViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport, LPDIRECT3DVIEWPORT* lplpDirect3DViewport, DWORD dwFlags);
 349+ HRESULT WINAPI Pick(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags,
 350+ LPD3DRECT lpRect);
 351+ HRESULT WINAPI SetMatrix(D3DMATRIXHANDLE d3dMatHandle, LPD3DMATRIX lpD3DMatrix);
 352+ HRESULT WINAPI SwapTextureHandles(LPDIRECT3DTEXTURE lpD3DTex1, LPDIRECT3DTEXTURE lpD3DTex2);
 353+private:
 354+ glDirect3DDevice7 *glD3DDev7;
 355+ ULONG refcount;
302356 };
\ No newline at end of file
Index: ddraw/glDirect3DMaterial.cpp
@@ -35,6 +35,7 @@
3636 material.dwRampSize = 0;
3737 handle = 0;
3838 glD3DM2 = NULL;
 39+ glD3DM1 = NULL;
3940 }
4041
4142 glDirect3DMaterial3::~glDirect3DMaterial3()
@@ -73,6 +74,22 @@
7475 return D3D_OK;
7576 }
7677 }
 78+ if(riid == IID_IDirect3DMaterial)
 79+ {
 80+ if(glD3DM1)
 81+ {
 82+ *ppvObj = glD3DM1;
 83+ glD3DM1->AddRef();
 84+ return D3D_OK;
 85+ }
 86+ else
 87+ {
 88+ this->AddRef();
 89+ *ppvObj = new glDirect3DMaterial1(this);
 90+ glD3DM1 = (glDirect3DMaterial1*)*ppvObj;
 91+ return D3D_OK;
 92+ }
 93+ }
7794 return E_NOINTERFACE;
7895 }
7996
@@ -216,3 +233,86 @@
217234 if(!this) return DDERR_INVALIDOBJECT;
218235 return glD3DM3->SetMaterial(lpMat);
219236 }
 237+
 238+glDirect3DMaterial1::glDirect3DMaterial1(glDirect3DMaterial3 *glD3DM3)
 239+{
 240+ refcount = 1;
 241+ this->glD3DM3 = glD3DM3;
 242+}
 243+
 244+glDirect3DMaterial1::~glDirect3DMaterial1()
 245+{
 246+ glD3DM3->glD3DM1 = NULL;
 247+ glD3DM3->Release();
 248+}
 249+
 250+ULONG WINAPI glDirect3DMaterial1::AddRef()
 251+{
 252+ if(!this) return 0;
 253+ refcount++;
 254+ return refcount;
 255+}
 256+
 257+ULONG WINAPI glDirect3DMaterial1::Release()
 258+{
 259+ if(!this) return 0;
 260+ ULONG ret;
 261+ refcount--;
 262+ ret = refcount;
 263+ if(refcount == 0) delete this;
 264+ return ret;
 265+}
 266+
 267+HRESULT WINAPI glDirect3DMaterial1::QueryInterface(REFIID riid, void** ppvObj)
 268+{
 269+ if(!this) return DDERR_INVALIDOBJECT;
 270+ if(riid == IID_IUnknown)
 271+ {
 272+ this->AddRef();
 273+ *ppvObj = this;
 274+ return D3D_OK;
 275+ }
 276+ return glD3DM3->QueryInterface(riid,ppvObj);
 277+}
 278+
 279+HRESULT WINAPI glDirect3DMaterial1::GetHandle(LPDIRECT3DDEVICE lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle)
 280+{
 281+ if(!this) return DDERR_INVALIDOBJECT;
 282+ if(!lpDirect3DDevice) return DDERR_INVALIDPARAMS;
 283+ glDirect3DDevice1 *glD3DDev1 = (glDirect3DDevice1*)lpDirect3DDevice;
 284+ glDirect3DDevice3 *glD3DDev3;
 285+ glD3DDev1->QueryInterface(IID_IDirect3DDevice3,(void**)&glD3DDev3);
 286+ HRESULT ret = glD3DM3->GetHandle(glD3DDev3,lpHandle);
 287+ glD3DDev3->Release();
 288+ return ret;
 289+}
 290+
 291+HRESULT WINAPI glDirect3DMaterial1::GetMaterial(LPD3DMATERIAL lpMat)
 292+{
 293+ if(!this) return DDERR_INVALIDOBJECT;
 294+ return glD3DM3->GetMaterial(lpMat);
 295+}
 296+
 297+HRESULT WINAPI glDirect3DMaterial1::Initialize(LPDIRECT3D lpDirect3D)
 298+{
 299+ if(!this) return DDERR_INVALIDOBJECT;
 300+ return DDERR_ALREADYINITIALIZED;
 301+}
 302+
 303+HRESULT WINAPI glDirect3DMaterial1::Reserve()
 304+{
 305+ if(!this) return DDERR_INVALIDPARAMS;
 306+ return DDERR_UNSUPPORTED;
 307+}
 308+
 309+HRESULT WINAPI glDirect3DMaterial1::SetMaterial(LPD3DMATERIAL lpMat)
 310+{
 311+ if(!this) return DDERR_INVALIDOBJECT;
 312+ return glD3DM3->SetMaterial(lpMat);
 313+}
 314+
 315+HRESULT WINAPI glDirect3DMaterial1::Unreserve()
 316+{
 317+ if(!this) return DDERR_INVALIDPARAMS;
 318+ return DDERR_UNSUPPORTED;
 319+}
Index: ddraw/glDirect3DMaterial.h
@@ -19,6 +19,7 @@
2020 #ifndef __GLDIRECT3DMATERIAL_H
2121 #define __GLDIRECT3DMATERIAL_H
2222
 23+class glDirect3DMaterial1;
2324 class glDirect3DMaterial2;
2425 class glDirect3DMaterial3 : public IDirect3DMaterial3
2526 {
@@ -37,6 +38,7 @@
3839 D3DMATERIAL material;
3940 D3DMATERIALHANDLE handle;
4041 glDirect3DMaterial2 *glD3DM2;
 42+ glDirect3DMaterial1 *glD3DM1;
4143 private:
4244 ULONG refcount;
4345 bool current;
@@ -59,4 +61,23 @@
6062 glDirect3DMaterial3 *glD3DM3;
6163 };
6264
 65+class glDirect3DMaterial1 : public IDirect3DMaterial
 66+{
 67+public:
 68+ glDirect3DMaterial1(glDirect3DMaterial3 *glD3DM3);
 69+ virtual ~glDirect3DMaterial1();
 70+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 71+ ULONG WINAPI AddRef();
 72+ ULONG WINAPI Release();
 73+ HRESULT WINAPI GetHandle(LPDIRECT3DDEVICE lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle);
 74+ HRESULT WINAPI GetMaterial(LPD3DMATERIAL lpMat);
 75+ HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
 76+ HRESULT WINAPI Reserve();
 77+ HRESULT WINAPI SetMaterial(LPD3DMATERIAL lpMat);
 78+ HRESULT WINAPI Unreserve();
 79+private:
 80+ ULONG refcount;
 81+ glDirect3DMaterial3 *glD3DM3;
 82+};
 83+
6384 #endif //__GLDIRECT3DMATERIAL_H
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -58,6 +58,7 @@
5959 dds3 = NULL;
6060 dds4 = NULL;
6161 d3dt2 = NULL;
 62+ d3dt1 = NULL;
6263 buffer = gdibuffer = NULL;
6364 bigbuffer = NULL;
6465 zbuffer = NULL;