28 uint ShaderProgram::m_currentProgram = 0;
33 m_programId = glCreateProgram();
34 m_uniformLocations.fill(-1);
45 glDeleteProgram(m_programId);
49 glAttachShader(m_programId, shader->getShaderId());
51 m_shaders.push_back(shader);
57 if(!shader->compileSourceCode(sourceCode)) {
66 if(!shader->compileSourceFile(sourceFile)) {
75 auto it = std::find(m_shaders.begin(), m_shaders.end(), shader);
76 if(it == m_shaders.end())
79 glDetachShader(m_programId, shader->getShaderId());
86 while(!m_shaders.empty())
95 glLinkProgram(m_programId);
98 glGetProgramiv(m_programId, GL_LINK_STATUS, &value);
99 m_linked = (value != GL_FALSE);
108 if(m_currentProgram != m_programId) {
109 if(!m_linked && !
link())
111 glUseProgram(m_programId);
112 m_currentProgram = m_programId;
119 if(m_currentProgram != 0) {
120 m_currentProgram = 0;
128 int infoLogLength = 0;
129 glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
130 if(infoLogLength > 1) {
131 std::vector<char> buf(infoLogLength);
132 glGetShaderInfoLog(m_programId, infoLogLength-1,
nullptr, &buf[0]);
140 return glGetAttribLocation(m_programId, name);
145 return glBindAttribLocation(m_programId, location, name);
151 assert(location >= 0 && location < MAX_UNIFORM_LOCATIONS);
152 m_uniformLocations[location] = glGetUniformLocation(m_programId, name);