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

« back to all changes in this revision

Viewing changes to clutter/cogl/cogl/cogl-material.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) 2007,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, see <http://www.gnu.org/licenses/>.
 
20
 *
 
21
 *
 
22
 */
 
23
 
 
24
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
 
25
#error "Only <cogl/cogl.h> can be included directly."
 
26
#endif
 
27
 
 
28
#ifndef __COGL_MATERIAL_H__
 
29
#define __COGL_MATERIAL_H__
 
30
 
 
31
G_BEGIN_DECLS
 
32
 
 
33
#include <cogl/cogl-types.h>
 
34
#include <cogl/cogl-matrix.h>
 
35
 
 
36
/**
 
37
 * SECTION:cogl-material
 
38
 * @short_description: Fuctions for creating and manipulating materials
 
39
 *
 
40
 * COGL allows creating and manipulating materials used to fill in
 
41
 * geometry. Materials may simply be lighting attributes (such as an
 
42
 * ambient and diffuse colour) or might represent one or more textures
 
43
 * blended together.
 
44
 */
 
45
 
 
46
/**
 
47
 * CoglMaterialFilter:
 
48
 * @COGL_MATERIAL_FILTER_NEAREST: Measuring in manhatten distance from the,
 
49
 *   current pixel center, use the nearest texture texel
 
50
 * @COGL_MATERIAL_FILTER_LINEAR: Use the weighted average of the 4 texels
 
51
 *   nearest the current pixel center
 
52
 * @COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST: Select the mimap level whose
 
53
 *   texel size most closely matches the current pixel, and use the
 
54
 *   %COGL_MATERIAL_FILTER_NEAREST criterion
 
55
 * @COGL_MATERIAL_FILTER_LINEAR_MIPMAP_NEAREST: Select the mimap level whose
 
56
 *   texel size most closely matches the current pixel, and use the
 
57
 *   %COGL_MATERIAL_FILTER_LINEAR criterion
 
58
 * @COGL_MATERIAL_FILTER_NEAREST_MIPMAP_LINEAR: Select the two mimap levels
 
59
 *   whose texel size most closely matches the current pixel, use
 
60
 *   the %COGL_MATERIAL_FILTER_NEAREST criterion on each one and take
 
61
 *   their weighted average
 
62
 * @COGL_MATERIAL_FILTER_LINEAR_MIPMAP_LINEAR: Select the two mimap levels
 
63
 *   whose texel size most closely matches the current pixel, use
 
64
 *   the %COGL_MATERIAL_FILTER_LINEAR criterion on each one and take
 
65
 *   their weighted average
 
66
 *
 
67
 * Texture filtering is used whenever the current pixel maps either to more
 
68
 * than one texture element (texel) or less than one. These filter enums
 
69
 * correspond to different strategies used to come up with a pixel color, by
 
70
 * possibly referring to multiple neighbouring texels and taking a weighted
 
71
 * average or simply using the nearest texel.
 
72
 */
 
73
typedef enum {
 
74
  COGL_MATERIAL_FILTER_NEAREST = GL_NEAREST,
 
75
  COGL_MATERIAL_FILTER_LINEAR = GL_LINEAR,
 
76
  COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
 
77
  COGL_MATERIAL_FILTER_LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
 
78
  COGL_MATERIAL_FILTER_NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
 
79
  COGL_MATERIAL_FILTER_LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
 
80
} CoglMaterialFilter;
 
81
 
 
82
/**
 
83
 * cogl_material_new:
 
84
 *
 
85
 * Allocates and initializes a blank white material
 
86
 *
 
87
 * Return value: a handle to the new material
 
88
 */
 
89
CoglHandle
 
90
cogl_material_new (void);
 
91
 
 
92
/**
 
93
 * cogl_material_copy:
 
94
 * @source: the handle for the material to copy
 
95
 *
 
96
 * Creates a new material handle with the configuration copied from the
 
97
 * source material.
 
98
 *
 
99
 * We would strongly advise developers to always aim to use
 
100
 * cogl_material_copy() instead of cogl_material_new() whenever there will
 
101
 * be any similarity between two materials. Copying a material helps Cogl
 
102
 * keep track of a materials ancestry which we may use to help minimize GPU
 
103
 * state changes.
 
104
 *
 
105
 * Returns: a handle to the new material
 
106
 *
 
107
 * Since: 1.2
 
108
 */
 
109
CoglHandle
 
110
cogl_material_copy (CoglHandle source);
 
111
 
 
112
#ifndef COGL_DISABLE_DEPRECATED
 
