CVB++ 15.0
decl_opengl_image_renderer.hpp
1#pragma once
2
3#ifdef _MSC_VER
4# pragma warning(push, 1)
5# pragma warning(disable : 4127)
6# pragma warning(disable : 4005) // macro redefinition // TODO
7#endif
8
9#include <QtMath>
10#include <QRectF>
11#include <QOpenGLShaderProgram>
12#include <QOpenGLFunctions>
13
14#ifdef _MSC_VER
15# pragma warning(pop)
16#endif
17
18#include "../../global.hpp"
19#include "../../size_2d.hpp"
20
21#include "../ui.hpp"
22
23namespace Cvb
24{
25
26 CVB_BEGIN_INLINE_NS
27
28 namespace UI
29 {
30
32
42 class OpenGLImageRenderer : protected QOpenGLFunctions
43 {
44 public:
45 OpenGLImageRenderer(const OpenGLImageRenderer &other) = delete;
46 OpenGLImageRenderer &operator=(const OpenGLImageRenderer &other) = delete;
47 OpenGLImageRenderer(OpenGLImageRenderer &&other) = delete;
48 OpenGLImageRenderer &operator=(OpenGLImageRenderer &&other) = delete;
49 virtual ~OpenGLImageRenderer() = default;
50
52
58 void UpdateMaping(const QRectF &sourceRect, Size2D<int> textureSize) noexcept;
59
61
68 void Render(const QRectF &viewportRect) noexcept;
69
71
76 {
77 return bufferFormat_;
78 }
79
81
87 virtual void *BeginBufferAccess(int &linePad) noexcept = 0;
88
90
93 virtual void EndBufferAccess() noexcept = 0;
94
96
100 virtual void UpdateBufferFormat(const OpenGLBufferFormat &bufferFormat) noexcept = 0;
101
103
107 virtual bool MonoUploadSupported() const noexcept = 0;
108
109 protected:
110 OpenGLImageRenderer() noexcept;
111
112 void BindTexture() noexcept;
113 void ReleaseTexture() noexcept;
114
115 void Image2DTexture(const OpenGLBufferFormat &pixelBufferFormat, void *pixels, bool swizzleSupport) noexcept;
116 void Image2DTexture(void *pixels, bool swizzleSupport) noexcept;
117
118 void SetBufferFormat(OpenGLBufferFormat bufferFormat) noexcept
119 {
120 bufferFormat_ = bufferFormat;
121 }
122
123 private:
124 class GLTexture : protected QOpenGLFunctions
125 {
126 public:
127 GLTexture() noexcept;
128 GLTexture(const GLTexture &other) = delete;
129 GLTexture &operator=(const GLTexture &other) = delete;
130 GLTexture(GLTexture &&other) = delete;
131 GLTexture &operator=(GLTexture &&other) = delete;
132 ~GLTexture();
133
134 void Bind() noexcept;
135 void Release() noexcept;
136
137 void Image2D(const OpenGLBufferFormat &pixelBufferFormat, void *pixels, bool swizzleSupport) noexcept;
138 void Image2D(void *pixels, bool swizzleSupport) noexcept;
139
140 private:
141 GLuint handle_ = 0;
142
143 OpenGLBufferFormat pixelBufferFormat_;
144 };
145 std::unique_ptr<GLTexture> texture_;
146
147 class GLCoordBuffer : public QOpenGLFunctions
148 {
149 public:
150 GLCoordBuffer() noexcept;
151 GLCoordBuffer(const GLCoordBuffer &other) = delete;
152 GLCoordBuffer &operator=(const GLCoordBuffer &other) = delete;
153 GLCoordBuffer(GLCoordBuffer &&other) = delete;
154 GLCoordBuffer &operator=(GLCoordBuffer &&other) = delete;
155 ~GLCoordBuffer();
156
157 void Bind() noexcept;
158 void Release() noexcept;
159
160 void Data(int size, void *buffer) noexcept;
161
162 private:
163 GLuint handle_ = 0;
164 };
165 std::unique_ptr<GLCoordBuffer> coordBuffer_;
166
167 QOpenGLShaderProgram program_;
168
169 int attrVertex_ = 0;
170 int attrTexcoord_ = 0;
171 int unifModelView_ = 0;
172 int unifTexture_ = 0;
173
174 OpenGLBufferFormat bufferFormat_;
175 };
176
177 } // namespace UI
178
179 CVB_END_INLINE_NS
180
181} // namespace Cvb
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
void Render(const QRectF &viewportRect) noexcept
Actually renders the image.
Definition detail_opengl_image_renderer.hpp:52
virtual void UpdateBufferFormat(const OpenGLBufferFormat &bufferFormat) noexcept=0
Updates the buffer format associated with the current rendering.
OpenGLBufferFormat BufferFormat() const noexcept
Returns the current buffer format.
Definition decl_opengl_image_renderer.hpp:75
virtual void EndBufferAccess() noexcept=0
End the pixel buffer mapping.
void UpdateMaping(const QRectF &sourceRect, Size2D< int > textureSize) noexcept
Updates the vertex and texture coordinates before rendering.
Definition detail_opengl_image_renderer.hpp:15
virtual void * BeginBufferAccess(int &linePad) noexcept=0
Maps the pixel buffer to upload data.
virtual bool MonoUploadSupported() const noexcept=0
Check if a mono image can be uploaded without duplicating the date in the color channels.
Namespace for user interface components.
Definition decl_image_scene.hpp:39
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Buffer format description for a texture to hold the pixel data.
Definition ui.hpp:151