/** @brief Destroy D3D Offscreen and Backbuffer surfaces. */ static void destroy_d3d_surfaces(void) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>destroy_d3d_surfaces called.\n"); /* Let's destroy the old (if any) D3D Surfaces */ if (priv->locked_rect.pBits) IDirect3DSurface9_UnlockRect(priv->d3d_surface); priv->locked_rect.pBits = NULL; if (priv->d3d_surface) IDirect3DSurface9_Release(priv->d3d_surface); priv->d3d_surface = NULL; /* kill the OSD texture and its shadow copy */ if (priv->d3d_texture_osd) IDirect3DTexture9_Release(priv->d3d_texture_osd); priv->d3d_texture_osd = NULL; if (priv->d3d_texture_system) IDirect3DTexture9_Release(priv->d3d_texture_system); priv->d3d_texture_system = NULL; if (priv->d3d_backbuf) IDirect3DSurface9_Release(priv->d3d_backbuf); priv->d3d_backbuf = NULL; }
static void test_D3DXFilterTexture(IDirect3DDevice9 *device) { IDirect3DTexture9 *tex; HRESULT hr; hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL); if (SUCCEEDED(hr)) { hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE); ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK); hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */ ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Last miplevel */ ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 20, D3DX_FILTER_NONE); /* Invalid miplevel */ ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); } else skip("Failed to create texture\n"); IDirect3DTexture9_Release(tex); hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE); ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* Test different pools */ hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL); if (SUCCEEDED(hr)) { hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE); ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DTexture9_Release(tex); } else skip("Failed to create texture\n"); hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL); if (SUCCEEDED(hr)) { hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE); ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DTexture9_Release(tex); } else skip("Failed to create texture\n"); }
/** @brief Resize Direct3D context on window resize. * @return 1 on success, 0 on failure */ static int resize_d3d(void) { D3DVIEWPORT9 vp = {0, 0, vo_dwidth, vo_dheight, 0, 1}; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>resize_d3d called.\n"); /* Make sure that backbuffer is large enough to accomodate the new viewport dimensions. Grow it if necessary. */ if (vo_dwidth > priv->cur_backbuf_width || vo_dheight > priv->cur_backbuf_height) { if (!change_d3d_backbuffer(BACKBUFFER_RESET)) return 0; } /* Destroy the OSD textures. They should always match the new dimensions * of the onscreen window, so on each resize we need new OSD dimensions. */ if (priv->d3d_texture_osd) IDirect3DTexture9_Release(priv->d3d_texture_osd); priv->d3d_texture_osd = NULL; if (priv->d3d_texture_system) IDirect3DTexture9_Release(priv->d3d_texture_system); priv->d3d_texture_system = NULL; /* Recreate the OSD. The function will observe that the offscreen plain * surface and the backbuffer are not destroyed and will skip their creation, * effectively recreating only the OSD. */ if (!create_d3d_surfaces()) return 0; if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device, &vp))) { mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Setting viewport failed.\n"); return 0; } calc_fs_rect(); #ifdef CONFIG_FREETYPE // font needs to be adjusted force_load_font = 1; #endif // OSD needs to be drawn fresh for new size vo_osd_changed(OSDTYPE_OSD); return 1; }
void shutdownD3D9() { #ifdef __WIN32__ /* Free all resources */ if (gTexturePtr) IDirect3DTexture9_Release(gTexturePtr); gTexturePtr = NULL; if (gVShaderPtr) IDirect3DVertexShader9_Release(gVShaderPtr); gVShaderPtr = NULL; if (gPShaderPtr) IDirect3DPixelShader9_Release(gPShaderPtr); gPShaderPtr = NULL; if (gVertexBufferPtr) IDirect3DVertexBuffer9_Release(gVertexBufferPtr); gVertexBufferPtr = NULL; if (gIndexBufferPtr) IDirect3DIndexBuffer9_Release(gIndexBufferPtr); gIndexBufferPtr = NULL; if (gVertexDeclPtr) IDirect3DVertexDeclaration9_Release(gVertexDeclPtr); gVertexDeclPtr = NULL; if (gDevicePtr) IDirect3DDevice9_Release(gDevicePtr); gDevicePtr = NULL; if (gD3D9Ptr) IDirect3D9_Release(gD3D9Ptr); gD3D9Ptr = NULL; gDeviceBackBufferPtr = NULL; #endif }
void D3DCacheSystemShutdown(d3d_render_cache_system *pCacheSystem) { d3d_texture_cache_entry *pTexEntry; list_type list; d3d_render_cache *pRenderCache = NULL; // first free all textures for (list = pCacheSystem->textureCache.textureList; list != NULL; list = list->next) { pTexEntry = (d3d_texture_cache_entry *)list->data; if (pTexEntry->pTexture) IDirect3DTexture9_Release(pTexEntry->pTexture); } list_destroy(pCacheSystem->textureCache.textureList); // now destroy the vertex buffers for (list = pCacheSystem->renderCacheList; list != NULL; list = list->next) { pRenderCache = (d3d_render_cache *)list->data; if (pRenderCache) D3DCacheShutdown(pRenderCache); } list_destroy(pCacheSystem->renderCacheList); memset(pCacheSystem, 0, sizeof(d3d_render_cache_system)); }
static void Direct3DDeleteRegions(int count, d3d_region_t *region) { for (int i = 0; i < count; i++) { if (region[i].texture) IDirect3DTexture9_Release(region[i].texture); } free(region); }
static void test_surface_get_container(IDirect3DDevice9 *device_ptr) { IDirect3DTexture9 *texture_ptr = 0; IDirect3DSurface9 *surface_ptr = 0; void *container_ptr; HRESULT hr; hr = IDirect3DDevice9_CreateTexture(device_ptr, 128, 128, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture_ptr, 0); ok(SUCCEEDED(hr) && texture_ptr != NULL, "CreateTexture returned: hr %#lx, texture_ptr %p. " "Expected hr %#lx, texture_ptr != %p\n", hr, texture_ptr, D3D_OK, NULL); if (!texture_ptr || FAILED(hr)) goto cleanup; hr = IDirect3DTexture9_GetSurfaceLevel(texture_ptr, 0, &surface_ptr); ok(SUCCEEDED(hr) && surface_ptr != NULL, "GetSurfaceLevel returned: hr %#lx, surface_ptr %p. " "Expected hr %#lx, surface_ptr != %p\n", hr, surface_ptr, D3D_OK, NULL); if (!surface_ptr || FAILED(hr)) goto cleanup; /* These should work... */ container_ptr = (void *)0x1337c0d3; hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IUnknown, &container_ptr); ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#lx, container_ptr %p. " "Expected hr %#lx, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr); if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); container_ptr = (void *)0x1337c0d3; hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DResource9, &container_ptr); ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#lx, container_ptr %p. " "Expected hr %#lx, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr); if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); container_ptr = (void *)0x1337c0d3; hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DBaseTexture9, &container_ptr); ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#lx, container_ptr %p. " "Expected hr %#lx, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr); if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); container_ptr = (void *)0x1337c0d3; hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DTexture9, &container_ptr); ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#lx, container_ptr %p. " "Expected hr %#lx, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr); if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); /* ...and this one shouldn't. This should return E_NOINTERFACE and set container_ptr to NULL */ container_ptr = (void *)0x1337c0d3; hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DSurface9, &container_ptr); ok(hr == E_NOINTERFACE && container_ptr == NULL, "GetContainer returned: hr %#lx, container_ptr %p. " "Expected hr %#lx, container_ptr %p\n", hr, container_ptr, E_NOINTERFACE, NULL); if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); cleanup: if (texture_ptr) IDirect3DTexture9_Release(texture_ptr); if (surface_ptr) IDirect3DSurface9_Release(surface_ptr); }
void d3d_texture_free(LPDIRECT3DTEXTURE tex) { if (tex) { #if defined(HAVE_D3D9) && !defined(__cplusplus) IDirect3DTexture9_Release(tex); #else tex->Release(); #endif } }
static void D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) { D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; if (!data) { return; } if (data->texture) { IDirect3DTexture9_Release(data->texture); } SDL_free(data); texture->driverdata = NULL; }
/** * It releases the scene resources. */ static void Direct3DDestroyScene(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc; if (d3dvtc) IDirect3DVertexBuffer9_Release(d3dvtc); LPDIRECT3DTEXTURE9 d3dtex = sys->d3dtex; if (d3dtex) IDirect3DTexture9_Release(d3dtex); sys->d3dvtc = NULL; sys->d3dtex = NULL; msg_Dbg(vd, "Direct3D scene released successfully"); }
CR_API void crTextureFree(CrTexture* self) { CrTextureImpl* impl = (CrTextureImpl*)self; if(nullptr == self) return; if(nullptr != impl->d3dtex) { IDirect3DTexture9_Release(impl->d3dtex); } if(nullptr != impl->d3dsurf) { IDirect3DSurface9_Release(impl->d3dsurf); } crMem()->free(self, "CrTexture"); }
static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface) { struct d3dx_font *This = impl_from_ID3DXFont(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u\n", iface, ref); if (!ref) { if (This->texture) { IDirect3DTexture9_Release(This->texture); DeleteObject(This->bitmap); } DeleteObject(This->hfont); DeleteDC(This->hdc); IDirect3DDevice9_Release(This->device); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static HRESULT WINAPI ID3DXSpriteImpl_OnResetDevice(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); int i; TRACE("(%p)->()\n", This); for(i=0; i<This->sprite_count; i++) if(This->sprites[i].texture) IDirect3DTexture9_Release(This->sprites[i].texture); This->sprite_count=0; This->flags=0; This->ready=FALSE; /* keep matrices */ /* device objects get restored on Begin */ return D3D_OK; }
static ULONG WINAPI ID3DXSpriteImpl_Release(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); ULONG ref=InterlockedDecrement(&This->ref); TRACE("(%p)->(): ReleaseRef to %d\n", This, ref); if(ref==0) { if(This->sprites) { int i; for(i=0; i<This->sprite_count; i++) if(This->sprites[i].texture) IDirect3DTexture9_Release(This->sprites[i].texture); HeapFree(GetProcessHeap(), 0, This->sprites); } if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock); if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl); if(This->device) IDirect3DDevice9_Release(This->device); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static void test_lod(IDirect3DDevice9 *device) { HRESULT hr; DWORD ret; IDirect3DTexture9 *texture; hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 3, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr); /* SetLOD is only supported on D3DPOOL_MANAGED textures, but it doesn't return a HRESULT, * so it can't return a normal error. Instead, the call is simply ignored */ ret = IDirect3DTexture9_SetLOD(texture, 0); ok(ret == 0, "IDirect3DTexture9_SetLOD returned %u, expected 0\n", ret); ret = IDirect3DTexture9_SetLOD(texture, 1); ok(ret == 0, "IDirect3DTexture9_SetLOD returned %u, expected 0\n", ret); ret = IDirect3DTexture9_SetLOD(texture, 2); ok(ret == 0, "IDirect3DTexture9_SetLOD returned %u, expected 0\n", ret); ret = IDirect3DTexture9_GetLOD(texture); ok(ret == 0, "IDirect3DTexture9_GetLOD returned %u, expected 0\n", ret); IDirect3DTexture9_Release(texture); }
static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); SPRITEVERTEX *vertices; int i, count=0, start; TRACE("(%p)->(): relay\n", This); if(!This->ready) return D3DERR_INVALIDCALL; if(!This->sprite_count) return D3D_OK; /* TODO: use of a vertex buffer here */ vertices=HeapAlloc(GetProcessHeap(), 0, sizeof(SPRITEVERTEX)*6*This->sprite_count); for(start=0; start<This->sprite_count; start+=count,count=0) { i=start; while(i<This->sprite_count && (count==0 || This->sprites[i].texture==This->sprites[i-1].texture)) { float spritewidth=(float)This->sprites[i].rect.right-(float)This->sprites[i].rect.left; float spriteheight=(float)This->sprites[i].rect.bottom-(float)This->sprites[i].rect.top; vertices[6*i ].pos.x = This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i ].pos.y = This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i ].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+1].pos.x = spritewidth + This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+1].pos.y = This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+1].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+2].pos.x = spritewidth + This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+2].pos.y = spriteheight + This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+2].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i+3].pos.x = This->sprites[i].pos.x - This->sprites[i].center.x; vertices[6*i+3].pos.y = spriteheight + This->sprites[i].pos.y - This->sprites[i].center.y; vertices[6*i+3].pos.z = This->sprites[i].pos.z - This->sprites[i].center.z; vertices[6*i ].col = This->sprites[i].color; vertices[6*i+1].col = This->sprites[i].color; vertices[6*i+2].col = This->sprites[i].color; vertices[6*i+3].col = This->sprites[i].color; vertices[6*i ].tex.x = (float)This->sprites[i].rect.left / (float)This->sprites[i].texw; vertices[6*i ].tex.y = (float)This->sprites[i].rect.top / (float)This->sprites[i].texh; vertices[6*i+1].tex.x = (float)This->sprites[i].rect.right / (float)This->sprites[i].texw; vertices[6*i+1].tex.y = (float)This->sprites[i].rect.top / (float)This->sprites[i].texh; vertices[6*i+2].tex.x = (float)This->sprites[i].rect.right / (float)This->sprites[i].texw; vertices[6*i+2].tex.y = (float)This->sprites[i].rect.bottom / (float)This->sprites[i].texh; vertices[6*i+3].tex.x = (float)This->sprites[i].rect.left / (float)This->sprites[i].texw; vertices[6*i+3].tex.y = (float)This->sprites[i].rect.bottom / (float)This->sprites[i].texh; vertices[6*i+4]=vertices[6*i]; vertices[6*i+5]=vertices[6*i+2]; D3DXVec3TransformCoordArray(&vertices[6*i].pos, sizeof(SPRITEVERTEX), &vertices[6*i].pos, sizeof(SPRITEVERTEX), &This->sprites[i].transform, 6); count++; i++; } IDirect3DDevice9_SetTexture(This->device, 0, (struct IDirect3DBaseTexture9 *)This->sprites[start].texture); IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl); IDirect3DDevice9_DrawPrimitiveUP(This->device, D3DPT_TRIANGLELIST, 2*count, vertices+6*start, sizeof(SPRITEVERTEX)); } HeapFree(GetProcessHeap(), 0, vertices); if(!(This->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE)) for(i=0; i<This->sprite_count; i++) IDirect3DTexture9_Release(This->sprites[i].texture); This->sprite_count=0; /* Flush may be called more than once, so we don't reset This->ready here */ return D3D_OK; }
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata; if (data->yuv) { if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { return -1; } UpdateYUVTextureData(texture); return 0; } else { #ifdef SDL_MEMORY_POOL_DEFAULT IDirect3DTexture9 *temp; RECT d3drect; D3DLOCKED_RECT locked; const Uint8 *src; Uint8 *dst; int row, length; HRESULT result; result = IDirect3DDevice9_CreateTexture(renderdata->device, texture->w, texture->h, 1, 0, PixelFormatToD3DFMT(texture-> format), D3DPOOL_SYSTEMMEM, &temp, NULL); if (FAILED(result)) { D3D_SetError("CreateTexture()", result); return -1; } d3drect.left = rect->x; d3drect.right = rect->x + rect->w; d3drect.top = rect->y; d3drect.bottom = rect->y + rect->h; result = IDirect3DTexture9_LockRect(temp, 0, &locked, &d3drect, 0); if (FAILED(result)) { IDirect3DTexture9_Release(temp); D3D_SetError("LockRect()", result); return -1; } src = pixels; dst = locked.pBits; length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += locked.Pitch; } IDirect3DTexture9_UnlockRect(temp, 0); result = IDirect3DDevice9_UpdateTexture(renderdata->device, (IDirect3DBaseTexture9 *) temp, (IDirect3DBaseTexture9 *) data->texture); IDirect3DTexture9_Release(temp); if (FAILED(result)) { D3D_SetError("UpdateTexture()", result); return -1; } #else RECT d3drect; D3DLOCKED_RECT locked; const Uint8 *src; Uint8 *dst; int row, length; HRESULT result; d3drect.left = rect->x; d3drect.right = rect->x + rect->w; d3drect.top = rect->y; d3drect.bottom = rect->y + rect->h; result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0); if (FAILED(result)) { D3D_SetError("LockRect()", result); return -1; } src = pixels; dst = locked.pBits; length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += locked.Pitch; } IDirect3DTexture9_UnlockRect(data->texture, 0); #endif // SDL_MEMORY_POOL_DEFAULT return 0; } }
void JBKRender_DestroyTexture(JBKNativeTexture nativeTexture) { IDirect3DTexture9_Release((IDirect3DTexture9*)nativeTexture); }
LPDIRECT3DTEXTURE9 D3DCacheTextureLookupSwizzled(d3d_texture_cache *pTextureCache, d3d_render_packet_new *pPacket, int effect) { LPDIRECT3DTEXTURE9 pTexture = NULL; D3DSURFACE_DESC surfDesc; d3d_texture_cache_entry *pTexEntry; list_type list; int curTex = 0; for (list = pTextureCache->textureList; list != NULL; list = list->next) { pTexEntry = (d3d_texture_cache_entry *)list->data; if ((pPacket->pDib->uniqueID == pTexEntry->pDibID) && (pPacket->pDib->uniqueID2 == pTexEntry->pDibID2) && (pPacket->pDib->frame == pTexEntry->frame)) { if ((pPacket->xLat0 == pTexEntry->xLat0) && (pPacket->xLat0 == pTexEntry->xLat0) && (effect == pTexEntry->effects)) { return pTexEntry->pTexture; } } } while (pTextureCache->size > pTextureCache->max) { pTexEntry = (d3d_texture_cache_entry *)list_first_item(pTextureCache->textureList); if (pTexEntry) { if (pTexEntry->pTexture) IDirect3DTexture9_Release(pTexEntry->pTexture); pTexEntry->pTexture = NULL; pTextureCache->size -= pTexEntry->size; free(pTextureCache->textureList->data); pTextureCache->textureList = list_delete_first(pTextureCache->textureList); } } pTexture = D3DRenderTextureCreateFromBGFSwizzled(pPacket->pDib, pPacket->xLat0, pPacket->xLat1, effect); if (NULL == pTexture) return NULL; pTexEntry = (d3d_texture_cache_entry *)D3DRenderMalloc(sizeof(d3d_texture_cache_entry)); assert(pTexEntry); IDirect3DTexture9_GetLevelDesc(pTexture, 0, &surfDesc); pTexEntry->effects = effect; pTexEntry->pDibID = pPacket->pDib->uniqueID; pTexEntry->pDibID2 = pPacket->pDib->uniqueID2; pTexEntry->frame = pPacket->pDib->frame; pTexEntry->pTexture = pTexture; pTexEntry->xLat0 = pPacket->xLat0; pTexEntry->xLat1 = pPacket->xLat1; pTexEntry->size = getTextureSizeBytes(surfDesc); pTextureCache->textureList = list_add_item(pTextureCache->textureList, pTexEntry); pTextureCache->size += pTexEntry->size; return pTexEntry->pTexture; }
IDirect3DTexture9* ILAPIENTRY ilutD3D9Texture(IDirect3DDevice9 *Device) { IDirect3DTexture9 *Texture; // D3DLOCKED_RECT Rect; D3DFORMAT Format; ILimage *Image; ILenum DXTCFormat; ILuint Size; ILubyte *Buffer; Image = ilutCurImage = ilGetCurImage(); if (ilutCurImage == NULL) { ilSetError(ILUT_ILLEGAL_OPERATION); return NULL; } if (!FormatsDX9Checked) CheckFormatsDX9(Device); if (ilutGetBoolean(ILUT_D3D_USE_DXTC) && FormatsDX9supported[3] && FormatsDX9supported[4] && FormatsDX9supported[5]) { if (ilutCurImage->DxtcData != NULL && ilutCurImage->DxtcSize != 0) { ILuint dxtcFormat = ilutGetInteger(ILUT_DXTC_FORMAT); Format = D3DGetDXTCNumDX9(ilutCurImage->DxtcFormat); ilutSetInteger(ILUT_DXTC_FORMAT, ilutCurImage->DxtcFormat); Texture = iD3DMakeTexture(Device, ilutCurImage->DxtcData, ilutCurImage->DxtcSize, ilutCurImage->Width, ilutCurImage->Height, Format, ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT ? D3DPOOL_SYSTEMMEM : ilutGetInteger(ILUT_D3D_POOL), ilutGetInteger(ILUT_D3D_MIPLEVELS)); if (!Texture) return NULL; iD3D9CreateMipmaps(Texture, Image); if (ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT) { IDirect3DTexture9 *SysTex = Texture; // copy texture to device memory if (FAILED(IDirect3DDevice9_CreateTexture(Device, ilutCurImage->Width, ilutCurImage->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, D3DPOOL_DEFAULT, &Texture, NULL))) { IDirect3DTexture9_Release(SysTex); return NULL; } if (FAILED(IDirect3DDevice9_UpdateTexture(Device, (LPDIRECT3DBASETEXTURE9)SysTex, (LPDIRECT3DBASETEXTURE9)Texture))) { IDirect3DTexture9_Release(SysTex); return NULL; } IDirect3DTexture9_Release(SysTex); } ilutSetInteger(ILUT_DXTC_FORMAT, dxtcFormat); goto success; } if (ilutGetBoolean(ILUT_D3D_GEN_DXTC)) { DXTCFormat = ilutGetInteger(ILUT_DXTC_FORMAT); /* Image = MakeD3D9Compliant(Device, &Format); if (Image == NULL) { if (Image != ilutCurImage) ilCloseImage(Image); return NULL; } */ Size = ilGetDXTCData(NULL, 0, DXTCFormat); if (Size != 0) { Buffer = (ILubyte*)ialloc(Size); if (Buffer == NULL) return NULL; Size = ilGetDXTCData(Buffer, Size, DXTCFormat); if (Size == 0) { ifree(Buffer); return NULL; } Format = D3DGetDXTCNumDX9(DXTCFormat); Texture = iD3DMakeTexture(Device, Buffer, Size, ilutCurImage->Width, ilutCurImage->Height, Format, ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT ? D3DPOOL_SYSTEMMEM : ilutGetInteger(ILUT_D3D_POOL), ilutGetInteger(ILUT_D3D_MIPLEVELS)); if (!Texture) return NULL; iD3D9CreateMipmaps(Texture, Image); if (ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT) { IDirect3DTexture9 *SysTex = Texture; if (FAILED(IDirect3DDevice9_CreateTexture(Device, ilutCurImage->Width, ilutCurImage->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, D3DPOOL_DEFAULT, &Texture, NULL))) { IDirect3DTexture9_Release(SysTex); return NULL; } if (FAILED(IDirect3DDevice9_UpdateTexture(Device, (LPDIRECT3DBASETEXTURE9)SysTex, (LPDIRECT3DBASETEXTURE9)Texture))) { IDirect3DTexture9_Release(SysTex); return NULL; } IDirect3DTexture9_Release(SysTex); } goto success; } } } Image = MakeD3D9Compliant(Device, &Format); if (Image == NULL) { if (Image != ilutCurImage) ilCloseImage(Image); return NULL; } Texture = iD3DMakeTexture(Device, Image->Data, Image->SizeOfPlane, Image->Width, Image->Height, Format, ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT ? D3DPOOL_SYSTEMMEM : ilutGetInteger(ILUT_D3D_POOL), ilutGetInteger(ILUT_D3D_MIPLEVELS)); if (!Texture) return NULL; iD3D9CreateMipmaps(Texture, Image); if (ilutGetInteger(ILUT_D3D_POOL) == D3DPOOL_DEFAULT) { IDirect3DTexture9 *SysTex = Texture; // create texture in system memory if (FAILED(IDirect3DDevice9_CreateTexture(Device, Image->Width, Image->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, ilutGetInteger(ILUT_D3D_POOL), &Texture, NULL))) { IDirect3DTexture9_Release(SysTex); return NULL; } if (FAILED(IDirect3DDevice9_UpdateTexture(Device, (LPDIRECT3DBASETEXTURE9)SysTex, (LPDIRECT3DBASETEXTURE9)Texture))) { IDirect3DTexture9_Release(SysTex); return NULL; } IDirect3DTexture9_Release(SysTex); } // if (Image != ilutCurImage) // ilCloseImage(Image); success: if (Image != ilutCurImage) ilCloseImage(Image); return Texture; }
/** * It allocates and initializes the resources needed to render the scene. */ static int Direct3DCreateScene(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev; HRESULT hr; /* * Create a texture for use when rendering a scene * for performance reason, texture format is identical to backbuffer * which would usually be a RGB format */ LPDIRECT3DTEXTURE9 d3dtex; hr = IDirect3DDevice9_CreateTexture(d3ddev, sys->d3dpp.BackBufferWidth, sys->d3dpp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, sys->d3dpp.BackBufferFormat, D3DPOOL_DEFAULT, &d3dtex, NULL); if (FAILED(hr)) { msg_Err(vd, "Failed to create texture. (hr=0x%lx)", hr); return VLC_EGENERIC; } /* ** Create a vertex buffer for use when rendering scene */ LPDIRECT3DVERTEXBUFFER9 d3dvtc; hr = IDirect3DDevice9_CreateVertexBuffer(d3ddev, sizeof(CUSTOMVERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &d3dvtc, NULL); if (FAILED(hr)) { msg_Err(vd, "Failed to create vertex buffer. (hr=0x%lx)", hr); IDirect3DTexture9_Release(d3dtex); return VLC_EGENERIC; } /* */ sys->d3dtex = d3dtex; sys->d3dvtc = d3dvtc; // Texture coordinates outside the range [0.0, 1.0] are set // to the texture color at 0.0 or 1.0, respectively. IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); // Set linear filtering quality IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // set maximum ambient light IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255)); // Turn off culling IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_CULLMODE, D3DCULL_NONE); // Turn off the zbuffer IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZENABLE, D3DZB_FALSE); // Turn off lights IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_LIGHTING, FALSE); // Enable dithering IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DITHERENABLE, TRUE); // disable stencil IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_STENCILENABLE, FALSE); // manage blending IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHATESTENABLE,TRUE); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAREF, 0x10); IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAFUNC,D3DCMP_GREATER); // Set texture states IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLOROP,D3DTOP_MODULATE); IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG1,D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG2,D3DTA_DIFFUSE); // turn off alpha operation IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); msg_Dbg(vd, "Direct3D scene created successfully"); return VLC_SUCCESS; }
static void test_filter(IDirect3DDevice9 *device) { HRESULT hr; IDirect3DTexture9 *texture; IDirect3D9 *d3d9; DWORD passes = 0; unsigned int i; struct filter_tests { DWORD magfilter, minfilter, mipfilter; BOOL has_texture; HRESULT result; } tests[] = { { D3DTEXF_NONE, D3DTEXF_NONE, D3DTEXF_NONE, FALSE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_NONE, FALSE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_NONE, D3DTEXF_POINT, D3DTEXF_NONE, FALSE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_POINT, D3DTEXF_POINT, D3DTEXF_NONE, FALSE, D3D_OK }, { D3DTEXF_POINT, D3DTEXF_POINT, D3DTEXF_POINT, FALSE, D3D_OK }, { D3DTEXF_NONE, D3DTEXF_NONE, D3DTEXF_NONE, TRUE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_NONE, TRUE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_POINT, D3DTEXF_POINT, D3DTEXF_NONE, TRUE, D3D_OK }, { D3DTEXF_POINT, D3DTEXF_POINT, D3DTEXF_POINT, TRUE, D3D_OK }, { D3DTEXF_NONE, D3DTEXF_NONE, D3DTEXF_NONE, TRUE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_LINEAR, D3DTEXF_NONE, D3DTEXF_NONE, TRUE, D3DERR_UNSUPPORTEDTEXTUREFILTER }, { D3DTEXF_LINEAR, D3DTEXF_POINT, D3DTEXF_NONE, TRUE, E_FAIL }, { D3DTEXF_POINT, D3DTEXF_LINEAR, D3DTEXF_NONE, TRUE, E_FAIL }, { D3DTEXF_POINT, D3DTEXF_POINT, D3DTEXF_LINEAR, TRUE, E_FAIL }, }; hr = IDirect3DDevice9_GetDirect3D(device, &d3d9); ok(hr == D3D_OK, "IDirect3DDevice9_GetDirect3D(levels = 1) returned %08x\n", hr); hr = IDirect3D9_CheckDeviceFormat(d3d9, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F); if(FAILED(hr)) { skip("D3DFMT_A32B32G32R32F not supported\n"); goto out; } hr = IDirect3D9_CheckDeviceFormat(d3d9, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F); if(SUCCEEDED(hr)) { skip("D3DFMT_A32B32G32R32F supports filtering\n"); goto out; } hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 0, 0, D3DFMT_A32B32G32R32F, D3DPOOL_MANAGED, &texture, 0); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr); /* Needed for ValidateDevice */ hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1); ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr); for(i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) { if(tests[i].has_texture) { hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture); ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr); } else { hr = IDirect3DDevice9_SetTexture(device, 0, NULL); ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr); } hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, tests[i].magfilter); ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState returned %08x\n", hr); hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, tests[i].minfilter); ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState returned %08x\n", hr); hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, tests[i].mipfilter); ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState returned %08x\n", hr); passes = 0xdeadbeef; hr = IDirect3DDevice9_ValidateDevice(device, &passes); ok(hr == tests[i].result, "ValidateDevice failed: Texture %s, min %u, mag %u, mip %u. Got %08x, expected %08x\n", tests[i].has_texture ? "TRUE" : "FALSE", tests[i].magfilter, tests[i].minfilter, tests[i].mipfilter, hr, tests[i].result); if(SUCCEEDED(hr)) { ok(passes != 0, "ValidateDevice succeeded, passes is %u\n", passes); } else { ok(passes == 0xdeadbeef, "ValidateDevice failed, passes is %u\n", passes); } } hr = IDirect3DDevice9_SetTexture(device, 0, NULL); ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture returned %#x.\n", hr); IDirect3DTexture9_Release(texture); out: IDirect3D9_Release(d3d9); }
static void test_mipmap_gen(IDirect3DDevice9 *device) { HRESULT hr; IDirect3D9 *d3d9; IDirect3DTexture9 *texture = NULL; IDirect3DSurface9 *surface; DWORD levels; D3DSURFACE_DESC desc; int i; D3DLOCKED_RECT lr; hr = IDirect3DDevice9_GetDirect3D(device, &d3d9); ok(hr == D3D_OK, "IDirect3DDevice9_GetDirect3D returned %#x\n", hr); hr = IDirect3D9_CheckDeviceFormat(d3d9, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8); if(FAILED(hr)) { skip("No mipmap generation support\n"); return; } /* testing shows that autogenmipmap and rendertarget are mutually exclusive options */ hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, (D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP), D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, 0); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned 0x%08x, expected 0x%08x\n", hr, D3D_OK); if (texture) IDirect3DTexture9_Release(texture); texture = NULL; hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed(%08x)\n", hr); if (SUCCEEDED(hr)) { D3DTEXTUREFILTERTYPE fltt; fltt = IDirect3DTexture9_GetAutoGenFilterType(texture); ok(D3DTEXF_LINEAR == fltt /* || broken(D3DTEXF_POINT == fltt)*/, "GetAutoGenFilterType returned default %d\n", fltt); hr = IDirect3DTexture9_SetAutoGenFilterType(texture, D3DTEXF_NONE); todo_wine ok(hr == D3DERR_INVALIDCALL, "SetAutoGenFilterType D3DTEXF_NONE returned %08x\n", hr); hr = IDirect3DTexture9_SetAutoGenFilterType(texture, D3DTEXF_ANISOTROPIC); ok(hr == D3D_OK, "SetAutoGenFilterType D3DTEXF_ANISOTROPIC returned %08x\n", hr); fltt = IDirect3DTexture9_GetAutoGenFilterType(texture); ok(D3DTEXF_ANISOTROPIC == fltt, "GetAutoGenFilterType returned %d\n", fltt); hr = IDirect3DTexture9_SetAutoGenFilterType(texture, D3DTEXF_LINEAR); ok(hr == D3D_OK, "SetAutoGenFilterType D3DTEXF_LINEAR returned %08x\n", hr); } levels = IDirect3DTexture9_GetLevelCount(texture); ok(levels == 1, "Got %d levels, expected 1\n", levels); for(i = 0; i < 6 /* 64 = 2 ^ 6 */; i++) { surface = NULL; hr = IDirect3DTexture9_GetSurfaceLevel(texture, i, &surface); ok(hr == (i == 0 ? D3D_OK : D3DERR_INVALIDCALL), "GetSurfaceLevel on level %d returned %#x\n", i, hr); if(surface) IDirect3DSurface9_Release(surface); hr = IDirect3DTexture9_GetLevelDesc(texture, i, &desc); ok(hr == (i == 0 ? D3D_OK : D3DERR_INVALIDCALL), "GetLevelDesc on level %d returned %#x\n", i, hr); hr = IDirect3DTexture9_LockRect(texture, i, &lr, NULL, 0); ok(hr == (i == 0 ? D3D_OK : D3DERR_INVALIDCALL), "LockRect on level %d returned %#x\n", i, hr); if(SUCCEEDED(hr)) { hr = IDirect3DTexture9_UnlockRect(texture, i); ok(hr == D3D_OK, "Unlock returned %08x\n", hr); } } IDirect3DTexture9_Release(texture); hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 2 /* levels */, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateTexture(levels = 2) returned %08x\n", hr); hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 6 /* levels */, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateTexture(levels = 6) returned %08x\n", hr); hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1 /* levels */, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture(levels = 1) returned %08x\n", hr); levels = IDirect3DTexture9_GetLevelCount(texture); ok(levels == 1, "Got %d levels, expected 1\n", levels); IDirect3DTexture9_Release(texture); }
static void test_ID3DXSprite(IDirect3DDevice9 *device) { ID3DXSprite *sprite; IDirect3D9 *d3d; IDirect3DDevice9 *cmpdev; IDirect3DTexture9 *tex1, *tex2; D3DXMATRIX mat, cmpmat; D3DVIEWPORT9 vp; RECT rect; D3DXVECTOR3 pos, center; HRESULT hr; IDirect3DDevice9_GetDirect3D(device, &d3d); hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); IDirect3D9_Release(d3d); ok (hr == D3D_OK, "D3DFMT_A8R8G8B8 not supported\n"); if (FAILED(hr)) return; hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL); ok (hr == D3D_OK, "Failed to create first texture (error code: %#x)\n", hr); if (FAILED(hr)) return; hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL); ok (hr == D3D_OK, "Failed to create second texture (error code: %#x)\n", hr); if (FAILED(hr)) { IDirect3DTexture9_Release(tex1); return; } /* Test D3DXCreateSprite */ hr = D3DXCreateSprite(device, NULL); ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateSprite(NULL, &sprite); ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateSprite(device, &sprite); ok (hr == D3D_OK, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3D_OK); /* Test ID3DXSprite_GetDevice */ hr = ID3DXSprite_GetDevice(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev == NULL */ ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev != NULL */ ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DDevice9_Release(device); IDirect3DDevice9_Release(device); /* Test ID3DXSprite_GetTransform */ hr = ID3DXSprite_GetTransform(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "GetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_GetTransform(sprite, &mat); ok (hr == D3D_OK, "GetTransform returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { D3DXMATRIX identity; D3DXMatrixIdentity(&identity); check_mat(mat, identity); } /* Test ID3DXSprite_SetTransform */ /* Set a transform and test if it gets returned correctly */ U(mat).m[0][0]=2.1f; U(mat).m[0][1]=6.5f; U(mat).m[0][2]=-9.6f; U(mat).m[0][3]=1.7f; U(mat).m[1][0]=4.2f; U(mat).m[1][1]=-2.5f; U(mat).m[1][2]=2.1f; U(mat).m[1][3]=5.5f; U(mat).m[2][0]=-2.6f; U(mat).m[2][1]=0.3f; U(mat).m[2][2]=8.6f; U(mat).m[2][3]=8.4f; U(mat).m[3][0]=6.7f; U(mat).m[3][1]=-5.1f; U(mat).m[3][2]=6.1f; U(mat).m[3][3]=2.2f; hr = ID3DXSprite_SetTransform(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "SetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_SetTransform(sprite, &mat); ok (hr == D3D_OK, "SetTransform returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { hr=ID3DXSprite_GetTransform(sprite, &cmpmat); if(SUCCEEDED(hr)) check_mat(cmpmat, mat); else skip("GetTransform returned %#x\n", hr); } /* Test ID3DXSprite_SetWorldViewLH/RH */ todo_wine { hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, &mat); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, &mat); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, NULL); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, NULL); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, &mat); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, &mat); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, NULL); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, NULL); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); } IDirect3DDevice9_BeginScene(device); /* Test ID3DXSprite_Begin*/ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &mat); D3DXMatrixIdentity(&cmpmat); check_mat(mat, cmpmat); IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &mat); check_mat(mat, cmpmat); IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &mat); IDirect3DDevice9_GetViewport(device, &vp); D3DXMatrixOrthoOffCenterLH(&cmpmat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ); check_mat(mat, cmpmat); /* Test ID3DXSprite_Flush and ID3DXSprite_End */ hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); /* May not be called before next Begin */ ok (hr == D3DERR_INVALIDCALL, "Flush returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_End(sprite); ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* Test ID3DXSprite_Draw */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); if(FAILED(hr)) skip("Couldn't ID3DXSprite_Begin, can't test ID3DXSprite_Draw\n"); else { /* Feed the sprite batch */ int texref1, texref2; SetRect(&rect, 53, 12, 142, 165); pos.x = 2.2f; pos.y = 4.5f; pos.z = 5.1f; center.x = 11.3f; center.y = 3.4f; center.z = 1.2f; texref1 = get_ref((IUnknown*)tex1); texref2 = get_ref((IUnknown*)tex2); hr = ID3DXSprite_Draw(sprite, NULL, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3DERR_INVALIDCALL, "Draw returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB( 3, 45, 66)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, NULL, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, &rect, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, NULL, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, NULL, NULL, NULL, 0); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); check_ref((IUnknown*)tex1, texref1+5); check_ref((IUnknown*)tex2, texref2+1); hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); /* Flushing twice should work */ ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); check_ref((IUnknown*)tex1, texref1); check_ref((IUnknown*)tex2, texref2); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); } /* Test ID3DXSprite_OnLostDevice and ID3DXSprite_OnResetDevice */ /* Both can be called twice */ hr = ID3DXSprite_OnLostDevice(sprite); ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnLostDevice(sprite); ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); /* Make sure everything works like before */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); /* OnResetDevice makes the interface "forget" the Begin call */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); IDirect3DDevice9_EndScene(device); check_release((IUnknown*)sprite, 0); check_release((IUnknown*)tex2, 0); check_release((IUnknown*)tex1, 0); }
static void test_D3DXCreateTexture(IDirect3DDevice9 *device) { IDirect3DTexture9 *texture; D3DSURFACE_DESC desc; D3DCAPS9 caps; UINT mipmaps; HRESULT hr; IDirect3DDevice9_GetDeviceCaps(device, &caps); hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* width and height tests */ hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256); ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256); IDirect3DTexture9_Release(texture); } hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1); ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1); IDirect3DTexture9_Release(texture); } if (caps.TextureCaps & D3DPTEXTURECAPS_POW2) skip("Hardware only supports pow2 textures\n"); else { hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture); ok((hr == D3D_OK) || /* may not work with conditional NPOT */ ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)), "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); /* Conditional NPOT may create a texture with different dimensions, so allow those situations instead of returning a fail */ ok(desc.Width == 63 || (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL), "Returned width %d, expected %d\n", desc.Width, 63); ok(desc.Height == 63 || (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL), "Returned height %d, expected %d\n", desc.Height, 63); IDirect3DTexture9_Release(texture); } } /* mipmaps */ hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { mipmaps = IDirect3DTexture9_GetLevelCount(texture); ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7); IDirect3DTexture9_Release(texture); } hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { mipmaps = IDirect3DTexture9_GetLevelCount(texture); ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9); IDirect3DTexture9_Release(texture); } hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { mipmaps = IDirect3DTexture9_GetLevelCount(texture); ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1); IDirect3DTexture9_Release(texture); } hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { mipmaps = IDirect3DTexture9_GetLevelCount(texture); ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1); IDirect3DTexture9_Release(texture); } /* usage */ hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); /* format */ hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8); IDirect3DTexture9_Release(texture); } hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); if (texture) { hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8); IDirect3DTexture9_Release(texture); } /* D3DXCreateTextureFromResource */ todo_wine { hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture); ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK); if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture); } hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture); ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK); if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture); hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture); ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture); ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* D3DXCreateTextureFromResourceEx */ hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture); ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK); if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture); hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture); ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); hr = D3DXCreateTextureFromResourceExA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture); ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, NULL); ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); }
CR_API CrBool crTextureCommit(CrTexture* self, const void* data) { CrTextureImpl* impl = (CrTextureImpl*)self; if(nullptr == self) return CrFalse; if(nullptr == impl->apiFormatMapping) return CrFalse; if(self->surfCount == 1) { HRESULT hr; size_t i; IDirect3DTexture9* stageTex; hr = IDirect3DDevice9_CreateTexture(crContextImpl()->d3ddev, self->width, self->height, self->mipCount, 0, impl->apiFormatMapping->d3dFormat, D3DPOOL_SYSTEMMEM, &stageTex, nullptr); if(FAILED(hr)) { crDbgStr("d3d9 failed to create texture %8x", hr); return CrFalse; } for(i=0; i<self->mipCount; ++i) { size_t mipW, mipH; D3DLOCKED_RECT locked; unsigned char* mipdata = crTextureGetMipLevel(self, (unsigned char*)data, 0, i, &mipW, &mipH); hr = IDirect3DTexture9_LockRect(stageTex, i, &locked, nullptr, 0); if(FAILED(hr)) continue; if(CrGpuFormat_UnormR8G8B8A8 != self->format) { memcpy(locked.pBits, mipdata, mipW * mipH * impl->apiFormatMapping->pixelSize); } else { // CrGpuFormat_UnormR8G8B8A8 need to flip the endian since we actually use the OpenGL's layout char* dst = locked.pBits; char* src = mipdata; size_t cnt = mipW * mipH; size_t i; for(i = 0; i<cnt; ++i) { dst[0] = src[2]; dst[1] = src[1]; dst[2] = src[0]; dst[3] = src[3]; dst += 4; src += 4; } } IDirect3DTexture9_UnlockRect(stageTex, i); } IDirect3DDevice9_UpdateTexture(crContextImpl()->d3ddev, (IDirect3DBaseTexture9*)stageTex, (IDirect3DBaseTexture9*)impl->d3dtex); IDirect3DTexture9_Release(stageTex); } return CrTrue; }
static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color) { struct d3dx_font *This = impl_from_ID3DXFont(iface); RECT calc_rect; INT height; TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x\n", iface, sprite, debugstr_w(string), count, wine_dbgstr_rect(rect), format, color); if (!string || count == 0) return 0; if (count < 0) count = lstrlenW(string); /* Strip terminating NULL characters */ while (count > 0 && !string[count-1]) count--; if (rect) calc_rect = *rect; height = DrawTextW(This->hdc, string, count, &calc_rect, format | DT_CALCRECT); if (format & DT_CALCRECT) { if (rect) *rect = calc_rect; return height; } if (format & DT_CENTER) { UINT new_width = calc_rect.right - calc_rect.left; calc_rect.left = (rect->right + rect->left - new_width) / 2; calc_rect.right = calc_rect.left + new_width; } if (height && (calc_rect.left < calc_rect.right)) { D3DLOCKED_RECT locked_rect; D3DXVECTOR3 position; UINT text_width, text_height; RECT text_rect; ID3DXSprite *target = sprite; HRESULT hr; int i, j; /* Get rect position and dimensions */ position.x = calc_rect.left; position.y = calc_rect.top; position.z = 0; text_width = calc_rect.right - calc_rect.left; text_height = calc_rect.bottom - calc_rect.top; text_rect.left = 0; text_rect.top = 0; text_rect.right = text_width; text_rect.bottom = text_height; /* We need to flush as it seems all draws in the begin/end sequence use only the latest updated texture */ if (sprite) ID3DXSprite_Flush(sprite); /* Extend texture and DIB section to contain text */ if ((text_width > This->tex_width) || (text_height > This->tex_height)) { BITMAPINFOHEADER header; if (text_width > This->tex_width) This->tex_width = make_pow2(text_width); if (text_height > This->tex_height) This->tex_height = make_pow2(text_height); if (This->texture) { IDirect3DTexture9_Release(This->texture); DeleteObject(This->bitmap); } hr = D3DXCreateTexture(This->device, This->tex_width, This->tex_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &This->texture); if (FAILED(hr)) { This->texture = NULL; return 0; } header.biSize = sizeof(header); header.biWidth = This->tex_width; header.biHeight = -This->tex_height; header.biPlanes = 1; header.biBitCount = 32; header.biCompression = BI_RGB; header.biSizeImage = sizeof(DWORD) * This->tex_width * This->tex_height; header.biXPelsPerMeter = 0; header.biYPelsPerMeter = 0; header.biClrUsed = 0; header.biClrImportant = 0; This->bitmap = CreateDIBSection(This->hdc, (const BITMAPINFO*)&header, DIB_RGB_COLORS, (void**)&This->bits, NULL, 0); if (!This->bitmap) { IDirect3DTexture9_Release(This->texture); This->texture = NULL; return 0; } SelectObject(This->hdc, This->bitmap); } if (FAILED(IDirect3DTexture9_LockRect(This->texture, 0, &locked_rect, &text_rect, D3DLOCK_DISCARD))) return 0; /* Clear rect */ for (i = 0; i < text_height; i++) memset(This->bits + i * This->tex_width * sizeof(DWORD), 0, text_width * sizeof(DWORD)); DrawTextW(This->hdc, string, count, &text_rect, format); /* All RGB components are equal so take one as alpha and set RGB * color to white, so it can be modulated with color parameter */ for (i = 0; i < text_height; i++) { DWORD *src = (DWORD *)This->bits + i * This->tex_width; DWORD *dst = (DWORD *)((BYTE *)locked_rect.pBits + i * locked_rect.Pitch); for (j = 0; j < text_width; j++) { *dst++ = (*src++ << 24) | 0xFFFFFF; } } IDirect3DTexture9_UnlockRect(This->texture, 0); if (!sprite) { hr = D3DXCreateSprite(This->device, &target); if (FAILED(hr)) return 0; ID3DXSprite_Begin(target, 0); } hr = target->lpVtbl->Draw(target, This->texture, &text_rect, NULL, &position, color); if (!sprite) { ID3DXSprite_End(target); ID3DXSprite_Release(target); } if (FAILED(hr)) return 0; } return height; }