From cfaf8b836b21842b5d22ad774f93c2c364d33c0b Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Sun, 14 Aug 2005 23:57:06 +0000 Subject: Fully removed the useOpenGL global. --- src/resources/image.cpp | 96 ++++++++++++++++++++++++++++++------------------- src/resources/image.h | 10 ++++++ 2 files changed, 69 insertions(+), 37 deletions(-) (limited to 'src/resources') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 4efe12e7..a468bb30 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -27,7 +27,9 @@ #include "../log.h" -extern bool useOpenGL; +#ifdef USE_OPENGL +bool Image::useOpenGL = false; +#endif Image::Image(SDL_Surface *image): image(image) @@ -149,27 +151,9 @@ Image* Image::load(void* buffer, unsigned int bufferSize) SDL_SetAlpha(tmpImage, SDL_SRCALPHA | SDL_RLEACCEL, SDL_ALPHA_OPAQUE); } - if (!useOpenGL) { - // Set color key and alpha blending optins, and convert the surface to the - // current display format - SDL_Surface *prevImage = tmpImage; - if (hasAlpha) { - image = SDL_DisplayFormatAlpha(tmpImage); - } - else { - image = SDL_DisplayFormat(tmpImage); - } - SDL_FreeSurface(prevImage); - - if (image == NULL) { - logger->log("Error: Image convert failed."); - return NULL; - } - - return new Image(image); - } #ifdef USE_OPENGL - else { + if (useOpenGL) + { int width = tmpImage->w; int height = tmpImage->h; int realWidth = 1, realHeight = 1; @@ -252,19 +236,44 @@ Image* Image::load(void* buffer, unsigned int bufferSize) return new Image(texture, width, height, realWidth, realHeight); } -#else - return NULL; #endif + + // Set color key and alpha blending optins, and convert the surface to the + // current display format + SDL_Surface *prevImage = tmpImage; + if (hasAlpha) { + image = SDL_DisplayFormatAlpha(tmpImage); + } + else { + image = SDL_DisplayFormat(tmpImage); + } + SDL_FreeSurface(prevImage); + + if (image == NULL) { + logger->log("Error: Image convert failed."); + return NULL; + } + + return new Image(image); } void Image::unload() { - // Free the image surface. - if (!useOpenGL && (image != NULL)) { - SDL_FreeSurface(image); - image = NULL; - } loaded = false; + +#ifdef USE_OPENGL + if (useOpenGL) { + return; + } +#endif + + if (!image) { + return; + } + + // Free the image surface. + SDL_FreeSurface(image); + image = NULL; } int Image::getWidth() const @@ -280,26 +289,27 @@ int Image::getHeight() const Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image - if (!useOpenGL) { - return new SubImage(this, image, x, y, width, height); - } #ifdef USE_OPENGL - else { + if (useOpenGL) { return new SubImage(this, glimage, x, y, width, height, texWidth, texHeight); } -#else - return NULL; #endif + + return new SubImage(this, image, x, y, width, height); } void Image::setAlpha(float a) { alpha = a; - if (!useOpenGL) { - // Set the alpha value this image is drawn at - SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha)); +#ifdef USE_OPENGL + if (useOpenGL) { + return; } +#endif + + // Set the alpha value this image is drawn at + SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha)); } float Image::getAlpha() @@ -307,6 +317,13 @@ float Image::getAlpha() return alpha; } +#ifdef USE_OPENGL +void Image::setLoadAsOpenGL(bool useOpenGL) +{ + Image::useOpenGL = useOpenGL; +} +#endif + //============================================================================ // SubImage Class //============================================================================ @@ -341,9 +358,14 @@ SubImage::SubImage(Image *parent, GLuint image, SubImage::~SubImage() { +#ifdef USE_OPENGL if (!useOpenGL) { image = NULL; } +#else + image = NULL; +#endif + parent->decRef(); } diff --git a/src/resources/image.h b/src/resources/image.h index 85f790ba..b99ad189 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -96,6 +96,14 @@ class Image : public Resource float getAlpha(); +#ifdef USE_OPENGL + /** + * Sets the target image format. Use false for SDL and + * true for OpenGL. + */ + static void setLoadAsOpenGL(bool useOpenGL); +#endif + protected: /** @@ -112,6 +120,8 @@ class Image : public Resource #ifdef USE_OPENGL GLuint glimage; int texWidth, texHeight; + + static bool useOpenGL; #endif SDL_Surface *image; float alpha; -- cgit v1.2.3-70-g09d2