support transparency now
This commit is contained in:
@@ -71,7 +71,6 @@ void GeometryEngine::loadFile(QString filePath)
|
||||
m_boundings = file.getBoundingBox();
|
||||
|
||||
// collect data
|
||||
//TODO: sort transparent faces
|
||||
unsigned int indexOffset(0);
|
||||
unsigned int vertexOffset(0);
|
||||
for (auto& modelIterator : *models)
|
||||
@@ -94,7 +93,11 @@ void GeometryEngine::loadFile(QString filePath)
|
||||
// save data
|
||||
vertexData += segmentIterator->vertices;
|
||||
indexData += segmentIterator->indices;
|
||||
m_drawList.push_back(new_info);
|
||||
|
||||
if (segmentIterator->textureIndex < m_materials->size() && m_materials->at(segmentIterator->textureIndex).transparent)
|
||||
m_drawList.push_back(new_info);
|
||||
else
|
||||
m_drawList.push_front(new_info);
|
||||
|
||||
// update offset
|
||||
indexOffset += new_info.size;
|
||||
@@ -172,15 +175,25 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
|
||||
for (auto& it : m_drawList)
|
||||
{
|
||||
bool tmp_transparent(false);
|
||||
|
||||
// bind the correct texture
|
||||
if (it.textureIndex < m_materials->size())
|
||||
{
|
||||
m_materials->at(it.textureIndex).texture->bind();
|
||||
tmp_transparent = m_materials->at(it.textureIndex).transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_materials->last().texture->bind();
|
||||
|
||||
tmp_transparent = m_materials->last().transparent;
|
||||
}
|
||||
// Set model matrix
|
||||
program->setUniformValue("m_matrix", it.modelMatrix);
|
||||
|
||||
// decide if this is transparent
|
||||
program->setUniformValue("b_transparent", tmp_transparent);
|
||||
|
||||
// Draw cube geometry using indices from VBO 1
|
||||
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user