113
 
 
114
/**
 
115
 * cogl_material_ref:
 
116
 * @handle: a @CoglHandle.
 
117
 *
 
118
 * Increment the reference count for a cogl material.
 
119
 *
 
120
 * Return value: the @handle.
 
121
 *
 
122
 * Since: 1.0
 
123
 *
 
124
 * Deprecated: 1.2: Use cogl_handle_ref() instead
 
125
 */
 
126
CoglHandle
 
127
cogl_material_ref (CoglHandle handle) G_GNUC_DEPRECATED;
 
128
 
 
129
/**
 
130
 * cogl_material_unref:
 
131
 * @handle: a @CoglHandle.
 
132
 *
 
133
 * Decrement the reference count for a cogl material.
 
134
 *
 
135
 * Since: 1.0
 
136
 *
 
137
 * Deprecated: 1.2: Use cogl_handle_unref() instead
 
138
 */
 
139
void
 
140
cogl_material_unref (CoglHandle handle) G_GNUC_DEPRECATED;
 
141
 
 
142
#endif /* COGL_DISABLE_DEPRECATED */
 
143
 
 
144
/**
 
145
 * cogl_is_material:
 
146
 * @handle: A CoglHandle
 
147
 *
 
148
 * Gets whether the given handle references an existing material object.
 
149
 *
 
150
 * Return value: %TRUE if the handle references a #CoglMaterial,
 
151
 *   %FALSE otherwise
 
152
 */
 
153
gboolean
 
154
cogl_is_material (CoglHandle handle);
 
155
 
 
156
/**
 
157
 * cogl_material_set_color:
 
158
 * @material: A CoglMaterial object
 
159
 * @color: The components of the color
 
160
 *
 
161
 * Sets the basic color of the material, used when no lighting is enabled.
 
162
 *
 
163
 * Note that if you don't add any layers to the material then the color
 
164
 * will be blended unmodified with the destination; the default blend
 
165
 * expects premultiplied colors: for example, use (0.5, 0.0, 0.0, 0.5) for
 
166
 * semi-transparent red. See cogl_color_premultiply().
 
167
 *
 
168
 * The default value is (1.0, 1.0, 1.0, 1.0)
 
169
 *
 
170
 * Since: 1.0
 
171
 */
 
172
void
 
173
cogl_material_set_color (CoglHandle       material,
 
174
                         const CoglColor *color);
 
175
 
 
176
/**
 
177
 * cogl_material_set_color4ub:
 
178
 * @material: A CoglMaterial object
 
179
 * @red: The red component
 
180
 * @green: The green component
 
181
 * @blue: The blue component
 
182
 * @alpha: The alpha component
 
183
 *
 
184
 * Sets the basic color of the material, used when no lighting is enabled.
 
185
 *
 
186
 * The default value is (0xff, 0xff, 0xff, 0xff)
 
187
 *
 
188
 * Since: 1.0
 
189
 */
 
190
void
 
191
cogl_material_set_color4ub (CoglHandle material,
 
192
                            guint8     red,
 
193
                            guint8     green,
 
194
                            guint8     blue,
 
195
                            guint8     alpha);
 
196
 
 
197
/**
 
198
 * cogl_material_set_color4f:
 
199
 * @material: A CoglMaterial object
 
200
 * @red: The red component
 
201
 * @green: The green component
 
202
 * @blue: The blue component
 
203
 * @alpha: The alpha component
 
204
 *
 
205
 * Sets the basic color of the material, used when no lighting is enabled.
 
206
 *
 
207
 * The default value is (1.0, 1.0, 1.0, 1.0)
 
208
 *
 
209
 * Since: 1.0
 
210
 */
 
211
void
 
212
cogl_material_set_color4f (CoglHandle material,
 
213
                           float      red,
 
214
                           float      green,
 
215
                           float      blue,
 
216
                           float      alpha);
 
217
 
 
218
/**
 
219
 * cogl_material_get_color:
 
220
 * @material: A CoglMaterial object
 
221
 * @color: (out): The location to store the color
 
222
 *
 
223
 * Retrieves the current material color.
 
224
 *
 
225
 * Since: 1.0
 
226
 */
 
227
void
 
228
cogl_material_get_color (CoglHandle  material,
 
229
                         CoglColor  *color);
 
230
 
 
231
/**
 
232
 * cogl_material_set_ambient:
 
233
 * @material: A CoglMaterial object
 
234
 * @ambient: The components of the desired ambient color
 
235
 *
 
236
 * Sets the material's ambient color, in the standard OpenGL lighting
 
237
 * model. The ambient color affects the overall color of the object.
 
238
 *
 
239
 * Since the diffuse color will be intense when the light hits the surface
 
240
 * directly, the ambient will be most apparent where the light hits at a
 
241
 * slant.
 
242
 *
 
243
 * The default value is (0.2, 0.2, 0.2, 1.0)
 
244
 *
 
245
 * Since: 1.0
 
246
 */
 
247
void
 
248
cogl_material_set_ambient (CoglHandle       material,
 
249
                           const CoglColor *ambient);
 
250
 
 
251
/**
 
252
 * cogl_material_get_ambient:
 
253
 * @material: A CoglMaterial object
 
254
 * @ambient: The location to store the ambient color
 
255
 *
 
256
 * Retrieves the current ambient color for @material
 
257
 *
 
258
 * Since: 1.0
 
259
 */
 
260
void
 
261
cogl_material_get_ambient (CoglHandle  material,
 
262
                           CoglColor  *ambient);
 
263
 
 
264
/**
 
265
 * cogl_material_set_diffuse:
 
266
 * @material: A CoglMaterial object
 
267
 * @diffuse: The components of the desired diffuse color
 
268
 *
 
269
 * Sets the material's diffuse color, in the standard OpenGL lighting
 
270
 * model. The diffuse color is most intense where the light hits the
 
271
 * surface directly - perpendicular to the surface.
 
272
 *
 
273
 * The default value is (0.8, 0.8, 0.8, 1.0)
 
274
 *
 
275
 * Since: 1.0
 
276
 */
 
277
void
 
278
cogl_material_set_diffuse (CoglHandle       material,
 
279
                           const CoglColor *diffuse);
 
280
 
 
281
/**
 
282
 * cogl_material_get_diffuse:
 
283
 * @material: A CoglMaterial object
 
284
 * @diffuse: The location to store the diffuse color
 
285
 *
 
286
 * Retrieves the current diffuse color for @material
 
287
 *
 
288
 * Since: 1.0
 
289
 */
 
290
void
 
291
cogl_material_get_diffuse (CoglHandle  material,
 
292
                           CoglColor  *diffuse);
 
293
 
 
294
/**
 
295
 * cogl_material_set_ambient_and_diffuse:
 
296
 * @material: A CoglMaterial object
 
297
 * @color: The components of the desired ambient and diffuse colors
 
298
 *
 
299
 * Conveniently sets the diffuse and ambient color of @material at the same
 
300
 * time. See cogl_material_set_ambient() and cogl_material_set_diffuse().
 
301
 *
 
302
 * The default ambient color is (0.2, 0.2, 0.2, 1.0)
 
303
 *
 
304
 * The default diffuse color is (0.8, 0.8, 0.8, 1.0)
 
305
 *
 
306
 * Since: 1.0
 
307
 */
 
308
void
 
309
cogl_material_set_ambient_and_diffuse (CoglHandle       material,
 
310
                                       const CoglColor *color);
 
311
 
 
312
/**
 
313
 * cogl_material_set_specular:
 
314
 * @material: A CoglMaterial object
 
315
 * @specular: The components of the desired specular color
 
316
 *
 
317
 * Sets the material's specular color, in the standard OpenGL lighting
 
318
 * model. The intensity of the specular color depends on the viewport
 
319
 * position, and is brightest along the lines of reflection.
 
320
 *
 
321
 * The default value is (0.0, 0.0, 0.0, 1.0)
 
322
 *
 
323
 * Since: 1.0
 
324
 */
 
325
void
 
326
cogl_material_set_specular (CoglHandle       material,
 
327
                            const CoglColor *specular);
 
328
 
 
329
/**
 
330
 * cogl_material_get_specular:
 
331
 * @material: A CoglMaterial object
 
332
 * @specular: The location to store the specular color
 
333
 *
 
334
 * Retrieves the materials current specular color.
 
335
 *
 
336
 * Since: 1.0
 
337
 */
 
338
void
 
339
cogl_material_get_specular (CoglHandle  material,
 
340
                            CoglColor  *specular);
 
341
 
 
342
/**
 
343
 * cogl_material_set_shininess:
 
344
 * @material: A CoglMaterial object
 
345
 * @shininess: The desired shininess; range: [0.0, 1.0]
 
346
 *
 
347
 * Sets the materials shininess, in the standard OpenGL lighting model,
 
348
 * which determines how specular highlights are calculated. A higher
 
349
 * @shininess will produce smaller brigher highlights.
 
350
 *
 
351
 * The default value is 0.0
 
352
 *
 
353
 * Since: 1.0
 
354
 */
 
355
void
 
356
cogl_material_set_shininess (CoglHandle material,
 
357
                             float      shininess);
 
358
 
 
359
/**
 
360
 * cogl_material_get_shininess:
 
361
 * @material: A CoglMaterial object
 
362
 *
 
363
 * Retrieves the materials current emission color.
 
364
 *
 
365
 * Return value: The materials current shininess value
 
366
 *
 
367
 * Since: 1.0
 
368
 */
 
369
float
 
370
cogl_material_get_shininess (CoglHandle material);
 
371
 
 
372
/**
 
373
 * cogl_material_set_emission:
 
374
 * @material: A CoglMaterial object
 
375
 * @emission: The components of the desired emissive color
 
376
 *
 
377
 * Sets the material's emissive color, in the standard OpenGL lighting
 
378
 * model. It will look like the surface is a light source emitting this
 
379
 * color.
 
380
 *
 
381
 * The default value is (0.0, 0.0, 0.0, 1.0)
 
382
 *
 
383
 * Since: 1.0
 
384
 */
 
385
void
 
386
cogl_material_set_emission (CoglHandle       material,
 
387
                            const CoglColor *emission);
 
388
 
 
389
/**
 
390
 * cogl_material_get_emission:
 
391
 * @material: A CoglMaterial object
 
392
 * @emission: The location to store the emission color
 
393
 *
 
394
 * Retrieves the materials current emission color.
 
395
 *
 
396
 * Since: 1.0
 
397
 */
 
398
void
 
399
cogl_material_get_emission (CoglHandle material,
 
400
                            CoglColor *emission);
 
401
 
 
402
/**
 
403
 * CoglMaterialAlphaFunc:
 
404
 * @COGL_MATERIAL_ALPHA_FUNC_NEVER: Never let the fragment through.
 
405
 * @COGL_MATERIAL_ALPHA_FUNC_LESS: Let the fragment through if the incoming
 
406
 *   alpha value is less than the reference alpha value
 
407
 * @COGL_MATERIAL_ALPHA_FUNC_EQUAL: Let the fragment through if the incoming
 
408
 *   alpha value equals the reference alpha value
 
409
 * @COGL_MATERIAL_ALPHA_FUNC_LEQUAL: Let the fragment through if the incoming
 
410
 *   alpha value is less than or equal to the reference alpha value
 
411
 * @COGL_MATERIAL_ALPHA_FUNC_GREATER: Let the fragment through if the incoming
 
412
 *   alpha value is greater than the reference alpha value
 
413
 * @COGL_MATERIAL_ALPHA_FUNC_NOTEQUAL: Let the fragment through if the incoming
 
414
 *   alpha value does not equal the reference alpha value
 
415
 * @COGL_MATERIAL_ALPHA_FUNC_GEQUAL: Let the fragment through if the incoming
 
416
 *   alpha value is greater than or equal to the reference alpha value.
 
417
 * @COGL_MATERIAL_ALPHA_FUNC_ALWAYS: Always let the fragment through.
 
418
 *
 
419
 * Alpha testing happens before blending primitives with the framebuffer and
 
420
 * gives an opportunity to discard fragments based on a comparison with the
 
421
 * incoming alpha value and a reference alpha value. The #CoglMaterialAlphaFunc
 
422
 * determines how the comparison is done.
 
423
 */
 
424
typedef enum {
 
425
  COGL_MATERIAL_ALPHA_FUNC_NEVER    = GL_NEVER,
 
426
  COGL_MATERIAL_ALPHA_FUNC_LESS     = GL_LESS,
 
427
  COGL_MATERIAL_ALPHA_FUNC_EQUAL    = GL_EQUAL,
 
428
  COGL_MATERIAL_ALPHA_FUNC_LEQUAL   = GL_LEQUAL,
 
429
  COGL_MATERIAL_ALPHA_FUNC_GREATER  = GL_GREATER,
 
430
  COGL_MATERIAL_ALPHA_FUNC_NOTEQUAL = GL_NOTEQUAL,
 
431
  COGL_MATERIAL_ALPHA_FUNC_GEQUAL   = GL_GEQUAL,
 
432
  COGL_MATERIAL_ALPHA_FUNC_ALWAYS   = GL_ALWAYS
 
433
} CoglMaterialAlphaFunc;
 
434
 
 
435
/**
 
436
 * cogl_material_set_alpha_test_function:
 
437
 * @material: A CoglMaterial object
 
438
 * @alpha_func: A @CoglMaterialAlphaFunc constant
 
439
 * @alpha_reference: A reference point that the chosen alpha function uses
 
440
 *   to compare incoming fragments to.
 
441
 *
 
442
 * Before a primitive is blended with the framebuffer, it goes through an
 
443
 * alpha test stage which lets you discard fragments based on the current
 
444
 * alpha value. This function lets you change the function used to evaluate
 
445
 * the alpha channel, and thus determine which fragments are discarded
 
446
 * and which continue on to the blending stage.
 
447
 *
 
448
 * The default is %COGL_MATERIAL_ALPHA_FUNC_ALWAYS
 
449
 *
 
450
 * Since: 1.0
 
451
 */
 
