Update of /cvsroot/simspark/simspark/spark/kerosin/textureserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24230/textureserver Modified Files: Tag: WIN32 texture.cpp texture.h texture2d.cpp texture2d.h textureserver.cpp textureserver.h Log Message: - cleanup - use CachedPath objects to cache references Index: texture2d.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/texture2d.cpp,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** texture2d.cpp 5 Dec 2005 21:38:23 -0000 1.1 --- texture2d.cpp 16 Feb 2007 15:40:49 -0000 1.1.2.1 *************** *** 1,9 **** #include "texture2d.h" ! #include "../openglserver/openglserver.h" ! #include "../imageserver/image.h" using namespace kerosin; ! Texture2D::Texture2D(const boost::shared_ptr<TextureServer> &textureServer) : Texture(textureServer) { } --- 1,30 ---- + /* -*- 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$ + + 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 "texture2d.h" ! #include <kerosin/openglserver/openglserver.h> ! #include <kerosin/imageserver/image.h> using namespace kerosin; ! Texture2D::Texture2D() : Texture() { } *************** *** 15,21 **** void Texture2D::Bind() const { ! if (mTexID != 0) { ! glBindTexture(GL_TEXTURE_2D, mTexID); } } --- 36,42 ---- void Texture2D::Bind() const { ! if (mTexID != 0) { ! glBindTexture(GL_TEXTURE_2D, mTexID); } } *************** *** 23,67 **** 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); } --- 44,92 ---- 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); } Index: textureserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/textureserver.cpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** textureserver.cpp 10 Feb 2007 16:19:21 -0000 1.1.2.1 --- textureserver.cpp 16 Feb 2007 15:40:53 -0000 1.1.2.2 *************** *** 44,81 **** 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 ! #ifdef WIN32 ! mImageServer.reset(); ! #else ! mImageServer = shared_dynamic_cast<ImageServer> ! (GetCore()->Get("sys/server/image")); ! #endif ! 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; } --- 44,57 ---- void TextureServer::OnLink() { ! #ifndef WIN32 // setup ImageServer reference ! RegisterCachedPath(mImageServer, "/sys/server/image"); ! if (mImageServer.expired()) { GetLog()->Error() << "(TextureServer) ERROR: ImageServer not found\n"; } ! #endif } *************** *** 90,94 **** } ! if (mImageServer.get() == 0) { return shared_ptr<Texture>(); --- 66,70 ---- } ! if (mImageServer.expired()) { return shared_ptr<Texture>(); *************** *** 106,111 **** } ! Texture2D *tex2D = new Texture2D(shared_static_cast<TextureServer> ! (make_shared(GetSelf()))); tex2D->Create(image); shared_ptr<Texture> texture(tex2D); --- 82,86 ---- } ! Texture2D *tex2D = new Texture2D(); tex2D->Create(image); shared_ptr<Texture> texture(tex2D); Index: textureserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/textureserver.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** textureserver.h 5 Dec 2005 21:38:23 -0000 1.1 --- textureserver.h 16 Feb 2007 15:40:53 -0000 1.1.2.1 *************** *** 44,47 **** --- 44,49 ---- #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> + #include <kerosin/openglserver/openglserver.h> + #include <kerosin/imageserver/imageserver.h> #if HAVE_HASH_MAP *************** *** 57,62 **** #endif - class OpenGLServer; - class ImageServer; class Texture; --- 59,62 ---- *************** *** 91,106 **** 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 */ --- 91,100 ---- virtual void OnLink(); // // members // private: /** reference to the ImageServer */ ! CachedPath<ImageServer> mImageServer; /** registry of cached textures */ Index: texture.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/texture.cpp,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** texture.cpp 5 Dec 2005 21:38:23 -0000 1.1 --- texture.cpp 16 Feb 2007 15:40:49 -0000 1.1.2.1 *************** *** 1,2 **** --- 1,23 ---- + /* -*- 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$ + + 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 "texture.h" #include "../openglserver/openglserver.h" *************** *** 5,10 **** using namespace kerosin; ! Texture::Texture(const boost::shared_ptr<TextureServer> &textureServer) : ! mTexID(0), mWidth(0), mHeight(0), mTextureServer(textureServer) { } --- 26,31 ---- using namespace kerosin; ! Texture::Texture() ! : mTexID(0), mWidth(0), mHeight(0) { } *************** *** 12,45 **** 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); } --- 33,63 ---- Texture::~Texture() { ! Reset(); } void Texture::Reset() { ! if (! mTexID) ! { ! return; ! } ! ! 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; } Index: texture2d.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/texture2d.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** texture2d.h 5 Dec 2005 21:38:23 -0000 1.1 --- texture2d.h 16 Feb 2007 15:40:52 -0000 1.1.2.1 *************** *** 36,48 **** // 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; --- 36,58 ---- // public: ! Texture2D(); ~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; Index: texture.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/textureserver/texture.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** texture.h 5 Dec 2005 21:38:23 -0000 1.1 --- texture.h 16 Feb 2007 15:40:49 -0000 1.1.2.1 *************** *** 57,61 **** // public: ! Texture(const boost::shared_ptr<TextureServer> &textureServer); virtual ~Texture(); --- 57,61 ---- // public: ! Texture(); virtual ~Texture(); *************** *** 66,75 **** 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; --- 66,85 ---- 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; *************** *** 80,93 **** 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 }; --- 90,105 ---- unsigned int GetHeight() const; // // members // protected: ! //! OpenGL texture handle ! unsigned int mTexID; ! ! //! width of texture ! unsigned int mWidth; ! ! //! height of texture ! unsigned int mHeight; }; |