diff options
author | Emmanuel Gil Peyrot <emmanuel.peyrot@collabora.com> | 2015-12-09 21:39:31 +0000 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2015-12-11 15:29:01 +0100 |
commit | facfbeb5cbff191da956827bc37df7bc74ed0b81 (patch) | |
tree | 7d5a2a79a454dda962942540f7740b528e4875f6 | |
parent | 129b8b85c945091665ad3ae1c4fa3b6d9a157d25 (diff) |
opengl: Add Geometry Shader support to OpenGLHelper
This is the ground work for some later transitions in slideshow.
Change-Id: Ib200cf7fabd579256a5255b0fb5d8c4accf7d24b
-rw-r--r-- | include/vcl/opengl/OpenGLHelper.hxx | 5 | ||||
-rw-r--r-- | slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx | 8 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLHelper.cxx | 62 |
3 files changed, 68 insertions, 7 deletions
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx index 1e2741102dc8..a7f139cf6440 100644 --- a/include/vcl/opengl/OpenGLHelper.hxx +++ b/include/vcl/opengl/OpenGLHelper.hxx @@ -43,7 +43,10 @@ public: static rtl::OString GetDigest(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const rtl::OString& preamble = "" ); - static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const rtl::OString& preamble = "", const rtl::OString& rDigest = "" ); + static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OUString& rGeometryShaderName, const rtl::OString& preamble, const rtl::OString& rDigest ); + static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const rtl::OString& preamble, const rtl::OString& rDigest ); + static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, const OUString& rGeometryShaderName); + static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName); /** * The caller is responsible for allocate the memory for the RGBA buffer, before call diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx index 9bd4476f2a93..387e96e585fd 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx @@ -366,10 +366,12 @@ bool OGLTransitionerImpl::initWindowFromSlideShowView( const Reference< presenta aDeviceParams[1] >>= aVal; mpContext = OpenGLContext::Create(); - mpContext->requestLegacyContext(); - if( !mpContext->init( reinterpret_cast< vcl::Window* >( aVal ) ) ) - return false; + if( !mpContext->init( reinterpret_cast< vcl::Window* >( aVal ) ) ) { + mpContext->requestLegacyContext(); + if( !mpContext->init( reinterpret_cast< vcl::Window* >( aVal ) ) ) + return false; + } SAL_INFO("slideshow", "created the context"); CHECK_GL_ERROR(); diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index c7cbfa354d15..f1e1660beaaf 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -302,12 +302,15 @@ namespace OString createFileName( const OUString& rVertexShaderName, const OUString& rFragmentShaderName, + const OUString& rGeometryShaderName, const OString& rDigest ) { OString aFileName; aFileName += getCacheFolder(); aFileName += rtl::OUStringToOString( rVertexShaderName, RTL_TEXTENCODING_UTF8 ) + "-"; aFileName += rtl::OUStringToOString( rFragmentShaderName, RTL_TEXTENCODING_UTF8 ) + "-"; + if (!rGeometryShaderName.isEmpty()) + aFileName += rtl::OUStringToOString( rGeometryShaderName, RTL_TEXTENCODING_UTF8 ) + "-"; aFileName += rDigest + ".bin"; return aFileName; } @@ -376,6 +379,7 @@ rtl::OString OpenGLHelper::GetDigest( const OUString& rVertexShaderName, GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName, + const OUString& rGeometryShaderName, const OString& preamble, const OString& rDigest) { @@ -383,18 +387,23 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, gbInShaderCompile = true; + bool bHasGeometryShader = !rGeometryShaderName.isEmpty(); + // create the program object GLint ProgramID = glCreateProgram(); // read shaders from file OString aVertexShaderSource = getShaderSource(rVertexShaderName); OString aFragmentShaderSource = getShaderSource(rFragmentShaderName); + OString aGeometryShaderSource; + if (bHasGeometryShader) + aGeometryShaderSource = getShaderSource(rGeometryShaderName); GLint bBinaryResult = GL_FALSE; if( GLEW_ARB_get_program_binary && !rDigest.isEmpty() ) { OString aFileName = - createFileName(rVertexShaderName, rFragmentShaderName, rDigest); + createFileName(rVertexShaderName, rFragmentShaderName, rGeometryShaderName, rDigest); bBinaryResult = loadProgramBinary(ProgramID, aFileName); VCL_GL_INFO("Load binary shader from '" << aFileName << "'" << bBinaryResult); CHECK_GL_ERROR(); @@ -403,10 +412,16 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, if( bBinaryResult != GL_FALSE ) return ProgramID; - VCL_GL_INFO("Load shader: vertex " << rVertexShaderName << " fragment " << rFragmentShaderName); + if (bHasGeometryShader) + VCL_GL_INFO("Load shader: vertex " << rVertexShaderName << " fragment " << rFragmentShaderName << " geometry " << rGeometryShaderName); + else + VCL_GL_INFO("Load shader: vertex " << rVertexShaderName << " fragment " << rFragmentShaderName); // Create the shaders GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); + GLuint GeometryShaderID = 0; + if (bHasGeometryShader) + GeometryShaderID = glCreateShader(GL_GEOMETRY_SHADER); GLint Result = GL_FALSE; @@ -436,9 +451,27 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, return LogCompilerError(FragmentShaderID, "fragment", rFragmentShaderName, true); + if (bHasGeometryShader) + { + // Compile Geometry Shader + if( !preamble.isEmpty()) + addPreamble( aGeometryShaderSource, preamble ); + char const * GeometrySourcePointer = aGeometryShaderSource.getStr(); + glShaderSource(GeometryShaderID, 1, &GeometrySourcePointer , nullptr); + glCompileShader(GeometryShaderID); + + // Check Geometry Shader + glGetShaderiv(GeometryShaderID, GL_COMPILE_STATUS, &Result); + if (!Result) + return LogCompilerError(GeometryShaderID, "geometry", + rGeometryShaderName, true); + } + // Link the program glAttachShader(ProgramID, VertexShaderID); glAttachShader(ProgramID, FragmentShaderID); + if (bHasGeometryShader) + glAttachShader(ProgramID, GeometryShaderID); if( GLEW_ARB_get_program_binary && !rDigest.isEmpty() ) { @@ -451,7 +484,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, return LogCompilerError(ProgramID, "program", "<both>", false); } OString aFileName = - createFileName(rVertexShaderName, rFragmentShaderName, rDigest); + createFileName(rVertexShaderName, rFragmentShaderName, rGeometryShaderName, rDigest); saveProgramBinary(ProgramID, aFileName); } else @@ -461,6 +494,8 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, glDeleteShader(VertexShaderID); glDeleteShader(FragmentShaderID); + if (bHasGeometryShader) + glDeleteShader(GeometryShaderID); // Check the program glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); @@ -476,6 +511,27 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, return ProgramID; } +GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, + const OUString& rFragmentShaderName, + const OString& preamble, + const OString& rDigest) +{ + return LoadShaders(rVertexShaderName, rFragmentShaderName, OUString(), preamble, rDigest); +} + +GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, + const OUString& rFragmentShaderName, + const OUString& rGeometryShaderName) +{ + return LoadShaders(rVertexShaderName, rFragmentShaderName, rGeometryShaderName, OString(), OString()); +} + +GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName, + const OUString& rFragmentShaderName) +{ + return LoadShaders(rVertexShaderName, rFragmentShaderName, OUString(), "", ""); +} + void OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer, const bool bFlip) { long nBmpWidth = rBitmapEx.GetSizePixel().Width(); |