Refractor upload to OpenGL
This commit is contained in:
+22
-15
@@ -7,6 +7,23 @@
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#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)
|
||||
{
|
||||
int page = scrollBar->pageStep();
|
||||
@@ -43,28 +60,18 @@ void ImageWidget::setImage(RawImage *image)
|
||||
m_imgWidth = image->width();
|
||||
m_imgHeight = image->height();
|
||||
|
||||
const RawImageType &rawImageType = rawImageTypes[image->type()];
|
||||
|
||||
m_image->destroy();
|
||||
m_image->setFormat(QOpenGLTexture::R16_UNorm);
|
||||
m_image->setFormat(rawImageType.textureFormat);
|
||||
m_image->setSize(image->width(), image->height());
|
||||
m_image->allocateStorage();
|
||||
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
||||
m_image->setWrapMode(QOpenGLTexture::ClampToBorder);
|
||||
m_image->setBorderColor(0, 0, 0, 0);
|
||||
switch(image->type())
|
||||
{
|
||||
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->setData(0, rawImageType.pixelFormat, rawImageType.dataType, image->data(), m_transferOptions.get());
|
||||
m_image->generateMipMaps();
|
||||
m_bwImg = true;
|
||||
m_bwImg = rawImageType.bw;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user