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
|
|
|
|
2016-11-25 20:25:27 +00:00
|
|
|
#include <epoxy/gl.h>
|
2015-08-28 11:28:13 +01:00
|
|
|
#include <sal/log.hxx>
|
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>
|
|
|
|
|
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 { \
|
2015-09-04 17:13:30 +03:00
|
|
|
if (SAL_DETAIL_ENABLE_LOG_INFO && OpenGLHelper::isVCLOpenGLEnabled()) \
|
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 { \
|
|
|
|
if (SAL_DETAIL_ENABLE_LOG_INFO && OpenGLHelper::isVCLOpenGLEnabled()) \
|
|
|
|
{ \
|
|
|
|
::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.
|
|
|
|
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:
|
|
|
|
|
2016-08-30 15:34:35 +02:00
|
|
|
static OString GetDigest(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OString& preamble );
|
2015-09-13 12:15:13 +02:00
|
|
|
|
2016-01-08 13:40:13 +11:00
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OUString& rGeometryShaderName, const OString& preamble, const OString& rDigest );
|
|
|
|
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OString& preamble, const OString& 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
|
|
|
/**
|
2014-08-11 10:18:04 +02:00
|
|
|
* The caller is responsible for allocate the memory for the RGBA buffer, before call
|
|
|
|
* this method. RGBA buffer size is assumed to be 4*width*height.
|
|
|
|
* Since OpenGL uses textures flipped relative to BitmapEx storage this method
|
2014-09-17 08:04:36 +02:00
|
|
|
* also adds the possibility to mirror the bitmap vertically at the same time.
|
2014-08-04 12:04:10 +02:00
|
|
|
**/
|
2014-09-17 08:04:36 +02:00
|
|
|
static void ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer, const bool bFlip = false);
|
2014-04-27 20:25:52 +02:00
|
|
|
static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
|
2014-05-09 00:31:05 +02:00
|
|
|
static void renderToFile(long nWidth, long nHeight, const OUString& rFileName);
|
2014-04-29 08:27:58 +03:00
|
|
|
|
|
|
|
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
|
2014-05-21 14:23:07 +02:00
|
|
|
* nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId
|
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
|
2016-01-08 17:37:01 +11:00
|
|
|
* @param bRenderbuffer true => off-screen rendering, false => rendering to texture
|
2014-08-08 04:52:38 +02:00
|
|
|
* This also affects whether to free with glDeleteRenderbuffers or glDeleteTextures
|
2014-05-21 00:41:37 +02:00
|
|
|
*/
|
2014-08-08 04:52:38 +02:00
|
|
|
static void createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
|
2014-08-08 05:05:11 +02:00
|
|
|
GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer = true);
|
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.
|
|
|
|
*/
|
2016-07-25 13:58:44 +09:00
|
|
|
static void debugMsgPrint(const int nType, const char *pFormat, ...);
|
2015-11-20 10:14:49 +01: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
|
|
|
/**
|
|
|
|
* checks if the device/driver pair is on our OpenGL blacklist
|
|
|
|
*/
|
|
|
|
static bool isDeviceBlacklisted();
|
2015-08-28 11:28:13 +01:00
|
|
|
|
2014-11-02 00:12:21 +01:00
|
|
|
/**
|
|
|
|
* checks if the system supports all features that are necessary for the OpenGL VCL support
|
|
|
|
*/
|
|
|
|
static bool supportsVCLOpenGL();
|
2014-11-04 17:31:12 -05:00
|
|
|
|
2014-11-10 16:02:31 +00:00
|
|
|
/**
|
|
|
|
* Returns true if VCL has OpenGL rendering enabled
|
|
|
|
*/
|
|
|
|
static bool isVCLOpenGLEnabled();
|
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: */
|