1 // $Id: sdl_texture.hpp 4063 2006-07-21 21:05:23Z anmaster $
4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __SDL_TEXTURE_HPP__
21 #define __SDL_TEXTURE_HPP__
27 #include "texture.hpp"
32 class Texture : public ::Texture
37 //unsigned int height;
41 static const int HASHED_BITS = 3;
42 static const int CACHE_SIZE = 1 << (HASHED_BITS * 3);
44 static void ref(SDL_Surface *surface)
52 static int hash(const Color &color)
55 ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
56 ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
57 ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
60 SDL_Surface *data[CACHE_SIZE];
64 memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
69 std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
72 void operator = (const ColorCache &other)
74 std::for_each(other.data, other.data + CACHE_SIZE, ref);
75 std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
76 memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
79 SDL_Surface *&operator [] (const Color &color)
81 return data[hash(color)];
84 //typedef std::map<Color, SDL_Surface *> ColorCache;
85 ColorCache cache[NUM_EFFECTS];
88 Texture(SDL_Surface* sdlsurface);
91 SDL_Surface *get_transform(const Color &color, DrawingEffect effect);
93 SDL_Surface *get_texture() const
98 unsigned int get_texture_width() const
103 unsigned int get_texture_height() const
108 unsigned int get_image_width() const
113 unsigned int get_image_height() const
118 /*unsigned int get_texture_width() const
123 unsigned int get_texture_height() const
128 unsigned int get_image_width() const
133 unsigned int get_image_height() const