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-07-21 14:37:25 +01:00
|
|
|
#include <vcl/opengl/GLMHelper.hxx>
|
2014-04-15 00:55:07 +02:00
|
|
|
#include <vcl/opengl/OpenGLHelper.hxx>
|
|
|
|
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
#include <config_folders.h>
|
2014-04-18 15:24:25 +02:00
|
|
|
#include <vcl/salbtype.hxx>
|
|
|
|
#include <vcl/bmpacc.hxx>
|
2014-05-09 00:31:05 +02:00
|
|
|
#include <boost/scoped_array.hpp>
|
|
|
|
#include <vcl/pngwrite.hxx>
|
|
|
|
#include <vcl/graph.hxx>
|
2015-01-24 14:26:25 +11:00
|
|
|
#include <vcl/svapp.hxx>
|
2014-11-10 16:02:31 +00:00
|
|
|
#include <officecfg/Office/Common.hxx>
|
2014-04-15 00:55:07 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2014-11-20 09:52:03 +01:00
|
|
|
#if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID
|
|
|
|
#include "opengl/x11/X11DeviceInfo.hxx"
|
2014-11-24 16:46:15 +01:00
|
|
|
#elif defined (_WIN32)
|
|
|
|
#include "opengl/win/WinDeviceInfo.hxx"
|
2014-11-20 09:52:03 +01:00
|
|
|
#endif
|
|
|
|
|
2014-04-15 00:55:07 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
OUString getShaderFolder()
|
|
|
|
{
|
|
|
|
OUString aUrl("$BRAND_BASE_DIR/" LIBO_ETC_FOLDER);
|
|
|
|
rtl::Bootstrap::expandMacros(aUrl);
|
|
|
|
|
|
|
|
return aUrl + "/opengl/";
|
|
|
|
}
|
|
|
|
|
|
|
|
OString loadShader(const OUString& rFilename)
|
|
|
|
{
|
2014-04-15 09:53:30 +03:00
|
|
|
OUString aFileURL = getShaderFolder() + rFilename +".glsl";
|
2014-04-15 00:55:07 +02:00
|
|
|
osl::File aFile(aFileURL);
|
|
|
|
if(aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None)
|
|
|
|
{
|
|
|
|
sal_uInt64 nSize = 0;
|
|
|
|
aFile.getSize(nSize);
|
2014-05-23 02:01:03 +02:00
|
|
|
boost::scoped_array<char> content(new char[nSize+1]);
|
2014-04-15 00:55:07 +02:00
|
|
|
sal_uInt64 nBytesRead = 0;
|
2014-05-23 02:01:03 +02:00
|
|
|
aFile.read(content.get(), nSize, nBytesRead);
|
2015-01-25 14:36:14 +00:00
|
|
|
assert(nSize == nBytesRead);
|
2015-01-31 21:14:39 +00:00
|
|
|
content.get()[nBytesRead] = 0;
|
2014-05-23 02:01:03 +02:00
|
|
|
return OString(content.get());
|
2014-04-15 00:55:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SAL_WARN("vcl.opengl", "could not load the file: " << aFileURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OString();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-18 21:17:52 +00:00
|
|
|
namespace {
|
|
|
|
int LogCompilerError(GLuint nId, const rtl::OUString &rDetail,
|
|
|
|
const rtl::OUString &rName, bool bShaderNotProgram)
|
|
|
|
{
|
|
|
|
int InfoLogLength = 0;
|
|
|
|
|
|
|
|
CHECK_GL_ERROR();
|
|
|
|
|
|
|
|
if (bShaderNotProgram)
|
|
|
|
glGetShaderiv (nId, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
|
|
|
else
|
|
|
|
glGetProgramiv(nId, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
|
|
|
|
|
|
|
CHECK_GL_ERROR();
|
|
|
|
|
|
|
|
if ( InfoLogLength > 0 )
|
|
|
|
{
|
|
|
|
std::vector<char> ErrorMessage(InfoLogLength+1);
|
|
|
|
if (bShaderNotProgram)
|
|
|
|
glGetShaderInfoLog (nId, InfoLogLength, NULL, &ErrorMessage[0]);
|
|
|
|
else
|
|
|
|
glGetProgramInfoLog(nId, InfoLogLength, NULL, &ErrorMessage[0]);
|
|
|
|
CHECK_GL_ERROR();
|
|
|
|
|
|
|
|
ErrorMessage.push_back('\0');
|
|
|
|
SAL_WARN("vcl.opengl", rDetail << " shader " << nId << " compile for " << rName << " failed : " << &ErrorMessage[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SAL_WARN("vcl.opengl", rDetail << " shader: " << rName << " compile " << nId << "failed without error log");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 01:34:17 +11:00
|
|
|
static void addPreamble(OString& rShaderSource, const OString& rPreamble)
|
|
|
|
{
|
|
|
|
if (rPreamble.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
OString aVersionStr("#version");
|
|
|
|
int nVersionStrStartPos = rShaderSource.indexOf(aVersionStr, 0);
|
|
|
|
|
|
|
|
if (nVersionStrStartPos == -1)
|
|
|
|
{
|
|
|
|
rShaderSource = rPreamble + "\n" + rShaderSource;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int nVersionStrEndPos = rShaderSource.indexOf('\n', nVersionStrStartPos);
|
|
|
|
|
2015-03-09 20:59:47 +00:00
|
|
|
SAL_WARN_IF(nVersionStrEndPos == -1, "vcl.opengl", "syntax error in shader");
|
2015-01-30 01:34:17 +11:00
|
|
|
|
|
|
|
if (nVersionStrEndPos == -1)
|
|
|
|
nVersionStrEndPos = nVersionStrStartPos + 8;
|
|
|
|
|
|
|
|
OString aVersionLine = rShaderSource.copy(0, nVersionStrEndPos - nVersionStrStartPos);
|
|
|
|
OString aShaderBody = rShaderSource.copy(nVersionStrEndPos - nVersionStrStartPos);
|
|
|
|
|
|
|
|
rShaderSource = aVersionLine + "\n" + rPreamble + "\n" + aShaderBody;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 14:48:48 +01:00
|
|
|
GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString& rFragmentShaderName, const OString& preamble)
|
2014-04-15 00:55:07 +02:00
|
|
|
{
|
|
|
|
// Create the shaders
|
|
|
|
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
|
|
|
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
|
|
|
|
|
GLint Result = GL_FALSE;
|
|
|
|
|
|
|
|
// Compile Vertex Shader
|
|
|
|
OString aVertexShaderSource = loadShader(rVertexShaderName);
|
2015-01-20 14:48:48 +01:00
|
|
|
if( !preamble.isEmpty())
|
2015-01-30 01:34:17 +11:00
|
|
|
addPreamble( aVertexShaderSource, preamble );
|
2014-04-15 00:55:07 +02:00
|
|
|
char const * VertexSourcePointer = aVertexShaderSource.getStr();
|
|
|
|
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
|
|
|
|
glCompileShader(VertexShaderID);
|
|
|
|
|
|
|
|
// Check Vertex Shader
|
|
|
|
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
|
2014-11-18 21:17:52 +00:00
|
|
|
if (!Result)
|
|
|
|
return LogCompilerError(VertexShaderID, "vertex",
|
|
|
|
rVertexShaderName, true);
|
2014-04-15 00:55:07 +02:00
|
|
|
|
|
|
|
// Compile Fragment Shader
|
|
|
|
OString aFragmentShaderSource = loadShader(rFragmentShaderName);
|
2015-01-20 14:48:48 +01:00
|
|
|
if( !preamble.isEmpty())
|
2015-01-30 01:34:17 +11:00
|
|
|
addPreamble( aFragmentShaderSource, preamble );
|
2014-04-15 00:55:07 +02:00
|
|
|
char const * FragmentSourcePointer = aFragmentShaderSource.getStr();
|
|
|
|
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
|
|
|
|
glCompileShader(FragmentShaderID);
|
|
|
|
|
|
|
|
// Check Fragment Shader
|
|
|
|
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
|
2014-11-18 21:17:52 +00:00
|
|
|
if (!Result)
|
|
|
|
return LogCompilerError(FragmentShaderID, "fragment",
|
|
|
|
rFragmentShaderName, true);
|
2014-04-15 00:55:07 +02:00
|
|
|
|
|
|
|
// Link the program
|
|
|
|
GLint ProgramID = glCreateProgram();
|
|
|
|
glAttachShader(ProgramID, VertexShaderID);
|
|
|
|
glAttachShader(ProgramID, FragmentShaderID);
|
|
|
|
glLinkProgram(ProgramID);
|
|
|
|
|
2014-08-06 23:49:30 +02:00
|
|
|
glDeleteShader(VertexShaderID);
|
|
|
|
glDeleteShader(FragmentShaderID);
|
|
|
|
|
2014-04-15 00:55:07 +02:00
|
|
|
// Check the program
|
|
|
|
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
|
2014-11-18 21:17:52 +00:00
|
|
|
if (!Result)
|
|
|
|
return LogCompilerError(ProgramID, "program", "<both>", false);
|
2014-04-15 00:55:07 +02:00
|
|
|
|
2014-11-14 15:43:44 +01:00
|
|
|
CHECK_GL_ERROR();
|
2014-04-15 00:55:07 +02:00
|
|
|
return ProgramID;
|
|
|
|
}
|
|
|
|
|
2014-09-17 08:04:36 +02:00
|
|
|
void OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer, const bool bFlip)
|
2014-04-18 15:24:25 +02:00
|
|
|
{
|
|
|
|
long nBmpWidth = rBitmapEx.GetSizePixel().Width();
|
|
|
|
long nBmpHeight = rBitmapEx.GetSizePixel().Height();
|
|
|
|
|
|
|
|
Bitmap aBitmap (rBitmapEx.GetBitmap());
|
|
|
|
AlphaMask aAlpha (rBitmapEx.GetAlpha());
|
|
|
|
Bitmap::ScopedReadAccess pReadAccces( aBitmap );
|
|
|
|
AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha );
|
|
|
|
size_t i = 0;
|
2014-09-17 08:04:36 +02:00
|
|
|
for (long ny = (bFlip ? nBmpHeight - 1 : 0); (bFlip ? ny >= 0 : ny < nBmpHeight); (bFlip ? ny-- : ny++))
|
2014-04-18 15:24:25 +02:00
|
|
|
{
|
|
|
|
Scanline pAScan = pAlphaReadAccess ? pAlphaReadAccess->GetScanline(ny) : 0;
|
|
|
|
for(long nx = 0; nx < nBmpWidth; nx++)
|
|
|
|
{
|
|
|
|
BitmapColor aCol = pReadAccces->GetColor( ny, nx );
|
2014-08-04 12:04:10 +02:00
|
|
|
o_pRGBABuffer[i++] = aCol.GetRed();
|
|
|
|
o_pRGBABuffer[i++] = aCol.GetGreen();
|
|
|
|
o_pRGBABuffer[i++] = aCol.GetBlue();
|
|
|
|
o_pRGBABuffer[i++] = pAScan ? 255 - *pAScan++ : 255;
|
2014-04-18 15:24:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:31:05 +02:00
|
|
|
void OpenGLHelper::renderToFile(long nWidth, long nHeight, const OUString& rFileName)
|
|
|
|
{
|
|
|
|
boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nWidth*nHeight*4]);
|
|
|
|
glReadPixels(0, 0, nWidth, nHeight, GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.get());
|
|
|
|
BitmapEx aBitmap = ConvertBGRABufferToBitmapEx(pBuffer.get(), nWidth, nHeight);
|
|
|
|
try {
|
|
|
|
vcl::PNGWriter aWriter( aBitmap );
|
2015-01-07 09:28:42 +02:00
|
|
|
SvFileStream sOutput( rFileName, StreamMode::WRITE );
|
2014-05-09 00:31:05 +02:00
|
|
|
aWriter.Write( sOutput );
|
|
|
|
sOutput.Close();
|
|
|
|
} catch (...) {
|
|
|
|
SAL_WARN("vcl.opengl", "Error writing png to " << rFileName);
|
|
|
|
}
|
2014-11-14 15:43:44 +01:00
|
|
|
|
|
|
|
CHECK_GL_ERROR();
|
2014-05-09 00:31:05 +02:00
|
|
|
}
|
|
|
|
|
2014-04-27 20:25:52 +02:00
|
|
|
BitmapEx OpenGLHelper::ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight)
|
|
|
|
{
|
|
|
|
assert(pBuffer);
|
|
|
|
Bitmap aBitmap( Size(nWidth, nHeight), 24 );
|
|
|
|
AlphaMask aAlpha( Size(nWidth, nHeight) );
|
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
|
|
|
|
AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha );
|
|
|
|
|
|
|
|
size_t nCurPos = 0;
|
|
|
|
for( int y = 0; y < nHeight; ++y)
|
|
|
|
{
|
|
|
|
Scanline pScan = pWriteAccess->GetScanline(y);
|
|
|
|
Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y);
|
|
|
|
for( int x = 0; x < nWidth; ++x )
|
|
|
|
{
|
|
|
|
*pScan++ = pBuffer[nCurPos];
|
|
|
|
*pScan++ = pBuffer[nCurPos+1];
|
|
|
|
*pScan++ = pBuffer[nCurPos+2];
|
|
|
|
|
|
|
|
nCurPos += 3;
|
|
|
|
*pAlphaScan++ = static_cast<sal_uInt8>( 255 - pBuffer[nCurPos++] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BitmapEx(aBitmap, aAlpha);
|
|
|
|
}
|
|
|
|
|
2014-04-29 08:27:58 +03:00
|
|
|
const char* OpenGLHelper::GLErrorString(GLenum errorCode)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
GLenum code;
|
|
|
|
const char *string;
|
|
|
|
} errors[]=
|
|
|
|
{
|
|
|
|
/* GL */
|
|
|
|
{GL_NO_ERROR, "no error"},
|
|
|
|
{GL_INVALID_ENUM, "invalid enumerant"},
|
|
|
|
{GL_INVALID_VALUE, "invalid value"},
|
|
|
|
{GL_INVALID_OPERATION, "invalid operation"},
|
|
|
|
{GL_STACK_OVERFLOW, "stack overflow"},
|
|
|
|
{GL_STACK_UNDERFLOW, "stack underflow"},
|
|
|
|
{GL_OUT_OF_MEMORY, "out of memory"},
|
2014-08-26 19:09:04 +02:00
|
|
|
{GL_INVALID_FRAMEBUFFER_OPERATION, "invalid framebuffer operation"},
|
2014-04-29 08:27:58 +03:00
|
|
|
|
|
|
|
{0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; errors[i].string; i++)
|
|
|
|
{
|
|
|
|
if (errors[i].code == errorCode)
|
|
|
|
{
|
|
|
|
return errors[i].string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-11 18:04:01 +02:00
|
|
|
std::ostream& operator<<(std::ostream& rStrm, const glm::vec4& rPos)
|
|
|
|
{
|
|
|
|
rStrm << "( " << rPos[0] << ", " << rPos[1] << ", " << rPos[2] << ", " << rPos[3] << ")";
|
|
|
|
return rStrm;
|
|
|
|
}
|
|
|
|
|
2014-05-23 22:30:24 +02:00
|
|
|
std::ostream& operator<<(std::ostream& rStrm, const glm::vec3& rPos)
|
|
|
|
{
|
|
|
|
rStrm << "( " << rPos[0] << ", " << rPos[1] << ", " << rPos[2] << ")";
|
|
|
|
return rStrm;
|
|
|
|
}
|
|
|
|
|
2014-05-11 18:04:01 +02:00
|
|
|
std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
rStrm << "\n( ";
|
|
|
|
for(int j = 0; j < 4; ++j)
|
|
|
|
{
|
|
|
|
rStrm << rMatrix[j][i];
|
|
|
|
rStrm << " ";
|
|
|
|
}
|
|
|
|
rStrm << ")\n";
|
|
|
|
}
|
|
|
|
return rStrm;
|
|
|
|
}
|
|
|
|
|
2014-08-08 04:52:38 +02:00
|
|
|
void OpenGLHelper::createFramebuffer(long nWidth, long nHeight, GLuint& nFramebufferId,
|
|
|
|
GLuint& nRenderbufferDepthId, GLuint& nRenderbufferColorId, bool bRenderbuffer)
|
2014-05-21 00:41:37 +02:00
|
|
|
{
|
2014-05-21 14:23:07 +02:00
|
|
|
// create a renderbuffer for depth attachment
|
|
|
|
glGenRenderbuffers(1, &nRenderbufferDepthId);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferDepthId);
|
2014-05-21 00:41:37 +02:00
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, nWidth, nHeight);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
|
|
|
2014-08-08 04:52:38 +02:00
|
|
|
if(bRenderbuffer)
|
|
|
|
{
|
|
|
|
// create a renderbuffer for color attachment
|
|
|
|
glGenRenderbuffers(1, &nRenderbufferColorId);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferColorId);
|
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, nWidth, nHeight);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glGenTextures(1, &nRenderbufferColorId);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, nRenderbufferColorId);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, nWidth, nHeight, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_TEXTURE_2D, nRenderbufferColorId, 0);
|
|
|
|
}
|
2014-05-21 00:41:37 +02:00
|
|
|
|
2014-08-08 04:52:38 +02:00
|
|
|
// create a framebuffer object and attach renderbuffer
|
2014-05-21 00:41:37 +02:00
|
|
|
glGenFramebuffers(1, &nFramebufferId);
|
|
|
|
glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, nFramebufferId);
|
2014-12-23 14:39:22 +02:00
|
|
|
// attach a renderbuffer to FBO color attachment point
|
2014-05-21 14:23:07 +02:00
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferColorId);
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, nRenderbufferColorId);
|
2014-05-21 00:41:37 +02:00
|
|
|
glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
// attach a renderbuffer to depth attachment point
|
2014-05-21 14:23:07 +02:00
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, nRenderbufferDepthId);
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, nRenderbufferDepthId);
|
2014-08-26 18:02:58 +02:00
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
{
|
|
|
|
SAL_WARN("vcl.opengl", "invalid framebuffer status");
|
|
|
|
}
|
2014-05-21 00:41:37 +02:00
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2014-11-14 15:43:44 +01:00
|
|
|
|
|
|
|
CHECK_GL_ERROR();
|
2014-05-21 00:41:37 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 14:20:35 +02:00
|
|
|
float OpenGLHelper::getGLVersion()
|
|
|
|
{
|
|
|
|
float fVersion = 1.0;
|
|
|
|
const GLubyte* aVersion = glGetString( GL_VERSION );
|
|
|
|
if( aVersion && aVersion[0] )
|
|
|
|
{
|
|
|
|
fVersion = aVersion[0] - '0';
|
|
|
|
if( aVersion[1] == '.' && aVersion[2] )
|
|
|
|
{
|
|
|
|
fVersion += (aVersion[2] - '0')/10.0;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 15:43:44 +01:00
|
|
|
|
|
|
|
CHECK_GL_ERROR();
|
2014-07-20 14:20:35 +02:00
|
|
|
return fVersion;
|
|
|
|
}
|
|
|
|
|
2014-08-18 15:38:04 +02:00
|
|
|
void OpenGLHelper::checkGLError(const char* pFile, size_t nLine)
|
|
|
|
{
|
|
|
|
GLenum glErr = glGetError();
|
2014-11-17 00:28:29 +01:00
|
|
|
if (glErr != GL_NO_ERROR)
|
2014-08-18 15:38:04 +02:00
|
|
|
{
|
|
|
|
const char* sError = OpenGLHelper::GLErrorString(glErr);
|
|
|
|
|
|
|
|
if (sError)
|
|
|
|
SAL_WARN("vcl.opengl", "GL Error #" << glErr << "(" << sError << ") in File " << pFile << " at line: " << nLine);
|
|
|
|
else
|
|
|
|
SAL_WARN("vcl.opengl", "GL Error #" << glErr << " (no message available) in File " << pFile << " at line: " << nLine);
|
2014-08-26 18:02:58 +02:00
|
|
|
|
|
|
|
glErr = glGetError();
|
2014-08-18 15:38:04 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-11 18:04:01 +02:00
|
|
|
|
2014-11-20 09:52:03 +01:00
|
|
|
bool OpenGLHelper::isDeviceBlacklisted()
|
|
|
|
{
|
|
|
|
static bool bSet = false;
|
|
|
|
static bool bBlacklisted = true; // assume the worst
|
|
|
|
if (!bSet)
|
|
|
|
{
|
|
|
|
#if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID
|
|
|
|
X11OpenGLDeviceInfo aInfo;
|
|
|
|
bBlacklisted = aInfo.isDeviceBlocked();
|
|
|
|
SAL_INFO("vcl.opengl", "blacklisted: " << bBlacklisted);
|
2014-11-24 16:46:15 +01:00
|
|
|
#elif defined( _WIN32 )
|
|
|
|
WinOpenGLDeviceInfo aInfo;
|
|
|
|
bBlacklisted = aInfo.isDeviceBlocked();
|
2014-11-20 09:52:03 +01:00
|
|
|
#else
|
|
|
|
bBlacklisted = false;
|
|
|
|
#endif
|
|
|
|
bSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bBlacklisted;
|
|
|
|
}
|
|
|
|
|
2014-11-02 00:12:21 +01:00
|
|
|
bool OpenGLHelper::supportsVCLOpenGL()
|
|
|
|
{
|
2014-11-10 16:02:31 +00:00
|
|
|
static bool bDisableGL = !!getenv("SAL_DISABLEGL");
|
2014-11-20 09:52:03 +01:00
|
|
|
bool bBlacklisted = isDeviceBlacklisted();
|
2014-11-10 16:02:31 +00:00
|
|
|
|
2014-11-20 09:52:03 +01:00
|
|
|
if (bDisableGL || bBlacklisted)
|
2014-11-10 16:02:31 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLHelper::isVCLOpenGLEnabled()
|
|
|
|
{
|
2014-12-18 10:13:40 +01:00
|
|
|
/**
|
|
|
|
* The !bSet part should only be called once! Changing the results in the same
|
|
|
|
* run will mix OpenGL and normal rendering.
|
|
|
|
*/
|
|
|
|
static bool bSet = false;
|
|
|
|
static bool bEnable = false;
|
|
|
|
static bool bForceOpenGL = false;
|
2015-01-24 14:26:25 +11:00
|
|
|
|
|
|
|
// If we are a console app, then we don't use OpenGL
|
|
|
|
if ( Application::IsConsoleOnly() )
|
|
|
|
return false;
|
|
|
|
|
2014-12-18 10:13:40 +01:00
|
|
|
if (bSet)
|
|
|
|
{
|
|
|
|
return bForceOpenGL || bEnable;
|
|
|
|
}
|
2014-12-01 01:18:25 +01:00
|
|
|
/*
|
|
|
|
* There are a number of cases that these environment variables cover:
|
|
|
|
* * SAL_FORCEGL forces OpenGL independent of any other option
|
|
|
|
* * SAL_DISABLEGL or a blacklisted driver avoid the use of OpenGL if SAL_FORCEGL is not set
|
|
|
|
* * SAL_ENABLEGL overrides VCL_HIDE_WINDOWS and the configuration variable
|
|
|
|
* * the configuration variable is checked if no environment variable is set
|
|
|
|
*/
|
2014-12-18 10:13:40 +01:00
|
|
|
|
|
|
|
bSet = true;
|
|
|
|
bForceOpenGL = !!getenv("SAL_FORCEGL") || officecfg::Office::Common::VCL::ForceOpenGL::get();
|
2014-12-01 01:18:25 +01:00
|
|
|
if (bForceOpenGL)
|
|
|
|
return true;
|
|
|
|
|
2014-11-10 16:02:31 +00:00
|
|
|
if (!supportsVCLOpenGL())
|
2014-12-18 10:13:40 +01:00
|
|
|
{
|
2014-11-10 16:02:31 +00:00
|
|
|
return false;
|
2014-12-18 10:13:40 +01:00
|
|
|
}
|
2014-11-12 06:02:48 +01:00
|
|
|
|
|
|
|
static bool bEnableGLEnv = !!getenv("SAL_ENABLEGL");
|
2014-11-16 16:59:04 +01:00
|
|
|
|
2014-12-18 10:13:40 +01:00
|
|
|
bEnable = bEnableGLEnv;
|
2014-11-16 16:59:04 +01:00
|
|
|
|
|
|
|
static bool bDuringBuild = getenv("VCL_HIDE_WINDOWS");
|
|
|
|
if (bDuringBuild && !bEnable /* env. enable overrides */)
|
|
|
|
bEnable = false;
|
|
|
|
else if (officecfg::Office::Common::VCL::UseOpenGL::get())
|
|
|
|
bEnable = true;
|
|
|
|
|
2014-11-10 16:02:31 +00:00
|
|
|
return bEnable;
|
2014-11-02 00:12:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 19:10:59 +01:00
|
|
|
#if defined UNX && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS)
|
2014-11-04 17:31:12 -05:00
|
|
|
|
|
|
|
bool OpenGLHelper::GetVisualInfo(Display* pDisplay, int nScreen, XVisualInfo& rVI)
|
|
|
|
{
|
|
|
|
XVisualInfo* pVI;
|
|
|
|
int aAttrib[] = { GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
|
|
|
GLX_DEPTH_SIZE, 24,
|
2014-11-29 02:16:41 +01:00
|
|
|
GLX_STENCIL_SIZE, 8,
|
2014-11-04 17:31:12 -05:00
|
|
|
None };
|
|
|
|
|
|
|
|
pVI = glXChooseVisual( pDisplay, nScreen, aAttrib );
|
|
|
|
if( !pVI )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
rVI = *pVI;
|
|
|
|
XFree( pVI );
|
|
|
|
|
2014-11-14 15:43:44 +01:00
|
|
|
CHECK_GL_ERROR();
|
2014-11-04 17:31:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-08 13:14:14 -05:00
|
|
|
GLXFBConfig OpenGLHelper::GetPixmapFBConfig( Display* pDisplay, bool& bInverted )
|
|
|
|
{
|
|
|
|
int nScreen = DefaultScreen( pDisplay );
|
|
|
|
GLXFBConfig *aFbConfigs;
|
|
|
|
int i, nFbConfigs, nValue;
|
|
|
|
|
|
|
|
aFbConfigs = glXGetFBConfigs( pDisplay, nScreen, &nFbConfigs );
|
|
|
|
for( i = 0; i < nFbConfigs; i++ )
|
|
|
|
{
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_DRAWABLE_TYPE, &nValue );
|
|
|
|
if( !(nValue & GLX_PIXMAP_BIT) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_BIND_TO_TEXTURE_TARGETS_EXT, &nValue );
|
|
|
|
if( !(nValue & GLX_TEXTURE_2D_BIT_EXT) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_DEPTH_SIZE, &nValue );
|
|
|
|
if( nValue != 24 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_RED_SIZE, &nValue );
|
|
|
|
if( nValue != 8 )
|
|
|
|
continue;
|
|
|
|
SAL_INFO( "vcl.opengl", "Red is " << nValue );
|
|
|
|
|
|
|
|
// TODO: lfrb: Make it configurable wrt RGB/RGBA
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &nValue );
|
|
|
|
if( nValue == False )
|
|
|
|
{
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &nValue );
|
|
|
|
if( nValue == False )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
glXGetFBConfigAttrib( pDisplay, aFbConfigs[i], GLX_Y_INVERTED_EXT, &nValue );
|
|
|
|
bInverted = (nValue == True) ? true : false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i == nFbConfigs )
|
|
|
|
{
|
|
|
|
SAL_WARN( "vcl.opengl", "Unable to find FBconfig for pixmap texturing" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-14 15:43:44 +01:00
|
|
|
CHECK_GL_ERROR();
|
2014-11-08 13:14:14 -05:00
|
|
|
return aFbConfigs[i];
|
|
|
|
}
|
|
|
|
|
2014-11-04 17:31:12 -05:00
|
|
|
#endif
|
|
|
|
|
2014-04-15 00:55:07 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|