2010-06-15 15:44:52 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2010-07-25 20:36:41 +00:00
|
|
|
#include "cogl-debug.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline-private.h"
|
2010-07-02 00:07:36 +00:00
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
#ifdef COGL_PIPELINE_FRAGEND_ARBFP
|
2010-07-02 00:07:36 +00:00
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-internal.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2010-06-15 15:44:52 +00:00
|
|
|
#include "cogl-handle.h"
|
|
|
|
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-blend-string.h"
|
|
|
|
#include "cogl-journal-private.h"
|
|
|
|
#include "cogl-color-private.h"
|
|
|
|
#include "cogl-profile.h"
|
2010-10-15 17:00:29 +00:00
|
|
|
#include "cogl-program-private.h"
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-01 21:04:59 +00:00
|
|
|
/* This might not be defined on GLES */
|
|
|
|
#ifndef GL_TEXTURE_3D
|
|
|
|
#define GL_TEXTURE_3D 0x806F
|
|
|
|
#endif
|
|
|
|
|
2010-09-13 20:17:30 +00:00
|
|
|
typedef struct _UnitState
|
|
|
|
{
|
2010-09-13 23:33:46 +00:00
|
|
|
int constant_id; /* The program.local[] index */
|
|
|
|
unsigned int dirty_combine_constant:1;
|
|
|
|
|
2010-09-13 20:17:30 +00:00
|
|
|
unsigned int sampled:1;
|
|
|
|
} UnitState;
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
typedef struct _ArbfpProgramState
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
int ref_count;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-12-08 16:29:37 +00:00
|
|
|
/* XXX: only valid during codegen */
|
|
|
|
CoglPipeline *arbfp_authority;
|
|
|
|
|
2010-08-04 16:53:51 +00:00
|
|
|
CoglHandle user_program;
|
2010-12-08 16:29:37 +00:00
|
|
|
/* XXX: only valid during codegen */
|
2010-06-15 15:44:52 +00:00
|
|
|
GString *source;
|
|
|
|
GLuint gl_program;
|
2010-09-13 20:17:30 +00:00
|
|
|
UnitState *unit_state;
|
2010-06-15 15:44:52 +00:00
|
|
|
int next_constant_id;
|
2010-09-14 17:50:50 +00:00
|
|
|
|
2010-10-15 17:00:29 +00:00
|
|
|
/* Age of the program the last time the uniforms were flushed. This
|
|
|
|
is used to detect when we need to flush all of the uniforms */
|
|
|
|
unsigned int user_program_age;
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
/* We need to track the last pipeline that an ARBfp program was used
|
2010-09-14 17:50:50 +00:00
|
|
|
* with so know if we need to update any program.local parameters. */
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *last_used_for_pipeline;
|
2010-09-14 17:50:50 +00:00
|
|
|
} ArbfpProgramState;
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
typedef struct _CoglPipelineFragendARBfpPrivate
|
2010-09-14 17:50:50 +00:00
|
|
|
{
|
|
|
|
ArbfpProgramState *arbfp_program_state;
|
2010-11-29 16:56:41 +00:00
|
|
|
} CoglPipelineFragendARBfpPrivate;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
const CoglPipelineFragend _cogl_pipeline_arbfp_fragend;
|
2010-09-14 11:13:30 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
|
|
|
|
static ArbfpProgramState *
|
|
|
|
arbfp_program_state_new (int n_layers)
|
|
|
|
{
|
|
|
|
ArbfpProgramState *state = g_slice_new0 (ArbfpProgramState);
|
|
|
|
state->ref_count = 1;
|
|
|
|
state->unit_state = g_new0 (UnitState, n_layers);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ArbfpProgramState *
|
|
|
|
arbfp_program_state_ref (ArbfpProgramState *state)
|
|
|
|
{
|
|
|
|
state->ref_count++;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arbfp_program_state_unref (ArbfpProgramState *state)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
g_return_if_fail (state->ref_count > 0);
|
|
|
|
|
|
|
|
state->ref_count--;
|
|
|
|
if (state->ref_count == 0)
|
|
|
|
{
|
|
|
|
if (state->gl_program)
|
|
|
|
{
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glDeletePrograms (1, &state->gl_program));
|
2010-09-14 17:50:50 +00:00
|
|
|
state->gl_program = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (state->unit_state);
|
|
|
|
|
|
|
|
g_slice_free (ArbfpProgramState, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
static CoglPipelineFragendARBfpPrivate *
|
2010-10-27 17:54:57 +00:00
|
|
|
get_arbfp_priv (CoglPipeline *pipeline)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
if (!(pipeline->fragend_priv_set_mask & COGL_PIPELINE_FRAGEND_ARBFP_MASK))
|
2010-09-14 17:50:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
return pipeline->fragend_privs[COGL_PIPELINE_FRAGEND_ARBFP];
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:18 +00:00
|
|
|
static void
|
2010-11-29 16:56:41 +00:00
|
|
|
set_arbfp_priv (CoglPipeline *pipeline, CoglPipelineFragendARBfpPrivate *priv)
|
2010-09-13 22:52:18 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
if (priv)
|
2010-09-13 22:52:18 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
pipeline->fragend_privs[COGL_PIPELINE_FRAGEND_ARBFP] = priv;
|
|
|
|
pipeline->fragend_priv_set_mask |= COGL_PIPELINE_FRAGEND_ARBFP_MASK;
|
2010-09-13 22:52:18 +00:00
|
|
|
}
|
2010-09-14 17:50:50 +00:00
|
|
|
else
|
2010-11-29 16:56:41 +00:00
|
|
|
pipeline->fragend_priv_set_mask &= ~COGL_PIPELINE_FRAGEND_ARBFP_MASK;
|
2010-09-14 17:50:50 +00:00
|
|
|
}
|
2010-09-13 22:52:18 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
static ArbfpProgramState *
|
2010-10-27 17:54:57 +00:00
|
|
|
get_arbfp_program_state (CoglPipeline *pipeline)
|
2010-09-14 17:50:50 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *priv = get_arbfp_priv (pipeline);
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!priv)
|
|
|
|
return NULL;
|
|
|
|
return priv->arbfp_program_state;
|
2010-09-13 22:52:18 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
static gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_start (CoglPipeline *pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
int n_layers,
|
2010-12-02 21:08:30 +00:00
|
|
|
unsigned long pipelines_difference,
|
|
|
|
int n_tex_coord_attribs)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *priv;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *authority;
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *authority_priv;
|
2010-12-08 16:23:10 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state;
|
2010-08-04 16:53:51 +00:00
|
|
|
CoglHandle user_program;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-08-04 16:53:51 +00:00
|
|
|
/* First validate that we can handle the current state using ARBfp
|
|
|
|
*/
|
|
|
|
|
2010-08-05 09:59:03 +00:00
|
|
|
if (!cogl_features_available (COGL_FEATURE_SHADERS_ARBFP))
|
2010-06-15 15:44:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* TODO: support fog */
|
2010-07-06 19:18:26 +00:00
|
|
|
if (ctx->legacy_fog_state.enabled)
|
2010-06-15 15:44:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
user_program = cogl_pipeline_get_user_program (pipeline);
|
2010-12-14 13:02:47 +00:00
|
|
|
if (user_program != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
/* If the program doesn't have a fragment shader then some other
|
|
|
|
vertend will handle the vertex shader state and we still need
|
|
|
|
to generate a fragment program */
|
|
|
|
if (!_cogl_program_has_fragment_shader (user_program))
|
|
|
|
user_program = COGL_INVALID_HANDLE;
|
|
|
|
/* If the user program does have a fragment shader then we can
|
|
|
|
only handle it if it's in ARBfp */
|
|
|
|
else if (_cogl_program_get_language (user_program) !=
|
|
|
|
COGL_SHADER_LANGUAGE_ARBFP)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-04 16:53:51 +00:00
|
|
|
|
|
|
|
/* Now lookup our ARBfp backend private state (allocating if
|
2010-09-14 17:50:50 +00:00
|
|
|
* necessary) */
|
2010-10-27 17:54:57 +00:00
|
|
|
priv = get_arbfp_priv (pipeline);
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!priv)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
priv = g_slice_new0 (CoglPipelineFragendARBfpPrivate);
|
2010-10-27 17:54:57 +00:00
|
|
|
set_arbfp_priv (pipeline, priv);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
/* If we have a valid arbfp_program_state pointer then we are all
|
|
|
|
* set and don't need to generate a new program. */
|
|
|
|
if (priv->arbfp_program_state)
|
|
|
|
return TRUE;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
/* If we don't have an associated arbfp program yet then find the
|
|
|
|
* arbfp-authority (the oldest ancestor whose state will result in
|
2010-10-27 17:54:57 +00:00
|
|
|
* the same program being generated as for this pipeline).
|
2010-09-13 22:52:18 +00:00
|
|
|
*
|
2010-09-14 17:50:50 +00:00
|
|
|
* We always make sure to associate new programs with the
|
2010-10-27 17:54:57 +00:00
|
|
|
* arbfp-authority to maximize the chance that other pipelines can
|
2010-09-14 17:50:50 +00:00
|
|
|
* share it.
|
2010-09-13 22:52:18 +00:00
|
|
|
*/
|
2010-12-01 17:06:18 +00:00
|
|
|
authority = _cogl_pipeline_find_equivalent_parent
|
|
|
|
(pipeline,
|
2011-07-07 19:44:56 +00:00
|
|
|
_cogl_pipeline_get_state_for_fragment_codegen (ctx) &
|
2010-12-01 17:06:18 +00:00
|
|
|
~COGL_PIPELINE_STATE_LAYERS,
|
2011-07-07 19:44:56 +00:00
|
|
|
_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx));
|
2010-09-14 17:50:50 +00:00
|
|
|
authority_priv = get_arbfp_priv (authority);
|
2010-12-08 16:23:10 +00:00
|
|
|
if (authority_priv &&
|
|
|
|
authority_priv->arbfp_program_state)
|
|
|
|
{
|
|
|
|
/* If we are going to share our program state with an arbfp-authority
|
|
|
|
* then steal a reference to the program state associated with that
|
|
|
|
* arbfp-authority... */
|
|
|
|
priv->arbfp_program_state =
|
|
|
|
arbfp_program_state_ref (authority_priv->arbfp_program_state);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!authority_priv)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
authority_priv = g_slice_new0 (CoglPipelineFragendARBfpPrivate);
|
2010-09-14 17:50:50 +00:00
|
|
|
set_arbfp_priv (authority, authority_priv);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 12:01:18 +00:00
|
|
|
/* If we haven't yet found an existing program then before we resort to
|
|
|
|
* generating a new arbfp program we see if we can find a suitable
|
|
|
|
* program in the arbfp_cache. */
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_PROGRAM_CACHES))))
|
2010-12-03 12:01:18 +00:00
|
|
|
{
|
2010-12-08 16:23:10 +00:00
|
|
|
arbfp_program_state = g_hash_table_lookup (ctx->arbfp_cache, authority);
|
|
|
|
if (arbfp_program_state)
|
|
|
|
{
|
|
|
|
priv->arbfp_program_state =
|
|
|
|
arbfp_program_state_ref (arbfp_program_state);
|
|
|
|
|
|
|
|
/* Since we have already resolved the arbfp-authority at this point
|
|
|
|
* we might as well also associate any program we find from the cache
|
|
|
|
* with the authority too... */
|
|
|
|
if (authority_priv != priv)
|
|
|
|
authority_priv->arbfp_program_state =
|
|
|
|
arbfp_program_state_ref (arbfp_program_state);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-12-03 12:01:18 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 16:23:10 +00:00
|
|
|
/* If we still haven't found an existing program then start
|
|
|
|
* generating code for a new program...
|
|
|
|
*/
|
|
|
|
|
|
|
|
arbfp_program_state = arbfp_program_state_new (n_layers);
|
|
|
|
|
|
|
|
priv->arbfp_program_state = arbfp_program_state_ref (arbfp_program_state);
|
|
|
|
|
|
|
|
/* Since we have already resolved the arbfp-authority at this point we might
|
|
|
|
* as well also associate any program we generate with the authority too...
|
|
|
|
*/
|
|
|
|
if (authority_priv != priv)
|
|
|
|
authority_priv->arbfp_program_state =
|
|
|
|
arbfp_program_state_ref (arbfp_program_state);
|
|
|
|
|
|
|
|
arbfp_program_state->user_program = user_program;
|
|
|
|
if (user_program == COGL_INVALID_HANDLE)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-12-08 16:23:10 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* We reuse a single grow-only GString for code-gen */
|
2010-12-02 18:05:22 +00:00
|
|
|
g_string_set_size (ctx->codegen_source_buffer, 0);
|
|
|
|
arbfp_program_state->source = ctx->codegen_source_buffer;
|
2010-12-08 16:23:10 +00:00
|
|
|
g_string_append (arbfp_program_state->source,
|
|
|
|
"!!ARBfp1.0\n"
|
|
|
|
"TEMP output;\n"
|
|
|
|
"TEMP tmp0, tmp1, tmp2, tmp3, tmp4;\n"
|
|
|
|
"PARAM half = {.5, .5, .5, .5};\n"
|
|
|
|
"PARAM one = {1, 1, 1, 1};\n"
|
|
|
|
"PARAM two = {2, 2, 2, 2};\n"
|
|
|
|
"PARAM minus_one = {-1, -1, -1, -1};\n");
|
|
|
|
|
2010-12-08 16:29:37 +00:00
|
|
|
/* At the end of code-gen we'll add the program to a cache and
|
|
|
|
* we'll use the authority pipeline as the basis for key into
|
|
|
|
* that cache... */
|
|
|
|
arbfp_program_state->arbfp_authority = authority;
|
|
|
|
|
2010-12-08 16:23:10 +00:00
|
|
|
for (i = 0; i < n_layers; i++)
|
2010-09-13 20:17:30 +00:00
|
|
|
{
|
2010-12-08 16:23:10 +00:00
|
|
|
arbfp_program_state->unit_state[i].sampled = FALSE;
|
|
|
|
arbfp_program_state->unit_state[i].dirty_combine_constant = FALSE;
|
2010-09-13 20:17:30 +00:00
|
|
|
}
|
2010-12-08 16:27:57 +00:00
|
|
|
arbfp_program_state->next_constant_id = 0;
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
return TRUE;
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 12:01:18 +00:00
|
|
|
unsigned int
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_hash (const void *data)
|
2010-12-03 12:01:18 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
unsigned int fragment_state;
|
|
|
|
unsigned int layer_fragment_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
fragment_state =
|
|
|
|
_cogl_pipeline_get_state_for_fragment_codegen (ctx);
|
|
|
|
layer_fragment_state =
|
|
|
|
_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx);
|
2010-12-03 12:01:18 +00:00
|
|
|
|
|
|
|
return _cogl_pipeline_hash ((CoglPipeline *)data,
|
2011-07-07 19:44:56 +00:00
|
|
|
|
2010-12-03 12:01:18 +00:00
|
|
|
fragment_state, layer_fragment_state,
|
2011-01-11 16:02:06 +00:00
|
|
|
0);
|
2010-12-03 12:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_equal (const void *a, const void *b)
|
2010-12-03 12:01:18 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
unsigned int fragment_state;
|
|
|
|
unsigned int layer_fragment_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
fragment_state =
|
|
|
|
_cogl_pipeline_get_state_for_fragment_codegen (ctx);
|
|
|
|
layer_fragment_state =
|
|
|
|
_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx);
|
2010-12-03 12:01:18 +00:00
|
|
|
|
|
|
|
return _cogl_pipeline_equal ((CoglPipeline *)a, (CoglPipeline *)b,
|
|
|
|
fragment_state, layer_fragment_state,
|
2011-01-11 16:02:06 +00:00
|
|
|
0);
|
2010-12-03 12:01:18 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
static const char *
|
|
|
|
gl_target_to_arbfp_string (GLenum gl_target)
|
|
|
|
{
|
|
|
|
if (gl_target == GL_TEXTURE_1D)
|
|
|
|
return "1D";
|
2011-07-07 19:44:56 +00:00
|
|
|
else if (gl_target == GL_TEXTURE_2D)
|
2010-06-15 15:44:52 +00:00
|
|
|
return "2D";
|
|
|
|
#ifdef GL_ARB_texture_rectangle
|
|
|
|
else if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
return "RECT";
|
|
|
|
#endif
|
2010-07-01 21:04:59 +00:00
|
|
|
else if (gl_target == GL_TEXTURE_3D)
|
|
|
|
return "3D";
|
2010-06-15 15:44:52 +00:00
|
|
|
else
|
|
|
|
return "2D";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-09-14 17:50:50 +00:00
|
|
|
setup_texture_source (ArbfpProgramState *arbfp_program_state,
|
2010-06-15 15:44:52 +00:00
|
|
|
int unit_index,
|
|
|
|
GLenum gl_target)
|
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!arbfp_program_state->unit_state[unit_index].sampled)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2011-06-08 17:03:58 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)))
|
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
|
|
|
"TEMP texel%d;\n"
|
|
|
|
"MOV texel%d, one;\n",
|
|
|
|
unit_index,
|
|
|
|
unit_index);
|
|
|
|
else
|
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
|
|
|
"TEMP texel%d;\n"
|
|
|
|
"TEX texel%d,fragment.texcoord[%d],"
|
|
|
|
"texture[%d],%s;\n",
|
|
|
|
unit_index,
|
|
|
|
unit_index,
|
|
|
|
unit_index,
|
|
|
|
unit_index,
|
|
|
|
gl_target_to_arbfp_string (gl_target));
|
2010-09-14 17:50:50 +00:00
|
|
|
arbfp_program_state->unit_state[unit_index].sampled = TRUE;
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
typedef enum _CoglPipelineFragendARBfpArgType
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE,
|
|
|
|
COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_CONSTANT,
|
|
|
|
COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_TEXTURE
|
|
|
|
} CoglPipelineFragendARBfpArgType;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
typedef struct _CoglPipelineFragendARBfpArg
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpArgType type;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
/* for type = TEXTURE */
|
|
|
|
int texture_unit;
|
|
|
|
GLenum texture_target;
|
|
|
|
|
|
|
|
/* for type = CONSTANT */
|
|
|
|
int constant_id;
|
|
|
|
|
|
|
|
const char *swizzle;
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
} CoglPipelineFragendARBfpArg;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
static void
|
2010-11-29 16:56:41 +00:00
|
|
|
append_arg (GString *source, const CoglPipelineFragendARBfpArg *arg)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
switch (arg->type)
|
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
case COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_TEXTURE:
|
2010-06-15 15:44:52 +00:00
|
|
|
g_string_append_printf (source, "texel%d%s",
|
|
|
|
arg->texture_unit, arg->swizzle);
|
|
|
|
break;
|
2010-11-29 16:56:41 +00:00
|
|
|
case COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_CONSTANT:
|
2010-09-13 23:33:46 +00:00
|
|
|
g_string_append_printf (source, "program.local[%d]%s",
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->constant_id, arg->swizzle);
|
|
|
|
break;
|
2010-11-29 16:56:41 +00:00
|
|
|
case COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE:
|
2010-06-15 15:44:52 +00:00
|
|
|
g_string_append_printf (source, "%s%s",
|
|
|
|
arg->name, arg->swizzle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: we are trying to avoid duplicating strings during codegen
|
|
|
|
* which is why we have the slightly awkward
|
2010-11-29 16:56:41 +00:00
|
|
|
* CoglPipelineFragendARBfpArg mechanism. */
|
2010-06-15 15:44:52 +00:00
|
|
|
static void
|
2010-10-27 17:54:57 +00:00
|
|
|
setup_arg (CoglPipeline *pipeline,
|
|
|
|
CoglPipelineLayer *layer,
|
2010-06-15 15:44:52 +00:00
|
|
|
CoglBlendStringChannelMask mask,
|
|
|
|
int arg_index,
|
|
|
|
GLint src,
|
|
|
|
GLint op,
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpArg *arg)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (pipeline);
|
2010-06-15 15:44:52 +00:00
|
|
|
static const char *tmp_name[3] = { "tmp0", "tmp1", "tmp2" };
|
|
|
|
GLenum gl_target;
|
|
|
|
CoglHandle texture;
|
|
|
|
|
|
|
|
switch (src)
|
|
|
|
{
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_TEXTURE:
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_TEXTURE;
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = "texel%d";
|
2010-10-27 17:54:57 +00:00
|
|
|
arg->texture_unit = _cogl_pipeline_layer_get_unit_index (layer);
|
|
|
|
texture = _cogl_pipeline_layer_get_texture (layer);
|
2010-06-15 15:44:52 +00:00
|
|
|
cogl_texture_get_gl_texture (texture, NULL, &gl_target);
|
2010-09-14 17:50:50 +00:00
|
|
|
setup_texture_source (arbfp_program_state, arg->texture_unit, gl_target);
|
2010-06-15 15:44:52 +00:00
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_CONSTANT:
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
2010-09-14 17:50:50 +00:00
|
|
|
UnitState *unit_state = &arbfp_program_state->unit_state[unit_index];
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
unit_state->constant_id = arbfp_program_state->next_constant_id++;
|
2010-09-13 23:33:46 +00:00
|
|
|
unit_state->dirty_combine_constant = TRUE;
|
2010-07-16 22:37:59 +00:00
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_CONSTANT;
|
2010-09-13 23:33:46 +00:00
|
|
|
arg->name = "program.local[%d]";
|
|
|
|
arg->constant_id = unit_state->constant_id;
|
2010-06-15 15:44:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_PRIMARY_COLOR:
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE;
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = "fragment.color.primary";
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_SOURCE_PREVIOUS:
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE;
|
2010-10-27 17:54:57 +00:00
|
|
|
if (_cogl_pipeline_layer_get_unit_index (layer) == 0)
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = "fragment.color.primary";
|
|
|
|
else
|
|
|
|
arg->name = "output";
|
|
|
|
break;
|
|
|
|
default: /* GL_TEXTURE0..N */
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_TEXTURE;
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = "texture[%d]";
|
|
|
|
arg->texture_unit = src - GL_TEXTURE0;
|
2010-10-27 17:54:57 +00:00
|
|
|
texture = _cogl_pipeline_layer_get_texture (layer);
|
2010-06-15 15:44:52 +00:00
|
|
|
cogl_texture_get_gl_texture (texture, NULL, &gl_target);
|
2010-09-14 17:50:50 +00:00
|
|
|
setup_texture_source (arbfp_program_state, arg->texture_unit, gl_target);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
arg->swizzle = "";
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_OP_SRC_COLOR:
|
2010-06-15 15:44:52 +00:00
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_OP_ONE_MINUS_SRC_COLOR:
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
2010-06-15 15:44:52 +00:00
|
|
|
"SUB tmp%d, one, ",
|
|
|
|
arg_index);
|
2010-09-14 17:50:50 +00:00
|
|
|
append_arg (arbfp_program_state->source, arg);
|
|
|
|
g_string_append_printf (arbfp_program_state->source, ";\n");
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE;
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = tmp_name[arg_index];
|
|
|
|
arg->swizzle = "";
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_OP_SRC_ALPHA:
|
2010-06-15 15:44:52 +00:00
|
|
|
/* avoid a swizzle if we know RGB are going to be masked
|
|
|
|
* in the end anyway */
|
|
|
|
if (mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
|
|
|
arg->swizzle = ".a";
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_OP_ONE_MINUS_SRC_ALPHA:
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
2010-06-15 15:44:52 +00:00
|
|
|
"SUB tmp%d, one, ",
|
|
|
|
arg_index);
|
2010-09-14 17:50:50 +00:00
|
|
|
append_arg (arbfp_program_state->source, arg);
|
2010-06-15 15:44:52 +00:00
|
|
|
/* avoid a swizzle if we know RGB are going to be masked
|
|
|
|
* in the end anyway */
|
|
|
|
if (mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, ".a;\n");
|
2010-06-15 15:44:52 +00:00
|
|
|
else
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, ";\n");
|
2010-11-29 16:56:41 +00:00
|
|
|
arg->type = COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_SIMPLE;
|
2010-06-15 15:44:52 +00:00
|
|
|
arg->name = tmp_name[arg_index];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error ("Unknown texture combine operator %d", op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
fragend_arbfp_args_equal (CoglPipelineFragendARBfpArg *arg0,
|
|
|
|
CoglPipelineFragendARBfpArg *arg1)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
if (arg0->type != arg1->type)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (arg0->name != arg1->name &&
|
|
|
|
strcmp (arg0->name, arg1->name) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
if (arg0->type == COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_TEXTURE &&
|
2010-06-15 15:44:52 +00:00
|
|
|
arg0->texture_unit != arg1->texture_unit)
|
|
|
|
return FALSE;
|
|
|
|
/* Note we don't have to check the target; a texture unit can only
|
|
|
|
* have one target enabled at a time. */
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
if (arg0->type == COGL_PIPELINE_FRAGEND_ARBFP_ARG_TYPE_CONSTANT &&
|
2011-05-11 12:50:32 +00:00
|
|
|
arg0->constant_id != arg1->constant_id)
|
2010-06-15 15:44:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (arg0->swizzle != arg1->swizzle &&
|
|
|
|
strcmp (arg0->swizzle, arg1->swizzle) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-27 17:54:57 +00:00
|
|
|
append_function (CoglPipeline *pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
CoglBlendStringChannelMask mask,
|
|
|
|
GLint function,
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpArg *args,
|
2010-06-15 15:44:52 +00:00
|
|
|
int n_args)
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (pipeline);
|
2010-06-15 15:44:52 +00:00
|
|
|
const char *mask_name;
|
|
|
|
|
|
|
|
switch (mask)
|
|
|
|
{
|
|
|
|
case COGL_BLEND_STRING_CHANNEL_MASK_RGB:
|
|
|
|
mask_name = ".rgb";
|
|
|
|
break;
|
|
|
|
case COGL_BLEND_STRING_CHANNEL_MASK_ALPHA:
|
|
|
|
mask_name = ".a";
|
|
|
|
break;
|
|
|
|
case COGL_BLEND_STRING_CHANNEL_MASK_RGBA:
|
|
|
|
mask_name = "";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error ("Unknown channel mask %d", mask);
|
|
|
|
mask_name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (function)
|
|
|
|
{
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_ADD:
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
|
|
|
"ADD_SAT output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_MODULATE:
|
2010-06-15 15:44:52 +00:00
|
|
|
/* Note: no need to saturate since we can assume operands
|
|
|
|
* have values in the range [0,1] */
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, "MUL output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_REPLACE:
|
2010-06-15 15:44:52 +00:00
|
|
|
/* Note: no need to saturate since we can assume operand
|
|
|
|
* has a value in the range [0,1] */
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, "MOV output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_SUBTRACT:
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
|
|
|
"SUB_SAT output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_ADD_SIGNED:
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, "ADD tmp3%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
2010-09-14 17:50:50 +00:00
|
|
|
append_arg (arbfp_program_state->source, &args[0]);
|
|
|
|
g_string_append (arbfp_program_state->source, ", ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[1]);
|
|
|
|
g_string_append (arbfp_program_state->source, ";\n");
|
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
|
|
|
"SUB_SAT output%s, tmp3, half",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
n_args = 0;
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_DOT3_RGB:
|
2010-06-15 15:44:52 +00:00
|
|
|
/* These functions are the same except that GL_DOT3_RGB never
|
|
|
|
* updates the alpha channel.
|
|
|
|
*
|
|
|
|
* NB: GL_DOT3_RGBA is a bit special because it effectively forces
|
|
|
|
* an RGBA mask and we end up ignoring any separate alpha channel
|
|
|
|
* function.
|
|
|
|
*/
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_DOT3_RGBA:
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
const char *tmp4 = "tmp4";
|
|
|
|
|
|
|
|
/* The maths for this was taken from Mesa;
|
|
|
|
* apparently:
|
|
|
|
*
|
|
|
|
* tmp3 = 2*src0 - 1
|
|
|
|
* tmp4 = 2*src1 - 1
|
|
|
|
* output = DP3 (tmp3, tmp4)
|
|
|
|
*
|
|
|
|
* is the same as:
|
|
|
|
*
|
|
|
|
* output = 4 * DP3 (src0 - 0.5, src1 - 0.5)
|
|
|
|
*/
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source, "MAD tmp3, two, ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[0]);
|
|
|
|
g_string_append (arbfp_program_state->source, ", minus_one;\n");
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
if (!fragend_arbfp_args_equal (&args[0], &args[1]))
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source, "MAD tmp4, two, ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[1]);
|
|
|
|
g_string_append (arbfp_program_state->source, ", minus_one;\n");
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
tmp4 = "tmp3";
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source,
|
2010-06-15 15:44:52 +00:00
|
|
|
"DP3_SAT output%s, tmp3, %s",
|
|
|
|
mask_name, tmp4);
|
|
|
|
n_args = 0;
|
|
|
|
}
|
|
|
|
break;
|
2010-12-06 21:29:56 +00:00
|
|
|
case COGL_PIPELINE_COMBINE_FUNC_INTERPOLATE:
|
2010-06-15 15:44:52 +00:00
|
|
|
/* Note: no need to saturate since we can assume operands
|
|
|
|
* have values in the range [0,1] */
|
|
|
|
|
|
|
|
/* NB: GL_INTERPOLATE = arg0*arg2 + arg1*(1-arg2)
|
|
|
|
* but LRP dst, a, b, c = b*a + c*(1-a) */
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, "LRP output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
2010-09-14 17:50:50 +00:00
|
|
|
append_arg (arbfp_program_state->source, &args[2]);
|
|
|
|
g_string_append (arbfp_program_state->source, ", ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[0]);
|
|
|
|
g_string_append (arbfp_program_state->source, ", ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[1]);
|
2010-06-15 15:44:52 +00:00
|
|
|
n_args = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error ("Unknown texture combine function %d", function);
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append_printf (arbfp_program_state->source, "MUL_SAT output%s, ",
|
2010-06-15 15:44:52 +00:00
|
|
|
mask_name);
|
|
|
|
n_args = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_args > 0)
|
2010-09-14 17:50:50 +00:00
|
|
|
append_arg (arbfp_program_state->source, &args[0]);
|
2010-06-15 15:44:52 +00:00
|
|
|
if (n_args > 1)
|
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source, ", ");
|
|
|
|
append_arg (arbfp_program_state->source, &args[1]);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source, ";\n");
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-27 17:54:57 +00:00
|
|
|
append_masked_combine (CoglPipeline *arbfp_authority,
|
|
|
|
CoglPipelineLayer *layer,
|
2010-06-15 15:44:52 +00:00
|
|
|
CoglBlendStringChannelMask mask,
|
2010-12-06 21:29:56 +00:00
|
|
|
CoglPipelineCombineFunc function,
|
|
|
|
CoglPipelineCombineSource *src,
|
|
|
|
CoglPipelineCombineOp *op)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n_args;
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpArg args[3];
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
n_args = _cogl_get_n_args_for_combine_func (function);
|
|
|
|
|
|
|
|
for (i = 0; i < n_args; i++)
|
|
|
|
{
|
|
|
|
setup_arg (arbfp_authority,
|
|
|
|
layer,
|
|
|
|
mask,
|
|
|
|
i,
|
|
|
|
src[i],
|
|
|
|
op[i],
|
|
|
|
&args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
append_function (arbfp_authority,
|
|
|
|
mask,
|
|
|
|
function,
|
|
|
|
args,
|
|
|
|
n_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_add_layer (CoglPipeline *pipeline,
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipelineLayer *layer,
|
2010-06-15 15:44:52 +00:00
|
|
|
unsigned long layers_difference)
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (pipeline);
|
|
|
|
CoglPipelineLayer *combine_authority =
|
|
|
|
_cogl_pipeline_layer_get_authority (layer,
|
|
|
|
COGL_PIPELINE_LAYER_STATE_COMBINE);
|
|
|
|
CoglPipelineLayerBigState *big_state = combine_authority->big_state;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
/* Notes...
|
|
|
|
*
|
|
|
|
* We are ignoring the issue of texture indirection limits until
|
|
|
|
* someone complains (Ref Section 3.11.6 in the ARB_fragment_program
|
|
|
|
* spec)
|
|
|
|
*
|
|
|
|
* There always five TEMPs named tmp0, tmp1 and tmp2, tmp3 and tmp4
|
|
|
|
* available and these constants: 'one' = {1, 1, 1, 1}, 'half'
|
|
|
|
* {.5, .5, .5, .5}, 'two' = {2, 2, 2, 2}, 'minus_one' = {-1, -1,
|
|
|
|
* -1, -1}
|
|
|
|
*
|
|
|
|
* tmp0-2 are intended for dealing with some of the texture combine
|
|
|
|
* operands (e.g. GL_ONE_MINUS_SRC_COLOR) tmp3/4 are for dealing
|
|
|
|
* with the GL_ADD_SIGNED texture combine and the GL_DOT3_RGB[A]
|
|
|
|
* functions.
|
|
|
|
*
|
|
|
|
* Each layer outputs to the TEMP called "output", and reads from
|
|
|
|
* output if it needs to refer to GL_PREVIOUS. (we detect if we are
|
|
|
|
* layer0 so we will read fragment.color for GL_PREVIOUS in that
|
|
|
|
* case)
|
|
|
|
*
|
|
|
|
* We aim to do all the channels together if the same function is
|
|
|
|
* used for RGB as for A.
|
|
|
|
*
|
|
|
|
* We aim to avoid string duplication / allocations during codegen.
|
|
|
|
*
|
|
|
|
* We are careful to only saturate when writing to output.
|
|
|
|
*/
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!arbfp_program_state->source)
|
2010-06-15 15:44:52 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2010-11-19 15:42:26 +00:00
|
|
|
if (!_cogl_pipeline_need_texture_combine_separate (combine_authority))
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
append_masked_combine (pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
layer,
|
|
|
|
COGL_BLEND_STRING_CHANNEL_MASK_RGBA,
|
|
|
|
big_state->texture_combine_rgb_func,
|
|
|
|
big_state->texture_combine_rgb_src,
|
|
|
|
big_state->texture_combine_rgb_op);
|
|
|
|
}
|
2010-12-06 21:29:56 +00:00
|
|
|
else if (big_state->texture_combine_rgb_func ==
|
|
|
|
COGL_PIPELINE_COMBINE_FUNC_DOT3_RGBA)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
/* GL_DOT3_RGBA Is a bit weird as a GL_COMBINE_RGB function
|
|
|
|
* since if you use it, it overrides your ALPHA function...
|
|
|
|
*/
|
2010-10-27 17:54:57 +00:00
|
|
|
append_masked_combine (pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
layer,
|
|
|
|
COGL_BLEND_STRING_CHANNEL_MASK_RGBA,
|
|
|
|
big_state->texture_combine_rgb_func,
|
|
|
|
big_state->texture_combine_rgb_src,
|
|
|
|
big_state->texture_combine_rgb_op);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
append_masked_combine (pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
layer,
|
|
|
|
COGL_BLEND_STRING_CHANNEL_MASK_RGB,
|
|
|
|
big_state->texture_combine_rgb_func,
|
|
|
|
big_state->texture_combine_rgb_src,
|
|
|
|
big_state->texture_combine_rgb_op);
|
2010-10-27 17:54:57 +00:00
|
|
|
append_masked_combine (pipeline,
|
2010-06-15 15:44:52 +00:00
|
|
|
layer,
|
|
|
|
COGL_BLEND_STRING_CHANNEL_MASK_ALPHA,
|
|
|
|
big_state->texture_combine_alpha_func,
|
|
|
|
big_state->texture_combine_alpha_src,
|
|
|
|
big_state->texture_combine_alpha_op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_passthrough (CoglPipeline *pipeline)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (pipeline);
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!arbfp_program_state->source)
|
2010-06-15 15:44:52 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source,
|
|
|
|
"MOV output, fragment.color.primary;\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _UpdateConstantsState
|
|
|
|
{
|
|
|
|
int unit;
|
2010-09-14 19:25:23 +00:00
|
|
|
gboolean update_all;
|
2010-09-14 17:50:50 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state;
|
|
|
|
} UpdateConstantsState;
|
|
|
|
|
|
|
|
static gboolean
|
2010-10-27 17:54:57 +00:00
|
|
|
update_constants_cb (CoglPipeline *pipeline,
|
2010-09-14 17:50:50 +00:00
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
UpdateConstantsState *state = user_data;
|
|
|
|
ArbfpProgramState *arbfp_program_state = state->arbfp_program_state;
|
|
|
|
UnitState *unit_state = &arbfp_program_state->unit_state[state->unit++];
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-09-14 19:25:23 +00:00
|
|
|
if (state->update_all || unit_state->dirty_combine_constant)
|
2010-09-14 17:50:50 +00:00
|
|
|
{
|
|
|
|
float constant[4];
|
2010-10-27 17:54:57 +00:00
|
|
|
_cogl_pipeline_get_layer_combine_constant (pipeline,
|
2010-09-14 17:50:50 +00:00
|
|
|
layer_index,
|
|
|
|
constant);
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
unit_state->constant_id,
|
|
|
|
constant));
|
2010-09-14 17:50:50 +00:00
|
|
|
unit_state->dirty_combine_constant = FALSE;
|
|
|
|
}
|
2010-06-15 15:44:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
|
2010-10-27 17:54:57 +00:00
|
|
|
unsigned long pipelines_difference)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (pipeline);
|
2010-08-04 16:53:51 +00:00
|
|
|
GLuint gl_program;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (arbfp_program_state->source)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
GLenum gl_error;
|
2010-11-29 16:56:41 +00:00
|
|
|
COGL_STATIC_COUNTER (fragend_arbfp_compile_counter,
|
2010-06-15 15:44:52 +00:00
|
|
|
"arbfp compile counter",
|
|
|
|
"Increments each time a new ARBfp "
|
|
|
|
"program is compiled",
|
|
|
|
0 /* no application private data */);
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
COGL_COUNTER_INC (_cogl_uprof_context, fragend_arbfp_compile_counter);
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
g_string_append (arbfp_program_state->source,
|
|
|
|
"MOV result.color,output;\n");
|
|
|
|
g_string_append (arbfp_program_state->source, "END\n");
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
|
2010-10-27 17:54:57 +00:00
|
|
|
g_message ("pipeline program:\n%s", arbfp_program_state->source->str);
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glGenPrograms (1, &arbfp_program_state->gl_program));
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB,
|
2010-09-14 17:50:50 +00:00
|
|
|
arbfp_program_state->gl_program));
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
2010-06-15 15:44:52 +00:00
|
|
|
;
|
2011-07-06 20:51:00 +00:00
|
|
|
ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
GL_PROGRAM_FORMAT_ASCII_ARB,
|
|
|
|
arbfp_program_state->source->len,
|
|
|
|
arbfp_program_state->source->str);
|
|
|
|
if (ctx->glGetError () != GL_NO_ERROR)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
|
|
|
g_warning ("\n%s\n%s",
|
2010-09-14 17:50:50 +00:00
|
|
|
arbfp_program_state->source->str,
|
2011-07-06 20:51:00 +00:00
|
|
|
ctx->glGetString (GL_PROGRAM_ERROR_STRING_ARB));
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
arbfp_program_state->source = NULL;
|
2010-12-03 12:01:18 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_PROGRAM_CACHES))))
|
2010-12-03 12:01:18 +00:00
|
|
|
{
|
2010-12-08 16:29:37 +00:00
|
|
|
CoglPipeline *key;
|
|
|
|
|
2010-12-03 12:01:18 +00:00
|
|
|
/* XXX: I wish there was a way to insert into a GHashTable
|
|
|
|
* with a pre-calculated hash value since there is a cost to
|
|
|
|
* calculating the hash of a CoglPipeline and in this case
|
|
|
|
* we know we have already called _cogl_pipeline_hash during
|
2010-11-29 16:56:41 +00:00
|
|
|
* _cogl_pipeline_fragend_arbfp_backend_start so we could pass the
|
2010-12-03 12:01:18 +00:00
|
|
|
* value through to here to avoid hashing it again.
|
|
|
|
*/
|
2010-12-08 16:29:37 +00:00
|
|
|
|
|
|
|
/* XXX: Any keys referenced by the hash table need to remain
|
|
|
|
* valid all the while that there are corresponding values,
|
|
|
|
* so for now we simply make a copy of the current authority
|
|
|
|
* pipeline.
|
|
|
|
*
|
|
|
|
* FIXME: A problem with this is that our key into the cache
|
|
|
|
* may hold references to some arbitrary user textures which
|
|
|
|
* will now be kept alive indefinitly which is a shame. A
|
|
|
|
* better solution will be to derive a special "key
|
|
|
|
* pipeline" from the authority which derives from the base
|
|
|
|
* Cogl pipeline (to avoid affecting the lifetime of any
|
|
|
|
* other pipelines) and only takes a copy of the state that
|
|
|
|
* relates to the arbfp program and references small dummy
|
|
|
|
* textures instead of potentially large user textures. */
|
|
|
|
key = cogl_pipeline_copy (arbfp_program_state->arbfp_authority);
|
2010-12-03 12:01:18 +00:00
|
|
|
arbfp_program_state_ref (arbfp_program_state);
|
2010-12-08 16:29:37 +00:00
|
|
|
g_hash_table_insert (ctx->arbfp_cache, key, arbfp_program_state);
|
2010-12-03 12:01:18 +00:00
|
|
|
if (G_UNLIKELY (g_hash_table_size (ctx->arbfp_cache) > 50))
|
|
|
|
{
|
|
|
|
static gboolean seen = FALSE;
|
|
|
|
if (!seen)
|
|
|
|
g_warning ("Over 50 separate ARBfp programs have been "
|
|
|
|
"generated which is very unusual, so something "
|
|
|
|
"is probably wrong!\n");
|
|
|
|
seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2010-12-08 16:29:37 +00:00
|
|
|
|
|
|
|
/* The authority is only valid during codegen since the program
|
|
|
|
* state may have a longer lifetime than the original authority
|
|
|
|
* it is created for. */
|
|
|
|
arbfp_program_state->arbfp_authority = NULL;
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
2010-08-04 16:53:51 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (arbfp_program_state->user_program != COGL_INVALID_HANDLE)
|
2010-08-04 16:53:51 +00:00
|
|
|
{
|
2010-10-15 17:00:29 +00:00
|
|
|
/* An arbfp program should contain exactly one shader which we
|
|
|
|
can use directly */
|
|
|
|
CoglProgram *program = arbfp_program_state->user_program;
|
|
|
|
CoglShader *shader = program->attached_shaders->data;
|
|
|
|
|
|
|
|
gl_program = shader->gl_handle;
|
2010-08-04 16:53:51 +00:00
|
|
|
}
|
2010-06-15 15:44:52 +00:00
|
|
|
else
|
2010-09-14 17:50:50 +00:00
|
|
|
gl_program = arbfp_program_state->gl_program;
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB, gl_program));
|
2010-12-02 20:48:45 +00:00
|
|
|
_cogl_use_fragment_program (0, COGL_PIPELINE_PROGRAM_TYPE_ARBFP);
|
2010-06-15 15:44:52 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (arbfp_program_state->user_program == COGL_INVALID_HANDLE)
|
2010-09-13 23:33:46 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
UpdateConstantsState state;
|
|
|
|
state.unit = 0;
|
|
|
|
state.arbfp_program_state = arbfp_program_state;
|
2010-10-27 17:54:57 +00:00
|
|
|
/* If this arbfp program was last used with a different pipeline
|
2010-09-14 19:25:23 +00:00
|
|
|
* then we need to ensure we update all program.local params */
|
|
|
|
state.update_all =
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline != arbfp_program_state->last_used_for_pipeline;
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
2010-09-14 17:50:50 +00:00
|
|
|
update_constants_cb,
|
|
|
|
&state);
|
2010-09-13 23:33:46 +00:00
|
|
|
}
|
2010-10-15 17:00:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglProgram *program = arbfp_program_state->user_program;
|
|
|
|
gboolean program_changed;
|
|
|
|
|
|
|
|
/* If the shader has changed since it was last flushed then we
|
|
|
|
need to update all uniforms */
|
|
|
|
program_changed = program->age != arbfp_program_state->user_program_age;
|
|
|
|
|
|
|
|
_cogl_program_flush_uniforms (program, gl_program, program_changed);
|
|
|
|
|
|
|
|
arbfp_program_state->user_program_age = program->age;
|
|
|
|
}
|
2010-09-13 23:33:46 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
/* We need to track what pipeline used this arbfp program last since
|
2010-09-14 19:25:23 +00:00
|
|
|
* we will need to update program.local params when switching
|
2010-10-27 17:54:57 +00:00
|
|
|
* between different pipelines. */
|
|
|
|
arbfp_program_state->last_used_for_pipeline = pipeline;
|
2010-09-14 19:25:23 +00:00
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:18 +00:00
|
|
|
static void
|
2010-10-27 17:54:57 +00:00
|
|
|
dirty_arbfp_program_state (CoglPipeline *pipeline)
|
2010-09-13 22:52:18 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *priv;
|
2010-09-13 22:52:18 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2010-09-13 22:52:18 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
priv = get_arbfp_priv (pipeline);
|
2010-09-14 17:50:50 +00:00
|
|
|
if (!priv)
|
|
|
|
return;
|
2010-09-13 22:52:18 +00:00
|
|
|
|
2010-09-14 17:50:50 +00:00
|
|
|
if (priv->arbfp_program_state)
|
2010-09-13 22:52:18 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
arbfp_program_state_unref (priv->arbfp_program_state);
|
|
|
|
priv->arbfp_program_state = NULL;
|
2010-09-13 22:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
static void
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_pipeline_pre_change_notify (
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglPipelineState change,
|
2010-06-15 15:44:52 +00:00
|
|
|
const CoglColor *new_color)
|
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if ((change & _cogl_pipeline_get_state_for_fragment_codegen (ctx)))
|
2010-12-01 17:06:18 +00:00
|
|
|
dirty_arbfp_program_state (pipeline);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 22:05:49 +00:00
|
|
|
/* NB: layers are considered immutable once they have any dependants
|
2010-10-27 17:54:57 +00:00
|
|
|
* so although multiple pipelines can end up depending on a single
|
2010-09-13 22:05:49 +00:00
|
|
|
* static layer, we can guarantee that if a layer is being *changed*
|
2010-10-27 17:54:57 +00:00
|
|
|
* then it can only have one pipeline depending on it.
|
2010-09-13 22:05:49 +00:00
|
|
|
*
|
|
|
|
* XXX: Don't forget this is *pre* change, we can't read the new value
|
|
|
|
* yet!
|
|
|
|
*/
|
2010-06-15 15:44:52 +00:00
|
|
|
static void
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_layer_pre_change_notify (
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *owner,
|
|
|
|
CoglPipelineLayer *layer,
|
|
|
|
CoglPipelineLayerState change)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *priv = get_arbfp_priv (owner);
|
2011-07-07 19:44:56 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-09-13 23:18:02 +00:00
|
|
|
if (!priv)
|
|
|
|
return;
|
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
if ((change & _cogl_pipeline_get_layer_state_for_fragment_codegen (ctx)))
|
2010-09-13 23:27:57 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
dirty_arbfp_program_state (owner);
|
2010-09-13 23:27:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-09-13 23:18:02 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
if (change & COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT)
|
2010-09-13 23:33:46 +00:00
|
|
|
{
|
2010-12-08 18:57:42 +00:00
|
|
|
ArbfpProgramState *arbfp_program_state = get_arbfp_program_state (owner);
|
|
|
|
|
|
|
|
if (arbfp_program_state)
|
|
|
|
{
|
|
|
|
int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
|
|
|
|
arbfp_program_state->unit_state[unit_index].dirty_combine_constant =
|
|
|
|
TRUE;
|
|
|
|
}
|
2010-09-13 23:33:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 15:44:52 +00:00
|
|
|
/* TODO: we could be saving snippets of texture combine code along
|
|
|
|
* with each layer and then when a layer changes we would just free
|
|
|
|
* the snippet. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_free_priv (CoglPipeline *pipeline)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
CoglPipelineFragendARBfpPrivate *priv = get_arbfp_priv (pipeline);
|
2010-09-14 17:50:50 +00:00
|
|
|
if (priv)
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-09-14 17:50:50 +00:00
|
|
|
if (priv->arbfp_program_state)
|
|
|
|
arbfp_program_state_unref (priv->arbfp_program_state);
|
2010-11-29 16:56:41 +00:00
|
|
|
g_slice_free (CoglPipelineFragendARBfpPrivate, priv);
|
2010-10-27 17:54:57 +00:00
|
|
|
set_arbfp_priv (pipeline, NULL);
|
2010-06-15 15:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
const CoglPipelineFragend _cogl_pipeline_arbfp_fragend =
|
2010-06-15 15:44:52 +00:00
|
|
|
{
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_start,
|
|
|
|
_cogl_pipeline_fragend_arbfp_add_layer,
|
|
|
|
_cogl_pipeline_fragend_arbfp_passthrough,
|
|
|
|
_cogl_pipeline_fragend_arbfp_end,
|
|
|
|
_cogl_pipeline_fragend_arbfp_pipeline_pre_change_notify,
|
2010-09-14 17:50:50 +00:00
|
|
|
NULL,
|
2010-11-29 16:56:41 +00:00
|
|
|
_cogl_pipeline_fragend_arbfp_layer_pre_change_notify,
|
|
|
|
_cogl_pipeline_fragend_arbfp_free_priv
|
2010-06-15 15:44:52 +00:00
|
|
|
};
|
|
|
|
|
2010-11-29 16:56:41 +00:00
|
|
|
#endif /* COGL_PIPELINE_FRAGEND_ARBFP */
|
2010-07-02 00:07:36 +00:00
|
|
|
|