From 90eab469e1d517626282e556880a2869ff94a8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boldizs=C3=A1r=20Lipka?= Date: Thu, 3 Jul 2014 14:29:18 +0200 Subject: [PATCH] SDL_gpu implementation for get_texture et al. --- src/image.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/image.hpp | 12 ++++++++ 2 files changed, 92 insertions(+) diff --git a/src/image.cpp b/src/image.cpp index c25fe36ef8a1..ba69f37704e8 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -127,10 +127,16 @@ image::image_cache images_, #if SDL_VERSION_ATLEAST(2,0,0) /** Rexture caches */ +image::texture_cache txt_images_, + txt_hexed_images_, + txt_brightened_images_; +#else +#ifdef SDL_GPU image::texture_cache txt_images_, txt_hexed_images_, txt_brightened_images_; #endif +#endif // cache storing if each image fit in a hex image::bool_cache in_hex_info_; @@ -633,6 +639,18 @@ sdl::ttexture load_texture(const locator &loc, const int access) return sdl::ttexture(); } } +#else +#ifdef SDL_GPU +sdl::ttexture load_texture(const locator &loc) +{ + surface img = load_from_disk(loc); + if (!img.null()) { + return sdl::ttexture(img); + } else { + return sdl::ttexture(); + } +} +#endif #endif manager::manager() {} @@ -962,6 +980,68 @@ sdl::ttexture get_texture(const locator& loc, TYPE type) return result; } +#else +#ifdef SDL_GPU +sdl::ttexture get_texture(const locator& loc, TYPE type) +{ + if (loc.is_void()) { + return sdl::ttexture(); + } + + texture_cache *cache; + + switch (type) { + case UNSCALED: + case SCALED_TO_ZOOM: + cache = &txt_images_; + break; + case BRIGHTENED: + cache = &txt_brightened_images_; + break; + case HEXED: + case SCALED_TO_HEX: + case TOD_COLORED: + cache = &txt_hexed_images_; + break; + default: + return sdl::ttexture(); + } + + if (!loc.in_cache(*cache)) { + if (type == UNSCALED || type == SCALED_TO_ZOOM) { + sdl::ttexture txt = load_texture(loc); + loc.add_to_cache(*cache, txt); + } else if (type == BRIGHTENED) { + surface surf = get_brightened(loc); + sdl::ttexture txt(surf); + loc.add_to_cache(*cache, txt); + } else { + surface surf = get_hexed(loc); + sdl::ttexture txt(surf); + loc.add_to_cache(*cache, txt); + } + } + + sdl::ttexture result = loc.locate_in_cache(*cache); + + switch (type) { + case UNSCALED: + case HEXED: + case BRIGHTENED: + break; + case TOD_COLORED: + result.set_color_mod(red_adjust, green_adjust, blue_adjust); + case SCALED_TO_ZOOM: + case SCALED_TO_HEX: + result.set_scale(zoom, zoom); + break; + default: + return sdl::ttexture(); + } + + return result; +} +#endif #endif surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type) diff --git a/src/image.hpp b/src/image.hpp index b36925aa3b7a..1dd2d0a1b44b 100644 --- a/src/image.hpp +++ b/src/image.hpp @@ -129,6 +129,10 @@ namespace image { #if SDL_VERSION_ATLEAST(2,0,0) sdl::ttexture load_texture(const locator &loc, const int access = SDL_TEXTUREACCESS_STATIC); +#else +#ifdef SDL_GPU + sdl::ttexture load_texture(const locator &loc); +#endif #endif size_t hash_value(const locator::value&); @@ -137,6 +141,10 @@ namespace image { typedef cache_type image_cache; #if SDL_VERSION_ATLEAST(2,0,0) typedef cache_type texture_cache; +#else +#ifdef SDL_GPU + typedef cache_type texture_cache; +#endif #endif typedef cache_type bool_cache; @@ -212,6 +220,10 @@ namespace image { surface get_image(const locator& i_locator, TYPE type=UNSCALED); #if SDL_VERSION_ATLEAST(2,0,0) sdl::ttexture get_texture(const locator& loc, TYPE type=UNSCALED); +#else +#ifdef SDL_GPU + sdl::ttexture get_texture(const locator &loc, TYPE type=UNSCALED); +#endif #endif ///function to get the surface corresponding to an image.