mirror of
https://github.com/brl/mutter.git
synced 2025-02-08 17:44:09 +00:00
add cogl-glsl-shader files to aid backporting patches
To aid with backporting patches from master made after the deprecated CoglShader api was removed this patch adds the cogl-glsl- files that have been added on master so we should get less conflicts when cherry picking.
This commit is contained in:
parent
258aba3836
commit
62b472f4f5
@ -336,6 +336,9 @@ cogl_sources_c = \
|
|||||||
$(srcdir)/cogl-pipeline-layer-state.c \
|
$(srcdir)/cogl-pipeline-layer-state.c \
|
||||||
$(srcdir)/cogl-pipeline-state-private.h \
|
$(srcdir)/cogl-pipeline-state-private.h \
|
||||||
$(srcdir)/cogl-pipeline-debug.c \
|
$(srcdir)/cogl-pipeline-debug.c \
|
||||||
|
$(srcdir)/cogl-glsl-shader.c \
|
||||||
|
$(srcdir)/cogl-glsl-shader-private.h \
|
||||||
|
$(srcdir)/cogl-glsl-shader-boilerplate.h \
|
||||||
$(srcdir)/cogl-pipeline-snippet-private.h \
|
$(srcdir)/cogl-pipeline-snippet-private.h \
|
||||||
$(srcdir)/cogl-pipeline-snippet.c \
|
$(srcdir)/cogl-pipeline-snippet.c \
|
||||||
$(srcdir)/cogl-pipeline-cache.h \
|
$(srcdir)/cogl-pipeline-cache.h \
|
||||||
@ -384,7 +387,6 @@ cogl_sources_c = \
|
|||||||
$(srcdir)/cogl-flags.h \
|
$(srcdir)/cogl-flags.h \
|
||||||
$(srcdir)/cogl-bitmask.h \
|
$(srcdir)/cogl-bitmask.h \
|
||||||
$(srcdir)/cogl-bitmask.c \
|
$(srcdir)/cogl-bitmask.c \
|
||||||
$(srcdir)/cogl-shader-boilerplate.h \
|
|
||||||
$(srcdir)/cogl-shader-private.h \
|
$(srcdir)/cogl-shader-private.h \
|
||||||
$(srcdir)/cogl-shader.c \
|
$(srcdir)/cogl-shader.c \
|
||||||
$(srcdir)/cogl-gtype-private.h \
|
$(srcdir)/cogl-gtype-private.h \
|
||||||
|
35
cogl/cogl-glsl-shader-private.h
Normal file
35
cogl/cogl-glsl-shader-private.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Cogl
|
||||||
|
*
|
||||||
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Intel Corporation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _COGL_GLSL_SHADER_PRIVATE_H_
|
||||||
|
#define _COGL_GLSL_SHADER_PRIVATE_H_
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
||||||
|
GLuint shader_gl_handle,
|
||||||
|
GLenum shader_gl_type,
|
||||||
|
int n_tex_coord_attribs,
|
||||||
|
GLsizei count_in,
|
||||||
|
const char **strings_in,
|
||||||
|
const GLint *lengths_in);
|
||||||
|
|
||||||
|
#endif /* _COGL_GLSL_SHADER_PRIVATE_H_ */
|
154
cogl/cogl-glsl-shader.c
Normal file
154
cogl/cogl-glsl-shader.c
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Cogl
|
||||||
|
*
|
||||||
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Intel Corporation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Robert Bragg <robert@linux.intel.com>
|
||||||
|
* Neil Roberts <neil@linux.intel.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "cogl-context-private.h"
|
||||||
|
#include "cogl-glsl-shader-private.h"
|
||||||
|
#include "cogl-glsl-shader-boilerplate.h"
|
||||||
|
#include "cogl-internal.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
||||||
|
GLuint shader_gl_handle,
|
||||||
|
GLenum shader_gl_type,
|
||||||
|
int n_tex_coord_attribs,
|
||||||
|
GLsizei count_in,
|
||||||
|
const char **strings_in,
|
||||||
|
const GLint *lengths_in)
|
||||||
|
{
|
||||||
|
const char *vertex_boilerplate;
|
||||||
|
const char *fragment_boilerplate;
|
||||||
|
|
||||||
|
const char **strings = g_alloca (sizeof (char *) * (count_in + 3));
|
||||||
|
GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 3));
|
||||||
|
int count = 0;
|
||||||
|
char *tex_coord_declarations = NULL;
|
||||||
|
|
||||||
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
||||||
|
{
|
||||||
|
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GLES2;
|
||||||
|
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GLES2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GL;
|
||||||
|
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
||||||
|
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
|
||||||
|
{
|
||||||
|
static const char texture_3d_extension[] =
|
||||||
|
"#extension GL_OES_texture_3D : enable\n";
|
||||||
|
strings[count] = texture_3d_extension;
|
||||||
|
lengths[count++] = sizeof (texture_3d_extension) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shader_gl_type == GL_VERTEX_SHADER)
|
||||||
|
{
|
||||||
|
strings[count] = vertex_boilerplate;
|
||||||
|
lengths[count++] = strlen (vertex_boilerplate);
|
||||||
|
}
|
||||||
|
else if (shader_gl_type == GL_FRAGMENT_SHADER)
|
||||||
|
{
|
||||||
|
strings[count] = fragment_boilerplate;
|
||||||
|
lengths[count++] = strlen (fragment_boilerplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
||||||
|
n_tex_coord_attribs)
|
||||||
|
{
|
||||||
|
GString *declarations = g_string_new (NULL);
|
||||||
|
|
||||||
|
g_string_append_printf (declarations,
|
||||||
|
"varying vec4 _cogl_tex_coord[%d];\n",
|
||||||
|
n_tex_coord_attribs);
|
||||||
|
|
||||||
|
if (shader_gl_type == GL_VERTEX_SHADER)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
g_string_append_printf (declarations,
|
||||||
|
"uniform mat4 cogl_texture_matrix[%d];\n",
|
||||||
|
n_tex_coord_attribs);
|
||||||
|
|
||||||
|
for (i = 0; i < n_tex_coord_attribs; i++)
|
||||||
|
g_string_append_printf (declarations,
|
||||||
|
"attribute vec4 cogl_tex_coord%d_in;\n",
|
||||||
|
i);
|
||||||
|
}
|
||||||
|
|
||||||
|
tex_coord_declarations = g_string_free (declarations, FALSE);
|
||||||
|
strings[count] = tex_coord_declarations;
|
||||||
|
lengths[count++] = -1; /* null terminated */
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy (strings + count, strings_in, sizeof (char *) * count_in);
|
||||||
|
if (lengths_in)
|
||||||
|
memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < count_in; i++)
|
||||||
|
lengths[count + i] = -1; /* null terminated */
|
||||||
|
}
|
||||||
|
count += count_in;
|
||||||
|
|
||||||
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
|
||||||
|
{
|
||||||
|
GString *buf = g_string_new (NULL);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
g_string_append_printf (buf,
|
||||||
|
"%s shader:\n",
|
||||||
|
shader_gl_type == GL_VERTEX_SHADER ?
|
||||||
|
"vertex" : "fragment");
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
if (lengths[i] != -1)
|
||||||
|
g_string_append_len (buf, strings[i], lengths[i]);
|
||||||
|
else
|
||||||
|
g_string_append (buf, strings[i]);
|
||||||
|
|
||||||
|
g_message ("%s", buf->str);
|
||||||
|
|
||||||
|
g_string_free (buf, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
GE( ctx, glShaderSource (shader_gl_handle, count,
|
||||||
|
(const char **) strings, lengths) );
|
||||||
|
|
||||||
|
g_free (tex_coord_declarations);
|
||||||
|
}
|
@ -26,10 +26,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cogl-shader-private.h"
|
#include "cogl-shader-private.h"
|
||||||
#include "cogl-shader-boilerplate.h"
|
|
||||||
#include "cogl-internal.h"
|
#include "cogl-internal.h"
|
||||||
#include "cogl-context-private.h"
|
#include "cogl-context-private.h"
|
||||||
#include "cogl-object-private.h"
|
#include "cogl-object-private.h"
|
||||||
|
#include "cogl-glsl-shader-private.h"
|
||||||
|
#include "cogl-glsl-shader-boilerplate.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -172,121 +173,6 @@ cogl_shader_compile (CoglHandle handle)
|
|||||||
* replace it with a pipeline snippets API. */
|
* replace it with a pipeline snippets API. */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
_cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
|
|
||||||
GLenum shader_gl_type,
|
|
||||||
int n_tex_coord_attribs,
|
|
||||||
GLsizei count_in,
|
|
||||||
const char **strings_in,
|
|
||||||
const GLint *lengths_in)
|
|
||||||
{
|
|
||||||
const char *vertex_boilerplate;
|
|
||||||
const char *fragment_boilerplate;
|
|
||||||
|
|
||||||
const char **strings = g_alloca (sizeof (char *) * (count_in + 3));
|
|
||||||
GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 3));
|
|
||||||
int count = 0;
|
|
||||||
char *tex_coord_declarations = NULL;
|
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
||||||
|
|
||||||
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
||||||
{
|
|
||||||
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GLES2;
|
|
||||||
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GLES2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GL;
|
|
||||||
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
|
||||||
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
|
|
||||||
{
|
|
||||||
static const char texture_3d_extension[] =
|
|
||||||
"#extension GL_OES_texture_3D : enable\n";
|
|
||||||
strings[count] = texture_3d_extension;
|
|
||||||
lengths[count++] = sizeof (texture_3d_extension) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shader_gl_type == GL_VERTEX_SHADER)
|
|
||||||
{
|
|
||||||
strings[count] = vertex_boilerplate;
|
|
||||||
lengths[count++] = strlen (vertex_boilerplate);
|
|
||||||
}
|
|
||||||
else if (shader_gl_type == GL_FRAGMENT_SHADER)
|
|
||||||
{
|
|
||||||
strings[count] = fragment_boilerplate;
|
|
||||||
lengths[count++] = strlen (fragment_boilerplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
|
||||||
n_tex_coord_attribs)
|
|
||||||
{
|
|
||||||
GString *declarations = g_string_new (NULL);
|
|
||||||
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"varying vec4 _cogl_tex_coord[%d];\n",
|
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
if (shader_gl_type == GL_VERTEX_SHADER)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"uniform mat4 cogl_texture_matrix[%d];\n",
|
|
||||||
n_tex_coord_attribs);
|
|
||||||
|
|
||||||
for (i = 0; i < n_tex_coord_attribs; i++)
|
|
||||||
g_string_append_printf (declarations,
|
|
||||||
"attribute vec4 cogl_tex_coord%d_in;\n",
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
|
|
||||||
tex_coord_declarations = g_string_free (declarations, FALSE);
|
|
||||||
strings[count] = tex_coord_declarations;
|
|
||||||
lengths[count++] = -1; /* null terminated */
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (strings + count, strings_in, sizeof (char *) * count_in);
|
|
||||||
if (lengths_in)
|
|
||||||
memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < count_in; i++)
|
|
||||||
lengths[count + i] = -1; /* null terminated */
|
|
||||||
}
|
|
||||||
count += count_in;
|
|
||||||
|
|
||||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
|
|
||||||
{
|
|
||||||
GString *buf = g_string_new (NULL);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_string_append_printf (buf,
|
|
||||||
"%s shader:\n",
|
|
||||||
shader_gl_type == GL_VERTEX_SHADER ?
|
|
||||||
"vertex" : "fragment");
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
if (lengths[i] != -1)
|
|
||||||
g_string_append_len (buf, strings[i], lengths[i]);
|
|
||||||
else
|
|
||||||
g_string_append (buf, strings[i]);
|
|
||||||
|
|
||||||
g_message ("%s", buf->str);
|
|
||||||
|
|
||||||
g_string_free (buf, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
GE( ctx, glShaderSource (shader_gl_handle, count,
|
|
||||||
(const char **) strings, lengths) );
|
|
||||||
|
|
||||||
g_free (tex_coord_declarations);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_shader_compile_real (CoglHandle handle,
|
_cogl_shader_compile_real (CoglHandle handle,
|
||||||
int n_tex_coord_attribs)
|
int n_tex_coord_attribs)
|
||||||
@ -364,12 +250,14 @@ _cogl_shader_compile_real (CoglHandle handle,
|
|||||||
|
|
||||||
shader->gl_handle = ctx->glCreateShader (gl_type);
|
shader->gl_handle = ctx->glCreateShader (gl_type);
|
||||||
|
|
||||||
_cogl_shader_set_source_with_boilerplate (shader->gl_handle,
|
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
||||||
gl_type,
|
shader->gl_handle,
|
||||||
n_tex_coord_attribs,
|
gl_type,
|
||||||
1,
|
n_tex_coord_attribs,
|
||||||
(const char **) &shader->source,
|
1,
|
||||||
NULL);
|
(const char **)
|
||||||
|
&shader->source,
|
||||||
|
NULL);
|
||||||
|
|
||||||
GE (ctx, glCompileShader (shader->gl_handle));
|
GE (ctx, glCompileShader (shader->gl_handle));
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "cogl-program-private.h"
|
#include "cogl-program-private.h"
|
||||||
#include "cogl-pipeline-cache.h"
|
#include "cogl-pipeline-cache.h"
|
||||||
#include "cogl-pipeline-fragend-glsl-private.h"
|
#include "cogl-pipeline-fragend-glsl-private.h"
|
||||||
|
#include "cogl-glsl-shader-private.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -1074,11 +1075,12 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
|
|||||||
lengths[1] = shader_state->source->len;
|
lengths[1] = shader_state->source->len;
|
||||||
source_strings[1] = shader_state->source->str;
|
source_strings[1] = shader_state->source->str;
|
||||||
|
|
||||||
_cogl_shader_set_source_with_boilerplate (shader, GL_FRAGMENT_SHADER,
|
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
||||||
shader_state
|
shader, GL_FRAGMENT_SHADER,
|
||||||
->n_tex_coord_attribs,
|
shader_state
|
||||||
2, /* count */
|
->n_tex_coord_attribs,
|
||||||
source_strings, lengths);
|
2, /* count */
|
||||||
|
source_strings, lengths);
|
||||||
|
|
||||||
GE( ctx, glCompileShader (shader) );
|
GE( ctx, glCompileShader (shader) );
|
||||||
GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
|
GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "cogl-program-private.h"
|
#include "cogl-program-private.h"
|
||||||
#include "cogl-pipeline-vertend-glsl-private.h"
|
#include "cogl-pipeline-vertend-glsl-private.h"
|
||||||
#include "cogl-pipeline-state-private.h"
|
#include "cogl-pipeline-state-private.h"
|
||||||
|
#include "cogl-glsl-shader-private.h"
|
||||||
|
|
||||||
const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
||||||
|
|
||||||
@ -462,11 +463,12 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
|
|||||||
lengths[1] = shader_state->source->len;
|
lengths[1] = shader_state->source->len;
|
||||||
source_strings[1] = shader_state->source->str;
|
source_strings[1] = shader_state->source->str;
|
||||||
|
|
||||||
_cogl_shader_set_source_with_boilerplate (shader, GL_VERTEX_SHADER,
|
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
|
||||||
shader_state
|
shader, GL_VERTEX_SHADER,
|
||||||
->n_tex_coord_attribs,
|
shader_state
|
||||||
2, /* count */
|
->n_tex_coord_attribs,
|
||||||
source_strings, lengths);
|
2, /* count */
|
||||||
|
source_strings, lengths);
|
||||||
|
|
||||||
GE( ctx, glCompileShader (shader) );
|
GE( ctx, glCompileShader (shader) );
|
||||||
GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
|
GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user