IDirect3DTexture8* ILAPIENTRY ilutD3D8Texture(IDirect3DDevice8 *Device) { IDirect3DTexture8 *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 (!FormatsDX8Checked) CheckFormatsDX8(Device); if (ilutGetBoolean(ILUT_D3D_USE_DXTC) && FormatsDX8supported[3] && FormatsDX8supported[4] && FormatsDX8supported[5]) { if (ilutCurImage->DxtcData != NULL && ilutCurImage->DxtcSize != 0) { Format = D3DGetDXTCNumDX8(ilutCurImage->DxtcFormat); if (FAILED(IDirect3DDevice8_CreateTexture(Device, ilutCurImage->Width, ilutCurImage->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, ilutGetInteger(ILUT_D3D_POOL), &Texture))) return NULL; if (FAILED(IDirect3DTexture8_LockRect(Texture, 0, &Rect, NULL, 0))) return NULL; memcpy(Rect.pBits, ilutCurImage->DxtcData, ilutCurImage->DxtcSize); goto success; } 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) return NULL; Size = ilGetDXTCData(Buffer, Size, DXTCFormat); if (Size == 0) { ifree(Buffer); return NULL; } Format = D3DGetDXTCNumDX8(DXTCFormat); if (FAILED(IDirect3DDevice8_CreateTexture(Device, ilutCurImage->Width, ilutCurImage->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, ilutGetInteger(ILUT_D3D_POOL), &Texture))) { ifree(Buffer); return NULL; } if (FAILED(IDirect3DTexture8_LockRect(Texture, 0, &Rect, NULL, 0))) { ifree(Buffer); return NULL; } memcpy(Rect.pBits, Buffer, Size); ifree(Buffer); goto success; } } } Image = MakeD3D8Compliant(Device, &Format); if (Image == NULL) { if (Image != ilutCurImage) ilCloseImage(Image); return NULL; } if (FAILED(IDirect3DDevice8_CreateTexture(Device, Image->Width, Image->Height, ilutGetInteger(ILUT_D3D_MIPLEVELS), 0, Format, ilutGetInteger(ILUT_D3D_POOL), &Texture))) { if (Image != ilutCurImage) ilCloseImage(Image); return NULL; } if (FAILED(IDirect3DTexture8_LockRect(Texture, 0, &Rect, NULL, 0))) return NULL; memcpy(Rect.pBits, Image->Data, Image->SizeOfPlane); success: IDirect3DTexture8_UnlockRect(Texture, 0); // Just let D3DX filter for us. //D3DXFilterTexture(Texture, NULL, D3DX_DEFAULT, D3DX_FILTER_BOX); iD3D8CreateMipmaps(Texture, Image); if (Image != ilutCurImage) ilCloseImage(Image); return Texture; }
static HRESULT d3d_device_create_texture(d3d_device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, d3d_texture **texture) { IDirect3DDevice8 *device = (IDirect3DDevice8 *)dev; return IDirect3DDevice8_CreateTexture(device, width, height, levels, usage, format, pool, (IDirect3DTexture8 **)texture); }