diff options
author | Neil Roberts <neil@linux.intel.com> | 2010-12-02 20:48:45 +0000 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2010-12-13 17:28:28 +0000 |
commit | fa13f6c1078dd3f67b18048afbe4ef271b4804e4 (patch) | |
tree | b18af83b938bb7719b779b55acef8d40f7bca1d3 /cogl/cogl-pipeline-opengl.c | |
parent | e98bd86e0a2f03d87e7987d4f520f804738a201e (diff) | |
download | cogl-fa13f6c1078dd3f67b18048afbe4ef271b4804e4.tar.gz |
cogl: Add a vertend to generate GLSL
The GLSL vertend is mostly only useful for GLES2. The fixed function
vertend is kept at higher priority than the GLSL vertend so it is
unlikely to be used in any other circumstances.
Diffstat (limited to 'cogl/cogl-pipeline-opengl.c')
-rw-r--r-- | cogl/cogl-pipeline-opengl.c | 130 |
1 files changed, 95 insertions, 35 deletions
diff --git a/cogl/cogl-pipeline-opengl.c b/cogl/cogl-pipeline-opengl.c index f417ba19..83570c4e 100644 --- a/cogl/cogl-pipeline-opengl.c +++ b/cogl/cogl-pipeline-opengl.c @@ -251,21 +251,45 @@ _cogl_pipeline_texture_storage_change_notify (CoglHandle texture) * we continue to check the rest */ } } +static void +set_glsl_program (GLuint gl_program) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (ctx->current_gl_program != gl_program) + { + GLenum gl_error; + + while ((gl_error = glGetError ()) != GL_NO_ERROR) + ; + glUseProgram (gl_program); + if (glGetError () == GL_NO_ERROR) + ctx->current_gl_program = gl_program; + else + { + GE( glUseProgram (0) ); + ctx->current_gl_program = 0; + } + } +} void -_cogl_use_program (GLuint gl_program, CoglPipelineProgramType type) +_cogl_use_fragment_program (GLuint gl_program, CoglPipelineProgramType type) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); /* If we're changing program type... */ - if (type != ctx->current_use_program_type) + if (type != ctx->current_fragment_program_type) { /* ... disable the old type */ - switch (ctx->current_use_program_type) + switch (ctx->current_fragment_program_type) { case COGL_PIPELINE_PROGRAM_TYPE_GLSL: - GE( glUseProgram (0) ); - ctx->current_gl_program = 0; + /* If the program contains a vertex shader then we shouldn't + disable it */ + if (ctx->current_vertex_program_type != + COGL_PIPELINE_PROGRAM_TYPE_GLSL) + set_glsl_program (0); break; case COGL_PIPELINE_PROGRAM_TYPE_ARBFP: @@ -298,22 +322,7 @@ _cogl_use_program (GLuint gl_program, CoglPipelineProgramType type) if (type == COGL_PIPELINE_PROGRAM_TYPE_GLSL) { #ifdef COGL_PIPELINE_FRAGEND_GLSL - - if (ctx->current_gl_program != gl_program) - { - GLenum gl_error; - - while ((gl_error = glGetError ()) != GL_NO_ERROR) - ; - glUseProgram (gl_program); - if (glGetError () == GL_NO_ERROR) - ctx->current_gl_program = gl_program; - else - { - GE( glUseProgram (0) ); - ctx->current_gl_program = 0; - } - } + set_glsl_program (gl_program); #else @@ -323,10 +332,73 @@ _cogl_use_program (GLuint gl_program, CoglPipelineProgramType type) } #ifndef COGL_PIPELINE_FRAGEND_ARBFP else if (type == COGL_PIPELINE_PROGRAM_TYPE_ARBFP) - g_warning ("Unexpected use of ARBFP fragend!"); + g_warning ("Unexpected use of ARBFP fragend!"); #endif /* COGL_PIPELINE_FRAGEND_ARBFP */ - ctx->current_use_program_type = type; + ctx->current_fragment_program_type = type; +} + +void +_cogl_use_vertex_program (GLuint gl_program, CoglPipelineProgramType type) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + /* If we're changing program type... */ + if (type != ctx->current_vertex_program_type) + { + /* ... disable the old type */ + switch (ctx->current_vertex_program_type) + { + case COGL_PIPELINE_PROGRAM_TYPE_GLSL: + /* If the program contains a fragment shader then we shouldn't + disable it */ + if (ctx->current_fragment_program_type != + COGL_PIPELINE_PROGRAM_TYPE_GLSL) + set_glsl_program (0); + break; + + case COGL_PIPELINE_PROGRAM_TYPE_ARBFP: + /* It doesn't make sense to enable ARBfp for the vertex program */ + g_assert_not_reached (); + break; + + case COGL_PIPELINE_PROGRAM_TYPE_FIXED: + /* don't need to to anything */ + break; + } + + /* ... and enable the new type */ + switch (type) + { + case COGL_PIPELINE_PROGRAM_TYPE_ARBFP: + /* It doesn't make sense to enable ARBfp for the vertex program */ + g_assert_not_reached (); + break; + + case COGL_PIPELINE_PROGRAM_TYPE_GLSL: + case COGL_PIPELINE_PROGRAM_TYPE_FIXED: + /* don't need to to anything */ + break; + } + } + + if (type == COGL_PIPELINE_PROGRAM_TYPE_GLSL) + { +#ifdef COGL_PIPELINE_VERTEND_GLSL + set_glsl_program (gl_program); + +#else + + g_warning ("Unexpected use of GLSL vertend!"); + +#endif /* COGL_PIPELINE_VERTEND_GLSL */ + } +#ifndef COGL_PIPELINE_VERTEND_ARBFP + else if (type == COGL_PIPELINE_PROGRAM_TYPE_ARBFP) + g_warning ("Unexpected use of ARBFP vertend!"); +#endif /* COGL_PIPELINE_VERTEND_ARBFP */ + + ctx->current_vertex_program_type = type; } #if defined (COGL_PIPELINE_FRAGEND_GLSL) || \ @@ -519,18 +591,6 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state ( } } - 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; - } - } - if (pipeline->real_blend_enable != ctx->gl_blend_enable_cache) { if (pipeline->real_blend_enable) |