material: Split the fragment processing backends out

This splits the fragment processing backends (glsl, arbfp and fixed) out
from cogl-material.c into their own cogl-material-{glsl,arbfp,fixed}.c
files in an effort to help and keep cogl-material.c maintainable.
This commit is contained in:
Robert Bragg 2010-06-15 16:44:52 +01:00
parent 411438f309
commit 3e1323a636
9 changed files with 1587 additions and 1272 deletions

View File

@ -119,6 +119,12 @@ cogl_sources_c = \
$(srcdir)/cogl-matrix-stack.h \
$(srcdir)/cogl-material.c \
$(srcdir)/cogl-material-private.h \
$(srcdir)/cogl-material-glsl.c \
$(srcdir)/cogl-material-glsl-private.h \
$(srcdir)/cogl-material-arbfp.c \
$(srcdir)/cogl-material-arbfp-private.h \
$(srcdir)/cogl-material-fixed.c \
$(srcdir)/cogl-material-fixed-private.h \
$(srcdir)/cogl-blend-string.c \
$(srcdir)/cogl-blend-string.h \
$(srcdir)/cogl-debug.c \

View File

@ -0,0 +1,36 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_MATERIAL_ARBFP_PRIVATE_H
#define __COGL_MATERIAL_ARBFP_PRIVATE_H
#include "cogl-material-private.h"
const CoglMaterialBackend _cogl_material_arbfp_backend;
#endif /* __COGL_MATERIAL_ARBFP_PRIVATE_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_MATERIAL_FIXED_PRIVATE_H
#define __COGL_MATERIAL_FIXED_PRIVATE_H
#include "cogl-material-private.h"
const CoglMaterialBackend _cogl_material_fixed_backend;
#endif /* __COGL_MATERIAL_FIXED_PRIVATE_H */

View File

@ -0,0 +1,201 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2008,2009,2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-context.h"
#include "cogl-handle.h"
#include "cogl-material-private.h"
#include "cogl-texture-private.h"
#include "cogl-blend-string.h"
#include "cogl-profile.h"
#ifndef HAVE_COGL_GLES
#include "cogl-program.h"
#endif
#include <glib.h>
#include <glib/gprintf.h>
#include <string.h>
#ifdef HAVE_COGL_GLES2
#include "../gles/cogl-gles2-wrapper.h"
#endif
static int
_cogl_material_backend_fixed_get_max_texture_units (void)
{
_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;
GE (glGetIntegerv (GL_MAX_TEXTURE_UNITS,
&ctx->max_texture_units));
}
return ctx->max_texture_units;
}
static gboolean
_cogl_material_backend_fixed_start (CoglMaterial *material,
int n_layers,
unsigned long materials_difference)
{
_cogl_use_program (COGL_INVALID_HANDLE, COGL_MATERIAL_PROGRAM_TYPE_FIXED);
return TRUE;
}
static gboolean
_cogl_material_backend_fixed_add_layer (CoglMaterial *material,
CoglMaterialLayer *layer,
unsigned long layers_difference)
{
CoglTextureUnit *unit =
_cogl_get_texture_unit (_cogl_material_layer_get_unit_index (layer));
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);
if (layers_difference & COGL_MATERIAL_LAYER_STATE_COMBINE)
{
CoglMaterialLayer *authority =
_cogl_material_layer_get_authority (layer,
COGL_MATERIAL_LAYER_STATE_COMBINE);
CoglMaterialLayerBigState *big_state = authority->big_state;
GE (glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
/* Set the combiner functions... */
GE (glTexEnvi (GL_TEXTURE_ENV,
GL_COMBINE_RGB,
big_state->texture_combine_rgb_func));
GE (glTexEnvi (GL_TEXTURE_ENV,
GL_COMBINE_ALPHA,
big_state->texture_combine_alpha_func));
/*
* 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);
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB,
big_state->texture_combine_rgb_src[0]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB,
big_state->texture_combine_rgb_op[0]));
if (n_rgb_func_args > 1)
{
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB,
big_state->texture_combine_rgb_src[1]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB,
big_state->texture_combine_rgb_op[1]));
}
if (n_rgb_func_args > 2)
{
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_RGB,
big_state->texture_combine_rgb_src[2]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_RGB,
big_state->texture_combine_rgb_op[2]));
}
/* For the Alpha component */
n_alpha_func_args =
_cogl_get_n_args_for_combine_func (big_state->texture_combine_alpha_func);
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA,
big_state->texture_combine_alpha_src[0]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
big_state->texture_combine_alpha_op[0]));
if (n_alpha_func_args > 1)
{
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA,
big_state->texture_combine_alpha_src[1]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
big_state->texture_combine_alpha_op[1]));
}
if (n_alpha_func_args > 2)
{
GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_ALPHA,
big_state->texture_combine_alpha_src[2]));
GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
big_state->texture_combine_alpha_op[2]));
}
}
if (layers_difference & COGL_MATERIAL_LAYER_STATE_COMBINE)
{
CoglMaterialLayer *authority =
_cogl_material_layer_get_authority (layer,
COGL_MATERIAL_LAYER_STATE_COMBINE);
CoglMaterialLayerBigState *big_state = authority->big_state;
GE (glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
big_state->texture_combine_constant));
}
return TRUE;
}
static gboolean
_cogl_material_backend_fixed_end (CoglMaterial *material,
unsigned long materials_difference)
{
return TRUE;
}
const CoglMaterialBackend _cogl_material_fixed_backend =
{
_cogl_material_backend_fixed_get_max_texture_units,
_cogl_material_backend_fixed_start,
_cogl_material_backend_fixed_add_layer,
NULL, /* passthrough */
_cogl_material_backend_fixed_end,
NULL, /* material_change_notify */
NULL, /* material_set_parent_notify */
NULL, /* layer_change_notify */
NULL /* free_priv */
};

