DXGL r321 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r320‎ | r321 | r322 >
Date:19:29, 8 February 2013
Author:admin
Status:new
Tags:
Comment:
Add IDirect3DViewport interface.
Clean up viewport objects on destructor.
Modified paths:
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DViewport.cpp
@@ -47,10 +47,17 @@
4848 refcount = 1;
4949 current = false;
5050 glD3DV2 = NULL;
 51+ glD3DV1 = NULL;
5152 }
5253
5354 glDirect3DViewport3::~glDirect3DViewport3()
5455 {
 56+ if(device) device->Release();
 57+ if(backZ) backZ->Release();
 58+ for(int i = 0; i < 8; i++)
 59+ {
 60+ if(lights[i]) lights[i]->Release();
 61+ }
5562 }
5663
5764 HRESULT WINAPI glDirect3DViewport3::QueryInterface(REFIID riid, void** ppvObj)
@@ -84,6 +91,22 @@
8592 return D3D_OK;
8693 }
8794 }
 95+ if(riid == IID_IDirect3DViewport)
 96+ {
 97+ if(glD3DV1)
 98+ {
 99+ *ppvObj = glD3DV1;
 100+ glD3DV1->AddRef();
 101+ return D3D_OK;
 102+ }
 103+ else
 104+ {
 105+ this->AddRef();
 106+ *ppvObj = new glDirect3DViewport1(this);
 107+ glD3DV1 = (glDirect3DViewport1*)*ppvObj;
 108+ return D3D_OK;
 109+ }
 110+ }
88111 return E_NOINTERFACE;
89112 }
90113
@@ -446,3 +469,111 @@
447470 if(!this) return DDERR_INVALIDOBJECT;
448471 return glD3DV3->TransformVertices(dwVertexCount,lpData,dwFlags,lpOffscreen);
449472 }
 473+
 474+
 475+glDirect3DViewport1::glDirect3DViewport1(glDirect3DViewport3 *glD3DV3)
 476+{
 477+ this->glD3DV3 = glD3DV3;
 478+ refcount = 1;
 479+}
 480+
 481+glDirect3DViewport1::~glDirect3DViewport1()
 482+{
 483+ glD3DV3->glD3DV1 = NULL;
 484+ glD3DV3->Release();
 485+}
 486+
 487+ULONG WINAPI glDirect3DViewport1::AddRef()
 488+{
 489+ if(!this) return 0;
 490+ refcount++;
 491+ return refcount;
 492+}
 493+
 494+ULONG WINAPI glDirect3DViewport1::Release()
 495+{
 496+ if(!this) return 0;
 497+ ULONG ret;
 498+ refcount--;
 499+ ret = refcount;
 500+ if(refcount == 0) delete this;
 501+ return ret;
 502+}
 503+
 504+HRESULT WINAPI glDirect3DViewport1::QueryInterface(REFIID riid, void** ppvObj)
 505+{
 506+ if(!this) return DDERR_INVALIDOBJECT;
 507+ if(riid == IID_IUnknown)
 508+ {
 509+ this->AddRef();
 510+ *ppvObj = this;
 511+ return D3D_OK;
 512+ }
 513+ return glD3DV3->QueryInterface(riid,ppvObj);
 514+}
 515+
 516+HRESULT WINAPI glDirect3DViewport1::AddLight(LPDIRECT3DLIGHT lpLight)
 517+{
 518+ if(!this) return DDERR_INVALIDOBJECT;
 519+ return glD3DV3->AddLight(lpLight);
 520+}
 521+HRESULT WINAPI glDirect3DViewport1::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags)
 522+{
 523+ if(!this) return DDERR_INVALIDOBJECT;
 524+ return glD3DV3->Clear(dwCount,lpRects,dwFlags);
 525+}
 526+HRESULT WINAPI glDirect3DViewport1::DeleteLight(LPDIRECT3DLIGHT lpDirect3DLight)
 527+{
 528+ if(!this) return DDERR_INVALIDOBJECT;
 529+ return glD3DV3->DeleteLight(lpDirect3DLight);
 530+}
 531+HRESULT WINAPI glDirect3DViewport1::GetBackground(LPD3DMATERIALHANDLE lphMat, LPBOOL lpValid)
 532+{
 533+ if(!this) return DDERR_INVALIDOBJECT;
 534+ return glD3DV3->GetBackground(lphMat,lpValid);
 535+}
 536+HRESULT WINAPI glDirect3DViewport1::GetBackgroundDepth(LPDIRECTDRAWSURFACE* lplpDDSurface, LPBOOL lpValid)
 537+{
 538+ if(!this) return DDERR_INVALIDOBJECT;
 539+ return glD3DV3->GetBackgroundDepth(lplpDDSurface,lpValid);
 540+}
 541+HRESULT WINAPI glDirect3DViewport1::GetViewport(LPD3DVIEWPORT lpData)
 542+{
 543+ if(!this) return DDERR_INVALIDOBJECT;
 544+ return glD3DV3->GetViewport(lpData);
 545+}
 546+HRESULT WINAPI glDirect3DViewport1::Initialize(LPDIRECT3D lpDirect3D)
 547+{
 548+ if(!this) return DDERR_INVALIDOBJECT;
 549+ return glD3DV3->Initialize(lpDirect3D);
 550+}
 551+HRESULT WINAPI glDirect3DViewport1::LightElements(DWORD dwElementCount, LPD3DLIGHTDATA lpData)
 552+{
 553+ if(!this) return DDERR_INVALIDOBJECT;
 554+ return glD3DV3->LightElements(dwElementCount,lpData);
 555+}
 556+HRESULT WINAPI glDirect3DViewport1::NextLight(LPDIRECT3DLIGHT lpDirect3DLight, LPDIRECT3DLIGHT* lplpDirect3DLight, DWORD dwFlags)
 557+{
 558+ if(!this) return DDERR_INVALIDOBJECT;
 559+ return glD3DV3->NextLight(lpDirect3DLight,lplpDirect3DLight,dwFlags);
 560+}
 561+HRESULT WINAPI glDirect3DViewport1::SetBackground(D3DMATERIALHANDLE hMat)
 562+{
 563+ if(!this) return DDERR_INVALIDOBJECT;
 564+ return glD3DV3->SetBackground(hMat);
 565+}
 566+HRESULT WINAPI glDirect3DViewport1::SetBackgroundDepth(LPDIRECTDRAWSURFACE lpDDSurface)
 567+{
 568+ if(!this) return DDERR_INVALIDOBJECT;
 569+ return glD3DV3->SetBackgroundDepth(lpDDSurface);
 570+}
 571+HRESULT WINAPI glDirect3DViewport1::SetViewport(LPD3DVIEWPORT lpData)
 572+{
 573+ if(!this) return DDERR_INVALIDOBJECT;
 574+ return glD3DV3->SetViewport(lpData);
 575+}
 576+HRESULT WINAPI glDirect3DViewport1::TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen)
 577+{
 578+ if(!this) return DDERR_INVALIDOBJECT;
 579+ return glD3DV3->TransformVertices(dwVertexCount,lpData,dwFlags,lpOffscreen);
 580+}
