Index: src/sprite3d/data.hpp =================================================================== --- src/sprite3d/data.hpp (revision 792) +++ src/sprite3d/data.hpp (working copy) @@ -65,7 +65,7 @@ { Mesh(); - Ref texture; + Texture texture; uint16_t triangle_count; uint16_t* vertex_indices; float* tex_coords; Index: src/sprite3d/sprite.cpp =================================================================== --- src/sprite3d/sprite.cpp (revision 792) +++ src/sprite3d/sprite.cpp (working copy) @@ -362,7 +362,7 @@ const MeshVertices& vertices2 = aframe2.meshs[m]; // set texture - glBindTexture(GL_TEXTURE_2D, mesh.texture->handle); + glBindTexture(GL_TEXTURE_2D, mesh.texture.get_handle()); // blend between frame1 + frame2 float* verts = new float[mesh.vertex_count * 3]; Index: src/Jamfile =================================================================== --- src/Jamfile (revision 792) +++ src/Jamfile (working copy) @@ -80,6 +80,7 @@ sector.hpp spawnpoint.cpp spawnpoint.hpp + sharedptr.hpp test_object.cpp test_object.hpp text_area.hpp Index: src/glutil/texture_manager.hpp =================================================================== --- src/glutil/texture_manager.hpp (revision 792) +++ src/glutil/texture_manager.hpp (working copy) @@ -25,7 +25,7 @@ * SurfaceManager for images with other dimensions. * Note: Texture is a refcounted class, store it with Ref */ - Texture* get(const std::string& filename); + Texture get(const std::string& filename); /** * Upload an SDL_Surface onto an OpenGL texture. The surface must have power @@ -36,7 +36,7 @@ private: friend class TextureManagerTexture; - typedef std::map Textures; + typedef std::map Textures; Textures textures; }; Index: src/glutil/texture.cpp =================================================================== --- src/glutil/texture.cpp (revision 792) +++ src/glutil/texture.cpp (working copy) @@ -1,12 +1,60 @@ +/* $Id: windstille_main.hpp 752 2005-07-25 10:00:44Z grumbel $ +** __ __ __ ___ __ __ __ __ +** / \ / \__| ____ __| _/_______/ |_|__| | | | ____ +** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \ +** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/ +** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ > +** \/ \/ \/ \/ \/ +** Copyright (C) 2000,2005 Ingo Ruhnke , +** Matthias Braun +** +** 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. +*/ + #include "texture.hpp" +class TextureImpl +{ +public: + GLuint handle; + + TextureImpl(GLuint handle_) + : handle(handle_) + { + } + + TextureImpl::~TextureImpl() + { + glDeleteTextures(1, &handle); + } +}; + Texture::Texture(GLuint handle_) - : handle(handle_) + : impl(new TextureImpl(handle_)) { } Texture::~Texture() { - glDeleteTextures(1, &handle); } +GLuint +Texture::get_handle() const +{ + return impl->handle; +} + +/* EOF */ Index: src/glutil/texture.hpp =================================================================== --- src/glutil/texture.hpp (revision 792) +++ src/glutil/texture.hpp (working copy) @@ -1,3 +1,29 @@ +/* $Id: windstille_main.hpp 752 2005-07-25 10:00:44Z grumbel $ +** __ __ __ ___ __ __ __ __ +** / \ / \__| ____ __| _/_______/ |_|__| | | | ____ +** \ \/\/ / |/ \ / __ |/ ___/\ __\ | | | | _/ __ \ +** \ /| | | \/ /_/ |\___ \ | | | | |_| |_\ ___/ +** \__/\ / |__|___| /\____ /____ > |__| |__|____/____/\___ > +** \/ \/ \/ \/ \/ +** Copyright (C) 2000,2005 Ingo Ruhnke , +** Matthias Braun +** +** 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 __TEXTURE_HPP__ #define __TEXTURE_HPP__ @@ -2,15 +28,20 @@ #include -#include "refcounter.hpp" +#include "../sharedptr.hpp" -class Texture : public RefCounter +class TextureImpl; + +class Texture { public: - GLuint handle; - Texture(GLuint handle); Texture() {} ~Texture(); + + GLuint get_handle() const; +private: + SharedPtr impl; }; #endif +/* EOF */ Index: src/glutil/surface_manager.hpp =================================================================== --- src/glutil/surface_manager.hpp (revision 792) +++ src/glutil/surface_manager.hpp (working copy) @@ -7,6 +7,7 @@ #include #include #include "ref.hpp" +#include "texture.hpp" class Surface; Index: src/glutil/surface.cpp =================================================================== --- src/glutil/surface.cpp (revision 792) +++ src/glutil/surface.cpp (working copy) @@ -47,3 +47,5 @@ } } } + +/* EOF */ Index: src/glutil/texture_manager.cpp =================================================================== --- src/glutil/texture_manager.cpp (revision 792) +++ src/glutil/texture_manager.cpp (working copy) @@ -32,30 +32,7 @@ } } -class TextureManagerTexture : public Texture -{ -public: - TextureManagerTexture(GLuint handle) - : Texture(handle) - { } - ~TextureManagerTexture() - { - if(!texture_manager) - return; - - for(TextureManager::Textures::iterator i = texture_manager->textures.begin(); - i != texture_manager->textures.end(); ++i) - { - if(i->second == this) - { - texture_manager->textures.erase(i); - return; - } - } - } -}; - -Texture* +Texture TextureManager::get(const std::string& filename) { Textures::iterator i = textures.find(filename); @@ -85,7 +62,7 @@ SDL_FreeSurface(image); - Texture* result = new TextureManagerTexture(handle); + Texture result(handle); textures.insert(std::make_pair(filename, result)); return result; }