aboutsummaryrefslogtreecommitdiff
path: root/voronoisplat.h
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-12-19 22:11:33 +0100
committerSamuel Fadel <samuelfadel@gmail.com>2015-12-19 22:11:33 +0100
commit841ede5c34a5cb001b540ed13a8439dc8df7d2a9 (patch)
tree11970d698ded9c6353895eca37ca662241edda4b /voronoisplat.h
parente20c03905d6f8418963bd3ce63040e2fe571a6da (diff)
Experimenting using VoronoiSplat as a texture.
Diffstat (limited to 'voronoisplat.h')
-rw-r--r--voronoisplat.h91
1 files changed, 23 insertions, 68 deletions
diff --git a/voronoisplat.h b/voronoisplat.h
index 5913218..78dfd3e 100644
--- a/voronoisplat.h
+++ b/voronoisplat.h
@@ -1,26 +1,31 @@
#ifndef VORONOISPLAT_H
#define VORONOISPLAT_H
-#include <QQuickFramebufferObject>
+#include <QSGDynamicTexture>
#include <QOpenGLFunctions>
-#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <armadillo>
#include "colorscale.h"
-class VoronoiSplat; // defined after this class
-
-class VoronoiSplatRenderer
- : public QQuickFramebufferObject::Renderer
+class VoronoiSplatTexture
+ : public QSGDynamicTexture
{
public:
// 'size' must be square (and power of 2)
- VoronoiSplatRenderer(const QSize &size);
- ~VoronoiSplatRenderer();
+ VoronoiSplatTexture(const QSize &size);
+ virtual ~VoronoiSplatTexture();
+
+ void bind();
- void synchronize(QQuickFramebufferObject *item);
+ // When true is returned, should probably call resetOpenGLState() on window
+ bool updateTexture();
+
+ bool hasAlphaChannel() const { return true; }
+ bool hasMipmaps() const { return false; }
+ int textureId() const { return m_tex; }
+ QSize textureSize() const { return m_size; }
// 'points' should be a 2D points matrix (each point in a row)
void setSites(const arma::mat &points);
@@ -29,79 +34,29 @@ public:
void setValues(const arma::vec &values);
// Set colormap data based on the given color scale;
- void setColorMap(const ColorScale *scale);
-
- QOpenGLFramebufferObject *createFramebufferObject(const QSize &size);
- void render();
+ void setColormap(const ColorScale *scale);
private:
void setupShaders();
void setupVAOs();
void setupTextures();
- void copyPoints(const arma::mat &points);
+
+ void updateSites();
+ void updateValues();
+ void updateColormap();
void computeDT();
- VoronoiSplat *m_item;
QOpenGLFunctions gl;
QOpenGLShaderProgram *m_program1, *m_program2;
+ GLuint m_FBO;
GLuint m_VBOs[3];
- GLuint m_textures[2], m_colorMapTex;
+ GLuint m_textures[2], m_colormapTex, m_tex;
QOpenGLVertexArrayObject m_sitesVAO, m_2ndPassVAO;
- std::vector<float> m_sites, m_values;
+ std::vector<float> m_sites, m_values, m_cmap;
QSize m_size;
-};
-
-class VoronoiSplat
- : public QQuickFramebufferObject
-{
- Q_OBJECT
-public:
- VoronoiSplat(QQuickItem *parent = 0);
- Renderer *createRenderer() const;
-
- const arma::mat &points() const { return m_points; }
- const arma::vec &values() const { return m_values; }
- const ColorScale *colorScale() const { return m_colorScale; }
-
- bool colorScaleUpdated() const { return m_colorScaleUpdated; }
- bool pointsUpdated() const { return m_pointsUpdated; }
- bool valuesUpdated() const { return m_valuesUpdated; }
-
-public slots:
- void setColorScale(const ColorScale *scale)
- {
- m_colorScale = scale;
- m_colorScaleUpdated = true;
- update();
- }
- void setPoints(const arma::mat &points)
- {
- m_points = points;
- m_pointsUpdated = true;
- update();
- }
-
- void setValues(const arma::vec &values)
- {
- m_values = values;
- m_valuesUpdated = true;
- update();
- }
-
- void setUpdated(bool updated)
- {
- m_colorScaleUpdated = updated;
- m_pointsUpdated = updated;
- m_valuesUpdated = updated;
- }
-
-private:
- bool m_colorScaleUpdated, m_pointsUpdated, m_valuesUpdated;
- const ColorScale *m_colorScale;
- arma::mat m_points;
- arma::vec m_values;
+ bool m_sitesUpdated, m_valuesUpdated, m_colormapUpdated;
};
#endif // VORONOISPLAT_H