android: Update app-specific/MIME type icons
[LibreOffice.git] / include / vcl / opengl / OpenGLHelper.hxx
blob45383bd6fb9dcd45217de8711efbbedf7a337370
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 <epoxy/gl.h>
14 #include <sal/detail/log.h>
15 #include <vcl/dllapi.h>
16 #include <vcl/bitmapex.hxx>
18 #include <rtl/ustring.hxx>
19 #include <sstream>
20 #include <string_view>
22 /// Helper to do a SAL_INFO as well as a GL log.
23 #define VCL_GL_INFO(stream) \
24 do { \
25 if (SAL_DETAIL_ENABLE_LOG_INFO) \
26 { \
27 ::std::ostringstream detail_stream; \
28 detail_stream << stream; \
29 OpenGLHelper::debugMsgStream(detail_stream); \
30 } \
31 } while (false)
33 /// Helper to do a SAL_WARN as well as a GL log.
34 #define VCL_GL_WARN(stream) \
35 do { \
36 if (SAL_DETAIL_ENABLE_LOG_INFO) \
37 { \
38 ::std::ostringstream detail_stream; \
39 detail_stream << stream; \
40 OpenGLHelper::debugMsgStreamWarn(detail_stream); \
41 } \
42 } while (false)
44 // All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
45 struct VCL_DLLPUBLIC OpenGLHelper
47 OpenGLHelper() = delete; // Should not be instantiated
49 public:
51 #if defined _WIN32
52 static OString GetDigest(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, std::string_view preamble );
53 #endif
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);
60 /**
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().
64 **/
65 static BitmapEx ConvertBufferToBitmapEx(const sal_uInt8* const pBuffer, tools::Long nWidth, tools::Long nHeight);
66 /**
67 * Returns the optimal buffer format for OpenGL (GL_BGRA or GL_RGBA).
68 **/
69 static GLenum OptimalBufferFormat();
70 static void renderToFile(tools::Long nWidth, tools::Long nHeight, const OUString& rFileName);
72 static const char* GLErrorString(GLenum errorCode);
74 /**
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
78 * glDeleteTextures.
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);
94 /**
95 * Insert a glDebugMessage into the queue - helpful for debugging
96 * with apitrace to annotate the output and correlate it with code.
98 #if defined __GNUC__
99 __attribute__ ((format (printf, 2, 3)))
100 #endif
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();
116 #ifdef SAL_LOG_WARN
117 #define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
118 #else
119 #define CHECK_GL_ERROR() do { } while (false)
120 #endif
122 #endif
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */