Handle more properly versions for Direct3D and Direct3DDevice

objects.
This commit is contained in:
Christian Costa 2005-02-14 11:09:46 +00:00 committed by Alexandre Julliard
parent 37efec53f1
commit e64aae00e0
7 changed files with 40 additions and 28 deletions

View File

@ -197,6 +197,9 @@ struct IDirect3DDeviceImpl
ICOM_VFIELD_MULTI(IDirect3DDevice);
DWORD ref;
/* Version of the Direct3D object from which the device has been created */
DWORD version;
/* IDirect3DDevice fields */
IDirectDrawImpl *d3d;
IDirectDrawSurfaceImpl *surface;

View File

@ -207,6 +207,9 @@ Main_IDirect3DDeviceImpl_7_3T_2T_1T_QueryInterface(LPDIRECT3DDEVICE7 iface,
*obp = NULL;
/* Note: We cannot get an interface whose version is higher than the
* Direct3D object that created the device */
if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
*obp = iface;
@ -219,19 +222,19 @@ Main_IDirect3DDeviceImpl_7_3T_2T_1T_QueryInterface(LPDIRECT3DDEVICE7 iface,
TRACE(" Creating IDirect3DDevice interface %p\n", *obp);
return S_OK;
}
if ( IsEqualGUID( &IID_IDirect3DDevice2, riid ) ) {
if ( IsEqualGUID( &IID_IDirect3DDevice2, riid ) && (This->version >= 2)) {
IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
*obp = ICOM_INTERFACE(This, IDirect3DDevice2);
TRACE(" Creating IDirect3DDevice2 interface %p\n", *obp);
return S_OK;
}
if ( IsEqualGUID( &IID_IDirect3DDevice3, riid ) ) {
if ( IsEqualGUID( &IID_IDirect3DDevice3, riid ) && (This->version >= 3)) {
IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
*obp = ICOM_INTERFACE(This, IDirect3DDevice3);
TRACE(" Creating IDirect3DDevice3 interface %p\n", *obp);
return S_OK;
}
if ( IsEqualGUID( &IID_IDirect3DDevice7, riid ) ) {
if ( IsEqualGUID( &IID_IDirect3DDevice7, riid ) && (This->version >= 7)) {
IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
*obp = ICOM_INTERFACE(This, IDirect3DDevice7);
TRACE(" Creating IDirect3DDevice7 interface %p\n", *obp);

View File

@ -474,7 +474,7 @@ GL_IDirect3DDeviceImpl_3_2T_1T_GetCaps(LPDIRECT3DDEVICE3 iface,
static HRESULT enum_texture_format_OpenGL(LPD3DENUMTEXTUREFORMATSCALLBACK cb_1,
LPD3DENUMPIXELFORMATSCALLBACK cb_2,
LPVOID context)
LPVOID context, int version)
{
DDSURFACEDESC sdesc;
LPDDPIXELFORMAT pformat;
@ -617,7 +617,8 @@ static HRESULT enum_texture_format_OpenGL(LPD3DENUMTEXTUREFORMATSCALLBACK cb_1,
if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
if (GL_extensions.s3tc_compressed_texture) {
/* DXT textures only exist for devices created from IDirect3D3 and above */
if ((version >= 3) && GL_extensions.s3tc_compressed_texture) {
TRACE("Enumerating DXT1\n");
pformat->dwFlags = DDPF_FOURCC;
pformat->dwFourCC = MAKE_FOURCC('D','X','T','1');
@ -682,7 +683,7 @@ GL_IDirect3DDeviceImpl_2_1T_EnumTextureFormats(LPDIRECT3DDEVICE2 iface,
{
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpD3DEnumTextureProc, lpArg);
return enum_texture_format_OpenGL(lpD3DEnumTextureProc, NULL, lpArg);
return enum_texture_format_OpenGL(lpD3DEnumTextureProc, NULL, lpArg, This->version);
}
HRESULT WINAPI
@ -692,7 +693,7 @@ GL_IDirect3DDeviceImpl_7_3T_EnumTextureFormats(LPDIRECT3DDEVICE7 iface,
{
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpD3DEnumPixelProc, lpArg);
return enum_texture_format_OpenGL(NULL, lpD3DEnumPixelProc, lpArg);
return enum_texture_format_OpenGL(NULL, lpD3DEnumPixelProc, lpArg, This->version);
}
HRESULT WINAPI
@ -2312,7 +2313,7 @@ draw_primitive_handle_textures(IDirect3DDeviceImpl *This)
/* Apparently, whatever the state of BLEND, color keying is always activated for 'old' D3D versions */
if (((This->state_block.render_state[D3DRENDERSTATE_COLORKEYENABLE - 1]) ||
(glThis->version == 1)) &&
(glThis->parent.version == 1)) &&
(enable_colorkey)) {
TRACE(" colorkey activated.\n");
@ -3877,7 +3878,7 @@ apply_texture_state(IDirect3DDeviceImpl *This)
}
HRESULT
d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, BOOLEAN from_surface)
d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, int version)
{
IDirect3DDeviceImpl *object;
IDirect3DDeviceGLImpl *gl_object;
@ -3903,6 +3904,7 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSur
object->set_matrices = d3ddevice_set_matrices;
object->matrices_updated = d3ddevice_matrices_updated;
object->flush_to_framebuffer = d3ddevice_flush_to_frame_buffer;
object->version = version;
TRACE(" creating OpenGL device for surface = %p, d3d = %p\n", surface, d3d);
@ -3910,13 +3912,6 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSur
TRACE(" device critical section : %p\n", &(object->crit));
/* This is just a hack for some badly done games :-/ */
if (from_surface) {
gl_object->version = 1;
TRACE(" using D3D1 special hacks.\n");
} else
gl_object->version = 7;
device_context = GetDC(surface->ddraw_owner->window);
gl_object->display = get_display(device_context);
gl_object->drawable = get_drawable(device_context);
@ -4067,8 +4062,7 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSur
/* And finally warn D3D that this device is now present */
object->d3d->d3d_added_device(object->d3d, object);
/* FIXME: Should handle other versions than just 7 */
InitDefaultStateBlock(&object->state_block, 7);
InitDefaultStateBlock(&object->state_block, object->version);
/* Apply default render state and texture stage state values */
apply_render_state(object, &object->state_block);
apply_texture_state(object);

View File

@ -62,7 +62,22 @@ GL_IDirect3DImpl_1_EnumDevices(LPDIRECT3D iface,
}
HRESULT WINAPI
GL_IDirect3DImpl_3_2T_EnumDevices(LPDIRECT3D3 iface,
GL_IDirect3DImpl_2_EnumDevices(LPDIRECT3D2 iface,
LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
LPVOID lpUserArg)
{
ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpEnumDevicesCallback, lpUserArg);
/* Call functions defined in d3ddevices.c */
if (d3ddevice_enumerate(lpEnumDevicesCallback, lpUserArg, 2) != D3DENUMRET_OK)
return D3D_OK;
return D3D_OK;
}
HRESULT WINAPI
GL_IDirect3DImpl_3_EnumDevices(LPDIRECT3D3 iface,
LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
LPVOID lpUserArg)
{
@ -146,7 +161,7 @@ create_device_helper(IDirectDrawImpl *This,
IDirect3DDeviceImpl *lpd3ddev;
HRESULT ret_value;
ret_value = d3ddevice_create(&lpd3ddev, This, lpDDS, FALSE);
ret_value = d3ddevice_create(&lpd3ddev, This, lpDDS, version);
if (FAILED(ret_value)) return ret_value;
if ((iid == NULL) ||
@ -331,7 +346,7 @@ IDirect3D3Vtbl VTABLE_IDirect3D3 =
XCAST(QueryInterface) Thunk_IDirect3DImpl_3_QueryInterface,
XCAST(AddRef) Thunk_IDirect3DImpl_3_AddRef,
XCAST(Release) Thunk_IDirect3DImpl_3_Release,
XCAST(EnumDevices) GL_IDirect3DImpl_3_2T_EnumDevices,
XCAST(EnumDevices) GL_IDirect3DImpl_3_EnumDevices,
XCAST(CreateLight) GL_IDirect3DImpl_3_2T_1T_CreateLight,
XCAST(CreateMaterial) GL_IDirect3DImpl_3_2T_1T_CreateMaterial,
XCAST(CreateViewport) GL_IDirect3DImpl_3_2T_1T_CreateViewport,
@ -358,7 +373,7 @@ IDirect3D2Vtbl VTABLE_IDirect3D2 =
XCAST(QueryInterface) Thunk_IDirect3DImpl_2_QueryInterface,
XCAST(AddRef) Thunk_IDirect3DImpl_2_AddRef,
XCAST(Release) Thunk_IDirect3DImpl_2_Release,
XCAST(EnumDevices) Thunk_IDirect3DImpl_2_EnumDevices,
XCAST(EnumDevices) GL_IDirect3DImpl_2_EnumDevices,
XCAST(CreateLight) Thunk_IDirect3DImpl_2_CreateLight,
XCAST(CreateMaterial) Thunk_IDirect3DImpl_2_CreateMaterial,
XCAST(CreateViewport) Thunk_IDirect3DImpl_2_CreateViewport,

View File

@ -195,7 +195,7 @@ Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid,
IDirect3DDeviceImpl *d3ddevimpl;
HRESULT ret_value;
ret_value = d3ddevice_create(&d3ddevimpl, This->ddraw_owner, This, TRUE);
ret_value = d3ddevice_create(&d3ddevimpl, This->ddraw_owner, This, 1);
if (FAILED(ret_value)) return ret_value;
*ppObj = ICOM_INTERFACE(d3ddevimpl, IDirect3DDevice);

View File

@ -361,7 +361,7 @@ void set_render_state(IDirect3DDeviceImpl* This,
glThis->blending = dwRenderState;
/* Hack for some old games ... */
if (glThis->version == 1) {
if (glThis->parent.version == 1) {
lpStateBlock->render_state[D3DRENDERSTATE_COLORKEYENABLE - 1] = dwRenderState;
}
break;

View File

@ -117,9 +117,6 @@ typedef struct IDirect3DDeviceGLImpl
/* The last type of vertex drawn */
GL_TRANSFORM_STATE transform_state;
/* Maybe a hack, but it works */
DWORD version;
/* Used to handle fogging faster... */
BYTE fog_table[3 * 0x10000]; /* 3 is for R, G and B
0x10000 is 0xFF for the vertex color and
@ -192,7 +189,7 @@ extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirect
extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d);
extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d);
extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags);
extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, BOOLEAN from_surface);
extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, int version);
/* Used for Direct3D to request the device to enumerate itself */
extern HRESULT d3ddevice_enumerate(LPD3DENUMDEVICESCALLBACK cb, LPVOID context, DWORD version) ;