Browse Source

Improve backwards compatibility of OpenGLImage

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
5f58bfbadb
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 74 additions and 8 deletions
  1. +1
    -0
      dgl/ImageBase.hpp
  2. +49
    -8
      dgl/OpenGL.hpp
  3. +6
    -0
      dgl/src/Cairo.cpp
  4. +18
    -0
      dgl/src/OpenGL.cpp

+ 1
- 0
dgl/ImageBase.hpp View File

@@ -25,6 +25,7 @@ START_NAMESPACE_DGL

enum ImageFormat {
kImageFormatNull,
kImageFormatGrayscale,
kImageFormatBGR,
kImageFormatBGRA,
kImageFormatRGB,


+ 49
- 8
dgl/OpenGL.hpp View File

@@ -117,6 +117,26 @@ 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)
{
@@ -124,6 +144,8 @@ GLenum asOpenGLImageFormat(const ImageFormat 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.


+ 6
- 0
dgl/src/Cairo.cpp View File

@@ -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)


+ 18
- 0
dgl/src/OpenGL.cpp View File

@@ -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);


Loading…
Cancel
Save