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; }
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); }
static int _al_draw_prim_raw(ALLEGRO_BITMAP* texture, const void* vtx, const ALLEGRO_VERTEX_DECL* decl, const int* indices, int num_vtx, int type) { int stride = decl ? decl->stride : (int)sizeof(ALLEGRO_VERTEX); int num_primitives = 0; ALLEGRO_DISPLAY *display; LPDIRECT3DDEVICE9 device; LPDIRECT3DBASETEXTURE9 d3d_texture; DWORD old_wrap_state[2]; DWORD old_ttf_state; int min_idx = 0, max_idx = num_vtx - 1; if(indices) { int ii; for(ii = 0; ii < num_vtx; ii++) { int idx = indices[ii]; if(ii == 0) { min_idx = idx; max_idx = idx; } else if (idx < min_idx) { min_idx = idx; } else if (idx > max_idx) { max_idx = idx; } } } display = al_get_current_display(); device = al_d3d_get_device(display); if(decl) { if(decl->d3d_decl) { IDirect3DDevice9_SetVertexDeclaration(device, (IDirect3DVertexDeclaration9*)decl->d3d_decl); } else { return _al_draw_prim_soft(texture, vtx, decl, 0, num_vtx, type); } } else { IDirect3DDevice9_SetFVF(device, A5V_FVF); } set_blender(display); if (texture) { int tex_x, tex_y; D3DSURFACE_DESC desc; float mat[4][4] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; IDirect3DTexture9_GetLevelDesc(al_d3d_get_video_texture(texture), 0, &desc); al_get_d3d_texture_position(texture, &tex_x, &tex_y); if(decl) { if(decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL].attribute) { mat[0][0] = 1.0f / desc.Width; mat[1][1] = 1.0f / desc.Height; } else { mat[0][0] = (float)al_get_bitmap_width(texture) / desc.Width; mat[1][1] = (float)al_get_bitmap_height(texture) / desc.Height; } } else { mat[0][0] = 1.0f / desc.Width; mat[1][1] = 1.0f / desc.Height; } mat[2][0] = (float)tex_x / desc.Width; mat[2][1] = (float)tex_y / desc.Height; IDirect3DDevice9_GetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, &old_ttf_state); IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, (D3DMATRIX *)&mat); d3d_texture = (LPDIRECT3DBASETEXTURE9)al_d3d_get_video_texture(texture); IDirect3DDevice9_SetTexture(device, 0, d3d_texture); } else { IDirect3DDevice9_SetTexture(device, 0, NULL); } IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_ADDRESSU, &old_wrap_state[0]); IDirect3DDevice9_GetSamplerState(device, 0, D3DSAMP_ADDRESSV, &old_wrap_state[1]); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); if(!indices) { switch (type) { case ALLEGRO_PRIM_LINE_LIST: { num_primitives = num_vtx / 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINELIST, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_STRIP: { num_primitives = num_vtx - 1; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINESTRIP, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_LOOP: { int in[2]; in[0] = 0; in[1] = num_vtx-1; num_primitives = num_vtx - 1; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_LINESTRIP, num_primitives, vtx, stride); IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, 0, num_vtx, 1, in, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_LIST: { num_primitives = num_vtx / 3; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_STRIP: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_FAN: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLEFAN, num_primitives, vtx, stride); break; }; case ALLEGRO_PRIM_POINT_LIST: { num_primitives = num_vtx; IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, num_primitives, vtx, stride); break; }; } } else { switch (type) { case ALLEGRO_PRIM_LINE_LIST: { num_primitives = num_vtx / 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_STRIP: { num_primitives = num_vtx - 1; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_LINE_LOOP: { int in[2]; num_primitives = num_vtx - 1; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); in[0] = indices[0]; in[1] = indices[num_vtx-1]; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_LINELIST, min_idx, max_idx + 1, 1, in, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_LIST: { num_primitives = num_vtx / 3; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_STRIP: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLESTRIP, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_TRIANGLE_FAN: { num_primitives = num_vtx - 2; IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLEFAN, min_idx, max_idx + 1, num_primitives, indices, D3DFMT_INDEX32, vtx, stride); break; }; case ALLEGRO_PRIM_POINT_LIST: { /* * D3D does not support point lists in indexed mode, so we draw them using the non-indexed mode. To gain at least a semblance * of speed, we detect consecutive runs of vertices and draw them using a single DrawPrimitiveUP call */ int ii = 0; int start_idx = indices[0]; int run_length = 0; for(ii = 0; ii < num_vtx; ii++) { run_length++; if(indices[ii] + 1 != indices[ii + 1] || ii == num_vtx - 1) { IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, run_length, (const char*)vtx + start_idx * stride, stride); if(ii != num_vtx - 1) start_idx = indices[ii + 1]; run_length = 0; } } break; }; } } IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, old_wrap_state[0]); IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, old_wrap_state[1]); if(texture) { IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, old_ttf_state); } return num_primitives; }
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 HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9 *texture, const RECT *rect, const D3DXVECTOR3 *center, const D3DXVECTOR3 *position, D3DCOLOR color) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); D3DSURFACE_DESC texdesc; TRACE("iface %p, texture %p, rect %s, center %p, position %p, color 0x%08x.\n", iface, texture, wine_dbgstr_rect(rect), center, position, color); if(texture==NULL) return D3DERR_INVALIDCALL; if(!This->ready) return D3DERR_INVALIDCALL; if(This->allocated_sprites==0) { This->sprites=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 32*sizeof(SPRITE)); This->allocated_sprites=32; } else if(This->allocated_sprites<=This->sprite_count) { This->allocated_sprites=This->allocated_sprites*3/2; This->sprites=HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->sprites, This->allocated_sprites*sizeof(SPRITE)); } This->sprites[This->sprite_count].texture=texture; if(!(This->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE)) IDirect3DTexture9_AddRef(texture); /* Reuse the texture desc if possible */ if(This->sprite_count) { if(This->sprites[This->sprite_count-1].texture!=texture) { IDirect3DTexture9_GetLevelDesc(texture, 0, &texdesc); } else { texdesc.Width=This->sprites[This->sprite_count-1].texw; texdesc.Height=This->sprites[This->sprite_count-1].texh; } } else IDirect3DTexture9_GetLevelDesc(texture, 0, &texdesc); This->sprites[This->sprite_count].texw=texdesc.Width; This->sprites[This->sprite_count].texh=texdesc.Height; if(rect==NULL) { This->sprites[This->sprite_count].rect.left=0; This->sprites[This->sprite_count].rect.top=0; This->sprites[This->sprite_count].rect.right=texdesc.Width; This->sprites[This->sprite_count].rect.bottom=texdesc.Height; } else This->sprites[This->sprite_count].rect=*rect; if(center==NULL) { This->sprites[This->sprite_count].center.x=0.0f; This->sprites[This->sprite_count].center.y=0.0f; This->sprites[This->sprite_count].center.z=0.0f; } else This->sprites[This->sprite_count].center=*center; if(position==NULL) { This->sprites[This->sprite_count].pos.x=0.0f; This->sprites[This->sprite_count].pos.y=0.0f; This->sprites[This->sprite_count].pos.z=0.0f; } else This->sprites[This->sprite_count].pos=*position; This->sprites[This->sprite_count].color=color; This->sprites[This->sprite_count].transform=This->transform; This->sprite_count++; return D3D_OK; }
ILboolean iD3D9CreateMipmaps(IDirect3DTexture9 *Texture, ILimage *Image) { D3DLOCKED_RECT Rect; D3DSURFACE_DESC Desc; ILuint NumMips, Width, Height, i; ILimage *CurImage, *MipImage, *Temp; ILenum DXTCFormat; ILuint Size; ILubyte *Buffer; ILboolean useDXTC = IL_FALSE; NumMips = IDirect3DTexture9_GetLevelCount(Texture); Width = Image->Width; Height = Image->Height; if (NumMips == 1) return IL_TRUE; CurImage = ilGetCurImage(); MipImage = Image; if (MipImage->NumMips != NumMips-1) { MipImage = ilCopyImage_(Image); ilSetCurImage(MipImage); if (!iluBuildMipmaps()) { ilCloseImage(MipImage); ilSetCurImage(CurImage); return IL_FALSE; } } // ilSetCurImage(CurImage); Temp = MipImage->Mipmaps; if (ilutGetBoolean(ILUT_D3D_USE_DXTC) && FormatsDX9supported[3] && FormatsDX9supported[4] && FormatsDX9supported[5]) useDXTC = IL_TRUE; // Counts the base texture as 1. for (i = 1; i < NumMips && Temp != NULL; i++) { ilSetCurImage(Temp); if (FAILED(IDirect3DTexture9_LockRect(Texture, i, &Rect, NULL, 0))) return IL_FALSE; Width = IL_MAX(1, Width / 2); Height = IL_MAX(1, Height / 2); IDirect3DTexture9_GetLevelDesc(Texture, i, &Desc); if (Desc.Width != Width || Desc.Height != Height) { IDirect3DTexture9_UnlockRect(Texture, i); return IL_FALSE; } if (useDXTC) { if (Temp->DxtcData != NULL && Temp->DxtcSize != 0) { memcpy(Rect.pBits, Temp->DxtcData, Temp->DxtcSize); } else if (ilutGetBoolean(ILUT_D3D_GEN_DXTC)) { DXTCFormat = ilutGetInteger(ILUT_DXTC_FORMAT); Size = ilGetDXTCData(NULL, 0, DXTCFormat); if (Size != 0) { Buffer = (ILubyte*)ialloc(Size); if (Buffer == NULL) { IDirect3DTexture9_UnlockRect(Texture, i); return IL_FALSE; } Size = ilGetDXTCData(Buffer, Size, DXTCFormat); if (Size == 0) { ifree(Buffer); IDirect3DTexture9_UnlockRect(Texture, i); return IL_FALSE; } memcpy(Rect.pBits, Buffer, Size); } else { IDirect3DTexture9_UnlockRect(Texture, i); return IL_FALSE; } } else { IDirect3DTexture9_UnlockRect(Texture, i); return IL_FALSE; } } else memcpy(Rect.pBits, Temp->Data, Temp->SizeOfData); IDirect3DTexture9_UnlockRect(Texture, i); Temp = Temp->Next; } if (MipImage != Image) ilCloseImage(MipImage); ilSetCurImage(CurImage); return IL_TRUE; }