BambooIsland: C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/ShaderManager.cpp Source File

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

# C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/ShaderManager.cpp

    00001 #include <string>
    00002
    00003 #include "ShaderManager.h"
    00004 #include "Logger.h"
    00005
    00006 using namespace std;
    00007
    00008 ShaderManager shadermanager_singleton_instance;
    00009
    00010 ShaderManager *ShaderManager::instance()
    00011 {
    00012     return &shadermanager_singleton_instance;
    00013 }
    00014
    00015 ShaderManager::ShaderManager() : shader_lock(false)
    00016 {
    00017
    00018 }
    00019
    00020 void ShaderManager::addShader(std::string name, std::string filename_vertex_shader, std::string filename_fragment_shader)
    00021 {
    00022     Shader *new_shader = new Shader(filename_vertex_shader.data(), filename_fragment_shader.data());
    00023
    00024     this->shaders.push_back(new_shader);
    00025     this->shader_names.push_back(name);
    00026 }
    00027
    00028 void ShaderManager::addShader(std::string name, std::string filename_vertex_shader, std::string filename_fragment_shader, std::string filename_geometry_shader)
    00029 {
    00030         Shader *new_shader = new Shader(filename_vertex_shader.data(), filename_fragment_shader.data(), filename_geometry_shader.data());
    00031
    00032         this->shaders.push_back(new_shader);
    00033         this->shader_names.push_back(name);
    00034 }
    00035
    00036 bool ShaderManager::activateShader(std::string name)
    00037 {
    00038     if (shader_lock == false)
    00039     {
    00040         int a;
    00041         bool success = false;
    00042
    00043         for (a=0; a < this->shaders.size(); a++)
    00044         {
    00045             if (this->shader_names[a].compare(name)==0)
    00046             {
    00047                 this->shaders[a]->activate();
    00048                 this->current_active = a;
    00049                 success = true;
    00050                 break;
    00051             }
    00052         }
    00053
    00054         if (success == false)
    00055             Logger::instance()->log(Logger::ERROR, "Could not activate shader with internal name \"" + name + string("\", because it is not registered in ShaderManager"));
    00056
    00057         return true;
    00058     }
    00059     else
    00060         return false;
    00061 }
    00062
    00063 GLint ShaderManager::getAttribute(std::string attribute_name)
    00064 {
    00065     return this->shaders[this->current_active]->getAttribLocation(attribute_name.data());
    00066 }
    00067
    00068 GLint ShaderManager::getUniform(std::string uniform_name)
    00069 {
    00070     return this->shaders[this->current_active]->getUniformLocation(uniform_name.data());
    00071 }
    00072
    00073 void ShaderManager::pushActiveShader()
    00074 {
    00075     if (shader_lock == false)
    00076         this->active_shader_stack.push(this->current_active);
    00077 }
    00078
    00079 void ShaderManager::popActiveShader()
    00080 {
    00081     if (shader_lock == false)
    00082     {
    00083         this->current_active = this->active_shader_stack.top();
    00084         this->active_shader_stack.pop();
    00085         this->shaders[this->current_active]->activate();
    00086     }
    00087 }
    00088
    00089 void ShaderManager::lockActiveShader()
    00090 {
    00091     this->shader_lock = true;
    00092 }
    00093
    00094 void ShaderManager::unlockActiveShader()
    00095 {
    00096     this->shader_lock = false;
    00097 }
    00098
    00099 bool ShaderManager::isActiveShaderLocked()
    00100 {
    00101     return this->shader_lock;
    00102 }

All Classes Functions Variables Enumerations Enumerator