- fix in the GetHandle method

- factorize some code between D3D1/2/3 and D3D7
- fix reference counting for palettes
oldstable
Lionel Ulmer 2003-01-05 01:04:55 +00:00 committed by Alexandre Julliard
parent 274e72672b
commit 07f1269302
3 changed files with 40 additions and 67 deletions

View File

@ -312,9 +312,11 @@ GL_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface)
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
if (!--(This->ref)) {
int i;
/* Release texture associated with the device */
if (This->current_texture[0] != NULL)
IDirect3DTexture2_Release(ICOM_INTERFACE(This->current_texture[0], IDirect3DTexture2));
for (i = 0; i < MAX_TEXTURES; i++)
if (This->current_texture[i] != NULL)
IDirectDrawSurface7_Release(ICOM_INTERFACE(This->current_texture[i], IDirectDrawSurface7));
/* And warn the D3D object that this device is no longer active... */
This->d3d->removed_device(This->d3d, This);
@ -1402,12 +1404,13 @@ GL_IDirect3DDeviceImpl_7_3T_SetTexture(LPDIRECT3DDEVICE7 iface,
TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, dwStage, lpTexture2);
if (This->current_texture[dwStage] != NULL) {
/* Seems that this is not right... Need to test in real Windows
IDirect3DTexture2_Release(ICOM_INTERFACE(This->current_texture[dwStage], IDirect3DTexture2)); */
IDirectDrawSurface7_Release(ICOM_INTERFACE(This->current_texture[dwStage], IDirectDrawSurface7));
}
ENTER_GL();
if (lpTexture2 == NULL) {
This->current_texture[dwStage] = NULL;
TRACE(" disabling 2D texturing.\n");
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
@ -2102,9 +2105,6 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
surf->d3ddevice = object;
}
/* FIXME: Should handle other versions than just 7 */
InitDefaultStateBlock(&object->state_block,7);
/* FIXME: These 4 statements are kept for compatibility but should be removed as soon
as they are correctly handled */
gl_object->render_state.fog_on = FALSE;
@ -2137,10 +2137,6 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
ENTER_GL();
TRACE(" current context set\n");
/* Apply default render state values */
apply_render_state(gl_object, &object->state_block);
/* FIXME: do something similar for ligh_state and texture_stage_state */
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDrawBuffer(buffer);
@ -2161,6 +2157,12 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
/* And finally warn D3D that this device is now present */
object->d3d->added_device(object->d3d, object);
/* FIXME: Should handle other versions than just 7 */
InitDefaultStateBlock(&object->state_block,7);
/* Apply default render state values */
apply_render_state(gl_object, &object->state_block);
/* FIXME: do something similar for ligh_state and texture_stage_state */
return DD_OK;
}

View File

@ -496,8 +496,19 @@ Main_IDirect3DTextureImpl_2_1T_GetHandle(LPDIRECT3DTEXTURE2 iface,
LPD3DTEXTUREHANDLE lpHandle)
{
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpDirect3DDevice2, lpHandle);
return DD_OK;
IDirect3DDeviceImpl *lpDeviceImpl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice2, lpDirect3DDevice2);
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice2, lpHandle);
/* The handle is simply the pointer to the implementation structure */
*lpHandle = (D3DTEXTUREHANDLE) This;
TRACE(" returning handle %08lx.\n", *lpHandle);
/* Now set the device for this texture */
This->d3ddevice = lpDeviceImpl;
return D3D_OK;
}
HRESULT WINAPI
@ -525,9 +536,10 @@ gltex_final_release(IDirectDrawSurfaceImpl *This)
{
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
DWORD mem_used;
int i;
TRACE(" deleting texture with GL id %d.\n", glThis->tex_name);
/* And delete texture handle */
ENTER_GL();
if (glThis->tex_name != 0)
@ -536,8 +548,9 @@ gltex_final_release(IDirectDrawSurfaceImpl *This)
/* And if this texture was the current one, remove it at the device level */
if (This->d3ddevice != NULL)
if (This->d3ddevice->current_texture[0] == This)
This->d3ddevice->current_texture[0] = NULL;
for (i = 0; i < MAX_TEXTURES; i++)
if (This->d3ddevice->current_texture[i] == This)
This->d3ddevice->current_texture[i] = NULL;
/* All this should be part of main surface management not just a hack for texture.. */
if (glThis->loaded) {
@ -569,37 +582,6 @@ gltex_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
glThis->dirty_flag = TRUE;
}
HRESULT WINAPI
GL_IDirect3DTextureImpl_2_1T_GetHandle(LPDIRECT3DTEXTURE2 iface,
LPDIRECT3DDEVICE2 lpDirect3DDevice2,
LPD3DTEXTUREHANDLE lpHandle)
{
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
IDirect3DDeviceImpl *lpDeviceImpl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice2, lpDirect3DDevice2);
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice2, lpHandle);
/* The handle is simply the pointer to the implementation structure */
*lpHandle = (D3DTEXTUREHANDLE) This;
TRACE(" returning handle %08lx.\n", *lpHandle);
/* Now, bind a new texture */
This->d3ddevice = lpDeviceImpl;
/* Associate the texture with the device and perform the appropriate AddRef/Release */
/* FIXME: Is there only one or several textures associated with the device ? */
if (lpDeviceImpl->current_texture[0] != NULL)
IDirectDrawSurface7_Release(ICOM_INTERFACE(lpDeviceImpl->current_texture[0], IDirectDrawSurface7));
IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This, IDirectDrawSurface7));
lpDeviceImpl->current_texture[0] = This;
TRACE("OpenGL texture handle is : %d\n", glThis->tex_name);
return D3D_OK;
}
HRESULT WINAPI
GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
LPDIRECT3DTEXTURE2 lpD3DTexture2)
@ -641,12 +623,11 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
if (This->palette == NULL) {
This->palette = lpD3DTextureImpl->palette;
if (lpD3DTextureImpl->palette != NULL) IDirectDrawPalette_AddRef(ICOM_INTERFACE(lpD3DTextureImpl->palette,
IDirectDrawPalette));
IDirectDrawPalette));
} else {
if (lpD3DTextureImpl->palette != NULL) {
PALETTEENTRY palent[256];
IDirectDrawPalette *pal_int = ICOM_INTERFACE(lpD3DTextureImpl->palette, IDirectDrawPalette);
IDirectDrawPalette_AddRef(pal_int);
IDirectDrawPalette_GetEntries(pal_int, 0, 0, 256, palent);
IDirectDrawPalette_SetEntries(ICOM_INTERFACE(This->palette, IDirectDrawPalette),
0, 0, 256, palent);
@ -667,6 +648,7 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
/* Copy also the ColorKeying stuff */
if (src_d->dwFlags & DDSD_CKSRCBLT) {
dst_d->dwFlags |= DDSD_CKSRCBLT;
dst_d->ddckCKSrcBlt.dwColorSpaceLowValue = src_d->ddckCKSrcBlt.dwColorSpaceLowValue;
dst_d->ddckCKSrcBlt.dwColorSpaceHighValue = src_d->ddckCKSrcBlt.dwColorSpaceHighValue;
}
@ -780,7 +762,7 @@ ICOM_VTABLE(IDirect3DTexture2) VTABLE_IDirect3DTexture2 =
XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_2_QueryInterface,
XCAST(AddRef) Thunk_IDirect3DTextureImpl_2_AddRef,
XCAST(Release) Thunk_IDirect3DTextureImpl_2_Release,
XCAST(GetHandle) GL_IDirect3DTextureImpl_2_1T_GetHandle,
XCAST(GetHandle) Main_IDirect3DTextureImpl_2_1T_GetHandle,
XCAST(PaletteChanged) Main_IDirect3DTextureImpl_2_1T_PaletteChanged,
XCAST(Load) GL_IDirect3DTextureImpl_2_1T_Load,
};

View File

@ -81,23 +81,12 @@ void set_render_state(IDirect3DDeviceGLImpl* This,
case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
IDirectDrawSurfaceImpl *tex = (IDirectDrawSurfaceImpl*) dwRenderState;
if (tex == NULL) {
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
TRACE("disabling texturing\n");
} else {
glEnable(GL_TEXTURE_2D);
/* Default parameters */
gltex_upload_texture(tex);
/* To prevent state change, we could test here what are the parameters
stored in the texture */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
}
LEAVE_GL();
IDirect3DDevice7_SetTexture(ICOM_INTERFACE(&(This->parent), IDirect3DDevice7),
0,
ICOM_INTERFACE(tex, IDirectDrawSurface7));
ENTER_GL();
} break;
case D3DRENDERSTATE_TEXTUREADDRESSU: /* 44 */
case D3DRENDERSTATE_TEXTUREADDRESSV: /* 45 */