OBJ.cpp   OBJ.cpp 
skipping to change at line 103 skipping to change at line 103
//because they are all stored successively in a vect or! //because they are all stored successively in a vect or!
//making sure that material switches are minimized //making sure that material switches are minimized
return lMat < rMat; return lMat < rMat;
} }
} }
} }
bool OBJ::vertexArraysSupported=false; bool OBJ::vertexArraysSupported=false;
GLenum OBJ::indexBufferType=GL_UNSIGNED_SHORT; GLenum OBJ::indexBufferType=GL_UNSIGNED_SHORT;
size_t OBJ::indexBufferTypeSize=0; size_t OBJ::indexBufferTypeSize=0;
QOpenGLFunctions* OBJ::gl=Q_NULLPTR;
//static function //static function
void OBJ::setupGL() void OBJ::setupGL()
{ {
QOpenGLContext* ctx = QOpenGLContext::currentContext();
gl = ctx->functions();
//disable VAOs on Intel because of serious bugs in their implemenati on... //disable VAOs on Intel because of serious bugs in their implemenati on...
QString vendor(reinterpret_cast<const char*>(glGetString(GL_VENDOR)) ); QString vendor(reinterpret_cast<const char*>(gl->glGetString(GL_VEND OR)));
if(vendor.contains("Intel",Qt::CaseInsensitive)) if(vendor.contains("Intel",Qt::CaseInsensitive))
{ {
OBJ::vertexArraysSupported = false; OBJ::vertexArraysSupported = false;
qWarning()<<"[OBJ] Disabling VAO usage because of Intel bugs "; qWarning()<<"[OBJ] Disabling VAO usage because of Intel bugs ";
} }
else else
{ {
//find out if VAOs are supported, simplest way is just tryin g to create one //find out if VAOs are supported, simplest way is just tryin g to create one
//Qt has the necessary checks inside the create method //Qt has the necessary checks inside the create method
QOpenGLVertexArrayObject testObj; QOpenGLVertexArrayObject testObj;
skipping to change at line 133 skipping to change at line 137
if( OBJ::vertexArraysSupported ) if( OBJ::vertexArraysSupported )
{ {
qDebug()<<"[OBJ] Vertex Array Objects are supported"; qDebug()<<"[OBJ] Vertex Array Objects are supported";
} }
else else
{ {
qWarning()<<"[OBJ] Vertex Array Objects are not supported on your hardware"; qWarning()<<"[OBJ] Vertex Array Objects are not supported on your hardware";
} }
//check if we can enable int index buffers //check if we can enable int index buffers
QOpenGLContext* ctx = QOpenGLContext::currentContext();
if(ctx->isOpenGLES()) if(ctx->isOpenGLES())
{ {
//query for extension //query for extension
if(ctx->hasExtension("GL_OES_element_index_uint")) if(ctx->hasExtension("GL_OES_element_index_uint"))
{ {
OBJ::indexBufferType = GL_UNSIGNED_INT; OBJ::indexBufferType = GL_UNSIGNED_INT;
} }
} }
else else
{ {
skipping to change at line 1711 skipping to change at line 1714
void OBJ::bindBuffersGL() void OBJ::bindBuffersGL()
{ {
m_vertexBuffer.bind(); m_vertexBuffer.bind();
//using qt wrappers here is not possible because the only implementa tion is in QOpenGLShaderProgram, which requires a shader program instance //using qt wrappers here is not possible because the only implementa tion is in QOpenGLShaderProgram, which requires a shader program instance
//this is a bit incorrect, because the following is global state tha t does not depend on a shader //this is a bit incorrect, because the following is global state tha t does not depend on a shader
//(but may be stored in a VAO to enable faster binding/unbinding) //(but may be stored in a VAO to enable faster binding/unbinding)
//enable the attrib arrays //enable the attrib arrays
glEnableVertexAttribArray(ShaderMgr::ATTLOC_VERTEX); gl->glEnableVertexAttribArray(ShaderMgr::ATTLOC_VERTEX);
glEnableVertexAttribArray(ShaderMgr::ATTLOC_NORMAL); gl->glEnableVertexAttribArray(ShaderMgr::ATTLOC_NORMAL);
glEnableVertexAttribArray(ShaderMgr::ATTLOC_TEXCOORD); gl->glEnableVertexAttribArray(ShaderMgr::ATTLOC_TEXCOORD);
glEnableVertexAttribArray(ShaderMgr::ATTLOC_TANGENT); gl->glEnableVertexAttribArray(ShaderMgr::ATTLOC_TANGENT);
glEnableVertexAttribArray(ShaderMgr::ATTLOC_BITANGENT); gl->glEnableVertexAttribArray(ShaderMgr::ATTLOC_BITANGENT);
const GLsizei stride = sizeof(Vertex); const GLsizei stride = sizeof(Vertex);
glVertexAttribPointer(ShaderMgr::ATTLOC_VERTEX, 3,GL_FLOAT,GL_FALS gl->glVertexAttribPointer(ShaderMgr::ATTLOC_VERTEX, 3,GL_FLOAT,GL_
E,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, position))) FALSE,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, positio
; n)));
glVertexAttribPointer(ShaderMgr::ATTLOC_NORMAL, 3,GL_FLOAT,GL_FALS gl->glVertexAttribPointer(ShaderMgr::ATTLOC_NORMAL, 3,GL_FLOAT,GL_
E,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, normal))); FALSE,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, normal)
glVertexAttribPointer(ShaderMgr::ATTLOC_TEXCOORD, 2,GL_FLOAT,GL_FALS ));
E,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, texCoord))) gl->glVertexAttribPointer(ShaderMgr::ATTLOC_TEXCOORD, 2,GL_FLOAT,GL_
; FALSE,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, texCoor
glVertexAttribPointer(ShaderMgr::ATTLOC_TANGENT, 4,GL_FLOAT,GL_FALS d)));
E,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, tangent))); gl->glVertexAttribPointer(ShaderMgr::ATTLOC_TANGENT, 4,GL_FLOAT,GL_
glVertexAttribPointer(ShaderMgr::ATTLOC_BITANGENT,3,GL_FLOAT,GL_FALS FALSE,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, tangent
E,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, bitangent)) )));
); gl->glVertexAttribPointer(ShaderMgr::ATTLOC_BITANGENT,3,GL_FLOAT,GL_
FALSE,stride,reinterpret_cast<const void *>(offsetof(struct Vertex, bitange
nt)));
//vertex buffer does not need to remain bound, because the binding i s stored by glVertexAttribPointer //vertex buffer does not need to remain bound, because the binding i s stored by glVertexAttribPointer
m_vertexBuffer.release(); m_vertexBuffer.release();
//index buffer must remain bound //index buffer must remain bound
m_indexBuffer.bind(); m_indexBuffer.bind();
} }
void OBJ::unbindBuffersGL() void OBJ::unbindBuffersGL()
{ {
//unbind the index buffer (vertex buffer is NOT bound by bindBuffers GL //unbind the index buffer (vertex buffer is NOT bound by bindBuffers GL
m_indexBuffer.release(); m_indexBuffer.release();
//disable our attribute arrays //disable our attribute arrays
glDisableVertexAttribArray(ShaderMgr::ATTLOC_VERTEX); gl->glDisableVertexAttribArray(ShaderMgr::ATTLOC_VERTEX);
glDisableVertexAttribArray(ShaderMgr::ATTLOC_NORMAL); gl->glDisableVertexAttribArray(ShaderMgr::ATTLOC_NORMAL);
glDisableVertexAttribArray(ShaderMgr::ATTLOC_TEXCOORD); gl->glDisableVertexAttribArray(ShaderMgr::ATTLOC_TEXCOORD);
glDisableVertexAttribArray(ShaderMgr::ATTLOC_TANGENT); gl->glDisableVertexAttribArray(ShaderMgr::ATTLOC_TANGENT);
glDisableVertexAttribArray(ShaderMgr::ATTLOC_BITANGENT); gl->glDisableVertexAttribArray(ShaderMgr::ATTLOC_BITANGENT);
} }
void OBJ::transform(QMatrix4x4 mat) void OBJ::transform(QMatrix4x4 mat)
{ {
QMatrix3x3 normalMat = mat.normalMatrix(); QMatrix3x3 normalMat = mat.normalMatrix();
//Transform all vertices and normals by mat //Transform all vertices and normals by mat
for(int i=0; i<getNumberOfVertices(); ++i) for(int i=0; i<getNumberOfVertices(); ++i)
{ {
Vertex *pVertex = &m_vertexArray[i]; Vertex *pVertex = &m_vertexArray[i];
 End of changes. 7 change blocks. 
25 lines changed or deleted 30 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/