void ShaderManager::LoadShader(ShaderName shaderName, const char* vshFilename, const char *fshFilename, const char *gshFilename) { std::string vShaderSrc = ReadShaderFromFile(vshFilename); std::string fShaderSrc = ReadShaderFromFile(fshFilename); CompileShader(&m_shaderProgram[shaderName].vertShader, GL_VERTEX_SHADER, vShaderSrc.c_str()); if (strlen(gshFilename) > 0) { std::string gShaderSrc = ReadShaderFromFile(gshFilename); CompileShader(&m_shaderProgram[shaderName].geomShader, GL_GEOMETRY_SHADER, gShaderSrc.c_str()); } CompileShader(&m_shaderProgram[shaderName].fragShader, GL_FRAGMENT_SHADER, fShaderSrc.c_str()); LinkShader(&m_shaderProgram[shaderName].id, m_shaderProgram[shaderName].vertShader, m_shaderProgram[shaderName].fragShader, m_shaderProgram[shaderName].geomShader); glUniform1i(glGetUniformLocation(m_shaderProgram[shaderName].id, "sTexture"), 0); // Texture unit 0 is the primary texture. // Store the location of uniforms for later use for (int j = 0; j < NUM_UNIFORMS; ++j) { m_shaderProgram[shaderName].uniforms[j] = glGetUniformLocation(m_shaderProgram[shaderName].id, uniformNames[j]); } }
GLuint ShaderManager::Get (std::string shaderPath) { GLuint shader = _shaderMap[shaderPath]; if (!shader) { char* shaderText = ReadShaderFromFile(shaderPath); shader = CompileShader(shaderText); delete shaderText; _shaderMap[shaderPath] = shader; } return shader; }