~gnome3-team/mutter/trunk

« back to all changes in this revision

Viewing changes to cogl/cogl/cogl-atlas-texture.h

  • Committer: Rui Matos
  • Date: 2016-04-27 16:36:25 UTC
  • mfrom: (0.87.3184)
  • Revision ID: git-v1:3fcbe1d3ec5c9208dde080f7e9dac24e4c379bc0
Merge cogl's cogl-1.22 branch into mutter

https://bugzilla.gnome.org/show_bug.cgi?id=760439

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * A Low Level GPU Graphics and Utilities API
 
5
 *
 
6
 * Copyright (C) 2013 Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person
 
9
 * obtaining a copy of this software and associated documentation
 
10
 * files (the "Software"), to deal in the Software without
 
11
 * restriction, including without limitation the rights to use, copy,
 
12
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 
13
 * of the Software, and to permit persons to whom the Software is
 
14
 * furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 *
 
28
 *
 
29
 */
 
30
 
 
31
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
 
32
#error "Only <cogl/cogl.h> can be included directly."
 
33
#endif
 
34
 
 
35
#ifndef _COGL_ATLAS_TEXTURE_H_
 
36
#define _COGL_ATLAS_TEXTURE_H_
 
37
 
 
38
#include <cogl/cogl-context.h>
 
39
 
 
40
#ifdef COGL_HAS_GTYPE_SUPPORT
 
41
#include <glib-object.h>
 
42
#endif
 
43
 
 
44
COGL_BEGIN_DECLS
 
45
 
 
46
/**
 
47
 * SECTION:cogl-atlas-texture
 
48
 * @short_description: Functions for managing textures in Cogl's global
 
49
 *                     set of texture atlases
 
50
 *
 
51
 * A texture atlas is a texture that contains many smaller images that
 
52
 * an application is interested in. These are packed together as a way
 
53
 * of optimizing drawing with those images by avoiding the costs of
 
54
 * repeatedly telling the hardware to change what texture it should
 
55
 * sample from.  This can enable more geometry to be batched together
 
56
 * into few draw calls.
 
57
 *
 
58
 * Each #CoglContext has an shared, pool of texture atlases that are
 
59
 * are managed by Cogl.
 
60
 *
 
61
 * This api lets applications upload texture data into one of Cogl's
 
62
 * shared texture atlases using a high-level #CoglAtlasTexture which
 
63
 * represents a sub-region of one of these atlases.
 
64
 *
 
65
 * <note>A #CoglAtlasTexture is a high-level meta texture which has
 
66
 * some limitations to be aware of. Please see the documentation for
 
67
 * #CoglMetaTexture for more details.</note>
 
68
 */
 
69
 
 
70
 
 
71
typedef struct _CoglAtlasTexture CoglAtlasTexture;
 
72
#define COGL_ATLAS_TEXTURE(tex) ((CoglAtlasTexture *) tex)
 
73
 
 
74
#ifdef COGL_HAS_GTYPE_SUPPORT
 
75
/**
 
76
 * cogl_atlas_texture_get_gtype:
 
77
 *
 
78
 * Returns: a #GType that can be used with the GLib type system.
 
79
 */
 
80
GType cogl_atlas_texture_get_gtype (void);
 
81
#endif
 
82
 
 
83
/**
 
84
 * cogl_atlas_texture_new_with_size:
 
85
 * @ctx: A #CoglContext
 
86
 * @width: The width of your atlased texture.
 
87
 * @height: The height of your atlased texture.
 
88
 *
 
89
 * Creates a #CoglAtlasTexture with a given @width and @height. A
 
90
 * #CoglAtlasTexture represents a sub-region within one of Cogl's
 
91
 * shared texture atlases.
 
92
 *
 
93
 * The storage for the texture is not allocated before this function
 
94
 * returns. You can call cogl_texture_allocate() to explicitly
 
95
 * allocate the underlying storage or let Cogl automatically allocate
 
96
 * storage lazily.
 
97
 *
 
98
 * The texture is still configurable until it has been allocated so
 
99
 * for example you can influence the internal format of the texture
 
100
 * using cogl_texture_set_components() and
 
101
 * cogl_texture_set_premultiplied().
 
102
 *
 
103
 * <note>Allocate call can fail if Cogl considers the internal
 
104
 * format to be incompatible with the format of its internal
 
105
 * atlases.</note>
 
106
 *
 
107
 * <note>The returned #CoglAtlasTexture is a high-level meta-texture
 
108
 * with some limitations. See the documentation for #CoglMetaTexture
 
109
 * for more details.</note>
 
110
 *
 
111
 * Returns: (transfer full): A new #CoglAtlasTexture object.
 
112
 * Since: 1.16
 
113
 * Stability: unstable
 
114
 */
 
115
CoglAtlasTexture *
 
116
cogl_atlas_texture_new_with_size (CoglContext *ctx,
 
117
                                  int width,
 
118
                                  int height);
 
119
 
 
120
/**
 
121
 * cogl_atlas_texture_new_from_file:
 
122
 * @ctx: A #CoglContext
 
123
 * @filename: the file to load
 
124
 * @error: A #CoglError to catch exceptional errors or %NULL
 
125
 *
 
126
 * Creates a #CoglAtlasTexture from an image file. A #CoglAtlasTexture
 
127
 * represents a sub-region within one of Cogl's shared texture
 
128
 * atlases.
 
129
 *
 
130
 * The storage for the texture is not allocated before this function
 
131
 * returns. You can call cogl_texture_allocate() to explicitly
 
132
 * allocate the underlying storage or let Cogl automatically allocate
 
133
 * storage lazily.
 
134
 *
 
135
 * The texture is still configurable until it has been allocated so
 
136
 * for example you can influence the internal format of the texture
 
137
 * using cogl_texture_set_components() and
 
138
 * cogl_texture_set_premultiplied().
 
139
 *
 
140
 * <note>Allocate call can fail if Cogl considers the internal
 
141
 * format to be incompatible with the format of its internal
 
142
 * atlases.</note>
 
143
 *
 
144
 * <note>The returned #CoglAtlasTexture is a high-level meta-texture
 
145
 * with some limitations. See the documentation for #CoglMetaTexture
 
146
 * for more details.</note>
 
147
 *
 
148
 * Return value: (transfer full): A new #CoglAtlasTexture object or
 
149
 *          %NULL on failure and @error will be updated.
 
150
 * Since: 1.16
 
151
 * Stability: unstable
 
152
 */
 