452
void
 
453
cogl_material_set_alpha_test_function (CoglHandle            material,
 
454
                                       CoglMaterialAlphaFunc alpha_func,
 
455
                                       float                 alpha_reference);
 
456
 
 
457
/**
 
458
 * cogl_material_set_blend:
 
459
 * @material: A CoglMaterial object
 
460
 * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
 
461
 *   describing the desired blend function.
 
462
 * @error: return location for a #GError that may report lack of driver
 
463
 *   support if you give separate blend string statements for the alpha
 
464
 *   channel and RGB channels since some drivers, or backends such as
 
465
 *   GLES 1.1, don't support this feature. May be %NULL, in which case a
 
466
 *   warning will be printed out using GLib's logging facilities if an
 
467
 *   error is encountered.
 
468
 *
 
469
 * If not already familiar; please refer <link linkend="cogl-Blend-Strings">here</link>
 
470
 * for an overview of what blend strings are, and their syntax.
 
471
 *
 
472
 * Blending occurs after the alpha test function, and combines fragments with
 
473
 * the framebuffer.
 
474
 
 
475
 * Currently the only blend function Cogl exposes is ADD(). So any valid
 
476
 * blend statements will be of the form:
 
477
 *
 
478
 * |[
 
479
 *   &lt;channel-mask&gt;=ADD(SRC_COLOR*(&lt;factor&gt;), DST_COLOR*(&lt;factor&gt;))
 
480
 * ]|
 
481
 *
 
482
 * <warning>The brackets around blend factors are currently not
 
483
 * optional!</warning>
 
484
 *
 
485
 * This is the list of source-names usable as blend factors:
 
486
 * <itemizedlist>
 
487
 *   <listitem><para>SRC_COLOR: The color of the in comming fragment</para></listitem>
 
488
 *   <listitem><para>DST_COLOR: The color of the framebuffer</para></listitem>
 
489
 *   <listitem><para>CONSTANT: The constant set via cogl_material_set_blend_constant()</para></listitem>
 
490
 * </itemizedlist>
 
491
 *
 
492
 * The source names can be used according to the
 
493
 * <link linkend="cogl-Blend-String-syntax">color-source and factor syntax</link>,
 
494
 * so for example "(1-SRC_COLOR[A])" would be a valid factor, as would
 
495
 * "(CONSTANT[RGB])"
 
496
 *
 
497
 * These can also be used as factors:
 
498
 * <itemizedlist>
 
499
 *   <listitem>0: (0, 0, 0, 0)</listitem>
 
500
 *   <listitem>1: (1, 1, 1, 1)</listitem>
 
501
 *   <listitem>SRC_ALPHA_SATURATE_FACTOR: (f,f,f,1) where f = MIN(SRC_COLOR[A],1-DST_COLOR[A])</listitem>
 
502
 * </itemizedlist>
 
503
 *
 
504
 * <note>Remember; all color components are normalized to the range [0, 1]
 
505
 * before computing the result of blending.</note>
 
506
 *
 
507
 * <example id="cogl-Blend-Strings-blend-unpremul">
 
508
 *   <title>Blend Strings/1</title>
 
509
 *   <para>Blend a non-premultiplied source over a destination with
 
510
 *   premultiplied alpha:</para>
 
511
 *   <programlisting>
 
512
 * "RGB = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))"
 
513
 * "A   = ADD(SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))"
 
514
 *   </programlisting>
 
515
 * </example>
 
516
 *
 
517
 * <example id="cogl-Blend-Strings-blend-premul">
 
518
 *   <title>Blend Strings/2</title>
 
519
 *   <para>Blend a premultiplied source over a destination with
 
520
 *   premultiplied alpha</para>
 
521
 *   <programlisting>
 
522
 * "RGBA = ADD(SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))"
 
523
 *   </programlisting>
 
524
 * </example>
 
525
 *
 
526
 * The default blend string is:
 
527
 * |[
 
528
 *    RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))
 
529
 * ]|
 
530
 *
 
531
 * That gives normal alpha-blending when the calculated color for the material
 
532
 * is in premultiplied form.
 
533
 *
 
534
 * Return value: %TRUE if the blend string was successfully parsed, and the
 
535
 *   described blending is supported by the underlying driver/hardware. If
 
536
 *   there was an error, %FALSE is returned and @error is set accordingly (if
 
537
 *   present).
 
538
 *
 
539
 * Since: 1.0
 
540
 */
 
