Commit be29e370 authored by Christian Costa's avatar Christian Costa Committed by Alexandre Julliard

Finish moving d3d[1..3] light code to use d3d7.

parent 5c256c51
......@@ -97,22 +97,12 @@ GL_IDirect3DImpl_3_2T_1T_CreateLight(LPDIRECT3D3 iface,
IUnknown* pUnkOuter)
{
ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This->d3d_private;
int fl;
IDirect3DLightImpl *d3dlimpl;
HRESULT ret_value;
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lplpDirect3DLight, pUnkOuter);
for (fl = 0; fl < MAX_LIGHTS; fl++) {
if ((glThis->free_lights & (0x01 << fl)) != 0) {
glThis->free_lights &= ~(0x01 << fl);
break;
}
}
if (fl == MAX_LIGHTS) {
return DDERR_INVALIDPARAMS; /* No way to say 'max lights reached' ... */
}
ret_value = d3dlight_create(&d3dlimpl, This, GL_LIGHT0 + fl);
ret_value = d3dlight_create(&d3dlimpl, This);
*lplpDirect3DLight = ICOM_INTERFACE(d3dlimpl, IDirect3DLight);
return ret_value;
......@@ -306,12 +296,6 @@ GL_IDirect3DImpl_7_3T_CreateVertexBuffer(LPDIRECT3D7 iface,
return res;
}
static void light_released(IDirectDrawImpl *This, GLenum light_num)
{
IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This->d3d_private;
glThis->free_lights |= (light_num - GL_LIGHT0);
}
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
# define XCAST(fun) (typeof(VTABLE_IDirect3D7.fun))
#else
......@@ -453,9 +437,6 @@ HRESULT direct3d_create(IDirectDrawImpl *This)
ICOM_INIT_INTERFACE(This, IDirect3D3, VTABLE_IDirect3D3);
ICOM_INIT_INTERFACE(This, IDirect3D7, VTABLE_IDirect3D7);
globject->free_lights = (0x01 << MAX_LIGHTS) - 1; /* There are, in total, 8 lights in OpenGL */
globject->light_released = light_released;
This->d3d_private = globject;
TRACE(" creating OpenGL private storage at %p.\n", globject);
......
......@@ -156,54 +156,63 @@ Main_IDirect3DLightImpl_1_GetLight(LPDIRECT3DLIGHT iface,
* Light static functions
*/
static void update(IDirect3DLightImpl* This) {
static void update(IDirect3DLightImpl* This)
{
IDirect3DDeviceImpl* device;
if (!This->active_viewport||!This->active_viewport->active_device)
TRACE("(%p)\n", This);
if (!This->active_viewport || !This->active_viewport->active_device)
return;
device = This->active_viewport->active_device;
IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7),This->dwLightIndex,&(This->light7));
IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
}
static void activate(IDirect3DLightImpl* This) {
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
static void activate(IDirect3DLightImpl* This)
{
IDirect3DDeviceImpl* device;
TRACE("(%p)\n", This);
if (!This->active_viewport || !This->active_viewport->active_device)
return;
device = This->active_viewport->active_device;
ENTER_GL();
update(This);
/* If was not active, activate it */
if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
glEnable(glThis->light_num);
glThis->parent.light.dwFlags |= D3DLIGHT_ACTIVE;
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, TRUE);
This->light.dwFlags |= D3DLIGHT_ACTIVE;
}
LEAVE_GL();
}
static void desactivate(IDirect3DLightImpl* This) {
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
static void desactivate(IDirect3DLightImpl* This)
{
IDirect3DDeviceImpl* device;
TRACE("(%p)\n", This);
if (!This->active_viewport || !This->active_viewport->active_device)
return;
device = This->active_viewport->active_device;
ENTER_GL();
/* If was not active, activate it */
if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
glDisable(glThis->light_num);
glThis->parent.light.dwFlags &= ~D3DLIGHT_ACTIVE;
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, FALSE);
This->light.dwFlags &= ~D3DLIGHT_ACTIVE;
}
LEAVE_GL();
}
ULONG WINAPI
GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
{
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
if (!ref) {
((IDirect3DGLImpl *) This->d3d->d3d_private)->light_released(This->d3d, glThis->light_num);
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
......@@ -233,14 +242,12 @@ static const IDirect3DLightVtbl VTABLE_IDirect3DLight =
HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num)
HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d)
{
IDirect3DLightImpl *object;
IDirect3DLightGLImpl *gl_object;
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightGLImpl));
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
if (object == NULL) return DDERR_OUTOFMEMORY;
gl_object = (IDirect3DLightGLImpl *) object;
object->ref = 1;
object->d3d = d3d;
......@@ -249,7 +256,6 @@ HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum l
object->desactivate = desactivate;
object->update = update;
object->active_viewport = NULL;
gl_object->light_num = light_num;
ICOM_INIT_INTERFACE(object, IDirect3DLight, VTABLE_IDirect3DLight);
......
......@@ -48,16 +48,9 @@ typedef enum {
/* This structure is used for the 'd3d_private' field of the IDirectDraw structure */
typedef struct IDirect3DGLImpl
{
DWORD free_lights;
void (*light_released)(IDirectDrawImpl *, GLenum light_num);
int dummy; /* Empty for the moment */
} IDirect3DGLImpl;
typedef struct IDirect3DLightGLImpl
{
struct IDirect3DLightImpl parent;
GLenum light_num;
} IDirect3DLightGLImpl;
/* This structure is used for the 'private' field of the IDirectDrawSurfaceImpl structure */
typedef struct IDirect3DTextureGLImpl
{
......@@ -185,7 +178,7 @@ extern GL_EXTENSIONS_LIST GL_extensions;
/* All non-static functions 'exported' by various sub-objects */
extern HRESULT direct3d_create(IDirectDrawImpl *This);
extern HRESULT d3dtexture_create(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main_surf);
extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num);
extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d);
extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d);
extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment