내 목표는 인스턴스화 된 렌더링 작동을 얻는 것이지만, 단 하나의 glDrawElements
도 지금은 실패합니다. 참고 :이 코드는 이미 Windows에서 작동합니다. 그러나 OS X에서는 실패합니다. GL_INVALID_OPERATION
glDrawElements가 오류 GL_INVALID_OPERATION과 함께 실패합니다.
기본적으로 모든 정적 데이터를 버퍼에로드 한 다음 마지막 버퍼에는 모든 그리기 전에 다시로드하는 동적 데이터가 포함되어 있습니다. 그런 다음 glDrawElementsInstanced (또는 glDrawElements
디버깅 용) 호출 즉시 실패합니다. 이전에 오류 인쇄가 있었기 때문에 그 호출 후에 항상 OpenGL 오류를 인쇄합니다. (glDrawElements
도 마찬가지 임) 대신 glDrawArrays
을 사용하면이 오류가 표시되지 않습니다.
몇 가지 추가 정보는 코드의 주석을 참조하십시오. 어떤 도움이라도 대단히 감사합니다.
//Setup code, at this point vertices,textureCoordiantes,normals are all populated
//Allocate the space for the gpu buffers now
//and send the static data
//Rebind the array to bring them into the current context
glBindVertexArray (vertexArray);
//Push voxel to gpu
glBindBuffer (GL_ARRAY_BUFFER, vertexBuffer);
glBufferData (GL_ARRAY_BUFFER, 36*sizeof(vec3), vertices, GL_STATIC_READ);
glEnableVertexAttribArray (shader->AttributeVertex());
glVertexAttribPointer (shader->AttributeVertex(), 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer (GL_ARRAY_BUFFER, textureBuffer);
glBufferData (GL_ARRAY_BUFFER, 36*sizeof(vec2), textureCoordinates, GL_STATIC_READ);
glEnableVertexAttribArray (shader->AttributeTexture());
glVertexAttribPointer (shader->AttributeTexture(), 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer (GL_ARRAY_BUFFER, normalBuffer);
glBufferData (GL_ARRAY_BUFFER, 36*sizeof(vec3), normals, GL_STATIC_READ);
glEnableVertexAttribArray (shader->AttributeNormal());
glVertexAttribPointer (shader->AttributeNormal(), 3, GL_FLOAT, GL_FALSE, 0, 0);
//Allocate space for positions
glBindBuffer (GL_ARRAY_BUFFER, positionBuffer);
glBufferData (GL_ARRAY_BUFFER, INSTANCE_RENDER_SWEEP*sizeof(vec4), positions, GL_DYNAMIC_READ);
glEnableVertexAttribArray (shader->AttributePosition());
glVertexAttribPointer (shader->AttributePosition(), 4, GL_FLOAT, GL_FALSE, 0, 0);
//This code runs a bit later, but runs over and over:
//indices is a vector<GLuint> of length 36 and is just 0-35
glBindVertexArray (vertexArray);
glBindBuffer (GL_ARRAY_BUFFER, positionBuffer);
glBufferSubData (GL_ARRAY_BUFFER, 0,INSTANCE_RENDER_SWEEP*sizeof(vec4), positions);
glEnableVertexAttribArray (shader->AttributePosition());
glVertexAttribPointer (shader->AttributePosition(), 4, GL_FLOAT, GL_FALSE, 0, 0);
//The position is per-instance
//everything else is per-vertex
glVertexAttribDivisor(shader->AttributeNormal(),0);
glVertexAttribDivisor(shader->AttributePosition(),1);
glVertexAttribDivisor(shader->AttributeTexture(),0);
glVertexAttribDivisor(shader->AttributeVertex(),0);
cout << "1Err: " << glGetError() << "\n";
glDrawDelements(GL_TRIANGLES,36,GL_UNSIGNED_BYTE,&indices[0]);
//glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, &indices[0], bufferedVoxels);
//This next error prints out 1282 which is GL_INVALID_OPERATION
//However if i replace the above with glDrawArrays, it works for one instance (no error)
cout << "2Err: " << glGetError() << "\n";
//All buffered voxels now drawn
bufferedVoxels = 0;
현재 OS X에서 어떤 종류의 OpenGL 컨텍스트를 사용하고 있습니까? 코어 3.2 이상? 인스 턴싱은 GL 3.x 시대입니다. OS X에서 확장되지 않은 형태로 사용하려면 코어 프로파일이 필요합니다. GL 2.1 컨텍스트에서 호출하려고하는 코어에서만 노출 된 함수는 OS X에서 자동으로 실패하거나 GL_INVALID_OPERATION을 생성합니다. 다른 플랫폼과 다른 점이 있습니다. 함수가 지원되지 않으면 함수 포인터는 NULL이됩니다. –