Created
March 13, 2016 20:47
-
-
Save Robadob/f4773dc51a24e072c5f1 to your computer and use it in GitHub Desktop.
OpenGL bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Create a shader program with the below frag and vertex shaders | |
//2. Call the below method passing "_projectionMat" as the uniformName (and the shaderPrograms ID) | |
//3. glGetUniformLocation() correctly identifies the location as 2 | |
//4. glGetActiveUniform() incorrectly identifies the type as GL_SAMPLER_CUBE, instead of GL_FLOAT_MAT4 | |
//5. Removing the explicit uniform locations from the vertex shader fixes this, therefore is layout(location for a uniform undefined behaviour, or is this a bug? | |
std::pair<int, GLenum> findUniform(const char *uniformName, int shaderProgram) | |
{ | |
int result = GL_CALL(glGetUniformLocation(shaderProgram, uniformName)); | |
if (result > -1) | |
{ | |
GLenum type; | |
GLint size;//Collect size, because its not documented that you can pass 0 | |
GL_CALL(glGetActiveUniform(shaderProgram, result, 0, 0, &size, &type, 0)); | |
return std::pair<int, GLenum>(result, type); | |
} | |
return std::pair<int, GLenum>(-1, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 430 | |
layout(location = 2) in vec3 tex_coords; | |
layout(location = 3) uniform samplerCube cube_texture; | |
out vec4 frag_colour; | |
void main () { | |
frag_colour = texture(cube_texture, tex_coords); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 430 | |
layout(location = 0) in vec3 _vertex; | |
//layout(location = 1) in vec3 in_normal; | |
layout(location = 2) out vec3 tex_coords; | |
layout(location = 1) uniform mat4 _modelViewMat; | |
layout(location = 2) uniform mat4 _projectionMat; | |
void main () { | |
tex_coords = _vertex; | |
gl_Position = _projectionMat * _modelViewMat * vec4(_vertex, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment