DXGL r248 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r247‎ | r248 | r249 >
Date:21:32, 1 September 2012
Author:admin
Status:new
Tags:
Comment:
Add IDirect3D2 interfaces.
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/glDirect3DTexture.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.h (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -188,11 +188,13 @@
189189 this->glDD7 = glDD7;
190190 glDD7->AddRef();
191191 glD3D3 = NULL;
 192+ glD3D2 = NULL;
192193 }
193194
194195 glDirect3D7::~glDirect3D7()
195196 {
196197 if(glD3D3) glD3D3->Release();
 198+ if(glD3D2) glD3D2->Release();
197199 glDD7->Release();
198200 }
199201
@@ -238,6 +240,22 @@
239241 return D3D_OK;
240242 }
241243 }
 244+ if(riid == IID_IDirect3D2)
 245+ {
 246+ if(glD3D2)
 247+ {
 248+ *ppvObj = glD3D2;
 249+ glD3D2->AddRef();
 250+ return D3D_OK;
 251+ }
 252+ else
 253+ {
 254+ this->AddRef();
 255+ *ppvObj = new glDirect3D2(this);
 256+ glD3D2 = (glDirect3D2*)*ppvObj;
 257+ return D3D_OK;
 258+ }
 259+ }
242260 return E_NOINTERFACE;
243261 }
244262
@@ -487,7 +505,7 @@
488506 return ret;
489507 }
490508
491 -HRESULT WINAPI glDirect3D3::CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE4 lpDDS, LPDIRECT3DDEVICE3 * lplpD3DDevice, LPUNKNOWN pUnkOuter)
 509+HRESULT WINAPI glDirect3D3::CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE4 lpDDS, LPDIRECT3DDEVICE3 *lplpD3DDevice, LPUNKNOWN pUnkOuter)
492510 {
493511 if(!this) return DDERR_INVALIDPARAMS;
494512 if(pUnkOuter) return DDERR_INVALIDPARAMS;
@@ -538,7 +556,7 @@
539557 return glD3D7->EnumDevices3(lpEnumDevicesCallback,lpUserArg);
540558 }
541559
542 -HRESULT WINAPI glDirect3D3::EnumZBufferFormats(REFCLSID riidDevice, LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback, LPVOID lpContext)
 560+HRESULT WINAPI glDirect3D3::EnumZBufferFormats(REFCLSID riidDevice, LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback, LPVOID lpContext)
543561 {
544562 if(!this) return DDERR_INVALIDPARAMS;
545563 return glD3D7->EnumZBufferFormats(riidDevice,lpEnumCallback,lpContext);
@@ -553,3 +571,100 @@
554572 if(!this) return DDERR_INVALIDPARAMS;
555573 return glD3D7->FindDevice(lpD3DFDS,lpD3DFDR);
556574 }
 575+
 576+
 577+glDirect3D2::glDirect3D2(glDirect3D7 *glD3D7)
 578+{
 579+ this->glD3D7 = glD3D7;
 580+ refcount = 1;
 581+}
 582+
 583+glDirect3D2::~glDirect3D2()
 584+{
 585+ glD3D7->Release();
 586+}
 587+
 588+HRESULT WINAPI glDirect3D2::QueryInterface(REFIID riid, void** ppvObj)
 589+{
 590+ if(!this) return DDERR_INVALIDPARAMS;
 591+ if(riid == IID_IUnknown)
 592+ {
 593+ this->AddRef();
 594+ *ppvObj = this;
 595+ return DD_OK;
 596+ }
 597+ return glD3D7->QueryInterface(riid,ppvObj);
 598+}
 599+
 600+ULONG WINAPI glDirect3D2::AddRef()
 601+{
 602+ if(!this) return 0;
 603+ refcount++;
 604+ return refcount;
 605+}
 606+
 607+ULONG WINAPI glDirect3D2::Release()
 608+{
 609+ if(!this) return 0;
 610+ ULONG ret;
 611+ refcount--;
 612+ ret = refcount;
 613+ if(refcount == 0) delete this;
 614+ return ret;
 615+}
 616+
 617+HRESULT WINAPI glDirect3D2::CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE lpDDS, LPDIRECT3DDEVICE2 *lplpD3DDevice)
 618+{
 619+ if(!this) return DDERR_INVALIDPARAMS;
 620+ LPDIRECT3DDEVICE7 lpD3DDev7;
 621+ HRESULT err = glD3D7->CreateDevice(rclsid,((glDirectDrawSurface1*)lpDDS)->GetDDS7(),&lpD3DDev7);
 622+ if(err == D3D_OK)
 623+ {
 624+ lpD3DDev7->QueryInterface(IID_IDirect3DDevice2,(LPVOID*)lplpD3DDevice);
 625+ lpD3DDev7->Release();
 626+ return D3D_OK;
 627+ }
 628+ return err;
 629+}
 630+
 631+HRESULT WINAPI glDirect3D2::CreateLight(LPDIRECT3DLIGHT* lplpDirect3DLight, IUnknown* pUnkOuter)
 632+{
 633+ if(!this) return DDERR_INVALIDPARAMS;
 634+ return glD3D7->CreateLight(lplpDirect3DLight,pUnkOuter);
 635+}
 636+
 637+HRESULT WINAPI glDirect3D2::CreateMaterial(LPDIRECT3DMATERIAL2* lplpDirect3DMaterial2, IUnknown* pUnkOuter)
 638+{
 639+ if(!this) return DDERR_INVALIDPARAMS;
 640+ if(!lplpDirect3DMaterial2) return DDERR_INVALIDPARAMS;
 641+ glDirect3DMaterial3 *glD3DM3;
 642+ HRESULT error = glD3D7->CreateMaterial((LPDIRECT3DMATERIAL3*)&glD3DM3,pUnkOuter);
 643+ if(error) return error;
 644+ glD3DM3->QueryInterface(IID_IDirect3DMaterial2,(void**)lplpDirect3DMaterial2);
 645+ glD3DM3->Release();
 646+ return D3D_OK;
 647+}
 648+
 649+HRESULT WINAPI glDirect3D2::CreateViewport(LPDIRECT3DVIEWPORT2* lplpD3DViewport2, IUnknown* pUnkOuter)
 650+{
 651+ if(!this) return DDERR_INVALIDPARAMS;
 652+ if(!lplpD3DViewport2) return DDERR_INVALIDPARAMS;
 653+ glDirect3DMaterial3 *glD3DV3;
 654+ HRESULT error = glD3D7->CreateViewport((LPDIRECT3DVIEWPORT3*)&glD3DV3,pUnkOuter);
 655+ if(error) return error;
 656+ glD3DV3->QueryInterface(IID_IDirect3DViewport2,(void**)lplpD3DViewport2);
 657+ glD3DV3->Release();
 658+ return D3D_OK;
 659+}
 660+
 661+HRESULT WINAPI glDirect3D2::EnumDevices(LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback, LPVOID lpUserArg)
 662+{
 663+ if(!this) return DDERR_INVALIDPARAMS;
 664+ return glD3D7->EnumDevices3(lpEnumDevicesCallback,lpUserArg);
 665+}
 666+
 667+HRESULT WINAPI glDirect3D2::FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR)
 668+{
 669+ if(!this) return DDERR_INVALIDPARAMS;
 670+ return glD3D7->FindDevice(lpD3DFDS,lpD3DFDR);
 671+}
Index: ddraw/glDirect3D.h
@@ -24,6 +24,7 @@
2525 class glDirectDraw7;
2626
2727 class glDirect3D3;
 28+class glDirect3D2;
2829 class glDirect3D7 : public IDirect3D7
2930 {
3031 public:
@@ -46,17 +47,18 @@
4748 private:
4849 ULONG refcount;
4950 glDirect3D3 *glD3D3;
 51+ glDirect3D2 *glD3D2;
5052 };
5153
5254 class glDirect3D3 : public IDirect3D3
5355 {
5456 public:
55 - glDirect3D3(glDirect3D7 *glDD7);
 57+ glDirect3D3(glDirect3D7 *glD3D7);
5658 virtual ~glDirect3D3();
5759 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
5860 ULONG WINAPI AddRef();
5961 ULONG WINAPI Release();
60 - HRESULT WINAPI CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE4 lpDDS, LPDIRECT3DDEVICE3 * lplpD3DDevice, LPUNKNOWN pUnkOuter);
 62+ HRESULT WINAPI CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE4 lpDDS, LPDIRECT3DDEVICE3 *lplpD3DDevice, LPUNKNOWN pUnkOuter);
6163 HRESULT WINAPI CreateLight(LPDIRECT3DLIGHT* lplpDirect3DLight, IUnknown* pUnkOuter);
6264 HRESULT WINAPI CreateMaterial(LPDIRECT3DMATERIAL3* lplpDirect3DMaterial, IUnknown* pUnkOuter);
6365 HRESULT WINAPI CreateVertexBuffer(LPD3DVERTEXBUFFERDESC lpVBDesc, LPDIRECT3DVERTEXBUFFER* lplpD3DVertexBuffer, DWORD dwFlags, LPUNKNOWN pUnkOuter);
@@ -70,5 +72,23 @@
7173 glDirect3D7 *glD3D7;
7274 };
7375
 76+class glDirect3D2 : public IDirect3D2
 77+{
 78+public:
 79+ glDirect3D2(glDirect3D7 *glD3D7);
 80+ virtual ~glDirect3D2();
 81+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 82+ ULONG WINAPI AddRef();
 83+ ULONG WINAPI Release();
 84+ HRESULT WINAPI CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE lpDDS, LPDIRECT3DDEVICE2 *lplpD3DDevice2);
 85+ HRESULT WINAPI CreateLight(LPDIRECT3DLIGHT* lplpDirect3DLight, IUnknown* pUnkOuter);
 86+ HRESULT WINAPI CreateMaterial(LPDIRECT3DMATERIAL2* lplpDirect3DMaterial2, IUnknown* pUnkOuter);
 87+ HRESULT WINAPI CreateViewport(LPDIRECT3DVIEWPORT2* lplpD3DViewport2, IUnknown* pUnkOuter);
 88+ HRESULT WINAPI EnumDevices(LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback, LPVOID lpUserArg);
 89+ HRESULT WINAPI FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR);
 90+private:
 91+ ULONG refcount;
 92+ glDirect3D7 *glD3D7;
 93+};
7494
7595 #endif //__GLDIRECT3D_H
\ No newline at end of file
Index: ddraw/glDirect3DDevice.cpp
@@ -217,6 +217,10 @@
218218 materialcount = 1;
219219 materials[0] = NULL;
220220 currentmaterial = NULL;
 221+ maxtextures = 32;
 222+ textures = (glDirectDrawSurface7**)malloc(32*sizeof(glDirectDrawSurface7*));
 223+ texturecount = 1;
 224+ textures[0] = NULL;
221225 maxviewports = 32;
222226 currentviewport = NULL;
223227 viewportcount = 0;
@@ -312,10 +316,36 @@
313317 }
314318 if(riid == IID_IDirect3DDevice3)
315319 {
316 - this->AddRef();
317 - *ppvObj = new glDirect3DDevice3(this);
318 - return D3D_OK;
 320+ if(glD3DDev3)
 321+ {
 322+ *ppvObj = glD3DDev3;
 323+ glD3DDev3->AddRef();
 324+ return D3D_OK;
 325+ }
 326+ else
 327+ {
 328+ this->AddRef();
 329+ *ppvObj = new glDirect3DDevice3(this);
 330+ glD3DDev3 = (glDirect3DDevice3*)*ppvObj;
 331+ return D3D_OK;
 332+ }
319333 }
 334+ if(riid == IID_IDirect3DDevice2)
 335+ {
 336+ if(glD3DDev2)
 337+ {
 338+ *ppvObj = glD3DDev2;
 339+ glD3DDev2->AddRef();
 340+ return D3D_OK;
 341+ }
 342+ else
 343+ {
 344+ this->AddRef();
 345+ *ppvObj = new glDirect3DDevice2(this);
 346+ glD3DDev2 = (glDirect3DDevice2*)*ppvObj;
 347+ return D3D_OK;
 348+ }
 349+ }
320350 ERR(E_NOINTERFACE);
321351 }
322352
@@ -1319,6 +1349,19 @@
13201350 return materialcount-1;
13211351 }
13221352
 1353+D3DTEXTUREHANDLE glDirect3DDevice7::AddTexture(glDirectDrawSurface7 *texture)
 1354+{
 1355+ textures[texturecount] = texture;
 1356+ texture->AddRef();
 1357+ texturecount++;
 1358+ if(texturecount >= maxtextures)
 1359+ {
 1360+ maxtextures += 32;
 1361+ textures = (glDirectDrawSurface7**)realloc(textures,maxtextures*sizeof(glDirectDrawSurface7*));
 1362+ }
 1363+ return texturecount-1;
 1364+}
 1365+
13231366 HRESULT glDirect3DDevice7::AddViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport)
13241367 {
13251368 if(!this) return DDERR_INVALIDOBJECT;
@@ -1519,6 +1562,15 @@
15201563 return DDERR_GENERIC;
15211564 }
15221565
 1566+HRESULT glDirect3DDevice7::SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2)
 1567+{
 1568+ if(!this) return DDERR_INVALIDOBJECT;
 1569+ if(!lpD3DTex1) return DDERR_INVALIDPARAMS;
 1570+ if(!lpD3DTex2) return DDERR_INVALIDPARAMS;
 1571+ FIXME("glDirect3DDevice7::SwapTextureHandles: stub");
 1572+ return DDERR_GENERIC;
 1573+}
 1574+
15231575 // IDirect3DDevice3 wrapper
15241576 glDirect3DDevice3::glDirect3DDevice3(glDirect3DDevice7 *glD3DDev7)
15251577 {
@@ -1528,6 +1580,7 @@
15291581
15301582 glDirect3DDevice3::~glDirect3DDevice3()
15311583 {
 1584+ glD3DDev7->glD3DDev3 = NULL;
15321585 glD3DDev7->Release();
15331586 }
15341587
@@ -1706,7 +1759,7 @@
17071760 LPDIRECTDRAWSURFACE7 dds7;
17081761 HRESULT err = glD3DDev7->GetRenderTarget(&dds7);
17091762 if(!dds7) return err;
1710 - dds7->QueryInterface(IID_IDirectDrawSurface7,(void**)lplpRenderTarget);
 1763+ dds7->QueryInterface(IID_IDirectDrawSurface4,(void**)lplpRenderTarget);
17111764 dds7->Release();
17121765 return err;
17131766 }
@@ -1818,4 +1871,300 @@
18191872 {
18201873 if(!this) return DDERR_INVALIDOBJECT;
18211874 return glD3DDev7->Vertex(lpVertex);
1822 -}
\ No newline at end of file
 1875+}
 1876+
 1877+// IDirect3DDevice2 wrapper
 1878+glDirect3DDevice2::glDirect3DDevice2(glDirect3DDevice7 *glD3DDev7)
 1879+{
 1880+ this->glD3DDev7 = glD3DDev7;
 1881+ refcount = 1;
 1882+}
 1883+
 1884+glDirect3DDevice2::~glDirect3DDevice2()
 1885+{
 1886+ glD3DDev7->glD3DDev2 = NULL;
 1887+ glD3DDev7->Release();
 1888+}
 1889+
 1890+HRESULT WINAPI glDirect3DDevice2::QueryInterface(REFIID riid, void** ppvObj)
 1891+{
 1892+ if(!this) return DDERR_INVALIDOBJECT;
 1893+ if(riid == IID_IUnknown)
 1894+ {
 1895+ this->AddRef();
 1896+ *ppvObj = this;
 1897+ return DD_OK;
 1898+ }
 1899+ return glD3DDev7->QueryInterface(riid,ppvObj);
 1900+}
 1901+
 1902+ULONG WINAPI glDirect3DDevice2::AddRef()
 1903+{
 1904+ if(!this) return 0;
 1905+ refcount++;
 1906+ return refcount;
 1907+}
 1908+
 1909+ULONG WINAPI glDirect3DDevice2::Release()
 1910+{
 1911+ if(!this) return 0;
 1912+ ULONG ret;
 1913+ refcount--;
 1914+ ret = refcount;
 1915+ if(refcount == 0) delete this;
 1916+ return ret;
 1917+}
 1918+
 1919+HRESULT WINAPI glDirect3DDevice2::AddViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
 1920+{
 1921+ if(!this) return DDERR_INVALIDOBJECT;
 1922+ if(!lpDirect3DViewport2) return DDERR_INVALIDPARAMS;
 1923+ glDirect3DViewport3 *glD3DV3;
 1924+ lpDirect3DViewport2->QueryInterface(IID_IDirect3DViewport3,(void**)&glD3DV3);
 1925+ HRESULT ret = glD3DDev7->AddViewport(glD3DV3);
 1926+ glD3DV3->Release();
 1927+ return ret;
 1928+}
 1929+
 1930+DWORD d3dvttofvf(D3DVERTEXTYPE d3dvt)
 1931+{
 1932+ switch(d3dvt)
 1933+ {
 1934+ case D3DVT_VERTEX:
 1935+ return D3DFVF_VERTEX;
 1936+ case D3DVT_LVERTEX:
 1937+ return D3DFVF_LVERTEX;
 1938+ case D3DVT_TLVERTEX:
 1939+ return D3DFVF_TLVERTEX;
 1940+ default:
 1941+ return 0;
 1942+ }
 1943+}
 1944+
 1945+HRESULT WINAPI glDirect3DDevice2::Begin(D3DPRIMITIVETYPE d3dpt, D3DVERTEXTYPE d3dvt, DWORD dwFlags)
 1946+{
 1947+ if(!this) return DDERR_INVALIDOBJECT;
 1948+ DWORD vertextype = d3dvttofvf(d3dvt);
 1949+ if(!vertextype) return DDERR_INVALIDPARAMS;
 1950+ return glD3DDev7->Begin(d3dpt,vertextype,dwFlags);
 1951+}
 1952+
 1953+HRESULT WINAPI glDirect3DDevice2::BeginIndexed(D3DPRIMITIVETYPE dptPrimitiveType, D3DVERTEXTYPE dvtVertexType, LPVOID lpvVertices, DWORD dwNumVertices, DWORD dwFlags)
 1954+{
 1955+ if(!this) return DDERR_INVALIDOBJECT;
 1956+ DWORD vertextype = d3dvttofvf(dvtVertexType);
 1957+ if(!vertextype) return DDERR_INVALIDPARAMS;
 1958+ return glD3DDev7->BeginIndexed(dptPrimitiveType,vertextype,lpvVertices,dwNumVertices,dwFlags);
 1959+}
 1960+
 1961+HRESULT WINAPI glDirect3DDevice2::BeginScene()
 1962+{
 1963+ if(!this) return DDERR_INVALIDOBJECT;
 1964+ return glD3DDev7->BeginScene();
 1965+}
 1966+
 1967+HRESULT WINAPI glDirect3DDevice2::DeleteViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
 1968+{
 1969+ if(!this) return DDERR_INVALIDOBJECT;
 1970+ glDirect3DViewport3 *glD3DV3;
 1971+ lpDirect3DViewport2->QueryInterface(IID_IDirect3DViewport3,(void**)&glD3DV3);
 1972+ HRESULT ret = glD3DDev7->DeleteViewport(glD3DV3);
 1973+ glD3DV3->Release();
 1974+ return ret;
 1975+}
 1976+
 1977+HRESULT WINAPI glDirect3DDevice2::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, D3DVERTEXTYPE d3dvtVertexType,
 1978+ LPVOID lpvVertices, DWORD dwVertexCount, LPWORD dwIndices, DWORD dwIndexCount, DWORD dwFlags)
 1979+{
 1980+ if(!this) return DDERR_INVALIDOBJECT;
 1981+ DWORD vertextype = d3dvttofvf(d3dvtVertexType);
 1982+ if(!vertextype) return DDERR_INVALIDPARAMS;
 1983+ return glD3DDev7->DrawIndexedPrimitive(d3dptPrimitiveType,vertextype,lpvVertices,dwVertexCount,dwIndices,dwIndexCount,dwFlags);
 1984+}
 1985+
 1986+HRESULT WINAPI glDirect3DDevice2::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, D3DVERTEXTYPE dvtVertexType, LPVOID lpvVertices,
 1987+ DWORD dwVertexCount, DWORD dwFlags)
 1988+{
 1989+ if(!this) return DDERR_INVALIDOBJECT;
 1990+ DWORD vertextype = d3dvttofvf(dvtVertexType);
 1991+ if(!vertextype) return DDERR_INVALIDPARAMS;
 1992+ return glD3DDev7->DrawPrimitive(dptPrimitiveType,vertextype,lpvVertices,dwVertexCount,dwFlags);
 1993+}
 1994+
 1995+HRESULT WINAPI glDirect3DDevice2::End(DWORD dwFlags)
 1996+{
 1997+ if(!this) return DDERR_INVALIDOBJECT;
 1998+ return glD3DDev7->End(dwFlags);
 1999+}
 2000+
 2001+HRESULT WINAPI glDirect3DDevice2::EndScene()
 2002+{
 2003+ if(!this) return DDERR_INVALIDOBJECT;
 2004+ return glD3DDev7->EndScene();
 2005+}
 2006+
 2007+HRESULT WINAPI EnumTex2(LPDDPIXELFORMAT ddpf, LPVOID lpUserArg)
 2008+{
 2009+ int *args = (int*)lpUserArg;
 2010+ LPD3DENUMTEXTUREFORMATSCALLBACK callback = (LPD3DENUMTEXTUREFORMATSCALLBACK)args[0];
 2011+ DDSURFACEDESC ddsd;
 2012+ ZeroMemory(&ddsd,sizeof(DDSURFACEDESC));
 2013+ ddsd.dwSize = sizeof(DDSURFACEDESC);
 2014+ ddsd.dwFlags = DDSD_CAPS|DDSD_PIXELFORMAT;
 2015+ ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 2016+ ddsd.ddpfPixelFormat = *ddpf;
 2017+ HRESULT ret = callback(&ddsd,(LPVOID)args[1]);
 2018+ return ret;
 2019+}
 2020+
 2021+HRESULT WINAPI glDirect3DDevice2::EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg)
 2022+{
 2023+ if(!this) return DDERR_INVALIDOBJECT;
 2024+ LPVOID context[2];
 2025+ context[0] = (LPVOID)lpd3dEnumTextureProc;
 2026+ context[1] = lpArg;
 2027+ return glD3DDev7->EnumTextureFormats(EnumTex2,&context);
 2028+}
 2029+
 2030+HRESULT WINAPI glDirect3DDevice2::GetCaps(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc)
 2031+{
 2032+ if(!this) return DDERR_INVALIDOBJECT;
 2033+ return glD3DDev7->GetCaps3(lpD3DHWDevDesc,lpD3DHELDevDesc);
 2034+}
 2035+
 2036+HRESULT WINAPI glDirect3DDevice2::GetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus)
 2037+{
 2038+ if(!this) return DDERR_INVALIDOBJECT;
 2039+ return glD3DDev7->GetClipStatus(lpD3DClipStatus);
 2040+}
 2041+
 2042+HRESULT WINAPI glDirect3DDevice2::GetCurrentViewport(LPDIRECT3DVIEWPORT2 *lplpd3dViewport2)
 2043+{
 2044+ if(!this) return DDERR_INVALIDOBJECT;
 2045+ glDirect3DViewport3 *glD3DV3;
 2046+ HRESULT ret = glD3DDev7->GetCurrentViewport((LPDIRECT3DVIEWPORT3*)&glD3DV3);
 2047+ if(!glD3DV3) return ret;
 2048+ glD3DV3->QueryInterface(IID_IDirect3DViewport2,(void**)lplpd3dViewport2);
 2049+ glD3DV3->Release();
 2050+ return ret;
 2051+}
 2052+
 2053+HRESULT WINAPI glDirect3DDevice2::GetDirect3D(LPDIRECT3D2 *lplpD3D2)
 2054+{
 2055+ if(!this) return DDERR_INVALIDOBJECT;
 2056+ LPDIRECT3D7 d3d7;
 2057+ HRESULT err = glD3DDev7->GetDirect3D(&d3d7);
 2058+ if(!d3d7) return err;
 2059+ d3d7->QueryInterface(IID_IDirect3D2,(void**)lplpD3D2);
 2060+ d3d7->Release();
 2061+ return err;
 2062+}
 2063+
 2064+HRESULT WINAPI glDirect3DDevice2::GetLightState(D3DLIGHTSTATETYPE dwLightStateType, LPDWORD lpdwLightState)
 2065+{
 2066+ if(!this) return DDERR_INVALIDOBJECT;
 2067+ return glD3DDev7->GetLightState(dwLightStateType,lpdwLightState);
 2068+}
 2069+
 2070+HRESULT WINAPI glDirect3DDevice2::GetRenderState(D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState)
 2071+{
 2072+ if(!this) return DDERR_INVALIDOBJECT;
 2073+ return glD3DDev7->GetRenderState(dwRenderStateType,lpdwRenderState);
 2074+}
 2075+
 2076+HRESULT WINAPI glDirect3DDevice2::GetRenderTarget(LPDIRECTDRAWSURFACE *lplpRenderTarget)
 2077+{
 2078+ if(!this) return DDERR_INVALIDOBJECT;
 2079+ LPDIRECTDRAWSURFACE7 dds7;
 2080+ HRESULT err = glD3DDev7->GetRenderTarget(&dds7);
 2081+ if(!dds7) return err;
 2082+ dds7->QueryInterface(IID_IDirectDrawSurface,(void**)lplpRenderTarget);
 2083+ dds7->Release();
 2084+ return err;
 2085+}
 2086+
 2087+HRESULT WINAPI glDirect3DDevice2::GetStats(LPD3DSTATS lpD3DStats)
 2088+{
 2089+ if(!this) return DDERR_INVALIDOBJECT;
 2090+ return glD3DDev7->GetStats(lpD3DStats);
 2091+}
 2092+
 2093+HRESULT WINAPI glDirect3DDevice2::GetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
 2094+{
 2095+ if(!this) return DDERR_INVALIDOBJECT;
 2096+ return glD3DDev7->GetTransform(dtstTransformStateType,lpD3DMatrix);
 2097+}
 2098+
 2099+HRESULT WINAPI glDirect3DDevice2::Index(WORD wVertexIndex)
 2100+{
 2101+ if(!this) return DDERR_INVALIDOBJECT;
 2102+ return glD3DDev7->Index(wVertexIndex);
 2103+}
 2104+
 2105+HRESULT WINAPI glDirect3DDevice2::MultiplyTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
 2106+{
 2107+ if(!this) return DDERR_INVALIDOBJECT;
 2108+ return glD3DDev7->MultiplyTransform(dtstTransformStateType,lpD3DMatrix);
 2109+}
 2110+
 2111+HRESULT WINAPI glDirect3DDevice2::NextViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2, LPDIRECT3DVIEWPORT2 *lplpDirect3DViewport2, DWORD dwFlags)
 2112+{
 2113+ if(!this) return DDERR_INVALIDOBJECT;
 2114+ if(!lpDirect3DViewport2) return DDERR_INVALIDPARAMS;
 2115+ if(!lplpDirect3DViewport2) return DDERR_INVALIDPARAMS;
 2116+ FIXME("glDirect3DDevice2::NextViewport: stub");
 2117+ ERR(DDERR_GENERIC);
 2118+}
 2119+
 2120+HRESULT WINAPI glDirect3DDevice2::SetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus)
 2121+{
 2122+ if(!this) return DDERR_INVALIDOBJECT;
 2123+ return glD3DDev7->SetClipStatus(lpD3DClipStatus);
 2124+}
 2125+
 2126+HRESULT WINAPI glDirect3DDevice2::SetCurrentViewport(LPDIRECT3DVIEWPORT2 lpd3dViewport2)
 2127+{
 2128+ if(!this) return DDERR_INVALIDOBJECT;
 2129+ if(!lpd3dViewport2) return glD3DDev7->SetCurrentViewport(NULL);
 2130+ glDirect3DViewport3 *glD3DV3;
 2131+ lpd3dViewport2->QueryInterface(IID_IDirect3DViewport3,(void**)&glD3DV3);
 2132+ HRESULT ret = glD3DDev7->SetCurrentViewport(glD3DV3);
 2133+ glD3DV3->Release();
 2134+ return ret;
 2135+}
 2136+
 2137+HRESULT WINAPI glDirect3DDevice2::SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState)
 2138+{
 2139+ if(!this) return DDERR_INVALIDOBJECT;
 2140+ return glD3DDev7->SetLightState(dwLightStateType,dwLightState);
 2141+}
 2142+
 2143+HRESULT WINAPI glDirect3DDevice2::SetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState)
 2144+{
 2145+ if(!this) return DDERR_INVALIDOBJECT;
 2146+ return glD3DDev7->SetRenderState(dwRenderStateType,dwRenderState);
 2147+}
 2148+
 2149+HRESULT WINAPI glDirect3DDevice2::SetRenderTarget(LPDIRECTDRAWSURFACE lpNewRenderTarget, DWORD dwFlags)
 2150+{
 2151+ if(!this) return DDERR_INVALIDOBJECT;
 2152+ return glD3DDev7->SetRenderTarget(((glDirectDrawSurface1*)lpNewRenderTarget)->GetDDS7(),dwFlags);
 2153+}
 2154+
 2155+HRESULT WINAPI glDirect3DDevice2::SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
 2156+{
 2157+ if(!this) return DDERR_INVALIDOBJECT;
 2158+ return glD3DDev7->SetTransform(dtstTransformStateType,lpD3DMatrix);
 2159+}
 2160+
 2161+HRESULT WINAPI glDirect3DDevice2::SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2)
 2162+{
 2163+ if(!this) return DDERR_INVALIDOBJECT;
 2164+ return glD3DDev7->SwapTextureHandles(lpD3DTex1,lpD3DTex2);
 2165+}
 2166+
 2167+HRESULT WINAPI glDirect3DDevice2::Vertex(LPVOID lpVertexType)
 2168+{
 2169+ if(!this) return DDERR_INVALIDOBJECT;
 2170+ return glD3DDev7->Vertex(lpVertexType);
 2171+}
