"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-pipeline-vertend-fixed.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2008,2009,2010 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  *
23  *
24  * Authors:
25  *   Neil Roberts <neil@linux.intel.com>
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "cogl-context-private.h"
33 #include "cogl-pipeline-private.h"
34 #include "cogl-pipeline-state-private.h"
35 #include "cogl-pipeline-opengl-private.h"
36
37 #ifdef COGL_PIPELINE_VERTEND_FIXED
38
39 #include "cogl-internal.h"
40 #include "cogl-context-private.h"
41 #include "cogl-handle.h"
42 #include "cogl-program-private.h"
43
44 const CoglPipelineVertend _cogl_pipeline_fixed_vertend;
45
46 static gboolean
47 _cogl_pipeline_vertend_fixed_start (CoglPipeline *pipeline,
48                                     int n_layers,
49                                     unsigned long pipelines_difference,
50                                     int n_tex_coord_attribs)
51 {
52   CoglProgram *user_program;
53
54   _COGL_GET_CONTEXT (ctx, FALSE);
55
56   if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_FIXED)))
57     return FALSE;
58
59   if (ctx->driver == COGL_DRIVER_GLES2)
60     return FALSE;
61
62   /* Vertex snippets are only supported in the GLSL fragend */
63   if (_cogl_pipeline_has_vertex_snippets (pipeline))
64     return FALSE;
65
66   /* If there is a user program with a vertex shader then the
67      appropriate backend for that language should handle it. We can
68      still use the fixed vertex backend if the program only contains
69      a fragment shader */
70   user_program = cogl_pipeline_get_user_program (pipeline);
71   if (user_program != COGL_INVALID_HANDLE &&
72       _cogl_program_has_vertex_shader (user_program))
73     return FALSE;
74
75   _cogl_use_vertex_program (0, COGL_PIPELINE_PROGRAM_TYPE_FIXED);
76
77   return TRUE;
78 }
79
80 static gboolean
81 _cogl_pipeline_vertend_fixed_add_layer (CoglPipeline *pipeline,
82                                         CoglPipelineLayer *layer,
83                                         unsigned long layers_difference)
84 {
85   int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
86   CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index);
87
88   _COGL_GET_CONTEXT (ctx, FALSE);
89
90   if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX)
91     {
92       CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_USER_MATRIX;
93       CoglPipelineLayer *authority =
94         _cogl_pipeline_layer_get_authority (layer, state);
95
96       _cogl_matrix_stack_set (unit->matrix_stack,
97                               &authority->big_state->matrix);
98
99       _cogl_set_active_texture_unit (unit_index);
100
101       _cogl_matrix_stack_flush_to_gl_builtins (ctx, unit->matrix_stack,
102                                                COGL_MATRIX_TEXTURE,
103                                                FALSE /* enable flip */);
104     }
105
106   return TRUE;
107 }
108
109 static gboolean
110 _cogl_pipeline_vertend_fixed_end (CoglPipeline *pipeline,
111                                   unsigned long pipelines_difference)
112 {
113   _COGL_GET_CONTEXT (ctx, FALSE);
114
115   if (pipelines_difference & COGL_PIPELINE_STATE_POINT_SIZE)
116     {
117       CoglPipeline *authority =
118         _cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_POINT_SIZE);
119
120       GE( ctx, glPointSize (authority->big_state->point_size) );
121     }
122
123   return TRUE;
124 }
125
126 const CoglPipelineVertend _cogl_pipeline_fixed_vertend =
127 {
128   _cogl_pipeline_vertend_fixed_start,
129   _cogl_pipeline_vertend_fixed_add_layer,
130   _cogl_pipeline_vertend_fixed_end,
131   NULL, /* pipeline_change_notify */
132   NULL /* layer_change_notify */
133 };
134
135 #endif /* COGL_PIPELINE_VERTEND_FIXED */
136