2014-04-15 00:55:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2014-04-18 18:21:34 +02:00
|
|
|
#ifndef INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
|
|
|
|
#define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
|
2014-04-15 00:55:07 +02:00
|
|
|
|
2024-03-01 15:58:23 +02:00
|
|
|
#include <config_options.h>
|
2016-11-25 20:25:27 +00:00
|
|
|
#include <epoxy/gl.h>
|
2018-12-01 17:59:14 +01:00
|
|
|
#include <sal/detail/log.h>
|
2015-04-23 13:44:47 +03:00
|
|
|
#include <vcl/dllapi.h>
|
2014-04-18 15:24:25 +02:00
|
|
|
#include <vcl/bitmapex.hxx>
|
2014-04-15 00:55:07 +02:00
|
|
|
|
|
|
|
#include <rtl/ustring.hxx>
|
2018-12-01 17:59:14 +01:00
|
|
|
#include <sstream>
|
2020-12-28 17:56:40 +01:00
|
|
|
#include <string_view>
|
2014-04-15 00:55:07 +02:00
|
|
|
|
2015-08-28 11:28:13 +01:00
|
|
|
/// Helper to do a SAL_INFO as well as a GL log.
|
2015-11-20 10:14:49 +01:00
|
|
|
#define VCL_GL_INFO(stream) \
|
2015-08-28 20:05:44 +01:00
|
|
|
do { \
|
2020-12-08 10:44:52 +01:00
|
|
|
if (SAL_DETAIL_ENABLE_LOG_INFO) \
|
2015-08-28 20:05:44 +01:00
|
|
|
{ \
|
|
|
|
::std::ostringstream detail_stream; \
|
|
|
|
detail_stream << stream; \
|
2015-11-20 10:14:49 +01:00
|
|
|
OpenGLHelper::debugMsgStream(detail_stream); \
|
2015-08-28 20:05:44 +01:00
|
|
|
} \
|
2015-08-29 07:55:29 +03:00
|
|
|
} while (false)
|
2015-08-28 11:28:13 +01:00
|
|
|
|
2016-07-25 13:58:44 +09:00
|
|
|
/// Helper to do a SAL_WARN as well as a GL log.
|
|
|
|
#define VCL_GL_WARN(stream) \
|
|
|
|
do { \
|
2020-12-08 10:44:52 +01:00
|
|
|
if (SAL_DETAIL_ENABLE_LOG_INFO) \
|
2016-07-25 13:58:44 +09:00
|
|
|
{ \
|
|
|
|
::std::ostringstream detail_stream; \
|
|
|
|
detail_stream << stream; \
|
|
|
|
OpenGLHelper::debugMsgStreamWarn(detail_stream); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2015-09-04 16:51:26 +03:00
|
|
|
// All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
|
2024-03-05 11:59:14 +02:00
|
|
|
struct VCL_DLLPUBLIC OpenGLHelper
|
2014-04-15 00:55:07 +02:00
|
|
|
{
|
2015-10-12 15:25:41 +02:00
|
|
|
OpenGLHelper() = delete; // Should not be instantiated
|
2015-09-04 16:51:26 +03:00
|
|
|
|
2015-09-13 12:15:13 +02:00
|
|
|
public:
|
|
|
|
|
2022-03-22 07:45:46 +01:00
|
|
|
#if defined _WIN32
|
2020-12-28 17:56:40 +01:00
|
|
|
static OString GetDigest(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, std::string_view preamble );
|
2022-03-22 07:45:46 +01:00
|
|
|
#endif
|
2015-09-13 12:15:13 +02:00
|
|
|
|
2020-12-28 17:56:40 +01:00
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OUString& rGeometryShaderName, std::string_view preamble, std::string_view rDigest );
|
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, std::string_view preamble, std::string_view rDigest );
|
2015-12-09 21:39:31 +00:00
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OUString& rGeometryShaderName);
|
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
|
2014-04-15 00:55:07 +02:00
|
|
|
|
2014-08-04 12:04:10 +02:00
|
|
|
/**
|
2019-04-14 18:21:04 +02:00
|
|
|
* The caller is responsible for allocating the memory for the buffer before calling
|
|
|
|
* this method. The buffer size is assumed to be 4*width*height and the format
|
|
|
|
* to be OptimalBufferFormat().
|
2014-08-04 12:04:10 +02:00
|
|
|
**/
|
2024-03-15 08:13:00 +02:00
|
|
|
SAL_DLLPRIVATE static BitmapEx ConvertBufferToBitmapEx(const sal_uInt8* const pBuffer, tools::Long nWidth, tools::Long nHeight);
|
2019-04-14 18:21:04 +02:00
|
|
|
/**
|
|
|
|
* Returns the optimal buffer format for OpenGL (GL_BGRA or GL_RGBA).
|
|
|
|
**/
|
2024-03-15 08:13:00 +02:00
|
|
|
SAL_DLLPRIVATE static GLenum OptimalBufferFormat();
|
|
|
|
SAL_DLLPRIVATE static void renderToFile(tools::Long nWidth, tools::Long nHeight, const OUString& rFileName);
|
2014-04-29 08:27:58 +03:00
|
|
|
|
2024-03-15 08:13:00 +02:00
|
|
|
SAL_DLLPRIVATE static const char* GLErrorString(GLenum errorCode);
|
2014-05-21 00:41:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The caller is responsible for deleting the buffer objects identified by
|
2018-07-18 15:03:30 +02:00
|
|
|
* nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId.
|
|
|
|
* This create a buffer for rendering to texture and should be freed with
|
|
|
|
* glDeleteTextures.
|
|
|
|
*
|
2016-01-08 17:37:01 +11:00
|
|
|
* @param nWidth Width of frame
|
|
|
|
* @param nHeight Height of frame
|
|
|
|
* @param nFramebufferId FrameBuffer ID
|
2016-01-08 23:21:51 +11:00
|
|
|
* @param nRenderbufferDepthId RenderBuffer's depth ID
|
|
|
|
* @param nRenderbufferColorId RenderBuffer's color ID
|
2014-05-21 00:41:37 +02:00
|
|
|
*/
|
2020-10-19 15:12:38 +02:00
|
|
|
static void createFramebuffer(tools::Long nWidth, tools::Long nHeight, GLuint& nFramebufferId,
|
2018-07-18 15:03:30 +02:00
|
|
|
GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId);
|
2014-07-20 14:20:35 +02:00
|
|
|
|
2015-08-28 11:28:13 +01:00
|
|
|
/// Get OpenGL version (needs a context)
|
2014-07-20 14:20:35 +02:00
|
|
|
static float getGLVersion();
|
2014-08-18 15:38:04 +02:00
|
|
|
|
|
|
|
static void checkGLError(const char* aFile, size_t nLine);
|
2014-11-02 00:12:21 +01:00
|
|
|
|
2015-08-28 11:28:13 +01:00
|
|
|
/**
|
|
|
|
* Insert a glDebugMessage into the queue - helpful for debugging
|
|
|
|
* with apitrace to annotate the output and correlate it with code.
|
|
|
|
*/
|
2019-10-28 09:21:35 +02:00
|
|
|
#if defined __GNUC__
|
|
|
|
__attribute__ ((format (printf, 2, 3)))
|
|
|
|
#endif
|
2016-07-25 13:58:44 +09:00
|
|
|
static void debugMsgPrint(const int nType, const char *pFormat, ...);
|
2024-03-05 11:59:14 +02:00
|
|
|
static void debugMsgStream(std::ostringstream const &pStream);
|
2016-07-25 13:58:44 +09:00
|
|
|
static void debugMsgStreamWarn(std::ostringstream const &pStream);
|
2015-08-28 11:28:13 +01:00
|
|
|
|
2014-11-20 09:52:03 +01:00
|
|
|
/**
|
2020-07-06 03:01:51 +02:00
|
|
|
* checks if the device/driver pair is on our OpenGL denylist
|
2014-11-20 09:52:03 +01:00
|
|
|
*/
|
2024-03-15 08:13:00 +02:00
|
|
|
SAL_DLLPRIVATE static bool isDeviceDenylisted();
|
2015-08-28 11:28:13 +01:00
|
|
|
|
2014-11-02 00:12:21 +01:00
|
|
|
/**
|
2020-12-08 10:44:52 +01:00
|
|
|
* checks if the system supports all features that are necessary for the OpenGL support
|
2014-11-02 00:12:21 +01:00
|
|
|
*/
|
2020-12-08 10:44:52 +01:00
|
|
|
static bool supportsOpenGL();
|
2014-04-15 00:55:07 +02:00
|
|
|
};
|
|
|
|
|
2015-11-16 20:39:17 +02:00
|
|
|
#ifdef SAL_LOG_WARN
|
2014-08-18 15:38:04 +02:00
|
|
|
#define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
|
2015-11-16 20:39:17 +02:00
|
|
|
#else
|
|
|
|
#define CHECK_GL_ERROR() do { } while (false)
|
|
|
|
#endif
|
2014-08-18 15:38:04 +02:00
|
|
|
|
2014-04-15 00:55:07 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|