OpenColorIO: Update glsl implementation to be ready for ogl 3.3 core

This commit is contained in:
Clément Foucault 2017-02-24 12:38:35 +01:00
parent 1e7475a5d7
commit 1f453a8909
5 changed files with 58 additions and 7 deletions

View File

@ -66,6 +66,7 @@ if(WITH_OPENCOLORIO)
endif()
data_to_c_simple(gpu_shader_display_transform.glsl SRC)
data_to_c_simple(gpu_shader_display_transform_vertex.glsl SRC)
endif()

View File

@ -10,6 +10,15 @@ uniform float image_texture_width;
uniform float image_texture_height;
#endif
#if __VERSION__ < 130
varying vec2 texCoord_interp;
#define fragColor gl_FragColor
#else
in vec2 texCoord_interp;
out vec4 fragColor;
#define texture2D texture
#endif
#ifdef USE_CURVE_MAPPING
/* Curve mapping parameters
*
@ -143,7 +152,7 @@ vec4 apply_dither(vec2 st, vec4 col)
void main()
{
vec4 col = texture2D(image_texture, gl_TexCoord[0].st);
vec4 col = texture2D(image_texture, texCoord_interp.st);
#ifdef USE_CURVE_MAPPING
col = curvemapping_evaluate_premulRGBF(col);
#endif
@ -165,8 +174,8 @@ void main()
vec4 result = OCIODisplay(col, lut3d_texture);
#ifdef USE_DITHER
result = apply_dither(gl_TexCoord[0].st, result);
result = apply_dither(texCoord_interp.st, result);
#endif
gl_FragColor = result;
fragColor = result;
}

View File

@ -0,0 +1,18 @@
uniform mat4 ModelViewProjectionMatrix;
#if __VERSION__ == 120
attribute vec2 texCoord;
attribute vec2 pos;
varying vec2 texCoord_interp;
#else
in vec2 texCoord;
in vec2 pos;
out vec2 texCoord_interp;
#endif
void main()
{
gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
texCoord_interp = texCoord;
}

View File

@ -58,6 +58,7 @@ using namespace OCIO_NAMESPACE;
static const int LUT3D_EDGE_SIZE = 64;
extern "C" char datatoc_gpu_shader_display_transform_glsl[];
extern "C" char datatoc_gpu_shader_display_transform_vertex_glsl[];
/* **** OpenGL drawing routines using GLSL for color space transform ***** */
@ -89,6 +90,7 @@ typedef struct OCIO_GLSLDrawState {
/* GLSL stuff */
GLuint ocio_shader;
GLuint vert_shader;
GLuint program;
/* Previous OpenGL state. */
@ -116,14 +118,15 @@ static GLuint compileShaderText(GLenum shaderType, const char *text)
return shader;
}
static GLuint linkShaders(GLuint ocio_shader)
static GLuint linkShaders(GLuint ocio_shader, GLuint vert_shader)
{
if (!ocio_shader)
if (!ocio_shader || !vert_shader)
return 0;
GLuint program = glCreateProgram();
glAttachShader(program, ocio_shader);
glAttachShader(program, vert_shader);
glLinkProgram(program);
@ -339,6 +342,25 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc
glDeleteShader(state->ocio_shader);
}
if (state->vert_shader) {
glDeleteShader(state->vert_shader);
}
/* Vertex shader */
std::ostringstream osv;
if (supportGLSL13()) {
osv << "#version 130\n";
}
else {
osv << "#version 120\n";
}
osv << datatoc_gpu_shader_display_transform_vertex_glsl;
state->vert_shader = compileShaderText(GL_VERTEX_SHADER, osv.str().c_str());
/* Fragment shader */
std::ostringstream os;
if (supportGLSL13()) {
@ -366,8 +388,8 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc
state->ocio_shader = compileShaderText(GL_FRAGMENT_SHADER, os.str().c_str());
if (state->ocio_shader) {
state->program = linkShaders(state->ocio_shader);
if (state->ocio_shader && state->vert_shader) {
state->program = linkShaders(state->ocio_shader, state->vert_shader);
}
state->curve_mapping_used = use_curve_mapping;

View File

@ -1,6 +1,7 @@
uniform mat4 ModelViewProjectionMatrix;
/* Keep in sync with intern/opencolorio/gpu_shader_display_transform_vertex.glsl */
#if __VERSION__ == 120
attribute vec2 texCoord;
attribute vec2 pos;