2014-02-07 6 views
2

내 목표는 인스턴스화 된 렌더링 작동을 얻는 것이지만, 단 하나의 glDrawElements도 지금은 실패합니다. 참고 :이 코드는 이미 Windows에서 작동합니다. 그러나 OS X에서는 실패합니다. GL_INVALID_OPERATIONglDrawElements가 오류 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; 
+0

현재 OS X에서 어떤 종류의 OpenGL 컨텍스트를 사용하고 있습니까? 코어 3.2 이상? 인스 턴싱은 GL 3.x 시대입니다. OS X에서 확장되지 않은 형태로 사용하려면 코어 프로파일이 필요합니다. GL 2.1 컨텍스트에서 호출하려고하는 코어에서만 노출 된 함수는 OS X에서 자동으로 실패하거나 GL_INVALID_OPERATION을 생성합니다. 다른 플랫폼과 다른 점이 있습니다. 함수가 지원되지 않으면 함수 포인터는 NULL이됩니다. –

답변

0

저는 OpenGL에 익숙하지 않지만 glew를 사용하고 있습니까? 그렇다면 glewExperimental = GL_TRUEglewInit() 앞에 설정 했습니까?

+0

OS X에서는 GLEW가 필요하지 않습니다. Apple은 항상 다른 방식으로 작업 해 왔으며, GL을 사용하는 방식은 OP 질문에 대한 내 의견에서 설명한 것처럼 약간 까다 롭습니다. –

+0

지적 해 주셔서 감사합니다. – lightandlight

1

GL 코어 컨텍스트를 사용하면 glDrawElements 또는 glDrawElementsInstancedindices 매개 변수에 대한 클라이언트 측 배열을 전달할 수 없습니다. 두 경우 모두 인덱스 버퍼를 만들고이 버퍼에 인덱스를 저장해야합니다. 그리기 호출의 indices 매개 변수는 인덱스를 읽을 바인드 된 인덱스 버퍼로의 오프셋 (바이트)이됩니다.

그러나 인덱스 배열을 0에서 35로 보는 대신 glDrawArrays 또는 glDrawArraysInstanced을 대신 사용하지 않으시겠습니까?