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
14 #include <sal/detail/log.h>
15 #include <vcl/dllapi.h>
16 #include <vcl/bitmapex.hxx>
18 #include <rtl/ustring.hxx>
20 #include <string_view>
22 /// Helper to do a SAL_INFO as well as a GL log.
23 #define VCL_GL_INFO(stream) \
25 if (SAL_DETAIL_ENABLE_LOG_INFO) \
27 ::std::ostringstream detail_stream; \
28 detail_stream << stream; \
29 OpenGLHelper::debugMsgStream(detail_stream); \
33 /// Helper to do a SAL_WARN as well as a GL log.
34 #define VCL_GL_WARN(stream) \
36 if (SAL_DETAIL_ENABLE_LOG_INFO) \
38 ::std::ostringstream detail_stream; \
39 detail_stream << stream; \
40 OpenGLHelper::debugMsgStreamWarn(detail_stream); \
44 // All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
45 struct VCL_DLLPUBLIC OpenGLHelper
47 OpenGLHelper() = delete; // Should not be instantiated
52 static OString
GetDigest(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, std::string_view preamble
);
55 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const OUString
& rGeometryShaderName
, std::string_view preamble
, std::string_view rDigest
);
56 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, std::string_view preamble
, std::string_view rDigest
);
57 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const OUString
& rGeometryShaderName
);
58 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
);
61 * The caller is responsible for allocating the memory for the buffer before calling
62 * this method. The buffer size is assumed to be 4*width*height and the format
63 * to be OptimalBufferFormat().
65 static BitmapEx
ConvertBufferToBitmapEx(const sal_uInt8
* const pBuffer
, tools::Long nWidth
, tools::Long nHeight
);
67 * Returns the optimal buffer format for OpenGL (GL_BGRA or GL_RGBA).
69 static GLenum
OptimalBufferFormat();
70 static void renderToFile(tools::Long nWidth
, tools::Long nHeight
, const OUString
& rFileName
);
72 static const char* GLErrorString(GLenum errorCode
);
75 * The caller is responsible for deleting the buffer objects identified by
76 * nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId.
77 * This create a buffer for rendering to texture and should be freed with
80 * @param nWidth Width of frame
81 * @param nHeight Height of frame
82 * @param nFramebufferId FrameBuffer ID
83 * @param nRenderbufferDepthId RenderBuffer's depth ID
84 * @param nRenderbufferColorId RenderBuffer's color ID
86 static void createFramebuffer(tools::Long nWidth
, tools::Long nHeight
, GLuint
& nFramebufferId
,
87 GLuint
& nRenderbufferDepthId
, GLuint
& nRenderbufferColorId
);
89 /// Get OpenGL version (needs a context)
90 static float getGLVersion();
92 static void checkGLError(const char* aFile
, size_t nLine
);
95 * Insert a glDebugMessage into the queue - helpful for debugging
96 * with apitrace to annotate the output and correlate it with code.
99 __attribute__ ((format (printf
, 2, 3)))
101 static void debugMsgPrint(const int nType
, const char *pFormat
, ...);
102 static void debugMsgStream(std::ostringstream
const &pStream
);
103 static void debugMsgStreamWarn(std::ostringstream
const &pStream
);
106 * checks if the device/driver pair is on our OpenGL denylist
108 static bool isDeviceDenylisted();
111 * checks if the system supports all features that are necessary for the OpenGL support
113 static bool supportsOpenGL();
117 #define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
119 #define CHECK_GL_ERROR() do { } while (false)
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */