void UseEffect(Effect *effect) { glUseProgram(effect->getProgramID()); Error error = _checkForErrors(); if(error.Report().length() > 0) { throw error; } }
GLuint _compileShader(int shaderType, std::vector<std::string> scripts) { std::vector<const char*> scriptData; for(unsigned int i=0; i<scripts.size(); i++) { scriptData.push_back(scripts.at(i).data()); } GLuint shaderID = glCreateShader(shaderType); glShaderSource(shaderID, scripts.size(), &scriptData[0], NULL); glCompileShader(shaderID); Error error = _checkShaderCompiled(shaderID, shaderType); if(error.Report().length() > 0) { throw error; } return shaderID; }
Effect::Effect(std::vector<std::string> scripts, std::vector<int> types) { GLuint programID = glCreateProgram(); std::vector<std::string> vscript, fscript; for (unsigned int i=0; i<scripts.size(); i++) { if(types.at(i) == Vertex) { vscript.push_back(scripts.at(i)); } else if(types.at(i) == Fragment) { fscript.push_back(scripts.at(i)); } } GLuint vshaderID = _compileShader(Vertex, vscript); glAttachShader(programID, vshaderID); GLuint fshaderID = _compileShader(Fragment, fscript); glAttachShader(programID, fshaderID); Error error = _checkForErrors(); if(error.Report().length() > 0) { throw error; } glLinkProgram(programID); GLint status; glGetProgramiv(programID, GL_LINK_STATUS, &status); if(status == GL_FALSE) { char programInfoLog[100]; GLsizei length; glGetProgramInfoLog(programID, 100, &length, &programInfoLog[0]); throw Error(&programInfoLog[0]); } this->program = programID; }