View File

@ -0,0 +1,36 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_MATERIAL_GLSL_PRIVATE_H
#define __COGL_MATERIAL_GLSL_PRIVATE_H
#include "cogl-material-private.h"
const CoglMaterialBackend _cogl_material_glsl_backend;
#endif /* __COGL_MATERIAL_GLSL_PRIVATE_H */

View File

@ -0,0 +1,123 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2008,2009,2010 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl.h"
#include "cogl-internal.h"
#include "cogl-context.h"
#include "cogl-handle.h"
#include "cogl-material-private.h"
#ifndef HAVE_COGL_GLES
#include "cogl-program.h"
#endif
#include <glib.h>
/*
* GL/GLES compatability defines for material thingies:
*/
#ifdef HAVE_COGL_GLES2
#include "../gles/cogl-gles2-wrapper.h"
#endif
static int
_cogl_material_backend_glsl_get_max_texture_units (void)
{
return _cogl_get_max_texture_image_units ();
}
static gboolean
_cogl_material_backend_glsl_start (CoglMaterial *material,
int n_layers,
unsigned long materials_difference)
{
_COGL_GET_CONTEXT (ctx, FALSE);
if (!cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
return FALSE;
/* FIXME: This will likely conflict with the GLES 2 backends use of
* glUseProgram.
*/
if (materials_difference & COGL_MATERIAL_STATE_USER_SHADER)
{
CoglMaterial *authority =
_cogl_material_get_authority (material,
COGL_MATERIAL_STATE_USER_SHADER);
CoglHandle program = authority->big_state->user_program;
if (program == COGL_INVALID_HANDLE)
return FALSE; /* XXX: change me when we support code generation here */
_cogl_use_program (program, COGL_MATERIAL_PROGRAM_TYPE_GLSL);
return TRUE;
}
/* TODO: also support code generation */
return FALSE;
}
gboolean
_cogl_material_backend_glsl_add_layer (CoglMaterial *material,
CoglMaterialLayer *layer,
unsigned long layers_difference)
{
return TRUE;
}
gboolean
_cogl_material_backend_glsl_passthrough (CoglMaterial *material)
{
return TRUE;
}
gboolean
_cogl_material_backend_glsl_end (CoglMaterial *material,
unsigned long materials_difference)
{
return TRUE;
}
const CoglMaterialBackend _cogl_material_glsl_backend =
{
_cogl_material_backend_glsl_get_max_texture_units,
_cogl_material_backend_glsl_start,
_cogl_material_backend_glsl_add_layer,
_cogl_material_backend_glsl_passthrough,
_cogl_material_backend_glsl_end,
NULL, /* material_state_change_notify */
NULL, /* material_set_parent_notify */
NULL, /* layer_state_change_notify */
NULL, /* free_priv */
};

View File

@ -143,16 +143,38 @@ _cogl_bind_gl_texture_transient (GLenum gl_target,
gboolean is_foreign);
#if defined (HAVE_COGL_GL)
/* glsl, arbfp, fixed */
/* NB: material->backend is currently a 3bit unsigned int bitfield */
#define COGL_MATERIAL_BACKEND_GLSL 0
#define COGL_MATERIAL_BACKEND_GLSL_MASK (1L<<0)
#define COGL_MATERIAL_BACKEND_ARBFP 1
#define COGL_MATERIAL_BACKEND_ARBFP_MASK (1L<<1)
#define COGL_MATERIAL_BACKEND_FIXED 2
#define COGL_MATERIAL_BACKEND_FIXED_MASK (1L<<2)
#define COGL_MATERIAL_N_BACKENDS 3
#elif defined (HAVE_COGL_GLES2)
/* glsl, fixed */
#define COGL_MATERIAL_BACKEND_GLSL 0
#define COGL_MATERIAL_BACKEND_GLSL_MASK (1L<<0)
#define COGL_MATERIAL_BACKEND_FIXED 1
#define COGL_MATERIAL_BACKEND_FIXED_MASK (1L<<1)
#define COGL_MATERIAL_N_BACKENDS 2
#else /* HAVE_COGL_GLES */
/* fixed */
#define COGL_MATERIAL_BACKEND_FIXED 0
#define COGL_MATERIAL_BACKEND_FIXED_MASK (1L<<0)
#define COGL_MATERIAL_N_BACKENDS 1
#endif
#define COGL_MATERIAL_BACKEND_DEFAULT 0
#define COGL_MATERIAL_BACKEND_UNDEFINED 3
typedef enum
{
COGL_MATERIAL_LAYER_STATE_UNIT = 1L<<0,
@ -724,6 +746,24 @@ typedef struct _CoglMaterialFlushOptions
CoglMaterialWrapModeOverrides wrap_mode_overrides;
} CoglMaterialFlushOptions;
void
_cogl_set_active_texture_unit (int unit_index);
void
_cogl_delete_gl_texture (GLuint gl_texture);
int
_cogl_get_max_texture_image_units (void);
void
_cogl_use_program (CoglHandle program_handle, CoglMaterialProgramType type);
unsigned int
_cogl_get_n_args_for_combine_func (GLint func);
void
_cogl_material_get_colorubv (CoglHandle handle,
guint8 *color);
@ -757,9 +797,6 @@ void
_cogl_material_set_user_program (CoglHandle handle,
CoglHandle program);
void
_cogl_delete_gl_texture (GLuint gl_texture);
void
_cogl_material_texture_storage_change_notify (CoglHandle texture);
@ -787,5 +824,39 @@ _cogl_material_set_static_breadcrumb (CoglHandle handle,
unsigned long
_cogl_material_get_age (CoglHandle handle);
CoglMaterial *
_cogl_material_get_authority (CoglMaterial *material,
unsigned long difference);
typedef gboolean (*CoglMaterialChildCallback) (CoglMaterial *child,
void *user_data);
void
_cogl_material_foreach_child (CoglMaterial *material,
CoglMaterialChildCallback callback,
void *user_data);
unsigned long
_cogl_material_layer_compare_differences (CoglMaterialLayer *layer0,
CoglMaterialLayer *layer1);
CoglMaterialLayer *
_cogl_material_layer_get_authority (CoglMaterialLayer *layer,
unsigned long difference);
CoglHandle
_cogl_material_layer_get_texture (CoglMaterialLayer *layer);
typedef gboolean (*CoglMaterialLayerCallback) (CoglMaterialLayer *layer,
void *user_data);
void
_cogl_material_foreach_layer (CoglMaterial *material,
CoglMaterialLayerCallback callback,
void *user_data);
int
_cogl_material_layer_get_unit_index (CoglMaterialLayer *layer);
#endif /* __COGL_MATERIAL_PRIVATE_H */

File diff suppressed because it is too large Load Diff