Skip to content

Commit

Permalink
IOSupport/glsl: update from OCIO 2.1.1
Browse files Browse the repository at this point in the history
just to keep up to date - no major change
  • Loading branch information
devernay committed Jan 22, 2022
1 parent c6ad47b commit 99d4471
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion IOSupport/GenericOCIOOpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ GenericOCIO::applyGL(const Texture* srcImg,
glBuilder->allocateAllTextures(1);

// Step 5: Build the fragment shader program
glBuilder->buildProgram(g_fragShaderText);
glBuilder->buildProgram(g_fragShaderText, false);
}

glEnable(GL_TEXTURE_2D);
Expand Down
6 changes: 3 additions & 3 deletions IOSupport/glsl.README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
glsl.cpp and glsl.h are from OpenCOlorIO 2.1.0:
https://github.com/AcademySoftwareFoundation/OpenColorIO/tree/v2.1.0/src/libutils/oglapphelpers
glsl.cpp and glsl.h are from OpenCOlorIO 2.1.1:
https://github.com/AcademySoftwareFoundation/OpenColorIO/tree/v2.1.1/src/libutils/oglapphelpers

gsls.cpp was modified to use glad.h indlead of GL/glew.h, in order to avoid using another external library.

These files are Copyright Contributors to the OpenColorIO Project.
They are distributed under the BSD 3-Clause License:
https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/v2.1.0/LICENSE
https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/v2.1.1/LICENSE
30 changes: 21 additions & 9 deletions IOSupport/glsl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.


#if 1
#include <glad.h>
#define HAVE_GLU 1
Expand Down Expand Up @@ -460,20 +461,31 @@ void OpenGLBuilder::useAllUniforms()

std::string OpenGLBuilder::getGLSLVersionString()
{
if (m_shaderDesc->getLanguage() == GPU_LANGUAGE_GLSL_1_3)
switch (m_shaderDesc->getLanguage())
{
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_MSL_2_0:
// That's the minimal version supported.
return "#version 120";
case GPU_LANGUAGE_GLSL_1_3:
return "#version 130";
}
else if (m_shaderDesc->getLanguage() == GPU_LANGUAGE_GLSL_4_0)
{
case GPU_LANGUAGE_GLSL_4_0:
return "#version 400 core";
case GPU_LANGUAGE_GLSL_ES_1_0:
return "#version 100";
case GPU_LANGUAGE_GLSL_ES_3_0:
return "#version 300 es";
case GPU_LANGUAGE_CG:
case GPU_LANGUAGE_HLSL_DX11:
case LANGUAGE_OSL_1:
default:
// These are all impossible in OpenGL contexts.
// The shader will be unusable, so let's throw
throw Exception("Invalid shader language for OpenGLBuilder");
}

// That's the minimal version supported.
return "#version 120";
}

unsigned OpenGLBuilder::buildProgram(const std::string & clientShaderProgram)
unsigned OpenGLBuilder::buildProgram(const std::string & clientShaderProgram, bool standaloneShader)
{
const std::string shaderCacheID = m_shaderDesc->getCacheID();
if(shaderCacheID!=m_shaderCacheID)
Expand All @@ -486,7 +498,7 @@ unsigned OpenGLBuilder::buildProgram(const std::string & clientShaderProgram)

std::ostringstream os;
os << getGLSLVersionString() << std::endl
<< m_shaderDesc->getShaderText() << std::endl
<< (!standaloneShader ? m_shaderDesc->getShaderText() : "") << std::endl
<< clientShaderProgram << std::endl;

if(m_verbose)
Expand Down
2 changes: 1 addition & 1 deletion IOSupport/glsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class OpenGLBuilder

// Build the complete shader program which includes the OCIO shader program
// and the client shader program.
unsigned buildProgram(const std::string & clientShaderProgram);
unsigned buildProgram(const std::string & clientShaderProgram, bool standaloneShader);
void useProgram();
unsigned getProgramHandle();

Expand Down

0 comments on commit 99d4471

Please sign in to comment.