ShaderCache.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2008 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016  
00017 #include "ShaderCache.h"
00018 
00019 using namespace Fluxus;
00020     
00021 std::map<std::string,GLSLShaderPair *> ShaderCache::m_Cache;
00022     
00023 ShaderCache::ShaderCache()
00024 {
00025 }
00026 
00027 ShaderCache::~ShaderCache()
00028 {
00029     Clear();
00030 }
00031     
00032 GLSLShader *ShaderCache::Get(const string &vert, const string &frag)
00033 {
00034     // look in the cache, and copy it if it is there
00035     string key = vert+" "+frag;
00036     map<string, GLSLShaderPair *>::iterator i = m_Cache.find(key);
00037     if (i!=m_Cache.end()) return new GLSLShader(*i->second);
00038     
00039     GLSLShaderPair *pair = new GLSLShaderPair(vert,frag);
00040     m_Cache[key] = pair;
00041     return new GLSLShader(*pair);
00042 }
00043 
00044 void ShaderCache::Clear()
00045 {
00046     for (map<string, GLSLShaderPair *>::iterator i=m_Cache.begin();
00047         i!=m_Cache.end(); ++i)
00048     {
00049         delete i->second;
00050     }
00051     m_Cache.clear();
00052 }
00053 
00054 void ShaderCache::Dump()
00055 {
00056     for (map<string, GLSLShaderPair *>::iterator i=m_Cache.begin();
00057         i!=m_Cache.end(); ++i)
00058     {
00059         Trace::Stream<<i->first<<endl;
00060     }
00061     m_Cache.clear();
00062 }

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1