aboutsummaryrefslogtreecommitdiff
path: root/colormap.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2023-06-04 13:02:14 +0200
committerSamuel Fadel <samuel@nihil.ws>2023-06-04 13:02:14 +0200
commitfb23c8d47f6dcef429423256d8dddcc0f7184fc4 (patch)
tree34e0032f28df5807e4abd90d6b1b4baad24d2991 /colormap.cpp
parent0f34fd437efb936ef29ac91186321aa7251fbfb1 (diff)
Further advances in nuklear port.
Rendering now looks similar to Qt version, needs a few tweaks: * Proper multisampling * Background Missing features: * Barcharts * Interactivity (e.g. brushing/linking in all objects) * History view of interactions
Diffstat (limited to 'colormap.cpp')
-rw-r--r--colormap.cpp117
1 files changed, 18 insertions, 99 deletions
diff --git a/colormap.cpp b/colormap.cpp
index 08a3d61..0a9b4cc 100644
--- a/colormap.cpp
+++ b/colormap.cpp
@@ -3,69 +3,38 @@
#include <algorithm>
#include <glad/gl.h>
-class ColormapTexture
-{
-public:
- ColormapTexture(const std::vector<float> &cmap,
- Colormap::Orientation orientation = Colormap::Horizontal);
- ~ColormapTexture();
-
- bool hasAlphaChannel() const { return false; }
- bool hasMipmaps() const { return false; }
- void bind();
- bool updateTexture();
-
- int textureId() const { return m_texture; }
- size_t width() const { return m_width; }
- size_t height() const { return m_height; }
-
- void setOrientation(Colormap::Orientation orientation);
-
-private:
- Colormap::Orientation m_orientation;
- // QSize m_size;
- size_t m_width, m_height;
- GLuint m_texture;
- const std::vector<float> &m_cmap;
-};
-
-ColormapTexture::ColormapTexture(const std::vector<float> &cmap,
- Colormap::Orientation orientation)
- : m_cmap(cmap)
- , m_width(0)
+Colormap::Colormap()
+ : m_width(0)
, m_height(0)
+ , m_shouldUpdateTexture(false)
+ , m_orientation(Colormap::Horizontal)
{
- // Setup OpenGL texture
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- setOrientation(orientation);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
-ColormapTexture::~ColormapTexture()
+Colormap::~Colormap()
{
glDeleteTextures(1, &m_texture);
}
-void ColormapTexture::bind()
+void Colormap::update()
{
- glBindTexture(GL_TEXTURE_2D, m_texture);
+ if (m_shouldUpdateTexture) {
+ updateTexture();
+ }
}
-void ColormapTexture::setOrientation(Colormap::Orientation orientation)
+void Colormap::updateTexture()
{
- if (m_orientation == orientation) {
+ if (m_cmap.empty()) {
return;
}
- m_orientation = orientation;
- updateTexture();
-}
-
-bool ColormapTexture::updateTexture()
-{
switch (m_orientation) {
case Colormap::Horizontal:
m_width = m_cmap.size() / 3;
@@ -78,23 +47,8 @@ bool ColormapTexture::updateTexture()
}
glBindTexture(GL_TEXTURE_2D, m_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height,
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, m_width, m_height,
0, GL_RGB, GL_FLOAT, m_cmap.data());
- return true;
-}
-
-Colormap::Colormap()
- : m_shouldUpdateTexture(false)
- , m_orientation(Colormap::Horizontal)
-{
-}
-
-Colormap::~Colormap()
-{
-}
-
-void Colormap::update()
-{
}
static void reverseCMap(std::vector<float> &cmap)
@@ -110,9 +64,9 @@ static void reverseCMap(std::vector<float> &cmap)
}
}
-void Colormap::setOrientation(Colormap::Orientation orientation)
+void Colormap::setOrientation(Colormap::Orientation _orientation)
{
- if (m_orientation == orientation) {
+ if (m_orientation == _orientation) {
return;
}
@@ -120,8 +74,8 @@ void Colormap::setOrientation(Colormap::Orientation orientation)
reverseCMap(m_cmap);
}
- m_orientation = orientation;
- m_shouldUpdateOrientation = true;
+ m_orientation = _orientation;
+ m_shouldUpdateTexture = true;
update();
}
@@ -138,38 +92,3 @@ void Colormap::setColorScale(std::shared_ptr<const ColorScale> scale)
m_shouldUpdateTexture = true;
update();
}
-
-/*
-QSGNode *Colormap::newSceneGraph()
-{
- QSGSimpleTextureNode *node = new QSGSimpleTextureNode;
- m_texture = new ColormapTexture(m_cmap);
-
- node->setTexture(m_texture);
- node->setOwnsTexture(false);
- node->setSourceRect(0, 0, m_texture->width(), m_texture->height());
-
- return node;
-}
-
-QSGNode *Colormap::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
-{
- QSGNode *root = oldNode ? oldNode : newSceneGraph();
-
- QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(root);
- node->setRect(x(), y(), width(), height());
-
- ColormapTexture *texture = static_cast<ColormapTexture *>(m_texture);
- if (m_shouldUpdateOrientation) {
- texture->setOrientation(m_orientation);
- m_shouldUpdateOrientation = false;
- }
-
- if (m_shouldUpdateTexture) {
- texture->updateTexture();
- m_shouldUpdateTexture = false;
- }
-
- return root;
-}
-*/