153
CoglAtlasTexture *
 
154
cogl_atlas_texture_new_from_file (CoglContext *ctx,
 
155
                                  const char *filename,
 
156
                                  CoglError **error);
 
157
 
 
158
/**
 
159
 * cogl_atlas_texture_new_from_data:
 
160
 * @ctx: A #CoglContext
 
161
 * @width: width of texture in pixels
 
162
 * @height: height of texture in pixels
 
163
 * @format: the #CoglPixelFormat the buffer is stored in in RAM
 
164
 * @rowstride: the memory offset in bytes between the start of each
 
165
 *    row in @data. A value of 0 will make Cogl automatically
 
166
 *    calculate @rowstride from @width and @format.
 
167
 * @data: pointer to the memory region where the source buffer resides
 
168
 * @error: A #CoglError to catch exceptional errors or %NULL
 
169
 *
 
170
 * Creates a new #CoglAtlasTexture texture based on data residing in
 
171
 * memory. A #CoglAtlasTexture represents a sub-region within one of
 
172
 * Cogl's shared texture atlases.
 
173
 *
 
174
 * <note>This api will always immediately allocate GPU memory for the
 
175
 * texture and upload the given data so that the @data pointer does
 
176
 * not need to remain valid once this function returns. This means it
 
177
 * is not possible to configure the texture before it is allocated. If
 
178
 * you do need to configure the texture before allocation (to specify
 
179
 * constraints on the internal format for example) then you can
 
180
 * instead create a #CoglBitmap for your data and use
 
181
 * cogl_atlas_texture_new_from_bitmap() or use
 
182
 * cogl_atlas_texture_new_with_size() and then upload data using
 
183
 * cogl_texture_set_data()</note>
 
184
 *
 
185
 * <note>Allocate call can fail if Cogl considers the internal
 
186
 * format to be incompatible with the format of its internal
 
187
 * atlases.</note>
 
188
 *
 
189
 * <note>The returned #CoglAtlasTexture is a high-level
 
190
 * meta-texture with some limitations. See the documentation for
 
191
 * #CoglMetaTexture for more details.</note>
 
192
 *
 
193
 * Return value: (transfer full): A new #CoglAtlasTexture object or
 
194
 *          %NULL on failure and @error will be updated.
 
195
 * Since: 1.16
 
196
 * Stability: unstable
 
197
 */
 
198
CoglAtlasTexture *
 
199
cogl_atlas_texture_new_from_data (CoglContext *ctx,
 
200
                                  int width,
 
201
                                  int height,
 
202
                                  CoglPixelFormat format,
 
203
                                  int rowstride,
 
204
                                  const uint8_t *data,
 
205
                                  CoglError **error);
 
206
 
 
207
/**
 
208
 * cogl_atlas_texture_new_from_bitmap:
 
209
 * @bitmap: A #CoglBitmap
 
210
 *
 
211
 * Creates a new #CoglAtlasTexture texture based on data residing in a
 
212
 * @bitmap. A #CoglAtlasTexture represents a sub-region within one of
 
213
 * Cogl's shared texture atlases.
 
214
 *
 
215
 * The storage for the texture is not allocated before this function
 
216
 * returns. You can call cogl_texture_allocate() to explicitly
 
217
 * allocate the underlying storage or preferably let Cogl
 
218
 * automatically allocate storage lazily when it may know more about
 
219
 * how the texture is being used and can optimize how it is allocated.
 
220
 *
 
221
 * The texture is still configurable until it has been allocated so
 
222
 * for example you can influence the internal format of the texture
 
223
 * using cogl_texture_set_components() and
 
224
 * cogl_texture_set_premultiplied().
 
225
 *
 
226
 * <note>Allocate call can fail if Cogl considers the internal
 
227
 * format to be incompatible with the format of its internal
 
228
 * atlases.</note>
 
229
 *
 
230
 * <note>The returned #CoglAtlasTexture is a high-level meta-texture
 
231
 * with some limitations. See the documentation for #CoglMetaTexture
 
232
 * for more details.</note>
 
233
 *
 
234
 * Returns: (transfer full): A new #CoglAtlasTexture object.
 
235
 * Since: 1.16
 
236
 * Stability: unstable
 
237
 */
 
238
CoglAtlasTexture *
 
239
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp);
 
240
 
 
241
/**
 
242
 * cogl_is_atlas_texture:
 
243
 * @object: a #CoglObject
 
244
 *
 
245
 * Checks whether the given object references a #CoglAtlasTexture
 
246
 *
 
247
 * Return value: %TRUE if the passed object represents an atlas
 
248
 *   texture and %FALSE otherwise
 
249
 *
 
250
 * Since: 1.16
 
251
 * Stability: Unstable
 
252
 */
 
253
CoglBool
 
254
cogl_is_atlas_texture (void *object);
 
255
 
 
256
COGL_END_DECLS
 
257
 
 
258
#endif /* _COGL_ATLAS_TEXTURE_H_ */