Added support for DXT2 and DXT4.

This commit is contained in:
Oliver Stieber 2005-08-29 12:20:02 +00:00 committed by Alexandre Julliard
parent 341ba0f696
commit 33b2c1fd3c
4 changed files with 27 additions and 7 deletions

View File

@ -4910,7 +4910,9 @@ HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface, IWineD3
} else { /* Full width, so just write out the whole texture */
if (WINED3DFMT_DXT1 == destFormat ||
WINED3DFMT_DXT2 == destFormat ||
WINED3DFMT_DXT3 == destFormat ||
WINED3DFMT_DXT4 == destFormat ||
WINED3DFMT_DXT5 == destFormat) {
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
if (destSurfaceHeight != srcHeight || destSurfaceWidth != srcWidth) {

View File

@ -1189,7 +1189,9 @@ HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, D3D
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (CheckFormat) {
case D3DFMT_DXT1:
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
TRACE_(d3d_caps)("[OK]\n");
return D3D_OK;

View File

@ -277,11 +277,12 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, D3DLOCKED_RE
}
/* DXTn formats don't have exact pitches as they are to the new row of blocks,
where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt3/5)
where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5)
ie pitch = (width/4) * bytes per block */
if (This->resource.format == WINED3DFMT_DXT1) /* DXT1 is 8 bytes per block */
pLockedRect->Pitch = (This->currentDesc.Width >> 2) << 3;
else if (This->resource.format == WINED3DFMT_DXT3 || This->resource.format == WINED3DFMT_DXT5) /* DXT3/5 is 16 bytes per block */
else if (This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
pLockedRect->Pitch = (This->currentDesc.Width >> 2) << 4;
else
pLockedRect->Pitch = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */
@ -297,7 +298,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, D3DLOCKED_RE
TRACE("Lock Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
if (This->resource.format == WINED3DFMT_DXT1) { /* DXT1 is half byte per pixel */
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel/2));
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel / 2));
} else {
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
}
@ -332,9 +333,11 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, D3DLOCKED_RE
IWineD3DSurface_PreLoad(iface); /* Make sure there is a texture to bind! */
TRACE("(%p) glGetTexImage level(%d), fmt(%d), typ(%d), mem(%p) \n" , This, This->glDescription.level, This->glDescription.glFormat, This->glDescription.glType, This->resource.allocatedMemory);
/* TODO: DXT2 and DXT4 formats */
if (This->resource.format == WINED3DFMT_DXT1 ||
This->resource.format == WINED3DFMT_DXT2 ||
This->resource.format == WINED3DFMT_DXT3 ||
This->resource.format == WINED3DFMT_DXT4 ||
This->resource.format == WINED3DFMT_DXT5) {
TRACE("Locking a compressed texture\n");
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) { /* we can assume this as the texture would not have been created otherwise */
@ -362,7 +365,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, D3DLOCKED_RE
pLockedRect->pBits = This->resource.allocatedMemory;
} else{
if (This->resource.format == D3DFMT_DXT1) { /* DXT1 is half byte per pixel */
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel/2));
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel / 2));
} else {
pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
}
@ -806,7 +809,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface) {
if (This->glDescription.level != 0)
FIXME("Surface in texture is only supported for level 0\n");
else if (This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8 ||
This->resource.format == WINED3DFMT_DXT1 || This->resource.format == WINED3DFMT_DXT3 ||
This->resource.format == WINED3DFMT_DXT1 || This->resource.format == WINED3DFMT_DXT2 ||
This->resource.format == WINED3DFMT_DXT3 || This->resource.format == WINED3DFMT_DXT4 ||
This->resource.format == WINED3DFMT_DXT5)
FIXME("Format %d not supported\n", This->resource.format);
else {
@ -888,9 +892,11 @@ HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface) {
}
/* TODO: Compressed non-power 2 support */
/* TODO: DXT2 DXT4 support */
if (This->resource.format == WINED3DFMT_DXT1 ||
This->resource.format == WINED3DFMT_DXT2 ||
This->resource.format == WINED3DFMT_DXT3 ||
This->resource.format == WINED3DFMT_DXT4 ||
This->resource.format == WINED3DFMT_DXT5) {
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
TRACE("Calling glCompressedTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, sz=%d, Mem=%p\n",

View File

@ -1575,7 +1575,9 @@ GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case WINED3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case WINED3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default:
/* stupid compiler */
@ -1636,7 +1638,9 @@ GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case WINED3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case WINED3DFMT_DXT2: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case WINED3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case WINED3DFMT_DXT4: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
case WINED3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default:
/* stupid compiler */
@ -1696,7 +1700,9 @@ GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case WINED3DFMT_DXT1: retVal = 0; break;
case WINED3DFMT_DXT2: retVal = 0; break;
case WINED3DFMT_DXT3: retVal = 0; break;
case WINED3DFMT_DXT4: retVal = 0; break;
case WINED3DFMT_DXT5: retVal = 0; break;
default:
/* stupid compiler */
@ -1740,7 +1746,9 @@ GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
case WINED3DFMT_D16_LOCKABLE: retVal = GL_UNSIGNED_SHORT; break;
/* compressed textures */
case WINED3DFMT_DXT1: retVal = 0; break;
case WINED3DFMT_DXT2: retVal = 0; break;
case WINED3DFMT_DXT3: retVal = 0; break;
case WINED3DFMT_DXT4: retVal = 0; break;
case WINED3DFMT_DXT5: retVal = 0; break;
default:
@ -1791,7 +1799,9 @@ SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
case WINED3DFMT_Q16W16V16U16: retVal = 8; break;
/* Compressed */
case WINED3DFMT_DXT1: retVal = 1; break; /* Actually 8 bytes per 16 pixels - Special cased later */
case WINED3DFMT_DXT2: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
case WINED3DFMT_DXT3: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
case WINED3DFMT_DXT4: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
case WINED3DFMT_DXT5: retVal = 1; break; /* Actually 16 bytes per 16 pixels */
/* to see */
case WINED3DFMT_A8: retVal = 1; break;