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__
28 #include "texture.hpp"
33 class Texture : public ::Texture
38 //unsigned int height;
42 static const int HASHED_BITS = 3;
43 static const int CACHE_SIZE = 1 << (HASHED_BITS * 3);
45 static void ref(SDL_Surface *surface)
53 static int hash(const Color &color)
56 ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
57 ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
58 ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
61 SDL_Surface *data[CACHE_SIZE];
65 memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
70 std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
73 void operator = (const ColorCache &other)
75 std::for_each(other.data, other.data + CACHE_SIZE, ref);
76 std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
77 memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
80 SDL_Surface *&operator [] (const Color &color)
82 return data[hash(color)];
85 //typedef std::map<Color, SDL_Surface *> ColorCache;
86 ColorCache cache[NUM_EFFECTS];
89 Texture(SDL_Surface* sdlsurface);
92 SDL_Surface *get_transform(const Color &color, DrawingEffect effect);
94 SDL_Surface *get_texture() const
99 unsigned int get_texture_width() const
104 unsigned int get_texture_height() const
109 unsigned int get_image_width() const
114 unsigned int get_image_height() const
119 /*unsigned int get_texture_width() const
124 unsigned int get_texture_height() const
129 unsigned int get_image_width() const
134 unsigned int get_image_height() const