Index: ddraw/glDirect3DDevice.h
@@ -58,6 +58,8 @@
5959 class glDirectDrawSurface7;
6060 class glDirect3DMaterial3;
6161 class glDirect3DViewport3;
 62+class glDirect3DDevice3;
 63+class glDirect3DDevice2;
6264 class glDirect3DDevice7 : public IDirect3DDevice7
6365 {
6466 public:
@@ -125,6 +127,7 @@
126128 void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
127129 void SetDepthComp();
128130 D3DMATERIALHANDLE AddMaterial(glDirect3DMaterial3* material);
 131+ D3DTEXTUREHANDLE AddTexture(glDirectDrawSurface7* texture);
129132 HRESULT AddViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport);
130133 HRESULT DeleteViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport);
131134 HRESULT NextViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport, LPDIRECT3DVIEWPORT3 *lplpAnotherViewport, DWORD dwFlags);
@@ -140,6 +143,7 @@
141144 HRESULT GetLightState(D3DLIGHTSTATETYPE dwLightStateType, LPDWORD lpdwLightState);
142145 HRESULT SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState);
143146 HRESULT GetStats(LPD3DSTATS lpD3DStats);
 147+ HRESULT SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2);
144148 __int64 SelectShader(GLVERTEX *VertexType);
145149 GLfloat matWorld[16];
146150 GLfloat matView[16];
@@ -155,8 +159,12 @@
156160 glDirect3DMaterial3 **materials;
157161 glDirect3DMaterial3 *currentmaterial;
158162 int materialcount;
 163+ glDirectDrawSurface7 **textures;
 164+ int texturecount;
