summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2014-03-31 10:10:03 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-03-31 10:17:27 +0300
commit25f48fc046bbce83abeeef0a6081de9f5efcd6d7 (patch)
treea65f608827740fc5a9aa5493547f435dfd18afac
parentfffa26dc1470ad6562e390133314fc149134b8e5 (diff)
Row/colun selection using axis labels, part 1
Task-number: QTRD-2981 + Bars done + Scatter done (= no label selection) - Surface to be done Change-Id: Icd352e40ad6d0ada76380f3dba742f280fd278b3 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp228
-rw-r--r--src/datavisualization/engine/bars3drenderer_p.h8
-rw-r--r--src/datavisualization/engine/drawer.cpp25
-rw-r--r--src/datavisualization/engine/drawer_p.h4
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp34
-rw-r--r--src/datavisualization/engine/scatter3drenderer_p.h4
-rw-r--r--src/datavisualization/engine/shaders/plainColor.frag5
-rw-r--r--src/datavisualization/global/datavisualizationglobal_p.h7
-rw-r--r--src/datavisualization/input/q3dinputhandler.cpp7
-rw-r--r--src/datavisualization/utils/texturehelper.cpp5
-rw-r--r--src/datavisualization/utils/utils.cpp7
-rw-r--r--src/datavisualization/utils/utils_p.h2
12 files changed, 187 insertions, 149 deletions
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index b928e5f0..6d54b190 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -825,6 +825,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
bool rowMode = m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionRow);
+ GLfloat rowScaleFactor = m_rowWidth / m_scaleFactor;
+ GLfloat columnScaleFactor = m_columnDepth / m_scaleFactor;
+
+ BarRenderItem *selectedBar(0);
+
#if !defined(QT_OPENGL_ES_2)
if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) {
// Render scene into a depth texture for using with shadow mapping
@@ -982,39 +987,26 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
MVPMatrix = projectionViewMatrix * modelMatrix;
- QVector3D barColor = QVector3D(GLfloat(row) / 255.0f,
+ QVector4D barColor = QVector4D(GLfloat(row) / 255.0f,
GLfloat(bar) / 255.0f,
- GLfloat(series) / 255.0f);
+ GLfloat(series) / 255.0f,
+ itemAlpha);
m_selectionShader->setUniformValue(m_selectionShader->MVP(), MVPMatrix);
m_selectionShader->setUniformValue(m_selectionShader->color(), barColor);
- // 1st attribute buffer : vertices
- glEnableVertexAttribArray(m_selectionShader->posAtt());
- glBindBuffer(GL_ARRAY_BUFFER, barObj->vertexBuf());
- glVertexAttribPointer(m_selectionShader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0,
- (void *)0);
-
- // Index buffer
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, barObj->elementBuf());
-
- // Draw the triangles
- glDrawElements(GL_TRIANGLES, barObj->indexCount(), GL_UNSIGNED_SHORT,
- (void *)0);
-
- // Free buffers
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glDisableVertexAttribArray(m_selectionShader->posAtt());
+ m_drawer->drawSelectionObject(m_selectionShader, barObj);
}
}
seriesPos += m_seriesStep;
}
+ glCullFace(GL_BACK);
+ drawLabels(true, activeCamera, viewMatrix, projectionMatrix, rowScaleFactor,
+ columnScaleFactor, false, selectedBar);
glEnable(GL_DITHER);
// Read color under cursor
- QVector3D clickedColor = Utils::getSelection(m_inputPosition,
+ QVector4D clickedColor = Utils::getSelection(m_inputPosition,
m_viewport.height());
m_clickedPosition = selectionColorToArrayPosition(clickedColor);
m_clickedSeries = selectionColorToSeries(clickedColor);
@@ -1097,7 +1089,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
GLfloat adjustedHighlightStrength = m_cachedTheme->highlightLightStrength() / 10.0f;
bool barSelectionFound = false;
- BarRenderItem *selectedBar(0);
QVector3D baseColor;
QVector3D barColor;
@@ -1331,9 +1322,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
glCullFace(GL_BACK);
// Draw background
- GLfloat rowScaleFactor = m_rowWidth / m_scaleFactor;
- GLfloat columnScaleFactor = m_columnDepth / m_scaleFactor;
-
if (m_cachedTheme->isBackgroundEnabled() && m_backgroundObj) {
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
@@ -1654,75 +1642,100 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
}
}
}
+ drawLabels(false, activeCamera, viewMatrix, projectionMatrix, rowScaleFactor,
+ columnScaleFactor, barSelectionFound, selectedBar);
- // Bind label shader
- m_labelShader->bind();
+ // Release shader
+ glUseProgram(0);
+ m_selectionDirty = false;
+}
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_POLYGON_OFFSET_FILL);
+void Bars3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix,
+ GLfloat rowScaleFactor, GLfloat columnScaleFactor,
+ bool barSelectionFound, BarRenderItem *selectedBar) {
+ ShaderHelper *shader = 0;
+ GLfloat alphaForRowSelection = labelRowAlpha / 255.0f;
+ GLfloat alphaForColumnSelection = labelColumnAlpha / 255.0f;
+ if (drawSelection) {
+ shader = m_selectionShader;
+ // m_selectionShader is already bound
+ } else {
+ shader = m_labelShader;
+ shader->bind();
- // Y Labels
- int labelNbr = 0;
- int labelCount = m_axisCacheY.labelCount();
- GLfloat labelMarginXTrans = labelMargin;
- GLfloat labelMarginZTrans = labelMargin;
- GLfloat labelXTrans = rowScaleFactor;
- GLfloat labelZTrans = columnScaleFactor;
- QVector3D backLabelRotation(0.0f, -90.0f, 0.0f);
- QVector3D sideLabelRotation(0.0f, 0.0f, 0.0f);
- Qt::AlignmentFlag backAlignment = Qt::AlignLeft;
- Qt::AlignmentFlag sideAlignment = Qt::AlignLeft;
- if (!m_xFlipped) {
- labelXTrans = -labelXTrans;
- labelMarginXTrans = -labelMargin;
- backLabelRotation.setY(90.0f);
- sideAlignment = Qt::AlignRight;
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- if (m_zFlipped) {
- labelZTrans = -labelZTrans;
- labelMarginZTrans = -labelMargin;
- backAlignment = Qt::AlignRight;
- sideLabelRotation.setY(180.f);
- }
- QVector3D backLabelTrans = QVector3D(labelXTrans, 0.0f,
- labelZTrans + labelMarginZTrans);
- QVector3D sideLabelTrans = QVector3D(-labelXTrans - labelMarginXTrans,
- 0.0f, -labelZTrans);
-
- for (int i = 0; i < labelCount; i++) {
- if (m_axisCacheY.labelItems().size() > labelNbr) {
- backLabelTrans.setY(m_axisCacheY.labelPosition(i));
- sideLabelTrans.setY(backLabelTrans.y());
- glPolygonOffset(GLfloat(i) / -10.0f, 1.0f);
-
- const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr);
-
- // Back wall
- m_dummyBarRenderItem.setTranslation(backLabelTrans);
- m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
- zeroVector, backLabelRotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, backAlignment);
+ glEnable(GL_POLYGON_OFFSET_FILL);
- // Side wall
- m_dummyBarRenderItem.setTranslation(sideLabelTrans);
- m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
- zeroVector, sideLabelRotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, sideAlignment);
+ // Y Labels
+ if (!drawSelection) {
+ int labelNbr = 0;
+ int labelCount = m_axisCacheY.labelCount();
+ GLfloat labelMarginXTrans = labelMargin;
+ GLfloat labelMarginZTrans = labelMargin;
+ GLfloat labelXTrans = rowScaleFactor;
+ GLfloat labelZTrans = columnScaleFactor;
+ QVector3D backLabelRotation(0.0f, -90.0f, 0.0f);
+ QVector3D sideLabelRotation(0.0f, 0.0f, 0.0f);
+ Qt::AlignmentFlag backAlignment = Qt::AlignLeft;
+ Qt::AlignmentFlag sideAlignment = Qt::AlignLeft;
+ if (!m_xFlipped) {
+ labelXTrans = -labelXTrans;
+ labelMarginXTrans = -labelMargin;
+ backLabelRotation.setY(90.0f);
+ sideAlignment = Qt::AlignRight;
+ }
+ if (m_zFlipped) {
+ labelZTrans = -labelZTrans;
+ labelMarginZTrans = -labelMargin;
+ backAlignment = Qt::AlignRight;
+ sideLabelRotation.setY(180.f);
+ }
+ QVector3D backLabelTrans = QVector3D(labelXTrans, 0.0f,
+ labelZTrans + labelMarginZTrans);
+ QVector3D sideLabelTrans = QVector3D(-labelXTrans - labelMarginXTrans,
+ 0.0f, -labelZTrans);
+
+ for (int i = 0; i < labelCount; i++) {
+ if (m_axisCacheY.labelItems().size() > labelNbr) {
+ backLabelTrans.setY(m_axisCacheY.labelPosition(i));
+ sideLabelTrans.setY(backLabelTrans.y());
+
+ glPolygonOffset(GLfloat(i) / -10.0f, 1.0f);
+
+ const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr);
+
+ // Back wall
+ m_dummyBarRenderItem.setTranslation(backLabelTrans);
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
+ zeroVector, backLabelRotation, 0, m_cachedSelectionMode,
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, backAlignment);
+
+ // Side wall
+ m_dummyBarRenderItem.setTranslation(sideLabelTrans);
+ m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
+ zeroVector, sideLabelRotation, 0, m_cachedSelectionMode,
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, sideAlignment);
+ }
+ labelNbr++;
}
- labelNbr++;
}
+ // Z labels
// Calculate the positions for row and column labels and store them
GLfloat labelYAdjustment = 0.005f;
GLfloat scaledRowWidth = rowScaleFactor;
GLfloat scaledColumnDepth = columnScaleFactor;
GLfloat colPosValue = scaledRowWidth + labelMargin;
GLfloat rowPosValue = scaledColumnDepth + labelMargin;
+ GLfloat rowPos = 0.0f;
+ GLfloat colPos = 0.0f;
QVector3D labelRotation(-90.0f, 0.0f, 0.0f);
if (m_zFlipped)
labelRotation.setY(180.0f);
@@ -1754,10 +1767,16 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
m_dummyBarRenderItem.setTranslation(labelPos);
const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(row);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(row / 255.0f, 0.0f, 0.0f, alphaForRowSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
zeroVector, labelRotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, alignment, m_cachedIsSlicingActivated);
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, alignment,
+ false, drawSelection);
}
}
labelRotation = QVector3D(-90.0f, 90.0f, 0.0f);
@@ -1771,6 +1790,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
labelRotation.setZ(180.0f);
}
+ // X labels
alignment = m_zFlipped ? Qt::AlignRight : Qt::AlignLeft;
for (int column = 0; column != m_cachedColumnCount; column++) {
if (m_axisCacheX.labelItems().size() > column) {
@@ -1791,10 +1811,16 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
m_dummyBarRenderItem.setTranslation(labelPos);
const LabelItem &axisLabelItem = *m_axisCacheX.labelItems().at(column);
+ if (drawSelection) {
+ QVector4D labelColor = QVector4D(0.0f, column / 255.0f, 0.0f,
+ alphaForColumnSelection);
+ shader->setUniformValue(shader->color(), labelColor);
+ }
+
m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix,
zeroVector, labelRotation, 0, m_cachedSelectionMode,
- m_labelShader, m_labelObj, activeCamera,
- true, true, Drawer::LabelMid, alignment);
+ shader, m_labelObj, activeCamera,
+ true, true, Drawer::LabelMid, alignment, false, drawSelection);
}
}
@@ -1859,7 +1885,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
m_drawer->drawLabel(*selectedBar, labelItem, viewMatrix, projectionMatrix,
zeroVector, zeroVector, selectedBar->height(),
- m_cachedSelectionMode, m_labelShader,
+ m_cachedSelectionMode, shader,
m_labelObj, activeCamera, true, false);
// Reset label update flag; they should have been updated when we get here
@@ -1870,13 +1896,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
m_selectedBar = 0;
}
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
-
- // Release shader
- glUseProgram(0);
-
- m_selectionDirty = false;
+ if (!drawSelection) {
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_BLEND);
+ }
}
void Bars3DRenderer::updateMultiSeriesScaling(bool uniform)
@@ -2128,19 +2151,34 @@ Bars3DController::SelectionType Bars3DRenderer::isSelected(int row, int bar, int
return isSelectedType;
}
-QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector3D &selectionColor)
+QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector4D &selectionColor)
{
QPoint position;
- if (selectionColor == selectionSkipColor) {
+ if (selectionColor == selectionSkipColor
+ || (selectionColor.w() == labelRowAlpha
+ && !m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionRow))
+ || (selectionColor.w() == labelColumnAlpha
+ && !m_cachedSelectionMode.testFlag(QAbstract3DGraph::SelectionColumn))) {
position = Bars3DController::invalidSelectionPosition();
- } else {
+ } else if (selectionColor.w() == itemAlpha) {
+ // Normal selection item
position = QPoint(int(selectionColor.x() + int(m_axisCacheZ.min())),
int(selectionColor.y()) + int(m_axisCacheX.min()));
+ } else if (selectionColor.w() == labelRowAlpha) {
+ // Row selection
+ // Use column from previous selection in case we have row + column mode
+ GLint previousCol = qMax(0, m_selectedBarPos.y()); // Use 0 if previous is invalid
+ position = QPoint(int(selectionColor.x() + int(m_axisCacheZ.min())), previousCol);
+ } else if (selectionColor.w() == labelColumnAlpha) {
+ // Column selection
+ // Use row from previous selection in case we have row + column mode
+ GLint previousRow = qMax(0, m_selectedBarPos.x()); // Use 0 if previous is invalid
+ position = QPoint(previousRow, int(selectionColor.y()) + int(m_axisCacheX.min()));
}
return position;
}
-QBar3DSeries *Bars3DRenderer::selectionColorToSeries(const QVector3D &selectionColor)
+QBar3DSeries *Bars3DRenderer::selectionColorToSeries(const QVector4D &selectionColor)
{
if (selectionColor == selectionSkipColor)
return 0;
diff --git a/src/datavisualization/engine/bars3drenderer_p.h b/src/datavisualization/engine/bars3drenderer_p.h
index 2c0417e4..3e7e5178 100644
--- a/src/datavisualization/engine/bars3drenderer_p.h
+++ b/src/datavisualization/engine/bars3drenderer_p.h
@@ -143,6 +143,10 @@ private:
void drawSlicedScene();
void drawScene(GLuint defaultFboHandle);
+ void drawLabels(bool drawSelection, const Q3DCamera *activeCamera,
+ const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix,
+ GLfloat rowScaleFactor, GLfloat columnScaleFactor,
+ bool barSelectionFound, BarRenderItem *selectedBar);
void loadBackgroundMesh();
void loadGridLineMesh();
@@ -158,8 +162,8 @@ private:
void calculateSceneScalingFactors();
void calculateHeightAdjustment();
Abstract3DController::SelectionType isSelected(int row, int bar, int seriesIndex);
- QPoint selectionColorToArrayPosition(const QVector3D &selectionColor);
- QBar3DSeries *selectionColorToSeries(const QVector3D &selectionColor);
+ QPoint selectionColorToArrayPosition(const QVector4D &selectionColor);
+ QBar3DSeries *selectionColorToSeries(const QVector4D &selectionColor);
Q_DISABLE_COPY(Bars3DRenderer)
diff --git a/src/datavisualization/engine/drawer.cpp b/src/datavisualization/engine/drawer.cpp
index 38c15a58..ff48d71c 100644
--- a/src/datavisualization/engine/drawer.cpp
+++ b/src/datavisualization/engine/drawer.cpp
@@ -149,6 +149,18 @@ void Drawer::drawObject(ShaderHelper *shader, AbstractObjectHelper *object, GLui
}
}
+void Drawer::drawSelectionObject(ShaderHelper *shader, AbstractObjectHelper *object)
+{
+ glEnableVertexAttribArray(shader->posAtt());
+ glBindBuffer(GL_ARRAY_BUFFER, object->vertexBuf());
+ glVertexAttribPointer(shader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->elementBuf());
+ glDrawElements(GL_TRIANGLES, object->indexCount(), GL_UNSIGNED_SHORT, (void *)0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glDisableVertexAttribArray(shader->posAtt());
+}
+
void Drawer::drawSurfaceGrid(ShaderHelper *shader, SurfaceObject *object)
{
// 1st attribute buffer : vertices
@@ -225,7 +237,8 @@ void Drawer::drawLabel(const AbstractRenderItem &item, const LabelItem &labelIte
GLfloat itemHeight, QAbstract3DGraph::SelectionFlags mode,
ShaderHelper *shader, ObjectHelper *object,
const Q3DCamera *camera, bool useDepth, bool rotateAlong,
- LabelPosition position, Qt::AlignmentFlag alignment, bool isSlicing)
+ LabelPosition position, Qt::AlignmentFlag alignment, bool isSlicing,
+ bool isSelecting)
{
// Draw label
if (!labelItem.textureId())
@@ -379,11 +392,15 @@ void Drawer::drawLabel(const AbstractRenderItem &item, const LabelItem &labelIte
MVPMatrix = projectionmatrix * viewmatrix * modelMatrix;
- // Set shader bindings
shader->setUniformValue(shader->MVP(), MVPMatrix);
- // Draw the object
- drawObject(shader, object, labelItem.textureId());
+ if (isSelecting) {
+ // Draw the selection object
+ drawSelectionObject(shader, object);
+ } else {
+ // Draw the object
+ drawObject(shader, object, labelItem.textureId());
+ }
}
void Drawer::generateSelectionLabelTexture(Abstract3DRenderer *renderer)
diff --git a/src/datavisualization/engine/drawer_p.h b/src/datavisualization/engine/drawer_p.h
index 5d10018e..c4fb749f 100644
--- a/src/datavisualization/engine/drawer_p.h
+++ b/src/datavisualization/engine/drawer_p.h
@@ -74,6 +74,7 @@ public:
void drawObject(ShaderHelper *shader, AbstractObjectHelper *object, GLuint textureId = 0,
GLuint depthTextureId = 0);
+ void drawSelectionObject(ShaderHelper *shader, AbstractObjectHelper *object);
void drawSurfaceGrid(ShaderHelper *shader, SurfaceObject *object);
void drawPoint(ShaderHelper *shader);
void drawLine(ShaderHelper *shader);
@@ -83,7 +84,8 @@ public:
QAbstract3DGraph::SelectionFlags mode, ShaderHelper *shader, ObjectHelper *object,
const Q3DCamera *camera, bool useDepth = false, bool rotateAlong = false,
LabelPosition position = LabelOver,
- Qt::AlignmentFlag alignment = Qt::AlignCenter, bool isSlicing = false);
+ Qt::AlignmentFlag alignment = Qt::AlignCenter, bool isSlicing = false,
+ bool isSelecting = false);
void generateSelectionLabelTexture(Abstract3DRenderer *item);
void generateLabelItem(LabelItem &item, const QString &text, int widestLabel = 0);
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 909d434f..9a2522d4 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -534,41 +534,23 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
MVPMatrix = projectionViewMatrix * modelMatrix;
- QVector3D dotColor = indexToSelectionColor(dotNo);
+ QVector4D dotColor = indexToSelectionColor(dotNo);
dotColor /= 255.0f;
selectionShader->setUniformValue(selectionShader->MVP(), MVPMatrix);
selectionShader->setUniformValue(selectionShader->color(), dotColor);
- if (drawingPoints) {
+ if (drawingPoints)
m_drawer->drawPoint(selectionShader);
- } else {
- // 1st attribute buffer : vertices
- glEnableVertexAttribArray(selectionShader->posAtt());
- glBindBuffer(GL_ARRAY_BUFFER, dotObj->vertexBuf());
- glVertexAttribPointer(selectionShader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0,
- (void *)0);
-
- // Index buffer
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dotObj->elementBuf());
-
- // Draw the triangles
- glDrawElements(GL_TRIANGLES, dotObj->indexCount(), GL_UNSIGNED_SHORT,
- (void *)0);
-
- // Free buffers
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glDisableVertexAttribArray(selectionShader->posAtt());
- }
+ else
+ m_drawer->drawSelectionObject(selectionShader, dotObj);
dotNo++;
}
}
glEnable(GL_DITHER);
// Read color under cursor
- QVector3D clickedColor = Utils::getSelection(m_inputPosition,
+ QVector4D clickedColor = Utils::getSelection(m_inputPosition,
m_viewport.height());
selectionColorToSeriesAndIndex(clickedColor, m_clickedIndex, m_clickedSeries);
@@ -1739,16 +1721,16 @@ void Scatter3DRenderer::initLabelShaders(const QString &vertexShader, const QStr
m_labelShader->initialize();
}
-QVector3D Scatter3DRenderer::indexToSelectionColor(GLint index)
+QVector4D Scatter3DRenderer::indexToSelectionColor(GLint index)
{
GLubyte dotIdxRed = index & 0xff;
GLubyte dotIdxGreen = (index & 0xff00) >> 8;
GLubyte dotIdxBlue = (index & 0xff0000) >> 16;
- return QVector3D(dotIdxRed, dotIdxGreen, dotIdxBlue);
+ return QVector4D(dotIdxRed, dotIdxGreen, dotIdxBlue, 0);
}
-void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector3D &color,
+void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector4D &color,
int &index,
QAbstract3DSeries *&series)
{
diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h
index b82ff4ae..62a8de73 100644
--- a/src/datavisualization/engine/scatter3drenderer_p.h
+++ b/src/datavisualization/engine/scatter3drenderer_p.h
@@ -146,8 +146,8 @@ public slots:
void updateSelectedItem(int index, const QScatter3DSeries *series);
private:
- QVector3D indexToSelectionColor(GLint index);
- void selectionColorToSeriesAndIndex(const QVector3D &color, int &index,
+ QVector4D indexToSelectionColor(GLint index);
+ void selectionColorToSeriesAndIndex(const QVector4D &color, int &index,
QAbstract3DSeries *&series);
};
diff --git a/src/datavisualization/engine/shaders/plainColor.frag b/src/datavisualization/engine/shaders/plainColor.frag
index 099c87a1..da9ee060 100644
--- a/src/datavisualization/engine/shaders/plainColor.frag
+++ b/src/datavisualization/engine/shaders/plainColor.frag
@@ -1,7 +1,6 @@
-uniform highp vec3 color_mdl;
+uniform highp vec4 color_mdl;
void main() {
- gl_FragColor.rgb = color_mdl;
- gl_FragColor.a = 1.0;
+ gl_FragColor = color_mdl;
}
diff --git a/src/datavisualization/global/datavisualizationglobal_p.h b/src/datavisualization/global/datavisualizationglobal_p.h
index 71dc8a93..ff658be3 100644
--- a/src/datavisualization/global/datavisualizationglobal_p.h
+++ b/src/datavisualization/global/datavisualizationglobal_p.h
@@ -57,8 +57,11 @@ static const QVector3D cameraDistanceVector = QVector3D(0.0f, 0.0f, cameraDistan
static const QQuaternion identityQuaternion;
// Skip color == selection texture's background color
-static const QVector3D selectionSkipColor = QVector3D(255.0f, 255.0f, 255.0f);
-static const QVector3D invalidColorVector = QVector3D(-1.0f, -1.0f, -1.0f);
+static const QVector4D selectionSkipColor = QVector4D(255.0f, 255.0f, 255.0f, 255.0f);
+static const QVector4D invalidColorVector = QVector4D(-1.0f, -1.0f, -1.0f, -1.0f);
+static const GLfloat itemAlpha = 0.0f;
+static const GLfloat labelRowAlpha = 254.0f;
+static const GLfloat labelColumnAlpha = 255.0f;
static const GLfloat gradientTextureHeight = 1024.0f;
static const GLfloat gradientTextureWidth = 2.0f;
static const GLfloat uniformTextureHeight = 64.0f;
diff --git a/src/datavisualization/input/q3dinputhandler.cpp b/src/datavisualization/input/q3dinputhandler.cpp
index 1a197418..bcbf1014 100644
--- a/src/datavisualization/input/q3dinputhandler.cpp
+++ b/src/datavisualization/input/q3dinputhandler.cpp
@@ -94,13 +94,12 @@ void Q3DInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos
#else
if (Qt::LeftButton == event->button()) {
if (scene()->isSlicingActive()) {
- if (scene()->isPointInPrimarySubView(mousePos)) {
+ if (scene()->isPointInPrimarySubView(mousePos))
setInputView(InputViewOnPrimary);
- } else if (scene()->isPointInSecondarySubView(mousePos)) {
+ else if (scene()->isPointInSecondarySubView(mousePos))
setInputView(InputViewOnSecondary);
- } else {
+ else
setInputView(InputViewNone);
- }
} else {
// update mouse positions to prevent jumping when releasing or repressing a button
setInputPosition(mousePos);
diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp
index 52c673dc..ee1d51a6 100644
--- a/src/datavisualization/utils/texturehelper.cpp
+++ b/src/datavisualization/utils/texturehelper.cpp
@@ -108,13 +108,8 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf
glBindTexture(GL_TEXTURE_2D, textureid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-#if !defined(QT_OPENGL_ES_2)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
-#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB,
- GL_UNSIGNED_BYTE, NULL);
-#endif
glBindTexture(GL_TEXTURE_2D, 0);
// Create render buffer
diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp
index 38fa0b2a..eb84f162 100644
--- a/src/datavisualization/utils/utils.cpp
+++ b/src/datavisualization/utils/utils.cpp
@@ -126,15 +126,14 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
return image;
}
-QVector3D Utils::getSelection(QPoint mousepos, int height)
+QVector4D Utils::getSelection(QPoint mousepos, int height)
{
// This is the only one that works with OpenGL ES 2.0, so we're forced to use it
// Item count will be limited to 256*256*256
- GLubyte pixel[4] = {255, 255, 255, 0};
+ GLubyte pixel[4] = {255, 255, 255, 255};
glReadPixels(mousepos.x(), height - mousepos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
(void *)pixel);
- QVector3D selectedColor(pixel[0], pixel[1], pixel[2]);
-
+ QVector4D selectedColor(pixel[0], pixel[1], pixel[2], pixel[3]);
return selectedColor;
}
diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h
index d2c23abf..c89a299c 100644
--- a/src/datavisualization/utils/utils_p.h
+++ b/src/datavisualization/utils/utils_p.h
@@ -63,7 +63,7 @@ public:
bool labelBackground,
bool borders = false,
int maxLabelWidth = 0);
- static QVector3D getSelection(QPoint mousepos, int height);
+ static QVector4D getSelection(QPoint mousepos, int height);
static QImage getGradientImage(const QLinearGradient &gradient);
static ParamType findFormatParamType(const QString &format);