DXGL r198 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r197‎ | r198 | r199 >
Date:00:02, 5 July 2012
Author:admin
Status:new
Tags:
Comment:
Set lights in viewport (not yet working)
Modified paths:
  • /ddraw/glDirect3DLight.cpp (modified) (history)
  • /ddraw/glDirect3DLight.h (modified) (history)
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DLight.cpp
@@ -16,6 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "glRenderer.h"
 21+#include "glDirect3DDevice.h"
2022 #include "glDirect3DViewport.h"
2123 #include "glDirect3DLight.h"
2224 #define _USE_MATH_DEFINES
@@ -27,6 +29,7 @@
2830 {
2931 refcount=1;
3032 viewport = NULL;
 33+ device = NULL;
3134 ZeroMemory(&light,sizeof(D3DLIGHT7));
3235 light.dltType = D3DLIGHT_DIRECTIONAL;
3336 light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = 1.0f;
@@ -89,12 +92,54 @@
9093 HRESULT WINAPI glDirect3DLight::GetLight(LPD3DLIGHT lpLight)
9194 {
9295 if(!this) return DDERR_INVALIDPARAMS;
93 - FIXME("glDirect3DLight::GetLight: stub");
94 - ERR(DDERR_GENERIC);
 96+ if(!lpLight) return DDERR_INVALIDPARAMS;
 97+ if(lpLight->dwSize < sizeof(D3DLIGHT)) return DDERR_INVALIDPARAMS;
 98+ lpLight->dltType = light.dltType;
 99+ lpLight->dcvColor = light.dcvDiffuse;
 100+ lpLight->dvPosition = light.dvPosition;
 101+ lpLight->dvDirection = light.dvDirection;
 102+ lpLight->dvRange = light.dvRange;
 103+ lpLight->dvFalloff = light.dvFalloff;
 104+ lpLight->dvAttenuation0 = light.dvAttenuation0;
 105+ lpLight->dvAttenuation1 = light.dvAttenuation1;
 106+ lpLight->dvAttenuation2 = light.dvAttenuation2;
 107+ lpLight->dvTheta = light.dvTheta;
 108+ lpLight->dvPhi = light.dvPhi;
 109+ return D3D_OK;
95110 }
96111 HRESULT WINAPI glDirect3DLight::SetLight(LPD3DLIGHT lpLight)
97112 {
98113 if(!this) return DDERR_INVALIDPARAMS;
99 - FIXME("glDirect3DLight::SetLight: stub");
100 - ERR(DDERR_GENERIC);
 114+ if(!lpLight) return DDERR_INVALIDPARAMS;
 115+ if(lpLight->dwSize < sizeof(D3DLIGHT)) return DDERR_INVALIDPARAMS;
 116+ light.dltType = lpLight->dltType;
 117+ light.dcvDiffuse = lpLight->dcvColor;
 118+ light.dvPosition = lpLight->dvPosition;
 119+ light.dvDirection = lpLight->dvDirection;
 120+ light.dvRange = lpLight->dvRange;
 121+ light.dvFalloff = lpLight->dvFalloff;
 122+ light.dvAttenuation0 = lpLight->dvAttenuation0;
 123+ light.dvAttenuation1 = lpLight->dvAttenuation1;
 124+ light.dvAttenuation2 = lpLight->dvAttenuation2;
 125+ light.dvTheta = lpLight->dvTheta;
 126+ light.dvPhi = lpLight->dvPhi;
 127+ bool enablelight = false;
 128+ if(device && (lpLight->dwSize >= sizeof(D3DLIGHT2))) enablelight = true;
 129+ else if(device) enablelight = true;
 130+ if(enablelight)
 131+ {
 132+ if(((LPD3DLIGHT2)lpLight)->dwFlags & D3DLIGHT_ACTIVE)
 133+ {
 134+ device->SetLight(index,&light);
 135+ device->LightEnable(index,TRUE);
 136+ }
 137+ else device->LightEnable(index,FALSE);
 138+ }
 139+ return D3D_OK;
 140+}
 141+
 142+void glDirect3DLight::SetDevice(glDirect3DDevice7 *device, int index)
 143+{
 144+ this->device = device;
 145+ this->index = index;
101146 }
\ No newline at end of file
Index: ddraw/glDirect3DLight.h
@@ -34,11 +34,14 @@
3535 HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
3636 HRESULT WINAPI SetLight(LPD3DLIGHT lpLight);
3737 void SetLight7(LPD3DLIGHT7 lpLight7);
 38+ void SetDevice(glDirect3DDevice7 *device, int index);
3839 D3DLIGHT7 light;
3940 glDirect3DViewport3 *viewport;
4041 private:
4142 ULONG refcount;
4243 D3DLIGHT2 convert;
 44+ glDirect3DDevice7 *device;
 45+ int index;
4346 };
4447
4548 #endif //__GLDIRECT3DLIGHT_H
\ No newline at end of file
Index: ddraw/glDirect3DViewport.cpp
@@ -122,6 +122,7 @@
123123 if(lights[i] == lpDirect3DLight)
124124 {
125125 lights[i]->Release();
 126+ lights[i]->SetDevice(NULL,0);
126127 lights[i] = NULL;
127128 return D3D_OK;
128129 }
@@ -266,7 +267,11 @@
267268 {
268269 if(this->current && current) return;
269270 this->current = current;
270 - if(current && device) Sync();
 271+ if(current && device)
 272+ {
 273+ Sync();
 274+ SyncLights();
 275+ }
271276 }
272277
273278 void glDirect3DViewport3::Sync()
@@ -279,4 +284,20 @@
280285 vp7.dvMinZ = viewport.dvMinZ;
281286 vp7.dvMaxZ = viewport.dvMaxZ;
282287 device->SetViewport(&vp7);
 288+}
 289+
 290+void glDirect3DViewport3::SyncLights()
 291+{
 292+ D3DLIGHT7 light;
 293+ for(int i = 0; i < 8; i++)
 294+ {
 295+ if(lights[i])
 296+ {
 297+ lights[i]->SetDevice(device,i);
 298+ lights[i]->GetLight7(&light);
 299+ device->SetLight(i,&light);
 300+ device->LightEnable(i,TRUE);
 301+ }
 302+ else device->LightEnable(i,FALSE);
 303+ }
283304 }
\ No newline at end of file
Index: ddraw/glDirect3DViewport.h
@@ -51,6 +51,7 @@
5252 void SetCurrent(bool current);
5353 void SetDevice(glDirect3DDevice7 *device){this->device = device;};
5454 void Sync();
 55+ void SyncLights();
5556 private:
5657 ULONG refcount;
5758 glDirect3DLight *lights[8];
Index: ddraw/glDirectDrawSurface.cpp
@@ -53,6 +53,7 @@
5454 dds2 = NULL;
5555 dds3 = NULL;
5656 dds4 = NULL;
 57+ d3dt2 = NULL;
5758 buffer = gdibuffer = NULL;
5859 bigbuffer = NULL;
5960 zbuffer = NULL;