From fb23c8d47f6dcef429423256d8dddcc0f7184fc4 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Sun, 4 Jun 2023 13:02:14 +0200 Subject: 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 --- colormap.cpp | 117 +++++++++-------------------------------------------------- 1 file changed, 18 insertions(+), 99 deletions(-) (limited to 'colormap.cpp') diff --git a/colormap.cpp b/colormap.cpp index 08a3d61..0a9b4cc 100644 --- a/colormap.cpp +++ b/colormap.cpp @@ -3,69 +3,38 @@ #include #include -class ColormapTexture -{ -public: - ColormapTexture(const std::vector &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 &m_cmap; -}; - -ColormapTexture::ColormapTexture(const std::vector &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 &cmap) @@ -110,9 +64,9 @@ static void reverseCMap(std::vector &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 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(root); - node->setRect(x(), y(), width(), height()); - - ColormapTexture *texture = static_cast(m_texture); - if (m_shouldUpdateOrientation) { - texture->setOrientation(m_orientation); - m_shouldUpdateOrientation = false; - } - - if (m_shouldUpdateTexture) { - texture->updateTexture(); - m_shouldUpdateTexture = false; - } - - return root; -} -*/ -- cgit v1.2.3