1 #ifndef MYTHRENDER_OPENGL_H_
2 #define MYTHRENDER_OPENGL_H_
11 #include <QOpenGLContext>
12 #include <QOpenGLFunctions>
13 #include <QOpenGLExtraFunctions>
14 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
15 #include <QOpenGLShaderProgram>
16 #include <QOpenGLFramebufferObject>
17 #include <QOpenGLTexture>
18 #include <QOpenGLBuffer>
19 #include <QOpenGLDebugLogger>
21 #include <QtOpenGL/QOpenGLTexture>
22 #include <QtOpenGL/QOpenGLShaderProgram>
23 #include <QtOpenGL/QOpenGLFramebufferObject>
24 #include <QtOpenGL/QOpenGLBuffer>
25 #include <QtOpenGL/QOpenGLDebugLogger>
28 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
31 #include <QRecursiveMutex>
67 unsigned char *m_data {
nullptr };
68 int m_bufferSize { 0 } ;
69 GLuint m_textureId { 0 } ;
70 QOpenGLTexture *m_texture {
nullptr } ;
71 QOpenGLTexture::PixelFormat m_pixelFormat { QOpenGLTexture::RGBA };
72 QOpenGLTexture::PixelType m_pixelType { QOpenGLTexture::UInt8 };
73 QOpenGLBuffer *m_vbo {
nullptr };
74 QSize m_size { QSize() };
75 QSize m_totalSize { QSize() };
77 bool m_crop {
false };
78 QRect m_source { QRect() };
79 QRect m_destination { QRect() };
80 std::array<GLfloat,16> m_vertexData { 0.0F };
81 GLenum m_target { QOpenGLTexture::Target2D };
118 int GetMaxTextureSize(
void)
const;
119 int GetMaxTextureUnits(
void)
const;
120 int GetExtraFeatures(
void)
const;
121 QOpenGLFunctions::OpenGLFeatures GetFeatures(
void)
const;
122 bool IsRecommendedRenderer(
void);
123 void SetViewPort(QRect Rect,
bool ViewportOnly =
false)
override;
125 void PushTransformation(
const UIEffects &Fx, QPointF &Center);
126 void PopTransformation(
void);
128 void SetBlend(
bool Enable);
129 void SetBackground(uint8_t Red, uint8_t Green, uint8_t Blue, uint8_t Alpha);
130 QFunctionPointer GetProcAddress(
const QString &Proc)
const;
131 uint64_t GetSwapCount();
133 static constexpr GLuint kVertexSize { 16 *
sizeof(GLfloat) };
134 QOpenGLBuffer* CreateVBO(
int Size,
bool Release =
true);
137 QSize GetTextureSize(QSize Size,
bool Normalised);
139 void SetTextureFilters(
MythGLTexture *Texture, QOpenGLTexture::Filter Filter,
140 QOpenGLTexture::WrapMode Wrap = QOpenGLTexture::ClampToEdge);
141 void ActiveTexture(GLuint ActiveTex);
143 static int GetBufferSize(QSize Size, QOpenGLTexture::PixelFormat
Format, QOpenGLTexture::PixelType Type);
145 QOpenGLFramebufferObject* CreateFramebuffer(QSize &Size,
bool SixteenBit =
false);
146 MythGLTexture* CreateFramebufferTexture(QOpenGLFramebufferObject *Framebuffer);
147 void DeleteFramebuffer(QOpenGLFramebufferObject *Framebuffer);
148 void BindFramebuffer(QOpenGLFramebufferObject *Framebuffer);
149 void ClearFramebuffer(
void);
151 QOpenGLShaderProgram* CreateShaderProgram(
const QString &Vertex,
const QString &Fragment);
152 QOpenGLShaderProgram* CreateComputeShader(
const QString &
Source);
153 void DeleteShaderProgram(QOpenGLShaderProgram* Program);
154 bool EnableShaderProgram(QOpenGLShaderProgram* Program);
155 void SetShaderProgramParams(QOpenGLShaderProgram* Program,
const QMatrix4x4 &Value,
const char* Uniform);
156 void SetShaderProjection(QOpenGLShaderProgram* Program);
158 void DrawBitmap(
MythGLTexture *Texture, QOpenGLFramebufferObject *Target,
159 QRect
Source, QRect Destination,
160 QOpenGLShaderProgram *Program,
int Alpha = 255, qreal Scale = 1.0);
161 void DrawBitmap(std::vector<MythGLTexture *> &Textures,
162 QOpenGLFramebufferObject *Target,
163 QRect
Source, QRect Destination,
164 QOpenGLShaderProgram *Program,
int Rotation);
165 void DrawRect(QOpenGLFramebufferObject *Target,
166 QRect Area,
const QBrush &FillBrush,
167 const QPen &LinePen,
int Alpha);
168 void DrawRoundRect(QOpenGLFramebufferObject *Target,
169 QRect Area,
int CornerRadius,
170 const QBrush &FillBrush,
const QPen &LinePen,
int Alpha);
171 void ClearRect(QOpenGLFramebufferObject *Target, QRect Area,
int Color,
int Alpha);
172 void DrawProcedural(QRect Area,
int Alpha, QOpenGLFramebufferObject* Target,
173 QOpenGLShaderProgram* Program,
float TimeVal);
174 std::tuple<int,int,int> GetGPUMemory();
177 void MessageLogged (
const QOpenGLDebugMessage &Message);
178 void logDebugMarker (
const QString &Message);
179 void contextToBeDestroyed(
void);
184 void SetWidget(QWidget *Widget);
185 void Init2DState(
void);
186 void SetMatrixView(
void);
187 void DeleteFramebuffers(
void);
189 QRect Destination,
int Rotation, qreal Scale = 1.0);
190 GLfloat* GetCachedVertices(GLuint Type, QRect Area);
191 void ExpireVertices(
int Max = 0);
192 void GetCachedVBO(GLuint Type, QRect Area);
193 void ExpireVBOS(
int Max = 0);
194 bool CreateDefaultShaders(
void);
195 void DeleteDefaultShaders(
void);
196 void Check16BitFBO(
void);
200 inline void glVertexAttribPointerI(GLuint Index, GLint Size, GLenum Type,
201 GLboolean Normalize, GLsizei Stride,
204 bool m_ready {
false };
207 GLuint m_activeFramebuffer { 0 };
210 GLuint m_fence { 0 };
213 std::array<QOpenGLShaderProgram*,kShaderCount> m_defaultPrograms {
nullptr };
214 QOpenGLShaderProgram* m_activeProgram {
nullptr };
223 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
224 QMutex m_lock { QMutex::Recursive };
228 int m_lockLevel { 0 };
231 QOpenGLFunctions::OpenGLFeatures m_features { Multitexture };
234 int m_maxTextureSize { 0 };
235 int m_maxTextureUnits { 0 };
238 uint64_t m_swapCount { 0 };
240 GLuint m_activeTexture { 0 };
241 bool m_blend {
false };
242 int32_t m_background { 0x00000001 };
243 bool m_fullRange {
true };
253 bool m_flushEnabled {
true };
257 void DebugFeatures (
void);
258 QOpenGLDebugLogger *m_openglDebugger {
nullptr };
259 QOpenGLDebugMessage::Types m_openGLDebuggerFilter { QOpenGLDebugMessage::InvalidType };
260 QWindow *m_window {
nullptr };