summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-05-22 13:23:45 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-05-22 13:32:24 +0300
commitc912ecfee7458acc49fc1fea483aff26efbeb1aa (patch)
tree4b6704d73826dae6a9c04b796688b3629e1a9e4a
parent2fa772a324612d30d2374510e5acd424f5a76e52 (diff)
OpenGL ES2 support implemented
Change-Id: I5259f6baa8da8939d6470d495e9219ce84eb8dae Change-Id: I5259f6baa8da8939d6470d495e9219ce84eb8dae Reviewed-by: Mika Salmela <mika.salmela@digia.com> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--src/datavis3d/engine/engine.qrc4
-rw-r--r--src/datavis3d/engine/q3dbars.cpp141
-rw-r--r--src/datavis3d/engine/q3dbars_p.h4
-rw-r--r--src/datavis3d/engine/q3dmaps.cpp126
-rw-r--r--src/datavis3d/engine/q3dmaps_p.h4
-rw-r--r--src/datavis3d/engine/q3dwindow.cpp9
-rw-r--r--src/datavis3d/engine/shaders/fragmentShaderColorOnYES235
-rw-r--r--src/datavis3d/engine/shaders/fragmentShaderES238
-rw-r--r--src/datavis3d/engine/shaders/fragmentShaderTexture2
-rw-r--r--src/datavis3d/engine/shaders/fragmentShaderTextureES237
-rw-r--r--src/datavis3d/engine/shaders/vertexShaderES226
-rw-r--r--src/datavis3d/utils/texturehelper.cpp14
-rw-r--r--src/datavis3d/utils/texturehelper_p.h2
13 files changed, 391 insertions, 51 deletions
diff --git a/src/datavis3d/engine/engine.qrc b/src/datavis3d/engine/engine.qrc
index 386b1038..88865718 100644
--- a/src/datavis3d/engine/engine.qrc
+++ b/src/datavis3d/engine/engine.qrc
@@ -35,6 +35,10 @@
<file alias="vertexShadow">shaders/vertexShadow</file>
<file alias="fragmentShadowNoTex">shaders/fragmentShadowNoTex</file>
<file alias="fragmentShadowNoTexColorOnY">shaders/fragmentShadowNoTexColorOnY</file>
+ <file alias="fragmentColorOnYES2">shaders/fragmentShaderColorOnYES2</file>
+ <file alias="fragmentES2">shaders/fragmentShaderES2</file>
+ <file alias="vertexES2">shaders/vertexShaderES2</file>
+ <file alias="fragmentTextureES2">shaders/fragmentShaderTextureES2</file>
</qresource>
<qresource prefix="/textures"/>
</RCC>
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index 992f0fcb..53ee0b7b 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -95,6 +95,7 @@ Q3DBars::~Q3DBars()
void Q3DBars::initialize()
{
// Initialize shaders
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
if (!d_ptr->m_theme->m_uniformColor) {
d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
@@ -118,11 +119,25 @@ void Q3DBars::initialize()
d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertex"),
QStringLiteral(":/shaders/fragment"));
}
+#else
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+ }
+ d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+#endif
+
d_ptr->initLabelShaders(QStringLiteral(":/shaders/vertexLabel"),
QStringLiteral(":/shaders/fragmentLabel"));
+#if !defined(QT_OPENGL_ES_2)
// Init depth shader (for shadows). Init in any case, easier to handle shadow activation if done via api.
d_ptr->initDepthShader();
+#endif
// Init selection shader
d_ptr->initSelectionShader();
@@ -149,9 +164,12 @@ void Q3DBars::initialize()
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
+
+#if !defined(QT_OPENGL_ES_2)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+#endif
// Set initial camera position
// X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later
@@ -492,6 +510,7 @@ void Q3DBars::drawScene()
QMatrix4x4 depthViewMatrix;
QMatrix4x4 depthProjectionMatrix;
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone/*!d_ptr->m_zoomActivated*/) {
// Render scene into a depth texture for using with shadow mapping
// Bind depth shader
@@ -611,6 +630,7 @@ void Q3DBars::drawScene()
glViewport(d_ptr->m_sceneViewPort.x(), d_ptr->m_sceneViewPort.y(),
d_ptr->m_sceneViewPort.width(), d_ptr->m_sceneViewPort.height());
}
+#endif
// Skip selection mode drawing if we're zoomed or have no selection mode
if (!d_ptr->m_zoomActivated && d_ptr->m_selectionMode > ModeNone) {
@@ -886,6 +906,7 @@ void Q3DBars::drawScene()
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS(),
d_ptr->m_theme->m_ambientStrength);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -898,7 +919,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_barObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(),
lightStrength);
@@ -960,6 +983,7 @@ void Q3DBars::drawScene()
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->ambientS(),
d_ptr->m_theme->m_ambientStrength * 2.0f);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->shadowQ(),
@@ -972,7 +996,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -1025,6 +1051,7 @@ void Q3DBars::drawScene()
itModelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -1037,7 +1064,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_gridLineObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -1071,6 +1100,7 @@ void Q3DBars::drawScene()
itModelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -1083,7 +1113,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_gridLineObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -1131,6 +1163,7 @@ void Q3DBars::drawScene()
itModelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -1143,7 +1176,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_gridLineObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -1186,6 +1221,7 @@ void Q3DBars::drawScene()
itModelMatrix.inverted().transposed());
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->MVP(), MVPMatrix);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -1198,7 +1234,9 @@ void Q3DBars::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_gridLineObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -1487,9 +1525,11 @@ void Q3DBars::resizeEvent(QResizeEvent *event)
// Re-init selection buffer
d_ptr->initSelectionBuffer();
+#if !defined(QT_OPENGL_ES_2)
// Re-init depth buffer
if (d_ptr->m_isInitialized && d_ptr->m_shadowQuality > ShadowNone)
d_ptr->initDepthBuffer();
+#endif
}
void Q3DBars::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative)
@@ -1582,13 +1622,33 @@ void Q3DBars::setTheme(ColorTheme theme)
d_ptr->m_theme->useTheme(theme);
d_ptr->m_drawer->setTheme(*d_ptr->m_theme);
// Re-initialize shaders
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->m_shadowQuality > ShadowNone) {
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ }
+ } else {
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
+ }
+ }
+#else
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
}
+#endif
}
void Q3DBars::setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, bool uniform)
@@ -1598,14 +1658,33 @@ void Q3DBars::setBarColor(QColor baseColor, QColor heightColor, QColor depthColo
d_ptr->m_theme->m_depthColor = depthColor;
//qDebug() << "colors:" << d_ptr->m_baseColor << d_ptr->m_heightColor << d_ptr->m_depthColor;
if (d_ptr->m_theme->m_uniformColor != uniform) {
- // Re-initialize shaders
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->m_shadowQuality > ShadowNone) {
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ }
+ } else {
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
+ }
+ }
+#else
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
}
+#endif
}
d_ptr->m_theme->m_uniformColor = uniform;
}
@@ -1677,6 +1756,7 @@ void Q3DBars::setShadowQuality(ShadowQuality quality)
break;
}
if (d_ptr->m_isInitialized) {
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Re-init depth buffer
d_ptr->initDepthBuffer();
@@ -1702,6 +1782,17 @@ void Q3DBars::setShadowQuality(ShadowQuality quality)
d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertex"),
QStringLiteral(":/shaders/fragment"));
}
+#else
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+ }
+ d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+#endif
}
}
@@ -2001,15 +2092,6 @@ void Q3DBarsPrivate::initSelectionShader()
m_selectionShader->initialize();
}
-void Q3DBarsPrivate::initDepthShader()
-{
- if (m_depthShader)
- delete m_depthShader;
- m_depthShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexDepth"),
- QStringLiteral(":/shaders/fragmentDepth"));
- m_depthShader->initialize();
-}
-
void Q3DBarsPrivate::initSelectionBuffer()
{
#ifndef USE_HAX0R_SELECTION
@@ -2024,6 +2106,16 @@ void Q3DBarsPrivate::initSelectionBuffer()
#endif
}
+#if !defined(QT_OPENGL_ES_2)
+void Q3DBarsPrivate::initDepthShader()
+{
+ if (m_depthShader)
+ delete m_depthShader;
+ m_depthShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexDepth"),
+ QStringLiteral(":/shaders/fragmentDepth"));
+ m_depthShader->initialize();
+}
+
void Q3DBarsPrivate::initDepthBuffer()
{
if (m_depthTexture) {
@@ -2033,6 +2125,7 @@ void Q3DBarsPrivate::initDepthBuffer()
m_depthTexture = m_textureHelper->createDepthTexture(q_ptr->size(), m_depthFrameBuffer,
m_shadowQuality);
}
+#endif
void Q3DBarsPrivate::initBackgroundShaders(const QString &vertexShader,
const QString &fragmentShader)
diff --git a/src/datavis3d/engine/q3dbars_p.h b/src/datavis3d/engine/q3dbars_p.h
index 30cdb6da..abce4aca 100644
--- a/src/datavis3d/engine/q3dbars_p.h
+++ b/src/datavis3d/engine/q3dbars_p.h
@@ -104,9 +104,11 @@ public:
void initSelectionShader();
void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader);
void initLabelShaders(const QString &vertexShader, const QString &fragmentShader);
- void initDepthShader();
void initSelectionBuffer();
+#if !defined(QT_OPENGL_ES_2)
+ void initDepthShader();
void initDepthBuffer();
+#endif
void updateTextures();
void calculateSceneScalingFactors();
void calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits);
diff --git a/src/datavis3d/engine/q3dmaps.cpp b/src/datavis3d/engine/q3dmaps.cpp
index 8dd6ce2e..6f54d037 100644
--- a/src/datavis3d/engine/q3dmaps.cpp
+++ b/src/datavis3d/engine/q3dmaps.cpp
@@ -96,6 +96,7 @@ Q3DMaps::~Q3DMaps()
void Q3DMaps::initialize()
{
// Initialize shaders
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
if (!d_ptr->m_theme->m_uniformColor) {
d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
@@ -119,11 +120,24 @@ void Q3DMaps::initialize()
d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"),
QStringLiteral(":/shaders/fragmentTexture"));
}
+#else
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+ }
+ d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), // Same vertex shader ok for ES2
+ QStringLiteral(":/shaders/fragmentTextureES2"));
+#endif
d_ptr->initLabelShaders(QStringLiteral(":/shaders/vertexLabel"),
QStringLiteral(":/shaders/fragmentLabel"));
+#if !defined(QT_OPENGL_ES_2)
// Init depth shader (for shadows). Init in any case, easier to handle shadow activation if done via api.
d_ptr->initDepthShader();
+#endif
// Init selection shader
d_ptr->initSelectionShader();
@@ -148,9 +162,12 @@ void Q3DMaps::initialize()
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
+
+#if !defined(QT_OPENGL_ES_2)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+#endif
// Set initial camera position
// X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later
@@ -284,6 +301,7 @@ void Q3DMaps::drawScene()
QMatrix4x4 depthViewMatrix;
QMatrix4x4 depthProjectionMatrix;
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Render scene into a depth texture for using with shadow mapping
// Bind depth shader
@@ -423,6 +441,8 @@ void Q3DMaps::drawScene()
d_ptr->m_labelShader->release();
#endif
}
+#endif
+
#if 1
// Skip selection mode drawing if we're zoomed or have no selection mode
if (!d_ptr->m_zoomActivated && d_ptr->m_selectionMode > ModeNone) {
@@ -612,6 +632,7 @@ void Q3DMaps::drawScene()
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->ambientS(),
d_ptr->m_theme->m_ambientStrength);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->shadowQ(),
@@ -624,7 +645,9 @@ void Q3DMaps::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_barShader, d_ptr->m_barObj,
0, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_barShader->setUniformValue(d_ptr->m_barShader->lightS(), lightStrength);
@@ -677,6 +700,7 @@ void Q3DMaps::drawScene()
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->ambientS(),
d_ptr->m_theme->m_ambientStrength * 3.0f);
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Set shadow shader bindings
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->shadowQ(),
@@ -689,7 +713,9 @@ void Q3DMaps::drawScene()
// Draw the object
d_ptr->m_drawer->drawObject(d_ptr->m_backgroundShader, d_ptr->m_backgroundObj,
d_ptr->m_bgrTexture, d_ptr->m_depthTexture);
- } else {
+ } else
+#endif
+ {
// Set shadowless shader bindings
d_ptr->m_backgroundShader->setUniformValue(d_ptr->m_backgroundShader->lightS(),
d_ptr->m_theme->m_lightStrength);
@@ -995,9 +1021,11 @@ void Q3DMaps::resizeEvent(QResizeEvent *event)
// Re-init selection buffer
d_ptr->initSelectionBuffer();
+#if !defined(QT_OPENGL_ES_2)
// Re-init depth buffer
if (d_ptr->m_isInitialized && d_ptr->m_shadowQuality > ShadowNone)
d_ptr->initDepthBuffer();
+#endif
}
void Q3DMaps::setBarSpecs(const QVector3D &thickness, AdjustmentDirection direction)
@@ -1068,14 +1096,35 @@ void Q3DMaps::setTheme(ColorTheme theme)
{
d_ptr->m_theme->useTheme(theme);
d_ptr->m_drawer->setTheme(*d_ptr->m_theme);
- // Re-initialize shaders
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->m_shadowQuality > ShadowNone) {
+ // Re-init shaders
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ }
+ } else {
+ // Re-init shaders
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
+ }
+ }
+#else
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
}
+#endif
d_ptr->m_updateLabels = true;
}
@@ -1084,14 +1133,35 @@ void Q3DMaps::setBarColor(QColor baseColor, QColor heightColor, bool uniform)
d_ptr->m_theme->m_baseColor = baseColor;
d_ptr->m_theme->m_heightColor = heightColor;
if (d_ptr->m_theme->m_uniformColor != uniform) {
- // Re-initialize shaders
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->m_shadowQuality > ShadowNone) {
+ // Re-init shaders
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
+ QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ }
+ } else {
+ // Re-init shaders
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragmentColorOnY"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertex"),
+ QStringLiteral(":/shaders/fragment"));
+ }
+ }
+#else
if (!d_ptr->m_theme->m_uniformColor) {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
} else {
- d_ptr->initShaders(QStringLiteral(":/shaders/vertexShadow"),
- QStringLiteral(":/shaders/fragmentShadowNoTex"));
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
}
+#endif
}
d_ptr->m_theme->m_uniformColor = uniform;
}
@@ -1274,6 +1344,7 @@ void Q3DMaps::setShadowQuality(ShadowQuality quality)
break;
}
if (d_ptr->m_isInitialized) {
+#if !defined(QT_OPENGL_ES_2)
if (d_ptr->m_shadowQuality > ShadowNone) {
// Re-init depth buffer
d_ptr->initDepthBuffer();
@@ -1299,6 +1370,17 @@ void Q3DMaps::setShadowQuality(ShadowQuality quality)
d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"),
QStringLiteral(":/shaders/fragmentTexture"));
}
+#else
+ if (!d_ptr->m_theme->m_uniformColor) {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentColorOnYES2"));
+ } else {
+ d_ptr->initShaders(QStringLiteral(":/shaders/vertexES2"),
+ QStringLiteral(":/shaders/fragmentES2"));
+ }
+ d_ptr->initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), // Same vertex shader ok for ES2
+ QStringLiteral(":/shaders/fragmentTextureES2"));
+#endif
}
}
@@ -1424,15 +1506,6 @@ void Q3DMapsPrivate::initSelectionShader()
m_selectionShader->initialize();
}
-void Q3DMapsPrivate::initDepthShader()
-{
- if (m_depthShader)
- delete m_depthShader;
- m_depthShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexDepth"),
- QStringLiteral(":/shaders/fragmentDepth"));
- m_depthShader->initialize();
-}
-
void Q3DMapsPrivate::initSelectionBuffer()
{
if (m_selectionTexture) {
@@ -1445,6 +1518,16 @@ void Q3DMapsPrivate::initSelectionBuffer()
m_selectionDepthBuffer);
}
+#if !defined(QT_OPENGL_ES_2)
+void Q3DMapsPrivate::initDepthShader()
+{
+ if (m_depthShader)
+ delete m_depthShader;
+ m_depthShader = new ShaderHelper(q_ptr, QStringLiteral(":/shaders/vertexDepth"),
+ QStringLiteral(":/shaders/fragmentDepth"));
+ m_depthShader->initialize();
+}
+
void Q3DMapsPrivate::initDepthBuffer()
{
if (m_depthTexture) {
@@ -1454,6 +1537,7 @@ void Q3DMapsPrivate::initDepthBuffer()
m_depthTexture = m_textureHelper->createDepthTexture(q_ptr->size(), m_depthFrameBuffer,
m_shadowQuality);
}
+#endif
void Q3DMapsPrivate::initBackgroundShaders(const QString &vertexShader,
const QString &fragmentShader)
diff --git a/src/datavis3d/engine/q3dmaps_p.h b/src/datavis3d/engine/q3dmaps_p.h
index d765acb6..df3c415b 100644
--- a/src/datavis3d/engine/q3dmaps_p.h
+++ b/src/datavis3d/engine/q3dmaps_p.h
@@ -104,9 +104,11 @@ public:
void initSelectionShader();
void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader);
void initLabelShaders(const QString &vertexShader, const QString &fragmentShader);
- void initDepthShader();
void initSelectionBuffer();
+#if !defined(QT_OPENGL_ES_2)
+ void initDepthShader();
void initDepthBuffer();
+#endif
void updateTextures();
void calculateSceneScalingFactors(const QRect &areaRect);
void calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits);
diff --git a/src/datavis3d/engine/q3dwindow.cpp b/src/datavis3d/engine/q3dwindow.cpp
index 2db3d964..4d94834b 100644
--- a/src/datavis3d/engine/q3dwindow.cpp
+++ b/src/datavis3d/engine/q3dwindow.cpp
@@ -59,9 +59,13 @@ Q3DWindow::Q3DWindow(QWindow *parent)
setSurfaceType(QWindow::OpenGLSurface);
QSurfaceFormat surfaceFormat;
surfaceFormat.setDepthBufferSize(16);
- surfaceFormat.setSamples(4);
+#if !defined(QT_OPENGL_ES_2)
+ surfaceFormat.setSamples(8);
+ surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);
+#else
+ surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
+#endif
surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
- //surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); // OpenGL crashes with ANGLE, comment out or define OpenGLES
setFormat(surfaceFormat);
create();
@@ -82,7 +86,6 @@ void Q3DWindow::initialize()
{
qDebug() << "OpenGL version" << format().majorVersion() << format().minorVersion();
qDebug() << "OpenGL renderer" << format().renderableType();
- //qDebug() << "OpenGL swapBehavior" << format().swapBehavior();
setAnimating(true);
}
diff --git a/src/datavis3d/engine/shaders/fragmentShaderColorOnYES2 b/src/datavis3d/engine/shaders/fragmentShaderColorOnYES2
new file mode 100644
index 00000000..dd7c0cf3
--- /dev/null
+++ b/src/datavis3d/engine/shaders/fragmentShaderColorOnYES2
@@ -0,0 +1,35 @@
+uniform highp vec3 lightPosition_wrld;
+uniform highp vec3 color_mdl;
+uniform highp float lightStrength;
+uniform highp float ambientStrength;
+
+varying highp vec3 position_wrld;
+varying highp vec3 normal_cmr;
+varying highp vec3 eyeDirection_cmr;
+varying highp vec3 lightDirection_cmr;
+varying highp vec2 coords_mdl;
+
+void main() {
+ highp vec3 materialDiffuseColor = vec3(coords_mdl.y * color_mdl.x, coords_mdl.y * color_mdl.y, coords_mdl.y * color_mdl.z);
+ highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor;
+ highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0);
+
+ highp float distance = length(lightPosition_wrld - position_wrld);
+ highp vec3 n = normalize(normal_cmr);
+ highp vec3 l = normalize(lightDirection_cmr);
+ highp float cosTheta = dot(n, l);
+ if (cosTheta < 0.0) cosTheta = 0.0;
+ else if (cosTheta > 1.0) cosTheta = 1.0;
+
+ highp vec3 E = normalize(eyeDirection_cmr);
+ highp vec3 R = reflect(-l, n);
+ highp float cosAlpha = dot(E, R);
+ if (cosAlpha < 0.0) cosAlpha = 0.0;
+ else if (cosAlpha > 1.0) cosAlpha = 1.0;
+
+ gl_FragColor.rgb =
+ materialAmbientColor +
+ materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / (distance * distance) +
+ materialSpecularColor * lightStrength * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / (distance * distance);
+}
+
diff --git a/src/datavis3d/engine/shaders/fragmentShaderES2 b/src/datavis3d/engine/shaders/fragmentShaderES2
new file mode 100644
index 00000000..a70ed241
--- /dev/null
+++ b/src/datavis3d/engine/shaders/fragmentShaderES2
@@ -0,0 +1,38 @@
+varying highp vec2 UV;
+varying highp vec2 coords_mdl;
+varying highp vec3 position_wrld;
+varying highp vec3 normal_cmr;
+varying highp vec3 eyeDirection_cmr;
+varying highp vec3 lightDirection_cmr;
+
+uniform highp vec3 lightPosition_wrld;
+uniform highp vec3 color_mdl;
+uniform highp float lightStrength;
+uniform highp float ambientStrength;
+
+void main() {
+ highp vec3 materialDiffuseColor = color_mdl.rgb;
+ highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor;
+ highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0);
+
+ highp float distance = length(lightPosition_wrld - position_wrld);
+
+ highp vec3 n = normalize(normal_cmr);
+ highp vec3 l = normalize(lightDirection_cmr);
+ highp float cosTheta = dot(n, l);
+ if (cosTheta < 0.0) cosTheta = 0.0;
+ else if (cosTheta > 1.0) cosTheta = 1.0;
+
+ highp vec3 E = normalize(eyeDirection_cmr);
+ highp vec3 R = reflect(-l, n);
+ highp float cosAlpha = dot(E, R);
+ if (cosAlpha < 0.0) cosAlpha = 0.0;
+ else if (cosAlpha > 1.0) cosAlpha = 1.0;
+
+ gl_FragColor.rgb =
+ materialAmbientColor +
+ materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance +
+ materialSpecularColor * lightStrength * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / distance;
+ gl_FragColor.a = 1.0;
+}
+
diff --git a/src/datavis3d/engine/shaders/fragmentShaderTexture b/src/datavis3d/engine/shaders/fragmentShaderTexture
index d271f985..a6d7b2eb 100644
--- a/src/datavis3d/engine/shaders/fragmentShaderTexture
+++ b/src/datavis3d/engine/shaders/fragmentShaderTexture
@@ -30,6 +30,6 @@ void main() {
materialAmbientColor +
materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance +
materialSpecularColor * lightStrength * pow(cosAlpha, 10) / distance;
- gl_FragColor.a = 1.0;
+ gl_FragColor.a = texture2D(textureSampler, UV).a;
}
diff --git a/src/datavis3d/engine/shaders/fragmentShaderTextureES2 b/src/datavis3d/engine/shaders/fragmentShaderTextureES2
new file mode 100644
index 00000000..16161035
--- /dev/null
+++ b/src/datavis3d/engine/shaders/fragmentShaderTextureES2
@@ -0,0 +1,37 @@
+uniform highp vec3 lightPosition_wrld;
+uniform highp vec3 color_mdl;
+uniform highp float lightStrength;
+uniform highp float ambientStrength;
+uniform sampler2D textureSampler;
+
+varying highp vec2 UV;
+varying highp vec3 position_wrld;
+varying highp vec3 normal_cmr;
+varying highp vec3 eyeDirection_cmr;
+varying highp vec3 lightDirection_cmr;
+
+void main() {
+ highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb;
+ highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor;
+ highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0);
+
+ highp float distance = length(lightPosition_wrld - position_wrld);
+ highp vec3 n = normalize(normal_cmr);
+ highp vec3 l = normalize(lightDirection_cmr);
+ highp float cosTheta = dot(n, l);
+ if (cosTheta < 0.0) cosTheta = 0.0;
+ else if (cosTheta > 1.0) cosTheta = 1.0;
+
+ highp vec3 E = normalize(eyeDirection_cmr);
+ highp vec3 R = reflect(-l, n);
+ highp float cosAlpha = dot(E, R);
+ if (cosAlpha < 0.0) cosAlpha = 0.0;
+ else if (cosAlpha > 1.0) cosAlpha = 1.0;
+
+ gl_FragColor.rgb =
+ materialAmbientColor +
+ materialDiffuseColor * lightStrength * (cosTheta * cosTheta) / distance +
+ materialSpecularColor * lightStrength * (cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha * cosAlpha) / distance;
+ gl_FragColor.a = texture2D(textureSampler, UV).a;
+}
+
diff --git a/src/datavis3d/engine/shaders/vertexShaderES2 b/src/datavis3d/engine/shaders/vertexShaderES2
new file mode 100644
index 00000000..efb40862
--- /dev/null
+++ b/src/datavis3d/engine/shaders/vertexShaderES2
@@ -0,0 +1,26 @@
+attribute highp vec3 vertexPosition_mdl;
+attribute highp vec2 vertexUV;
+attribute highp vec3 vertexNormal_mdl;
+
+uniform highp mat4 MVP;
+uniform highp mat4 V;
+uniform highp mat4 M;
+uniform highp mat4 itM;
+uniform highp vec3 lightPosition_wrld;
+
+varying highp vec3 position_wrld;
+varying highp vec3 normal_cmr;
+varying highp vec3 eyeDirection_cmr;
+varying highp vec3 lightDirection_cmr;
+varying highp vec2 coords_mdl;
+
+void main() {
+ gl_Position = MVP * vec4(vertexPosition_mdl, 1.0);
+ coords_mdl = vertexPosition_mdl.xy;
+ position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz;
+ vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz;
+ eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr;
+ vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz;
+ lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr;
+ normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz;
+}
diff --git a/src/datavis3d/utils/texturehelper.cpp b/src/datavis3d/utils/texturehelper.cpp
index c0083b15..c21a09ab 100644
--- a/src/datavis3d/utils/texturehelper.cpp
+++ b/src/datavis3d/utils/texturehelper.cpp
@@ -166,7 +166,11 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf
// Create render buffer
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
+#if !defined(QT_OPENGL_ES_2)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.width(), size.height());
+#else
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.width(), size.height());
+#endif
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// Create frame buffer
@@ -191,6 +195,7 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf
return textureid;
}
+#if !defined(QT_OPENGL_ES_2)
GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize)
{
GLuint depthtextureid;
@@ -231,6 +236,7 @@ GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer,
return depthtextureid;
}
+#endif
void TextureHelper::deleteTexture(const GLuint *texture)
{
@@ -284,7 +290,11 @@ void TextureHelper::convertToGLFormatHelper(QImage &dstImage, const QImage &srcI
const uint *p = (const uint*) srcImage.scanLine(srcImage.height() - 1);
uint *q = (uint*) dstImage.scanLine(0);
+#if !defined(QT_OPENGL_ES_2)
if (texture_format == GL_BGRA) {
+#else
+ if (texture_format == GL_BGRA8_EXT) {
+#endif
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
// mirror + swizzle
for (int i=0; i < height; ++i) {
@@ -335,7 +345,11 @@ void TextureHelper::convertToGLFormatHelper(QImage &dstImage, const QImage &srcI
QRgb TextureHelper::qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format)
{
+#if !defined(QT_OPENGL_ES_2)
if (texture_format == GL_BGRA) {
+#else
+ if (texture_format == GL_BGRA8_EXT) {
+#endif
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
return ((src_pixel << 24) & 0xff000000)
| ((src_pixel >> 24) & 0x000000ff)
diff --git a/src/datavis3d/utils/texturehelper_p.h b/src/datavis3d/utils/texturehelper_p.h
index 4b420fa4..4ea5ada3 100644
--- a/src/datavis3d/utils/texturehelper_p.h
+++ b/src/datavis3d/utils/texturehelper_p.h
@@ -72,8 +72,10 @@ class TextureHelper : protected QOpenGLFunctions
GLuint createSelectionBuffer(const QSize &size, GLuint &texture, GLuint &depthTexture);
// Returns selection texture and inserts generated framebuffers to framebuffer parameters
GLuint createSelectionTexture(const QSize &size, GLuint &frameBuffer, GLuint &depthBuffer);
+#if !defined(QT_OPENGL_ES_2)
// Returns depth texture and inserts generated framebuffer to parameter
GLuint createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize = 1);
+#endif
void deleteTexture(const GLuint *texture);
private: