2008-05-27 17:42:50 +00:00
|
|
|
/*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Cogl
|
2008-05-27 17:42:50 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-05-27 17:42:50 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Copyright (C) 2008,2009 Intel Corporation.
|
2008-05-27 17:42:50 +00:00
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-05-27 17:42:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2009-01-29 13:40:37 +00:00
|
|
|
/* We don't want to get the remaps from the gl* functions to the
|
|
|
|
cogl_wrap_gl* functions in this file because we need to be able to
|
|
|
|
call the base version */
|
|
|
|
#define COGL_GLES2_WRAPPER_NO_REMAP 1
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-gles2-wrapper.h"
|
|
|
|
#include "cogl-fixed-vertex-shader.h"
|
|
|
|
#include "cogl-context.h"
|
2008-10-30 17:25:00 +00:00
|
|
|
#include "cogl-shader-private.h"
|
2010-10-14 15:32:13 +00:00
|
|
|
#include "cogl-shader.h"
|
2008-12-11 15:33:38 +00:00
|
|
|
#include "cogl-internal.h"
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
#define _COGL_GET_GLES2_WRAPPER(wvar, retval) \
|
|
|
|
CoglGles2Wrapper *wvar; \
|
|
|
|
{ \
|
|
|
|
CoglContext *__ctxvar = _cogl_context_get_default (); \
|
|
|
|
if (__ctxvar == NULL) return retval; \
|
2009-07-28 00:34:33 +00:00
|
|
|
wvar = &__ctxvar->drv.gles2; \
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
#define _COGL_GLES2_CHANGE_SETTING(w, var, val) \
|
|
|
|
do \
|
|
|
|
if ((w)->settings.var != (val)) \
|
|
|
|
{ \
|
|
|
|
(w)->settings.var = (val); \
|
|
|
|
(w)->settings_dirty = TRUE; \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
#define _COGL_GLES2_CHANGE_UNIFORM(w, flag, var, val) \
|
|
|
|
do \
|
|
|
|
if ((w)->var != (val)) \
|
|
|
|
{ \
|
|
|
|
(w)->var = (val); \
|
|
|
|
(w)->dirty_uniforms |= COGL_GLES2_DIRTY_ ## flag; \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
#define COGL_GLES2_WRAPPER_VERTEX_ATTRIB 0
|
2008-12-11 15:33:38 +00:00
|
|
|
#define COGL_GLES2_WRAPPER_COLOR_ATTRIB 1
|
|
|
|
#define COGL_GLES2_WRAPPER_NORMAL_ATTRIB 2
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
static GLuint
|
|
|
|
cogl_gles2_wrapper_create_shader (GLenum type, const char *source)
|
|
|
|
{
|
|
|
|
GLuint shader;
|
|
|
|
GLint source_len = strlen (source);
|
|
|
|
GLint status;
|
|
|
|
|
|
|
|
shader = glCreateShader (type);
|
|
|
|
glShaderSource (shader, 1, &source, &source_len);
|
|
|
|
glCompileShader (shader);
|
|
|
|
|
|
|
|
glGetShaderiv (shader, GL_COMPILE_STATUS, &status);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2009-05-27 22:39:18 +00:00
|
|
|
char shader_log[1024];
|
2008-05-27 17:42:50 +00:00
|
|
|
GLint len;
|
|
|
|
|
2009-05-27 22:39:18 +00:00
|
|
|
glGetShaderInfoLog (shader, sizeof (shader_log) - 1, &len, shader_log);
|
|
|
|
shader_log[len] = '\0';
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-05-27 22:39:18 +00:00
|
|
|
g_critical ("%s", shader_log);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
glDeleteShader (shader);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
static void
|
|
|
|
initialize_texture_units (CoglGles2Wrapper *w)
|
|
|
|
{
|
|
|
|
/* We save the active texture unit since we may need to temporarily
|
|
|
|
* change this to initialise each new texture unit and we want to
|
|
|
|
* restore the active unit afterwards */
|
|
|
|
int initial_active_unit = w->active_texture_unit;
|
|
|
|
GLint prev_mode;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* We will need to set the matrix mode to GL_TEXTURE to
|
|
|
|
* initialise any new texture units, so we save the current
|
|
|
|
* mode for restoring afterwards */
|
2010-06-11 13:36:38 +00:00
|
|
|
GE( _cogl_wrap_glGetIntegerv (GL_MATRIX_MODE, &prev_mode));
|
2009-02-20 15:56:57 +00:00
|
|
|
|
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
|
|
|
{
|
|
|
|
CoglGles2WrapperTextureUnit *new_unit;
|
|
|
|
|
|
|
|
new_unit = w->texture_units + i;
|
|
|
|
memset (new_unit, 0, sizeof (CoglGles2WrapperTextureUnit));
|
|
|
|
|
|
|
|
w->active_texture_unit = i;
|
2010-06-11 13:36:38 +00:00
|
|
|
GE( _cogl_wrap_glMatrixMode (GL_TEXTURE));
|
|
|
|
GE( _cogl_wrap_glLoadIdentity ());
|
2009-02-20 15:56:57 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:36:38 +00:00
|
|
|
GE( _cogl_wrap_glMatrixMode ((GLenum) prev_mode));
|
2009-02-20 15:56:57 +00:00
|
|
|
|
|
|
|
w->settings.texture_units = 0;
|
|
|
|
|
|
|
|
w->active_texture_unit = initial_active_unit;
|
|
|
|
}
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
memset (wrapper, 0, sizeof (CoglGles2Wrapper));
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Initialize the stacks */
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glMatrixMode (GL_PROJECTION);
|
|
|
|
_cogl_wrap_glLoadIdentity ();
|
|
|
|
_cogl_wrap_glMatrixMode (GL_MODELVIEW);
|
|
|
|
_cogl_wrap_glLoadIdentity ();
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
/* The gl*ActiveTexture wrappers will initialise the texture
|
|
|
|
* stack for the texture unit when it's first activated */
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glActiveTexture (GL_TEXTURE0);
|
|
|
|
_cogl_wrap_glClientActiveTexture (GL_TEXTURE0);
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2010-03-22 09:32:17 +00:00
|
|
|
/* Initialize the point size */
|
|
|
|
_cogl_wrap_glPointSize (1.0f);
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
initialize_texture_units (wrapper);
|
2008-06-24 16:21:40 +00:00
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
static gboolean
|
|
|
|
cogl_gles2_settings_equal (const CoglGles2WrapperSettings *a,
|
2010-11-23 14:47:17 +00:00
|
|
|
const CoglGles2WrapperSettings *b)
|
2008-06-24 16:21:40 +00:00
|
|
|
{
|
2009-02-20 15:56:57 +00:00
|
|
|
if (a->texture_units != b->texture_units)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglGles2WrapperShader *
|
|
|
|
cogl_gles2_get_vertex_shader (const CoglGles2WrapperSettings *settings)
|
|
|
|
{
|
|
|
|
GString *shader_source;
|
|
|
|
GLuint shader_obj;
|
|
|
|
CoglGles2WrapperShader *shader;
|
|
|
|
GSList *node;
|
2008-12-11 15:33:38 +00:00
|
|
|
int i;
|
2009-02-20 15:56:57 +00:00
|
|
|
int n_texture_units = 0;
|
2008-06-24 16:21:40 +00:00
|
|
|
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NULL);
|
|
|
|
|
|
|
|
/* Check if we already have a vertex shader for these settings */
|
|
|
|
for (node = w->compiled_vertex_shaders; node; node = node->next)
|
|
|
|
if (cogl_gles2_settings_equal (settings,
|
|
|
|
&((CoglGles2WrapperShader *)
|
2010-11-23 14:47:17 +00:00
|
|
|
node->data)->settings))
|
2008-06-24 16:21:40 +00:00
|
|
|
return (CoglGles2WrapperShader *) node->data;
|
|
|
|
|
|
|
|
/* Otherwise create a new shader */
|
2010-06-11 13:36:38 +00:00
|
|
|
shader_source = g_string_new (_cogl_fixed_vertex_shader_per_vertex_attribs);
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
|
|
|
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (settings->texture_units, i))
|
2008-12-11 15:33:38 +00:00
|
|
|
g_string_append_printf (shader_source,
|
2010-07-23 16:46:41 +00:00
|
|
|
"attribute vec4 cogl_tex_coord%d_in;\n",
|
2008-12-11 15:33:38 +00:00
|
|
|
i);
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
/* Find the biggest enabled texture unit index */
|
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
|
|
|
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (settings->texture_units, i))
|
|
|
|
n_texture_units = i + 1;
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2010-06-11 13:36:38 +00:00
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_transform_matrices);
|
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_output_variables);
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
if (n_texture_units > 0)
|
2008-12-11 15:33:38 +00:00
|
|
|
{
|
|
|
|
g_string_append_printf (shader_source,
|
2010-07-23 16:46:41 +00:00
|
|
|
"uniform mat4 cogl_texture_matrix[%d];\n",
|
2009-02-20 15:56:57 +00:00
|
|
|
n_texture_units);
|
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
g_string_append_printf (shader_source,
|
2010-07-23 16:46:41 +00:00
|
|
|
"varying vec2 _cogl_tex_coord[%d];",
|
2009-02-20 15:56:57 +00:00
|
|
|
n_texture_units);
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:36:38 +00:00
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_fogging_options);
|
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_main_start);
|
2009-02-20 15:56:57 +00:00
|
|
|
|
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
2010-11-23 14:47:17 +00:00
|
|
|
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (settings->texture_units, i))
|
2009-02-20 15:56:57 +00:00
|
|
|
{
|
|
|
|
g_string_append_printf (shader_source,
|
|
|
|
"transformed_tex_coord = "
|
2010-07-23 16:46:41 +00:00
|
|
|
"cogl_texture_matrix[%d] "
|
|
|
|
" * cogl_tex_coord%d_in;\n",
|
2009-02-20 15:56:57 +00:00
|
|
|
i, i);
|
|
|
|
g_string_append_printf (shader_source,
|
2010-07-23 16:46:41 +00:00
|
|
|
"_cogl_tex_coord[%d] = transformed_tex_coord.st "
|
2009-02-20 15:56:57 +00:00
|
|
|
" / transformed_tex_coord.q;\n",
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
|
2010-06-11 13:36:38 +00:00
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_frag_color_start);
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2010-06-11 13:36:38 +00:00
|
|
|
g_string_append (shader_source, _cogl_fixed_vertex_shader_end);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
shader_obj = cogl_gles2_wrapper_create_shader (GL_VERTEX_SHADER,
|
|
|
|
shader_source->str);
|
2008-05-29 13:29:04 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
g_string_free (shader_source, TRUE);
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
if (shader_obj == 0)
|
|
|
|
return NULL;
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
shader = g_slice_new (CoglGles2WrapperShader);
|
|
|
|
shader->shader = shader_obj;
|
|
|
|
shader->settings = *settings;
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
w->compiled_vertex_shaders = g_slist_prepend (w->compiled_vertex_shaders,
|
|
|
|
shader);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
return shader;
|
|
|
|
}
|
2008-05-28 17:14:17 +00:00
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
static void
|
|
|
|
cogl_gles2_wrapper_get_locations (GLuint program,
|
|
|
|
CoglGles2WrapperSettings *settings,
|
|
|
|
CoglGles2WrapperUniforms *uniforms,
|
|
|
|
CoglGles2WrapperAttributes *attribs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
uniforms->mvp_matrix_uniform
|
2010-07-23 16:46:41 +00:00
|
|
|
= glGetUniformLocation (program, "cogl_modelview_projection_matrix");
|
2008-12-11 15:33:38 +00:00
|
|
|
uniforms->modelview_matrix_uniform
|
2010-07-23 16:46:41 +00:00
|
|
|
= glGetUniformLocation (program, "cogl_modelview_matrix");
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
2010-11-30 12:48:27 +00:00
|
|
|
{
|
|
|
|
char *matrix_var_name = g_strdup_printf ("cogl_texture_matrix[%d]", i);
|
|
|
|
char *tex_coord_var_name =
|
|
|
|
g_strdup_printf ("cogl_tex_coord%d_in", i);
|
2009-02-20 15:56:57 +00:00
|
|
|
|
2010-11-30 12:48:27 +00:00
|
|
|
uniforms->texture_matrix_uniforms[i]
|
|
|
|
= glGetUniformLocation (program, matrix_var_name);
|
|
|
|
attribs->multi_texture_coords[i]
|
|
|
|
= glGetAttribLocation (program, tex_coord_var_name);
|
2009-02-20 15:56:57 +00:00
|
|
|
|
2010-11-30 12:48:27 +00:00
|
|
|
g_free (tex_coord_var_name);
|
|
|
|
g_free (matrix_var_name);
|
|
|
|
}
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2010-03-22 09:32:17 +00:00
|
|
|
uniforms->point_size_uniform
|
2010-07-23 16:46:41 +00:00
|
|
|
= glGetUniformLocation (program, "cogl_point_size_in");
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogl_gles2_wrapper_bind_attributes (GLuint program)
|
|
|
|
{
|
|
|
|
glBindAttribLocation (program, COGL_GLES2_WRAPPER_VERTEX_ATTRIB,
|
2010-07-23 16:46:41 +00:00
|
|
|
"cogl_position_in");
|
2008-12-11 15:33:38 +00:00
|
|
|
glBindAttribLocation (program, COGL_GLES2_WRAPPER_COLOR_ATTRIB,
|
2010-07-23 16:46:41 +00:00
|
|
|
"cogl_color_in");
|
2008-12-11 15:33:38 +00:00
|
|
|
glBindAttribLocation (program, COGL_GLES2_WRAPPER_NORMAL_ATTRIB,
|
2010-07-23 16:46:41 +00:00
|
|
|
"cogl_normal_in");
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
static CoglGles2WrapperProgram *
|
|
|
|
cogl_gles2_wrapper_get_program (const CoglGles2WrapperSettings *settings)
|
|
|
|
{
|
|
|
|
GSList *node;
|
|
|
|
CoglGles2WrapperProgram *program;
|
2010-11-23 14:47:17 +00:00
|
|
|
CoglGles2WrapperShader *vertex_shader;
|
2008-06-24 16:21:40 +00:00
|
|
|
GLint status;
|
|
|
|
gboolean custom_vertex_shader = FALSE, custom_fragment_shader = FALSE;
|
2010-10-15 17:00:29 +00:00
|
|
|
GLuint shaders[16];
|
|
|
|
GLsizei n_shaders = 0;
|
2008-06-24 16:21:40 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NULL);
|
|
|
|
|
|
|
|
/* Check if we've already got a program for these settings */
|
|
|
|
for (node = w->compiled_programs; node; node = node->next)
|
|
|
|
{
|
|
|
|
program = (CoglGles2WrapperProgram *) node->data;
|
|
|
|
|
2010-11-23 14:47:17 +00:00
|
|
|
if (cogl_gles2_settings_equal (settings, &program->settings)
|
2008-06-24 16:21:40 +00:00
|
|
|
&& program->settings.user_program == settings->user_program)
|
|
|
|
return (CoglGles2WrapperProgram *) node->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise create a new program */
|
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
if (settings->user_program)
|
2008-06-24 16:21:40 +00:00
|
|
|
{
|
2010-10-15 17:00:29 +00:00
|
|
|
/* We work out whether the program contains a vertex and
|
|
|
|
fragment shader by looking at the list of attached shaders */
|
|
|
|
glGetAttachedShaders (settings->user_program,
|
|
|
|
G_N_ELEMENTS (shaders),
|
|
|
|
&n_shaders, shaders);
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
for (i = 0; i < n_shaders; i++)
|
|
|
|
{
|
|
|
|
GLint shader_type;
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
glGetShaderiv (shaders[i], GL_SHADER_TYPE, &shader_type);
|
|
|
|
|
|
|
|
if (shader_type == GL_VERTEX_SHADER)
|
|
|
|
custom_vertex_shader = TRUE;
|
|
|
|
else if (shader_type == GL_FRAGMENT_SHADER)
|
|
|
|
custom_fragment_shader = TRUE;
|
|
|
|
}
|
2008-06-24 16:21:40 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 20:48:45 +00:00
|
|
|
/* We should always have a custom shaders because the pipeline
|
|
|
|
backend should create them for us */
|
2010-11-23 14:47:17 +00:00
|
|
|
g_assert (custom_fragment_shader);
|
2010-12-02 20:48:45 +00:00
|
|
|
g_assert (custom_vertex_shader);
|
2010-11-23 14:47:17 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Get or create the fixed functionality shaders for these settings
|
|
|
|
if there is no custom replacement */
|
|
|
|
if (!custom_vertex_shader)
|
|
|
|
{
|
|
|
|
vertex_shader = cogl_gles2_get_vertex_shader (settings);
|
|
|
|
if (vertex_shader == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
program = g_slice_new (CoglGles2WrapperProgram);
|
|
|
|
|
2010-12-02 20:48:45 +00:00
|
|
|
program->program = settings->user_program;
|
2008-06-24 16:21:40 +00:00
|
|
|
if (!custom_vertex_shader)
|
|
|
|
glAttachShader (program->program, vertex_shader->shader);
|
|
|
|
cogl_gles2_wrapper_bind_attributes (program->program);
|
|
|
|
glLinkProgram (program->program);
|
|
|
|
|
|
|
|
glGetProgramiv (program->program, GL_LINK_STATUS, &status);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2009-05-27 22:39:18 +00:00
|
|
|
char shader_log[1024];
|
2008-06-24 16:21:40 +00:00
|
|
|
GLint len;
|
|
|
|
|
2009-05-27 22:39:18 +00:00
|
|
|
glGetProgramInfoLog (program->program, sizeof (shader_log) - 1, &len, shader_log);
|
|
|
|
shader_log[len] = '\0';
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2009-05-27 22:39:18 +00:00
|
|
|
g_critical ("%s", shader_log);
|
2008-06-24 16:21:40 +00:00
|
|
|
|
|
|
|
g_slice_free (CoglGles2WrapperProgram, program);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
program->settings = *settings;
|
2008-12-11 15:33:38 +00:00
|
|
|
|
|
|
|
cogl_gles2_wrapper_get_locations (program->program,
|
|
|
|
&program->settings,
|
|
|
|
&program->uniforms,
|
|
|
|
&program->attributes);
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
w->compiled_programs = g_slist_append (w->compiled_programs, program);
|
2008-11-13 14:44:27 +00:00
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
return program;
|
2008-06-02 10:58:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_gles2_wrapper_deinit (CoglGles2Wrapper *wrapper)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-06-24 16:21:40 +00:00
|
|
|
GSList *node, *next;
|
|
|
|
|
|
|
|
for (node = wrapper->compiled_programs; node; node = next)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-06-24 16:21:40 +00:00
|
|
|
next = node->next;
|
|
|
|
g_slist_free1 (node);
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
2008-06-24 16:21:40 +00:00
|
|
|
wrapper->compiled_programs = NULL;
|
|
|
|
|
|
|
|
for (node = wrapper->compiled_vertex_shaders; node; node = next)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-06-24 16:21:40 +00:00
|
|
|
next = node->next;
|
|
|
|
glDeleteShader (((CoglGles2WrapperShader *) node->data)->shader);
|
|
|
|
g_slist_free1 (node);
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
2008-06-24 16:21:40 +00:00
|
|
|
wrapper->compiled_vertex_shaders = NULL;
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
static void
|
2009-09-29 01:56:23 +00:00
|
|
|
cogl_gles2_wrapper_notify_matrix_changed (CoglGles2Wrapper *wrapper,
|
|
|
|
GLenum mode)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-12-11 15:33:38 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
switch (mode)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
case GL_MODELVIEW:
|
2008-06-24 16:21:40 +00:00
|
|
|
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_MVP_MATRIX
|
|
|
|
| COGL_GLES2_DIRTY_MODELVIEW_MATRIX;
|
|
|
|
break;
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
case GL_PROJECTION:
|
2008-06-24 16:21:40 +00:00
|
|
|
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_MVP_MATRIX;
|
2008-05-27 17:42:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TEXTURE:
|
2008-12-11 15:33:38 +00:00
|
|
|
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_TEXTURE_MATRICES;
|
2009-02-20 15:56:57 +00:00
|
|
|
texture_unit = wrapper->texture_units + wrapper->active_texture_unit;
|
2008-12-11 15:33:38 +00:00
|
|
|
texture_unit->dirty_matrix = 1;
|
2008-05-27 17:42:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-09-29 01:56:23 +00:00
|
|
|
g_critical ("%s: Unexpected matrix mode %d\n", G_STRFUNC, mode);
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glMatrixMode (GLenum mode)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
w->matrix_mode = mode;
|
|
|
|
}
|
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
static CoglMatrix *
|
|
|
|
cogl_gles2_get_current_matrix (CoglGles2Wrapper *wrapper)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-12-11 15:33:38 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
switch (wrapper->matrix_mode)
|
|
|
|
{
|
2009-10-22 15:55:29 +00:00
|
|
|
default:
|
|
|
|
g_critical ("%s: Unexpected matrix mode %d\n",
|
|
|
|
G_STRFUNC, wrapper->matrix_mode);
|
|
|
|
/* flow through */
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
case GL_MODELVIEW:
|
2009-09-29 01:56:23 +00:00
|
|
|
return &wrapper->modelview_matrix;
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
case GL_PROJECTION:
|
2009-09-29 01:56:23 +00:00
|
|
|
return &wrapper->projection_matrix;
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
case GL_TEXTURE:
|
2009-02-20 15:56:57 +00:00
|
|
|
texture_unit = wrapper->texture_units + wrapper->active_texture_unit;
|
2009-09-29 01:56:23 +00:00
|
|
|
return &texture_unit->texture_matrix;
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glLoadIdentity (void)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2009-09-29 01:56:23 +00:00
|
|
|
CoglMatrix *matrix;
|
2008-05-27 17:42:50 +00:00
|
|
|
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
matrix = cogl_gles2_get_current_matrix (w);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
cogl_matrix_init_identity (matrix);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
cogl_gles2_wrapper_notify_matrix_changed (w, w->matrix_mode);
|
2009-01-29 13:40:37 +00:00
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-01-29 13:40:37 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glLoadMatrixf (const GLfloat *m)
|
2009-01-29 13:40:37 +00:00
|
|
|
{
|
2009-09-29 01:56:23 +00:00
|
|
|
CoglMatrix *matrix;
|
2009-01-29 13:40:37 +00:00
|
|
|
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
matrix = cogl_gles2_get_current_matrix (w);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
cogl_matrix_init_from_array (matrix, m);
|
2008-08-01 12:23:57 +00:00
|
|
|
|
2009-09-29 01:56:23 +00:00
|
|
|
cogl_gles2_wrapper_notify_matrix_changed (w, w->matrix_mode);
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glVertexPointer (GLint size, GLenum type, GLsizei stride,
|
2008-05-27 17:42:50 +00:00
|
|
|
const GLvoid *pointer)
|
|
|
|
{
|
|
|
|
glVertexAttribPointer (COGL_GLES2_WRAPPER_VERTEX_ATTRIB, size, type,
|
|
|
|
GL_FALSE, stride, pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glTexCoordPointer (GLint size, GLenum type, GLsizei stride,
|
2008-05-27 17:42:50 +00:00
|
|
|
const GLvoid *pointer)
|
|
|
|
{
|
2008-12-11 15:33:38 +00:00
|
|
|
int active_unit;
|
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
active_unit = w->active_client_texture_unit;
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
texture_unit = w->texture_units + active_unit;
|
2008-12-11 15:33:38 +00:00
|
|
|
texture_unit->texture_coords_size = size;
|
|
|
|
texture_unit->texture_coords_type = type;
|
|
|
|
texture_unit->texture_coords_stride = stride;
|
|
|
|
texture_unit->texture_coords_pointer = pointer;
|
|
|
|
|
|
|
|
w->dirty_attribute_pointers
|
|
|
|
|= COGL_GLES2_DIRTY_TEX_COORD_VERTEX_ATTRIB;
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride,
|
|
|
|
const GLvoid *pointer)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
glVertexAttribPointer (COGL_GLES2_WRAPPER_COLOR_ATTRIB, size, type,
|
2008-11-13 14:28:16 +00:00
|
|
|
GL_TRUE, stride, pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer)
|
2008-11-13 14:28:16 +00:00
|
|
|
{
|
|
|
|
glVertexAttribPointer (COGL_GLES2_WRAPPER_NORMAL_ATTRIB, 1, type,
|
2008-05-27 17:42:50 +00:00
|
|
|
GL_FALSE, stride, pointer);
|
|
|
|
}
|
|
|
|
|
2008-11-27 16:44:39 +00:00
|
|
|
static void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_prepare_for_draw (void)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-06-24 16:21:40 +00:00
|
|
|
CoglGles2WrapperProgram *program;
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Check if we need to switch programs */
|
|
|
|
if (w->settings_dirty)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Find or create a program for the current settings */
|
|
|
|
program = cogl_gles2_wrapper_get_program (&w->settings);
|
|
|
|
|
|
|
|
if (program == NULL)
|
|
|
|
/* Can't compile a shader so there is nothing we can do */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Start using it if we aren't already */
|
|
|
|
if (w->current_program != program)
|
|
|
|
{
|
|
|
|
w->current_program = program;
|
|
|
|
/* All of the uniforms are probably now out of date */
|
|
|
|
w->dirty_uniforms = COGL_GLES2_DIRTY_ALL;
|
|
|
|
}
|
|
|
|
w->settings_dirty = FALSE;
|
|
|
|
}
|
|
|
|
else
|
2010-10-15 17:00:29 +00:00
|
|
|
program = w->current_program;
|
|
|
|
|
|
|
|
/* We always have to reassert the program even if it hasn't changed
|
|
|
|
because the fixed-function material backend disables the program
|
|
|
|
again in the _start function. This should go away once the GLSL
|
|
|
|
code is generated in the GLSL material backend so it's probably
|
|
|
|
not worth worrying about now */
|
2010-12-02 20:48:45 +00:00
|
|
|
_cogl_use_fragment_program (w->settings.user_program,
|
|
|
|
COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
|
|
|
_cogl_use_vertex_program (w->settings.user_program,
|
|
|
|
COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Make sure all of the uniforms are up to date */
|
|
|
|
if (w->dirty_uniforms)
|
|
|
|
{
|
2010-12-06 12:31:51 +00:00
|
|
|
#if 0 /* <-- this will all be removed when this wrapper is removed */
|
2008-06-24 16:21:40 +00:00
|
|
|
if ((w->dirty_uniforms & (COGL_GLES2_DIRTY_MVP_MATRIX
|
|
|
|
| COGL_GLES2_DIRTY_MODELVIEW_MATRIX)))
|
|
|
|
{
|
2009-09-29 01:56:23 +00:00
|
|
|
CoglMatrix mvp_matrix;
|
|
|
|
CoglMatrix *modelview_matrix = &w->modelview_matrix;
|
|
|
|
CoglMatrix *projection_matrix = &w->projection_matrix;
|
|
|
|
|
|
|
|
/* FIXME: we should have a cogl_matrix_copy () function */
|
|
|
|
memcpy (&mvp_matrix, projection_matrix, sizeof (CoglMatrix));
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2009-10-22 15:55:29 +00:00
|
|
|
cogl_matrix_multiply (&mvp_matrix, &mvp_matrix, modelview_matrix);
|
2008-06-24 16:21:40 +00:00
|
|
|
|
|
|
|
if (program->uniforms.mvp_matrix_uniform != -1)
|
|
|
|
glUniformMatrix4fv (program->uniforms.mvp_matrix_uniform, 1,
|
2009-10-22 15:55:29 +00:00
|
|
|
GL_FALSE, (float *) &mvp_matrix);
|
2008-06-24 16:21:40 +00:00
|
|
|
if (program->uniforms.modelview_matrix_uniform != -1)
|
|
|
|
glUniformMatrix4fv (program->uniforms.modelview_matrix_uniform, 1,
|
2009-10-22 15:55:29 +00:00
|
|
|
GL_FALSE, (float *) &modelview_matrix);
|
2008-06-24 16:21:40 +00:00
|
|
|
}
|
2008-12-11 15:33:38 +00:00
|
|
|
if ((w->dirty_uniforms & COGL_GLES2_DIRTY_TEXTURE_MATRICES))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* TODO - we should probably have a per unit dirty flag too */
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
2008-12-11 15:33:38 +00:00
|
|
|
{
|
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
2009-02-20 15:56:57 +00:00
|
|
|
GLint uniform = program->uniforms.texture_matrix_uniforms[i];
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
texture_unit = w->texture_units + i;
|
2008-12-11 15:33:38 +00:00
|
|
|
if (uniform != -1)
|
|
|
|
glUniformMatrix4fv (uniform, 1, GL_FALSE,
|
2009-10-22 15:55:29 +00:00
|
|
|
(float *) &texture_unit->texture_matrix);
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 12:31:51 +00:00
|
|
|
#endif /* commented out */
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2010-03-22 09:32:17 +00:00
|
|
|
if ((w->dirty_uniforms & COGL_GLES2_DIRTY_POINT_SIZE))
|
|
|
|
glUniform1f (program->uniforms.point_size_uniform,
|
|
|
|
w->point_size);
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
w->dirty_uniforms = 0;
|
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
if (w->dirty_attribute_pointers
|
|
|
|
& COGL_GLES2_DIRTY_TEX_COORD_VERTEX_ATTRIB)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* TODO - coverage test */
|
2009-02-20 15:56:57 +00:00
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
2010-11-30 12:48:27 +00:00
|
|
|
{
|
|
|
|
GLint tex_coord_var_index;
|
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
|
|
|
|
texture_unit = w->texture_units + i;
|
|
|
|
if (!texture_unit->texture_coords_enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* TODO - we should probably have a per unit dirty flag too */
|
|
|
|
|
|
|
|
/* TODO - coverage test */
|
|
|
|
tex_coord_var_index = program->attributes.multi_texture_coords[i];
|
|
|
|
glVertexAttribPointer (tex_coord_var_index,
|
|
|
|
texture_unit->texture_coords_size,
|
|
|
|
texture_unit->texture_coords_type,
|
|
|
|
GL_FALSE,
|
|
|
|
texture_unit->texture_coords_stride,
|
|
|
|
texture_unit->texture_coords_pointer);
|
|
|
|
}
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (w->dirty_vertex_attrib_enables)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* TODO - coverage test */
|
|
|
|
|
|
|
|
/* TODO - we should probably have a per unit dirty flag too */
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
2008-12-11 15:33:38 +00:00
|
|
|
{
|
2010-06-08 16:26:26 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit = w->texture_units + i;
|
2009-02-20 15:56:57 +00:00
|
|
|
GLint attrib = program->attributes.multi_texture_coords[i];
|
|
|
|
|
|
|
|
if (attrib != -1)
|
|
|
|
{
|
|
|
|
if (texture_unit->texture_coords_enabled)
|
|
|
|
glEnableVertexAttribArray (attrib);
|
|
|
|
else
|
|
|
|
glDisableVertexAttribArray (attrib);
|
|
|
|
}
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
2009-02-20 15:56:57 +00:00
|
|
|
|
|
|
|
w->dirty_vertex_attrib_enables = 0;
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
2008-11-27 16:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count)
|
2008-11-27 16:44:39 +00:00
|
|
|
{
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_prepare_for_draw ();
|
2008-11-27 16:44:39 +00:00
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
glDrawArrays (mode, first, count);
|
|
|
|
}
|
|
|
|
|
2008-11-27 16:44:39 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type,
|
2008-11-27 16:44:39 +00:00
|
|
|
const GLvoid *indices)
|
|
|
|
{
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_prepare_for_draw ();
|
2008-11-27 16:44:39 +00:00
|
|
|
|
|
|
|
glDrawElements (mode, count, type, indices);
|
|
|
|
}
|
|
|
|
|
2008-12-11 15:33:38 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glClientActiveTexture (GLenum texture)
|
2008-12-11 15:33:38 +00:00
|
|
|
{
|
|
|
|
int texture_unit_index = texture - GL_TEXTURE0;
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
if (texture_unit_index < COGL_GLES2_MAX_TEXTURE_UNITS)
|
|
|
|
w->active_client_texture_unit = texture_unit_index;
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glActiveTexture (GLenum texture)
|
2008-12-11 15:33:38 +00:00
|
|
|
{
|
|
|
|
int texture_unit_index = texture - GL_TEXTURE0;
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2009-02-20 16:37:20 +00:00
|
|
|
glActiveTexture (texture);
|
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
if (texture_unit_index < COGL_GLES2_MAX_TEXTURE_UNITS)
|
|
|
|
w->active_texture_unit = texture_unit_index;
|
2008-12-11 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glEnable (GLenum cap)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
switch (cap)
|
|
|
|
{
|
|
|
|
case GL_TEXTURE_2D:
|
2010-07-01 21:04:59 +00:00
|
|
|
case GL_TEXTURE_3D_OES:
|
2009-02-20 15:56:57 +00:00
|
|
|
if (!COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (w->settings.texture_units,
|
|
|
|
w->active_texture_unit))
|
|
|
|
{
|
|
|
|
COGL_GLES2_TEXTURE_UNIT_SET_ENABLED (w->settings.texture_units,
|
|
|
|
w->active_texture_unit,
|
|
|
|
TRUE);
|
|
|
|
w->settings_dirty = TRUE;
|
|
|
|
}
|
2008-05-29 13:29:04 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
default:
|
|
|
|
glEnable (cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glDisable (GLenum cap)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
switch (cap)
|
|
|
|
{
|
|
|
|
case GL_TEXTURE_2D:
|
2010-07-01 21:04:59 +00:00
|
|
|
case GL_TEXTURE_3D_OES:
|
|
|
|
/* If this was the last enabled texture target then we'll
|
|
|
|
completely disable the unit */
|
2009-02-20 15:56:57 +00:00
|
|
|
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (w->settings.texture_units,
|
2010-11-23 14:47:17 +00:00
|
|
|
w->active_texture_unit))
|
2009-02-20 15:56:57 +00:00
|
|
|
{
|
|
|
|
COGL_GLES2_TEXTURE_UNIT_SET_ENABLED (w->settings.texture_units,
|
|
|
|
w->active_texture_unit,
|
|
|
|
FALSE);
|
|
|
|
w->settings_dirty = TRUE;
|
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
glDisable (cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glEnableClientState (GLenum array)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-12-11 15:33:38 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
switch (array)
|
|
|
|
{
|
|
|
|
case GL_VERTEX_ARRAY:
|
|
|
|
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_VERTEX_ATTRIB);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_COORD_ARRAY:
|
2008-12-11 15:33:38 +00:00
|
|
|
/* TODO - review if this should be in w->settings? */
|
|
|
|
|
2010-06-08 16:26:26 +00:00
|
|
|
texture_unit = w->texture_units + w->active_client_texture_unit;
|
2008-12-11 15:33:38 +00:00
|
|
|
if (texture_unit->texture_coords_enabled != 1)
|
|
|
|
{
|
|
|
|
texture_unit->texture_coords_enabled = 1;
|
|
|
|
w->dirty_vertex_attrib_enables
|
|
|
|
|= COGL_GLES2_DIRTY_TEX_COORD_ATTRIB_ENABLES;
|
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
break;
|
|
|
|
case GL_COLOR_ARRAY:
|
|
|
|
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB);
|
|
|
|
break;
|
2008-11-13 14:28:16 +00:00
|
|
|
case GL_NORMAL_ARRAY:
|
|
|
|
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB);
|
|
|
|
break;
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glDisableClientState (GLenum array)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2008-12-11 15:33:38 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
switch (array)
|
|
|
|
{
|
|
|
|
case GL_VERTEX_ARRAY:
|
|
|
|
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_VERTEX_ATTRIB);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_COORD_ARRAY:
|
2008-12-11 15:33:38 +00:00
|
|
|
|
2009-02-20 15:56:57 +00:00
|
|
|
texture_unit = w->texture_units + w->active_texture_unit;
|
2008-12-11 15:33:38 +00:00
|
|
|
/* TODO - review if this should be in w->settings? */
|
|
|
|
if (texture_unit->texture_coords_enabled != 0)
|
|
|
|
{
|
|
|
|
texture_unit->texture_coords_enabled = 0;
|
|
|
|
w->dirty_vertex_attrib_enables
|
|
|
|
|= COGL_GLES2_DIRTY_TEX_COORD_ATTRIB_ENABLES;
|
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
break;
|
|
|
|
case GL_COLOR_ARRAY:
|
|
|
|
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB);
|
|
|
|
break;
|
2008-11-13 14:28:16 +00:00
|
|
|
case GL_NORMAL_ARRAY:
|
|
|
|
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB);
|
|
|
|
break;
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glColor4f (GLclampf r, GLclampf g, GLclampf b, GLclampf a)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2009-01-20 16:20:54 +00:00
|
|
|
glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB, r, g, b, a);
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glColor4ub (GLubyte r, GLubyte g, GLubyte b, GLubyte a)
|
2009-06-04 13:23:16 +00:00
|
|
|
{
|
|
|
|
glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB,
|
|
|
|
r/255.0, g/255.0, b/255.0, a/255.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glClipPlanef (GLenum plane, GLfloat *equation)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
}
|
|
|
|
|
2008-05-29 13:29:04 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glGetIntegerv (GLenum pname, GLint *params)
|
2008-05-29 13:29:04 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
switch (pname)
|
|
|
|
{
|
|
|
|
case GL_MAX_CLIP_PLANES:
|
|
|
|
*params = 0;
|
|
|
|
break;
|
|
|
|
|
2010-01-12 14:43:36 +00:00
|
|
|
case GL_MATRIX_MODE:
|
2008-12-11 15:33:38 +00:00
|
|
|
*params = w->matrix_mode;
|
|
|
|
break;
|
|
|
|
|
2010-02-24 10:42:59 +00:00
|
|
|
case GL_MAX_TEXTURE_UNITS:
|
|
|
|
glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, params);
|
|
|
|
if (*params > COGL_GLES2_MAX_TEXTURE_UNITS)
|
|
|
|
*params = COGL_GLES2_MAX_TEXTURE_UNITS;
|
|
|
|
break;
|
|
|
|
|
2008-05-29 13:29:04 +00:00
|
|
|
default:
|
|
|
|
glGetIntegerv (pname, params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-27 17:42:50 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params)
|
2008-05-27 17:42:50 +00:00
|
|
|
{
|
2009-03-12 13:34:36 +00:00
|
|
|
CoglGles2WrapperTextureUnit *texture_unit;
|
|
|
|
|
2008-05-28 11:29:58 +00:00
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
switch (pname)
|
|
|
|
{
|
|
|
|
case GL_MODELVIEW_MATRIX:
|
2009-10-22 15:55:29 +00:00
|
|
|
memcpy (params, &w->modelview_matrix, sizeof (GLfloat) * 16);
|
2008-05-28 11:29:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_PROJECTION_MATRIX:
|
2009-10-22 15:55:29 +00:00
|
|
|
memcpy (params, &w->projection_matrix, sizeof (GLfloat) * 16);
|
2008-05-28 11:29:58 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-12 13:34:36 +00:00
|
|
|
case GL_TEXTURE_MATRIX:
|
|
|
|
texture_unit = w->texture_units + w->active_texture_unit;
|
2009-10-22 15:55:29 +00:00
|
|
|
memcpy (params, &texture_unit->texture_matrix, sizeof (GLfloat) * 16);
|
2009-03-12 13:34:36 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-28 11:29:58 +00:00
|
|
|
case GL_VIEWPORT:
|
2009-01-20 16:20:54 +00:00
|
|
|
glGetFloatv (GL_VIEWPORT, params);
|
2008-05-28 11:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-27 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 10:47:21 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param)
|
2008-05-28 10:47:21 +00:00
|
|
|
{
|
|
|
|
if (pname != GL_GENERATE_MIPMAP)
|
|
|
|
glTexParameteri (target, pname, param);
|
|
|
|
}
|
2008-06-24 16:21:40 +00:00
|
|
|
|
2009-01-29 13:40:37 +00:00
|
|
|
void
|
2010-06-11 13:36:38 +00:00
|
|
|
_cogl_wrap_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params)
|
2009-01-29 13:40:37 +00:00
|
|
|
{
|
|
|
|
/* FIXME: the GLES 2 backend doesn't yet support lighting so this
|
|
|
|
function can't do anything */
|
|
|
|
}
|
|
|
|
|
2010-03-22 09:32:17 +00:00
|
|
|
void
|
|
|
|
_cogl_wrap_glPointSize (GLfloat size)
|
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
|
|
|
w->point_size = size;
|
|
|
|
w->dirty_uniforms |= COGL_GLES2_DIRTY_POINT_SIZE;
|
|
|
|
}
|
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
/* This function is a massive hack to get custom GLSL programs to
|
|
|
|
work. It's only necessary until we move the GLSL shader generation
|
|
|
|
into the CoglMaterial. The gl_program specifies the user program to
|
|
|
|
be used. The list of shaders will be extracted out of this and
|
|
|
|
compiled into a new program containing any fixed function shaders
|
|
|
|
that need to be generated. The new program will be returned. */
|
|
|
|
GLuint
|
|
|
|
_cogl_gles2_use_program (GLuint gl_program)
|
|
|
|
{
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, 0);
|
|
|
|
|
|
|
|
_COGL_GLES2_CHANGE_SETTING (w, user_program, gl_program);
|
|
|
|
|
|
|
|
/* We need to bind the program immediately so that the GLSL material
|
|
|
|
backend can update the custom uniforms */
|
|
|
|
_cogl_wrap_prepare_for_draw ();
|
|
|
|
|
|
|
|
return w->current_program->program;
|
|
|
|
}
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
void
|
2010-10-15 17:00:29 +00:00
|
|
|
_cogl_gles2_clear_cache_for_program (GLuint gl_program)
|
2008-06-24 16:21:40 +00:00
|
|
|
{
|
|
|
|
GSList *node, *next, *last = NULL;
|
|
|
|
CoglGles2WrapperProgram *program;
|
|
|
|
|
|
|
|
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
if (w->settings.user_program == gl_program)
|
|
|
|
{
|
|
|
|
w->settings.user_program = 0;
|
|
|
|
w->settings_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-24 16:21:40 +00:00
|
|
|
/* Remove any cached programs that link against this custom program */
|
|
|
|
for (node = w->compiled_programs; node; node = next)
|
|
|
|
{
|
|
|
|
next = node->next;
|
|
|
|
program = (CoglGles2WrapperProgram *) node->data;
|
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
if (program->settings.user_program == gl_program)
|
2008-06-24 16:21:40 +00:00
|
|
|
{
|
|
|
|
if (last)
|
|
|
|
last->next = next;
|
|
|
|
else
|
|
|
|
w->compiled_programs = next;
|
|
|
|
|
|
|
|
g_slist_free1 (node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
last = node;
|
|
|
|
}
|
|
|
|
}
|