I've been mucking around with glsl shaders recently and have just started with the fancy new tessellation stage.
It was working perfectly for a while then all of the sudden, BANG, it fails.
Whenever I run it with the original parameters and such, it breaks on,
glDrawElements(GL_PATCHES, numIndicies, GL_UNSIGNED_INT, 0)
with an access violation at 0x00000054.
I've combed through my code and from what I can see, everything checks out.
But here's the thing, when I change GL_PATCHES
to GL_TRIANGLES
, it works flawlessly. Of course after disabling the tessellation control and eval shaders.
I've also tried glDrawArrays
and that still fails with GL_PATCHES
so I'm fairly confident it has something to do with that.
At the moment I'm using rudimentary tessellation in the geometry shader but thats gunna get old quickly.
I'm running Windows 7 x64 with an ATI Mobility Radeon HD 5650 and what is, to the best of my knowledge, the latest drivers. It says the exception occurs somewhere in atioglxx.dll if that helps. Here's some code.
GLuint CreateIcosahedron(vec3, unsigned int&);
void DrawScene(){
static unsigned int numindices = 0;
static GLuint vao = CreateIcosahedron(vec3(0,0,0), vec3(1,2,1), numindices);
glBindVertexArray(vao);
glDrawElements(GL_PATCHES, numindices, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
GLuint CreateIcosahedron(vec3 center, unsigned int& numindices){
GLuint vaoID;
GLuint vboID;
GLuint iboID;
const int indices[] = {
// indices omitted for your viewing pleasure
};
const vec3 vertices[] = {
// vertices omitted for your viewing pleasure
};
const GLuint uPosition = 0;
numindices = sizeof(indices)/sizeof(indices[0]);
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(uPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(uPosition);
glGenBuffers(1, &iboID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
return vaoID;
}
What am I doing wrong? :c
I've seen glDrawElements do this before when the VAO is not setup correctly. Your initialisation code looks correct, but the problem might be that you do not unbind your VAO at the end of the function. This means that any subsequent calls to glBindBuffer etc. can change the VAO state. Try unbinding the VAO at the end of CreateIcosahedron() and see if that helps.
[EDIT] If your code looks exactly as you have posted above, then this probably won't help. It seems you don't unbind the VAO, but you bind it immediately after the function returns anyway. To help you narrow down the problem, you should know that the behaviour of glDrawElements changes depending on whether there is an element array buffer bound when it is called. If there is an array bound, the last parameter is interpreted as a byte offset into the element array. Otherwise it is interpreted as a pointer, which I think is what is happening in your case.
User contributions licensed under CC BY-SA 3.0