HRESULT surface_init(struct d3d8_surface *surface, struct d3d8_device *device, UINT width, UINT height, D3DFORMAT format, DWORD flags, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) { HRESULT hr; surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl; surface->refcount = 1; /* FIXME: Check MAX bounds of MultisampleQuality. */ if (multisample_quality > 0) { FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality); multisample_quality = 0; } wined3d_mutex_lock(); hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format), usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality, flags, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d surface, hr %#x.\n", hr); return hr; } surface->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(surface->parent_device); return D3D_OK; }
static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); ULONG refcount; TRACE("iface %p.\n", iface); if (surface->texture) { TRACE("Forwarding to %p.\n", surface->texture); return IDirect3DBaseTexture8_AddRef(&surface->texture->IDirect3DBaseTexture8_iface); } refcount = InterlockedIncrement(&surface->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, refcount); if (refcount == 1) { if (surface->parent_device) IDirect3DDevice8_AddRef(surface->parent_device); wined3d_mutex_lock(); if (surface->wined3d_rtv) wined3d_rendertarget_view_incref(surface->wined3d_rtv); wined3d_surface_incref(surface->wined3d_surface); wined3d_mutex_unlock(); } return refcount; }
static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); if (surface->forwardReference) { /* Forward refcounting */ TRACE("Forwarding to %p.\n", surface->forwardReference); return IUnknown_AddRef(surface->forwardReference); } else { /* No container, handle our own refcounting */ ULONG ref = InterlockedIncrement(&surface->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { if (surface->parent_device) IDirect3DDevice8_AddRef(surface->parent_device); wined3d_mutex_lock(); wined3d_surface_incref(surface->wined3d_surface); wined3d_mutex_unlock(); } return ref; } }
/* IDirect3DSurface8 IDirect3DResource8 Interface follow: */ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) { IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface; TRACE("iface %p, device %p.\n", iface, device); if (This->forwardReference) { IDirect3DResource8 *resource; HRESULT hr; hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource); if (SUCCEEDED(hr)) { hr = IDirect3DResource8_GetDevice(resource, device); IDirect3DResource8_Release(resource); TRACE("Returning device %p.\n", *device); } return hr; } *device = (IDirect3DDevice8 *)This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d8_surface_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, device %p.\n", iface, device); if (surface->forwardReference) { IDirect3DResource8 *resource; HRESULT hr; hr = IUnknown_QueryInterface(surface->forwardReference, &IID_IDirect3DResource8, (void **)&resource); if (SUCCEEDED(hr)) { hr = IDirect3DResource8_GetDevice(resource, device); IDirect3DResource8_Release(resource); TRACE("Returning device %p.\n", *device); } return hr; } *device = surface->parent_device; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device, UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) { const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops; struct wined3d_buffer_desc desc; HRESULT hr; if (pool == D3DPOOL_SCRATCH) return D3DERR_INVALIDCALL; /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */ if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) return D3DERR_INVALIDCALL; desc.byte_width = size; desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL; desc.bind_flags = 0; desc.access = wined3daccess_from_d3dpool(pool, usage) | map_access_from_usage(usage); /* Buffers are always readable. */ if (pool != D3DPOOL_DEFAULT) desc.access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.misc_flags = 0; desc.structure_byte_stride = 0; if (desc.access & WINED3D_RESOURCE_ACCESS_GPU) { desc.bind_flags = WINED3D_BIND_INDEX_BUFFER; parent_ops = &d3d8_indexbuffer_wined3d_parent_ops; } buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl; d3d8_resource_init(&buffer->resource); buffer->format = wined3dformat_from_d3dformat(format); buffer->usage = usage; wined3d_mutex_lock(); hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer); if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU)) { desc.bind_flags = WINED3D_BIND_INDEX_BUFFER; desc.access = WINED3D_RESOURCE_ACCESS_GPU; if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->draw_buffer))) wined3d_buffer_decref(buffer->wined3d_buffer); } wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d buffer, hr %#x.\n", hr); return hr; } buffer->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(buffer->parent_device); return D3D_OK; }
HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device, UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) { const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops; struct wined3d_buffer_desc desc; HRESULT hr; if (pool == D3DPOOL_SCRATCH) { WARN("Vertex buffer with D3DPOOL_SCRATCH requested.\n"); return D3DERR_INVALIDCALL; } /* In d3d8, buffers can't be used as rendertarget or depth/stencil buffer. */ if (usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) return D3DERR_INVALIDCALL; buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl; d3d8_resource_init(&buffer->resource); buffer->fvf = fvf; desc.byte_width = size; desc.usage = usage & WINED3DUSAGE_MASK; desc.bind_flags = 0; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.misc_flags = 0; desc.structure_byte_stride = 0; if (desc.access & WINED3D_RESOURCE_ACCESS_GPU) { desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER; parent_ops = &d3d8_vertexbuffer_wined3d_parent_ops; } wined3d_mutex_lock(); hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer); if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU)) { desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER; desc.access = WINED3D_RESOURCE_ACCESS_GPU; if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->draw_buffer))) wined3d_buffer_decref(buffer->wined3d_buffer); } wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d buffer, hr %#x.\n", hr); return hr; } buffer->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(buffer->parent_device); return D3D_OK; }
HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device, D3DPRESENT_PARAMETERS *present_parameters) { struct wined3d_swapchain_desc desc; HRESULT hr; swapchain->ref = 1; swapchain->IDirect3DSwapChain8_iface.lpVtbl = &Direct3DSwapChain8_Vtbl; desc.backbuffer_width = present_parameters->BackBufferWidth; desc.backbuffer_height = present_parameters->BackBufferHeight; desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); desc.backbuffer_count = max(1, present_parameters->BackBufferCount); desc.multisample_type = present_parameters->MultiSampleType; desc.multisample_quality = 0; /* d3d9 only */ desc.swap_effect = present_parameters->SwapEffect; desc.device_window = present_parameters->hDeviceWindow; desc.windowed = present_parameters->Windowed; desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil; desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); desc.flags = present_parameters->Flags; desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz; desc.swap_interval = present_parameters->FullScreen_PresentationInterval; desc.auto_restore_display_mode = TRUE; wined3d_mutex_lock(); hr = wined3d_swapchain_create(device->wined3d_device, &desc, WINED3D_SURFACE_TYPE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain); wined3d_mutex_unlock(); present_parameters->BackBufferWidth = desc.backbuffer_width; present_parameters->BackBufferHeight = desc.backbuffer_height; present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format); present_parameters->BackBufferCount = desc.backbuffer_count; present_parameters->MultiSampleType = desc.multisample_type; present_parameters->SwapEffect = desc.swap_effect; present_parameters->hDeviceWindow = desc.device_window; present_parameters->Windowed = desc.windowed; present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil; present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format); present_parameters->Flags = desc.flags; present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate; present_parameters->FullScreen_PresentationInterval = desc.swap_interval; if (FAILED(hr)) { WARN("Failed to create wined3d swapchain, hr %#x.\n", hr); return hr; } swapchain->parentDevice = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(swapchain->parentDevice); return D3D_OK; }
HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device, D3DPRESENT_PARAMETERS *present_parameters) { WINED3DPRESENT_PARAMETERS wined3d_parameters; HRESULT hr; swapchain->ref = 1; swapchain->lpVtbl = &Direct3DSwapChain8_Vtbl; wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth; wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight; wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat); wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount); wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType; wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */ wined3d_parameters.SwapEffect = present_parameters->SwapEffect; wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow; wined3d_parameters.Windowed = present_parameters->Windowed; wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat); wined3d_parameters.Flags = present_parameters->Flags; wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; wined3d_parameters.PresentationInterval = present_parameters->FullScreen_PresentationInterval; wined3d_parameters.AutoRestoreDisplayMode = TRUE; wined3d_mutex_lock(); hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters, SURFACE_OPENGL, swapchain, &swapchain->wineD3DSwapChain); wined3d_mutex_unlock(); present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth; present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight; present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat); present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount; present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType; present_parameters->SwapEffect = wined3d_parameters.SwapEffect; present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow; present_parameters->Windowed = wined3d_parameters.Windowed; present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil; present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat); present_parameters->Flags = wined3d_parameters.Flags; present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz; present_parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval; if (FAILED(hr)) { WARN("Failed to create wined3d swapchain, hr %#x.\n", hr); return hr; } swapchain->parentDevice = (IDirect3DDevice8 *)device; IDirect3DDevice8_AddRef(swapchain->parentDevice); return D3D_OK; }
void surface_init(struct d3d8_surface *surface, struct wined3d_surface *wined3d_surface, struct d3d8_device *device, const struct wined3d_parent_ops **parent_ops) { surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl; d3d8_resource_init(&surface->resource); wined3d_surface_incref(wined3d_surface); surface->wined3d_surface = wined3d_surface; surface->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(surface->parent_device); *parent_ops = &d3d8_surface_wined3d_parent_ops; }
static HRESULT WINAPI d3d8_texture_2d_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device) { struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface); TRACE("iface %p, device %p.\n", iface, device); *device = texture->parent_device; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
/* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */ static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device) { IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface; TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice8 *)This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device) { struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface); TRACE("iface %p, device %p.\n", iface, device); *device = buffer->parent_device; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
/* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); TRACE("iface %p, device %p.\n", iface, device); *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d8_surface_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, device %p.\n", iface, device); if (surface->texture) return IDirect3DBaseTexture8_GetDevice(&surface->texture->IDirect3DBaseTexture8_iface, device); *device = surface->parent_device; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static ULONG WINAPI IDirect3DVolumeTexture8Impl_AddRef(LPDIRECT3DVOLUMETEXTURE8 iface) { IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface; ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { IDirect3DDevice8_AddRef(This->parentDevice); wined3d_mutex_lock(); IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture); wined3d_mutex_unlock(); } return ref; }
static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) { IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface; ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { IDirect3DDevice8_AddRef(This->parentDevice); wined3d_mutex_lock(); IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer); wined3d_mutex_unlock(); } return ref; }
static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface) { struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface); ULONG ref = InterlockedIncrement(&texture->refcount); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { IDirect3DDevice8_AddRef(texture->parent_device); wined3d_mutex_lock(); wined3d_texture_incref(texture->wined3d_texture); wined3d_mutex_unlock(); } return ref; }
static ULONG WINAPI IDirect3DVolumeTexture8Impl_AddRef(IDirect3DVolumeTexture8 *iface) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { IDirect3DDevice8_AddRef(This->parentDevice); wined3d_mutex_lock(); wined3d_texture_incref(This->wined3d_texture); wined3d_mutex_unlock(); } return ref; }
static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface) { IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface); ULONG refcount = InterlockedIncrement(&buffer->ref); TRACE("%p increasing refcount to %u.\n", iface, refcount); if (refcount == 1) { IDirect3DDevice8_AddRef(buffer->parentDevice); wined3d_mutex_lock(); wined3d_buffer_incref(buffer->wineD3DVertexBuffer); wined3d_mutex_unlock(); } return refcount; }
static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface) { struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface); ULONG ref = InterlockedIncrement(&swapchain->refcount); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { if (swapchain->parent_device) IDirect3DDevice8_AddRef(swapchain->parent_device); wined3d_mutex_lock(); wined3d_swapchain_incref(swapchain->wined3d_swapchain); wined3d_mutex_unlock(); } return ref; }
static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface) { struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface); ULONG refcount = InterlockedIncrement(&buffer->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, refcount); if (refcount == 1) { IDirect3DDevice8_AddRef(buffer->parent_device); wined3d_mutex_lock(); wined3d_buffer_incref(buffer->wined3d_buffer); if (buffer->draw_buffer) wined3d_buffer_incref(buffer->draw_buffer); wined3d_mutex_unlock(); } return refcount; }
HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; DWORD surface_flags = 0; HRESULT hr; texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl; texture->refcount = 1; desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE; desc.format = wined3dformat_from_d3dformat(format); desc.multisample_type = WINED3D_MULTISAMPLE_NONE; desc.multisample_quality = 0; desc.usage = usage & WINED3DUSAGE_MASK; desc.usage |= WINED3DUSAGE_TEXTURE; desc.pool = pool; desc.width = edge_length; desc.height = edge_length; desc.depth = 1; desc.size = 0; if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC)) surface_flags |= WINED3D_SURFACE_MAPPABLE; wined3d_mutex_lock(); hr = wined3d_texture_create_cube(device->wined3d_device, &desc, levels, surface_flags, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d cube texture, hr %#x.\n", hr); return hr; } texture->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(texture->parent_device); return D3D_OK; }
static ULONG WINAPI d3d8_texture_2d_AddRef(IDirect3DTexture8 *iface) { struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface); ULONG ref = InterlockedIncrement(&texture->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { struct d3d8_surface *surface; IDirect3DDevice8_AddRef(texture->parent_device); wined3d_mutex_lock(); LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d8_surface, rtv_entry) { wined3d_rendertarget_view_incref(surface->wined3d_rtv); } wined3d_texture_incref(texture->wined3d_texture); wined3d_mutex_unlock(); } return ref; }
HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) { HRESULT hr; texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl; texture->refcount = 1; wined3d_mutex_lock(); hr = wined3d_texture_create_cube(device->wined3d_device, edge_length, levels, usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d cube texture, hr %#x.\n", hr); return hr; } texture->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(texture->parent_device); return D3D_OK; }
HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *device, UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) { struct wined3d_resource_desc desc; HRESULT hr; texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl; texture->refcount = 1; desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE; desc.format = wined3dformat_from_d3dformat(format); desc.multisample_type = WINED3D_MULTISAMPLE_NONE; desc.multisample_quality = 0; desc.usage = usage & WINED3DUSAGE_MASK; desc.usage |= WINED3DUSAGE_TEXTURE; desc.pool = pool; desc.width = width; desc.height = height; desc.depth = depth; desc.size = 0; wined3d_mutex_lock(); hr = wined3d_texture_create_3d(device->wined3d_device, &desc, levels, texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d volume texture, hr %#x.\n", hr); return hr; } texture->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(texture->parent_device); return D3D_OK; }
HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device, UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) { HRESULT hr; texture->IDirect3DCubeTexture8_iface.lpVtbl = &Direct3DCubeTexture8_Vtbl; texture->ref = 1; wined3d_mutex_lock(); hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture, &d3d8_cubetexture_wined3d_parent_ops, &texture->wineD3DCubeTexture); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d cube texture, hr %#x.\n", hr); return hr; } texture->parentDevice = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(texture->parentDevice); return D3D_OK; }
HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device, UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) { HRESULT hr; texture->IDirect3DVolumeTexture8_iface.lpVtbl = &Direct3DVolumeTexture8_Vtbl; texture->ref = 1; wined3d_mutex_lock(); hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels, usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture, &d3d8_volumetexture_wined3d_parent_ops, &texture->wined3d_texture); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d volume texture, hr %#x.\n", hr); return hr; } texture->parentDevice = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(texture->parentDevice); return D3D_OK; }
static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device, struct wined3d_swapchain_desc *desc) { HRESULT hr; swapchain->refcount = 1; swapchain->IDirect3DSwapChain8_iface.lpVtbl = &d3d8_swapchain_vtbl; wined3d_mutex_lock(); hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain, &d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain); wined3d_mutex_unlock(); if (FAILED(hr)) { WARN("Failed to create wined3d swapchain, hr %#x.\n", hr); return hr; } swapchain->parent_device = &device->IDirect3DDevice8_iface; IDirect3DDevice8_AddRef(swapchain->parent_device); return D3D_OK; }
BOOL gldCreateDrawable_DX( DGL_ctx *ctx, // BOOL bDefaultDriver, BOOL bDirectDrawPersistant, BOOL bPersistantBuffers) { // // bDirectDrawPersistant: applies to IDirect3D8 // bPersistantBuffers: applies to IDirect3DDevice8 // HRESULT hResult; GLD_driver_dx8 *lpCtx = NULL; D3DDEVTYPE d3dDevType; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; DWORD dwBehaviourFlags; D3DADAPTER_IDENTIFIER8 d3dIdent; // Error if context is NULL. if (ctx == NULL) return FALSE; if (ctx->glPriv) { lpCtx = ctx->glPriv; // Release any existing interfaces SAFE_RELEASE(lpCtx->pDev); SAFE_RELEASE(lpCtx->pD3D); } else { lpCtx = (GLD_driver_dx8*)malloc(sizeof(GLD_driver_dx8)); ZeroMemory(lpCtx, sizeof(lpCtx)); } d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; // TODO: Check this // if (bDefaultDriver) // d3dDevType = D3DDEVTYPE_REF; // Use persistant interface if needed if (bDirectDrawPersistant && dx8Globals.bDirect3D) { lpCtx->pD3D = dx8Globals.pD3D; IDirect3D8_AddRef(lpCtx->pD3D); goto SkipDirectDrawCreate; } // Create Direct3D8 object lpCtx->pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); if (lpCtx->pD3D == NULL) { MessageBox(NULL, "Unable to initialize Direct3D8", "GLDirect", MB_OK); ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D8 interface"); nContextError = GLDERR_D3D; goto return_with_error; } // Cache Direct3D interface for subsequent GLRCs if (bDirectDrawPersistant && !dx8Globals.bDirect3D) { dx8Globals.pD3D = lpCtx->pD3D; IDirect3D8_AddRef(dx8Globals.pD3D); dx8Globals.bDirect3D = TRUE; } SkipDirectDrawCreate: // Get the display mode so we can make a compatible backbuffer hResult = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); if (FAILED(hResult)) { nContextError = GLDERR_D3D; goto return_with_error; } // Get device caps hResult = IDirect3D8_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps8); if (FAILED(hResult)) { ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_GetDeviceCaps failed", hResult); nContextError = GLDERR_D3D; goto return_with_error; } // Check for hardware transform & lighting lpCtx->bHasHWTnL = lpCtx->d3dCaps8.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; // If this flag is present then we can't default to Mesa // SW rendering between BeginScene() and EndScene(). if (lpCtx->d3dCaps8.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { ddlogMessage(DDLOG_WARN, "Warning : No 2D allowed during 3D scene.\n"); } // // Create the Direct3D context // // Re-use original IDirect3DDevice if persistant buffers exist. // Note that we test for persistant IDirect3D8 as well // bDirectDrawPersistant == persistant IDirect3D8 (DirectDraw8 does not exist) if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D && dx8Globals.pDev) { lpCtx->pDev = dx8Globals.pDev; IDirect3DDevice8_AddRef(dx8Globals.pDev); goto skip_direct3ddevice_create; } // Clear the presentation parameters (sets all members to zero) ZeroMemory(&d3dpp, sizeof(d3dpp)); // Recommended by MS; needed for MultiSample. // Be careful if altering this for FullScreenBlit d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; if (ctx->bFullscreen) { ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen d3dpp.Windowed = FALSE; d3dpp.BackBufferWidth = d3ddm.Width; d3dpp.BackBufferHeight = d3ddm.Height; d3dpp.hDeviceWindow = ctx->hWnd; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; // Support for vertical retrace synchronisation. // Set default presentation interval in case caps bits are missing d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; if (glb.bWaitForRetrace) { if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; } else { if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; } } else { ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages d3dpp.Windowed = TRUE; d3dpp.BackBufferWidth = ctx->dwWidth; d3dpp.BackBufferHeight = ctx->dwHeight; d3dpp.hDeviceWindow = ctx->hWnd; d3dpp.FullScreen_RefreshRateInHz = 0; // FullScreen_PresentationInterval must be default for Windowed mode d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; } // Decide if we can use hardware TnL dwBehaviourFlags = (lpCtx->bHasHWTnL) ? D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; // Add flag to tell D3D to be thread-safe if (glb.bMultiThreaded) dwBehaviourFlags |= D3DCREATE_MULTITHREADED; // Add flag to tell D3D to be FPU-safe if (!glb.bFastFPU) dwBehaviourFlags |= D3DCREATE_FPU_PRESERVE; hResult = IDirect3D8_CreateDevice(lpCtx->pD3D, glb.dwAdapter, d3dDevType, ctx->hWnd, dwBehaviourFlags, &d3dpp, &lpCtx->pDev); if (FAILED(hResult)) { ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_CreateDevice failed", hResult); nContextError = GLDERR_D3D; goto return_with_error; } if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D) { dx8Globals.pDev = lpCtx->pDev; dx8Globals.bDirect3DDevice = TRUE; } /* // See if DDraw interfaces are available (DaveM) hResult = IDirect3D8_QueryInterface(lpCtx->pDev, &IID_IDirectDraw7, (LPVOID*)&lpOpaque1); if (FAILED(hResult) || lpOpaque1 == NULL) { ddlogMessage(DDLOG_INFO, "DirectDraw QueryInterface unavailable\n"); } hResult = IDirect3DDevice8_QueryInterface(lpCtx->pDev, &IID_IDirectDrawSurface7, (LPVOID*)&lpOpaque2); if (FAILED(hResult) || lpOpaque2 == NULL) { ddlogMessage(DDLOG_INFO, "DirectDrawSurface QueryInterface unavialable\n"); } */ // Dump some useful stats hResult = IDirect3D8_GetAdapterIdentifier( lpCtx->pD3D, glb.dwAdapter, D3DENUM_NO_WHQL_LEVEL, // Avoids 1 to 2 second delay &d3dIdent); if (SUCCEEDED(hResult)) { ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", d3dIdent.Driver, HIWORD(d3dIdent.DriverVersion.HighPart), LOWORD(d3dIdent.DriverVersion.HighPart), HIWORD(d3dIdent.DriverVersion.LowPart), LOWORD(d3dIdent.DriverVersion.LowPart)); ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); } // Init projection matrix for D3D TnL D3DXMatrixIdentity(&lpCtx->matProjection); lpCtx->matModelView = lpCtx->matProjection; // gld->bUseMesaProjection = TRUE; skip_direct3ddevice_create: // Create buffers to hold primitives lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); lpCtx->PB2d.dwUsage = D3DUSAGE_DONOTCLIP | D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY; hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); if (FAILED(hResult)) goto return_with_error; lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); lpCtx->PB3d.dwUsage = D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY; hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); if (FAILED(hResult)) goto return_with_error; /* // NOTE: A FVF code of zero indicates a non-FVF vertex buffer (for vertex shaders) lpCtx->PBtwosidelight.dwFVF = 0; //GLD_FVF_TWOSIDED_VERTEX; lpCtx->PBtwosidelight.dwPool = D3DPOOL_DEFAULT; lpCtx->PBtwosidelight.dwStride = sizeof(GLD_TWOSIDED_VERTEX); lpCtx->PBtwosidelight.dwUsage = D3DUSAGE_DONOTCLIP | D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY; hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PBtwosidelight); if (FAILED(hResult)) goto return_with_error;*/ // Now try and create the DX8 Vertex Shaders // _gldCreateVertexShaders(lpCtx); // Zero the pipeline usage counters lpCtx->PipelineUsage.qwMesa.QuadPart = // lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; // Assign drawable to GL private ctx->glPriv = lpCtx; return TRUE; return_with_error: // Clean up and bail // _gldDestroyVertexShaders(lpCtx); // _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); SAFE_RELEASE(lpCtx->pDev); SAFE_RELEASE(lpCtx->pD3D); return FALSE; }