uno grid a11y: Use ImplInheritanceHelper
[LibreOffice.git] / include / vcl / opengl / OpenGLHelper.hxx
blob86e6e766fae3b932e10cb56859b324b74af6ed93
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #ifndef INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
11 #define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
13 #include <config_options.h>
14 #include <epoxy/gl.h>
15 #include <sal/detail/log.h>
16 #include <vcl/dllapi.h>
17 #include <vcl/bitmapex.hxx>
19 #include <rtl/ustring.hxx>
20 #include <sstream>
21 #include <string_view>
23 /// Helper to do a SAL_INFO as well as a GL log.
24 #define VCL_GL_INFO(stream) \
25 do { \
26 if (SAL_DETAIL_ENABLE_LOG_INFO) \
27 { \
28 ::std::ostringstream detail_stream; \
29 detail_stream << stream; \
30 OpenGLHelper::debugMsgStream(detail_stream); \
31 } \
32 } while (false)
34 /// Helper to do a SAL_WARN as well as a GL log.
35 #define VCL_GL_WARN(stream) \
36 do { \
37 if (SAL_DETAIL_ENABLE_LOG_INFO) \
38 { \
39 ::std::ostringstream detail_stream; \
40 detail_stream << stream; \
41 OpenGLHelper::debugMsgStreamWarn(detail_stream); \
42 } \
43 } while (false)
45 // All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
46 struct VCL_DLLPUBLIC OpenGLHelper
48 OpenGLHelper() = delete; // Should not be instantiated
50 public:
52 #if defined _WIN32
53 static OString GetDigest(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, std::string_view preamble );
54 #endif
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);
61 /**
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().
65 **/
66 SAL_DLLPRIVATE static BitmapEx ConvertBufferToBitmapEx(const sal_uInt8* const pBuffer, tools::Long nWidth, tools::Long nHeight);
67 /**
68 * Returns the optimal buffer format for OpenGL (GL_BGRA or GL_RGBA).
69 **/
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);
75 /**
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
79 * glDeleteTextures.
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);
95 /**
96 * Insert a glDebugMessage into the queue - helpful for debugging
97 * with apitrace to annotate the output and correlate it with code.
99 #if defined __GNUC__
100 __attribute__ ((format (printf, 2, 3)))
101 #endif
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();
117 #ifdef SAL_LOG_WARN
118 #define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
119 #else
120 #define CHECK_GL_ERROR() do { } while (false)
121 #endif
123 #endif
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */