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

« back to all changes in this revision

Viewing changes to clutter/cogl/cogl-texture.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, write to the
20
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
 
 * Boston, MA 02111-1307, USA.
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_TEXTURE_H__
29
 
#define __COGL_TEXTURE_H__
30
 
 
31
 
#include <cogl/cogl-types.h>
32
 
 
33
 
G_BEGIN_DECLS
34
 
 
35
 
/**
36
 
 * SECTION:cogl-texture
37
 
 * @short_description: Fuctions for creating and manipulating textures
38
 
 *
39
 
 * COGL allows creating and manipulating GL textures using a uniform
40
 
 * API that tries to hide all the various complexities of creating,
41
 
 * loading and manipulating textures.
42
 
 */
43
 
 
44
 
#define COGL_TEXTURE_MAX_WASTE  127
45
 
 
46
 
/**
47
 
 * cogl_texture_new_with_size:
48
 
 * @width: width of texture in pixels.
49
 
 * @height: height of texture in pixels.
50
 
 * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
51
 
 * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
52
 
 *    texture.
53
 
 *
54
 
 * Creates a new COGL texture with the specified dimensions and pixel format.
55
 
 *
56
 
 * Return value: a #CoglHandle to the newly created texture or
57
 
 *   %COGL_INVALID_HANDLE on failure
58
 
 *
59
 
 * Since: 0.8
60
 
 */
61
 
CoglHandle      cogl_texture_new_with_size    (guint            width,
62
 
                                               guint            height,
63
 
                                               CoglTextureFlags flags,
64
 
                                               CoglPixelFormat  internal_format);
65
 
 
66
 
/**
67
 
 * cogl_texture_new_from_file:
68
 
 * @filename: the file to load
69
 
 * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
70
 
 * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
71
 
 *    texture. If COGL_PIXEL_FORMAT_ANY is given then a premultiplied
72
 
 *    format similar to the format of the source data will be used. The
73
 
 *    default blending equations of Cogl expect premultiplied color data;
74
 
 *    the main use of passing a non-premultiplied format here is if you
75
 
 *    have non-premultiplied source data and are going to adjust the blend
76
 
 *    mode (see cogl_material_set_blend()) or use the data for something
77
 
 *    other than straight blending.
78
 
 * @error: return location for a #GError or %NULL
79
 
 *
80
 
 * Creates a COGL texture from an image file.
81
 
 *
82
 
 * Return value: a #CoglHandle to the newly created texture or
83
 
 *    %COGL_INVALID_HANDLE on failure
84
 
 *
85
 
 * Since: 0.8
86
 
 */
87
 
CoglHandle      cogl_texture_new_from_file    (const gchar       *filename,
88
 
                                               CoglTextureFlags   flags,
89
 
                                               CoglPixelFormat    internal_format,
90
 
                                               GError           **error);
91
 
 
92
 
/**
93
 
 * cogl_texture_new_from_data:
94
 
 * @width: width of texture in pixels
95
 
 * @height: height of texture in pixels
96
 
 * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
97
 
 * @format: the #CoglPixelFormat the buffer is stored in in RAM
98
 
 * @internal_format: the #CoglPixelFormat that will be used for storing
99
 
 *    the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
100
 
 *    premultiplied format similar to the format of the source data will
101
 
 *    be used. The default blending equations of Cogl expect premultiplied
102
 
 *    color data; the main use of passing a non-premultiplied format here
103
 
 *    is if you have non-premultiplied source data and are going to adjust
104
 
 *    the blend mode (see cogl_material_set_blend()) or use the data for
105
 
 *    something other than straight blending.
106
 
 * @rowstride: the memory offset in bytes between the starts of
107
 
 *    scanlines in @data
108
 
 * @data: pointer the memory region where the source buffer resides
109
 
 *
110
 
 * Creates a new COGL texture based on data residing in memory.
111
 
 *
112
 
 * Return value: a #CoglHandle to the newly created texture or
113
 
 *   %COGL_INVALID_HANDLE on failure
114
 
 *
115
 
 * Since: 0.8
116
 
 */
117
 
CoglHandle      cogl_texture_new_from_data    (guint             width,
118
 
                                               guint             height,
119
 
                                               CoglTextureFlags  flags,
120
 
                                               CoglPixelFormat   format,
121
 
                                               CoglPixelFormat   internal_format,
122
 
                                               guint             rowstride,
123
 
                                               const guchar     *data);
124
 
 
125
 
/**
126
 
 * cogl_texture_new_from_foreign:
127
 
 * @gl_handle: opengl target type of foreign texture
128
 
 * @gl_target: opengl handle of foreign texture.
129
 
 * @width: width of foreign texture
130
 
 * @height: height of foreign texture.
131
 
 * @x_pot_waste: maximum horizontal waste.
132
 
 * @y_pot_waste: maximum vertical waste.
133
 
 * @format: format of the foreign texture.
134
 
 *
135
 
 * Creates a COGL texture based on an existing OpenGL texture; the
136
 
 * width, height and format are passed along since it is not possible
137
 
 * to query this from a handle with GLES 1.0.
138
 
 *
139
 
 * Return value: a #CoglHandle to the newly created texture or
140
 
 *   %COGL_INVALID_HANDLE on failure
141
 
 *
142
 
 * Since: 0.8
143
 
 */
144
 
CoglHandle      cogl_texture_new_from_foreign (GLuint          gl_handle,
145
 
                                               GLenum          gl_target,
146
 
                                               GLuint          width,
147
 
                                               GLuint          height,
148
 
                                               GLuint          x_pot_waste,
149
 
                                               GLuint          y_pot_waste,
150
 
                                               CoglPixelFormat format);
151
 
 
152
 
/**
153
 
 * cogl_texture_new_from_bitmap:
154
 
 * @bmp_handle: A CoglBitmap handle
155
 
 * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
156
 
 * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
157
 
 * texture
158
 
 *
159
 
 * Creates a COGL texture from a CoglBitmap.
160
 
 *
161
 
 * Return value: a #CoglHandle to the newly created texture or
162
 
 *   %COGL_INVALID_HANDLE on failure
163
 
 *
164
 
 * Since: 1.0
165
 
 */
166
 
CoglHandle      cogl_texture_new_from_bitmap (CoglHandle       bmp_handle,
167
 
                                              CoglTextureFlags flags,
168
 
                                              CoglPixelFormat  internal_format);
169
 
 
170
 
/**
171
 
 * cogl_is_texture:
172
 
 * @handle: A CoglHandle
173
 
 *
174
 
 * Gets whether the given handle references an existing texture object.
175
 
 *
176
 
 * Returns: %TRUE if the handle references a texture,
177
 
 *   %FALSE otherwise
178
 
 */
179
 
gboolean        cogl_is_texture               (CoglHandle          handle);
180
 
 
181
 
/**
182
 
 * cogl_texture_get_width:
183
 
 * @handle: a #CoglHandle for a texture.
184
 
 *
185
 
 * Query the width of a cogl texture.
186
 
 *
187
 
 * Returns: the width of the GPU side texture in pixels:
188
 
 */
189
 
guint           cogl_texture_get_width        (CoglHandle          handle);
190
 
 
191
 
/**
192
 
 * cogl_texture_get_height:
193
 
 * @handle: a #CoglHandle for a texture.
194
 
 *
195
 
 * Query the height of a cogl texture.
196
 
 *
197
 
 * Returns: the height of the GPU side texture in pixels:
198
 
 */
199
 
guint           cogl_texture_get_height       (CoglHandle          handle);
200
 
 
201
 
/**
202
 
 * cogl_texture_get_format:
203
 
 * @handle: a #CoglHandle for a texture.
204
 
 *
205
 
 * Query the #CoglPixelFormat of a cogl texture.
206
 
 *
207
 
 * Returns: the #CoglPixelFormat of the GPU side texture.
208
 
 */
209
 
CoglPixelFormat cogl_texture_get_format       (CoglHandle          handle);
210
 
 
211
 
 
212
 
/**
213
 
 * cogl_texture_get_rowstride:
214
 
 * @handle: a #CoglHandle for a texture.
215
 
 *
216
 
 * Query the rowstride of a cogl texture.
217
 
 *
218
 
 * Returns: the offset in bytes between each consequetive row of pixels.
219
 
 */
220
 
guint           cogl_texture_get_rowstride    (CoglHandle          handle);
221
 
 
222
 
/**
223
 
 * cogl_texture_get_max_waste:
224
 
 * @handle: a #CoglHandle for a texture.
225
 
 *
226
 
 * Query the maximum wasted (unused) pixels in one dimension of a GPU side
227
 
 * texture.
228
 
 *
229
 
 * Returns: the maximum waste.
230
 
 */
231
 
gint            cogl_texture_get_max_waste    (CoglHandle          handle);
232
 
 
233
 
/**
234
 
 * cogl_texture_is_sliced:
235
 
 * @handle: a #CoglHandle for a texture.
236
 
 *
237
 
 * Query if a texture is sliced (stored as multiple GPU side tecture
238
 
 * objects).
239
 
 *
240
 
 * Returns: %TRUE if the texture is sliced, %FALSE if the texture
241
 
 * is stored as a single GPU texture.
242
 
 */
243
 
gboolean        cogl_texture_is_sliced        (CoglHandle          handle);
244
 
 
245
 
/**
246
 
 * cogl_texture_get_gl_texture:
247
 
 * @handle: a #CoglHandle for a texture.
248
 
 * @out_gl_handle: (out) (allow-none): pointer to return location for the
249
 
 *   textures GL handle, or %NULL.
250
 
 * @out_gl_target: (out) (allow-none): pointer to return location for the
251
 
 *   GL target type, or %NULL.
252
 
 *
253
 
 * Query the GL handles for a GPU side texture through it's #CoglHandle,
254
 
 * if the texture is spliced the data for the first sub texture will be
255
 
 * queried.
256
 
 *
257
 
 * Returns: %TRUE if the handle was successfully retrieved %FALSE
258
 
 * if the handle was invalid.
259
 
 */
260
 
gboolean        cogl_texture_get_gl_texture   (CoglHandle         handle,
261
 
                                               GLuint            *out_gl_handle,
262
 
                                               GLenum            *out_gl_target);
263
 
 
264
 
/**
265
 
 * cogl_texture_get_data:
266
 
 * @handle: a #CoglHandle for a texture.
267
 
 * @format: the #CoglPixelFormat to store the texture as.
268
 
 * @rowstride: the rowstride of @data or retrieved from texture if none is
269
 
 * specified.
270
 
 * @data: memory location to write contents of buffer, or %NULL if we're
271
 
 * only querying the data size through the return value.
272
 
 *
273
 
 * Copy the pixel data from a cogl texture to system memory.
274
 
 *
275
 
 * Returns: the size of the texture data in bytes (or 0 if the texture
276
 
 * is not valid.)
277
 
 */
278
 
gint            cogl_texture_get_data         (CoglHandle          handle,
279
 
                                               CoglPixelFormat     format,
280
 
                                               guint               rowstride,
281
 
                                               guchar             *data);
282
 
 
283
 
/**
284
 
 * cogl_texture_set_region:
285
 
 * @handle: a #CoglHandle.
286
 
 * @src_x: upper left coordinate to use from source data.
287
 
 * @src_y: upper left coordinate to use from source data.
288
 
 * @dst_x: upper left destination horizontal coordinate.
289
 
 * @dst_y: upper left destination vertical coordinate.
290
 
 * @dst_width: width of destination region to write.
291
 
 * @dst_height: height of destination region to write.
292
 
 * @width: width of source data buffer.
293
 
 * @height: height of source data buffer.
294
 
 * @format: the #CoglPixelFormat used in the source buffer.
295
 
 * @rowstride: rowstride of source buffer (computed from width if none
296
 
 * specified)
297
 
 * @data: the actual pixel data.
298
 
 *
299
 
 * Sets the pixels in a rectangular subregion of @handle from an in-memory
300
 
 * buffer containing pixel data.
301
 
 *
302
 
 * Returns: %TRUE if the subregion upload was successful, otherwise %FALSE.
303
 
 */
