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/log.hxx>
15 #include <vcl/dllapi.h>
16 #include <vcl/bitmapex.hxx>
18 #include <rtl/ustring.hxx>
20 #if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS)
22 # include "GL/glxew.h"
26 /// Helper to do a SAL_INFO as well as a GL log.
27 #define VCL_GL_INFO(area,stream) \
29 if (SAL_DETAIL_ENABLE_LOG_INFO) \
31 ::std::ostringstream detail_stream; \
32 detail_stream << stream; \
33 OpenGLHelper::debugMsgStream((area),detail_stream); \
37 class VCL_DLLPUBLIC OpenGLHelper
39 OpenGLHelper() SAL_DELETED_FUNCTION
; // Should not be instantiated
43 static rtl::OString
GetDigest(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const rtl::OString
& preamble
= "" );
45 static GLint
LoadShaders(const OUString
& rVertexShaderName
, const OUString
& rFragmentShaderName
, const rtl::OString
& preamble
= "", const rtl::OString
& rDigest
= "" );
48 * The caller is responsible for allocate the memory for the RGBA buffer, before call
49 * this method. RGBA buffer size is assumed to be 4*width*height.
50 * Since OpenGL uses textures flipped relative to BitmapEx storage this method
51 * also adds the possibility to mirror the bitmap vertically at the same time.
53 static void ConvertBitmapExToRGBATextureBuffer(const BitmapEx
& rBitmapEx
, sal_uInt8
* o_pRGBABuffer
, const bool bFlip
= false);
54 static BitmapEx
ConvertBGRABufferToBitmapEx(const sal_uInt8
* const pBuffer
, long nWidth
, long nHeight
);
55 static void renderToFile(long nWidth
, long nHeight
, const OUString
& rFileName
);
57 static const char* GLErrorString(GLenum errorCode
);
60 * The caller is responsible for deleting the buffer objects identified by
61 * nFramebufferId, nRenderbufferDepthId and nRenderbufferColorId
62 * @param bRenderbuffer true => off-screen rendering, false => rendering to texture
63 * This also affects whether to free with glDeleteRenderbuffers or glDeleteTextures
65 static void createFramebuffer(long nWidth
, long nHeight
, GLuint
& nFramebufferId
,
66 GLuint
& nRenderbufferDepthId
, GLuint
& nRenderbufferColorId
, bool bRenderbuffer
= true);
68 /// Get OpenGL version (needs a context)
69 static float getGLVersion();
71 static void checkGLError(const char* aFile
, size_t nLine
);
74 * Insert a glDebugMessage into the queue - helpful for debugging
75 * with apitrace to annotate the output and correlate it with code.
77 static void debugMsgPrint(const char *pArea
, const char *pFormat
, ...);
78 static void debugMsgStream(const char *pArea
, std::ostringstream
const &pStream
);
81 * checks if the device/driver pair is on our OpenGL blacklist
83 static bool isDeviceBlacklisted();
86 * checks if the system supports all features that are necessary for the OpenGL VCL support
88 static bool supportsVCLOpenGL();
91 * Returns true if VCL has OpenGL rendering enabled
93 static bool isVCLOpenGLEnabled();
95 #if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS)
96 static bool GetVisualInfo(Display
* pDisplay
, int nScreen
, XVisualInfo
& rVI
);
97 static GLXFBConfig
GetPixmapFBConfig( Display
* pDisplay
, bool& bInverted
);
101 #define CHECK_GL_ERROR() OpenGLHelper::checkGLError(__FILE__, __LINE__)
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */