Skip to content

Commit

Permalink
SDL_gpu implementation for get_texture et al.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jul 3, 2014
1 parent 5100fb9 commit 90eab46
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/image.cpp
Expand Up @@ -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_;
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/image.hpp
Expand Up @@ -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&);
Expand All @@ -137,6 +141,10 @@ namespace image {
typedef cache_type<surface> image_cache;
#if SDL_VERSION_ATLEAST(2,0,0)
typedef cache_type<sdl::ttexture> texture_cache;
#else
#ifdef SDL_GPU
typedef cache_type<sdl::ttexture> texture_cache;
#endif
#endif
typedef cache_type<bool> bool_cache;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 90eab46

Please sign in to comment.