00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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
00082 return (*entry).second;
00083 }
00084
00085 if (mImageServer.get() == 0)
00086 {
00087 return shared_ptr<Texture>();
00088 }
00089
00090
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
00104 mTextureCache[name] = texture;
00105
00106 return texture;
00107 }