304
 
gboolean        cogl_texture_set_region       (CoglHandle          handle,
305
 
                                               gint                src_x,
306
 
                                               gint                src_y,
307
 
                                               gint                dst_x,
308
 
                                               gint                dst_y,
309
 
                                               guint               dst_width,
310
 
                                               guint               dst_height,
311
 
                                               gint                width,
312
 
                                               gint                height,
313
 
                                               CoglPixelFormat     format,
314
 
                                               guint               rowstride,
315
 
                                               const guchar       *data);
316
 
 
317
 
/**
318
 
 * cogl_texture_ref:
319
 
 * @handle: a @CoglHandle.
320
 
 *
321
 
 * Increment the reference count for a cogl texture.
322
 
 *
323
 
 * Returns: the @handle.
324
 
 */
325
 
CoglHandle      cogl_texture_ref              (CoglHandle          handle);
326
 
 
327
 
/**
328
 
 * cogl_texture_unref:
329
 
 * @handle: a @CoglHandle.
330
 
 *
331
 
 * Deccrement the reference count for a cogl texture.
332
 
 */
333
 
void            cogl_texture_unref            (CoglHandle          handle);
334
 
 
335
 
/**
336
 
 * cogl_rectangle_with_texture_coords:
337
 
 * @x1: x coordinate upper left on screen.
338
 
 * @y1: y coordinate upper left on screen.
339
 
 * @x2: x coordinate lower right on screen.
340
 
 * @y2: y coordinate lower right on screen.
341
 
 * @tx1: x part of texture coordinate to use for upper left pixel
342
 
 * @ty1: y part of texture coordinate to use for upper left pixel
343
 
 * @tx2: x part of texture coordinate to use for lower right pixel
344
 
 * @ty2: y part of texture coordinate to use for left pixel
345
 
 *
346
 
 * Draw a rectangle using the current material and supply texture coordinates
347
 
 * to be used for the first texture layer of the material. To draw the entire
348
 
 * texture pass in @tx1=0.0 @ty1=0.0 @tx2=1.0 @ty2=1.0.
349
 
 *
350
 
 * Since 1.0
351
 
 */
352
 
void cogl_rectangle_with_texture_coords (float  x1,
353
 
                                         float  y1,
354
 
                                         float  x2,
355
 
                                         float  y2,
356
 
                                         float  tx1,
357
 
                                         float  ty1,
358
 
                                         float  tx2,
359
 
                                         float  ty2);
360
 
 
361
 
/**
362
 
 * cogl_rectangle_with_multitexture_coords:
363
 
 * @x1: x coordinate upper left on screen.
364
 
 * @y1: y coordinate upper left on screen.
365
 
 * @x2: x coordinate lower right on screen.
366
 
 * @y2: y coordinate lower right on screen.
367
 
 * @tex_coords: (in) (array) (transfer none): An array containing groups of 4
368
 
 *   float values: [tx1, ty1, tx2, ty2] that are interpreted as two texture
369
 
 *   coordinates; one for the upper left texel, and one for the lower right
370
 
 *   texel. Each value should be between 0.0 and 1.0, where the coordinate
371
 
 *   (0.0, 0.0) represents the top left of the texture, and (1.0, 1.0) the
372
 
 *   bottom right.
373
 
 * @tex_coords_len: The length of the tex_coords array. (e.g. for one layer
374
 
 *                  and one group of texture coordinates, this would be 4)
375
 
 *
376
 
 * This function draws a rectangle using the current source material to
377
 
 * texture or fill with. As a material may contain multiple texture layers
378
 
 * this interface lets you supply texture coordinates for each layer of the
379
 
 * material.
380
 
 *
381
 
 * The first pair of coordinates are for the first layer (with the smallest
382
 
 * layer index) and if you supply less texture coordinates than there are
383
 
 * layers in the current source material then default texture coordinates
384
 
 * (0.0, 0.0, 1.0, 1.0) are generated.
385
 
 *
386
 
 * Since 1.0
387
 
 */
