2010-06-15 11:44:52 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-06-15 11:44:52 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008,2009,2010 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-06-15 11:44:52 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-23 04:43:05 -04:00
|
|
|
#include "cogl-context-private.h"
|
2013-01-20 13:47:40 -05:00
|
|
|
#include "cogl-util-gl-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-private.h"
|
2011-11-17 11:52:21 -05:00
|
|
|
#include "cogl-pipeline-state-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2010-07-01 20:07:36 -04:00
|
|
|
|
2010-11-29 11:56:41 -05:00
|
|
|
#ifdef COGL_PIPELINE_FRAGEND_FIXED
|
2010-07-01 20:07:36 -04:00
|
|
|
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2010-06-15 11:44:52 -04:00
|
|
|
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-blend-string.h"
|
|
|
|
#include "cogl-profile.h"
|
2010-12-02 15:48:45 -05:00
|
|
|
#include "cogl-program-private.h"
|
2010-09-13 06:30:30 -04:00
|
|
|
|
2010-06-15 11:44:52 -04:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-02-09 07:52:45 -05:00
|
|
|
#ifndef GL_TEXTURE_RECTANGLE_ARB
|
|
|
|
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
|
|
|
|
#endif
|
|
|
|
|
2010-11-29 11:56:41 -05:00
|
|
|
const CoglPipelineFragend _cogl_pipeline_fixed_fragend;
|
2010-09-14 07:13:30 -04:00
|
|
|
|
2010-11-30 07:48:27 -05:00
|
|
|
static void
|
|
|
|
_cogl_disable_texture_unit (int unit_index)
|
|
|
|
{
|
|
|
|
CoglTextureUnit *unit;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
unit = &g_array_index (ctx->texture_units, CoglTextureUnit, unit_index);
|
|
|
|
|
|
|
|
if (unit->enabled_gl_target)
|
|
|
|
{
|
|
|
|
_cogl_set_active_texture_unit (unit_index);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glDisable (unit->enabled_gl_target));
|
2010-11-30 07:48:27 -05:00
|
|
|
unit->enabled_gl_target = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 11:44:52 -04:00
|
|
|
static int
|
2010-11-30 07:48:27 -05:00
|
|
|
get_max_texture_units (void)
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
/* This function is called quite often so we cache the value to
|
|
|
|
avoid too many GL calls */
|
|
|
|
if (ctx->max_texture_units == -1)
|
|
|
|
{
|
|
|
|
ctx->max_texture_units = 1;
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glGetIntegerv (GL_MAX_TEXTURE_UNITS,
|
|
|
|
&ctx->max_texture_units));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx->max_texture_units;
|
|
|
|
}
|
|
|
|
|
2012-09-25 16:08:10 -04:00
|
|
|
static void
|
2010-11-29 11:56:41 -05:00
|
|
|
_cogl_pipeline_fragend_fixed_start (CoglPipeline *pipeline,
|
2010-06-15 11:44:52 -04:00
|
|
|
int n_layers,
|
2012-09-27 06:06:16 -04:00
|
|
|
unsigned long pipelines_difference)
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
2010-12-02 15:48:45 -05:00
|
|
|
_cogl_use_fragment_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:39:27 -05:00
|
|
|
static void
|
|
|
|
translate_sources (CoglPipeline *pipeline,
|
|
|
|
int n_sources,
|
|
|
|
CoglPipelineCombineSource *source_in,
|
|
|
|
GLenum *source_out)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* The texture source numbers specified in the layer combine are the
|
|
|
|
layer numbers so we need to map these to unit indices */
|
|
|
|
|
|
|
|
for (i = 0; i < n_sources; i++)
|
|
|
|
switch (source_in[i])
|
|
|
|
{
|
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_TEXTURE:
|
|
|
|
source_out[i] = GL_TEXTURE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_CONSTANT:
|
|
|
|
source_out[i] = GL_CONSTANT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_PRIMARY_COLOR:
|
|
|
|
source_out[i] = GL_PRIMARY_COLOR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_PREVIOUS:
|
|
|
|
source_out[i] = GL_PREVIOUS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
int layer_num = source_in[i] - COGL_PIPELINE_COMBINE_SOURCE_TEXTURE0;
|
|
|
|
CoglPipelineGetLayerFlags flags = COGL_PIPELINE_GET_LAYER_NO_CREATE;
|
|
|
|
CoglPipelineLayer *layer =
|
|
|
|
_cogl_pipeline_get_layer_with_flags (pipeline, layer_num, flags);
|
|
|
|
|
|
|
|
if (layer == NULL)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2012-02-09 15:39:27 -05:00
|
|
|
if (!warning_seen)
|
|
|
|
{
|
|
|
|
g_warning ("The application is trying to use a texture "
|
|
|
|
"combine with a layer number that does not exist");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
source_out[i] = GL_PREVIOUS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
source_out[i] = (_cogl_pipeline_layer_get_unit_index (layer) +
|
|
|
|
GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-11-29 11:56:41 -05:00
|
|
|
_cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipelineLayer *layer,
|
2010-06-15 11:44:52 -04:00
|
|
|
unsigned long layers_difference)
|
|
|
|
{
|
|
|
|
CoglTextureUnit *unit =
|
2010-10-27 13:54:57 -04:00
|
|
|
_cogl_get_texture_unit (_cogl_pipeline_layer_get_unit_index (layer));
|
2010-06-15 11:44:52 -04:00
|
|
|
int unit_index = unit->index;
|
|
|
|
int n_rgb_func_args;
|
|
|
|
int n_alpha_func_args;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
/* XXX: Beware that since we are changing the active texture unit we
|
|
|
|
* must make sure we don't call into other Cogl components that may
|
|
|
|
* temporarily bind texture objects to query/modify parameters since
|
|
|
|
* they will end up binding texture unit 1. See
|
|
|
|
* _cogl_bind_gl_texture_transient for more details.
|
|
|
|
*/
|
|
|
|
_cogl_set_active_texture_unit (unit_index);
|
|
|
|
|
2010-11-30 07:48:27 -05:00
|
|
|
if (G_UNLIKELY (unit_index >= get_max_texture_units ()))
|
|
|
|
{
|
|
|
|
_cogl_disable_texture_unit (unit_index);
|
|
|
|
/* TODO: although this isn't considered an error that
|
|
|
|
* warrants falling back to a different backend we
|
|
|
|
* should print a warning here. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-09 07:52:45 -05:00
|
|
|
/* Handle enabling or disabling the right texture type */
|
|
|
|
if (layers_difference & COGL_PIPELINE_LAYER_STATE_TEXTURE_TYPE)
|
2010-11-30 07:48:27 -05:00
|
|
|
{
|
2012-02-09 07:52:45 -05:00
|
|
|
CoglTextureType texture_type =
|
|
|
|
_cogl_pipeline_layer_get_texture_type (layer);
|
|
|
|
GLenum gl_target;
|
|
|
|
|
|
|
|
switch (texture_type)
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_TYPE_2D:
|
|
|
|
gl_target = GL_TEXTURE_2D;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_TEXTURE_TYPE_3D:
|
|
|
|
gl_target = GL_TEXTURE_3D;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_TEXTURE_TYPE_RECTANGLE:
|
|
|
|
gl_target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
break;
|
2015-06-10 09:10:34 -04:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2012-02-09 07:52:45 -05:00
|
|
|
}
|
2010-11-30 07:48:27 -05:00
|
|
|
|
|
|
|
_cogl_set_active_texture_unit (unit_index);
|
|
|
|
|
|
|
|
/* The common GL code handles binding the right texture so we
|
|
|
|
just need to handle enabling and disabling it */
|
|
|
|
|
|
|
|
if (unit->enabled_gl_target != gl_target)
|
|
|
|
{
|
|
|
|
/* Disable the previous target if it's still enabled */
|
|
|
|
if (unit->enabled_gl_target)
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glDisable (unit->enabled_gl_target));
|
2010-11-30 07:48:27 -05:00
|
|
|
|
|
|
|
/* Enable the new target */
|
2011-01-24 09:28:00 -05:00
|
|
|
if (!G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)))
|
2010-11-30 07:48:27 -05:00
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glEnable (gl_target));
|
2010-11-30 07:48:27 -05:00
|
|
|
unit->enabled_gl_target = gl_target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Even though there may be no difference between the last flushed
|
|
|
|
* texture state and the current layers texture state it may be that the
|
|
|
|
* texture unit has been disabled for some time so we need to assert that
|
|
|
|
* it's enabled now.
|
|
|
|
*/
|
2011-01-24 09:28:00 -05:00
|
|
|
if (!G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)) &&
|
2011-05-24 11:37:11 -04:00
|
|
|
unit->enabled_gl_target == 0)
|
2010-11-30 07:48:27 -05:00
|
|
|
{
|
|
|
|
_cogl_set_active_texture_unit (unit_index);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glEnable (unit->gl_target));
|
2010-11-30 07:48:27 -05:00
|
|
|
unit->enabled_gl_target = unit->gl_target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
if (layers_difference & COGL_PIPELINE_LAYER_STATE_COMBINE)
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipelineLayer *authority =
|
|
|
|
_cogl_pipeline_layer_get_authority (layer,
|
|
|
|
COGL_PIPELINE_LAYER_STATE_COMBINE);
|
|
|
|
CoglPipelineLayerBigState *big_state = authority->big_state;
|
2012-02-09 15:39:27 -05:00
|
|
|
GLenum sources[3];
|
2010-06-15 11:44:52 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
|
2010-06-15 11:44:52 -04:00
|
|
|
|
|
|
|
/* Set the combiner functions... */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV,
|
|
|
|
GL_COMBINE_RGB,
|
|
|
|
big_state->texture_combine_rgb_func));
|
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV,
|
|
|
|
GL_COMBINE_ALPHA,
|
|
|
|
big_state->texture_combine_alpha_func));
|
2010-06-15 11:44:52 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the function arguments...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* For the RGB components... */
|
|
|
|
n_rgb_func_args =
|
|
|
|
_cogl_get_n_args_for_combine_func (big_state->texture_combine_rgb_func);
|
|
|
|
|
2012-02-09 15:39:27 -05:00
|
|
|
translate_sources (pipeline,
|
|
|
|
n_rgb_func_args,
|
|
|
|
big_state->texture_combine_rgb_src,
|
|
|
|
sources);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[0]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB,
|
|
|
|
big_state->texture_combine_rgb_op[0]));
|
2010-06-15 11:44:52 -04:00
|
|
|
if (n_rgb_func_args > 1)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[1]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB,
|
|
|
|
big_state->texture_combine_rgb_op[1]));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
if (n_rgb_func_args > 2)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_RGB,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[2]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_RGB,
|
|
|
|
big_state->texture_combine_rgb_op[2]));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For the Alpha component */
|
|
|
|
n_alpha_func_args =
|
|
|
|
_cogl_get_n_args_for_combine_func (big_state->texture_combine_alpha_func);
|
|
|
|
|
2012-02-09 15:39:27 -05:00
|
|
|
translate_sources (pipeline,
|
|
|
|
n_alpha_func_args,
|
|
|
|
big_state->texture_combine_alpha_src,
|
|
|
|
sources);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[0]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
|
|
|
|
big_state->texture_combine_alpha_op[0]));
|
2010-06-15 11:44:52 -04:00
|
|
|
if (n_alpha_func_args > 1)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[1]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
|
|
|
|
big_state->texture_combine_alpha_op[1]));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
if (n_alpha_func_args > 2)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_ALPHA,
|
2012-02-09 15:39:27 -05:00
|
|
|
sources[2]));
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
|
|
|
|
big_state->texture_combine_alpha_op[2]));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-30 17:28:38 -05:00
|
|
|
if (layers_difference & COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT)
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipelineLayer *authority =
|
2010-11-30 17:28:38 -05:00
|
|
|
_cogl_pipeline_layer_get_authority
|
|
|
|
(layer, COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT);
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipelineLayerBigState *big_state = authority->big_state;
|
2010-06-15 11:44:52 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
|
|
|
|
big_state->texture_combine_constant));
|
2010-06-15 11:44:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-11-30 07:48:27 -05:00
|
|
|
get_highest_unit_index_cb (CoglPipelineLayer *layer,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
|
|
|
int *highest_index = user_data;
|
|
|
|
|
|
|
|
*highest_index = unit_index;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-11-29 11:56:41 -05:00
|
|
|
_cogl_pipeline_fragend_fixed_end (CoglPipeline *pipeline,
|
2010-10-27 13:54:57 -04:00
|
|
|
unsigned long pipelines_difference)
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
2010-11-30 07:48:27 -05:00
|
|
|
int highest_unit_index = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
_cogl_pipeline_foreach_layer_internal (pipeline,
|
|
|
|
get_highest_unit_index_cb,
|
|
|
|
&highest_unit_index);
|
|
|
|
|
|
|
|
/* Disable additional texture units that may have previously been in use.. */
|
|
|
|
for (i = highest_unit_index + 1; i < ctx->texture_units->len; i++)
|
|
|
|
_cogl_disable_texture_unit (i);
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
if (pipelines_difference & COGL_PIPELINE_STATE_FOG)
|
2010-07-06 15:18:26 -04:00
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipeline *authority =
|
|
|
|
_cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_FOG);
|
|
|
|
CoglPipelineFogState *fog_state = &authority->big_state->fog_state;
|
2010-07-06 15:18:26 -04:00
|
|
|
|
|
|
|
if (fog_state->enabled)
|
|
|
|
{
|
|
|
|
GLfloat fogColor[4];
|
|
|
|
GLenum gl_mode = GL_LINEAR;
|
|
|
|
|
|
|
|
fogColor[0] = cogl_color_get_red_float (&fog_state->color);
|
|
|
|
fogColor[1] = cogl_color_get_green_float (&fog_state->color);
|
|
|
|
fogColor[2] = cogl_color_get_blue_float (&fog_state->color);
|
|
|
|
fogColor[3] = cogl_color_get_alpha_float (&fog_state->color);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glEnable (GL_FOG));
|
2010-07-06 15:18:26 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glFogfv (GL_FOG_COLOR, fogColor));
|
2010-07-06 15:18:26 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES1)
|
|
|
|
switch (fog_state->mode)
|
|
|
|
{
|
|
|
|
case COGL_FOG_MODE_LINEAR:
|
|
|
|
gl_mode = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
case COGL_FOG_MODE_EXPONENTIAL:
|
|
|
|
gl_mode = GL_EXP;
|
|
|
|
break;
|
|
|
|
case COGL_FOG_MODE_EXPONENTIAL_SQUARED:
|
|
|
|
gl_mode = GL_EXP2;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-06 15:18:26 -04:00
|
|
|
/* TODO: support other modes for GLES2 */
|
|
|
|
|
|
|
|
/* NB: GLES doesn't have glFogi */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glFogf (GL_FOG_MODE, gl_mode));
|
|
|
|
GE (ctx, glHint (GL_FOG_HINT, GL_NICEST));
|
2010-07-06 15:18:26 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glFogf (GL_FOG_DENSITY, fog_state->density));
|
|
|
|
GE (ctx, glFogf (GL_FOG_START, fog_state->z_near));
|
|
|
|
GE (ctx, glFogf (GL_FOG_END, fog_state->z_far));
|
2010-07-06 15:18:26 -04:00
|
|
|
}
|
|
|
|
else
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glDisable (GL_FOG));
|
2010-07-06 15:18:26 -04:00
|
|
|
}
|
|
|
|
|
2010-06-15 11:44:52 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-29 11:56:41 -05:00
|
|
|
const CoglPipelineFragend _cogl_pipeline_fixed_fragend =
|
2010-06-15 11:44:52 -04:00
|
|
|
{
|
2010-11-29 11:56:41 -05:00
|
|
|
_cogl_pipeline_fragend_fixed_start,
|
|
|
|
_cogl_pipeline_fragend_fixed_add_layer,
|
2010-06-15 11:44:52 -04:00
|
|
|
NULL, /* passthrough */
|
2010-11-29 11:56:41 -05:00
|
|
|
_cogl_pipeline_fragend_fixed_end,
|
2010-10-27 13:54:57 -04:00
|
|
|
NULL, /* pipeline_change_notify */
|
|
|
|
NULL, /* pipeline_set_parent_notify */
|
2010-06-15 11:44:52 -04:00
|
|
|
NULL, /* layer_change_notify */
|
|
|
|
};
|
|
|
|
|
2010-11-29 11:56:41 -05:00
|
|
|
#endif /* COGL_PIPELINE_FRAGEND_FIXED */
|
2010-07-01 20:07:36 -04:00
|
|
|
|