Refractor upload to OpenGL

This commit is contained in:
2021-03-25 09:33:53 +01:00
parent c1ed17dd86
commit d09bbd813b
+22 -15
View File
@@ -7,6 +7,23 @@
#include <QOpenGLFramebufferObject> #include <QOpenGLFramebufferObject>
#include <QGridLayout> #include <QGridLayout>
struct RawImageType
{
QOpenGLTexture::PixelFormat pixelFormat;
QOpenGLTexture::TextureFormat textureFormat;
QOpenGLTexture::PixelType dataType;
bool bw;
};
const RawImageType rawImageTypes[] = {
{QOpenGLTexture::Red, QOpenGLTexture::R8_UNorm, QOpenGLTexture::UInt8, true},
{QOpenGLTexture::Red, QOpenGLTexture::R16_UNorm, QOpenGLTexture::UInt16, true},
{QOpenGLTexture::Red, QOpenGLTexture::R32F, QOpenGLTexture::Float32, true},
{QOpenGLTexture::RGB, QOpenGLTexture::R8_UNorm, QOpenGLTexture::UInt8, true},
{QOpenGLTexture::RGB, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, true},
{QOpenGLTexture::RGB, QOpenGLTexture::RGB32F, QOpenGLTexture::Float32, true}
};
void setScrollRange(QScrollBar *scrollBar, int newRange) void setScrollRange(QScrollBar *scrollBar, int newRange)
{ {
int page = scrollBar->pageStep(); int page = scrollBar->pageStep();
@@ -43,28 +60,18 @@ void ImageWidget::setImage(RawImage *image)
m_imgWidth = image->width(); m_imgWidth = image->width();
m_imgHeight = image->height(); m_imgHeight = image->height();
const RawImageType &rawImageType = rawImageTypes[image->type()];
m_image->destroy(); m_image->destroy();
m_image->setFormat(QOpenGLTexture::R16_UNorm); m_image->setFormat(rawImageType.textureFormat);
m_image->setSize(image->width(), image->height()); m_image->setSize(image->width(), image->height());
m_image->allocateStorage(); m_image->allocateStorage();
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear); m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
m_image->setWrapMode(QOpenGLTexture::ClampToBorder); m_image->setWrapMode(QOpenGLTexture::ClampToBorder);
m_image->setBorderColor(0, 0, 0, 0); m_image->setBorderColor(0, 0, 0, 0);
switch(image->type()) m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, image->data(), m_transferOptions.get());
{
case RawImage::UINT8:
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt8, image->data(), m_transferOptions.get());
break;
case RawImage::UINT16:
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt16, image->data(), m_transferOptions.get());
break;
case RawImage::FLOAT32:
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::Float32, image->data(), m_transferOptions.get());
m_range = 1;
break;
}
m_image->generateMipMaps(); m_image->generateMipMaps();
m_bwImg = true; m_bwImg = rawImageType.bw;
update(); update();
} }