541
gboolean
 
542
cogl_material_set_blend (CoglHandle  material,
 
543
                         const char *blend_string,
 
544
                         GError    **error);
 
545
 
 
546
/**
 
547
 * cogl_material_set_blend_constant:
 
548
 * @material: A CoglMaterial object
 
549
 * @constant_color: The constant color you want
 
550
 *
 
551
 * When blending is setup to reference a CONSTANT blend factor then
 
552
 * blending will depend on the constant set with this function.
 
553
 *
 
554
 * Since: 1.0
 
555
 */
 
556
void
 
557
cogl_material_set_blend_constant (CoglHandle material,
 
558
                                  CoglColor *constant_color);
 
559
 
 
560
/**
 
561
 * cogl_material_set_layer:
 
562
 * @material: A #CoglHandle for a material object
 
563
 * @layer_index: the index of the layer
 
564
 * @texture: a #CoglHandle for the layer object
 
565
 *
 
566
 * In addition to the standard OpenGL lighting model a Cogl material may have
 
567
 * one or more layers comprised of textures that can be blended together in
 
568
 * order, with a number of different texture combine modes. This function
 
569
 * defines a new texture layer.
 
570
 *
 
571
 * The index values of multiple layers do not have to be consecutive; it is
 
572
 * only their relative order that is important.
 
573
 *
 
574
 * <note>In the future, we may define other types of material layers, such
 
575
 * as purely GLSL based layers.</note>
 
576
 *
 
577
 * Since: 1.0
 
578
 */
 
579
void
 
580
cogl_material_set_layer (CoglHandle material,
 
581
                         int        layer_index,
 
582
                         CoglHandle texture);
 
583
 
 
584
/**
 
585
 * cogl_material_remove_layer:
 
586
 * @material: A CoglMaterial object
 
587
 * @layer_index: Specifies the layer you want to remove
 
588
 *
 
589
 * This function removes a layer from your material
 
590
 */
 
591
void
 
592
cogl_material_remove_layer (CoglHandle material,
 
593
                            int        layer_index);
 