388
 
void cogl_rectangle_with_multitexture_coords (float        x1,
389
 
                                              float        y1,
390
 
                                              float        x2,
391
 
                                              float        y2,
392
 
                                              const float *tex_coords,
393
 
                                              gint         tex_coords_len);
394
 
 
395
 
/**
396
 
 * cogl_rectangles_with_texture_coords:
397
 
 * @verts: (in) (array) (transfer none): an array of vertices
398
 
 * @n_rects: number of rectangles to draw
399
 
 *
400
 
 * Draws a series of rectangles in the same way that
401
 
 * cogl_rectangle_with_texture_coords() does. In some situations it can give a
402
 
 * significant performance boost to use this function rather than
403
 
 * calling cogl_rectangle_with_texture_coords() separately for each rectangle.
404
 
 *
405
 
 * @verts should point to an array of #float<!-- -->s with
406
 
 * @n_rects * 8 elements. Each group of 8 values corresponds to the
407
 
 * parameters x1, y1, x2, y2, tx1, ty1, tx2 and ty2 and have the same
408
 
 * meaning as in cogl_rectangle_with_texture_coords().
409
 
 *
410
 
 * Since: 0.8.6
411
 
 */
412
 
void  cogl_rectangles_with_texture_coords (const float *verts,
413
 
                                           guint        n_rects);
414
 
 
415
 
/**
416
 
 * cogl_rectangles:
417
 
 * @verts: (in) (array) (transfer none): an array of vertices
418
 
 * @n_rects: number of rectangles to draw
419
 
 *
420
 
 * Draws a series of rectangles in the same way that
421
 
 * cogl_rectangle() does. In some situations it can give a
422
 
 * significant performance boost to use this function rather than
423
 
 * calling cogl_rectangle() separately for each rectangle.
424
 
 *
425
 
 * @verts should point to an array of #float<!-- -->s with
426
 
 * @n_rects * 4 elements. Each group of 4 values corresponds to the
427
 
 * parameters x1, y1, x2, and y2, and have the same
428
 
 * meaning as in cogl_rectangle().
429
 
 *
430
 
 * Since: 1.0
431
 
 */
432
 
void cogl_rectangles (const float *verts,
433
 
                      guint        n_rects);
434
 
 
435
 
 
436
 
/**
437
 
 * cogl_polygon:
438
 
 * @vertices: An array of #CoglTextureVertex structs
439
 
 * @n_vertices: The length of the vertices array
440
 
 * @use_color: %TRUE if the color member of #CoglTextureVertex should be used
441
 
 *
442
 
 * Draws a convex polygon using the current source material to fill / texture
443
 
 * with according to the texture coordinates passed.
444
 
 *
445
 
 * If @use_color is %TRUE then the color will be changed for each vertex using
446
 
 * the value specified in the color member of #CoglTextureVertex. This can be
447
 
 * used for example to make the texture fade out by setting the alpha value of
448
 
 * the color.
449
 
 *
450
 
 * All of the texture coordinates must be in the range [0,1] and repeating the
451
 
 * texture is not supported.
452
 
 *
453
 
 * Because of the way this function is implemented it will currently only work
454
 
 * if either the texture is not sliced or the backend is not OpenGL ES and the
455
 
 * minifying and magnifying functions are both set to CGL_NEAREST.
456
 
 *
457
 
 * Since 1.0
458
 
 */
459
 
void cogl_polygon (CoglTextureVertex  *vertices,
460
 
                   guint               n_vertices,
461
 
                   gboolean            use_color);
462
 
 
463
 
G_END_DECLS
464
 
 
465
 
#endif /* __COGL_TEXTURE_H__ */