159165 bool modelview_dirty;
160166 bool projection_dirty;
 167+ glDirect3DDevice3 *glD3DDev3;
 168+ glDirect3DDevice2 *glD3DDev2;
161169 private:
162170 HRESULT fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr);
163171 ULONG refcount;
@@ -175,6 +183,7 @@
176184 GLVERTEX vertdata[18];
177185 int texformats[8];
178186 int maxmaterials;
 187+ int maxtextures;
179188 glDirect3DViewport3 **viewports;
180189 glDirect3DViewport3 *currentviewport;
181190 int viewportcount;
@@ -240,4 +249,50 @@
241250 private:
242251 glDirect3DDevice7 *glD3DDev7;
243252 ULONG refcount;
 253+};
 254+
 255+
 256+class glDirect3DDevice2 : public IDirect3DDevice2
 257+{
 258+public:
 259+ glDirect3DDevice2(glDirect3DDevice7 *glD3DDev7);
 260+ virtual ~glDirect3DDevice2();
 261+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 262+ ULONG WINAPI AddRef();
 263+ ULONG WINAPI Release();
 264+ HRESULT WINAPI AddViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2);
 265+ HRESULT WINAPI Begin(D3DPRIMITIVETYPE d3dpt, D3DVERTEXTYPE d3dvt, DWORD dwFlags);
 266+ HRESULT WINAPI BeginIndexed(D3DPRIMITIVETYPE dptPrimitiveType, D3DVERTEXTYPE dvtVertexType, LPVOID lpvVertices, DWORD dwNumVertices, DWORD dwFlags);
 267+ HRESULT WINAPI BeginScene();
 268+ HRESULT WINAPI DeleteViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2);
 269+ HRESULT WINAPI DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, D3DVERTEXTYPE d3dvtVertexType,
 270+ LPVOID lpvVertices, DWORD dwVertexCount, LPWORD dwIndices, DWORD dwIndexCount, DWORD dwFlags);
 271+ HRESULT WINAPI DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, D3DVERTEXTYPE dvtVertexType, LPVOID lpvVertices,
 272+ DWORD dwVertexCount, DWORD dwFlags);
 273+ HRESULT WINAPI End(DWORD dwFlags);
 274+ HRESULT WINAPI EndScene();
 275+ HRESULT WINAPI EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg);
 276+ HRESULT WINAPI GetCaps(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc);
 277+ HRESULT WINAPI GetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus);
 278+ HRESULT WINAPI GetCurrentViewport(LPDIRECT3DVIEWPORT2 *lplpd3dViewport2);
 279+ HRESULT WINAPI GetDirect3D(LPDIRECT3D2 *lplpD3D2);
 280+ HRESULT WINAPI GetLightState(D3DLIGHTSTATETYPE dwLightStateType, LPDWORD lpdwLightState);
 281+ HRESULT WINAPI GetRenderState(D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState);
 282+ HRESULT WINAPI GetRenderTarget(LPDIRECTDRAWSURFACE *lplpRenderTarget);
 283+ HRESULT WINAPI GetStats(LPD3DSTATS lpD3DStats);
 284+ HRESULT WINAPI GetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
 285+ HRESULT WINAPI Index(WORD wVertexIndex);
 286+ HRESULT WINAPI MultiplyTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
 287+ HRESULT WINAPI NextViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2, LPDIRECT3DVIEWPORT2 *lplpDirect3DViewport2, DWORD dwFlags);
 288+ HRESULT WINAPI SetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus);
 289+ HRESULT WINAPI SetCurrentViewport(LPDIRECT3DVIEWPORT2 lpd3dViewport2);
 290+ HRESULT WINAPI SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState);
 291+ HRESULT WINAPI SetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState);
 292+ HRESULT WINAPI SetRenderTarget(LPDIRECTDRAWSURFACE lpNewRenderTarget, DWORD dwFlags);
 293+ HRESULT WINAPI SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
 294+ HRESULT WINAPI SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2);
 295+ HRESULT WINAPI Vertex(LPVOID lpVertexType);
 296+private:
 297+ glDirect3DDevice7 *glD3DDev7;
 298+ ULONG refcount;
244299 };
\ No newline at end of file
Index: ddraw/glDirect3DMaterial.cpp
@@ -34,6 +34,7 @@
3535 material.hTexture = 0;
3636 material.dwRampSize = 0;
3737 handle = 0;
 38+ glD3DM2 = NULL;