594
 
 
595
 
 
596
/**
 
597
 * cogl_material_set_layer_combine:
 
598
 * @material: A CoglMaterial object
 
599
 * @layer_index: Specifies the layer you want define a combine function for
 
600
 * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
 
601
 *    describing the desired texture combine function.
 
602
 * @error: A #GError that may report parse errors or lack of GPU/driver
 
603
 *   support. May be %NULL, in which case a warning will be printed out if an
 
604
 *   error is encountered.
 
605
 *
 
606
 * If not already familiar; you can refer
 
607
 * <link linkend="cogl-Blend-Strings">here</link> for an overview of what blend
 
608
 * strings are and there syntax.
 
609
 *
 
610
 * These are all the functions available for texture combining:
 
611
 * <itemizedlist>
 
612
 *   <listitem>REPLACE(arg0) = arg0</listitem>
 
613
 *   <listitem>MODULATE(arg0, arg1) = arg0 x arg1</listitem>
 
614
 *   <listitem>ADD(arg0, arg1) = arg0 + arg1</listitem>
 
615
 *   <listitem>ADD_SIGNED(arg0, arg1) = arg0 + arg1 - 0.5</listitem>
 
616
 *   <listitem>INTERPOLATE(arg0, arg1, arg2) = arg0 x arg2 + arg1 x (1 - arg2)</listitem>
 
617
 *   <listitem>SUBTRACT(arg0, arg1) = arg0 - arg1</listitem>
 
618
 *   <listitem>
 
619
 *     <programlisting>
 
620
 *  DOT3_RGB(arg0, arg1) = 4 x ((arg0[R] - 0.5)) * (arg1[R] - 0.5) +
 
621
 *                              (arg0[G] - 0.5)) * (arg1[G] - 0.5) +
 
622
 *                              (arg0[B] - 0.5)) * (arg1[B] - 0.5))
 
623
 *     </programlisting>
 
624
 *   </listitem>
 
625
 *   <listitem>
 
626
 *     <programlisting>
 
627
 *  DOT3_RGBA(arg0, arg1) = 4 x ((arg0[R] - 0.5)) * (arg1[R] - 0.5) +
 
628
 *                               (arg0[G] - 0.5)) * (arg1[G] - 0.5) +
 
629
 *                               (arg0[B] - 0.5)) * (arg1[B] - 0.5))
 
630
 *     </programlisting>
 
631
 *   </listitem>
 
632
 * </itemizedlist>
 
633
 *
 
634
 * Refer to the
 
635
 * <link linkend="cogl-Blend-String-syntax">color-source syntax</link> for
 
636
 * describing the arguments. The valid source names for texture combining
 
637
 * are:
 
638
 * <variablelist>
 
639
 *   <varlistentry>
 
640
 *     <term>TEXTURE</term>
 
641
 *     <listitem>Use the color from the current texture layer</listitem>
 
642
 *   </varlistentry>
 
643
 *   <varlistentry>
 
644
 *     <term>TEXTURE_0, TEXTURE_1, etc</term>
 
645
 *     <listitem>Use the color from the specified texture layer</listitem>
 
646
 *   </varlistentry>
 
647
 *   <varlistentry>
 
648
 *     <term>CONSTANT</term>
 
649
 *     <listitem>Use the color from the constant given with
 
650
 *     cogl_material_set_layer_constant()</listitem>
 
651
 *   </varlistentry>
 
652
 *   <varlistentry>
 
653
 *     <term>PRIMARY</term>
 
654
 *     <listitem>Use the color of the material as set with
 
655
 *     cogl_material_set_color()</listitem>
 
656
 *   </varlistentry>
 
657
 *   <varlistentry>
 
658
 *     <term>PREVIOUS</term>
 
659
 *     <listitem>Either use the texture color from the previous layer, or
 
660
 *     if this is layer 0, use the color of the material as set with
 
661
 *     cogl_material_set_color()</listitem>
 
662
 *   </varlistentry>
 
663
 * </variablelist>
 
664
 *
 
665
 * <refsect2 id="cogl-Layer-Combine-Examples">
 
666
 *   <title>Layer Combine Examples</title>
 
667
 *   <para>This is effectively what the default blending is:</para>
 
668
 *   <informalexample><programlisting>
 
669
 *   RGBA = MODULATE (PREVIOUS, TEXTURE)
 
670
 *   </programlisting></informalexample>
 
671
 *   <para>This could be used to cross-fade between two images, using
 
672
 *   the alpha component of a constant as the interpolator. The constant
 
673
 *   color is given by calling cogl_material_set_layer_constant.</para>
 
674
 *   <informalexample><programlisting>
 
675
 *   RGBA = INTERPOLATE (PREVIOUS, TEXTURE, CONSTANT[A])
 
676
 *   </programlisting></informalexample>
 
677
 * </refsect2>
 
678
 *
 
679
 * <note>You can't give a multiplication factor for arguments as you can
 
680
 * with blending.</note>
 
681
 *
 
682
 * Return value: %TRUE if the blend string was successfully parsed, and the
 
683
 *   described texture combining is supported by the underlying driver and
 
684
 *   or hardware. On failure, %FALSE is returned and @error is set
 
685
 *
 
686
 * Since: 1.0
 
687
 */
 
688
gboolean
 
689
cogl_material_set_layer_combine (CoglHandle   material,
 
690
                                 int          layer_index,
 
691
                                 const char  *blend_string,
 
692
                                 GError     **error);
 
693
 
 
694
/**
 
695
 * cogl_material_set_layer_combine_constant:
 
696
 * @material: A CoglMaterial object
 
697
 * @layer_index: Specifies the layer you want to specify a constant used
 
698
 *               for texture combining
 
699
 * @constant: The constant color you want
 
700
 *
 
701
 * When you are using the 'CONSTANT' color source in a layer combine
 
702
 * description then you can use this function to define its value.
 
703
 *
 
704
 * Since: 1.0
 
705
 */
 
706
void
 
707
cogl_material_set_layer_combine_constant (CoglHandle  material,
 
708
                                          int         layer_index,
 
709
                                          CoglColor  *constant);
 
710
 
 
711
/**
 
712
 * cogl_material_set_layer_matrix:
 
713
 * @material: A CoglMaterial object
 
714
 * @layer_index: the index for the layer inside @material
 
715
 * @matrix: the transformation matrix for the layer
 
716
 *
 
717
 * This function lets you set a matrix that can be used to e.g. translate
 
718
 * and rotate a single layer of a material used to fill your geometry.
 
719
 */
 
720
void
 
721
cogl_material_set_layer_matrix (CoglHandle  material,
 
722
                                int         layer_index,
 
723
                                CoglMatrix *matrix);
 
724
 
 
725
/**
 
726
 * cogl_material_get_layers:
 
727
 * @material: a #CoglHandle for a material
 
728
 *
 
729
 * This function lets you access a materials internal list of layers
 
730
 * for iteration.
 
731
 *
 
732
 * Return value: (element-type Handle) (transfer none): A list of
 
733
 *   #CoglHandle<!-- -->'s that can be passed to the  cogl_material_layer_*
 
734
 *   functions. The list is owned by COGL and it  should not be modified or
 
735
 *   freed
 
736
 */
 
