~oem-solutions-group/unity-2d/clutter-1.0

« back to all changes in this revision

Viewing changes to clutter/cogl/common/cogl-material-private.h

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Cogl
3
 
 *
4
 
 * An object oriented GL/GLES Abstraction/Utility Layer
5
 
 *
6
 
 * Copyright (C) 2008,2009 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, write to the
20
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
 
 * Boston, MA 02111-1307, USA.
22
 
 *
23
 
 * Authors:
24
 
 *   Robert Bragg <robert@linux.intel.com>
25
 
 */
26
 
 
27
 
#ifndef __COGL_MATERIAL_PRIVATE_H
28
 
#define __COGL_MATERIAL_PRIVATE_H
29
 
 
30
 
#include "cogl-material.h"
31
 
#include "cogl-matrix.h"
32
 
#include "cogl-handle.h"
33
 
 
34
 
#include <glib.h>
35
 
 
36
 
typedef struct _CoglMaterial          CoglMaterial;
37
 
typedef struct _CoglMaterialLayer     CoglMaterialLayer;
38
 
 
39
 
typedef enum _CoglMaterialEqualFlags
40
 
{
41
 
  /* Return FALSE if any component of either material isn't set to its
42
 
   * default value. (Note: if the materials have corresponding flush
43
 
   * options indicating that e.g. the material color won't be flushed then
44
 
   * this will not assert a default color value.) */
45
 
  COGL_MATERIAL_EQUAL_FLAGS_ASSERT_ALL_DEFAULTS   = 1L<<0,
46
 
 
47
 
} CoglMaterialEqualFlags;
48
 
 
49
 
/* XXX: I don't think gtk-doc supports having private enums so these aren't
50
 
 * bundled in with CoglMaterialLayerFlags */
51
 
typedef enum _CoglMaterialLayerPrivFlags
52
 
{
53
 
  /* Ref: CoglMaterialLayerFlags
54
 
  COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX  = 1L<<0
55
 
  */
56
 
  COGL_MATERIAL_LAYER_FLAG_DIRTY            = 1L<<1,
57
 
  COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE  = 1L<<2
58
 
} CoglMaterialLayerPrivFlags;
59
 
 
60
 
/* For tracking the state of a layer that's been flushed to OpenGL */
61
 
typedef struct _CoglLayerInfo
62
 
{
63
 
  CoglHandle  handle;
64
 
  gulong      flags;
65
 
  GLenum      gl_target;
66
 
  GLuint      gl_texture;
67
 
  gboolean    fallback;
68
 
  gboolean    disabled;
69
 
  gboolean    layer0_overridden;
70
 
} CoglLayerInfo;
71
 
 
72
 
struct _CoglMaterialLayer
73
 
{
74
 
  CoglHandleObject _parent;
75
 
  guint        index;   /*!< lowest index is blended first then others
76
 
                             on top */
77
 
  gulong       flags;
78
 
  CoglHandle   texture; /*!< The texture for this layer, or COGL_INVALID_HANDLE
79
 
                             for an empty layer */
80
 
 
81
 
  CoglMaterialFilter mag_filter;
82
 
  CoglMaterialFilter min_filter;
83
 
 
84
 
  /* Determines how the color of individual texture fragments
85
 
   * are calculated. */
86
 
  GLint texture_combine_rgb_func;
87
 
  GLint texture_combine_rgb_src[3];
88
 
  GLint texture_combine_rgb_op[3];
89
 
 
90
 
  GLint texture_combine_alpha_func;
91
 
  GLint texture_combine_alpha_src[3];
92
 
  GLint texture_combine_alpha_op[3];
93
 
 
94
 
  GLfloat texture_combine_constant[4];
95
 
 
96
 
  /* TODO: Support purely GLSL based material layers */
97
 
 
98
 
  CoglMatrix matrix;
99
 
};
100
 
 
101
 
typedef enum _CoglMaterialFlags
102
 
{
103
 
  COGL_MATERIAL_FLAG_SHOWN_SAMPLER_WARNING  = 1L<<0,
104
 
 
105
 
  COGL_MATERIAL_FLAG_DEFAULT_COLOR          = 1L<<1,
106
 
  COGL_MATERIAL_FLAG_DEFAULT_GL_MATERIAL    = 1L<<2,
107
 
  COGL_MATERIAL_FLAG_DEFAULT_ALPHA_FUNC     = 1L<<3,
108
 
  COGL_MATERIAL_FLAG_ENABLE_BLEND           = 1L<<4,
109
 
  COGL_MATERIAL_FLAG_DEFAULT_BLEND          = 1L<<5
110
 
} CoglMaterialFlags;
111
 
 
112
 
struct _CoglMaterial
113
 
{
114
 
  CoglHandleObject _parent;
115
 
  gulong           journal_ref_count;
116
 
 
117
 
  gulong    flags;
118
 
 
119
 
  /* If no lighting is enabled; this is the basic material color */
120
 
  GLubyte   unlit[4];
121
 
 
122
 
  /* Standard OpenGL lighting model attributes */
123
 
  GLfloat   ambient[4];
124
 
  GLfloat   diffuse[4];
125
 
  GLfloat   specular[4];
126
 
  GLfloat   emission[4];
127
 
  GLfloat   shininess;
128
 
 
129
 
  /* Determines what fragments are discarded based on their alpha */
130
 
  CoglMaterialAlphaFunc alpha_func;
131
 
  GLfloat               alpha_func_reference;
132
 
 
133
 
  /* Determines how this material is blended with other primitives */
134
 
#ifndef HAVE_COGL_GLES
135
 
  GLenum blend_equation_rgb;
136
 
  GLenum blend_equation_alpha;
137
 
  GLint blend_src_factor_alpha;
138
 
  GLint blend_dst_factor_alpha;
139
 
  GLfloat blend_constant[4];
140
 
#endif
141
 
  GLint blend_src_factor_rgb;
142
 
  GLint blend_dst_factor_rgb;
143
 
 
144
 
  GList    *layers;
145
 
  guint     n_layers;
146
 
};
147
 
 
148
 
/*
149
 
 * SECTION:cogl-material-internals
150
 
 * @short_description: Functions for creating custom primitives that make use
151
 
 *                     of Cogl materials for filling.
152
 
 *
153
 
 * Normally you shouldn't need to use this API directly, but if you need to
154
 
 * developing a custom/specialised primitive - probably using raw OpenGL - then
155
 
 * this API aims to expose enough of the material internals to support being
156
 
 * able to fill your geometry according to a given Cogl material.
157
 
 */
158
 
 
159
 
 
160
 
/*
161
 
 * cogl_material_get_cogl_enable_flags:
162
 
 * @material: A CoglMaterial object
163
 
 *
164
 
 * This determines what flags need to be passed to cogl_enable before this
165
 
 * material can be used. Normally you shouldn't need to use this function
166
 
 * directly since Cogl will do this internally, but if you are developing
167
 
 * custom primitives directly with OpenGL you may want to use this.
168
 
 *
169
 
 * Note: This API is hopfully just a stop-gap solution. Ideally cogl_enable
170
 
 * will be replaced.
171
 
 */
172
 
/* TODO: find a nicer solution! */
173
 
gulong _cogl_material_get_cogl_enable_flags (CoglHandle handle);
174
 
 
175
 
/*
176
 
 * CoglMaterialLayerFlags:
177
 
 * @COGL_MATERIAL_LAYER_FLAG_USER_MATRIX: Means the user has supplied a
178
 
 *                                        custom texture matrix.
179
 
 */
180
 
typedef enum _CoglMaterialLayerFlags
181
 
{
182
 
  COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX      = 1L<<0
183
 
} CoglMaterialLayerFlags;
184
 
/* XXX: NB: if you add flags here you will need to update
185
 
 * CoglMaterialLayerPrivFlags!!! */
186
 
 
187
 
/*
188
 
 * cogl_material_layer_get_flags:
189
 
 * @layer_handle: A CoglMaterialLayer layer handle
190
 
 *
191
 
 * This lets you get a number of flag attributes about the layer.  Normally
192
 
 * you shouldn't need to use this function directly since Cogl will do this
193
 
 * internally, but if you are developing custom primitives directly with
194
 
 * OpenGL you may need this.
195
 
 */
196
 
gulong _cogl_material_layer_get_flags (CoglHandle layer_handle);
197
 
 
198
 
/*
199
 
 * CoglMaterialFlushFlag:
200
 
 * @COGL_MATERIAL_FLUSH_FALLBACK_MASK: The fallback_layers member is set to
201
 
 *      a guint32 mask of the layers that can't be supported with the user
202
 
 *      supplied texture and need to be replaced with fallback textures. (1 =
203
 
 *      fallback, and the least significant bit = layer 0)
204
 
 * @COGL_MATERIAL_FLUSH_DISABLE_MASK: The disable_layers member is set to
205
 
 *      a guint32 mask of the layers that you want to completly disable
206
 
 *      texturing for (1 = fallback, and the least significant bit = layer 0)
207
 
 * @COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE: The layer0_override_texture member is
208
 
 *      set to a GLuint OpenGL texture name to override the texture used for
209
 
 *      layer 0 of the material. This is intended for dealing with sliced
210
 
 *      textures where you will need to point to each of the texture slices in
211
 
 *      turn when drawing your geometry.  Passing a value of 0 is the same as
212
 
 *      not passing the option at all.
213
 
 * @COGL_MATERIAL_FLUSH_SKIP_GL_COLOR: When flushing the GL state for the
214
 
 *      material don't call glColor.
215
 
 */
216
 
typedef enum _CoglMaterialFlushFlag
217
 
{
218
 
  COGL_MATERIAL_FLUSH_FALLBACK_MASK     = 1L<<0,
219
 
  COGL_MATERIAL_FLUSH_DISABLE_MASK      = 1L<<1,
220
 
  COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE   = 1L<<2,
221
 
  COGL_MATERIAL_FLUSH_SKIP_GL_COLOR     = 1L<<3
222
 
} CoglMaterialFlushFlag;
223
 
 
224
 
/*
225
 
 * CoglMaterialFlushOptions:
226
 
 *
227
 
 */
228
 
typedef struct _CoglMaterialFlushOptions
229
 
{
230
 
  CoglMaterialFlushFlag flags;
231
 
 
232
 
  guint32               fallback_layers;
233
 
  guint32               disable_layers;
234
 
  GLuint                layer0_override_texture;
235
 
} CoglMaterialFlushOptions;
236
 
 
237
 
 
238
 
 
239
 
void _cogl_material_get_colorubv (CoglHandle  handle,
240
 
                                  guint8     *color);
241
 
 
242
 
void _cogl_material_flush_gl_state (CoglHandle material,
243
 
                                    CoglMaterialFlushOptions *options);
244
 
 
245
 
gboolean _cogl_material_equal (CoglHandle material0_handle,
246
 
                               CoglMaterialFlushOptions *material0_flush_options,
247
 
                               CoglHandle material1_handle,
248
 
                               CoglMaterialFlushOptions *material1_flush_options);
249
 
 
250
 
CoglHandle _cogl_material_journal_ref (CoglHandle material_handle);
251
 
void _cogl_material_journal_unref (CoglHandle material_handle);
252
 
 
253
 
 
254
 
#endif /* __COGL_MATERIAL_PRIVATE_H */
255