mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
Remove the GLES2 wrapper
The GLES2 wrapper is no longer needed because the shader generation is done within the GLSL fragend and vertend and any functions that are different for GLES2 are now guarded by #ifdefs.
This commit is contained in:
parent
2b32a9eb2a
commit
dc1f1949d0
@ -106,28 +106,8 @@ cogl_driver_sources += \
|
||||
$(srcdir)/driver/gles/cogl-texture-driver-gles.c \
|
||||
$(NULL)
|
||||
|
||||
if USE_GLES2_WRAPPER
|
||||
cogl_driver_sources += \
|
||||
$(srcdir)/driver/gles/cogl-gles2-wrapper.c \
|
||||
$(srcdir)/driver/gles/cogl-gles2-wrapper.h \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES += \
|
||||
cogl-fixed-vertex-shader.h \
|
||||
cogl-fixed-vertex-shader.c
|
||||
|
||||
%.h: $(srcdir)/driver/gles/%.glsl
|
||||
/bin/sh $(top_srcdir)/build/stringify.sh -h $< > $@
|
||||
%.c: $(srcdir)/driver/gles/%.glsl
|
||||
/bin/sh $(top_srcdir)/build/stringify.sh $< > $@
|
||||
|
||||
endif # USE_GLES2_WAPPER
|
||||
endif # COGL_DRIVER_GLES
|
||||
|
||||
EXTRA_DIST += \
|
||||
$(srcdir)/driver/gles/cogl-fixed-vertex-shader.glsl \
|
||||
$(NULL)
|
||||
|
||||
# winsys sources, common to all backends
|
||||
cogl_winsys_common_sources = \
|
||||
$(srcdir)/winsys/cogl-winsys.h \
|
||||
|
@ -40,11 +40,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
|
||||
#define glGenFramebuffers ctx->drv.pf_glGenFramebuffers
|
||||
#define glBindFramebuffer ctx->drv.pf_glBindFramebuffer
|
||||
|
@ -60,10 +60,6 @@
|
||||
#define glMapBuffer ctx->drv.pf_glMapBuffer
|
||||
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
|
||||
|
||||
#elif defined (HAVE_COGL_GLES2)
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef GL_PIXEL_PACK_BUFFER
|
||||
|
@ -42,6 +42,15 @@
|
||||
#include "cogl-matrix-private.h"
|
||||
#include "cogl-primitives-private.h"
|
||||
|
||||
#ifndef GL_CLIP_PLANE0
|
||||
#define GL_CLIP_PLANE0 0x3000
|
||||
#define GL_CLIP_PLANE1 0x3001
|
||||
#define GL_CLIP_PLANE2 0x3002
|
||||
#define GL_CLIP_PLANE3 0x3003
|
||||
#define GL_CLIP_PLANE4 0x3004
|
||||
#define GL_CLIP_PLANE5 0x3005
|
||||
#endif
|
||||
|
||||
static void
|
||||
project_vertex (const CoglMatrix *modelview_projection,
|
||||
float *vertex)
|
||||
@ -105,7 +114,9 @@ set_clip_plane (GLint plane_num,
|
||||
plane[1] = -1.0;
|
||||
plane[2] = 0;
|
||||
plane[3] = vertex_a[1];
|
||||
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
||||
#if defined (HAVE_COGL_GLES2)
|
||||
g_assert_not_reached ();
|
||||
#elif defined (HAVE_COGL_GLES)
|
||||
GE( glClipPlanef (plane_num, plane) );
|
||||
#else
|
||||
GE( glClipPlane (plane_num, plane) );
|
||||
|
@ -245,11 +245,15 @@ cogl_create_context (void)
|
||||
|
||||
_context->texture_download_pipeline = COGL_INVALID_HANDLE;
|
||||
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
/* The default for GL_ALPHA_TEST is to always pass which is equivalent to
|
||||
* the test being disabled therefore we assume that for all drivers there
|
||||
* will be no performance impact if we always leave the test enabled which
|
||||
* makes things a bit simpler for us. */
|
||||
* makes things a bit simpler for us. Under GLES2 the alpha test is
|
||||
* implemented in the fragment shader so there is no enable for it
|
||||
*/
|
||||
GE (glEnable (GL_ALPHA_TEST));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
_context->flushed_modelview_stack = NULL;
|
||||
|
@ -37,11 +37,7 @@
|
||||
#include "cogl-clip-stack.h"
|
||||
#include "cogl-journal-private.h"
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
|
||||
#else
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
|
||||
#define glGenRenderbuffers ctx->drv.pf_glGenRenderbuffers
|
||||
#define glDeleteRenderbuffers ctx->drv.pf_glDeleteRenderbuffers
|
||||
|
@ -54,10 +54,6 @@
|
||||
* GL/GLES compatability defines for pipeline thingies:
|
||||
*/
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
#define glProgramString ctx->drv.pf_glProgramString
|
||||
#define glBindProgram ctx->drv.pf_glBindProgram
|
||||
|
@ -62,10 +62,6 @@
|
||||
* GL/GLES compatability defines for pipeline thingies:
|
||||
*/
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
#endif
|
||||
|
||||
/* This might not be defined on GLES */
|
||||
#ifndef GL_TEXTURE_3D
|
||||
#define GL_TEXTURE_3D 0x806F
|
||||
|
@ -49,10 +49,6 @@
|
||||
* GL/GLES compatability defines for pipeline thingies:
|
||||
*/
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
#define glActiveTexture ctx->drv.pf_glActiveTexture
|
||||
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
||||
@ -618,7 +614,7 @@ get_max_activateable_texture_units (void)
|
||||
|
||||
if (G_UNLIKELY (ctx->max_activateable_texture_units == -1))
|
||||
{
|
||||
#ifdef HAVE_COGL_GL
|
||||
#if defined (HAVE_COGL_GL)
|
||||
GLint max_tex_coords;
|
||||
GLint max_combined_tex_units;
|
||||
GE (glGetIntegerv (GL_MAX_TEXTURE_COORDS, &max_tex_coords));
|
||||
@ -626,6 +622,16 @@ get_max_activateable_texture_units (void)
|
||||
&max_combined_tex_units));
|
||||
ctx->max_activateable_texture_units =
|
||||
MAX (max_tex_coords - 1, max_combined_tex_units);
|
||||
#elif defined (HAVE_COGL_GLES2)
|
||||
GLint max_vertex_attribs;
|
||||
GLint max_combined_tex_units;
|
||||
GE (glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs));
|
||||
GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
|
||||
&max_combined_tex_units));
|
||||
/* Two of the vertex attribs need to be used for the position
|
||||
and color */
|
||||
ctx->max_activateable_texture_units =
|
||||
MAX (max_vertex_attribs - 2, max_combined_tex_units);
|
||||
#else
|
||||
GE (glGetIntegerv (GL_MAX_TEXTURE_UNITS,
|
||||
&ctx->max_activateable_texture_units));
|
||||
|
@ -130,20 +130,6 @@ typedef struct
|
||||
|
||||
static CoglUserDataKey glsl_priv_key;
|
||||
|
||||
static void
|
||||
delete_program (GLuint program)
|
||||
{
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
/* This hack can go away once this GLSL backend replaces the GLES2
|
||||
wrapper */
|
||||
_cogl_gles2_clear_cache_for_program (program);
|
||||
#else
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
#endif
|
||||
|
||||
GE (glDeleteProgram (program));
|
||||
}
|
||||
|
||||
static CoglPipelineProgendPrivate *
|
||||
get_glsl_priv (CoglPipeline *pipeline)
|
||||
{
|
||||
@ -289,6 +275,8 @@ destroy_glsl_priv (void *user_data)
|
||||
{
|
||||
CoglPipelineProgendPrivate *priv = user_data;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (--priv->ref_count == 0)
|
||||
{
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
@ -297,7 +285,7 @@ destroy_glsl_priv (void *user_data)
|
||||
#endif
|
||||
|
||||
if (priv->program)
|
||||
delete_program (priv->program);
|
||||
GE( glDeleteProgram (priv->program) );
|
||||
|
||||
g_free (priv->unit_state);
|
||||
|
||||
@ -326,10 +314,6 @@ dirty_glsl_program_state (CoglPipeline *pipeline)
|
||||
static void
|
||||
link_program (GLint gl_program)
|
||||
{
|
||||
/* On GLES2 we'll let the backend link the program. This hack can go
|
||||
away once this backend replaces the GLES2 wrapper */
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
|
||||
GLint link_status;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
@ -356,8 +340,6 @@ link_program (GLint gl_program)
|
||||
|
||||
g_free (log);
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
}
|
||||
|
||||
typedef struct
|
||||
@ -582,7 +564,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
||||
(user_program->age != priv->user_program_age ||
|
||||
n_tex_coord_attribs > priv->n_tex_coord_attribs))
|
||||
{
|
||||
delete_program (priv->program);
|
||||
GE( glDeleteProgram (priv->program) );
|
||||
priv->program = 0;
|
||||
}
|
||||
|
||||
@ -644,18 +626,10 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
|
||||
|
||||
gl_program = priv->program;
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
/* This function is a massive hack to get the GLES2 backend to
|
||||
work. It should only be neccessary until we move the GLSL vertex
|
||||
shader generation into a vertend instead of the GLES2 driver
|
||||
backend */
|
||||
_cogl_gles2_use_program (gl_program);
|
||||
#else
|
||||
if (pipeline->fragend == COGL_PIPELINE_FRAGEND_GLSL)
|
||||
_cogl_use_fragment_program (gl_program, COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
||||
if (pipeline->vertend == COGL_PIPELINE_VERTEND_GLSL)
|
||||
_cogl_use_vertex_program (gl_program, COGL_PIPELINE_PROGRAM_TYPE_GLSL);
|
||||
#endif
|
||||
|
||||
state.unit = 0;
|
||||
state.gl_program = gl_program;
|
||||
|
@ -218,6 +218,30 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
|
||||
"main ()\n"
|
||||
"{\n");
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
/* There is no builtin uniform for the pointsize on GLES2 so we need
|
||||
to copy it from the custom uniform in the vertex shader */
|
||||
g_string_append (priv->source,
|
||||
" cogl_point_size_out = cogl_point_size_in;\n");
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
|
||||
/* On regular OpenGL we'll just flush the point size builtin */
|
||||
if (pipelines_difference & COGL_PIPELINE_STATE_POINT_SIZE)
|
||||
{
|
||||
CoglPipeline *authority =
|
||||
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_POINT_SIZE);
|
||||
|
||||
if (ctx->point_size_cache != authority->big_state->point_size)
|
||||
{
|
||||
GE( glPointSize (authority->big_state->point_size) );
|
||||
ctx->point_size_cache = authority->big_state->point_size;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,6 @@
|
||||
#define GL_PIXEL_PACK_BUFFER GL_PIXEL_PACK_BUFFER_ARB
|
||||
#endif
|
||||
|
||||
#elif defined (HAVE_COGL_GLES2)
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
|
@ -545,6 +545,7 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||
if (cogl_features_available (COGL_FEATURE_OFFSCREEN))
|
||||
_cogl_texture_driver_gl_generate_mipmaps (GL_TEXTURE_2D);
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
else
|
||||
{
|
||||
GE( glTexParameteri (GL_TEXTURE_2D,
|
||||
@ -558,6 +559,7 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
GL_GENERATE_MIPMAP,
|
||||
GL_FALSE) );
|
||||
}
|
||||
#endif
|
||||
|
||||
tex_2d->mipmaps_dirty = FALSE;
|
||||
}
|
||||
|
@ -571,6 +571,7 @@ _cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||
if (cogl_features_available (COGL_FEATURE_OFFSCREEN))
|
||||
_cogl_texture_driver_gl_generate_mipmaps (GL_TEXTURE_3D);
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
else
|
||||
{
|
||||
GE( glTexParameteri (GL_TEXTURE_3D,
|
||||
@ -591,6 +592,7 @@ _cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
GL_GENERATE_MIPMAP,
|
||||
GL_FALSE) );
|
||||
}
|
||||
#endif
|
||||
|
||||
tex_3d->mipmaps_dirty = FALSE;
|
||||
}
|
||||
|
@ -84,7 +84,6 @@
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
#define MAY_HAVE_PROGRAMABLE_GL
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
16
cogl/cogl.c
16
cogl/cogl.c
@ -47,10 +47,6 @@
|
||||
#include "cogl-texture-driver.h"
|
||||
#include "cogl-vertex-attribute-private.h"
|
||||
|
||||
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
||||
#include "cogl-gles2-wrapper.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
||||
#endif
|
||||
@ -243,6 +239,16 @@ toggle_flag (CoglContext *ctx,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
/* Under GLES2 there are no builtin client flags so toggle_client_flag
|
||||
should never be reached */
|
||||
|
||||
#define toggle_client_flag(ctx, new_flags, flag, gl_flag) \
|
||||
g_assert (((new_flags) & (flag)) == 0)
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
|
||||
static gboolean
|
||||
toggle_client_flag (CoglContext *ctx,
|
||||
unsigned long new_flags,
|
||||
@ -270,6 +276,8 @@ toggle_client_flag (CoglContext *ctx,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
void
|
||||
_cogl_enable (unsigned long flags)
|
||||
{
|
||||
|
@ -26,7 +26,6 @@
|
||||
#endif
|
||||
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-gles2-wrapper.h"
|
||||
|
||||
#define COGL_FEATURE_BEGIN(a, b, c, d, e, f, g)
|
||||
#define COGL_FEATURE_FUNCTION(ret, name, args) \
|
||||
@ -37,10 +36,5 @@ void
|
||||
_cogl_create_context_driver (CoglContext *_context)
|
||||
{
|
||||
#include "cogl-feature-functions-gles.h"
|
||||
|
||||
/* Init the GLES2 wrapper */
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
_cogl_gles2_wrapper_init (&_context->drv.gles2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#define __COGL_CONTEXT_DRIVER_H
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-gles2-wrapper.h"
|
||||
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY
|
||||
@ -43,9 +42,6 @@ typedef struct _CoglContextDriver
|
||||
/* This defines a list of function pointers */
|
||||
#include "cogl-feature-functions-gles.h"
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
CoglGles2Wrapper gles2;
|
||||
#endif
|
||||
} CoglContextDriver;
|
||||
|
||||
#undef COGL_FEATURE_BEGIN
|
||||
|
@ -1,73 +0,0 @@
|
||||
/*** _cogl_fixed_vertex_shader_per_vertex_attribs ***/
|
||||
|
||||
/* Per vertex attributes */
|
||||
attribute vec4 cogl_position_in;
|
||||
attribute vec4 cogl_color_in;
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_transform_matrices ***/
|
||||
|
||||
/* Transformation matrices */
|
||||
uniform mat4 cogl_modelview_matrix;
|
||||
uniform mat4 cogl_modelview_projection_matrix; /* combined modelview and projection matrix */
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_output_variables ***/
|
||||
|
||||
/* Outputs to the fragment shader */
|
||||
varying vec4 _cogl_color;
|
||||
varying float _cogl_fog_amount;
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_fogging_options ***/
|
||||
|
||||
/* Fogging options */
|
||||
uniform float _cogl_fog_density;
|
||||
uniform float _cogl_fog_start;
|
||||
uniform float _cogl_fog_end;
|
||||
|
||||
/* Point options */
|
||||
uniform float cogl_point_size_in;
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_main_start ***/
|
||||
|
||||
void
|
||||
main (void)
|
||||
{
|
||||
vec4 transformed_tex_coord;
|
||||
|
||||
/* Calculate the transformed position */
|
||||
gl_Position = cogl_modelview_projection_matrix * cogl_position_in;
|
||||
|
||||
/* Copy across the point size from the uniform */
|
||||
gl_PointSize = cogl_point_size_in;
|
||||
|
||||
/* Calculate the transformed texture coordinate */
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_frag_color_start ***/
|
||||
|
||||
/* Pass the interpolated vertex color on to the fragment shader */
|
||||
_cogl_color = cogl_color_in;
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_fog_start ***/
|
||||
|
||||
/* Estimate the distance from the eye using just the z-coordinate to
|
||||
use as the fog coord */
|
||||
vec4 eye_coord = cogl_modelview_matrix * cogl_position_in;
|
||||
float fog_coord = abs (eye_coord.z / eye_coord.w);
|
||||
|
||||
/* Calculate the fog amount per-vertex and interpolate it for the
|
||||
fragment shader */
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_fog_exp ***/
|
||||
_cogl_fog_amount = exp (-fog_density * fog_coord);
|
||||
/*** _cogl_fixed_vertex_shader_fog_exp2 ***/
|
||||
_cogl_fog_amount = exp (-_cogl_fog_density * fog_coord
|
||||
* _cogl_fog_density * fog_coord);
|
||||
/*** _cogl_fixed_vertex_shader_fog_linear ***/
|
||||
_cogl_fog_amount = (_cogl_fog_end - fog_coord) /
|
||||
(_cogl_fog_end - _cogl_fog_start);
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_fog_end ***/
|
||||
_cogl_fog_amount = clamp (_cogl_fog_amount, 0.0, 1.0);
|
||||
|
||||
/*** _cogl_fixed_vertex_shader_end ***/
|
||||
}
|
||||
|
@ -74,7 +74,9 @@ void
|
||||
_cogl_features_init (void)
|
||||
{
|
||||
CoglFeatureFlags flags = 0;
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
int max_clip_planes = 0;
|
||||
#endif
|
||||
GLint num_stencil_bits = 0;
|
||||
const char *gl_extensions;
|
||||
int i;
|
||||
@ -94,9 +96,11 @@ _cogl_features_init (void)
|
||||
if (num_stencil_bits > 2)
|
||||
flags |= COGL_FEATURE_STENCIL_BUFFER;
|
||||
|
||||
#ifndef HAVE_COGL_GLES2
|
||||
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
|
||||
if (max_clip_planes >= 4)
|
||||
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
flags |= COGL_FEATURE_SHADERS_GLSL | COGL_FEATURE_OFFSCREEN;
|
||||
|
@ -1,993 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 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/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
/* 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
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-gles2-wrapper.h"
|
||||
#include "cogl-fixed-vertex-shader.h"
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-shader-private.h"
|
||||
#include "cogl-shader.h"
|
||||
#include "cogl-internal.h"
|
||||
|
||||
#define _COGL_GET_GLES2_WRAPPER(wvar, retval) \
|
||||
CoglGles2Wrapper *wvar; \
|
||||
{ \
|
||||
CoglContext *__ctxvar = _cogl_context_get_default (); \
|
||||
if (__ctxvar == NULL) return retval; \
|
||||
wvar = &__ctxvar->drv.gles2; \
|
||||
}
|
||||
|
||||
#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)
|
||||
|
||||
#define COGL_GLES2_WRAPPER_VERTEX_ATTRIB 0
|
||||
#define COGL_GLES2_WRAPPER_COLOR_ATTRIB 1
|
||||
#define COGL_GLES2_WRAPPER_NORMAL_ATTRIB 2
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
char shader_log[1024];
|
||||
GLint len;
|
||||
|
||||
glGetShaderInfoLog (shader, sizeof (shader_log) - 1, &len, shader_log);
|
||||
shader_log[len] = '\0';
|
||||
|
||||
g_critical ("%s", shader_log);
|
||||
|
||||
glDeleteShader (shader);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
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 */
|
||||
GE( _cogl_wrap_glGetIntegerv (GL_MATRIX_MODE, &prev_mode));
|
||||
|
||||
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;
|
||||
GE( _cogl_wrap_glMatrixMode (GL_TEXTURE));
|
||||
GE( _cogl_wrap_glLoadIdentity ());
|
||||
}
|
||||
|
||||
GE( _cogl_wrap_glMatrixMode ((GLenum) prev_mode));
|
||||
|
||||
w->settings.texture_units = 0;
|
||||
|
||||
w->active_texture_unit = initial_active_unit;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
|
||||
{
|
||||
memset (wrapper, 0, sizeof (CoglGles2Wrapper));
|
||||
|
||||
/* Initialize the stacks */
|
||||
_cogl_wrap_glMatrixMode (GL_PROJECTION);
|
||||
_cogl_wrap_glLoadIdentity ();
|
||||
_cogl_wrap_glMatrixMode (GL_MODELVIEW);
|
||||
_cogl_wrap_glLoadIdentity ();
|
||||
|
||||
/* The gl*ActiveTexture wrappers will initialise the texture
|
||||
* stack for the texture unit when it's first activated */
|
||||
_cogl_wrap_glActiveTexture (GL_TEXTURE0);
|
||||
_cogl_wrap_glClientActiveTexture (GL_TEXTURE0);
|
||||
|
||||
/* Initialize the point size */
|
||||
_cogl_wrap_glPointSize (1.0f);
|
||||
|
||||
initialize_texture_units (wrapper);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cogl_gles2_settings_equal (const CoglGles2WrapperSettings *a,
|
||||
const CoglGles2WrapperSettings *b)
|
||||
{
|
||||
if (a->texture_units != b->texture_units)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static CoglGles2WrapperShader *
|
||||
cogl_gles2_get_vertex_shader (const CoglGles2WrapperSettings *settings)
|
||||
{
|
||||
GString *shader_source;
|
||||
GLuint shader_obj;
|
||||
CoglGles2WrapperShader *shader;
|
||||
GSList *node;
|
||||
int i;
|
||||
int n_texture_units = 0;
|
||||
|
||||
_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 *)
|
||||
node->data)->settings))
|
||||
return (CoglGles2WrapperShader *) node->data;
|
||||
|
||||
/* Otherwise create a new shader */
|
||||
shader_source = g_string_new (_cogl_fixed_vertex_shader_per_vertex_attribs);
|
||||
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (settings->texture_units, i))
|
||||
g_string_append_printf (shader_source,
|
||||
"attribute vec4 cogl_tex_coord%d_in;\n",
|
||||
i);
|
||||
|
||||
/* 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;
|
||||
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_transform_matrices);
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_output_variables);
|
||||
|
||||
if (n_texture_units > 0)
|
||||
{
|
||||
g_string_append_printf (shader_source,
|
||||
"uniform mat4 cogl_texture_matrix[%d];\n",
|
||||
n_texture_units);
|
||||
|
||||
g_string_append_printf (shader_source,
|
||||
"varying vec2 _cogl_tex_coord[%d];",
|
||||
n_texture_units);
|
||||
}
|
||||
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_fogging_options);
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_main_start);
|
||||
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
if (COGL_GLES2_TEXTURE_UNIT_IS_ENABLED (settings->texture_units, i))
|
||||
{
|
||||
g_string_append_printf (shader_source,
|
||||
"transformed_tex_coord = "
|
||||
"cogl_texture_matrix[%d] "
|
||||
" * cogl_tex_coord%d_in;\n",
|
||||
i, i);
|
||||
g_string_append_printf (shader_source,
|
||||
"_cogl_tex_coord[%d] = transformed_tex_coord.st "
|
||||
" / transformed_tex_coord.q;\n",
|
||||
i);
|
||||
}
|
||||
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_frag_color_start);
|
||||
|
||||
g_string_append (shader_source, _cogl_fixed_vertex_shader_end);
|
||||
|
||||
shader_obj = cogl_gles2_wrapper_create_shader (GL_VERTEX_SHADER,
|
||||
shader_source->str);
|
||||
|
||||
g_string_free (shader_source, TRUE);
|
||||
|
||||
if (shader_obj == 0)
|
||||
return NULL;
|
||||
|
||||
shader = g_slice_new (CoglGles2WrapperShader);
|
||||
shader->shader = shader_obj;
|
||||
shader->settings = *settings;
|
||||
|
||||
w->compiled_vertex_shaders = g_slist_prepend (w->compiled_vertex_shaders,
|
||||
shader);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_gles2_wrapper_get_locations (GLuint program,
|
||||
CoglGles2WrapperSettings *settings,
|
||||
CoglGles2WrapperUniforms *uniforms,
|
||||
CoglGles2WrapperAttributes *attribs)
|
||||
{
|
||||
int i;
|
||||
|
||||
uniforms->mvp_matrix_uniform
|
||||
= glGetUniformLocation (program, "cogl_modelview_projection_matrix");
|
||||
uniforms->modelview_matrix_uniform
|
||||
= glGetUniformLocation (program, "cogl_modelview_matrix");
|
||||
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
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);
|
||||
|
||||
uniforms->texture_matrix_uniforms[i]
|
||||
= glGetUniformLocation (program, matrix_var_name);
|
||||
attribs->multi_texture_coords[i]
|
||||
= glGetAttribLocation (program, tex_coord_var_name);
|
||||
|
||||
g_free (tex_coord_var_name);
|
||||
g_free (matrix_var_name);
|
||||
}
|
||||
|
||||
uniforms->point_size_uniform
|
||||
= glGetUniformLocation (program, "cogl_point_size_in");
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_gles2_wrapper_bind_attributes (GLuint program)
|
||||
{
|
||||
glBindAttribLocation (program, COGL_GLES2_WRAPPER_VERTEX_ATTRIB,
|
||||
"cogl_position_in");
|
||||
glBindAttribLocation (program, COGL_GLES2_WRAPPER_COLOR_ATTRIB,
|
||||
"cogl_color_in");
|
||||
glBindAttribLocation (program, COGL_GLES2_WRAPPER_NORMAL_ATTRIB,
|
||||
"cogl_normal_in");
|
||||
}
|
||||
|
||||
static CoglGles2WrapperProgram *
|
||||
cogl_gles2_wrapper_get_program (const CoglGles2WrapperSettings *settings)
|
||||
{
|
||||
GSList *node;
|
||||
CoglGles2WrapperProgram *program;
|
||||
CoglGles2WrapperShader *vertex_shader;
|
||||
GLint status;
|
||||
gboolean custom_vertex_shader = FALSE, custom_fragment_shader = FALSE;
|
||||
GLuint shaders[16];
|
||||
GLsizei n_shaders = 0;
|
||||
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;
|
||||
|
||||
if (cogl_gles2_settings_equal (settings, &program->settings)
|
||||
&& program->settings.user_program == settings->user_program)
|
||||
return (CoglGles2WrapperProgram *) node->data;
|
||||
}
|
||||
|
||||
/* Otherwise create a new program */
|
||||
|
||||
if (settings->user_program)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
for (i = 0; i < n_shaders; i++)
|
||||
{
|
||||
GLint shader_type;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* We should always have a custom shaders because the pipeline
|
||||
backend should create them for us */
|
||||
g_assert (custom_fragment_shader);
|
||||
g_assert (custom_vertex_shader);
|
||||
|
||||
/* 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);
|
||||
|
||||
program->program = settings->user_program;
|
||||
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)
|
||||
{
|
||||
char shader_log[1024];
|
||||
GLint len;
|
||||
|
||||
glGetProgramInfoLog (program->program, sizeof (shader_log) - 1, &len, shader_log);
|
||||
shader_log[len] = '\0';
|
||||
|
||||
g_critical ("%s", shader_log);
|
||||
|
||||
g_slice_free (CoglGles2WrapperProgram, program);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
program->settings = *settings;
|
||||
|
||||
cogl_gles2_wrapper_get_locations (program->program,
|
||||
&program->settings,
|
||||
&program->uniforms,
|
||||
&program->attributes);
|
||||
|
||||
w->compiled_programs = g_slist_append (w->compiled_programs, program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_gles2_wrapper_deinit (CoglGles2Wrapper *wrapper)
|
||||
{
|
||||
GSList *node, *next;
|
||||
|
||||
for (node = wrapper->compiled_programs; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
g_slist_free1 (node);
|
||||
}
|
||||
wrapper->compiled_programs = NULL;
|
||||
|
||||
for (node = wrapper->compiled_vertex_shaders; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
glDeleteShader (((CoglGles2WrapperShader *) node->data)->shader);
|
||||
g_slist_free1 (node);
|
||||
}
|
||||
wrapper->compiled_vertex_shaders = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_gles2_wrapper_notify_matrix_changed (CoglGles2Wrapper *wrapper,
|
||||
GLenum mode)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GL_MODELVIEW:
|
||||
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_MVP_MATRIX
|
||||
| COGL_GLES2_DIRTY_MODELVIEW_MATRIX;
|
||||
break;
|
||||
|
||||
case GL_PROJECTION:
|
||||
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_MVP_MATRIX;
|
||||
break;
|
||||
|
||||
case GL_TEXTURE:
|
||||
wrapper->dirty_uniforms |= COGL_GLES2_DIRTY_TEXTURE_MATRICES;
|
||||
texture_unit = wrapper->texture_units + wrapper->active_texture_unit;
|
||||
texture_unit->dirty_matrix = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_critical ("%s: Unexpected matrix mode %d\n", G_STRFUNC, mode);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glMatrixMode (GLenum mode)
|
||||
{
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
w->matrix_mode = mode;
|
||||
}
|
||||
|
||||
static CoglMatrix *
|
||||
cogl_gles2_get_current_matrix (CoglGles2Wrapper *wrapper)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
|
||||
switch (wrapper->matrix_mode)
|
||||
{
|
||||
default:
|
||||
g_critical ("%s: Unexpected matrix mode %d\n",
|
||||
G_STRFUNC, wrapper->matrix_mode);
|
||||
/* flow through */
|
||||
|
||||
case GL_MODELVIEW:
|
||||
return &wrapper->modelview_matrix;
|
||||
|
||||
case GL_PROJECTION:
|
||||
return &wrapper->projection_matrix;
|
||||
|
||||
case GL_TEXTURE:
|
||||
texture_unit = wrapper->texture_units + wrapper->active_texture_unit;
|
||||
return &texture_unit->texture_matrix;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glLoadIdentity (void)
|
||||
{
|
||||
CoglMatrix *matrix;
|
||||
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
matrix = cogl_gles2_get_current_matrix (w);
|
||||
|
||||
cogl_matrix_init_identity (matrix);
|
||||
|
||||
cogl_gles2_wrapper_notify_matrix_changed (w, w->matrix_mode);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glLoadMatrixf (const GLfloat *m)
|
||||
{
|
||||
CoglMatrix *matrix;
|
||||
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
matrix = cogl_gles2_get_current_matrix (w);
|
||||
|
||||
cogl_matrix_init_from_array (matrix, m);
|
||||
|
||||
cogl_gles2_wrapper_notify_matrix_changed (w, w->matrix_mode);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glVertexPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer)
|
||||
{
|
||||
glVertexAttribPointer (COGL_GLES2_WRAPPER_VERTEX_ATTRIB, size, type,
|
||||
GL_FALSE, stride, pointer);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glTexCoordPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer)
|
||||
{
|
||||
int active_unit;
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
active_unit = w->active_client_texture_unit;
|
||||
|
||||
texture_unit = w->texture_units + active_unit;
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer)
|
||||
{
|
||||
glVertexAttribPointer (COGL_GLES2_WRAPPER_COLOR_ATTRIB, size, type,
|
||||
GL_TRUE, stride, pointer);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
{
|
||||
glVertexAttribPointer (COGL_GLES2_WRAPPER_NORMAL_ATTRIB, 1, type,
|
||||
GL_FALSE, stride, pointer);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_wrap_prepare_for_draw (void)
|
||||
{
|
||||
CoglGles2WrapperProgram *program;
|
||||
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
/* Check if we need to switch programs */
|
||||
if (w->settings_dirty)
|
||||
{
|
||||
/* 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
|
||||
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 */
|
||||
_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);
|
||||
|
||||
/* Make sure all of the uniforms are up to date */
|
||||
if (w->dirty_uniforms)
|
||||
{
|
||||
#if 0 /* <-- this will all be removed when this wrapper is removed */
|
||||
if ((w->dirty_uniforms & (COGL_GLES2_DIRTY_MVP_MATRIX
|
||||
| COGL_GLES2_DIRTY_MODELVIEW_MATRIX)))
|
||||
{
|
||||
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));
|
||||
|
||||
cogl_matrix_multiply (&mvp_matrix, &mvp_matrix, modelview_matrix);
|
||||
|
||||
if (program->uniforms.mvp_matrix_uniform != -1)
|
||||
glUniformMatrix4fv (program->uniforms.mvp_matrix_uniform, 1,
|
||||
GL_FALSE, (float *) &mvp_matrix);
|
||||
if (program->uniforms.modelview_matrix_uniform != -1)
|
||||
glUniformMatrix4fv (program->uniforms.modelview_matrix_uniform, 1,
|
||||
GL_FALSE, (float *) &modelview_matrix);
|
||||
}
|
||||
if ((w->dirty_uniforms & COGL_GLES2_DIRTY_TEXTURE_MATRICES))
|
||||
{
|
||||
int i;
|
||||
|
||||
/* TODO - we should probably have a per unit dirty flag too */
|
||||
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
GLint uniform = program->uniforms.texture_matrix_uniforms[i];
|
||||
|
||||
texture_unit = w->texture_units + i;
|
||||
if (uniform != -1)
|
||||
glUniformMatrix4fv (uniform, 1, GL_FALSE,
|
||||
(float *) &texture_unit->texture_matrix);
|
||||
}
|
||||
}
|
||||
#endif /* commented out */
|
||||
|
||||
if ((w->dirty_uniforms & COGL_GLES2_DIRTY_POINT_SIZE))
|
||||
glUniform1f (program->uniforms.point_size_uniform,
|
||||
w->point_size);
|
||||
|
||||
w->dirty_uniforms = 0;
|
||||
}
|
||||
|
||||
if (w->dirty_attribute_pointers
|
||||
& COGL_GLES2_DIRTY_TEX_COORD_VERTEX_ATTRIB)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* TODO - coverage test */
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (w->dirty_vertex_attrib_enables)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* TODO - coverage test */
|
||||
|
||||
/* TODO - we should probably have a per unit dirty flag too */
|
||||
|
||||
for (i = 0; i < COGL_GLES2_MAX_TEXTURE_UNITS; i++)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit = w->texture_units + i;
|
||||
GLint attrib = program->attributes.multi_texture_coords[i];
|
||||
|
||||
if (attrib != -1)
|
||||
{
|
||||
if (texture_unit->texture_coords_enabled)
|
||||
glEnableVertexAttribArray (attrib);
|
||||
else
|
||||
glDisableVertexAttribArray (attrib);
|
||||
}
|
||||
}
|
||||
|
||||
w->dirty_vertex_attrib_enables = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count)
|
||||
{
|
||||
_cogl_wrap_prepare_for_draw ();
|
||||
|
||||
glDrawArrays (mode, first, count);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type,
|
||||
const GLvoid *indices)
|
||||
{
|
||||
_cogl_wrap_prepare_for_draw ();
|
||||
|
||||
glDrawElements (mode, count, type, indices);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glClientActiveTexture (GLenum texture)
|
||||
{
|
||||
int texture_unit_index = texture - GL_TEXTURE0;
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
if (texture_unit_index < COGL_GLES2_MAX_TEXTURE_UNITS)
|
||||
w->active_client_texture_unit = texture_unit_index;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glActiveTexture (GLenum texture)
|
||||
{
|
||||
int texture_unit_index = texture - GL_TEXTURE0;
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
glActiveTexture (texture);
|
||||
|
||||
if (texture_unit_index < COGL_GLES2_MAX_TEXTURE_UNITS)
|
||||
w->active_texture_unit = texture_unit_index;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glEnable (GLenum cap)
|
||||
{
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (cap)
|
||||
{
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_3D_OES:
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
glEnable (cap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glDisable (GLenum cap)
|
||||
{
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (cap)
|
||||
{
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_3D_OES:
|
||||
/* If this was the last enabled texture target then we'll
|
||||
completely disable the unit */
|
||||
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,
|
||||
FALSE);
|
||||
w->settings_dirty = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
glDisable (cap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glEnableClientState (GLenum array)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (array)
|
||||
{
|
||||
case GL_VERTEX_ARRAY:
|
||||
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_VERTEX_ATTRIB);
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
/* TODO - review if this should be in w->settings? */
|
||||
|
||||
texture_unit = w->texture_units + w->active_client_texture_unit;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB);
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
glEnableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glDisableClientState (GLenum array)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (array)
|
||||
{
|
||||
case GL_VERTEX_ARRAY:
|
||||
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_VERTEX_ATTRIB);
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
|
||||
texture_unit = w->texture_units + w->active_texture_unit;
|
||||
/* 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;
|
||||
}
|
||||
break;
|
||||
case GL_COLOR_ARRAY:
|
||||
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB);
|
||||
break;
|
||||
case GL_NORMAL_ARRAY:
|
||||
glDisableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glColor4f (GLclampf r, GLclampf g, GLclampf b, GLclampf a)
|
||||
{
|
||||
glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB, r, g, b, a);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glColor4ub (GLubyte r, GLubyte g, GLubyte b, GLubyte a)
|
||||
{
|
||||
glVertexAttrib4f (COGL_GLES2_WRAPPER_COLOR_ATTRIB,
|
||||
r/255.0, g/255.0, b/255.0, a/255.0);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glClipPlanef (GLenum plane, GLfloat *equation)
|
||||
{
|
||||
/* FIXME */
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glGetIntegerv (GLenum pname, GLint *params)
|
||||
{
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (pname)
|
||||
{
|
||||
case GL_MAX_CLIP_PLANES:
|
||||
*params = 0;
|
||||
break;
|
||||
|
||||
case GL_MATRIX_MODE:
|
||||
*params = w->matrix_mode;
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
glGetIntegerv (pname, params);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params)
|
||||
{
|
||||
CoglGles2WrapperTextureUnit *texture_unit;
|
||||
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
switch (pname)
|
||||
{
|
||||
case GL_MODELVIEW_MATRIX:
|
||||
memcpy (params, &w->modelview_matrix, sizeof (GLfloat) * 16);
|
||||
break;
|
||||
|
||||
case GL_PROJECTION_MATRIX:
|
||||
memcpy (params, &w->projection_matrix, sizeof (GLfloat) * 16);
|
||||
break;
|
||||
|
||||
case GL_TEXTURE_MATRIX:
|
||||
texture_unit = w->texture_units + w->active_texture_unit;
|
||||
memcpy (params, &texture_unit->texture_matrix, sizeof (GLfloat) * 16);
|
||||
break;
|
||||
|
||||
case GL_VIEWPORT:
|
||||
glGetFloatv (GL_VIEWPORT, params);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param)
|
||||
{
|
||||
if (pname != GL_GENERATE_MIPMAP)
|
||||
glTexParameteri (target, pname, param);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_wrap_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params)
|
||||
{
|
||||
/* FIXME: the GLES 2 backend doesn't yet support lighting so this
|
||||
function can't do anything */
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_gles2_clear_cache_for_program (GLuint gl_program)
|
||||
{
|
||||
GSList *node, *next, *last = NULL;
|
||||
CoglGles2WrapperProgram *program;
|
||||
|
||||
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
|
||||
|
||||
if (w->settings.user_program == gl_program)
|
||||
{
|
||||
w->settings.user_program = 0;
|
||||
w->settings_dirty = TRUE;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
if (program->settings.user_program == gl_program)
|
||||
{
|
||||
if (last)
|
||||
last->next = next;
|
||||
else
|
||||
w->compiled_programs = next;
|
||||
|
||||
g_slist_free1 (node);
|
||||
}
|
||||
else
|
||||
last = node;
|
||||
}
|
||||
}
|
@ -1,388 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009 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_GLES2_WRAPPER_H__
|
||||
#define __COGL_GLES2_WRAPPER_H__
|
||||
|
||||
#include "cogl.h" /* needed for gl header include */
|
||||
#include "cogl-internal.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
|
||||
typedef struct _CoglGles2Wrapper CoglGles2Wrapper;
|
||||
typedef struct _CoglGles2WrapperTextureUnit
|
||||
CoglGles2WrapperTextureUnit;
|
||||
|
||||
typedef struct _CoglGles2WrapperAttributes CoglGles2WrapperAttributes;
|
||||
typedef struct _CoglGles2WrapperUniforms CoglGles2WrapperUniforms;
|
||||
typedef struct _CoglGles2WrapperTextureUnitSettings
|
||||
CoglGles2WrapperTextureUnitSettings;
|
||||
typedef struct _CoglGles2WrapperSettings CoglGles2WrapperSettings;
|
||||
typedef struct _CoglGles2WrapperProgram CoglGles2WrapperProgram;
|
||||
typedef struct _CoglGles2WrapperShader CoglGles2WrapperShader;
|
||||
|
||||
/* Must be a power of two */
|
||||
#define COGL_GLES2_MODELVIEW_STACK_SIZE 32
|
||||
#define COGL_GLES2_PROJECTION_STACK_SIZE 2
|
||||
#define COGL_GLES2_TEXTURE_STACK_SIZE 2
|
||||
|
||||
/* Accessors for the texture unit bit mask */
|
||||
#define COGL_GLES2_TEXTURE_UNIT_IS_ENABLED(mask, unit) \
|
||||
(((mask) & (1 << ((unit) * 2))) ? TRUE : FALSE)
|
||||
#define COGL_GLES2_SET_BIT(mask, bit, val) \
|
||||
((val) ? ((mask) |= (1 << (bit))) : ((mask) &= ~(1 << (bit))))
|
||||
#define COGL_GLES2_TEXTURE_UNIT_SET_ENABLED(mask, unit, val) \
|
||||
COGL_GLES2_SET_BIT ((mask), (unit) * 2, (val))
|
||||
|
||||
#define COGL_GLES2_MAX_TEXTURE_UNITS (sizeof (guint32) * 8 / 2)
|
||||
|
||||
/* Dirty flags for shader uniforms */
|
||||
enum
|
||||
{
|
||||
COGL_GLES2_DIRTY_MVP_MATRIX = 1 << 0,
|
||||
COGL_GLES2_DIRTY_MODELVIEW_MATRIX = 1 << 1,
|
||||
COGL_GLES2_DIRTY_TEXTURE_MATRICES = 1 << 2,
|
||||
COGL_GLES2_DIRTY_POINT_SIZE = 1 << 3,
|
||||
|
||||
COGL_GLES2_DIRTY_ALL = (1 << 4) - 1
|
||||
};
|
||||
|
||||
/* Dirty flags for shader vertex attribute pointers */
|
||||
enum
|
||||
{
|
||||
COGL_GLES2_DIRTY_TEX_COORD_VERTEX_ATTRIB = 1 << 0
|
||||
};
|
||||
|
||||
/* Dirty flags for shader vertex attributes enabled status */
|
||||
enum
|
||||
{
|
||||
COGL_GLES2_DIRTY_TEX_COORD_ATTRIB_ENABLES = 1 << 0
|
||||
};
|
||||
|
||||
struct _CoglGles2WrapperAttributes
|
||||
{
|
||||
GLint multi_texture_coords[COGL_GLES2_MAX_TEXTURE_UNITS];
|
||||
};
|
||||
|
||||
struct _CoglGles2WrapperUniforms
|
||||
{
|
||||
GLint mvp_matrix_uniform;
|
||||
GLint modelview_matrix_uniform;
|
||||
GLint texture_matrix_uniforms[COGL_GLES2_MAX_TEXTURE_UNITS];
|
||||
|
||||
GLint point_size_uniform;
|
||||
};
|
||||
|
||||
/* NB: We get a copy of this for each fragment/vertex
|
||||
* program varient we generate so we try to keep it
|
||||
* fairly lean */
|
||||
struct _CoglGles2WrapperSettings
|
||||
{
|
||||
guint32 texture_units;
|
||||
|
||||
/* The current in-use user program */
|
||||
GLuint user_program;
|
||||
};
|
||||
|
||||
struct _CoglGles2WrapperTextureUnit
|
||||
{
|
||||
CoglMatrix texture_matrix;
|
||||
|
||||
GLenum texture_coords_type;
|
||||
GLint texture_coords_size;
|
||||
GLsizei texture_coords_stride;
|
||||
const void *texture_coords_pointer;
|
||||
|
||||
unsigned int texture_coords_enabled:1;
|
||||
unsigned int dirty_matrix:1; /*!< shader uniform needs updating */
|
||||
};
|
||||
|
||||
struct _CoglGles2Wrapper
|
||||
{
|
||||
GLuint matrix_mode;
|
||||
CoglMatrix modelview_matrix;
|
||||
CoglMatrix projection_matrix;
|
||||
unsigned int active_texture_unit;
|
||||
unsigned int active_client_texture_unit;
|
||||
|
||||
CoglGles2WrapperTextureUnit texture_units[COGL_GLES2_MAX_TEXTURE_UNITS];
|
||||
|
||||
/* The combined modelview and projection matrix is only updated at
|
||||
the last minute in glDrawArrays to avoid recalculating it for
|
||||
every change to the modelview matrix */
|
||||
GLboolean mvp_uptodate;
|
||||
|
||||
/* The currently bound program */
|
||||
CoglGles2WrapperProgram *current_program;
|
||||
|
||||
/* The current settings. Effectively these represent anything that
|
||||
* will require a modified fixed function shader */
|
||||
CoglGles2WrapperSettings settings;
|
||||
/* Whether the settings have changed since the last draw */
|
||||
gboolean settings_dirty;
|
||||
/* Uniforms that have changed since the last draw */
|
||||
int dirty_uniforms;
|
||||
|
||||
/* Attribute pointers that have changed since the last draw */
|
||||
int dirty_attribute_pointers;
|
||||
|
||||
/* Vertex attribute pointer enables that have changed since the last draw */
|
||||
int dirty_vertex_attrib_enables;
|
||||
|
||||
/* List of all compiled program combinations */
|
||||
GSList *compiled_programs;
|
||||
|
||||
/* List of all compiled vertex shaders */
|
||||
GSList *compiled_vertex_shaders;
|
||||
|
||||
/* Values for the uniforms */
|
||||
GLfloat point_size;
|
||||
};
|
||||
|
||||
struct _CoglGles2WrapperProgram
|
||||
{
|
||||
GLuint program;
|
||||
|
||||
/* The settings that were used to generate this combination */
|
||||
CoglGles2WrapperSettings settings;
|
||||
|
||||
/* The attributes for this program that are not bound up-front
|
||||
* with constant indices */
|
||||
CoglGles2WrapperAttributes attributes;
|
||||
|
||||
/* The uniforms for this program */
|
||||
CoglGles2WrapperUniforms uniforms;
|
||||
};
|
||||
|
||||
struct _CoglGles2WrapperShader
|
||||
{
|
||||
GLuint shader;
|
||||
|
||||
/* The settings that were used to generate this shader */
|
||||
CoglGles2WrapperSettings settings;
|
||||
};
|
||||
|
||||
/* These defines are missing from GL ES 2 but we can still use them
|
||||
with the wrapper functions */
|
||||
|
||||
#ifndef GL_MODELVIEW
|
||||
|
||||
#define GL_MATRIX_MODE 0x0BA0
|
||||
|
||||
#define GL_MODELVIEW 0x1700
|
||||
#define GL_PROJECTION 0x1701
|
||||
|
||||
#ifdef COGL_ENABLE_DEBUG
|
||||
#define GL_STACK_OVERFLOW 0x0503
|
||||
#define GL_STACK_UNDERFLOW 0x0504
|
||||
#endif
|
||||
|
||||
#define GL_VERTEX_ARRAY 0x8074
|
||||
#define GL_TEXTURE_COORD_ARRAY 0x8078
|
||||
#define GL_COLOR_ARRAY 0x8076
|
||||
#define GL_NORMAL_ARRAY 0x8075
|
||||
|
||||
#define GL_LIGHTING 0x0B50
|
||||
#define GL_ALPHA_TEST 0x0BC0
|
||||
|
||||
#define GL_FOG 0x0B60
|
||||
#define GL_FOG_COLOR 0x0B66
|
||||
#define GL_FOG_MODE 0x0B65
|
||||
#define GL_FOG_HINT 0x0C54
|
||||
#define GL_FOG_DENSITY 0x0B62
|
||||
#define GL_FOG_START 0x0B63
|
||||
#define GL_FOG_END 0x0B64
|
||||
|
||||
#define GL_CLIP_PLANE0 0x3000
|
||||
#define GL_CLIP_PLANE1 0x3001
|
||||
#define GL_CLIP_PLANE2 0x3002
|
||||
#define GL_CLIP_PLANE3 0x3003
|
||||
#define GL_MAX_CLIP_PLANES 0x0D32
|
||||
|
||||
#define GL_MODELVIEW_MATRIX 0x0BA6
|
||||
#define GL_PROJECTION_MATRIX 0x0BA7
|
||||
#define GL_TEXTURE_MATRIX 0x0BA8
|
||||
|
||||
#define GL_GENERATE_MIPMAP 0x8191
|
||||
|
||||
#define GL_TEXTURE_ENV 0x2300
|
||||
#define GL_TEXTURE_ENV_MODE 0x2200
|
||||
#define GL_TEXTURE_ENV_COLOR 0x2201
|
||||
#define GL_MODULATE 0x2100
|
||||
|
||||
#define GL_EXP 0x8000
|
||||
#define GL_EXP2 0x8001
|
||||
|
||||
#define GL_MODULATE 0x2100
|
||||
#define GL_ADD 0x0104
|
||||
#define GL_ADD_SIGNED 0x8574
|
||||
#define GL_INTERPOLATE 0x8575
|
||||
#define GL_SUBTRACT 0x84e7
|
||||
#define GL_DOT3_RGB 0x86ae
|
||||
#define GL_DOT3_RGBA 0x86af
|
||||
#define GL_CONSTANT 0x8576
|
||||
#define GL_PRIMARY_COLOR 0x8577
|
||||
#define GL_PREVIOUS 0x8578
|
||||
#define GL_COMBINE 0x8570
|
||||
#define GL_COMBINE_RGB 0x8571
|
||||
#define GL_COMBINE_ALPHA 0x8572
|
||||
#define GL_SRC0_RGB 0x8580
|
||||
#define GL_OPERAND0_RGB 0x8590
|
||||
#define GL_SRC1_RGB 0x8581
|
||||
#define GL_OPERAND1_RGB 0x8591
|
||||
#define GL_SRC2_RGB 0x8582
|
||||
#define GL_OPERAND2_RGB 0x8592
|
||||
#define GL_SRC0_ALPHA 0x8588
|
||||
#define GL_OPERAND0_ALPHA 0x8598
|
||||
#define GL_SRC1_ALPHA 0x8589
|
||||
#define GL_OPERAND1_ALPHA 0x8599
|
||||
#define GL_SRC2_ALPHA 0x858a
|
||||
#define GL_OPERAND2_ALPHA 0x859a
|
||||
#define GL_AMBIENT 0x1200
|
||||
#define GL_DIFFUSE 0x1201
|
||||
#define GL_SPECULAR 0x1202
|
||||
#define GL_EMISSION 0x1600
|
||||
#define GL_SHININESS 0x1601
|
||||
|
||||
#define GL_MAX_TEXTURE_UNITS 0x84e2
|
||||
|
||||
#define GL_POINT_SPRITE 0x8861
|
||||
#define GL_COORD_REPLACE 0x8862
|
||||
|
||||
#endif /* GL_MODELVIEW */
|
||||
|
||||
void _cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper);
|
||||
void _cogl_gles2_wrapper_deinit (CoglGles2Wrapper *wrapper);
|
||||
|
||||
void _cogl_wrap_glPushMatrix ();
|
||||
void _cogl_wrap_glPopMatrix ();
|
||||
void _cogl_wrap_glMatrixMode (GLenum mode);
|
||||
void _cogl_wrap_glLoadIdentity ();
|
||||
void _cogl_wrap_glMultMatrixf (const GLfloat *m);
|
||||
void _cogl_wrap_glLoadMatrixf (const GLfloat *m);
|
||||
void _cogl_wrap_glFrustumf (GLfloat left, GLfloat right,
|
||||
GLfloat bottom, GLfloat top,
|
||||
GLfloat z_near, GLfloat z_far);
|
||||
void _cogl_wrap_glScalef (GLfloat x, GLfloat y, GLfloat z);
|
||||
void _cogl_wrap_glTranslatef (GLfloat x, GLfloat y, GLfloat z);
|
||||
void _cogl_wrap_glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
|
||||
void _cogl_wrap_glOrthof (GLfloat left, GLfloat right,
|
||||
GLfloat bottom, GLfloat top,
|
||||
GLfloat near, GLfloat far);
|
||||
|
||||
void _cogl_wrap_glEnable (GLenum cap);
|
||||
void _cogl_wrap_glDisable (GLenum cap);
|
||||
|
||||
void _cogl_wrap_glTexCoordPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer);
|
||||
void _cogl_wrap_glVertexPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer);
|
||||
void _cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer);
|
||||
void _cogl_wrap_glNormalPointer (GLenum type, GLsizei stride,
|
||||
const GLvoid *pointer);
|
||||
|
||||
void _cogl_wrap_glClientActiveTexture (GLenum texture);
|
||||
void _cogl_wrap_glActiveTexture (GLenum texture);
|
||||
|
||||
void _cogl_wrap_glEnableClientState (GLenum array);
|
||||
void _cogl_wrap_glDisableClientState (GLenum array);
|
||||
|
||||
void _cogl_wrap_glColor4f (GLclampf r, GLclampf g, GLclampf b, GLclampf a);
|
||||
void _cogl_wrap_glColor4ub (GLubyte r, GLubyte g, GLubyte b, GLubyte a);
|
||||
|
||||
void _cogl_wrap_glClipPlanef (GLenum plane, GLfloat *equation);
|
||||
|
||||
void _cogl_wrap_glGetIntegerv (GLenum pname, GLint *params);
|
||||
void _cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params);
|
||||
|
||||
void _cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count);
|
||||
void _cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type,
|
||||
const GLvoid *indices);
|
||||
void _cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param);
|
||||
|
||||
void _cogl_wrap_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params);
|
||||
|
||||
void _cogl_wrap_glPointSize (GLfloat point_size);
|
||||
|
||||
/* This function is only available on GLES 2 */
|
||||
#define _cogl_wrap_glGenerateMipmap glGenerateMipmap
|
||||
|
||||
GLuint _cogl_gles2_use_program (GLuint gl_program);
|
||||
void _cogl_gles2_clear_cache_for_program (GLuint gl_program);
|
||||
|
||||
/* Remap the missing GL functions to use the wrappers */
|
||||
#ifndef COGL_GLES2_WRAPPER_NO_REMAP
|
||||
#define glDrawArrays _cogl_wrap_glDrawArrays
|
||||
#define glDrawElements _cogl_wrap_glDrawElements
|
||||
#define glPushMatrix _cogl_wrap_glPushMatrix
|
||||
#define glPopMatrix _cogl_wrap_glPopMatrix
|
||||
#define glMatrixMode _cogl_wrap_glMatrixMode
|
||||
#define glLoadIdentity _cogl_wrap_glLoadIdentity
|
||||
#define glMultMatrixf _cogl_wrap_glMultMatrixf
|
||||
#define glLoadMatrixf _cogl_wrap_glLoadMatrixf
|
||||
#define glFrustumf _cogl_wrap_glFrustumf
|
||||
#define glScalef _cogl_wrap_glScalef
|
||||
#define glTranslatef _cogl_wrap_glTranslatef
|
||||
#define glRotatef _cogl_wrap_glRotatef
|
||||
#define glOrthof _cogl_wrap_glOrthof
|
||||
#define glEnable _cogl_wrap_glEnable
|
||||
#define glDisable _cogl_wrap_glDisable
|
||||
#define glTexCoordPointer _cogl_wrap_glTexCoordPointer
|
||||
#define glVertexPointer _cogl_wrap_glVertexPointer
|
||||
#define glColorPointer _cogl_wrap_glColorPointer
|
||||
#define glNormalPointer _cogl_wrap_glNormalPointer
|
||||
#define glTexEnvi _cogl_wrap_glTexEnvi
|
||||
#define glTexEnvfv _cogl_wrap_glTexEnvfv
|
||||
#define glActiveTexture _cogl_wrap_glActiveTexture
|
||||
#define glClientActiveTexture _cogl_wrap_glClientActiveTexture
|
||||
#define glEnableClientState _cogl_wrap_glEnableClientState
|
||||
#define glDisableClientState _cogl_wrap_glDisableClientState
|
||||
#define glColor4f _cogl_wrap_glColor4f
|
||||
#define glColor4ub _cogl_wrap_glColor4ub
|
||||
#define glClipPlanef _cogl_wrap_glClipPlanef
|
||||
#define glGetIntegerv _cogl_wrap_glGetIntegerv
|
||||
#define glGetFloatv _cogl_wrap_glGetFloatv
|
||||
#define glTexParameteri _cogl_wrap_glTexParameteri
|
||||
#define glMaterialfv _cogl_wrap_glMaterialfv
|
||||
#define glPointSize _cogl_wrap_glPointSize
|
||||
#endif /* COGL_GLES2_WRAPPER_NO_REMAP */
|
||||
|
||||
#else /* HAVE_COGL_GLES2 */
|
||||
|
||||
/* COGL uses the automatic mipmap generation for GLES 1 so
|
||||
glGenerateMipmap doesn't need to do anything */
|
||||
#define _cogl_wrap_glGenerateMipmap(x) ((void) 0)
|
||||
|
||||
/* GLES doesn't have glDrawRangeElements, so we simply pretend it does
|
||||
* but that it makes no use of the start, end constraints: */
|
||||
#define glDrawRangeElements(mode, start, end, count, type, indices) \
|
||||
glDrawElements (mode, count, type, indices)
|
||||
|
||||
#endif /* HAVE_COGL_GLES2 */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_GLES2_WRAPPER_H__ */
|
@ -46,8 +46,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "cogl-gles2-wrapper.h"
|
||||
|
||||
#define glTexImage3D ctx->drv.pf_glTexImage3D
|
||||
#define glTexSubImage3D ctx->drv.pf_glTexSubImage3D
|
||||
|
||||
@ -485,7 +483,9 @@ _cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
||||
void
|
||||
_cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
|
||||
{
|
||||
GE( _cogl_wrap_glGenerateMipmap (gl_target) );
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
GE( glGenerateMipmap (gl_target) );
|
||||
#endif
|
||||
}
|
||||
|
||||
CoglPixelFormat
|
||||
|
Loading…
Reference in New Issue
Block a user