| 144 | } |
| 145 | |
| 146 | GLuint GLSLProgramFactory::Compile(GLenum shaderType, std::string const& source) |
| 147 | { |
| 148 | GLuint handle = glCreateShader(shaderType); |
| 149 | if (handle > 0) |
| 150 | { |
| 151 | // Prepend to the definitions |
| 152 | // 1. The version of the GLSL program; for example, "#version 400". |
| 153 | // 2. A define for the matrix-vector multiplication convention if |
| 154 | // it is selected as GTE_USE_MAT_VEC: "define GTE_USE_MAT_VEC 1" |
| 155 | // else "define GTE_USE_MAT_VEC 0". |
| 156 | // 3. "layout(std140, *_major) uniform;" for either row_major or |
| 157 | // column_major to select default for all uniform matrices and |
| 158 | // select std140 layout. |
| 159 | // 4. "layout(std430, *_major) buffer;" for either row_major or |
| 160 | // column_major to select default for all buffer matrices and |
| 161 | // select std430 layout. |
| 162 | // Append to the definitions the source-code string. |
| 163 | auto const& definitions = defines.Get(); |
| 164 | std::vector<std::string> glslDefines; |
| 165 | glslDefines.reserve(definitions.size() + 5); |
| 166 | glslDefines.push_back(version + "\n"); |
| 167 | #if defined(GTE_USE_VEC_MAT) |
| 168 | glslDefines.push_back("#define GTE_USE_MAT_VEC 0\n"); |
| 169 | #else |
| 170 | glslDefines.push_back("#define GTE_USE_MAT_VEC 1\n"); |
| 171 | #endif |
| 172 | #if defined(GTE_USE_COL_MAJOR) |
| 173 | glslDefines.push_back("layout(std140, column_major) uniform;\n"); |
| 174 | glslDefines.push_back("layout(std430, column_major) buffer;\n"); |
| 175 | #else |
| 176 | glslDefines.push_back("layout(std140, row_major) uniform;\n"); |
| 177 | glslDefines.push_back("layout(std430, row_major) buffer;\n"); |
| 178 | #endif |
| 179 | for (auto const& d : definitions) |
| 180 | { |
| 181 | glslDefines.push_back("#define " + d.first + " " + d.second + "\n"); |
| 182 | } |
| 183 | glslDefines.push_back(source); |
| 184 | |
| 185 | // Repackage the definitions for glShaderSource. |
| 186 | std::vector<GLchar const*> code; |
| 187 | code.reserve(glslDefines.size()); |
| 188 | for (auto const& d : glslDefines) |
| 189 | { |
| 190 | code.push_back(d.c_str()); |
| 191 | } |
| 192 | |
| 193 | glShaderSource(handle, static_cast<GLsizei>(code.size()), &code[0], nullptr); |
| 194 | |
| 195 | glCompileShader(handle); |
| 196 | GLint status; |
| 197 | glGetShaderiv(handle, GL_COMPILE_STATUS, &status); |
| 198 | if (status == GL_TRUE) |
| 199 | { |
| 200 | return handle; |
| 201 | } |
| 202 | |
| 203 | GLint logLength; |
nothing calls this directly
no test coverage detected