Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

textureserver.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003 this file is part of rcssserver3D
00004 Fri May 9 2003
00005 Copyright (C) 2002,2003 Koblenz University
00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007 $Id: textureserver.cpp,v 1.3 2004/04/18 16:28:20 rollmark Exp $
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; version 2 of the License.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 
00023 #include "textureserver.h"
00024 #include <zeitgeist/logserver/logserver.h>
00025 #include "../openglserver/openglserver.h"
00026 #include "../imageserver/imageserver.h"
00027 #include "texture2d.h"
00028 
00029 using namespace boost;
00030 using namespace kerosin;
00031 using namespace zeitgeist;
00032 
00033 TextureServer::TextureServer() : Leaf()
00034 {
00035 }
00036 
00037 TextureServer::~TextureServer()
00038 {
00039 }
00040 
00041 void TextureServer::OnLink()
00042 {
00043     // setup OpenGLServer reference
00044     mOpenGLServer = shared_dynamic_cast<OpenGLServer>
00045         (GetCore()->Get("sys/server/opengl"));
00046 
00047     if (mOpenGLServer.get() == 0)
00048         {
00049             GetLog()->Error()
00050                 << "(TextureServer) ERROR: OpenGLServer not found\n";
00051         }
00052 
00053     // setup ImageServer reference
00054     mImageServer = shared_dynamic_cast<ImageServer>
00055         (GetCore()->Get("sys/server/image"));
00056 
00057     if (mImageServer.get() == 0)
00058         {
00059             GetLog()->Error()
00060                 << "(TextureServer) ERROR: ImageServer not found\n";
00061         }
00062 }
00063 
00064 void TextureServer::OnUnlink()
00065 {
00066     mOpenGLServer.reset();
00067     mImageServer.reset();
00068 }
00069 
00070 boost::shared_ptr<OpenGLServer> TextureServer::GetOpenGLServer() const
00071 {
00072     return mOpenGLServer;
00073 }
00074 
00075 boost::shared_ptr<Texture> TextureServer::GetTexture(const std::string &name)
00076 {
00077     TTextureCache::iterator entry = mTextureCache.find(name);
00078 
00079     if (entry != mTextureCache.end())
00080         {
00081             // we already have a match
00082             return (*entry).second;
00083         }
00084 
00085     if (mImageServer.get() == 0)
00086         {
00087             return shared_ptr<Texture>();
00088         }
00089 
00090     // no match for that name, so we have to load it
00091     shared_ptr<Image> image = mImageServer->Load(name.c_str());
00092 
00093     if (! image.get())
00094         {
00095             return shared_ptr<Texture>();
00096         }
00097 
00098     Texture2D *tex2D = new Texture2D(shared_static_cast<TextureServer>
00099                                      (make_shared(GetSelf())));
00100     tex2D->Create(image);
00101     shared_ptr<Texture> texture(tex2D);
00102 
00103     // register the texture, so we will find it later
00104     mTextureCache[name] = texture;
00105 
00106     return texture;
00107 }

Generated on Thu Apr 6 15:25:40 2006 for rcssserver3d by  doxygen 1.4.4