3839 }
3940
4041 glDirect3DMaterial3::~glDirect3DMaterial3()
@@ -43,7 +44,7 @@
4445
4546 HRESULT WINAPI glDirect3DMaterial3::QueryInterface(REFIID riid, void** ppvObj)
4647 {
47 - if(!this) return DDERR_INVALIDPARAMS;
 48+ if(!this) return DDERR_INVALIDOBJECT;
4849 if(riid == IID_IUnknown)
4950 {
5051 this->AddRef();
@@ -50,6 +51,28 @@
5152 *ppvObj = this;
5253 return DD_OK;
5354 }
 55+ if(riid == IID_IDirect3DMaterial3)
 56+ {
 57+ this->AddRef();
 58+ *ppvObj = this;
 59+ return DD_OK;
 60+ }
 61+ if(riid == IID_IDirect3DMaterial2)
 62+ {
 63+ if(glD3DM2)
 64+ {
 65+ *ppvObj = glD3DM2;
 66+ glD3DM2->AddRef();
 67+ return D3D_OK;
 68+ }
 69+ else
 70+ {
 71+ this->AddRef();
 72+ *ppvObj = new glDirect3DMaterial2(this);
 73+ glD3DM2 = (glDirect3DMaterial2*)*ppvObj;
 74+ return D3D_OK;
 75+ }
 76+ }
5477 return E_NOINTERFACE;
5578 }
5679
@@ -73,7 +96,7 @@
7497 HRESULT WINAPI glDirect3DMaterial3::GetHandle(LPDIRECT3DDEVICE3 lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle)
7598 {
7699 if(!this) return DDERR_INVALIDOBJECT;
77 - if(!lpDirect3DDevice) return DDERR_INVALIDOBJECT;
 100+ if(!lpDirect3DDevice) return DDERR_INVALIDPARAMS;
78101 glDirect3DDevice3 *dev3 = (glDirect3DDevice3*)lpDirect3DDevice;
79102 if(handle)
80103 {
@@ -127,4 +150,68 @@
128151 mat7.emissive = material.emissive;
129152 mat7.power = material.power;
130153 device->SetMaterial(&mat7);
131 -}
\ No newline at end of file
 154+}
 155+
 156+glDirect3DMaterial2::glDirect3DMaterial2(glDirect3DMaterial3 *glD3DM3)
 157+{
 158+ refcount = 1;
 159+ this->glD3DM3 = glD3DM3;
 160+}
 161+
 162+glDirect3DMaterial2::~glDirect3DMaterial2()
 163+{
 164+ glD3DM3->glD3DM2 = NULL;
 165+ glD3DM3->Release();
 166+}
 167+
 168+ULONG WINAPI glDirect3DMaterial2::AddRef()
 169+{
 170+ if(!this) return 0;
 171+ refcount++;
 172+ return refcount;
 173+}
 174+
 175+ULONG WINAPI glDirect3DMaterial2::Release()
 176+{
 177+ if(!this) return 0;
 178+ ULONG ret;
 179+ refcount--;
 180+ ret = refcount;
 181+ if(refcount == 0) delete this;
 182+ return ret;
 183+}
 184+
 185+HRESULT WINAPI glDirect3DMaterial2::QueryInterface(REFIID riid, void** ppvObj)
 186+{
 187+ if(!this) return DDERR_INVALIDOBJECT;
 188+ if(riid == IID_IUnknown)
 189+ {
 190+ this->AddRef();
 191+ *ppvObj = this;
 192+ return D3D_OK;
 193+ }
 194+ return glD3DM3->QueryInterface(riid,ppvObj);
 195+}
 196+
 197+HRESULT WINAPI glDirect3DMaterial2::GetHandle(LPDIRECT3DDEVICE2 lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle)
 198+{
 199+ if(!this) return DDERR_INVALIDOBJECT;
 200+ if(!lpDirect3DDevice) return DDERR_INVALIDPARAMS;
 201+ glDirect3DDevice2 *glD3DDev2 = (glDirect3DDevice2*)lpDirect3DDevice;
 202+ glDirect3DDevice3 *glD3DDev3;
 203+ glD3DDev2->QueryInterface(IID_IDirect3DDevice3,(void**)&glD3DDev3);
 204+ HRESULT ret = glD3DM3->GetHandle(glD3DDev3,lpHandle);
 205+ glD3DDev3->Release();
 206+ return ret;
 207+}
 208+
 209+HRESULT WINAPI glDirect3DMaterial2::GetMaterial(LPD3DMATERIAL lpMat)
 210+{
 211+ if(!this) return DDERR_INVALIDOBJECT;
 212+ return glD3DM3->GetMaterial(lpMat);
 213+}
 214+HRESULT WINAPI glDirect3DMaterial2::SetMaterial(LPD3DMATERIAL lpMat)
 215+{
 216+ if(!this) return DDERR_INVALIDOBJECT;
 217+ return glD3DM3->SetMaterial(lpMat);
 218+}
Index: ddraw/glDirect3DMaterial.h
@@ -19,6 +19,7 @@
2020 #ifndef __GLDIRECT3DMATERIAL_H
2121 #define __GLDIRECT3DMATERIAL_H
2222
 23+class glDirect3DMaterial2;
2324 class glDirect3DMaterial3 : public IDirect3DMaterial3
2425 {
2526 public:
@@ -35,6 +36,7 @@
3637 void unbind();
3738 D3DMATERIAL material;
3839 D3DMATERIALHANDLE handle;
 40+ glDirect3DMaterial2 *glD3DM2;
3941 private:
4042 ULONG refcount;
4143 bool current;
@@ -41,4 +43,20 @@
4244 glDirect3DDevice7 *device;
4345 };
4446
 47+class glDirect3DMaterial2 : public IDirect3DMaterial2
 48+{
 49+public:
 50+ glDirect3DMaterial2(glDirect3DMaterial3 *glD3DM3);
 51+ virtual ~glDirect3DMaterial2();
 52+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 53+ ULONG WINAPI AddRef();
 54+ ULONG WINAPI Release();
 55+ HRESULT WINAPI GetHandle(LPDIRECT3DDEVICE2 lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle);
 56+ HRESULT WINAPI GetMaterial(LPD3DMATERIAL lpMat);
 57+ HRESULT WINAPI SetMaterial(LPD3DMATERIAL lpMat);
 58+private:
 59+ ULONG refcount;
 60+ glDirect3DMaterial3 *glD3DM3;
 61+};
 62+
4563 #endif //__GLDIRECT3DMATERIAL_H
\ No newline at end of file
Index: ddraw/glDirect3DTexture.cpp
@@ -21,6 +21,7 @@
2222 #include "glDirectDraw.h"
2323 #include "glDirectDrawSurface.h"
2424 #include "glDirect3DTexture.h"
 25+#include "glDirect3DDevice.h"