737
G_CONST_RETURN GList *
 
738
cogl_material_get_layers (CoglHandle material);
 
739
 
 
740
/**
 
741
 * cogl_material_get_n_layers:
 
742
 * @material: a #CoglHandle for a material
 
743
 *
 
744
 * Retrieves the number of layers defined for the given @material
 
745
 *
 
746
 * Return value: the number of layers
 
747
 *
 
748
 * Since: 1.0
 
749
 */
 
750
int
 
751
cogl_material_get_n_layers (CoglHandle material);
 
752
 
 
753
/**
 
754
 * CoglMaterialLayerType:
 
755
 * @COGL_MATERIAL_LAYER_TYPE_TEXTURE: The layer represents a
 
756
 *   <link linkend="cogl-Textures">texture</link>
 
757
 *
 
758
 * Available types of layers for a #CoglMaterial. This enumeration
 
759
 * might be expanded in later versions.
 
760
 *
 
761
 * Since: 1.0
 
762
 */
 
763
typedef enum {
 
764
  COGL_MATERIAL_LAYER_TYPE_TEXTURE
 
765
} CoglMaterialLayerType;
 
766
 
 
767
 
 
768
/**
 
769
 * cogl_material_layer_get_type:
 
770
 * @layer: A #CoglHandle for a material layer
 
771
 *
 
772
 * Retrieves the type of the layer
 
773
 *
 
774
 * Currently there is only one type of layer defined:
 
775
 * %COGL_MATERIAL_LAYER_TYPE_TEXTURE, but considering we may add purely GLSL
 
776
 * based layers in the future, you should write code that checks the type
 
777
 * first.
 
778
 *
 
779
 * Return value: the type of the layer
 
780
 */
 
781
CoglMaterialLayerType
 
782
cogl_material_layer_get_type (CoglHandle layer);
 
783
 
 
784
/**
 
785
 * cogl_material_layer_get_texture:
 
786
 * @layer: A #CoglHandle for a material layer
 
787
 *
 
788
 * Extracts a texture handle for a specific layer.
 
789
 *
 
790
 * <note>In the future Cogl may support purely GLSL based layers; for those
 
791
 * layers this function which will likely return %COGL_INVALID_HANDLE if you
 
792
 * try to get the texture handle from them. Considering this scenario, you
 
793
 * should call cogl_material_layer_get_type() first in order check it is of
 
794
 * type %COGL_MATERIAL_LAYER_TYPE_TEXTURE before calling this function.</note>
 
795
 *
 
796
 * Return value: a #CoglHandle for the texture inside the layer
 
797
 */
 
798
CoglHandle
 
799
cogl_material_layer_get_texture (CoglHandle layer);
 
800
 
 
801
/**
 
802
 * cogl_material_layer_get_min_filter:
 
803
 * @layer: a #CoglHandle for a material layer
 
804
 *
 
805
 * Queries the currently set downscaling filter for a material layer
 
806
 *
 
807
 * Return value: the current downscaling filter
 
808
 */
 
809
CoglMaterialFilter
 
810
cogl_material_layer_get_min_filter (CoglHandle layer);
 
811
 
 
812
/**
 
813
 * cogl_material_layer_get_mag_filter:
 
814
 * @layer: a #CoglHandle for a material layer
 
815
 *
 
816
 * Queries the currently set downscaling filter for a material later
 
817
 *
 
818
 * Return value: the current downscaling filter
 
819
 */
 
820
CoglMaterialFilter
 
821
cogl_material_layer_get_mag_filter (CoglHandle layer);
 
822
 
 
823
/**
 
824
 * cogl_material_set_layer_filters:
 
825
 * @material: a #CoglHandle to a material.
 
826
 * @layer_index: the layer number to change.
 
827
 * @min_filter: the filter used when scaling a texture down.
 
828
 * @mag_filter: the filter used when magnifying a texture.
 
829
 *
 
830
 * Changes the decimation and interpolation filters used when a texture is
 
831
 * drawn at other scales than 100%.
 
832
 */
 
833
void
 
834
cogl_material_set_layer_filters (CoglHandle         material,
 
835
                                 int                layer_index,
 
836
                                 CoglMaterialFilter min_filter,
 
837
                                 CoglMaterialFilter mag_filter);
 
838
 
 
839
G_END_DECLS
 
840
 
 
841
#endif /* __COGL_MATERIAL_H__ */