Add initial bits for Qt6 support
[carla.git] / source / modules / dgl / OpenGL.hpp
blob91da7e3c3908b89cd4ff7289399a290c6a696e97
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef DGL_OPENGL_HPP_INCLUDED
18 #define DGL_OPENGL_HPP_INCLUDED
20 #include "ImageBase.hpp"
21 #include "ImageBaseWidgets.hpp"
23 #include "OpenGL-include.hpp"
25 START_NAMESPACE_DGL
27 // -----------------------------------------------------------------------
29 /**
30 OpenGL Graphics context.
32 struct OpenGLGraphicsContext : GraphicsContext
34 #ifdef DGL_USE_OPENGL3
35 #endif
38 // -----------------------------------------------------------------------
40 static inline
41 ImageFormat asDISTRHOImageFormat(const GLenum format)
43 switch (format)
45 #ifdef DGL_USE_OPENGL3
46 case GL_RED:
47 #else
48 case GL_LUMINANCE:
49 #endif
50 return kImageFormatGrayscale;
51 case GL_BGR:
52 return kImageFormatBGR;
53 case GL_BGRA:
54 return kImageFormatBGRA;
55 case GL_RGB:
56 return kImageFormatRGB;
57 case GL_RGBA:
58 return kImageFormatRGBA;
61 return kImageFormatNull;
64 static inline
65 GLenum asOpenGLImageFormat(const ImageFormat format)
67 switch (format)
69 case kImageFormatNull:
70 break;
71 case kImageFormatGrayscale:
72 #ifdef DGL_USE_OPENGL3
73 return GL_RED;
74 #else
75 return GL_LUMINANCE;
76 #endif
77 case kImageFormatBGR:
78 return GL_BGR;
79 case kImageFormatBGRA:
80 return GL_BGRA;
81 case kImageFormatRGB:
82 return GL_RGB;
83 case kImageFormatRGBA:
84 return GL_RGBA;
87 return 0x0;
90 // -----------------------------------------------------------------------
92 /**
93 OpenGL Image class.
95 This is an Image class that handles raw image data in pixels.
96 You can init the image data on the contructor or later on by calling loadFromMemory().
98 To generate raw data useful for this class see the utils/png2rgba.py script.
99 Be careful when using a PNG without alpha channel, for those the format is 'GL_BGR'
100 instead of the default 'GL_BGRA'.
102 Images are drawn on screen via 2D textures.
104 class OpenGLImage : public ImageBase
106 public:
108 Constructor for a null Image.
110 OpenGLImage();
113 Constructor using raw image data.
114 @note @a rawData must remain valid for the lifetime of this Image.
116 OpenGLImage(const char* rawData, uint width, uint height, ImageFormat format = kImageFormatBGRA);
119 Constructor using raw image data.
120 @note @a rawData must remain valid for the lifetime of this Image.
122 OpenGLImage(const char* rawData, const Size<uint>& size, ImageFormat format = kImageFormatBGRA);
125 Constructor using another image data.
127 OpenGLImage(const OpenGLImage& image);
130 Destructor.
132 ~OpenGLImage() override;
135 Load image data from memory.
136 @note @a rawData must remain valid for the lifetime of this Image.
138 void loadFromMemory(const char* rawData,
139 const Size<uint>& size,
140 ImageFormat format = kImageFormatBGRA) noexcept override;
143 Draw this image at position @a pos using the graphics context @a context.
145 void drawAt(const GraphicsContext& context, const Point<int>& pos) override;
148 TODO document this.
150 OpenGLImage& operator=(const OpenGLImage& image) noexcept;
152 // FIXME this should not be needed
153 inline void loadFromMemory(const char* rdata, uint w, uint h, ImageFormat fmt = kImageFormatBGRA)
154 { loadFromMemory(rdata, Size<uint>(w, h), fmt); }
155 inline void draw(const GraphicsContext& context)
156 { drawAt(context, Point<int>(0, 0)); }
157 inline void drawAt(const GraphicsContext& context, int x, int y)
158 { drawAt(context, Point<int>(x, y)); }
161 Constructor using raw image data, specifying an OpenGL image format.
162 @note @a rawData must remain valid for the lifetime of this Image.
163 DEPRECATED This constructor uses OpenGL image format instead of DISTRHO one.
165 DISTRHO_DEPRECATED_BY("OpenGLImage(const char*, uint, uint, ImageFormat)")
166 explicit OpenGLImage(const char* rawData, uint width, uint height, GLenum glFormat);
169 Constructor using raw image data, specifying an OpenGL image format.
170 @note @a rawData must remain valid for the lifetime of this Image.
171 DEPRECATED This constructor uses OpenGL image format instead of DISTRHO one.
173 DISTRHO_DEPRECATED_BY("OpenGLImage(const char*, const Size<uint>&, ImageFormat)")
174 explicit OpenGLImage(const char* rawData, const Size<uint>& size, GLenum glFormat);
177 Draw this image at (0, 0) point using the current OpenGL context.
178 DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
180 DISTRHO_DEPRECATED_BY("draw(const GraphicsContext&)")
181 void draw();
184 Draw this image at (x, y) point using the current OpenGL context.
185 DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
187 DISTRHO_DEPRECATED_BY("drawAt(const GraphicsContext&, int, int)")
188 void drawAt(int x, int y);
191 Draw this image at position @a pos using the current OpenGL context.
192 DEPRECATED This function does not take into consideration the current graphics context and only works in OpenGL.
194 DISTRHO_DEPRECATED_BY("drawAt(const GraphicsContext&, const Point<int>&)")
195 void drawAt(const Point<int>& pos);
198 Get the image type.
199 DEPRECATED Type is always assumed to be GL_UNSIGNED_BYTE.
201 DISTRHO_DEPRECATED
202 GLenum getType() const noexcept { return GL_UNSIGNED_BYTE; }
204 private:
205 GLuint textureId;
206 bool setupCalled;
209 // -----------------------------------------------------------------------
211 typedef ImageBaseAboutWindow<OpenGLImage> OpenGLImageAboutWindow;
212 typedef ImageBaseButton<OpenGLImage> OpenGLImageButton;
213 typedef ImageBaseKnob<OpenGLImage> OpenGLImageKnob;
214 typedef ImageBaseSlider<OpenGLImage> OpenGLImageSlider;
215 typedef ImageBaseSwitch<OpenGLImage> OpenGLImageSwitch;
217 // -----------------------------------------------------------------------
219 END_NAMESPACE_DGL
221 #endif // DGL_OPENGL_HPP_INCLUDED