X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftexture.h;h=53cb3a18943417ee955b045f2d21baa10af40276;hb=f4e27ac4cd869c6c2687be795f9c64f6a0593487;hp=1efd6e5980fb9daad0840a6be927e9714f422c4f;hpb=1cf03f7192b1840362da1a9eebcf3d68d7a4e8f6;p=supertux.git diff --git a/src/texture.h b/src/texture.h index 1efd6e598..53cb3a189 100644 --- a/src/texture.h +++ b/src/texture.h @@ -1,14 +1,22 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser // -// C Interface: texture -// -// Description: -// -// -// Author: Tobias Glaesser , (C) 2004 -// -// Copyright: See COPYING file that comes with this distribution -// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. #ifndef SUPERTUX_TEXTURE_H #define SUPERTUX_TEXTURE_H @@ -19,40 +27,131 @@ #include #endif +#include #include "screen.h" -/* Texture type */ -struct texture_type +class SurfaceImpl; +class SurfaceSDL; +class SurfaceOpenGL; + +/** This class holds all the data necessary to construct a surface */ +class SurfaceData +{ +public: + enum ConstructorType { LOAD, LOAD_PART, SURFACE }; + ConstructorType type; + SDL_Surface* surface; + std::string file; + int use_alpha; + int x; + int y; + int w; + int h; + + SurfaceData(SDL_Surface* surf, int use_alpha_); + SurfaceData(const std::string& file_, int use_alpha_); + SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_); + ~SurfaceData(); + + SurfaceSDL* create_SurfaceSDL(); + SurfaceOpenGL* create_SurfaceOpenGL(); + SurfaceImpl* create(); +}; + +/** Container class that holds a surface, necessary so that we can + switch Surface implementations (OpenGL, SDL) on the fly */ +class Surface +{ +public: + SurfaceData data; + SurfaceImpl* impl; + int w; + int h; + + typedef std::list Surfaces; + static Surfaces surfaces; +public: + static void reload_all(); + static void debug_check(); + + Surface(SDL_Surface* surf, int use_alpha); + Surface(const std::string& file, int use_alpha); + Surface(const std::string& file, int x, int y, int w, int h, int use_alpha); + ~Surface(); + + /** Reload the surface, which is necesarry in case of a mode swich */ + void reload(); + + void draw(float x, float y, Uint8 alpha = 255, bool update = false); + void draw_bg(Uint8 alpha = 255, bool update = false); + void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false); + void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false); + void resize(int w_, int h_); +}; + +/** Surface implementation, all implementation have to inherit from + this class */ +class SurfaceImpl { +protected: SDL_Surface* sdl_surface; - unsigned gl_texture; + +public: int w; int h; + +public: + SurfaceImpl(); + virtual ~SurfaceImpl(); + + /** Return 0 on success, -2 if surface needs to be reloaded */ + virtual int draw(float x, float y, Uint8 alpha, bool update) = 0; + virtual int draw_bg(Uint8 alpha, bool update) = 0; + virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0; + virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0; + int resize(int w_, int h_); + + SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function +}; + +class SurfaceSDL : public SurfaceImpl +{ +public: + SurfaceSDL(SDL_Surface* surf, int use_alpha); + SurfaceSDL(const std::string& file, int use_alpha); + SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha); + virtual ~SurfaceSDL(); + + int draw(float x, float y, Uint8 alpha, bool update); + int draw_bg(Uint8 alpha, bool update); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update); }; -void texture_setup(void); -extern void (*texture_load) (texture_type* ptexture, const std::string& file, int use_alpha); -extern void (*texture_load_part) (texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); -extern void (*texture_free) (texture_type* ptexture); -extern void (*texture_draw) (texture_type* ptexture, float x, float y, Uint8 alpha = 255, bool update = false); -extern void (*texture_draw_bg) (texture_type* ptexture, Uint8 alpha = 255, bool update = false); -extern void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false); -void texture_load_sdl(texture_type* ptexture, const std::string&, int use_alpha); -void texture_load_part_sdl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); -void texture_free_sdl(texture_type* ptexture); -void texture_draw_sdl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update); -void texture_draw_bg_sdl(texture_type* ptexture, Uint8 alpha, bool update); -void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); -void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha); #ifndef NOOPENGL -void texture_load_gl(texture_type* ptexture, const std::string& file, int use_alpha); -void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); -void texture_free_gl(texture_type* ptexture); -void texture_draw_gl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update); -void texture_draw_bg_gl(texture_type* ptexture, Uint8 alpha, bool update); -void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); -void texture_create_gl(SDL_Surface * surf, GLuint * tex); -#endif +class SurfaceOpenGL : public SurfaceImpl +{ +public: + unsigned gl_texture; + +public: + SurfaceOpenGL(SDL_Surface* surf, int use_alpha); + SurfaceOpenGL(const std::string& file, int use_alpha); + SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha); + virtual ~SurfaceOpenGL(); + + int draw(float x, float y, Uint8 alpha, bool update); + int draw_bg(Uint8 alpha, bool update); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update); + +private: + void create_gl(SDL_Surface * surf, GLuint * tex); +}; +#endif #endif /*SUPERTUX_TEXTURE_H*/ +/* Local Variables: */ +/* mode: c++ */ +/* End: */