passing poylNormal, tangent, bitangent to shader
This commit is contained in:
@@ -52,6 +52,58 @@ void GeometryEngine::clearData()
|
||||
m_drawList.clear();
|
||||
}
|
||||
|
||||
void GeometryEngine::setupPipeline(QOpenGLShaderProgram *program)
|
||||
{
|
||||
// Offset for position
|
||||
quintptr offset = 0;
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex position data
|
||||
int vertexLocation = program->attributeLocation("a_position");
|
||||
program->enableAttributeArray(vertexLocation);
|
||||
program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Offset for texture coordinate
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
|
||||
int texcoordLocation = program->attributeLocation("a_texcoord");
|
||||
program->enableAttributeArray(texcoordLocation);
|
||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||
|
||||
//Offset for vertexNormal
|
||||
offset += sizeof(QVector2D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||
int vertNormLocation = program->attributeLocation("a_normal");
|
||||
program->enableAttributeArray(vertNormLocation);
|
||||
program->setAttributeBuffer(vertNormLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
//Offset for polygonNormal
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate polygon normal data
|
||||
int polyNormLocation = program->attributeLocation("a_polyNorm");
|
||||
program->enableAttributeArray(polyNormLocation);
|
||||
program->setAttributeBuffer(polyNormLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
//Offset for polygonTangent
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate polygon tangent data
|
||||
int polyTanLocation = program->attributeLocation("a_polyTan");
|
||||
program->enableAttributeArray(polyTanLocation);
|
||||
program->setAttributeBuffer(polyTanLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
//Offset for polygonBitangent
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate polygon bitangent data
|
||||
int polyBiTanLocation = program->attributeLocation("a_polyBiTan");
|
||||
program->enableAttributeArray(polyBiTanLocation);
|
||||
program->setAttributeBuffer(polyBiTanLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
}
|
||||
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
{
|
||||
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
|
||||
@@ -72,30 +124,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
// Allways use texture unit 0
|
||||
program->setUniformValue("texture", 0);
|
||||
|
||||
// Offset for position
|
||||
quintptr offset = 0;
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex position data
|
||||
int vertexLocation = program->attributeLocation("a_position");
|
||||
program->enableAttributeArray(vertexLocation);
|
||||
program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Offset for texture coordinate
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
|
||||
int texcoordLocation = program->attributeLocation("a_texcoord");
|
||||
program->enableAttributeArray(texcoordLocation);
|
||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||
|
||||
//Offset for normal
|
||||
offset += sizeof(QVector2D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||
int normLocation = program->attributeLocation("a_normal");
|
||||
program->enableAttributeArray(normLocation);
|
||||
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
//setup the pipeline
|
||||
setupPipeline(program);
|
||||
|
||||
// Paint
|
||||
|
||||
for (auto& it : m_drawList)
|
||||
|
Reference in New Issue
Block a user