Skip to content

Commit

Permalink
Fix shader on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Mar 20, 2020
1 parent aa9b0b5 commit 6fcb86a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOGS.md
Original file line number Diff line number Diff line change
@@ -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:
--------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions dust3d.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
19 changes: 5 additions & 14 deletions src/modelmeshbinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/modelshaderprogram.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <QSurfaceFormat>
#include <QFile>
#include <map>
#include "modelshaderprogram.h"
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modelshaderprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ModelShaderProgram : public QOpenGLShaderProgram
{
public:
ModelShaderProgram();
ModelShaderProgram(bool isCoreProfile);
int projectionMatrixLoc();
int modelMatrixLoc();
int normalMatrixLoc();
Expand Down
13 changes: 11 additions & 2 deletions src/modelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QGuiApplication>
#include <math.h>
#include <QVector4D>
#include <QSurfaceFormat>
#include "modelwidget.h"
#include "util.h"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6fcb86a

Please sign in to comment.