1c449c67f6
This removes the need to maintain an array of tex_coord varyings and instead we now just emit a varying per-layer uniquely named using a layer_number infix like cogl_tex_coord0_out and cogl_tex_coord0_in. Notable this patch also had to change the journal flushing code to use pipeline layer numbers to determine the name of texture coordinate attributes. We now also break batches by using a deeper comparison of layers so such that two pipelines with the same number of layers can now cause a batch break if they use different layer numbers. This adds an internal _cogl_pipeline_layer_numbers_equal() function that takes two pipelines and returns TRUE if they have the same number of layers and all the layer numbers are the same too, otherwise it returns FALSE. Where we used to break batches based on changes to the number of layers we now break according to the status of _cogl_pipeline_layer_numbers_equal Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit e55b64a9cdc93285049d9b969bef67484c2d9fb3) Note: this will cause a temporary regression for the Cogl 1.x CoglShader api since it will break compatibility with existing shaders that reference the texture varyings from the fragment shader. The intention is to follow up with another patch to add back CoglShader compatibility.
125 lines
3.7 KiB
C
125 lines
3.7 KiB
C
/*
|
|
* 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,
|
|
const char *version_string,
|
|
GLuint shader_gl_handle,
|
|
GLenum shader_gl_type,
|
|
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 + 4));
|
|
GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4));
|
|
int count = 0;
|
|
char *tex_coord_declarations = NULL;
|
|
|
|
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE;
|
|
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE;
|
|
|
|
if (version_string)
|
|
{
|
|
strings[count] = version_string;
|
|
lengths[count++] = -1;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|