2526
2627 glDirect3DTexture2::glDirect3DTexture2(glDirectDrawSurface7 *glDDS7)
2728 {
@@ -65,6 +66,12 @@
6667 HRESULT WINAPI glDirect3DTexture2::GetHandle(LPDIRECT3DDEVICE2 lpDirect3DDevice2, LPD3DTEXTUREHANDLE lpHandle)
6768 {
6869 if(!this) return DDERR_INVALIDOBJECT;
 70+ if(!lpDirect3DDevice2) return DDERR_INVALIDPARAMS;
 71+ glDirect3DDevice7 *glD3DDev7;
 72+ lpDirect3DDevice2->QueryInterface(IID_IDirect3DDevice7,(void**)&glD3DDev7);
 73+ HRESULT ret = glDDS7->GetHandle(glD3DDev7,lpHandle);
 74+ glD3DDev7->Release();
 75+ return ret;
6976 FIXME("glDirect3DTexture2::GetHandle: stub");
7077 return DDERR_GENERIC;
7178 }
Index: ddraw/glDirect3DViewport.cpp
@@ -46,6 +46,7 @@
4747 lights[i] = NULL;
4848 refcount = 1;
4949 current = false;
 50+ glD3DV2 = NULL;
5051 }
5152
5253 glDirect3DViewport3::~glDirect3DViewport3()
@@ -54,13 +55,35 @@
5556
5657 HRESULT WINAPI glDirect3DViewport3::QueryInterface(REFIID riid, void** ppvObj)
5758 {
58 - if(!this) return DDERR_INVALIDPARAMS;
 59+ if(!this) return DDERR_INVALIDOBJECT;
5960 if(riid == IID_IUnknown)
6061 {
6162 this->AddRef();
6263 *ppvObj = this;
63 - return DD_OK;
 64+ return D3D_OK;
6465 }
 66+ if(riid == IID_IDirect3DViewport3)
 67+ {
 68+ this->AddRef();
 69+ *ppvObj = this;
 70+ return D3D_OK;
 71+ }
 72+ if(riid == IID_IDirect3DViewport2)
 73+ {
 74+ if(glD3DV2)
 75+ {
 76+ *ppvObj = glD3DV2;
 77+ glD3DV2->AddRef();
 78+ return D3D_OK;
 79+ }
 80+ else
 81+ {
 82+ this->AddRef();
 83+ *ppvObj = new glDirect3DViewport2(this);
 84+ glD3DV2 = (glDirect3DViewport2*)*ppvObj;
 85+ return D3D_OK;
 86+ }
 87+ }
6588 return E_NOINTERFACE;
6689 }
6790
@@ -304,4 +327,122 @@
305328 }
306329 else device->LightEnable(i,FALSE);
307330 }
308 -}
\ No newline at end of file
 331+}
 332+
 333+
 334+glDirect3DViewport2::glDirect3DViewport2(glDirect3DViewport3 *glD3DV3)
 335+{
 336+ this->glD3DV3 = glD3DV3;
 337+ refcount = 1;
 338+}
 339+
 340+glDirect3DViewport2::~glDirect3DViewport2()
 341+{
 342+ glD3DV3->glD3DV2 = NULL;
 343+ glD3DV3->Release();
 344+}
 345+
 346+ULONG WINAPI glDirect3DViewport2::AddRef()
 347+{
 348+ if(!this) return 0;
 349+ refcount++;
 350+ return refcount;
 351+}
 352+
 353+ULONG WINAPI glDirect3DViewport2::Release()
 354+{
 355+ if(!this) return 0;
 356+ ULONG ret;
 357+ refcount--;
 358+ ret = refcount;
 359+ if(refcount == 0) delete this;
 360+ return ret;
 361+}
 362+
 363+HRESULT WINAPI glDirect3DViewport2::QueryInterface(REFIID riid, void** ppvObj)
 364+{
 365+ if(!this) return DDERR_INVALIDOBJECT;
 366+ if(riid == IID_IUnknown)
 367+ {
 368+ this->AddRef();
 369+ *ppvObj = this;
 370+ return D3D_OK;
 371+ }
 372+ return glD3DV3->QueryInterface(riid,ppvObj);
 373+}
 374+
 375+HRESULT WINAPI glDirect3DViewport2::AddLight(LPDIRECT3DLIGHT lpLight)
 376+{
 377+ if(!this) return DDERR_INVALIDOBJECT;
 378+ return glD3DV3->AddLight(lpLight);
 379+}
 380+HRESULT WINAPI glDirect3DViewport2::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags)
 381+{
 382+ if(!this) return DDERR_INVALIDOBJECT;
 383+ return glD3DV3->Clear(dwCount,lpRects,dwFlags);
 384+}
 385+HRESULT WINAPI glDirect3DViewport2::DeleteLight(LPDIRECT3DLIGHT lpDirect3DLight)
 386+{
 387+ if(!this) return DDERR_INVALIDOBJECT;
 388+ return glD3DV3->DeleteLight(lpDirect3DLight);
 389+}
 390+HRESULT WINAPI glDirect3DViewport2::GetBackground(LPD3DMATERIALHANDLE lphMat, LPBOOL lpValid)
 391+{
 392+ if(!this) return DDERR_INVALIDOBJECT;
 393+ return glD3DV3->GetBackground(lphMat,lpValid);
 394+}
 395+HRESULT WINAPI glDirect3DViewport2::GetBackgroundDepth(LPDIRECTDRAWSURFACE* lplpDDSurface, LPBOOL lpValid)
 396+{
 397+ if(!this) return DDERR_INVALIDOBJECT;
 398+ return glD3DV3->GetBackgroundDepth(lplpDDSurface,lpValid);
 399+}
 400+HRESULT WINAPI glDirect3DViewport2::GetViewport(LPD3DVIEWPORT lpData)
 401+{
 402+ if(!this) return DDERR_INVALIDOBJECT;
 403+ return glD3DV3->GetViewport(lpData);
 404+}
 405+HRESULT WINAPI glDirect3DViewport2::GetViewport2(LPD3DVIEWPORT2 lpData)
 406+{
 407+ if(!this) return DDERR_INVALIDOBJECT;
 408+ return glD3DV3->GetViewport2(lpData);
 409+}
 410+HRESULT WINAPI glDirect3DViewport2::Initialize(LPDIRECT3D lpDirect3D)
 411+{
 412+ if(!this) return DDERR_INVALIDOBJECT;
 413+ return glD3DV3->Initialize(lpDirect3D);
 414+}
 415+HRESULT WINAPI glDirect3DViewport2::LightElements(DWORD dwElementCount, LPD3DLIGHTDATA lpData)
 416+{
 417+ if(!this) return DDERR_INVALIDOBJECT;
 418+ return glD3DV3->LightElements(dwElementCount,lpData);
 419+}
 420+HRESULT WINAPI glDirect3DViewport2::NextLight(LPDIRECT3DLIGHT lpDirect3DLight, LPDIRECT3DLIGHT* lplpDirect3DLight, DWORD dwFlags)
 421+{
 422+ if(!this) return DDERR_INVALIDOBJECT;
 423+ return glD3DV3->NextLight(lpDirect3DLight,lplpDirect3DLight,dwFlags);
 424+}
 425+HRESULT WINAPI glDirect3DViewport2::SetBackground(D3DMATERIALHANDLE hMat)
 426+{
 427+ if(!this) return DDERR_INVALIDOBJECT;
 428+ return glD3DV3->SetBackground(hMat);
 429+}
 430+HRESULT WINAPI glDirect3DViewport2::SetBackgroundDepth(LPDIRECTDRAWSURFACE lpDDSurface)
 431+{
 432+ if(!this) return DDERR_INVALIDOBJECT;
 433+ return glD3DV3->SetBackgroundDepth(lpDDSurface);
 434+}
 435+HRESULT WINAPI glDirect3DViewport2::SetViewport(LPD3DVIEWPORT lpData)
 436+{
 437+ if(!this) return DDERR_INVALIDOBJECT;
 438+ return glD3DV3->SetViewport(lpData);
 439+}
 440+HRESULT WINAPI glDirect3DViewport2::SetViewport2(LPD3DVIEWPORT2 lpData)
 441+{
 442+ if(!this) return DDERR_INVALIDOBJECT;
 443+ return glD3DV3->SetViewport2(lpData);
 444+}
 445+HRESULT WINAPI glDirect3DViewport2::TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen)
 446+{
 447+ if(!this) return DDERR_INVALIDOBJECT;
 448+ return glD3DV3->TransformVertices(dwVertexCount,lpData,dwFlags,lpOffscreen);
 449+}
Index: ddraw/glDirect3DViewport.h
@@ -22,6 +22,7 @@
2323 class glDirect3DLight;
2424 class glDirect3DDevice7;
2525 class glDirectDrawSurface7;
 26+class glDirect3DViewport2;
2627 class glDirect3DViewport3 : public IDirect3DViewport3
2728 {
2829 public:
@@ -52,6 +53,7 @@
5354 void SetDevice(glDirect3DDevice7 *device){this->device = device;};
5455 void Sync();
5556 void SyncLights();
 57+ glDirect3DViewport2 *glD3DV2;
5658 private:
5759 ULONG refcount;
5860 glDirect3DLight *lights[8];
@@ -66,4 +68,32 @@
6769 bool current;
6870 };
6971
 72+class glDirect3DViewport2 : public IDirect3DViewport2
 73+{
 74+public:
 75+ glDirect3DViewport2(glDirect3DViewport3 *glD3DV3);
 76+ virtual ~glDirect3DViewport2();
 77+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 78+ ULONG WINAPI AddRef();
 79+ ULONG WINAPI Release();
 80+ HRESULT WINAPI AddLight(LPDIRECT3DLIGHT lpLight);
 81+ HRESULT WINAPI Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags);
 82+ HRESULT WINAPI DeleteLight(LPDIRECT3DLIGHT lpDirect3DLight);
 83+ HRESULT WINAPI GetBackground(LPD3DMATERIALHANDLE lphMat, LPBOOL lpValid);
 84+ HRESULT WINAPI GetBackgroundDepth(LPDIRECTDRAWSURFACE* lplpDDSurface, LPBOOL lpValid);
 85+ HRESULT WINAPI GetViewport(LPD3DVIEWPORT lpData);
 86+ HRESULT WINAPI GetViewport2(LPD3DVIEWPORT2 lpData);
 87+ HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
 88+ HRESULT WINAPI LightElements(DWORD dwElementCount, LPD3DLIGHTDATA lpData);
 89+ HRESULT WINAPI NextLight(LPDIRECT3DLIGHT lpDirect3DLight, LPDIRECT3DLIGHT* lplpDirect3DLight, DWORD dwFlags);
 90+ HRESULT WINAPI SetBackground(D3DMATERIALHANDLE hMat);
 91+ HRESULT WINAPI SetBackgroundDepth(LPDIRECTDRAWSURFACE lpDDSurface);
 92+ HRESULT WINAPI SetViewport(LPD3DVIEWPORT lpData);
 93+ HRESULT WINAPI SetViewport2(LPD3DVIEWPORT2 lpData);
 94+ HRESULT WINAPI TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen);
 95+private:
 96+ glDirect3DViewport3 *glD3DV3;
 97+ int refcount;
 98+};
 99+
