2018-04-02 06:05:06 +00:00
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
2018-04-26 02:23:22 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <map>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
2020-03-18 14:17:09 +00:00
|
|
|
#include <QSurfaceFormat>
|
2018-04-02 06:05:06 +00:00
|
|
|
#include "modelmeshbinder.h"
|
2020-03-18 14:17:09 +00:00
|
|
|
#include "ddsfile.h"
|
2020-04-08 10:09:16 +00:00
|
|
|
#include "preferences.h"
|
2018-04-02 06:05:06 +00:00
|
|
|
|
2019-07-07 06:27:58 +00:00
|
|
|
ModelMeshBinder::ModelMeshBinder(bool toolEnabled) :
|
|
|
|
m_toolEnabled(toolEnabled)
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelMeshBinder::~ModelMeshBinder()
|
|
|
|
{
|
|
|
|
delete m_mesh;
|
2018-09-18 07:20:51 +00:00
|
|
|
delete m_newMesh;
|
2018-05-10 09:16:22 +00:00
|
|
|
delete m_texture;
|
2018-10-09 02:19:12 +00:00
|
|
|
delete m_normalMap;
|
|
|
|
delete m_metalnessRoughnessAmbientOcclusionMap;
|
2020-03-18 14:17:09 +00:00
|
|
|
delete m_environmentIrradianceMap;
|
|
|
|
delete m_environmentSpecularMap;
|
2020-04-02 10:39:57 +00:00
|
|
|
delete m_toonNormalMap;
|
|
|
|
delete m_toonDepthMap;
|
|
|
|
delete m_newToonNormalMap;
|
|
|
|
delete m_newToonDepthMap;
|
|
|
|
delete m_currentToonNormalMap;
|
|
|
|
delete m_currentToonDepthMap;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
void ModelMeshBinder::updateMesh(Model *mesh)
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2018-09-18 07:20:51 +00:00
|
|
|
QMutexLocker lock(&m_newMeshMutex);
|
2018-04-02 06:05:06 +00:00
|
|
|
if (mesh != m_mesh) {
|
2018-09-18 07:20:51 +00:00
|
|
|
delete m_newMesh;
|
|
|
|
m_newMesh = mesh;
|
|
|
|
m_newMeshComing = true;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:27:26 +00:00
|
|
|
void ModelMeshBinder::reloadMesh()
|
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
Model *mesh = nullptr;
|
2019-08-09 22:27:26 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_newMeshMutex);
|
|
|
|
if (nullptr == m_mesh)
|
|
|
|
return;
|
2020-04-07 23:15:20 +00:00
|
|
|
mesh = new Model(*m_mesh);
|
2019-08-09 22:27:26 +00:00
|
|
|
}
|
|
|
|
if (nullptr != mesh)
|
|
|
|
updateMesh(mesh);
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:05:06 +00:00
|
|
|
void ModelMeshBinder::initialize()
|
|
|
|
{
|
|
|
|
m_vaoTriangle.create();
|
|
|
|
m_vaoEdge.create();
|
2019-07-07 06:27:58 +00:00
|
|
|
if (m_toolEnabled)
|
|
|
|
m_vaoTool.create();
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 14:17:09 +00:00
|
|
|
void ModelMeshBinder::enableEnvironmentLight()
|
|
|
|
{
|
|
|
|
m_environmentLightEnabled = true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
Model *ModelMeshBinder::fetchCurrentMesh()
|
2020-04-02 10:39:57 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_meshMutex);
|
|
|
|
if (nullptr == m_mesh)
|
|
|
|
return nullptr;
|
2020-04-07 23:15:20 +00:00
|
|
|
return new Model(*m_mesh);
|
2020-04-02 10:39:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 09:16:22 +00:00
|
|
|
void ModelMeshBinder::paint(ModelShaderProgram *program)
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
Model *newMesh = nullptr;
|
2018-09-18 07:20:51 +00:00
|
|
|
bool hasNewMesh = false;
|
|
|
|
if (m_newMeshComing) {
|
|
|
|
QMutexLocker lock(&m_newMeshMutex);
|
|
|
|
if (m_newMeshComing) {
|
|
|
|
newMesh = m_newMesh;
|
|
|
|
m_newMesh = nullptr;
|
|
|
|
m_newMeshComing = false;
|
|
|
|
hasNewMesh = true;
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 10:39:57 +00:00
|
|
|
if (m_newToonMapsComing) {
|
|
|
|
QMutexLocker lock(&m_toonNormalAndDepthMapMutex);
|
|
|
|
if (m_newToonMapsComing) {
|
|
|
|
|
|
|
|
delete m_toonNormalMap;
|
|
|
|
m_toonNormalMap = nullptr;
|
|
|
|
delete m_currentToonNormalMap;
|
|
|
|
m_currentToonNormalMap = nullptr;
|
|
|
|
if (nullptr != m_newToonNormalMap) {
|
|
|
|
m_toonNormalMap = new QOpenGLTexture(*m_newToonNormalMap);
|
|
|
|
m_currentToonNormalMap = m_newToonNormalMap;
|
|
|
|
m_newToonNormalMap = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_toonDepthMap;
|
|
|
|
m_toonDepthMap = nullptr;
|
|
|
|
delete m_currentToonDepthMap;
|
|
|
|
m_currentToonDepthMap = nullptr;
|
|
|
|
if (nullptr != m_newToonDepthMap) {
|
|
|
|
m_toonDepthMap = new QOpenGLTexture(*m_newToonDepthMap);
|
|
|
|
m_currentToonDepthMap = m_newToonDepthMap;
|
|
|
|
m_newToonDepthMap = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_newToonMapsComing = false;
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_meshMutex);
|
2018-09-18 07:20:51 +00:00
|
|
|
if (hasNewMesh) {
|
|
|
|
delete m_mesh;
|
|
|
|
m_mesh = newMesh;
|
2018-04-02 06:05:06 +00:00
|
|
|
if (m_mesh) {
|
2018-05-10 09:16:22 +00:00
|
|
|
m_hasTexture = nullptr != m_mesh->textureImage();
|
|
|
|
delete m_texture;
|
|
|
|
m_texture = nullptr;
|
2019-08-09 22:27:26 +00:00
|
|
|
if (m_hasTexture) {
|
|
|
|
if (m_checkUvEnabled) {
|
|
|
|
static QImage *s_checkUv = nullptr;
|
|
|
|
if (nullptr == s_checkUv)
|
|
|
|
s_checkUv = new QImage(":/resources/checkuv.png");
|
|
|
|
m_texture = new QOpenGLTexture(*s_checkUv);
|
|
|
|
} else {
|
|
|
|
m_texture = new QOpenGLTexture(*m_mesh->textureImage());
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
|
|
|
|
m_hasNormalMap = nullptr != m_mesh->normalMapImage();
|
|
|
|
delete m_normalMap;
|
|
|
|
m_normalMap = nullptr;
|
|
|
|
if (m_hasNormalMap)
|
|
|
|
m_normalMap = new QOpenGLTexture(*m_mesh->normalMapImage());
|
|
|
|
|
|
|
|
m_hasMetalnessMap = m_mesh->hasMetalnessInImage();
|
|
|
|
m_hasRoughnessMap = m_mesh->hasRoughnessInImage();
|
|
|
|
m_hasAmbientOcclusionMap = m_mesh->hasAmbientOcclusionInImage();
|
|
|
|
delete m_metalnessRoughnessAmbientOcclusionMap;
|
|
|
|
m_metalnessRoughnessAmbientOcclusionMap = nullptr;
|
|
|
|
if (nullptr != m_mesh->metalnessRoughnessAmbientOcclusionImage() &&
|
|
|
|
(m_hasMetalnessMap || m_hasRoughnessMap || m_hasAmbientOcclusionMap))
|
|
|
|
m_metalnessRoughnessAmbientOcclusionMap = new QOpenGLTexture(*m_mesh->metalnessRoughnessAmbientOcclusionImage());
|
2020-03-18 14:17:09 +00:00
|
|
|
|
|
|
|
delete m_environmentIrradianceMap;
|
|
|
|
m_environmentIrradianceMap = nullptr;
|
|
|
|
delete m_environmentSpecularMap;
|
|
|
|
m_environmentSpecularMap = nullptr;
|
2020-03-19 07:54:30 +00:00
|
|
|
if (program->isCoreProfile() &&
|
|
|
|
m_environmentLightEnabled &&
|
2020-03-18 14:17:09 +00:00
|
|
|
(m_hasMetalnessMap || m_hasRoughnessMap)) {
|
|
|
|
DdsFileReader irradianceFile(":/resources/cedar_bridge_irradiance.dds");
|
|
|
|
m_environmentIrradianceMap = irradianceFile.createOpenGLTexture();
|
2018-10-09 02:19:12 +00:00
|
|
|
|
2020-03-18 14:17:09 +00:00
|
|
|
DdsFileReader specularFile(":/resources/cedar_bridge_specular.dds");
|
|
|
|
m_environmentSpecularMap = specularFile.createOpenGLTexture();
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:05:06 +00:00
|
|
|
{
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoTriangle);
|
|
|
|
if (m_vboTriangle.isCreated())
|
|
|
|
m_vboTriangle.destroy();
|
|
|
|
m_vboTriangle.create();
|
|
|
|
m_vboTriangle.bind();
|
2019-07-04 09:36:50 +00:00
|
|
|
m_vboTriangle.allocate(m_mesh->triangleVertices(), m_mesh->triangleVertexCount() * sizeof(ShaderVertex));
|
2018-04-02 06:05:06 +00:00
|
|
|
m_renderTriangleVertexCount = m_mesh->triangleVertexCount();
|
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
|
f->glEnableVertexAttribArray(0);
|
|
|
|
f->glEnableVertexAttribArray(1);
|
|
|
|
f->glEnableVertexAttribArray(2);
|
2018-05-10 09:16:22 +00:00
|
|
|
f->glEnableVertexAttribArray(3);
|
2018-10-04 12:51:01 +00:00
|
|
|
f->glEnableVertexAttribArray(4);
|
|
|
|
f->glEnableVertexAttribArray(5);
|
2018-10-09 02:19:12 +00:00
|
|
|
f->glEnableVertexAttribArray(6);
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glEnableVertexAttribArray(7);
|
2019-07-04 09:36:50 +00:00
|
|
|
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), 0);
|
|
|
|
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(6 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(9 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(11 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(12 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(13 * sizeof(GLfloat)));
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(16 * sizeof(GLfloat)));
|
2018-04-02 06:05:06 +00:00
|
|
|
m_vboTriangle.release();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
|
|
|
|
if (m_vboEdge.isCreated())
|
|
|
|
m_vboEdge.destroy();
|
|
|
|
m_vboEdge.create();
|
|
|
|
m_vboEdge.bind();
|
2019-07-04 09:36:50 +00:00
|
|
|
m_vboEdge.allocate(m_mesh->edgeVertices(), m_mesh->edgeVertexCount() * sizeof(ShaderVertex));
|
2018-04-02 06:05:06 +00:00
|
|
|
m_renderEdgeVertexCount = m_mesh->edgeVertexCount();
|
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
|
f->glEnableVertexAttribArray(0);
|
|
|
|
f->glEnableVertexAttribArray(1);
|
|
|
|
f->glEnableVertexAttribArray(2);
|
2018-05-10 09:16:22 +00:00
|
|
|
f->glEnableVertexAttribArray(3);
|
2018-10-04 12:51:01 +00:00
|
|
|
f->glEnableVertexAttribArray(4);
|
|
|
|
f->glEnableVertexAttribArray(5);
|
2018-10-09 02:19:12 +00:00
|
|
|
f->glEnableVertexAttribArray(6);
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glEnableVertexAttribArray(7);
|
2019-07-04 09:36:50 +00:00
|
|
|
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), 0);
|
|
|
|
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(6 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(9 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(11 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(12 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(13 * sizeof(GLfloat)));
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(16 * sizeof(GLfloat)));
|
2018-04-02 06:05:06 +00:00
|
|
|
m_vboEdge.release();
|
|
|
|
}
|
2019-07-07 06:27:58 +00:00
|
|
|
if (m_toolEnabled) {
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoTool);
|
|
|
|
if (m_vboTool.isCreated())
|
|
|
|
m_vboTool.destroy();
|
|
|
|
m_vboTool.create();
|
|
|
|
m_vboTool.bind();
|
|
|
|
m_vboTool.allocate(m_mesh->toolVertices(), m_mesh->toolVertexCount() * sizeof(ShaderVertex));
|
|
|
|
m_renderToolVertexCount = m_mesh->toolVertexCount();
|
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
|
f->glEnableVertexAttribArray(0);
|
|
|
|
f->glEnableVertexAttribArray(1);
|
|
|
|
f->glEnableVertexAttribArray(2);
|
|
|
|
f->glEnableVertexAttribArray(3);
|
|
|
|
f->glEnableVertexAttribArray(4);
|
|
|
|
f->glEnableVertexAttribArray(5);
|
|
|
|
f->glEnableVertexAttribArray(6);
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glEnableVertexAttribArray(7);
|
2019-07-07 06:27:58 +00:00
|
|
|
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), 0);
|
|
|
|
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(6 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(9 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(11 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(12 * sizeof(GLfloat)));
|
|
|
|
f->glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(13 * sizeof(GLfloat)));
|
2019-11-02 02:43:23 +00:00
|
|
|
f->glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, sizeof(ShaderVertex), reinterpret_cast<void *>(16 * sizeof(GLfloat)));
|
2019-07-07 06:27:58 +00:00
|
|
|
m_vboTool.release();
|
|
|
|
} else {
|
|
|
|
m_renderToolVertexCount = 0;
|
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
} else {
|
|
|
|
m_renderTriangleVertexCount = 0;
|
|
|
|
m_renderEdgeVertexCount = 0;
|
2019-07-07 06:27:58 +00:00
|
|
|
m_renderToolVertexCount = 0;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 23:01:00 +00:00
|
|
|
program->setUniformValue(program->textureIdLoc(), 0);
|
|
|
|
program->setUniformValue(program->normalMapIdLoc(), 1);
|
|
|
|
program->setUniformValue(program->metalnessRoughnessAmbientOcclusionMapIdLoc(), 2);
|
|
|
|
program->setUniformValue(program->environmentIrradianceMapIdLoc(), 3);
|
|
|
|
program->setUniformValue(program->environmentSpecularMapIdLoc(), 4);
|
2020-04-02 10:39:57 +00:00
|
|
|
program->setUniformValue(program->toonNormalMapIdLoc(), 5);
|
|
|
|
program->setUniformValue(program->toonDepthMapIdLoc(), 6);
|
2018-04-11 15:06:30 +00:00
|
|
|
if (m_showWireframes) {
|
2018-04-07 11:51:33 +00:00
|
|
|
if (m_renderEdgeVertexCount > 0) {
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge);
|
2018-04-12 08:34:00 +00:00
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
2020-01-14 12:08:57 +00:00
|
|
|
// glDrawArrays GL_LINES crashs on Mesa GL
|
2020-03-20 07:41:48 +00:00
|
|
|
if (program->isCoreProfile()) {
|
2020-01-14 12:08:57 +00:00
|
|
|
program->setUniformValue(program->textureEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->normalMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->metalnessMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->roughnessMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->ambientOcclusionMapEnabledLoc(), 0);
|
2020-03-18 14:17:09 +00:00
|
|
|
if (program->isCoreProfile()) {
|
|
|
|
program->setUniformValue(program->environmentIrradianceMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->environmentSpecularMapEnabledLoc(), 0);
|
|
|
|
}
|
2020-01-14 12:08:57 +00:00
|
|
|
f->glDrawArrays(GL_LINES, 0, m_renderEdgeVertexCount);
|
|
|
|
}
|
2018-04-07 11:51:33 +00:00
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
if (m_renderTriangleVertexCount > 0) {
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoTriangle);
|
2018-04-12 08:34:00 +00:00
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
2018-05-10 09:16:22 +00:00
|
|
|
if (m_hasTexture) {
|
|
|
|
if (m_texture)
|
|
|
|
m_texture->bind(0);
|
|
|
|
program->setUniformValue(program->textureEnabledLoc(), 1);
|
|
|
|
} else {
|
|
|
|
program->setUniformValue(program->textureEnabledLoc(), 0);
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
if (m_hasNormalMap) {
|
|
|
|
if (m_normalMap)
|
|
|
|
m_normalMap->bind(1);
|
|
|
|
program->setUniformValue(program->normalMapEnabledLoc(), 1);
|
|
|
|
} else {
|
|
|
|
program->setUniformValue(program->normalMapEnabledLoc(), 0);
|
|
|
|
}
|
|
|
|
if (m_hasMetalnessMap || m_hasRoughnessMap || m_hasAmbientOcclusionMap) {
|
|
|
|
if (m_metalnessRoughnessAmbientOcclusionMap)
|
|
|
|
m_metalnessRoughnessAmbientOcclusionMap->bind(2);
|
2020-03-18 23:01:00 +00:00
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
program->setUniformValue(program->metalnessMapEnabledLoc(), m_hasMetalnessMap ? 1 : 0);
|
|
|
|
program->setUniformValue(program->roughnessMapEnabledLoc(), m_hasRoughnessMap ? 1 : 0);
|
|
|
|
program->setUniformValue(program->ambientOcclusionMapEnabledLoc(), m_hasAmbientOcclusionMap ? 1 : 0);
|
2020-03-18 14:17:09 +00:00
|
|
|
if (program->isCoreProfile()) {
|
|
|
|
if (nullptr != m_environmentIrradianceMap) {
|
|
|
|
m_environmentIrradianceMap->bind(3);
|
|
|
|
program->setUniformValue(program->environmentIrradianceMapEnabledLoc(), 1);
|
|
|
|
} else {
|
|
|
|
program->setUniformValue(program->environmentIrradianceMapEnabledLoc(), 0);
|
|
|
|
}
|
|
|
|
if (nullptr != m_environmentSpecularMap) {
|
|
|
|
m_environmentSpecularMap->bind(4);
|
|
|
|
program->setUniformValue(program->environmentSpecularMapEnabledLoc(), 1);
|
|
|
|
} else {
|
|
|
|
program->setUniformValue(program->environmentSpecularMapEnabledLoc(), 0);
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 10:39:57 +00:00
|
|
|
if (nullptr != m_toonNormalMap && nullptr != m_toonDepthMap) {
|
|
|
|
m_toonNormalMap->bind(5);
|
|
|
|
m_toonDepthMap->bind(6);
|
2020-04-08 10:09:16 +00:00
|
|
|
program->setUniformValue(program->toonEdgeEnabledLoc(), (int)Preferences::instance().toonLine());
|
2020-04-02 10:39:57 +00:00
|
|
|
}
|
2018-04-12 08:34:00 +00:00
|
|
|
f->glDrawArrays(GL_TRIANGLES, 0, m_renderTriangleVertexCount);
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
2019-07-07 06:27:58 +00:00
|
|
|
if (m_toolEnabled) {
|
|
|
|
if (m_renderToolVertexCount > 0) {
|
|
|
|
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoTool);
|
|
|
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
|
program->setUniformValue(program->textureEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->normalMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->metalnessMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->roughnessMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->ambientOcclusionMapEnabledLoc(), 0);
|
2020-03-18 14:17:09 +00:00
|
|
|
if (program->isCoreProfile()) {
|
|
|
|
program->setUniformValue(program->environmentIrradianceMapEnabledLoc(), 0);
|
|
|
|
program->setUniformValue(program->environmentSpecularMapEnabledLoc(), 0);
|
|
|
|
}
|
2019-07-07 06:27:58 +00:00
|
|
|
f->glDrawArrays(GL_TRIANGLES, 0, m_renderToolVertexCount);
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 10:39:57 +00:00
|
|
|
void ModelMeshBinder::fetchCurrentToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap)
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_toonNormalAndDepthMapMutex);
|
|
|
|
if (nullptr != normalMap && nullptr != m_currentToonNormalMap)
|
|
|
|
*normalMap = *m_currentToonNormalMap;
|
|
|
|
if (nullptr != depthMap && nullptr != m_currentToonDepthMap)
|
|
|
|
*depthMap = *m_currentToonDepthMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelMeshBinder::updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap)
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_toonNormalAndDepthMapMutex);
|
|
|
|
|
|
|
|
delete m_newToonNormalMap;
|
|
|
|
m_newToonNormalMap = normalMap;
|
|
|
|
|
|
|
|
delete m_newToonDepthMap;
|
|
|
|
m_newToonDepthMap = depthMap;
|
|
|
|
|
|
|
|
m_newToonMapsComing = true;
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:05:06 +00:00
|
|
|
void ModelMeshBinder::cleanup()
|
|
|
|
{
|
|
|
|
if (m_vboTriangle.isCreated())
|
|
|
|
m_vboTriangle.destroy();
|
|
|
|
if (m_vboEdge.isCreated())
|
|
|
|
m_vboEdge.destroy();
|
2019-07-07 06:27:58 +00:00
|
|
|
if (m_toolEnabled) {
|
|
|
|
if (m_vboTool.isCreated())
|
|
|
|
m_vboTool.destroy();
|
|
|
|
}
|
2018-05-12 10:07:46 +00:00
|
|
|
delete m_texture;
|
|
|
|
m_texture = nullptr;
|
2018-10-09 02:19:12 +00:00
|
|
|
delete m_normalMap;
|
|
|
|
m_normalMap = nullptr;
|
|
|
|
delete m_metalnessRoughnessAmbientOcclusionMap;
|
|
|
|
m_metalnessRoughnessAmbientOcclusionMap = nullptr;
|
2020-03-20 07:41:48 +00:00
|
|
|
delete m_environmentIrradianceMap;
|
|
|
|
m_environmentIrradianceMap = nullptr;
|
|
|
|
delete m_environmentSpecularMap;
|
|
|
|
m_environmentSpecularMap = nullptr;
|
2020-04-02 10:39:57 +00:00
|
|
|
delete m_toonNormalMap;
|
|
|
|
m_toonNormalMap = nullptr;
|
|
|
|
delete m_toonDepthMap;
|
|
|
|
m_toonDepthMap = nullptr;
|
2018-04-02 06:05:06 +00:00
|
|
|
}
|
2018-04-07 11:51:33 +00:00
|
|
|
|
2018-04-11 15:06:30 +00:00
|
|
|
void ModelMeshBinder::showWireframes()
|
2018-04-07 11:51:33 +00:00
|
|
|
{
|
2018-04-11 15:06:30 +00:00
|
|
|
m_showWireframes = true;
|
2018-04-07 11:51:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 15:06:30 +00:00
|
|
|
void ModelMeshBinder::hideWireframes()
|
2018-04-07 11:51:33 +00:00
|
|
|
{
|
2018-04-11 15:06:30 +00:00
|
|
|
m_showWireframes = false;
|
2018-04-07 11:51:33 +00:00
|
|
|
}
|
2018-04-15 12:48:54 +00:00
|
|
|
|
|
|
|
bool ModelMeshBinder::isWireframesVisible()
|
|
|
|
{
|
|
|
|
return m_showWireframes;
|
|
|
|
}
|
2019-08-09 22:27:26 +00:00
|
|
|
|
|
|
|
void ModelMeshBinder::enableCheckUv()
|
|
|
|
{
|
|
|
|
m_checkUvEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelMeshBinder::disableCheckUv()
|
|
|
|
{
|
|
|
|
m_checkUvEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModelMeshBinder::isCheckUvEnabled()
|
|
|
|
{
|
|
|
|
return m_checkUvEnabled;
|
|
|
|
}
|