Update of /cvsroot/simspark/simspark/spark/kerosin/textureserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19774/textureserver Added Files: .cvsignore texture.cpp texture.h texture2d.cpp texture2d.h textureserver.cpp textureserver.h textureserver_c.cpp Log Message: --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs --- NEW FILE: texture2d.cpp --- #include "texture2d.h" #include "../openglserver/openglserver.h" #include "../imageserver/image.h" using namespace kerosin; Texture2D::Texture2D(const boost::shared_ptr<TextureServer> &textureServer) : Texture(textureServer) { } Texture2D::~Texture2D() { } void Texture2D::Bind() const { if (mTexID != 0) { glBindTexture(GL_TEXTURE_2D, mTexID); } } void Texture2D::Enable() const { glEnable(GL_TEXTURE_2D); } void Texture2D::Disable() const { glDisable(GL_TEXTURE_2D); } void Texture2D::Create(boost::shared_ptr<Image> &image) { mWidth = image->Width(); mHeight = image->Height(); Acquire(); Bind(); glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); if(image->HasAlpha()) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mWidth, mHeight, 0, image->Format(), image->Type(), image->Data()); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, image->Format(), image->Type(), image->Data()); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } void Texture2D::Clamp() const { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); } void Texture2D::ClampToEdge() const { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } void Texture2D::Repeat() const { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } --- NEW FILE: textureserver.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: textureserver.cpp,v 1.1 2005/12/05 21:38:23 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "textureserver.h" #include <zeitgeist/logserver/logserver.h> #include "../openglserver/openglserver.h" #include "../imageserver/imageserver.h" #include "texture2d.h" using namespace boost; using namespace kerosin; using namespace zeitgeist; TextureServer::TextureServer() : Leaf() { } TextureServer::~TextureServer() { } void TextureServer::OnLink() { // setup OpenGLServer reference mOpenGLServer = shared_dynamic_cast<OpenGLServer> (GetCore()->Get("sys/server/opengl")); if (mOpenGLServer.get() == 0) { GetLog()->Error() << "(TextureServer) ERROR: OpenGLServer not found\n"; } // setup ImageServer reference mImageServer = shared_dynamic_cast<ImageServer> (GetCore()->Get("sys/server/image")); if (mImageServer.get() == 0) { GetLog()->Error() << "(TextureServer) ERROR: ImageServer not found\n"; } } void TextureServer::OnUnlink() { mOpenGLServer.reset(); mImageServer.reset(); } boost::shared_ptr<OpenGLServer> TextureServer::GetOpenGLServer() const { return mOpenGLServer; } boost::shared_ptr<Texture> TextureServer::GetTexture(const std::string &name) { TTextureCache::iterator entry = mTextureCache.find(name); if (entry != mTextureCache.end()) { // we already have a match return (*entry).second; } if (mImageServer.get() == 0) { return shared_ptr<Texture>(); } // no match for that name, so we have to load it shared_ptr<Image> image = mImageServer->Load(name.c_str()); if (! image.get()) { return shared_ptr<Texture>(); } Texture2D *tex2D = new Texture2D(shared_static_cast<TextureServer> (make_shared(GetSelf()))); tex2D->Create(image); shared_ptr<Texture> texture(tex2D); // register the texture, so we will find it later mTextureCache[name] = texture; return texture; } --- NEW FILE: textureserver.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: textureserver.h,v 1.1 2005/12/05 21:38:23 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_TEXTURESERVER_H #define KEROSIN_TEXTURESERVER_H #ifdef HAVE_CONFIG_H #ifdef PACKAGE_BUGREPORT #undef PACKAGE_BUGREPORT #endif #ifdef PACKAGE_NAME #undef PACKAGE_NAME #endif #ifdef PACKAGE_STRING #undef PACKAGE_STRING #endif #ifdef PACKAGE_TARNAME #undef PACKAGE_TARNAME #endif #ifdef PACKAGE_VERSION #undef PACKAGE_VERSION #endif #include <config.h> #endif #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> #if HAVE_HASH_MAP #include <hash_map> #else #include <map> #endif namespace kerosin { #if 0 } #endif class OpenGLServer; class ImageServer; class Texture; class TextureServer : public zeitgeist::Leaf { // // types // private: #if HAVE_HASH_MAP typedef std::hash_map<std::string, boost::shared_ptr<Texture> > TTextureCache; #else typedef std::map<std::string, boost::shared_ptr<Texture> > TTextureCache; #endif // // functions // public: TextureServer(); virtual ~TextureServer(); /** retrieve pointer to the OpenGL server ... used by Textures to check extensions */ boost::shared_ptr<OpenGLServer> GetOpenGLServer() const; /** load (or returned cached) texture */ boost::shared_ptr<Texture> GetTexture(const std::string &name); protected: /** set up the OpenGLServer and ImageServer reference */ virtual void OnLink(); /** reset OpenGLServer and ImageServer reference */ virtual void OnUnlink(); // // members // private: /** reference to the OpenGLServer */ boost::shared_ptr<OpenGLServer> mOpenGLServer; /** reference to the ImageServer */ boost::shared_ptr<ImageServer> mImageServer; /** registry of cached textures */ TTextureCache mTextureCache; }; DECLARE_CLASS(TextureServer); } //kerosin #endif //KEROSIN_TEXTURESERVER_H --- NEW FILE: texture.cpp --- #include "texture.h" #include "../openglserver/openglserver.h" using namespace boost; using namespace kerosin; Texture::Texture(const boost::shared_ptr<TextureServer> &textureServer) : mTexID(0), mWidth(0), mHeight(0), mTextureServer(textureServer) { } Texture::~Texture() { Reset(); } void Texture::Reset() { if (mTexID) { glDeleteTextures(1, &mTexID); mTexID = 0; } } void Texture::Acquire() { Reset(); glGenTextures(1, &mTexID); } unsigned int Texture::GetWidth() const { return mWidth; } unsigned int Texture::GetHeight() const { return mHeight; } boost::shared_ptr<TextureServer> Texture::GetTextureServer() const { return make_shared(mTextureServer); } --- NEW FILE: texture2d.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: texture2d.h,v 1.1 2005/12/05 21:38:23 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_TEXTURE2D_H #define KEROSIN_TEXTURE2D_H #include "texture.h" namespace kerosin { class Image; class Texture2D : public Texture { // // functions // public: Texture2D(const boost::shared_ptr<TextureServer> &textureServer); ~Texture2D(); //! bind the texture contained in this object to the corresponding target (user code is responsible for setting correct enables and tex units) virtual void Bind() const; //! enable the target associated with a texture type (e.g. GL_TEXTURE_2D) virtual void Enable() const; //! disable the target associated with a texture type (e.g. GL_TEXTURE_2D) virtual void Disable() const; virtual void Clamp() const; virtual void ClampToEdge() const; virtual void Repeat() const; void Create(boost::shared_ptr<Image> &image); }; } //kerosin #endif //KEROSIN_TEXTURE2D_H --- NEW FILE: textureserver_c.cpp --- #include "textureserver.h" using namespace boost; using namespace kerosin; using namespace zeitgeist; void CLASS(TextureServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: texture.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: texture.h,v 1.1 2005/12/05 21:38:23 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_TEXTURE_H #define KEROSIN_TEXTURE_H #include <boost/weak_ptr.hpp> #include <boost/shared_ptr.hpp> namespace kerosin { class TextureServer; /* \class Texture This is the base class of all OpenGL based textures. In OpenGL a texture is represented by a so-called texture ID. This is a simple handle. The basic operations for creating/deleting this handle are contained in this class. Usually, textures are created via the texture server. NOTE: HISTORY: 14.10.02 - MK - Initial version TODO: - support mipmap building (currently done only when SGIS_generate_mipmap is supported) TOFIX: */ class Texture { // // functions // public: Texture(const boost::shared_ptr<TextureServer> &textureServer); virtual ~Texture(); //! release the associated OpenGL texture void Reset(); //! acquire an OpenGL texture handle (texture not loaded) void Acquire(); //! bind the texture contained in this object to the corresponding target (user code is responsible for setting correct enables and tex units) virtual void Bind() const = 0; //! enable the target associated with a texture type (e.g. GL_TEXTURE_2D) virtual void Enable() const = 0; //! disable the target associated with a texture type (e.g. GL_TEXTURE_2D) virtual void Disable() const = 0; virtual void Clamp() const = 0; virtual void ClampToEdge() const = 0; virtual void Repeat() const = 0; // accessors unsigned int GetWidth() const; unsigned int GetHeight() const; boost::shared_ptr<TextureServer> GetTextureServer() const; // // members // protected: unsigned int mTexID; // OpenGL texture handle (initialized to 0) unsigned int mWidth; // width of texture unsigned int mHeight; // height of texture private: boost::weak_ptr<TextureServer> mTextureServer; // texture server, which created this object }; } #endif //KEROSIN_TEXTURE_H |