reduce conversions
This commit is contained in:
@@ -138,6 +138,24 @@ SDL_Surface *RageBitmapTexture::CreateImg(int &pixfmt)
|
|||||||
if(img == NULL)
|
if(img == NULL)
|
||||||
RageException::Throw( "Couldn't load %s: %s", GetFilePath().GetString(), SDL_GetError() );
|
RageException::Throw( "Couldn't load %s: %s", GetFilePath().GetString(), SDL_GetError() );
|
||||||
|
|
||||||
|
if(m_ActualID.bHotPinkColorKey)
|
||||||
|
{
|
||||||
|
/* Annoying: SDL will do a nearest-match on paletted images if
|
||||||
|
* they don't have the color we ask for, so images without HOT PINK
|
||||||
|
* will get some other random color transparent. We have to make
|
||||||
|
* sure the value returned for paletted images is exactly #FF00FF. */
|
||||||
|
int color = SDL_MapRGB(img->format, 0xFF, 0, 0xFF);
|
||||||
|
if( img->format->BitsPerPixel == 8 ) {
|
||||||
|
if(img->format->palette->colors[color].r != 0xFF ||
|
||||||
|
img->format->palette->colors[color].g != 0x00 ||
|
||||||
|
img->format->palette->colors[color].b != 0xFF )
|
||||||
|
color = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( color != -1 )
|
||||||
|
SDL_SetColorKey( img, SDL_SRCCOLORKEY, color);
|
||||||
|
}
|
||||||
|
|
||||||
GLenum fmtTexture;
|
GLenum fmtTexture;
|
||||||
/* Figure out which texture format to use. */
|
/* Figure out which texture format to use. */
|
||||||
if( m_ActualID.iColorDepth == 16 )
|
if( m_ActualID.iColorDepth == 16 )
|
||||||
@@ -243,7 +261,7 @@ SDL_Surface *RageBitmapTexture::CreateImg(int &pixfmt)
|
|||||||
*/
|
*/
|
||||||
/* We could check to see if we happen to simply be in a reversed
|
/* We could check to see if we happen to simply be in a reversed
|
||||||
* pixel order, and tell OpenGL to do the switch for us. */
|
* pixel order, and tell OpenGL to do the switch for us. */
|
||||||
ConvertSDLSurface(img, m_iTextureWidth, m_iTextureHeight, PixFmtMasks[pixfmt].bpp,
|
ConvertSDLSurface(img, img->w, img->h, PixFmtMasks[pixfmt].bpp,
|
||||||
PixFmtMasks[pixfmt].masks[0], PixFmtMasks[pixfmt].masks[1],
|
PixFmtMasks[pixfmt].masks[0], PixFmtMasks[pixfmt].masks[1],
|
||||||
PixFmtMasks[pixfmt].masks[2], PixFmtMasks[pixfmt].masks[3]);
|
PixFmtMasks[pixfmt].masks[2], PixFmtMasks[pixfmt].masks[3]);
|
||||||
|
|
||||||
@@ -275,8 +293,14 @@ void RageBitmapTexture::Create()
|
|||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, PixFmtMasks[pixfmt].internalfmt, img->w, img->h, 0,
|
|
||||||
GL_RGBA, PixFmtMasks[pixfmt].type, img->pixels);
|
/* Here's a trick for loading a texture that doesn't necessarily have power-of-two
|
||||||
|
* dimensions into a texture, without wasting time converting it: */
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, PixFmtMasks[pixfmt].internalfmt, power_of_two(img->w), power_of_two(img->h), 0,
|
||||||
|
GL_RGBA, PixFmtMasks[pixfmt].type, NULL);
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
|
||||||
|
img->w, img->h, GL_RGBA, PixFmtMasks[pixfmt].type, img->pixels);
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ void mySDL_GetBitsPerChannel(const SDL_PixelFormat *fmt, Uint32 bits[4])
|
|||||||
bits[2] = 8 - fmt->Bloss;
|
bits[2] = 8 - fmt->Bloss;
|
||||||
bits[3] = 8 - fmt->Aloss;
|
bits[3] = 8 - fmt->Aloss;
|
||||||
}
|
}
|
||||||
|
#include "RageLog.h"
|
||||||
|
|
||||||
void ConvertSDLSurface(SDL_Surface *&image,
|
void ConvertSDLSurface(SDL_Surface *&image,
|
||||||
int width, int height, int bpp,
|
int width, int height, int bpp,
|
||||||
@@ -149,35 +150,18 @@ void ConvertSDLSurface(SDL_Surface *&image,
|
|||||||
SDL_SWSURFACE, width, height, bpp, R, G, B, A);
|
SDL_SWSURFACE, width, height, bpp, R, G, B, A);
|
||||||
ASSERT(ret_image != NULL);
|
ASSERT(ret_image != NULL);
|
||||||
|
|
||||||
/* If the formats are the same, no conversion is needed. */
|
/* If the formats are the same, no conversion is needed. One exception:
|
||||||
/* if(width == image->w && height == image->h &&
|
* if we have a color key and we're not paletted (8-bit). (If we have
|
||||||
|
* a color key but we're paletted, we'll handle this on texture load.) xxx unimplemented */
|
||||||
|
if(!(image->flags & SDL_SRCCOLORKEY) &&
|
||||||
|
width == image->w && height == image->h &&
|
||||||
!memcmp(image->format, ret_image->format, sizeof(SDL_PixelFormat)))
|
!memcmp(image->format, ret_image->format, sizeof(SDL_PixelFormat)))
|
||||||
{
|
{
|
||||||
|
LOG->Trace("noconv");
|
||||||
SDL_FreeSurface(ret_image);
|
SDL_FreeSurface(ret_image);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
It's needed because of the color key; the blit converts it to alpha. (Gah.) */
|
|
||||||
|
|
||||||
/* I'd really like to do away with this, but a lot of song images use it.
|
|
||||||
* I suppose this should be yet another hint, but they're getting cumbersome ... */
|
|
||||||
if(!(image->flags & SDL_SRCCOLORKEY)) {
|
|
||||||
/* Annoying: SDL will do a nearest-match on paletted images if
|
|
||||||
* they don't have the color we ask for, so images without HOT PINK
|
|
||||||
* will get some other random color transparent; so we have to make
|
|
||||||
* sure the value returned for paletted images is exactly #FF00FF. */
|
|
||||||
int color = SDL_MapRGB(image->format, 0xFF, 0, 0xFF);
|
|
||||||
if( image->format->BitsPerPixel == 8 ) {
|
|
||||||
if(image->format->palette->colors[color].r != 0xFF ||
|
|
||||||
image->format->palette->colors[color].g != 0x00 ||
|
|
||||||
image->format->palette->colors[color].b != 0xFF )
|
|
||||||
color = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( color != -1 )
|
|
||||||
SDL_SetColorKey( image, SDL_SRCCOLORKEY, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We don't want to actually blend the alpha channel over the destination converted
|
/* We don't want to actually blend the alpha channel over the destination converted
|
||||||
* surface; we want to simply blit it, so make sure SDL_SRCALPHA is not on. */
|
* surface; we want to simply blit it, so make sure SDL_SRCALPHA is not on. */
|
||||||
SDL_SetAlpha( image, 0, SDL_ALPHA_OPAQUE );
|
SDL_SetAlpha( image, 0, SDL_ALPHA_OPAQUE );
|
||||||
|
|||||||
Reference in New Issue
Block a user