commit 5f58bfbadbd8acff6f32fef8ae2bbfe61627f283
parent 030aee3a156b70a64c4865a9711cab7d86648632
Author: falkTX <falktx@falktx.com>
Date: Mon, 17 May 2021 22:56:42 +0100
Improve backwards compatibility of OpenGLImage
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/dgl/ImageBase.hpp b/dgl/ImageBase.hpp
@@ -25,6 +25,7 @@ START_NAMESPACE_DGL
enum ImageFormat {
kImageFormatNull,
+ kImageFormatGrayscale,
kImageFormatBGR,
kImageFormatBGRA,
kImageFormatRGB,
diff --git a/dgl/OpenGL.hpp b/dgl/OpenGL.hpp
@@ -118,12 +118,34 @@ struct OpenGLGraphicsContext : GraphicsContext
// -----------------------------------------------------------------------
static inline
+ImageFormat asDISTRHOImageFormat(const GLenum format)
+{
+ switch (format)
+ {
+ case GL_LUMINANCE:
+ return kImageFormatGrayscale;
+ case GL_BGR:
+ return kImageFormatBGR;
+ case GL_BGRA:
+ return kImageFormatBGRA;
+ case GL_RGB:
+ return kImageFormatRGB;
+ case GL_RGBA:
+ return kImageFormatRGBA;
+ }
+
+ return kImageFormatNull;
+}
+
+static inline
GLenum asOpenGLImageFormat(const ImageFormat format)
{
switch (format)
{
case kImageFormatNull:
break;
+ case kImageFormatGrayscale:
+ return GL_LUMINANCE;
case kImageFormatBGR:
return GL_BGR;
case kImageFormatBGRA:
@@ -199,32 +221,51 @@ public:
*/
OpenGLImage& operator=(const OpenGLImage& image) noexcept;
+ // FIXME this should not be needed
+ inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA)
+ { loadFromMemory(rawData, Size<uint>(w, h), format); };
+ inline void draw(const GraphicsContext& context)
+ { drawAt(context, Point<int>(0, 0)); };
+ inline void drawAt(const GraphicsContext& context, int x, int y)
+ { drawAt(context, Point<int>(x, y)); };
+
+ /**
+ Constructor using raw image data, specifying an OpenGL image format.
+ @note @a rawData must remain valid for the lifetime of this Image.
+ DEPRECATED This constructor uses OpenGL image format instead of DISTRHO one.
+ */
+ DISTRHO_DEPRECATED_BY("OpenGLImage(const char*,uint,uint,ImageFormat")
+ explicit OpenGLImage(const char* rawData, uint width, uint height, GLenum format);
+
+ /**
+ Constructor using raw image data, specifying an OpenGL image format.
+ @note @a rawData must remain valid for the lifetime of this Image.
+ DEPRECATED This constructor uses OpenGL image format instead of DISTRHO one.
+ */
+ DISTRHO_DEPRECATED_BY("OpenGLImage(const char*,const Size<uint>&,ImageFormat")
+ explicit OpenGLImage(const char* rawData, const Size<uint>& size, GLenum format);
+
/**
Draw this image at (0, 0) point using the current OpenGL context.
+ DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
*/
DISTRHO_DEPRECATED_BY("draw(const GraphicsContext&)")
void draw();
/**
Draw this image at (x, y) point using the current OpenGL context.
+ DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
*/
DISTRHO_DEPRECATED_BY("drawAt(const GraphicsContext&,int,int)")
void drawAt(const int x, const int y);
/**
Draw this image at position @a pos using the current OpenGL context.
+ DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
*/
DISTRHO_DEPRECATED_BY("drawAt(const GraphicsContext&,const Point<int>&)")
void drawAt(const Point<int>& pos);
- // FIXME this should not be needed
- inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format)
- { loadFromMemory(rawData, Size<uint>(w, h), format); };
- inline void draw(const GraphicsContext& context)
- { drawAt(context, Point<int>(0, 0)); };
- inline void drawAt(const GraphicsContext& context, int x, int y)
- { drawAt(context, Point<int>(x, y)); };
-
/**
Get the image type.
DEPRECATED Type is always assumed to be GL_UNSIGNED_BYTE.
diff --git a/dgl/src/Cairo.cpp b/dgl/src/Cairo.cpp
@@ -280,6 +280,8 @@ static cairo_format_t asCairoImageFormat(const ImageFormat format)
{
case kImageFormatNull:
break;
+ case kImageFormatGrayscale:
+ return CAIRO_FORMAT_A8;
case kImageFormatBGR:
case kImageFormatRGB:
return CAIRO_FORMAT_RGB24;
@@ -366,6 +368,10 @@ void CairoImage::loadFromMemory(const char* const rdata, const Size<uint>& s, co
{
case kImageFormatNull:
break;
+ case kImageFormatGrayscale:
+ // Grayscale to A8
+ // TODO
+ break;
case kImageFormatBGR:
// BGR8 to CAIRO_FORMAT_RGB24
for (uint h = 0; h < height; ++h)
diff --git a/dgl/src/OpenGL.cpp b/dgl/src/OpenGL.cpp
@@ -401,6 +401,24 @@ OpenGLImage& OpenGLImage::operator=(const OpenGLImage& image) noexcept
}
// deprecated calls
+OpenGLImage::OpenGLImage(const char* const rawData, const uint width, const uint height, const GLenum format)
+ : ImageBase(rawData, width, height, asDISTRHOImageFormat(format)),
+ textureId(0),
+ setupCalled(false)
+{
+ glGenTextures(1, &textureId);
+ DISTRHO_SAFE_ASSERT(textureId != 0);
+}
+
+OpenGLImage::OpenGLImage(const char* const rawData, const Size<uint>& size, const GLenum format)
+ : ImageBase(rawData, size, asDISTRHOImageFormat(format)),
+ textureId(0),
+ setupCalled(false)
+{
+ glGenTextures(1, &textureId);
+ DISTRHO_SAFE_ASSERT(textureId != 0);
+}
+
void OpenGLImage::draw()
{
drawOpenGLImage(*this, Point<int>(0, 0), textureId, setupCalled);