wined3d: Pixel format cleanup.

This commit is contained in:
Stefan Dösinger 2006-06-21 10:36:14 +02:00 committed by Alexandre Julliard
parent d23b83a026
commit 3518747165
6 changed files with 180 additions and 538 deletions

View File

@ -798,6 +798,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
IWineD3DSurfaceImpl *object; /*NOTE: impl ref allowed since this is a create function */ IWineD3DSurfaceImpl *object; /*NOTE: impl ref allowed since this is a create function */
unsigned int pow2Width, pow2Height; unsigned int pow2Width, pow2Height;
unsigned int Size = 1; unsigned int Size = 1;
const PixelFormatDesc *tableEntry = getFormatDescEntry(Format);
TRACE("(%p) Create surface\n",This); TRACE("(%p) Create surface\n",This);
/** FIXME: Check ranges on the inputs are valid /** FIXME: Check ranges on the inputs are valid
@ -861,13 +862,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
Size = 0; Size = 0;
} else if (Format == WINED3DFMT_DXT1) { } else if (Format == WINED3DFMT_DXT1) {
/* DXT1 is half byte per pixel */ /* DXT1 is half byte per pixel */
Size = ((max(pow2Width,4) * D3DFmtGetBpp(This, Format)) * max(pow2Height,4)) >> 1; Size = ((max(pow2Width,4) * tableEntry->bpp) * max(pow2Height,4)) >> 1;
} else if (Format == WINED3DFMT_DXT2 || Format == WINED3DFMT_DXT3 || } else if (Format == WINED3DFMT_DXT2 || Format == WINED3DFMT_DXT3 ||
Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5) { Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5) {
Size = ((max(pow2Width,4) * D3DFmtGetBpp(This, Format)) * max(pow2Height,4)); Size = ((max(pow2Width,4) * tableEntry->bpp) * max(pow2Height,4));
} else { } else {
Size = (pow2Width * D3DFmtGetBpp(This, Format)) * pow2Height; Size = (pow2Width * tableEntry->bpp) * pow2Height;
} }
/** Create and initialise the surface resource **/ /** Create and initialise the surface resource **/
@ -881,15 +882,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
object->currentDesc.MultiSampleQuality = MultisampleQuality; object->currentDesc.MultiSampleQuality = MultisampleQuality;
/* Setup some glformat defaults */ /* Setup some glformat defaults */
if (WINED3DFMT_UNKNOWN != Format) { object->glDescription.glFormat = tableEntry->glFormat;
object->glDescription.glFormat = D3DFmt2GLFmt(This, object->resource.format); object->glDescription.glFormatInternal = tableEntry->glInternal;
object->glDescription.glFormatInternal = D3DFmt2GLIntFmt(This, object->resource.format); object->glDescription.glType = tableEntry->glType;
object->glDescription.glType = D3DFmt2GLType(This, object->resource.format);
} else {
object->glDescription.glFormat = 0;
object->glDescription.glFormatInternal = 0;
object->glDescription.glType = 0;
}
object->glDescription.textureName = 0; object->glDescription.textureName = 0;
object->glDescription.level = Level; object->glDescription.level = Level;
@ -908,7 +903,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
if (WINED3DFMT_UNKNOWN != Format) { if (WINED3DFMT_UNKNOWN != Format) {
object->bytesPerPixel = D3DFmtGetBpp(This, Format); object->bytesPerPixel = tableEntry->bpp;
object->pow2Size = (pow2Width * object->bytesPerPixel) * pow2Height; object->pow2Size = (pow2Width * object->bytesPerPixel) * pow2Height;
} else { } else {
object->bytesPerPixel = 0; object->bytesPerPixel = 0;
@ -1148,8 +1143,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVolumeImpl *object; /** NOTE: impl ref allowed since this is a create function **/ IWineD3DVolumeImpl *object; /** NOTE: impl ref allowed since this is a create function **/
const PixelFormatDesc *formatDesc = getFormatDescEntry(Format);
D3DCREATERESOURCEOBJECTINSTANCE(object, Volume, WINED3DRTYPE_VOLUME, ((Width * D3DFmtGetBpp(This, Format)) * Height * Depth)) D3DCREATERESOURCEOBJECTINSTANCE(object, Volume, WINED3DRTYPE_VOLUME, ((Width * formatDesc->bpp) * Height * Depth))
TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%ld), Fmt(%u,%s), Pool(%s)\n", This, Width, Height, TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%ld), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool)); Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
@ -1157,7 +1153,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
object->currentDesc.Width = Width; object->currentDesc.Width = Width;
object->currentDesc.Height = Height; object->currentDesc.Height = Height;
object->currentDesc.Depth = Depth; object->currentDesc.Depth = Depth;
object->bytesPerPixel = D3DFmtGetBpp(This, Format); object->bytesPerPixel = formatDesc->bpp;
/** Note: Volume textures cannot be dxtn, hence no need to check here **/ /** Note: Volume textures cannot be dxtn, hence no need to check here **/
object->lockable = TRUE; object->lockable = TRUE;
@ -2043,6 +2039,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EnumDisplayModes(IWineD3DDevice *iface,
DEVMODEW DevModeW; DEVMODEW DevModeW;
int i; int i;
const PixelFormatDesc *formatDesc = getFormatDescEntry(pixelformat);
TRACE("(%p)->(%lx,%d,%d,%d,%p,%p)\n", This, Flags, Width, Height, pixelformat, context, callback); TRACE("(%p)->(%lx,%d,%d,%d,%p,%p)\n", This, Flags, Width, Height, pixelformat, context, callback);
@ -2050,7 +2047,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EnumDisplayModes(IWineD3DDevice *iface,
/* Ignore some modes if a description was passed */ /* Ignore some modes if a description was passed */
if ( (Width > 0) && (Width != DevModeW.dmPelsWidth)) continue; if ( (Width > 0) && (Width != DevModeW.dmPelsWidth)) continue;
if ( (Height > 0) && (Height != DevModeW.dmPelsHeight)) continue; if ( (Height > 0) && (Height != DevModeW.dmPelsHeight)) continue;
if ( (pixelformat != WINED3DFMT_UNKNOWN) && ( D3DFmtGetBpp(NULL, pixelformat) != DevModeW.dmBitsPerPel) ) continue; if ( (pixelformat != WINED3DFMT_UNKNOWN) && ( formatDesc->bpp != DevModeW.dmBitsPerPel) ) continue;
TRACE("Enumerating %ldx%ld@%s\n", DevModeW.dmPelsWidth, DevModeW.dmPelsHeight, debug_d3dformat(pixelformat_for_depth(DevModeW.dmBitsPerPel))); TRACE("Enumerating %ldx%ld@%s\n", DevModeW.dmPelsWidth, DevModeW.dmPelsHeight, debug_d3dformat(pixelformat_for_depth(DevModeW.dmBitsPerPel)));
@ -2065,6 +2062,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDisplayMode(IWineD3DDevice *iface, U
DEVMODEW devmode; DEVMODEW devmode;
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
LONG ret; LONG ret;
const PixelFormatDesc *formatDesc = getFormatDescEntry(pMode->Format);
TRACE("(%p)->(%d,%p) Mode=%dx%dx@%d, %s\n", This, iSwapChain, pMode, pMode->Width, pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format)); TRACE("(%p)->(%d,%p) Mode=%dx%dx@%d, %s\n", This, iSwapChain, pMode, pMode->Width, pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
@ -2075,7 +2073,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDisplayMode(IWineD3DDevice *iface, U
*/ */
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
devmode.dmBitsPerPel = D3DFmtGetBpp(This, pMode->Format) * 8; devmode.dmBitsPerPel = formatDesc->bpp * 8;
if(devmode.dmBitsPerPel == 24) devmode.dmBitsPerPel = 32; if(devmode.dmBitsPerPel == 24) devmode.dmBitsPerPel = 32;
devmode.dmPelsWidth = pMode->Width; devmode.dmPelsWidth = pMode->Width;
devmode.dmPelsHeight = pMode->Height; devmode.dmPelsHeight = pMode->Height;

View File

@ -967,6 +967,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
DWORD *masks; DWORD *masks;
HRESULT hr; HRESULT hr;
RGBQUAD col[256]; RGBQUAD col[256];
const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format);
TRACE("(%p)->(%p)\n",This,pHDC); TRACE("(%p)->(%p)\n",This,pHDC);
@ -1049,9 +1050,9 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
case WINED3DFMT_A16B16G16R16: case WINED3DFMT_A16B16G16R16:
usage = 0; usage = 0;
b_info->bmiHeader.biCompression = BI_BITFIELDS; b_info->bmiHeader.biCompression = BI_BITFIELDS;
masks[0] = get_bitmask_red(This->resource.format); masks[0] = formatEntry->redMask;
masks[1] = get_bitmask_green(This->resource.format); masks[1] = formatEntry->greenMask;
masks[2] = get_bitmask_blue(This->resource.format); masks[2] = formatEntry->blueMask;
break; break;
default: default:
@ -1186,14 +1187,12 @@ typedef enum {
HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp) { HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp) {
BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & DDSD_CKSRCBLT); BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & DDSD_CKSRCBLT);
const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format);
/* Default values: From the surface */ /* Default values: From the surface */
*format = D3DFmt2GLFmt(This->resource.wineD3DDevice, *format = formatEntry->glFormat;
This->resource.format); *internal = formatEntry->glInternal;
*internal = D3DFmt2GLIntFmt(This->resource.wineD3DDevice, *type = formatEntry->glType;
This->resource.format);
*type = D3DFmt2GLType(This->resource.wineD3DDevice,
This->resource.format);
*convert = NO_CONVERSION; *convert = NO_CONVERSION;
*target_bpp = This->bytesPerPixel; *target_bpp = This->bytesPerPixel;
@ -1873,6 +1872,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3D
HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) { HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface; IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
const PixelFormatDesc *formatEntry = getFormatDescEntry(format);
if (This->resource.format != WINED3DFMT_UNKNOWN) { if (This->resource.format != WINED3DFMT_UNKNOWN) {
FIXME("(%p) : The foramt of the surface must be WINED3DFORMAT_UNKNOWN\n", This); FIXME("(%p) : The foramt of the surface must be WINED3DFORMAT_UNKNOWN\n", This);
@ -1884,29 +1884,23 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORM
This->resource.size = 0; This->resource.size = 0;
} else if (format == WINED3DFMT_DXT1) { } else if (format == WINED3DFMT_DXT1) {
/* DXT1 is half byte per pixel */ /* DXT1 is half byte per pixel */
This->resource.size = ((max(This->pow2Width, 4) * D3DFmtGetBpp(This->resource.wineD3DDevice, format)) * max(This->pow2Height, 4)) >> 1; This->resource.size = ((max(This->pow2Width, 4) * formatEntry->bpp) * max(This->pow2Height, 4)) >> 1;
} else if (format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 || } else if (format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 ||
format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) { format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) {
This->resource.size = ((max(This->pow2Width, 4) * D3DFmtGetBpp(This->resource.wineD3DDevice, format)) * max(This->pow2Height, 4)); This->resource.size = ((max(This->pow2Width, 4) * formatEntry->bpp) * max(This->pow2Height, 4));
} else { } else {
This->resource.size = (This->pow2Width * D3DFmtGetBpp(This->resource.wineD3DDevice, format)) * This->pow2Height; This->resource.size = (This->pow2Width * formatEntry->bpp) * This->pow2Height;
} }
/* Setup some glformat defaults */ /* Setup some glformat defaults */
if (format != WINED3DFMT_UNKNOWN) { This->glDescription.glFormat = formatEntry->glFormat;
This->glDescription.glFormat = D3DFmt2GLFmt(This->resource.wineD3DDevice, format); This->glDescription.glFormatInternal = formatEntry->glInternal;
This->glDescription.glFormatInternal = D3DFmt2GLIntFmt(This->resource.wineD3DDevice, format); This->glDescription.glType = formatEntry->glType;
This->glDescription.glType = D3DFmt2GLType(This->resource.wineD3DDevice, format);
} else {
This->glDescription.glFormat = 0;
This->glDescription.glFormatInternal = 0;
This->glDescription.glType = 0;
}
if (format != WINED3DFMT_UNKNOWN) { if (format != WINED3DFMT_UNKNOWN) {
This->bytesPerPixel = D3DFmtGetBpp(This->resource.wineD3DDevice, format); This->bytesPerPixel = formatEntry->bpp;
This->pow2Size = (This->pow2Width * This->bytesPerPixel) * This->pow2Height; This->pow2Size = (This->pow2Width * This->bytesPerPixel) * This->pow2Height;
} else { } else {
This->bytesPerPixel = 0; This->bytesPerPixel = 0;

View File

@ -462,6 +462,7 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
WINED3DFORMAT dfmt = WINED3DFMT_UNKNOWN, sfmt = WINED3DFMT_UNKNOWN; WINED3DFORMAT dfmt = WINED3DFMT_UNKNOWN, sfmt = WINED3DFMT_UNKNOWN;
int bpp, srcheight, srcwidth, dstheight, dstwidth, width; int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
int x, y; int x, y;
const PixelFormatDesc *sEntry, *dEntry;
LPBYTE dbuf, sbuf; LPBYTE dbuf, sbuf;
TRACE("(%p)->(%p,%p,%p,%lx,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx); TRACE("(%p)->(%p,%p,%p,%lx,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
@ -494,6 +495,8 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
dfmt = This->resource.format; dfmt = This->resource.format;
slock = dlock; slock = dlock;
sfmt = dfmt; sfmt = dfmt;
sEntry = getFormatDescEntry(sfmt);
dEntry = sEntry;
} }
else else
{ {
@ -502,13 +505,15 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
IWineD3DSurface_LockRect(SrcSurface, &slock, NULL, D3DLOCK_READONLY); IWineD3DSurface_LockRect(SrcSurface, &slock, NULL, D3DLOCK_READONLY);
sfmt = Src->resource.format; sfmt = Src->resource.format;
} }
sEntry = getFormatDescEntry(sfmt);
dfmt = This->resource.format; dfmt = This->resource.format;
dEntry = getFormatDescEntry(dfmt);
IWineD3DSurface_LockRect(iface, &dlock,NULL,0); IWineD3DSurface_LockRect(iface, &dlock,NULL,0);
} }
if (!DDBltFx || !(DDBltFx->dwDDFX)) Flags &= ~DDBLT_DDFX; if (!DDBltFx || !(DDBltFx->dwDDFX)) Flags &= ~DDBLT_DDFX;
if (isFourcc(sfmt) && isFourcc(dfmt)) if (sEntry->isFourcc && dEntry->isFourcc)
{ {
if (sfmt != dfmt) if (sfmt != dfmt)
{ {
@ -521,8 +526,7 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
goto release; goto release;
} }
if (isFourcc(sfmt) && if (sEntry->isFourcc && !dEntry->isFourcc)
(!isFourcc(dfmt)))
{ {
FIXME("DXTC decompression not supported right now\n"); FIXME("DXTC decompression not supported right now\n");
goto release; goto release;
@ -897,9 +901,9 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
} }
else else
{ {
keymask = get_bitmask_red(Src->resource.format) | keymask = sEntry->redMask |
get_bitmask_green(Src->resource.format) | sEntry->greenMask |
get_bitmask_blue(Src->resource.format); sEntry->blueMask;
} }
Flags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE); Flags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE);
} }
@ -1086,6 +1090,7 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
RECT rsrc2; RECT rsrc2;
RECT lock_src, lock_dst, lock_union; RECT lock_src, lock_dst, lock_union;
BYTE *sbuf, *dbuf; BYTE *sbuf, *dbuf;
const PixelFormatDesc *sEntry, *dEntry;
if (TRACE_ON(d3d_surface)) if (TRACE_ON(d3d_surface))
{ {
@ -1169,8 +1174,10 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
/* Since slock was originally copied from this surface's description, we can just reuse it */ /* Since slock was originally copied from this surface's description, we can just reuse it */
assert(This->resource.allocatedMemory != NULL); assert(This->resource.allocatedMemory != NULL);
sbuf = (BYTE *)This->resource.allocatedMemory + lock_src.top * pitch + lock_src.left * bpp; sbuf = (BYTE *)This->resource.allocatedMemory + lock_src.top * pitch + lock_src.left * bpp;
dbuf = (BYTE *)This->resource.allocatedMemory + lock_dst.top * pitch + lock_dst.left * bpp; dbuf = (BYTE *)This->resource.allocatedMemory + lock_dst.top * pitch + lock_dst.left * bpp;
sEntry = getFormatDescEntry(Src->resource.format);
dEntry = sEntry;
} }
else else
{ {
@ -1182,10 +1189,13 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
sbuf = slock.pBits; sbuf = slock.pBits;
dbuf = dlock.pBits; dbuf = dlock.pBits;
TRACE("Dst is at %p, Src is at %p\n", dbuf, sbuf); TRACE("Dst is at %p, Src is at %p\n", dbuf, sbuf);
sEntry = getFormatDescEntry(Src->resource.format);
dEntry = getFormatDescEntry(This->resource.format);
} }
/* Handle first the FOURCC surfaces... */ /* Handle first the FOURCC surfaces... */
if (isFourcc(Src->resource.format) && isFourcc(This->resource.format)) if (sEntry->isFourcc && dEntry->isFourcc)
{ {
TRACE("Fourcc -> Fourcc copy\n"); TRACE("Fourcc -> Fourcc copy\n");
if (trans) if (trans)
@ -1202,8 +1212,7 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
memcpy(dbuf, sbuf, This->resource.size); memcpy(dbuf, sbuf, This->resource.size);
goto error; goto error;
} }
if ((isFourcc(Src->resource.format)) && if (sEntry->isFourcc && !dEntry->isFourcc)
(!isFourcc(This->resource.format)))
{ {
/* TODO: Use the libtxc_dxtn.so shared library to do /* TODO: Use the libtxc_dxtn.so shared library to do
* software decompression * software decompression
@ -1360,6 +1369,7 @@ const char* filename)
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface; IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
static char *output = NULL; static char *output = NULL;
static int size = 0; static int size = 0;
const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format);
if (This->pow2Width > size) { if (This->pow2Width > size) {
output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3); output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3);
@ -1404,9 +1414,9 @@ const char* filename)
pix_width = This->bytesPerPixel; pix_width = This->bytesPerPixel;
red_shift = get_shift(get_bitmask_red(This->resource.format)); red_shift = get_shift(formatEntry->redMask);
green_shift = get_shift(get_bitmask_green(This->resource.format)); green_shift = get_shift(formatEntry->greenMask);
blue_shift = get_shift(get_bitmask_blue(This->resource.format)); blue_shift = get_shift(formatEntry->blueMask);
for (y = 0; y < This->pow2Height; y++) { for (y = 0; y < This->pow2Height; y++) {
unsigned char *src = (unsigned char *) This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface)); unsigned char *src = (unsigned char *) This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
@ -1421,11 +1431,11 @@ const char* filename)
} }
src += 1 * pix_width; src += 1 * pix_width;
comp = color & get_bitmask_red(This->resource.format); comp = color & formatEntry->redMask;
output[3 * x + 0] = red_shift > 0 ? comp >> red_shift : comp << -red_shift; output[3 * x + 0] = red_shift > 0 ? comp >> red_shift : comp << -red_shift;
comp = color & get_bitmask_green(This->resource.format); comp = color & formatEntry->greenMask;
output[3 * x + 1] = green_shift > 0 ? comp >> green_shift : comp << -green_shift; output[3 * x + 1] = green_shift > 0 ? comp >> green_shift : comp << -green_shift;
comp = color & get_bitmask_blue(This->resource.format); comp = color & formatEntry->blueMask;
output[3 * x + 2] = blue_shift > 0 ? comp >> blue_shift : comp << -blue_shift; output[3 * x + 2] = blue_shift > 0 ? comp >> blue_shift : comp << -blue_shift;
} }
fwrite(output, 3 * This->pow2Width, 1, f); fwrite(output, 3 * This->pow2Width, 1, f);
@ -1467,7 +1477,7 @@ IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
This->resource.allocatedMemory = NULL; This->resource.allocatedMemory = NULL;
/* We don't mind the nonpow2 stuff in GDI */ /* We don't mind the nonpow2 stuff in GDI */
This->resource.size = This->currentDesc.Width * D3DFmtGetBpp(This->resource.wineD3DDevice, This->resource.format) * This->currentDesc.Width; This->resource.size = This->currentDesc.Width * getFormatDescEntry(This->resource.format)->bpp * This->currentDesc.Width;
This->pow2Size = This->resource.size; This->pow2Size = This->resource.size;
This->pow2Width = This->currentDesc.Width; This->pow2Width = This->currentDesc.Width;
This->pow2Height = This->currentDesc.Height; This->pow2Height = This->currentDesc.Height;

View File

@ -26,6 +26,108 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DEFAULT_DEBUG_CHANNEL(d3d);
/*****************************************************************************
* Pixel format array
*/
static const PixelFormatDesc formats[] = {
/*{WINED3DFORMAT ,alphamask ,redmask ,greenmask ,bluemask ,bpp ,isFourcc ,internal ,format ,type }*/
{WINED3DFMT_UNKNOWN ,0x0 ,0x0 ,0x0 ,0x0 ,1 ,F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,FALSE ,GL_RGB5 ,GL_RGB ,GL_UNSIGNED_SHORT_5_6_5 },
{WINED3DFMT_X1R5G5B5 ,0x0 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,FALSE ,GL_RGB5_A1 ,GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV },
{WINED3DFMT_A1R5G5B5 ,0x00008000 ,0x00007c00 ,0x000003e0 ,0x0000001f ,2 ,FALSE ,GL_RGB5_A1 ,GL_BGRA ,GL_UNSIGNED_SHORT_1_5_5_5_REV },
{WINED3DFMT_A4R4G4B4 ,0x0000f000 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,FALSE ,GL_RGBA4 ,GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV },
{WINED3DFMT_R3G3B2 ,0x0 ,0x000000e0 ,0x0000001c ,0x00000003 ,1 ,FALSE ,GL_R3_G3_B2 ,GL_RGB ,GL_UNSIGNED_BYTE_2_3_3_REV },
{WINED3DFMT_A8 ,0x000000ff ,0x0 ,0x0 ,0x0 ,1 ,FALSE ,GL_ALPHA8 ,GL_ALPHA ,GL_ALPHA },
{WINED3DFMT_A8R3G3B2 ,0x0000ff00 ,0x000000e0 ,0x0000001c ,0x00000003 ,2 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_X4R4G4B4 ,0x0 ,0x00000f00 ,0x000000f0 ,0x0000000f ,2 ,FALSE ,GL_RGB4 ,GL_BGRA ,GL_UNSIGNED_SHORT_4_4_4_4_REV },
{WINED3DFMT_A2B10G10R10 ,0xb0000000 ,0x000003ff ,0x000ffc00 ,0x3ff00000 ,4 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_A8B8G8R8 ,0xff000000 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,FALSE ,GL_RGBA8 ,GL_RGBA ,GL_UNSIGNED_INT_8_8_8_8_REV },
{WINED3DFMT_X8B8G8R8 ,0x0 ,0x000000ff ,0x0000ff00 ,0x00ff0000 ,4 ,FAL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WINED3DFMT_D32F_LOCKABLE,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_D24FS8 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
/* Is this a vertex buffer? */
{WINED3DFMT_VERTEXDATA ,0x0 ,0x0 ,0x0 ,0x0 ,0 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_INDEX16 ,0x0 ,0x0 ,0x0 ,0x0 ,2 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_INDEX32 ,0x0 ,0x0 ,0x0 ,0x0 ,4 ,FALSE ,0 ,0 ,0 },
{WINED3DFMT_Q16W16V16U16,0x0 ,0x0 ,0x0 ,0x0 ,8 ,FALSE ,GL_COLOR_INDEX ,GL_COLOR_INDEX ,GL_UNSIGNED_SHORT }
};
const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt)
{
/* First check if the format is at the position of its value.
* This will catch the argb formats before the loop is entered
*/
if(fmt < (sizeof(formats) / sizeof(formats[0])) && formats[fmt].format == fmt) {
return &formats[fmt];
} else {
unsigned int i;
for(i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
if(formats[i].format == fmt) {
return &formats[i];
}
}
}
FIXME("Can't find format %s(%d) in the format lookup table\n", debug_d3dformat(fmt), fmt);
if(fmt == WINED3DFMT_UNKNOWN) {
ERR("Format table corrupt - Can't find WINED3DFMT_UNKNOWN\n");
return NULL;
}
/* Get the caller a valid pointer */
return getFormatDescEntry(WINED3DFMT_UNKNOWN);
}
/***************************************************************************** /*****************************************************************************
* Trace formatting of useful values * Trace formatting of useful values
*/ */
@ -1635,276 +1737,6 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords)
} }
#define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info #define GLINFO_LOCATION ((IWineD3DImpl *)(This->wineD3D))->gl_info
GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
GLint retVal = 0;
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 */
break;
}
}
if (retVal == 0) {
switch (fmt) {
/* Paletted */
case WINED3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
/* Luminance */
case WINED3DFMT_L8: retVal = GL_LUMINANCE8; break;
case WINED3DFMT_L16: retVal = GL_LUMINANCE16_EXT; break;
case WINED3DFMT_A8L8: retVal = GL_LUMINANCE8_ALPHA8; break;
case WINED3DFMT_A4L4: retVal = GL_LUMINANCE4_ALPHA4; break;
/* Bump */
case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX8_EXT; break;
case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX8_EXT; break;
case WINED3DFMT_X8L8V8U8: retVal = GL_RGBA8; break;
case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA8; break; /* almost but not quite... */
case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break; /* almost but not quite... */
/* color buffer */
case WINED3DFMT_R3G3B2: retVal = GL_R3_G3_B2; break;
case WINED3DFMT_R5G6B5: retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
case WINED3DFMT_R8G8B8: retVal = GL_RGB8; break;
case WINED3DFMT_A1R5G5B5: retVal = GL_RGB5_A1; break;
case WINED3DFMT_X1R5G5B5: retVal = GL_RGB5_A1; break;
case WINED3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
case WINED3DFMT_X4R4G4B4: retVal = GL_RGB4; break;
case WINED3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
case WINED3DFMT_A8B8G8R8: retVal = GL_RGBA8; break;
case WINED3DFMT_A2R10G10B10: retVal = GL_RGBA8; break;
case WINED3DFMT_X8R8G8B8: retVal = GL_RGB8; break;
case WINED3DFMT_A16B16G16R16: retVal = GL_RGBA16_EXT; break;
/* to see */
case WINED3DFMT_A8: retVal = GL_ALPHA8; break;
/* Depth + Stencil NOTE: OpenGL doesn't support depth-stencil surfaces so the formats are the closes bits match for the data */
case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24FS8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_RGB8;
}
}
TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
GLenum retVal = 0;
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 */
break;
}
}
if (retVal == 0) {
switch (fmt) {
/* Paletted */
case WINED3DFMT_P8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
/* Luminance */
case WINED3DFMT_L8: retVal = GL_LUMINANCE; break;
case WINED3DFMT_L16: retVal = GL_LUMINANCE; break;
case WINED3DFMT_A8L8: retVal = GL_LUMINANCE_ALPHA; break;
case WINED3DFMT_A4L4: retVal = GL_LUMINANCE_ALPHA; break;
/* Bump */
case WINED3DFMT_V8U8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_V16U16: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_L6V5U5: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_X8L8V8U8: retVal = GL_BGRA; break;
case WINED3DFMT_Q8W8V8U8: retVal = GL_RGBA; break;
case WINED3DFMT_Q16W16V16U16: retVal = GL_COLOR_INDEX; break;
/* color buffer */
case WINED3DFMT_R3G3B2: retVal = GL_RGB; break;
case WINED3DFMT_R5G6B5: retVal = GL_RGB; break;
case WINED3DFMT_R8G8B8: retVal = GL_RGB; break;
case WINED3DFMT_A1R5G5B5: retVal = GL_BGRA; break;
case WINED3DFMT_X1R5G5B5: retVal = GL_BGRA; break;
case WINED3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
case WINED3DFMT_X4R4G4B4: retVal = GL_BGRA; break;
case WINED3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
case WINED3DFMT_A8B8G8R8: retVal = GL_RGBA; break;
case WINED3DFMT_A2R10G10B10: retVal = GL_BGRA; break;
case WINED3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
case WINED3DFMT_A16B16G16R16: retVal = GL_RGBA; break;
/* to see */
case WINED3DFMT_A8: retVal = GL_ALPHA; break;
/* Depth + Stencil */
case WINED3DFMT_D24S8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24FS8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24X8: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D24X4S4: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D32: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D16: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D15S1: retVal = GL_COLOR_INDEX; break;
case WINED3DFMT_D16_LOCKABLE: retVal = GL_COLOR_INDEX; break;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_BGR;
}
}
TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
GLenum D3DFmt2GLType(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
GLenum retVal = 0;
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 */
break;
}
}
if (retVal == 0) {
switch (fmt) {
/* Paletted */
case WINED3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
case WINED3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
/* Luminance */
case WINED3DFMT_L8: retVal = GL_UNSIGNED_BYTE; break;
case WINED3DFMT_L16: retVal = GL_UNSIGNED_SHORT; break;
case WINED3DFMT_A8L8: retVal = GL_UNSIGNED_BYTE; break;
case WINED3DFMT_A4L4: retVal = GL_UNSIGNED_BYTE; break;
/* Bump */
case WINED3DFMT_V8U8: retVal = GL_UNSIGNED_BYTE; break;
case WINED3DFMT_V16U16: retVal = GL_UNSIGNED_SHORT; break;
case WINED3DFMT_L6V5U5: retVal = GL_UNSIGNED_SHORT_5_5_5_1; break;
case WINED3DFMT_X8L8V8U8: retVal = GL_UNSIGNED_BYTE; break;
/* Color buffer */
case WINED3DFMT_R3G3B2: retVal = GL_UNSIGNED_BYTE_2_3_3_REV; break;
case WINED3DFMT_R5G6B5: retVal = GL_UNSIGNED_SHORT_5_6_5; break;
case WINED3DFMT_R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
case WINED3DFMT_A1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
case WINED3DFMT_X1R5G5B5: retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
case WINED3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
case WINED3DFMT_X4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
case WINED3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
case WINED3DFMT_A8B8G8R8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
case WINED3DFMT_A2R10G10B10: retVal = GL_UNSIGNED_INT_2_10_10_10_REV; break;
case WINED3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_INT_8_8_8_8_REV; break;
case WINED3DFMT_A16B16G16R16: retVal = GL_UNSIGNED_SHORT; break;
/* to see */
case WINED3DFMT_A8: retVal = GL_ALPHA; break;
/* Depth + Stencil */
case WINED3DFMT_D24S8: retVal = GL_UNSIGNED_INT; break;
case WINED3DFMT_D24FS8: retVal = GL_UNSIGNED_INT; break;
case WINED3DFMT_D24X8: retVal = GL_UNSIGNED_INT; break;
case WINED3DFMT_D24X4S4: retVal = GL_UNSIGNED_INT; break;
case WINED3DFMT_D32: retVal = GL_UNSIGNED_INT; break;
case WINED3DFMT_D16: retVal = GL_UNSIGNED_SHORT; break;
case WINED3DFMT_D15S1: retVal = GL_UNSIGNED_SHORT; break;
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:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_UNSIGNED_BYTE;
}
}
TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt) {
SHORT retVal;
switch (fmt) {
/* color buffer */
case WINED3DFMT_R3G3B2: retVal = 1; break;
case WINED3DFMT_R5G6B5: retVal = 2; break;
case WINED3DFMT_R8G8B8: retVal = 3; break;
case WINED3DFMT_A1R5G5B5: retVal = 2; break;
case WINED3DFMT_X1R5G5B5: retVal = 2; break;
case WINED3DFMT_A4R4G4B4: retVal = 2; break;
case WINED3DFMT_X4R4G4B4: retVal = 2; break;
case WINED3DFMT_A8R8G8B8: retVal = 4; break;
case WINED3DFMT_A8B8G8R8: retVal = 4; break;
case WINED3DFMT_A2R10G10B10: retVal = 4; break;
case WINED3DFMT_X8R8G8B8: retVal = 4; break;
case WINED3DFMT_A16B16G16R16: retVal = 8; break;
/* Paletted */
case WINED3DFMT_P8: retVal = 1; break;
case WINED3DFMT_A8P8: retVal = 2; break;
/* depth/stencil buffer */
case WINED3DFMT_D16_LOCKABLE: retVal = 2; break;
case WINED3DFMT_D16: retVal = 2; break;
case WINED3DFMT_D32: retVal = 4; break;
case WINED3DFMT_D15S1: retVal = 2; break;
case WINED3DFMT_D24X4S4: retVal = 4; break;
case WINED3DFMT_D24S8: retVal = 4; break;
case WINED3DFMT_D24FS8: retVal = 4; break;
case WINED3DFMT_D24X8: retVal = 4; break;
/* Luminance */
case WINED3DFMT_L8: retVal = 1; break;
case WINED3DFMT_L16: retVal = 2; break;
case WINED3DFMT_A4L4: retVal = 1; break;
case WINED3DFMT_A8L8: retVal = 2; break;
/* Bump */
case WINED3DFMT_V8U8: retVal = 2; break;
case WINED3DFMT_L6V5U5: retVal = 2; break;
case WINED3DFMT_V16U16: retVal = 4; break;
case WINED3DFMT_X8L8V8U8: retVal = 4; break;
case WINED3DFMT_Q8W8V8U8: retVal = 4; break;
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;
/* unknown */
case WINED3DFMT_UNKNOWN:
/* Guess at the highest value of the above */
TRACE("WINED3DFMT_UNKNOWN - Guessing at 8 bytes/pixel %u\n", fmt);
retVal = 8;
break;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = 8;
}
TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
/* Convertes a D3D format into a OpenGL configuration format */ /* Convertes a D3D format into a OpenGL configuration format */
int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){ int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate){
@ -2086,187 +1918,6 @@ WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
} }
} }
LONG get_bitmask_red(WINED3DFORMAT fmt)
{
switch (fmt) {
case WINED3DFMT_R8G8B8:
case WINED3DFMT_A8R8G8B8:
case WINED3DFMT_X8R8G8B8:
return 0x00ff0000;
case WINED3DFMT_X1R5G5B5:
case WINED3DFMT_A1R5G5B5:
return 0x7C00;
case WINED3DFMT_A4R4G4B4:
case WINED3DFMT_X4R4G4B4:
return 0xF00;
case WINED3DFMT_R3G3B2:
case WINED3DFMT_A8R3G3B2:
return 0xE0;
case WINED3DFMT_A2R10G10B10:
return 0x3F0000;
break;
case WINED3DFMT_A2B10G10R10:
return 0x3FF;
case WINED3DFMT_A8B8G8R8:
case WINED3DFMT_X8B8G8R8:
return 0xff;
case WINED3DFMT_R5G6B5:
return 0xF800;
case WINED3DFMT_P8:
/* No fixed mask for this format */
return 0;
#if 0
case WINED3DFMT_A16B16G16R16:
return 0x00000000ffff;
break;
#endif
default:
ERR("Unknown bitmask for format %d\n", fmt);
return 0;
}
}
LONG get_bitmask_green(WINED3DFORMAT fmt)
{
switch (fmt) {
case WINED3DFMT_R8G8B8:
case WINED3DFMT_A8R8G8B8:
case WINED3DFMT_X8R8G8B8:
return 0x0000ff00;
case WINED3DFMT_X1R5G5B5:
case WINED3DFMT_A1R5G5B5:
return 0x3E0;
case WINED3DFMT_A4R4G4B4:
case WINED3DFMT_X4R4G4B4:
return 0xF0;
case WINED3DFMT_R3G3B2:
case WINED3DFMT_A8R3G3B2:
return 0x1C;
case WINED3DFMT_A2B10G10R10:
return 0xFFC00;
case WINED3DFMT_A8B8G8R8:
case WINED3DFMT_X8B8G8R8:
return 0xFF00;
break;
case WINED3DFMT_A2R10G10B10:
return 0xFFC00;
break;
case WINED3DFMT_R5G6B5:
return 0x7E0;
case WINED3DFMT_P8:
/* No fixed mask for this format */
return 0;
#if 0
case WINED3DFMT_A16B16G16R16:
return 0x0000ffff0000;
break;
#endif
default:
ERR("Unknown bitmask for format %d\n", fmt);
return 0;
}
}
LONG get_bitmask_blue(WINED3DFORMAT fmt)
{
switch (fmt) {
case WINED3DFMT_R8G8B8:
case WINED3DFMT_A8R8G8B8:
case WINED3DFMT_X8R8G8B8:
return 0x000000ff;
case WINED3DFMT_X1R5G5B5:
case WINED3DFMT_A1R5G5B5:
return 0x1f;
case WINED3DFMT_A4R4G4B4:
case WINED3DFMT_X4R4G4B4:
return 0xF;
case WINED3DFMT_R3G3B2:
case WINED3DFMT_A8R3G3B2:
return 0x3;
case WINED3DFMT_A2B10G10R10:
return 0x3F0000;
case WINED3DFMT_A8B8G8R8:
case WINED3DFMT_X8B8G8R8:
return 0xFF0000;
case WINED3DFMT_A2R10G10B10:
return 0x3FF;
case WINED3DFMT_R5G6B5:
return 0x1F;
case WINED3DFMT_P8:
/* No fixed mask for this format */
return 0;
#if 0
case WINED3DFMT_A16B16G16R16:
return 0xffff00000000;
break;
#endif
default:
ERR("Unknown bitmask for format %d\n", fmt);
return 0;
}
}
LONG get_bitmask_alpha(WINED3DFORMAT fmt)
{
switch (fmt) {
case WINED3DFMT_A8R8G8B8:
return 0xff000000;
case WINED3DFMT_A1R5G5B5:
return 0x8000;
case WINED3DFMT_A4R4G4B4:
return 0xF000;
case WINED3DFMT_A8R3G3B2:
return 0xff00;
case WINED3DFMT_A2B10G10R10:
return 0xb0000000;
case WINED3DFMT_A8B8G8R8:
return 0xFF000000;
case WINED3DFMT_A2R10G10B10:
return 0xb0000000;
default:
return 0;
}
}
void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2) { void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2) {
D3DMATRIX temp; D3DMATRIX temp;
@ -2317,19 +1968,6 @@ DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) {
return size; return size;
} }
BOOL isFourcc(WINED3DFORMAT fmt) {
return (fmt == WINED3DFMT_UYVY) ||
(fmt == WINED3DFMT_YUY2) ||
(fmt == WINED3DFMT_DXT1) ||
(fmt == WINED3DFMT_DXT2) ||
(fmt == WINED3DFMT_DXT3) ||
(fmt == WINED3DFMT_DXT4) ||
(fmt == WINED3DFMT_DXT5) ||
(fmt == WINED3DFMT_MULTI2_ARGB) ||
(fmt == WINED3DFMT_G8R8_G8B8) ||
(fmt == WINED3DFMT_R8G8_B8G8);
}
/*********************************************************************** /***********************************************************************
* CalculateTexRect * CalculateTexRect
* *

View File

@ -283,28 +283,28 @@ static HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IWi
static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, GLenum gl_level) { static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, GLenum gl_level) {
IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface; IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice; const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format);
TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n", TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
GL_TEXTURE_3D, GL_TEXTURE_3D,
gl_level, gl_level,
D3DFmt2GLIntFmt(myDevice, This->resource.format), formatEntry->glInternal,
This->currentDesc.Width, This->currentDesc.Width,
This->currentDesc.Height, This->currentDesc.Height,
This->currentDesc.Depth, This->currentDesc.Depth,
0, 0,
D3DFmt2GLFmt(myDevice, This->resource.format), formatEntry->glFormat,
D3DFmt2GLType(myDevice, This->resource.format), formatEntry->glType,
This->resource.allocatedMemory); This->resource.allocatedMemory);
glTexImage3D(GL_TEXTURE_3D, glTexImage3D(GL_TEXTURE_3D,
gl_level, gl_level,
D3DFmt2GLIntFmt(myDevice, This->resource.format), formatEntry->glInternal,
This->currentDesc.Width, This->currentDesc.Width,
This->currentDesc.Height, This->currentDesc.Height,
This->currentDesc.Depth, This->currentDesc.Depth,
0, 0,
D3DFmt2GLFmt(myDevice, This->resource.format), formatEntry->glFormat,
D3DFmt2GLType(myDevice, This->resource.format), formatEntry->glType,
This->resource.allocatedMemory); This->resource.allocatedMemory);
checkGLcall("glTexImage3D"); checkGLcall("glTexImage3D");
return WINED3D_OK; return WINED3D_OK;

View File

@ -1169,11 +1169,6 @@ GLenum StencilFunc(DWORD func);
void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3); void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords); void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate); int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
/* Math utils */ /* Math utils */
@ -1574,10 +1569,17 @@ DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
/* DirectDraw utility functions */ /* DirectDraw utility functions */
extern WINED3DFORMAT pixelformat_for_depth(DWORD depth); extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
LONG get_bitmask_red(WINED3DFORMAT fmt);
LONG get_bitmask_green(WINED3DFORMAT fmt);
LONG get_bitmask_blue(WINED3DFORMAT fmt);
LONG get_bitmask_alpha(WINED3DFORMAT fmt);
BOOL isFourcc(WINED3DFORMAT fmt);
/*****************************************************************************
* Pixel format management
*/
typedef struct {
WINED3DFORMAT format;
DWORD alphaMask, redMask, greenMask, blueMask;
UINT bpp;
BOOL isFourcc;
GLint glInternal, glFormat, glType;
} PixelFormatDesc;
const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);
#endif #endif