Index: ddraw/glDirect3DViewport.h
@@ -22,6 +22,7 @@
2323 class glDirect3DLight;
2424 class glDirect3DDevice7;
2525 class glDirectDrawSurface7;
 26+class glDirect3DViewport1;
2627 class glDirect3DViewport2;
2728 class glDirect3DViewport3 : public IDirect3DViewport3
2829 {
@@ -54,6 +55,7 @@
5556 void Sync();
5657 void SyncLights();
5758 glDirect3DViewport2 *glD3DV2;
 59+ glDirect3DViewport1 *glD3DV1;
5860 private:
5961 ULONG refcount;
6062 glDirect3DLight *lights[8];
@@ -96,4 +98,30 @@
9799 int refcount;
98100 };
99101
 102+class glDirect3DViewport1 : public IDirect3DViewport
 103+{
 104+public:
 105+ glDirect3DViewport1(glDirect3DViewport3 *glD3DV3);
 106+ virtual ~glDirect3DViewport1();
 107+ HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
 108+ ULONG WINAPI AddRef();
 109+ ULONG WINAPI Release();
 110+ HRESULT WINAPI AddLight(LPDIRECT3DLIGHT lpLight);
 111+ HRESULT WINAPI Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags);
 112+ HRESULT WINAPI DeleteLight(LPDIRECT3DLIGHT lpDirect3DLight);
 113+ HRESULT WINAPI GetBackground(LPD3DMATERIALHANDLE lphMat, LPBOOL lpValid);
 114+ HRESULT WINAPI GetBackgroundDepth(LPDIRECTDRAWSURFACE* lplpDDSurface, LPBOOL lpValid);
 115+ HRESULT WINAPI GetViewport(LPD3DVIEWPORT lpData);
 116+ HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
 117+ HRESULT WINAPI LightElements(DWORD dwElementCount, LPD3DLIGHTDATA lpData);
 118+ HRESULT WINAPI NextLight(LPDIRECT3DLIGHT lpDirect3DLight, LPDIRECT3DLIGHT* lplpDirect3DLight, DWORD dwFlags);
 119+ HRESULT WINAPI SetBackground(D3DMATERIALHANDLE hMat);
 120+ HRESULT WINAPI SetBackgroundDepth(LPDIRECTDRAWSURFACE lpDDSurface);
 121+ HRESULT WINAPI SetViewport(LPD3DVIEWPORT lpData);
 122+ HRESULT WINAPI TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen);
 123+private:
 124+ glDirect3DViewport3 *glD3DV3;
 125+ int refcount;
 126+};
 127+
100128 #endif //__GLDIRECT3DVIEWPORT_H
\ No newline at end of file