From 0f34fd437efb936ef29ac91186321aa7251fbfb1 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 23 May 2023 11:22:33 +0200 Subject: Massive changes in initial port away from Qt. --- colormap.cpp | 76 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'colormap.cpp') diff --git a/colormap.cpp b/colormap.cpp index 961f475..08a3d61 100644 --- a/colormap.cpp +++ b/colormap.cpp @@ -1,15 +1,12 @@ #include "colormap.h" #include - -#include -#include +#include class ColormapTexture - : public QSGDynamicTexture { public: - ColormapTexture(const std::vector *cmap, + ColormapTexture(const std::vector &cmap, Colormap::Orientation orientation = Colormap::Horizontal); ~ColormapTexture(); @@ -19,41 +16,42 @@ public: bool updateTexture(); int textureId() const { return m_texture; } - QSize textureSize() const { return m_size; } + size_t width() const { return m_width; } + size_t height() const { return m_height; } void setOrientation(Colormap::Orientation orientation); private: - QOpenGLFunctions gl; - Colormap::Orientation m_orientation; - QSize m_size; + // QSize m_size; + size_t m_width, m_height; GLuint m_texture; - const std::vector *m_cmap; + const std::vector &m_cmap; }; -ColormapTexture::ColormapTexture(const std::vector *cmap, +ColormapTexture::ColormapTexture(const std::vector &cmap, Colormap::Orientation orientation) - : gl(QOpenGLContext::currentContext()) - , m_cmap(cmap) + : m_cmap(cmap) + , m_width(0) + , m_height(0) { // Setup OpenGL texture - gl.glGenTextures(1, &m_texture); - gl.glBindTexture(GL_TEXTURE_2D, m_texture); - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + 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); } ColormapTexture::~ColormapTexture() { - gl.glDeleteTextures(1, &m_texture); + glDeleteTextures(1, &m_texture); } void ColormapTexture::bind() { - gl.glBindTexture(GL_TEXTURE_2D, m_texture); + glBindTexture(GL_TEXTURE_2D, m_texture); } void ColormapTexture::setOrientation(Colormap::Orientation orientation) @@ -70,35 +68,33 @@ bool ColormapTexture::updateTexture() { switch (m_orientation) { case Colormap::Horizontal: - m_size.setWidth(m_cmap->size() / 3); - m_size.setHeight(1); + m_width = m_cmap.size() / 3; + m_height = 1; break; case Colormap::Vertical: - m_size.setWidth(1); - m_size.setHeight(m_cmap->size() / 3); + m_width = 1; + m_height = m_cmap.size() / 3; break; } - gl.glBindTexture(GL_TEXTURE_2D, m_texture); - gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_size.width(), m_size.height(), - 0, GL_RGB, GL_FLOAT, m_cmap->data()); + glBindTexture(GL_TEXTURE_2D, m_texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, + 0, GL_RGB, GL_FLOAT, m_cmap.data()); return true; } -Colormap::Colormap(QQuickItem *parent) - : QQuickItem(parent) - , m_texture(0) - , m_shouldUpdateTexture(false) +Colormap::Colormap() + : m_shouldUpdateTexture(false) , m_orientation(Colormap::Horizontal) { - setFlag(QQuickItem::ItemHasContents); } Colormap::~Colormap() { - if (m_texture) { - delete m_texture; - } +} + +void Colormap::update() +{ } static void reverseCMap(std::vector &cmap) @@ -129,7 +125,7 @@ void Colormap::setOrientation(Colormap::Orientation orientation) update(); } -void Colormap::setColorScale(const ColorScale *scale) +void Colormap::setColorScale(std::shared_ptr scale) { m_cmap.resize(SAMPLES * 3); scale->sample(SAMPLES, m_cmap.data()); @@ -137,22 +133,21 @@ void Colormap::setColorScale(const ColorScale *scale) reverseCMap(m_cmap); } - emit colorScaleChanged(scale); + colorScaleChanged(scale); m_shouldUpdateTexture = true; update(); } +/* QSGNode *Colormap::newSceneGraph() { QSGSimpleTextureNode *node = new QSGSimpleTextureNode; - m_texture = new ColormapTexture(&m_cmap); + m_texture = new ColormapTexture(m_cmap); node->setTexture(m_texture); node->setOwnsTexture(false); - - const QSize &texSize = m_texture->textureSize(); - node->setSourceRect(0, 0, texSize.width(), texSize.height()); + node->setSourceRect(0, 0, m_texture->width(), m_texture->height()); return node; } @@ -177,3 +172,4 @@ QSGNode *Colormap::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) return root; } +*/ -- cgit v1.2.3