70100 #endif //__GLDIRECT3DVIEWPORT_H
\ No newline at end of file
Index: ddraw/glDirectDraw.cpp
@@ -644,8 +644,10 @@
645645 }
646646 if(riid == IID_IDirect3D2)
647647 {
648 - FIXME("Add IDirect3D Interfaces\n");
649 - ERR(DDERR_GENERIC);
 648+ glDirect3D7 *tmp = new glDirect3D7(this);
 649+ tmp->QueryInterface(IID_IDirect3D2,ppvObj);
 650+ tmp->Release();
 651+ return DD_OK;
650652 }
651653 if(riid == IID_IDirect3D3)
652654 {
Index: ddraw/glDirectDrawSurface.cpp
@@ -40,6 +40,8 @@
4141 {
4242 hasstencil = false;
4343 dirty = 2;
 44+ handle = 0;
 45+ device = NULL;
4446 locked = 0;
4547 pagelocked = 0;
4648 flipcount = 0;
@@ -326,6 +328,7 @@
327329 if(buffer) free(buffer);
328330 if(bigbuffer) free(bigbuffer);
329331 if(zbuffer) zbuffer->Release();
 332+ if(device) device->Release();
330333 ddInterface->DeleteSurface(this);
331334 }
332335 HRESULT WINAPI glDirectDrawSurface7::QueryInterface(REFIID riid, void** ppvObj)
@@ -1144,6 +1147,22 @@
11451148 }
11461149 }
11471150
 1151+HRESULT glDirectDrawSurface7::GetHandle(glDirect3DDevice7 *glD3DDev7, LPD3DTEXTUREHANDLE lpHandle)
 1152+{
 1153+ if(!this) return DDERR_INVALIDOBJECT;
 1154+ if(!glD3DDev7) return DDERR_INVALIDPARAMS;
 1155+ if(handle)
 1156+ {
 1157+ if(device != glD3DDev7) return DDERR_INVALIDOBJECT;
 1158+ *lpHandle = handle;
 1159+ return D3D_OK;
 1160+ }
 1161+ device = glD3DDev7;
 1162+ handle = device->AddTexture(this);
 1163+ *lpHandle = handle;
 1164+ return D3D_OK;
 1165+}
 1166+
11481167 // DDRAW1 wrapper
11491168 glDirectDrawSurface1::glDirectDrawSurface1(glDirectDrawSurface7 *gl_DDS7)
11501169 {
@@ -1184,7 +1203,7 @@
11851204 HRESULT WINAPI glDirectDrawSurface1::AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSAttachedSurface)
11861205 {
11871206 if(!this) return DDERR_INVALIDPARAMS;
1188 - return glDDS7->AddAttachedSurface((LPDIRECTDRAWSURFACE7)lpDDSAttachedSurface);
 1207+ return glDDS7->AddAttachedSurface(((glDirectDrawSurface1*)lpDDSAttachedSurface)->GetDDS7());
11891208 }
11901209 HRESULT WINAPI glDirectDrawSurface1::AddOverlayDirtyRect(LPRECT lpRect)
11911210 {
@@ -1410,7 +1429,7 @@
14111430 HRESULT WINAPI glDirectDrawSurface2::AddAttachedSurface(LPDIRECTDRAWSURFACE2 lpDDSAttachedSurface)
14121431 {
14131432 if(!this) return DDERR_INVALIDPARAMS;
1414 - return glDDS7->AddAttachedSurface((LPDIRECTDRAWSURFACE7)lpDDSAttachedSurface);
 1433+ return glDDS7->AddAttachedSurface(((glDirectDrawSurface2*)lpDDSAttachedSurface)->GetDDS7());
14151434 }
14161435 HRESULT WINAPI glDirectDrawSurface2::AddOverlayDirtyRect(LPRECT lpRect)
14171436 {
@@ -1650,7 +1669,7 @@
16511670 HRESULT WINAPI glDirectDrawSurface3::AddAttachedSurface(LPDIRECTDRAWSURFACE3 lpDDSAttachedSurface)
16521671 {
16531672 if(!this) return DDERR_INVALIDPARAMS;
1654 - return glDDS7->AddAttachedSurface((LPDIRECTDRAWSURFACE7)lpDDSAttachedSurface);
 1673+ return glDDS7->AddAttachedSurface(((glDirectDrawSurface3*)lpDDSAttachedSurface)->GetDDS7());
16551674 }
16561675 HRESULT WINAPI glDirectDrawSurface3::AddOverlayDirtyRect(LPRECT lpRect)
16571676 {
@@ -1895,7 +1914,7 @@
18961915 HRESULT WINAPI glDirectDrawSurface4::AddAttachedSurface(LPDIRECTDRAWSURFACE4 lpDDSAttachedSurface)
18971916 {
18981917 if(!this) return DDERR_INVALIDPARAMS;
1899 - return glDDS7->AddAttachedSurface((LPDIRECTDRAWSURFACE7)lpDDSAttachedSurface);
 1918+ return glDDS7->AddAttachedSurface(((glDirectDrawSurface4*)lpDDSAttachedSurface)->GetDDS7());
19001919 }
19011920 HRESULT WINAPI glDirectDrawSurface4::AddOverlayDirtyRect(LPRECT lpRect)
19021921 {
Index: ddraw/glDirectDrawSurface.h
@@ -33,6 +33,7 @@
3434 class glDirectDrawSurface3;
3535 class glDirectDrawSurface4;
3636 class glDirect3DTexture2;
 37+class glDirect3DDevice7;
3738 class glDirectDrawSurface7 : public IDirectDrawSurface7
3839 {
3940 public:
@@ -105,6 +106,7 @@
106107 void RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface);
107108 // Special ddraw2->ddraw7 api
108109 HRESULT WINAPI Unlock2(LPVOID lpSurfaceData);
 110+ HRESULT GetHandle(glDirect3DDevice7 *glD3DDev7, LPD3DTEXTUREHANDLE lpHandle);
109111 glDirectDrawSurface1 *dds1;
110112 glDirectDrawSurface2 *dds2;
111113 glDirectDrawSurface3 *dds3;
@@ -127,6 +129,7 @@
128130 glDirectDrawPalette *palette;
129131 HGLRC hRC;
130132 glDirectDrawSurface7 *zbuffer;
 133+ D3DMATERIALHANDLE handle;
131134 private:
132135 ULONG refcount;
133136 int locked;
@@ -139,6 +142,7 @@
140143 glDirectDrawClipper *clipper;
141144 int pagelocked;
142145 GLint magfilter,minfilter;
 146+ glDirect3DDevice7 *device;
143147 };
144148
145149 // Legacy DDRAW Interfaces
Index: ddraw/shadergen.cpp
@@ -567,10 +567,11 @@
568568 GLint srclen = strlen(src);
569569 glShaderSource(genshaders[index].shader.vs,1,&src,&srclen);
570570 glCompileShader(genshaders[index].shader.vs);
571 - GLint loglen,result;
 571+ GLint result;
572572 char *infolog = NULL;
573573 glGetShaderiv(genshaders[index].shader.vs,GL_COMPILE_STATUS,&result);
574574 #ifdef _DEBUG
 575+ GLint loglen;
575576 if(!result)
576577 {
577578 glGetShaderiv(genshaders[index].shader.vs,GL_INFO_LOG_LENGTH,&loglen);