mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
add ddsurf=>pixbuf conversion
This commit is contained in:
parent
79e66527ed
commit
32052691ad
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
//#define FORCE_16bpp_1555
|
//#define FORCE_16bpp_1555
|
||||||
|
|
||||||
typedef enum {None,Conv32to32,Conv32to32_NoAlpha,Conv32to24,Conv32to16_0555,
|
typedef enum {
|
||||||
|
None,Conv32to32,Conv32to32_NoAlpha,Conv32to24,Conv32to16_0555,
|
||||||
Conv32to16_1555,Conv32to16_0565,Conv32to16_4444,Conv24to32,Conv24to24,
|
Conv32to16_1555,Conv32to16_0565,Conv32to16_4444,Conv24to32,Conv24to24,
|
||||||
Conv24to16_0555,Conv24to16_0565,ConvLum16to16_1555,ConvLum16to16_4444,
|
Conv24to16_0555,Conv24to16_0565,ConvLum16to16_1555,ConvLum16to16_4444,
|
||||||
ConvLum16to32,ConvLum16to16,ConvLum8to8,ConvLum8to24,ConvLum8to32,ConvLum8to16_0555,ConvLum8to16_0565
|
ConvLum16to32,ConvLum16to16,ConvLum8to8,ConvLum8to24,ConvLum8to32,ConvLum8to16_0555,ConvLum8to16_0565
|
||||||
@ -33,7 +34,7 @@ char *ConvNameStrs[] = {"None","Conv32to32","Conv32to32_NoAlpha","Conv32to24","C
|
|||||||
"Conv24to16_0555","Conv24to16_0565","ConvLum16to16_1555","ConvLum16to16_4444",
|
"Conv24to16_0555","Conv24to16_0565","ConvLum16to16_1555","ConvLum16to16_4444",
|
||||||
"ConvLum16to32","ConvLum16to16","ConvLum8to8","ConvLum8to24","ConvLum8to32",
|
"ConvLum16to32","ConvLum16to16","ConvLum8to8","ConvLum8to24","ConvLum8to32",
|
||||||
"ConvLum8to16_0555","ConvLum8to16_0565"
|
"ConvLum8to16_0555","ConvLum8to16_0565"
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TypeHandle DXTextureContext::_type_handle;
|
TypeHandle DXTextureContext::_type_handle;
|
||||||
@ -127,10 +128,11 @@ enum Format {
|
|||||||
// Note: PixelBuffer's format indicates REQUESTED final format,
|
// Note: PixelBuffer's format indicates REQUESTED final format,
|
||||||
// not the stored format, which is indicated by pixelbuffer type
|
// not the stored format, which is indicated by pixelbuffer type
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
unsigned int DXTextureContext::
|
unsigned int DXTextureContext::
|
||||||
get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
||||||
*alphbits = 0; // assume no alpha bits
|
*alphbits = 0; // assume no alpha bits
|
||||||
switch (format) {
|
switch(format) {
|
||||||
case PixelBuffer::F_alpha:
|
case PixelBuffer::F_alpha:
|
||||||
*alphbits = 8;
|
*alphbits = 8;
|
||||||
return 8;
|
return 8;
|
||||||
@ -172,14 +174,14 @@ get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
|||||||
*alphbits = 12;
|
*alphbits = 12;
|
||||||
return 48;
|
return 48;
|
||||||
}
|
}
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWSURFACE7 pDDSurf) {
|
HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWSURFACE7 pDDSurf) {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd);
|
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd);
|
||||||
|
|
||||||
if( FAILED( hr = pDDSurf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) {
|
if(FAILED( hr = pDDSurf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) {
|
||||||
dxgsg_cat.error() << "CreateTexture failed: _surface->Lock() failed on texture! hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << "CreateTexture failed: _surface->Lock() failed on texture! hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -188,8 +190,6 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
|
|
||||||
DWORD lPitch = ddsd.lPitch;
|
DWORD lPitch = ddsd.lPitch;
|
||||||
BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface;
|
BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface;
|
||||||
BYTE r,g,b,a;
|
|
||||||
DWORD x,y,dwPixel;
|
|
||||||
DWORD dwOrigWidth=ddsd.dwWidth,dwOrigHeight=ddsd.dwHeight;
|
DWORD dwOrigWidth=ddsd.dwWidth,dwOrigHeight=ddsd.dwHeight;
|
||||||
|
|
||||||
switch(ConvNeeded) {
|
switch(ConvNeeded) {
|
||||||
@ -200,15 +200,16 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
DWORD *pDstWord;
|
DWORD *pDstWord;
|
||||||
DWORD dwAlphaMaskOff = (ConvNeeded==Conv32to32_NoAlpha) ? 0x00FFFFFF : 0xFFFFFFFF;
|
DWORD dwAlphaMaskOff = (ConvNeeded==Conv32to32_NoAlpha) ? 0x00FFFFFF : 0xFFFFFFFF;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (DWORD*)pDDSurfBytes;
|
pDstWord = (DWORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
#if 0
|
#if 0
|
||||||
|
BYTE r,g,b,a;
|
||||||
a = (BYTE)((dwPixel>>24)); // unsigned >>, no need to &
|
a = (BYTE)((dwPixel>>24)); // unsigned >>, no need to &
|
||||||
b = (BYTE)((dwPixel>>16)&0x000000ff);
|
b = (BYTE)((dwPixel>>16)&0x000000ff);
|
||||||
g = (BYTE)((dwPixel>> 8)&0x000000ff);
|
g = (BYTE)((dwPixel>> 8)&0x000000ff);
|
||||||
@ -216,6 +217,7 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
|
|
||||||
*pDstWord = (a << 24) | (r << 16)| (g << 8) | b;
|
*pDstWord = (a << 24) | (r << 16)| (g << 8) | b;
|
||||||
#else
|
#else
|
||||||
|
BYTE r,b;
|
||||||
// simpler: just swap r & b
|
// simpler: just swap r & b
|
||||||
b = (BYTE)((dwPixel>>16)&0x000000ff);
|
b = (BYTE)((dwPixel>>16)&0x000000ff);
|
||||||
r = (BYTE)((dwPixel )&0x000000ff);
|
r = (BYTE)((dwPixel )&0x000000ff);
|
||||||
@ -228,7 +230,7 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
|
|
||||||
case Conv32to16_1555:
|
case Conv32to16_1555:
|
||||||
case Conv32to16_0555: {
|
case Conv32to16_0555: {
|
||||||
DWORD abit,*pSrcWord = (DWORD *) pbuf;
|
DWORD *pSrcWord = (DWORD *) pbuf;
|
||||||
WORD *pDstWord;
|
WORD *pDstWord;
|
||||||
DWORD dwAlphaMaskOff = (ConvNeeded==Conv32to16_0555) ? 0x7FFF : 0xFFFF;
|
DWORD dwAlphaMaskOff = (ConvNeeded==Conv32to16_0555) ? 0x7FFF : 0xFFFF;
|
||||||
|
|
||||||
@ -236,11 +238,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
// for some reason, bits are 'in-order' when converting to 16bit
|
// for some reason, bits are 'in-order' when converting to 16bit
|
||||||
|
|
||||||
// just handle 1/15 alpha/rgb
|
// just handle 1/15 alpha/rgb
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
BYTE r,g,b;
|
||||||
|
DWORD abit,dwPixel = *pSrcWord;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
@ -270,11 +273,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
// for some reason, bits are 'in-order' when converting to 16bit
|
// for some reason, bits are 'in-order' when converting to 16bit
|
||||||
|
|
||||||
// just handle 1/15 alpha/rgb
|
// just handle 1/15 alpha/rgb
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
BYTE r,g,b;
|
||||||
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
@ -300,13 +304,14 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
DWORD *pSrcWord = (DWORD *) pbuf;
|
DWORD *pSrcWord = (DWORD *) pbuf;
|
||||||
BYTE *pDstWord;
|
BYTE *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (BYTE*)pDDSurfBytes;
|
pDstWord = (BYTE*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord+=3) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord+=3) {
|
||||||
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
dwPixel = *pSrcWord;
|
BYTE r,g,b;
|
||||||
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
b = (BYTE)((dwPixel>>16) & 0x000000ff);
|
b = (BYTE)((dwPixel>>16) & 0x000000ff);
|
||||||
g = (BYTE)((dwPixel>> 8) & 0x000000ff);
|
g = (BYTE)((dwPixel>> 8) & 0x000000ff);
|
||||||
@ -328,11 +333,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB
|
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB
|
||||||
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x0f00); // assumes ARGB
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x0f00); // assumes ARGB
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
BYTE r,g,b,a;
|
||||||
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
@ -354,10 +360,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
BYTE *pSrcWord = (BYTE *) pbuf;
|
BYTE *pSrcWord = (BYTE *) pbuf;
|
||||||
BYTE *pDstWord;
|
BYTE *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (BYTE*)pDDSurfBytes;
|
pDstWord = (BYTE*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord+=3) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord+=3) {
|
||||||
|
BYTE r,g,b;
|
||||||
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
|
|
||||||
@ -380,10 +387,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00);
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00);
|
||||||
// for some reason, bits are 'in-order' when converting to 16bit
|
// for some reason, bits are 'in-order' when converting to 16bit
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
||||||
|
BYTE r,g,b;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
@ -406,10 +414,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800);
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800);
|
||||||
// for some reason, bits are 'in-order' when converting to 16bit
|
// for some reason, bits are 'in-order' when converting to 16bit
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
||||||
|
BYTE r,g,b;
|
||||||
|
|
||||||
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
// pixel buffer is in ABGR format (orig fmt designed for big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
@ -430,10 +439,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
BYTE *pSrcWord = (BYTE *) pbuf;
|
BYTE *pSrcWord = (BYTE *) pbuf;
|
||||||
DWORD *pDstWord;
|
DWORD *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (DWORD *)pDDSurfBytes;
|
pDstWord = (DWORD *)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord+=3,pDstWord++) {
|
||||||
|
BYTE r,g,b;
|
||||||
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
|
|
||||||
@ -456,13 +466,14 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
WORD *pSrcWord = (WORD *) pbuf;
|
WORD *pSrcWord = (WORD *) pbuf;
|
||||||
DWORD *pDstWord;
|
DWORD *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (DWORD *)pDDSurfBytes;
|
pDstWord = (DWORD *)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
// need to change byte order to ARGB
|
// need to change byte order to ARGB
|
||||||
dwPixel=*pSrcWord;
|
DWORD dwPixel=*pSrcWord;
|
||||||
|
BYTE r,a;
|
||||||
|
|
||||||
a = dwPixel >> 8;
|
a = dwPixel >> 8;
|
||||||
r = dwPixel & 0xFF;
|
r = dwPixel & 0xFF;
|
||||||
@ -479,10 +490,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
|
|
||||||
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB
|
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
|
DWORD dwPixel=*pSrcWord;
|
||||||
|
BYTE r,a;
|
||||||
dwPixel = *pSrcWord;
|
dwPixel = *pSrcWord;
|
||||||
|
|
||||||
a = (BYTE)(dwPixel>>8) >> 4;
|
a = (BYTE)(dwPixel>>8) >> 4;
|
||||||
@ -500,11 +513,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
|
|
||||||
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0x8000); // assumes ARGB
|
assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0x8000); // assumes ARGB
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
DWORD dwPixel=*pSrcWord;
|
||||||
|
BYTE r;
|
||||||
|
|
||||||
r = (BYTE)(dwPixel & 0x000000ff) >> 3;
|
r = (BYTE)(dwPixel & 0x000000ff) >> 3;
|
||||||
|
|
||||||
@ -524,7 +538,7 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
case ConvLum8to16_0555: {
|
case ConvLum8to16_0555: {
|
||||||
BYTE *pSrcWord = (BYTE *) pbuf;
|
BYTE *pSrcWord = (BYTE *) pbuf;
|
||||||
WORD *pDstWord;
|
WORD *pDstWord;
|
||||||
DWORD FarShift,OrVal,MiddleRoundShift,GrnVal;
|
DWORD FarShift,OrVal,MiddleRoundShift;
|
||||||
|
|
||||||
if(ConvNeeded==ConvLum8to16_0555) {
|
if(ConvNeeded==ConvLum8to16_0555) {
|
||||||
FarShift=10; OrVal=0x8000; // turn on alpha bit, just in case
|
FarShift=10; OrVal=0x8000; // turn on alpha bit, just in case
|
||||||
@ -536,11 +550,12 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800);
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800);
|
||||||
}
|
}
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes+=ddsd.lPitch) {
|
||||||
pDstWord = (WORD*)pDDSurfBytes;
|
pDstWord = (WORD*)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel = *pSrcWord;
|
DWORD dwPixel=*pSrcWord,GrnVal;
|
||||||
|
BYTE r;
|
||||||
|
|
||||||
r = (BYTE) dwPixel >> 3;
|
r = (BYTE) dwPixel >> 3;
|
||||||
GrnVal = (BYTE) dwPixel >> MiddleRoundShift;
|
GrnVal = (BYTE) dwPixel >> MiddleRoundShift;
|
||||||
@ -564,11 +579,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
BYTE *pSrcWord = (BYTE *) pbuf;
|
BYTE *pSrcWord = (BYTE *) pbuf;
|
||||||
DWORD *pDstWord;
|
DWORD *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (DWORD *)pDDSurfBytes;
|
pDstWord = (DWORD *)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel=*pSrcWord;
|
DWORD dwPixel=*pSrcWord;
|
||||||
|
|
||||||
*pDstWord = 0xFF000000 | (dwPixel<<16) | (dwPixel<<8) | dwPixel;
|
*pDstWord = 0xFF000000 | (dwPixel<<16) | (dwPixel<<8) | dwPixel;
|
||||||
}
|
}
|
||||||
@ -582,11 +597,11 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
BYTE *pSrcWord = (BYTE *) pbuf;
|
BYTE *pSrcWord = (BYTE *) pbuf;
|
||||||
BYTE *pDstWord;
|
BYTE *pDstWord;
|
||||||
|
|
||||||
for( y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
for(DWORD y=0; y<dwOrigHeight; y++,pDDSurfBytes += ddsd.lPitch) {
|
||||||
pDstWord = (BYTE *)pDDSurfBytes;
|
pDstWord = (BYTE *)pDDSurfBytes;
|
||||||
|
|
||||||
for( x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
for(DWORD x=0; x<dwOrigWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
dwPixel=*pSrcWord;
|
DWORD dwPixel=*pSrcWord;
|
||||||
|
|
||||||
*pDstWord++ = dwPixel;
|
*pDstWord++ = dwPixel;
|
||||||
*pDstWord++ = dwPixel;
|
*pDstWord++ = dwPixel;
|
||||||
@ -607,7 +622,295 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf) {
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
|
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd);
|
||||||
|
|
||||||
|
DWORD dwNumComponents=pixbuf->get_num_components();
|
||||||
|
|
||||||
|
assert(pixbuf->get_component_width()==sizeof(BYTE)); // cant handle anything else now
|
||||||
|
assert(pixbuf->get_image_type()==PixelBuffer::T_unsigned_byte); // cant handle anything else now
|
||||||
|
assert((dwNumComponents==3) || (dwNumComponents==4)); // cant handle anything else now
|
||||||
|
|
||||||
|
BYTE *pbuf=pixbuf->_image.p();
|
||||||
|
|
||||||
|
if(FAILED( hr = pDDSurf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) {
|
||||||
|
dxgsg_cat.error() << "ConvertDDSurftoPixBuf Lock() failed! hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD dwXWindowOffset=0,dwYWindowOffset=0;
|
||||||
|
DWORD dwCopyWidth=ddsd.dwWidth,dwCopyHeight=ddsd.dwHeight;
|
||||||
|
|
||||||
|
// get window offset so we know where to start grabbing pixels
|
||||||
|
LPDIRECTDRAWCLIPPER pDDClipper;
|
||||||
|
hr = pDDSurf->GetClipper(&pDDClipper);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
if(FAILED(hr) && !((hr == DDERR_NOCLIPPERATTACHED) && dx_full_screen)) {
|
||||||
|
dxgsg_cat.error() << "ConvertDDSurftoPixBuf GetClipper failed! hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(hr==S_OK) {
|
||||||
|
HWND hWin;
|
||||||
|
|
||||||
|
if(FAILED(hr = pDDClipper->GetHWnd(&hWin))) {
|
||||||
|
dxgsg_cat.error() << "ConvertDDSurftoPixBuf GetHwnd failed! hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT view_rect;
|
||||||
|
GetClientRect( hWin, &view_rect );
|
||||||
|
ClientToScreen( hWin, (POINT*)&view_rect.left );
|
||||||
|
ClientToScreen( hWin, (POINT*)&view_rect.right );
|
||||||
|
|
||||||
|
dwXWindowOffset=view_rect.left;
|
||||||
|
dwYWindowOffset=view_rect.top;
|
||||||
|
dwCopyWidth=view_rect.right-view_rect.left;
|
||||||
|
dwCopyHeight=view_rect.bottom-view_rect.top;
|
||||||
|
|
||||||
|
pDDClipper->Release(); // dec ref cnt
|
||||||
|
}
|
||||||
|
|
||||||
|
//make sure there's enough space in the pixbuf, its size must match (especially xsize)
|
||||||
|
// or scanlines will be too long
|
||||||
|
|
||||||
|
if(!((dwCopyWidth==pixbuf->get_xsize()) && (dwCopyHeight<=pixbuf->get_ysize()))) {
|
||||||
|
pDDSurf->Unlock(NULL);
|
||||||
|
assert(0);
|
||||||
|
dxgsg_cat.error() << "ConvertDDSurftoPixBuf, PixBuf incorrect size to hold display surface!\n";
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// others not handled yet
|
||||||
|
assert((ddsd.ddpfPixelFormat.dwRGBBitCount==32)||(ddsd.ddpfPixelFormat.dwRGBBitCount==16)||(ddsd.ddpfPixelFormat.dwRGBBitCount==24));
|
||||||
|
|
||||||
|
//pbuf contains raw ARGB in PixelBuffer byteorder
|
||||||
|
|
||||||
|
DWORD lPitch = ddsd.lPitch;
|
||||||
|
BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface;
|
||||||
|
|
||||||
|
if(dwNumComponents==4) {
|
||||||
|
DWORD *pDstWord = (DWORD *) pbuf;
|
||||||
|
switch(ddsd.ddpfPixelFormat.dwRGBBitCount) {
|
||||||
|
|
||||||
|
case 32: {
|
||||||
|
DWORD *pSrcWord;
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcWord = ((DWORD*)pDDSurfBytes)+dwXWindowOffset;
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
|
BYTE r,g,b;
|
||||||
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
|
// need to change byte order from ARGB
|
||||||
|
|
||||||
|
// simpler: just swap r & b
|
||||||
|
r = (BYTE)((dwPixel>>16)&0x000000ff);
|
||||||
|
g = (BYTE)((dwPixel>> 8)&0x000000ff);
|
||||||
|
b = (BYTE)((dwPixel )&0x000000ff);
|
||||||
|
|
||||||
|
*pDstWord = (dwPixel & 0xff00ff00) | (r<<16) | b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 24: {
|
||||||
|
BYTE *pSrcByte;
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcByte = pDDSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++,pDstWord++) {
|
||||||
|
DWORD r,g,b;
|
||||||
|
|
||||||
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
|
// need to change byte order from ARGB
|
||||||
|
|
||||||
|
b = *pSrcByte++;
|
||||||
|
g = *pSrcByte++;
|
||||||
|
r = *pSrcByte++;
|
||||||
|
|
||||||
|
*pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 16: {
|
||||||
|
|
||||||
|
assert((ddsd.ddpfPixelFormat.dwRBitMask==0xF800) || // 565
|
||||||
|
(ddsd.ddpfPixelFormat.dwRBitMask==0x0F00) || // 4444
|
||||||
|
(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00)); // 555 or 1555
|
||||||
|
|
||||||
|
WORD *pSrcWord;
|
||||||
|
// handle 0555,1555,0565 in same loop
|
||||||
|
BYTE redshift,greenshift,blueshift;
|
||||||
|
DWORD redmask,greenmask,bluemask;
|
||||||
|
|
||||||
|
if(ddsd.ddpfPixelFormat.dwRBitMask==0xF800) {
|
||||||
|
redshift=(11-3);
|
||||||
|
redmask=0xF800;
|
||||||
|
greenmask=0x07E0;
|
||||||
|
greenshift=(5-2);
|
||||||
|
bluemask=0x001F;
|
||||||
|
blueshift=3;
|
||||||
|
} else if(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00) {
|
||||||
|
redmask=0x7C00;
|
||||||
|
redshift=(10-3);
|
||||||
|
greenmask=0x03E0;
|
||||||
|
greenshift=(5-3);
|
||||||
|
bluemask=0x001F;
|
||||||
|
blueshift=3;
|
||||||
|
} else {
|
||||||
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x0F00);
|
||||||
|
redmask=0x0F00;
|
||||||
|
redshift=4;
|
||||||
|
greenmask=0x00F0;
|
||||||
|
greenshift=0;
|
||||||
|
bluemask=0x000F;
|
||||||
|
blueshift=4;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcWord = ((WORD*)pDDSurfBytes)+dwXWindowOffset;
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++,pDstWord++) {
|
||||||
|
WORD dwPixel = *pSrcWord;
|
||||||
|
BYTE r,g,b;
|
||||||
|
|
||||||
|
b = (dwPixel & bluemask) << blueshift;
|
||||||
|
g = (dwPixel & greenmask) >> greenshift;
|
||||||
|
r = (dwPixel & redmask) >> redshift;
|
||||||
|
|
||||||
|
*pDstWord = 0xFF000000 | (b << 16) | (g << 8) | r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else { // convert to 24bpp pixbuf
|
||||||
|
BYTE *pDstWord = (BYTE *) pbuf;
|
||||||
|
switch(ddsd.ddpfPixelFormat.dwRGBBitCount) {
|
||||||
|
|
||||||
|
case 32: {
|
||||||
|
DWORD *pSrcWord;
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcWord = ((DWORD*)pDDSurfBytes)+dwXWindowOffset;
|
||||||
|
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++) {
|
||||||
|
BYTE r,g,b;
|
||||||
|
DWORD dwPixel = *pSrcWord;
|
||||||
|
|
||||||
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
|
// need to change byte order to ARGB
|
||||||
|
|
||||||
|
// simpler: just swap r & b
|
||||||
|
r = (BYTE)((dwPixel>>16)&0x000000ff);
|
||||||
|
g = (BYTE)((dwPixel>> 8)&0x000000ff);
|
||||||
|
b = (BYTE)((dwPixel )&0x000000ff);
|
||||||
|
|
||||||
|
*pDstWord++ = r;
|
||||||
|
*pDstWord++ = g;
|
||||||
|
*pDstWord++ = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 24: {
|
||||||
|
BYTE *pSrcByte,*pDstByte;
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcByte = pDDSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++) {
|
||||||
|
BYTE r,g,b;
|
||||||
|
|
||||||
|
// pixel buffer is in ABGR format(it stores big-endian RGBA)
|
||||||
|
// need to change byte order from ARGB
|
||||||
|
|
||||||
|
b = *pSrcByte++;
|
||||||
|
g = *pSrcByte++;
|
||||||
|
r = *pSrcByte++;
|
||||||
|
|
||||||
|
*pDstByte++ = r;
|
||||||
|
*pDstByte++ = g;
|
||||||
|
*pDstByte++ = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 16: { // handle 555,1555,565,4444 cases (not 8-8 yet)
|
||||||
|
|
||||||
|
assert((ddsd.ddpfPixelFormat.dwRBitMask==0xF800) || // 565
|
||||||
|
(ddsd.ddpfPixelFormat.dwRBitMask==0x0F00) || // 4444
|
||||||
|
(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00)); // 555 or 1555
|
||||||
|
|
||||||
|
WORD *pSrcWord;
|
||||||
|
// handle 0555,1555,0565 in same loop
|
||||||
|
BYTE redshift,greenshift,blueshift;
|
||||||
|
DWORD redmask,greenmask,bluemask;
|
||||||
|
|
||||||
|
if(ddsd.ddpfPixelFormat.dwRBitMask==0xF800) {
|
||||||
|
redshift=(11-3);
|
||||||
|
redmask=0xF800;
|
||||||
|
greenmask=0x07E0;
|
||||||
|
greenshift=(5-2);
|
||||||
|
bluemask=0x001F;
|
||||||
|
blueshift=3;
|
||||||
|
} else if(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00) {
|
||||||
|
redmask=0x7C00;
|
||||||
|
redshift=(10-3);
|
||||||
|
greenmask=0x03E0;
|
||||||
|
greenshift=(5-3);
|
||||||
|
bluemask=0x001F;
|
||||||
|
blueshift=3;
|
||||||
|
} else {
|
||||||
|
assert(ddsd.ddpfPixelFormat.dwRBitMask==0x0F00);
|
||||||
|
redmask=0x0F00;
|
||||||
|
redshift=4;
|
||||||
|
greenmask=0x00F0;
|
||||||
|
greenshift=0;
|
||||||
|
bluemask=0x000F;
|
||||||
|
blueshift=4;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||||
|
for(DWORD y=0; y<dwCopyHeight; y++,pDDSurfBytes-=ddsd.lPitch) {
|
||||||
|
pSrcWord = ((WORD*)pDDSurfBytes)+dwXWindowOffset;
|
||||||
|
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++) {
|
||||||
|
WORD dwPixel = *pSrcWord;
|
||||||
|
BYTE r,g,b;
|
||||||
|
|
||||||
|
b = (dwPixel & bluemask) << blueshift;
|
||||||
|
g = (dwPixel & greenmask) >> greenshift;
|
||||||
|
r = (dwPixel & redmask) >> redshift;
|
||||||
|
|
||||||
|
*pDstWord++ = r;
|
||||||
|
*pDstWord++ = g;
|
||||||
|
*pDstWord++ = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pDDSurf->Unlock(NULL);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Name: CreateTextureFromBitmap()
|
// Name: CreateTextureFromBitmap()
|
||||||
@ -653,7 +956,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// Get the device caps so we can check if the device has any constraints
|
// Get the device caps so we can check if the device has any constraints
|
||||||
// when using textures
|
// when using textures
|
||||||
D3DDEVICEDESC7 devDesc;
|
D3DDEVICEDESC7 devDesc;
|
||||||
if( FAILED( pd3dDevice->GetCaps( &devDesc ) ) ) {
|
if(FAILED( pd3dDevice->GetCaps( &devDesc ) )) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,20 +982,18 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
ddsd.ddpfPixelFormat.dwRGBBitCount = bpp;
|
ddsd.ddpfPixelFormat.dwRGBBitCount = bpp;
|
||||||
|
|
||||||
if (cNumAlphaBits) {
|
if(cNumAlphaBits) {
|
||||||
if (bpp == 8 && cNumAlphaBits == 8) // handle special case: Alpha only buffer
|
if(bpp == 8 && cNumAlphaBits == 8) { // handle special case: Alpha only buffer
|
||||||
{
|
|
||||||
ddsd.dwFlags |= DDPF_ALPHA;
|
ddsd.dwFlags |= DDPF_ALPHA;
|
||||||
ddsd.dwAlphaBitDepth = 8;
|
ddsd.dwAlphaBitDepth = 8;
|
||||||
ddsd.ddpfPixelFormat.dwAlphaBitDepth = 8;
|
ddsd.ddpfPixelFormat.dwAlphaBitDepth = 8;
|
||||||
ddsd.ddpfPixelFormat.dwFlags = DDPF_ALPHA;
|
ddsd.ddpfPixelFormat.dwFlags = DDPF_ALPHA;
|
||||||
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff;
|
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ddsd.ddpfPixelFormat.dwFlags |= DDPF_ALPHAPIXELS;
|
ddsd.ddpfPixelFormat.dwFlags |= DDPF_ALPHAPIXELS;
|
||||||
if (cNumAlphaBits == 8)
|
if(cNumAlphaBits == 8)
|
||||||
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
|
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
|
||||||
else if (cNumAlphaBits == 4)
|
else if(cNumAlphaBits == 4)
|
||||||
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xf000;
|
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xf000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -700,25 +1001,25 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
ddsd.dwWidth = dwOrigWidth;
|
ddsd.dwWidth = dwOrigWidth;
|
||||||
ddsd.dwHeight = dwOrigHeight;
|
ddsd.dwHeight = dwOrigHeight;
|
||||||
|
|
||||||
#define ISPOW2(X) (((X) & ((X)-1))==0)
|
#define ISPOW2(X) (((X) & ((X)-1))==0)
|
||||||
|
|
||||||
if(!ISPOW2(ddsd.dwWidth) || !ISPOW2(ddsd.dwHeight)) {
|
if(!ISPOW2(ddsd.dwWidth) || !ISPOW2(ddsd.dwHeight)) {
|
||||||
dxgsg_cat.error() << "ERROR: texture dimensions are not a power of 2 for " << _tex->get_name() << "!!!!! \n";
|
dxgsg_cat.error() << "ERROR: texture dimensions are not a power of 2 for " << _tex->get_name() << "!!!!! \n";
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
exit(1); // want to catch badtexsize errors
|
exit(1); // want to catch badtexsize errors
|
||||||
#else
|
#else
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL bShrinkOriginal;
|
BOOL bShrinkOriginal;
|
||||||
|
|
||||||
bShrinkOriginal=FALSE;
|
bShrinkOriginal=FALSE;
|
||||||
if((dwOrigWidth>devDesc.dwMaxTextureWidth)||(dwOrigHeight>devDesc.dwMaxTextureHeight)) {
|
if((dwOrigWidth>devDesc.dwMaxTextureWidth)||(dwOrigHeight>devDesc.dwMaxTextureHeight)) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !!\n"
|
dxgsg_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !!\n"
|
||||||
<< "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !\n";
|
<< "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< devDesc.dwMaxTextureWidth << "," << devDesc.dwMaxTextureHeight << ") !\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(dwOrigWidth>devDesc.dwMaxTextureWidth)
|
if(dwOrigWidth>devDesc.dwMaxTextureWidth)
|
||||||
ddsd.dwWidth=devDesc.dwMaxTextureWidth;
|
ddsd.dwWidth=devDesc.dwMaxTextureWidth;
|
||||||
@ -730,7 +1031,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
#if 0
|
#if 0
|
||||||
// checks for SQUARE reqmt
|
// checks for SQUARE reqmt
|
||||||
//riva128 seems to handle non-sq fine. is it wasting mem to do this? do I care or should I shrink to be sure we save mem?
|
//riva128 seems to handle non-sq fine. is it wasting mem to do this? do I care or should I shrink to be sure we save mem?
|
||||||
if( (ddsd.dwWidth != ddsd.dwHeight) && (devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
|
if((ddsd.dwWidth != ddsd.dwHeight) && (devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) {
|
||||||
|
|
||||||
// assume pow2 textures. sum exponents, divide by 2 rounding down to get sq size
|
// assume pow2 textures. sum exponents, divide by 2 rounding down to get sq size
|
||||||
int i,width_exp,height_exp;
|
int i,width_exp,height_exp;
|
||||||
@ -739,9 +1040,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
ddsd.dwHeight = ddsd.dwWidth = 1<<((width_exp+height_exp)>>1);
|
ddsd.dwHeight = ddsd.dwWidth = 1<<((width_exp+height_exp)>>1);
|
||||||
bShrinkOriginal=TRUE;
|
bShrinkOriginal=TRUE;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dxgsg_cat.debug() << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< ddsd.dwWidth<<"," << ddsd.dwHeight << ") to meet HW square texture reqmt\n";
|
dxgsg_cat.debug() << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," <<dwOrigHeight << ") => ("<< ddsd.dwWidth<<"," << ddsd.dwHeight << ") to meet HW square texture reqmt\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -766,7 +1067,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
{ static BOOL bPrinted=FALSE;
|
{ static BOOL bPrinted=FALSE;
|
||||||
if(!bPrinted) {
|
if(!bPrinted) {
|
||||||
dxgsg_cat.debug() << "Gfx card supported TexFmts:\n";
|
dxgsg_cat.debug() << "Gfx card supported TexFmts:\n";
|
||||||
for(i=0;i<cNumTexPixFmts;i++) { DebugPrintPixFmt(&pTexPixFmts[i]); }
|
for(i=0;i<cNumTexPixFmts;i++) {
|
||||||
|
DebugPrintPixFmt(&pTexPixFmts[i]);
|
||||||
|
}
|
||||||
bPrinted=TRUE;
|
bPrinted=TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -784,7 +1087,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
// Mark formats I dont want to deal with
|
// Mark formats I dont want to deal with
|
||||||
for(i=0,pCurPixFmt=pTexPixFmts;i<cNumTexPixFmts;i++,pCurPixFmt++) {
|
for(i=0,pCurPixFmt=pTexPixFmts;i<cNumTexPixFmts;i++,pCurPixFmt++) {
|
||||||
if( ( pCurPixFmt->dwFlags & (DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) ) ||
|
if(( pCurPixFmt->dwFlags & (DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) ) ||
|
||||||
( pCurPixFmt->dwFourCC != 0 ) ||
|
( pCurPixFmt->dwFourCC != 0 ) ||
|
||||||
((cNumAlphaBits==0) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS))) {
|
((cNumAlphaBits==0) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS))) {
|
||||||
|
|
||||||
@ -833,9 +1136,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion
|
// assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion
|
||||||
// this should be true on most cards.
|
// this should be true on most cards.
|
||||||
|
|
||||||
#ifndef FORCE_16bpp_1555
|
#ifndef FORCE_16bpp_1555
|
||||||
if(cNumAlphaBits==1)
|
if(cNumAlphaBits==1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ConvTo1=Conv32to16_1555;
|
ConvTo1=Conv32to16_1555;
|
||||||
dwAlphaMask1=0x8000;
|
dwAlphaMask1=0x8000;
|
||||||
@ -849,9 +1152,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FORCE_16bpp_1555
|
#ifdef FORCE_16bpp_1555
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
||||||
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)
|
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)
|
||||||
@ -885,6 +1188,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(!dx_force_16bpptextures)
|
if(!dx_force_16bpptextures)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// no 24-bit fmt. look for 32 bit fmt (note: this is memory-hogging choice
|
// no 24-bit fmt. look for 32 bit fmt (note: this is memory-hogging choice
|
||||||
// instead I could look for memory-conserving 16-bit fmt).
|
// instead I could look for memory-conserving 16-bit fmt).
|
||||||
// check mask to ensure ARGB, not RGBA (which I am not handling here)
|
// check mask to ensure ARGB, not RGBA (which I am not handling here)
|
||||||
@ -922,9 +1226,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
if(ddsd.ddpfPixelFormat.dwFlags & DDPF_LUMINANCE) {
|
if(ddsd.ddpfPixelFormat.dwFlags & DDPF_LUMINANCE) {
|
||||||
// look for native lum fmt
|
// look for native lum fmt
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(!dx_force_16bpptextures)
|
if(!dx_force_16bpptextures)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
||||||
@ -951,9 +1255,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion
|
// assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion
|
||||||
// this should be true on most cards.
|
// this should be true on most cards.
|
||||||
|
|
||||||
#ifndef FORCE_16bpp_1555
|
#ifndef FORCE_16bpp_1555
|
||||||
if(cNumAlphaBits==1)
|
if(cNumAlphaBits==1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ConvTo1=ConvLum16to16_1555;
|
ConvTo1=ConvLum16to16_1555;
|
||||||
dwAlphaMask1=0x8000;
|
dwAlphaMask1=0x8000;
|
||||||
@ -967,9 +1271,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FORCE_16bpp_1555
|
#ifdef FORCE_16bpp_1555
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
||||||
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)
|
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)
|
||||||
@ -1026,9 +1330,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// look for native lum fmt
|
// look for native lum fmt
|
||||||
|
|
||||||
assert(cNumAlphaBits==0); // dont handle those other 8bit lum fmts like 4-4, since 16 8-8 is usually supported too
|
assert(cNumAlphaBits==0); // dont handle those other 8bit lum fmts like 4-4, since 16 8-8 is usually supported too
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(!dx_force_16bpptextures)
|
if(!dx_force_16bpptextures)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i<cNumTexPixFmts;i++,pCurPixFmt--) {
|
||||||
if((pCurPixFmt->dwRGBBitCount==8) && (pCurPixFmt->dwFlags & DDPF_LUMINANCE) &&
|
if((pCurPixFmt->dwRGBBitCount==8) && (pCurPixFmt->dwFlags & DDPF_LUMINANCE) &&
|
||||||
@ -1056,13 +1360,13 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find compatible 16bpp fmt, just look for any 565, then 0555
|
// find compatible 16bpp fmt, just look for any 565, then 0555
|
||||||
DWORD dwMasks[2] = {0xF800, 0x7C00 };
|
DWORD dwMasks[2] = {0xF800, 0x7C00};
|
||||||
|
|
||||||
for (DWORD modenum=0;modenum<2;modenum++)
|
for(DWORD modenum=0;modenum<2;modenum++)
|
||||||
for(i=0,pCurPixFmt=&pTexPixFmts[0];i<cNumTexPixFmts;i++,pCurPixFmt++) {
|
for(i=0,pCurPixFmt=&pTexPixFmts[0];i<cNumTexPixFmts;i++,pCurPixFmt++) {
|
||||||
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_RGB)
|
if((pCurPixFmt->dwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_RGB)
|
||||||
&& (!(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS))
|
&& (!(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS))
|
||||||
&& (pCurPixFmt->dwRBitMask==dwMasks[modenum]) ) {
|
&& (pCurPixFmt->dwRBitMask==dwMasks[modenum])) {
|
||||||
ConvNeeded=ConvLum8to16_0565;
|
ConvNeeded=ConvLum8to16_0565;
|
||||||
goto found_matching_format;
|
goto found_matching_format;
|
||||||
}
|
}
|
||||||
@ -1121,9 +1425,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
bDoMipMaps=FALSE;
|
bDoMipMaps=FALSE;
|
||||||
|
|
||||||
if(!dx_ignore_mipmaps) { // set if no HW mipmap capable
|
if(!dx_ignore_mipmaps) { // set if no HW mipmap capable
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
bDoMipMaps=dx_mipmap_everything;
|
bDoMipMaps=dx_mipmap_everything;
|
||||||
#endif
|
#endif
|
||||||
switch(ft) {
|
switch(ft) {
|
||||||
case Texture::FT_nearest_mipmap_nearest:
|
case Texture::FT_nearest_mipmap_nearest:
|
||||||
case Texture::FT_linear_mipmap_nearest:
|
case Texture::FT_linear_mipmap_nearest:
|
||||||
@ -1178,9 +1482,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
aniso_degree=devDesc.dwMaxAnisotropy;
|
aniso_degree=devDesc.dwMaxAnisotropy;
|
||||||
}
|
}
|
||||||
_tex->set_anisotropic_degree(aniso_degree);
|
_tex->set_anisotropic_degree(aniso_degree);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dxgsg_cat.spam() << "CreateTexture: setting aniso degree for "<< _tex->get_name() << " to: " << aniso_degree << endl;
|
dxgsg_cat.spam() << "CreateTexture: setting aniso degree for "<< _tex->get_name() << " to: " << aniso_degree << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(bDoMipMaps) {
|
if(bDoMipMaps) {
|
||||||
// We dont specify mipmapcount, so CreateSurface will auto-create surfs
|
// We dont specify mipmapcount, so CreateSurface will auto-create surfs
|
||||||
@ -1199,8 +1503,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
PRINTVIDMEM(pDD,&ddsd.ddsCaps,"texture surf (includes AGP mem)");
|
PRINTVIDMEM(pDD,&ddsd.ddsCaps,"texture surf (includes AGP mem)");
|
||||||
|
|
||||||
// Create a new surface for the texture
|
// Create a new surface for the texture
|
||||||
if( FAILED( hr = pDD->CreateSurface( &ddsd, &_surface, NULL ) ) )
|
if(FAILED( hr = pDD->CreateSurface( &ddsd, &_surface, NULL ) )) {
|
||||||
{
|
|
||||||
dxgsg_cat.error() << "CreateTexture failed: pDD->CreateSurface() failed! hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << "CreateTexture failed: pDD->CreateSurface() failed! hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -1261,9 +1564,9 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
DWORD x_srcptr_inc = ((oldcurxsize==1)? cPixelSize: (2*cPixelSize));
|
DWORD x_srcptr_inc = ((oldcurxsize==1)? cPixelSize: (2*cPixelSize));
|
||||||
|
|
||||||
// box-filter shrink down, avg 4 pixels at a time
|
// box-filter shrink down, avg 4 pixels at a time
|
||||||
for( y=0; y<curysize; y++,pSrcLineStart+=two_src_row_bytelength) {
|
for(y=0; y<curysize; y++,pSrcLineStart+=two_src_row_bytelength) {
|
||||||
pSrcWord=pSrcLineStart;
|
pSrcWord=pSrcLineStart;
|
||||||
for( x=0; x<curxsize; x++,pSrcWord+=x_srcptr_inc,pDstWord+=cPixelSize) {
|
for(x=0; x<curxsize; x++,pSrcWord+=x_srcptr_inc,pDstWord+=cPixelSize) {
|
||||||
// fetches, stores byte at a time.
|
// fetches, stores byte at a time.
|
||||||
// inefficient, but works for all channel sizes
|
// inefficient, but works for all channel sizes
|
||||||
|
|
||||||
@ -1295,7 +1598,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
|
|
||||||
hr = pCurDDSurf->GetAttachedSurface(&ddsCaps, &pMipLevel_DDSurf);
|
hr = pCurDDSurf->GetAttachedSurface(&ddsCaps, &pMipLevel_DDSurf);
|
||||||
if (FAILED(hr)) {
|
if(FAILED(hr)) {
|
||||||
dxgsg_cat.error() << "CreateTexture failed creating mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << "CreateTexture failed creating mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
pCurDDSurf->Release();
|
pCurDDSurf->Release();
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
@ -1319,7 +1622,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
delete pMipMapPixBufSpace;
|
delete pMipMapPixBufSpace;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(dx_debug_view_mipmaps) {
|
if(dx_debug_view_mipmaps) {
|
||||||
#if 0
|
#if 0
|
||||||
if(!(ddcaps.dwCaps & DDCAPS_BLTSTRETCH)) {
|
if(!(ddcaps.dwCaps & DDCAPS_BLTSTRETCH)) {
|
||||||
@ -1344,13 +1647,13 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
pTexturePrev->AddRef();
|
pTexturePrev->AddRef();
|
||||||
|
|
||||||
|
|
||||||
for (i = 0,curx=scrnrect.left,cury=scrnrect.top; i < ddsd.dwMipMapCount; i++) {
|
for(i = 0,curx=scrnrect.left,cury=scrnrect.top; i < ddsd.dwMipMapCount; i++) {
|
||||||
|
|
||||||
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_cur);
|
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_cur);
|
||||||
pTexturePrev->GetSurfaceDesc(&ddsd_cur);
|
pTexturePrev->GetSurfaceDesc(&ddsd_cur);
|
||||||
|
|
||||||
hr = pTexturePrev->GetDC(&hTexDC);
|
hr = pTexturePrev->GetDC(&hTexDC);
|
||||||
if (FAILED(hr)) {
|
if(FAILED(hr)) {
|
||||||
dxgsg_cat.error() << "GetDC failed hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << "GetDC failed hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1360,13 +1663,14 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// loader inverts y, so use StretchBlt to re-invert it
|
// loader inverts y, so use StretchBlt to re-invert it
|
||||||
// res = StretchBlt(PrimaryDC,0,ddsd_cur.dwHeight+cury,ddsd_cur.dwWidth,-ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,SRCCOPY);
|
// res = StretchBlt(PrimaryDC,0,ddsd_cur.dwHeight+cury,ddsd_cur.dwWidth,-ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,SRCCOPY);
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
// dxgsg_cat.error() << "WINVER = " << (void*)WINVER << "\n";
|
// dxgsg_cat.error() << "WINVER = " << (void*)WINVER << "\n";
|
||||||
if(cNumAlphaBits>0) {
|
if(cNumAlphaBits>0) {
|
||||||
BLENDFUNCTION bf;
|
BLENDFUNCTION bf;
|
||||||
bf.BlendOp = AC_SRC_OVER; bf.BlendFlags=0;
|
bf.BlendOp = AC_SRC_OVER; bf.BlendFlags=0;
|
||||||
bf.SourceConstantAlpha=255; bf.AlphaFormat=AC_SRC_ALPHA;
|
bf.SourceConstantAlpha=255; bf.AlphaFormat=AC_SRC_ALPHA;
|
||||||
res = AlphaBlend(hScreenDC,curx,cury,ddsd_cur.dwWidth,ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,bf);
|
res = AlphaBlend(hScreenDC,curx,cury,ddsd_cur.dwWidth,ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,bf);
|
||||||
if (!res) {
|
if(!res) {
|
||||||
PrintLastError(msg);
|
PrintLastError(msg);
|
||||||
dxgsg_cat.error() << "AlphaBlend BLT failed: "<<msg<<"\n";
|
dxgsg_cat.error() << "AlphaBlend BLT failed: "<<msg<<"\n";
|
||||||
}
|
}
|
||||||
@ -1375,7 +1679,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
res = StretchBlt(hScreenDC,curx,ddsd_cur.dwHeight+cury,ddsd_cur.dwWidth,-ddsd_cur.dwHeight, hTexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,SRCCOPY);
|
res = StretchBlt(hScreenDC,curx,ddsd_cur.dwHeight+cury,ddsd_cur.dwWidth,-ddsd_cur.dwHeight, hTexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,SRCCOPY);
|
||||||
if (!res) {
|
if(!res) {
|
||||||
PrintLastError(msg);
|
PrintLastError(msg);
|
||||||
dxgsg_cat.error() << "StretchBLT failed: "<<msg<<"\n";
|
dxgsg_cat.error() << "StretchBLT failed: "<<msg<<"\n";
|
||||||
|
|
||||||
@ -1393,7 +1697,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
|
|
||||||
hr = pTexturePrev->ReleaseDC(hTexDC);
|
hr = pTexturePrev->ReleaseDC(hTexDC);
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if(FAILED(hr)) {
|
||||||
dxgsg_cat.error() << "tex ReleaseDC failed for mip "<<i<<" hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << "tex ReleaseDC failed for mip "<<i<<" hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1408,7 +1712,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
|
ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
|
||||||
ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
|
ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
|
||||||
hr = pTexturePrev->GetAttachedSurface(&ddsCaps, &pTextureCurrent);
|
hr = pTexturePrev->GetAttachedSurface(&ddsCaps, &pTextureCurrent);
|
||||||
if (FAILED(hr)) {
|
if(FAILED(hr)) {
|
||||||
dxgsg_cat.error() << " failed displaying mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n";
|
dxgsg_cat.error() << " failed displaying mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n";
|
||||||
}
|
}
|
||||||
// done with the previous texture
|
// done with the previous texture
|
||||||
@ -1431,7 +1735,7 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
dxgsg_cat.error() << " MsgWaitForMultipleObjects returns " << val << endl;
|
dxgsg_cat.error() << " MsgWaitForMultipleObjects returns " << val << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done with DDraw
|
// Done with DDraw
|
||||||
@ -1458,9 +1762,8 @@ CreateTexture( HDC PrimaryDC, LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts,
|
|||||||
// Desc: Release the surface used to store the texture
|
// Desc: Release the surface used to store the texture
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void DXTextureContext::
|
void DXTextureContext::
|
||||||
DeleteTexture( )
|
DeleteTexture( ) {
|
||||||
{
|
if(_surface) _surface->Release();
|
||||||
if (_surface) _surface->Release();
|
|
||||||
_surface = NULL;
|
_surface = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1472,8 +1775,7 @@ DeleteTexture( )
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
DXTextureContext::
|
DXTextureContext::
|
||||||
DXTextureContext(Texture *tex) :
|
DXTextureContext(Texture *tex) :
|
||||||
TextureContext(tex)
|
TextureContext(tex) {
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dxgsg_cat.spam() << "Making DX texture for " << tex->get_name() << "\n";
|
dxgsg_cat.spam() << "Making DX texture for " << tex->get_name() << "\n";
|
||||||
#endif
|
#endif
|
||||||
@ -1482,8 +1784,7 @@ DXTextureContext(Texture *tex) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
DXTextureContext::
|
DXTextureContext::
|
||||||
~DXTextureContext()
|
~DXTextureContext() {
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dxgsg_cat.spam() << "Deleting DX texture for " << _tex->get_name() << "\n";
|
dxgsg_cat.spam() << "Deleting DX texture for " << _tex->get_name() << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user