1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
11 #define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
13 #include <config_options.h>
15 #include <sal/detail/log.h>
16 #include <vcl/dllapi.h>
17 #include <vcl/bitmapex.hxx>
19 #include <rtl/ustring.hxx>
21 #include <string_view>
23 /// Helper to do a SAL_INFO as well as a GL log.
24 #define VCL_GL_INFO(stream) \
26 if (SAL_DETAIL_ENABLE_LOG_INFO) \
28 ::std::ostringstream detail_stream; \
29 detail_stream << stream; \
30 OpenGLHelper::debugMsgStream(detail_stream); \
34 /// Helper to do a SAL_WARN as well as a GL log.
35 #define VCL_GL_WARN(stream) \
37 if (SAL_DETAIL_ENABLE_LOG_INFO) \
39 ::std::ostringstream detail_stream; \
40 detail_stream << stream; \
41 OpenGLHelper::debugMsgStreamWarn(detail_stream); \
45 // All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
46 struct VCL_DLLPUBLIC OpenGLHelper
48 OpenGLHelper() = delete; // Should not be instantiated
53 static OString
GetDigest(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, std::string_view preamble
);
56 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const OUString
& rGeometryShaderName
, std::string_view preamble
, std::string_view rDigest
);
57 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, std::string_view preamble
, std::string_view rDigest
);
58 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const OUString
& rGeometryShaderName
);
59 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
);
62 * The caller is responsible for allocating the memory for the buffer before calling
63 * this method. The buffer size is assumed to be 4*width*height and the format
64 * to be OptimalBufferFormat().
66 SAL_DLLPRIVATE
static BitmapEx
ConvertBufferToBitmapEx(const sal_uInt8
* const pBuffer
, tools::Long nWidth
, tools::Long nHeight
);
68 * Returns the optimal buffer format for OpenGL (GL_BGRA or GL_RGBA).
70 SAL_DLLPRIVATE
static GLenum
OptimalBufferFormat();
71 SAL_DLLPRIVATE
static void renderToFile(tools::Long nWidth
, tools::Long nHeight
, const OUString
& rFileName
);
73 SAL_DLLPRIVATE
static const char* GLErrorString(GLenum errorCode
);
76 * The caller is responsible for deleting the buffer objects identified by
77 * nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId.
78 * This create a buffer for rendering to texture and should be freed with
81 * @param nWidth Width of frame
82 * @param nHeight Height of frame
83 * @param nFramebufferId FrameBuffer ID
84 * @param nRenderbufferDepthId RenderBuffer's depth ID
85 * @param nRenderbufferColorId RenderBuffer's color ID
87 static void createFramebuffer(tools::Long nWidth
, tools::Long nHeight
, GLuint
& nFramebufferId
,
88 GLuint
& nRenderbufferDepthId
, GLuint
& nRenderbufferColorId
);
90 /// Get OpenGL version (needs a context)
91 static float getGLVersion();
93 static void checkGLError(const char* aFile
, size_t nLine
);
96 * Insert a glDebugMessage into the queue - helpful for debugging
97 * with apitrace to annotate the output and correlate it with code.
100 __attribute__ ((format (printf
, 2, 3)))
102 static void debugMsgPrint(const int nType
, const char *pFormat
, ...);
103 static void debugMsgStream(std::ostringstream
const &pStream
);
104 static void debugMsgStreamWarn(std::ostringstream
const &pStream
);
107 * checks if the device/driver pair is on our OpenGL denylist
109 SAL_DLLPRIVATE
static bool isDeviceDenylisted();
112 * checks if the system supports all features that are necessary for the OpenGL support
114 static bool supportsOpenGL();
118 #define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
120 #define CHECK_GL_ERROR() do { } while (false)
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */