From 6fcb86a191d7c019641fe9f924bd6c75eb1346cc Mon Sep 17 00:00:00 2001 From: huxingyi Date: Fri, 20 Mar 2020 17:11:48 +0930 Subject: [PATCH] Fix shader on win32 --- CHANGELOGS.md | 4 +++- dust3d.pro | 4 ++-- src/modelmeshbinder.cpp | 19 +++++-------------- src/modelshaderprogram.cpp | 5 ++--- src/modelshaderprogram.h | 2 +- src/modelwidget.cpp | 13 +++++++++++-- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/CHANGELOGS.md b/CHANGELOGS.md index 742a095b..669d1c70 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -1,6 +1,8 @@ -Changes between 1.0.0-rc.1 and 1.0.0-rc.2: +Changes between 1.0.0-rc.1 and 1.0.0-rc.3: +-------------------------------------------------- - Fix negative skinning weight - Fix IBL shader +- Add win32 release Changes between 1.0.0-beta.29 and 1.0.0-rc.1: -------------------------------------------------- diff --git a/dust3d.pro b/dust3d.pro index 5fff1c41..2dd8e53e 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -66,10 +66,10 @@ macx { } isEmpty(HUMAN_VERSION) { - HUMAN_VERSION = "1.0.0-rc.2" + HUMAN_VERSION = "1.0.0-rc.3" } isEmpty(VERSION) { - VERSION = 1.0.0.32 + VERSION = 1.0.0.33 } HOMEPAGE_URL = "https://dust3d.org/" diff --git a/src/modelmeshbinder.cpp b/src/modelmeshbinder.cpp index 6e498964..6e509bef 100644 --- a/src/modelmeshbinder.cpp +++ b/src/modelmeshbinder.cpp @@ -63,18 +63,6 @@ void ModelMeshBinder::enableEnvironmentLight() void ModelMeshBinder::paint(ModelShaderProgram *program) { - static int s_softwareGlState = 0; - if (0 == s_softwareGlState) { - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - const char *versionString = (const char *)f->glGetString(GL_VERSION); - if (nullptr != versionString && - '\0' != versionString[0] && - 0 == strstr(versionString, "Mesa")) { - s_softwareGlState = 2; - } else { - s_softwareGlState = 1; - } - } MeshLoader *newMesh = nullptr; bool hasNewMesh = false; if (m_newMeshComing) { @@ -127,7 +115,6 @@ void ModelMeshBinder::paint(ModelShaderProgram *program) m_environmentSpecularMap = nullptr; if (program->isCoreProfile() && m_environmentLightEnabled && - 2 == s_softwareGlState && (m_hasMetalnessMap || m_hasRoughnessMap)) { DdsFileReader irradianceFile(":/resources/cedar_bridge_irradiance.dds"); m_environmentIrradianceMap = irradianceFile.createOpenGLTexture(); @@ -236,7 +223,7 @@ void ModelMeshBinder::paint(ModelShaderProgram *program) QOpenGLVertexArrayObject::Binder vaoBinder(&m_vaoEdge); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); // glDrawArrays GL_LINES crashs on Mesa GL - if (2 == s_softwareGlState) { + if (program->isCoreProfile()) { program->setUniformValue(program->textureEnabledLoc(), 0); program->setUniformValue(program->normalMapEnabledLoc(), 0); program->setUniformValue(program->metalnessMapEnabledLoc(), 0); @@ -324,6 +311,10 @@ void ModelMeshBinder::cleanup() m_normalMap = nullptr; delete m_metalnessRoughnessAmbientOcclusionMap; m_metalnessRoughnessAmbientOcclusionMap = nullptr; + delete m_environmentIrradianceMap; + m_environmentIrradianceMap = nullptr; + delete m_environmentSpecularMap; + m_environmentSpecularMap = nullptr; } void ModelMeshBinder::showWireframes() diff --git a/src/modelshaderprogram.cpp b/src/modelshaderprogram.cpp index e068cbfa..07a8b082 100644 --- a/src/modelshaderprogram.cpp +++ b/src/modelshaderprogram.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "modelshaderprogram.h" @@ -22,9 +21,9 @@ bool ModelShaderProgram::isCoreProfile() return m_isCoreProfile; } -ModelShaderProgram::ModelShaderProgram() +ModelShaderProgram::ModelShaderProgram(bool isCoreProfile) { - if (QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile) { + if (isCoreProfile) { this->addShaderFromSourceCode(QOpenGLShader::Vertex, loadShaderSource(":/shaders/default.core.vert")); this->addShaderFromSourceCode(QOpenGLShader::Fragment, loadShaderSource(":/shaders/default.core.frag")); m_isCoreProfile = true; diff --git a/src/modelshaderprogram.h b/src/modelshaderprogram.h index a0d81f36..c36c51c5 100644 --- a/src/modelshaderprogram.h +++ b/src/modelshaderprogram.h @@ -6,7 +6,7 @@ class ModelShaderProgram : public QOpenGLShaderProgram { public: - ModelShaderProgram(); + ModelShaderProgram(bool isCoreProfile); int projectionMatrixLoc(); int modelMatrixLoc(); int normalMatrixLoc(); diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index 3c8f8c97..07660d39 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "modelwidget.h" #include "util.h" @@ -122,8 +123,16 @@ void ModelWidget::initializeGL() QColor bgcolor = QWidget::palette().color(QWidget::backgroundRole()); glClearColor(bgcolor.redF(), bgcolor.greenF(), bgcolor.blueF(), 1); } - - m_program = new ModelShaderProgram; + + bool isCoreProfile = false; + const char *versionString = (const char *)glGetString(GL_VERSION); + if (nullptr != versionString && + '\0' != versionString[0] && + 0 == strstr(versionString, "Mesa")) { + isCoreProfile = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile; + } + + m_program = new ModelShaderProgram(isCoreProfile); // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x // implementations this is optional and support may not be present