4
* A Low Level GPU Graphics and Utilities API
6
* Copyright (C) 2011,2013 Intel Corporation.
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:
16
* The above copyright notice and this permission notice shall be
17
* included in all copies or substantial portions of the Software.
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
30
* Robert Bragg <robert@linux.intel.com>
33
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
34
#error "Only <cogl/cogl.h> can be included directly."
37
#ifndef __COGL_TEXTURE_2D_H
38
#define __COGL_TEXTURE_2D_H
40
#include "cogl-context.h"
41
#include "cogl-bitmap.h"
43
#ifdef COGL_HAS_EGL_SUPPORT
44
#include "cogl-egl-defines.h"
50
* SECTION:cogl-texture-2d
51
* @short_description: Functions for creating and manipulating 2D textures
53
* These functions allow low-level 2D textures to be allocated. These
54
* differ from sliced textures for example which may internally be
55
* made up of multiple 2D textures, or atlas textures where Cogl must
56
* internally modify user texture coordinates before they can be used
59
* You should be aware that many GPUs only support power of two sizes
60
* for #CoglTexture2D textures. You can check support for non power of
61
* two textures by checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature
62
* via cogl_has_feature().
65
typedef struct _CoglTexture2D CoglTexture2D;
66
#define COGL_TEXTURE_2D(X) ((CoglTexture2D *)X)
69
* cogl_texture_2d_get_gtype:
71
* Returns: a #GType that can be used with the GLib type system.
73
GType cogl_texture_2d_get_gtype (void);
77
* @object: A #CoglObject
79
* Gets whether the given object references an existing #CoglTexture2D
82
* Return value: %TRUE if the object references a #CoglTexture2D,
86
cogl_is_texture_2d (void *object);
89
* cogl_texture_2d_new_with_size:
90
* @ctx: A #CoglContext
91
* @width: Width of the texture to allocate
92
* @height: Height of the texture to allocate
94
* Creates a low-level #CoglTexture2D texture with a given @width and
95
* @height that your GPU can texture from directly.
97
* The storage for the texture is not allocated before this function
98
* returns. You can call cogl_texture_allocate() to explicitly
99
* allocate the underlying storage or preferably let Cogl
100
* automatically allocate storage lazily when it may know more about
101
* how the texture is being used and can optimize how it is allocated.
103
* The texture is still configurable until it has been allocated so
104
* for example you can influence the internal format of the texture
105
* using cogl_texture_set_components() and
106
* cogl_texture_set_premultiplied().
108
* <note>Many GPUs only support power of two sizes for #CoglTexture2D
109
* textures. You can check support for non power of two textures by
110
* checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
111
* cogl_has_feature().</note>
113
* Returns: (transfer full): A new #CoglTexture2D object with no storage yet allocated.
118
cogl_texture_2d_new_with_size (CoglContext *ctx,
123
* cogl_texture_2d_new_from_file:
124
* @ctx: A #CoglContext
125
* @filename: the file to load
126
* @error: A #CoglError to catch exceptional errors or %NULL
128
* Creates a low-level #CoglTexture2D texture from an image file.
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 preferably let Cogl
133
* automatically allocate storage lazily when it may know more about
134
* how the texture is being used and can optimize how it is allocated.
136
* The texture is still configurable until it has been allocated so
137
* for example you can influence the internal format of the texture
138
* using cogl_texture_set_components() and
139
* cogl_texture_set_premultiplied().
141
* <note>Many GPUs only support power of two sizes for #CoglTexture2D
142
* textures. You can check support for non power of two textures by
143
* checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
144
* cogl_has_feature().</note>
146
* Return value: (transfer full): A newly created #CoglTexture2D or %NULL on failure
147
* and @error will be updated.
152
cogl_texture_2d_new_from_file (CoglContext *ctx,
153
const char *filename,
157
* cogl_texture_2d_new_from_data:
158
* @ctx: A #CoglContext
159
* @width: width of texture in pixels
160
* @height: height of texture in pixels
161
* @format: the #CoglPixelFormat the buffer is stored in in RAM
162
* @rowstride: the memory offset in bytes between the starts of
163
* scanlines in @data. A value of 0 will make Cogl automatically
164
* calculate @rowstride from @width and @format.
165
* @data: pointer the memory region where the source buffer resides
166
* @error: A #CoglError for exceptions
168
* Creates a low-level #CoglTexture2D texture based on data residing
171
* <note>This api will always immediately allocate GPU memory for the
172
* texture and upload the given data so that the @data pointer does
173
* not need to remain valid once this function returns. This means it
174
* is not possible to configure the texture before it is allocated. If
175
* you do need to configure the texture before allocation (to specify
176
* constraints on the internal format for example) then you can
177
* instead create a #CoglBitmap for your data and use
178
* cogl_texture_2d_new_from_bitmap() or use
179
* cogl_texture_2d_new_with_size() and then upload data using
180
* cogl_texture_set_data()</note>
182
* <note>Many GPUs only support power of two sizes for #CoglTexture2D
183
* textures. You can check support for non power of two textures by
184
* checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
185
* cogl_has_feature().</note>
187
* Returns: (transfer full): A newly allocated #CoglTexture2D, or if
188
* the size is not supported (because it is too large or a
189
* non-power-of-two size that the hardware doesn't support)
190
* it will return %NULL and set @error.
195
cogl_texture_2d_new_from_data (CoglContext *ctx,
198
CoglPixelFormat format,
204
* cogl_texture_2d_new_from_bitmap:
205
* @bitmap: A #CoglBitmap
207
* Creates a low-level #CoglTexture2D texture based on data residing
210
* The storage for the texture is not allocated before this function
211
* returns. You can call cogl_texture_allocate() to explicitly
212
* allocate the underlying storage or preferably let Cogl
213
* automatically allocate storage lazily when it may know more about
214
* how the texture is being used and can optimize how it is allocated.
216
* The texture is still configurable until it has been allocated so
217
* for example you can influence the internal format of the texture
218
* using cogl_texture_set_components() and
219
* cogl_texture_set_premultiplied().
221
* <note>Many GPUs only support power of two sizes for #CoglTexture2D
222
* textures. You can check support for non power of two textures by
223
* checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
224
* cogl_has_feature().</note>
226
* Returns: (transfer full): A newly allocated #CoglTexture2D
229
* Stability: unstable
232
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
234
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
235
/* NB: The reason we require the width, height and format to be passed
236
* even though they may seem redundant is because GLES 1/2 don't
237
* provide a way to query these properties. */
239
cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
242
CoglPixelFormat format,
246
typedef gboolean (*CoglTexture2DEGLImageExternalAlloc) (CoglTexture2D *tex_2d,
251
cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx,
254
CoglTexture2DEGLImageExternalAlloc alloc,
256
GDestroyNotify destroy,
260
cogl_texture_2d_egl_image_external_bind (CoglTexture2D *tex_2d);
263
cogl_texture_2d_egl_image_external_alloc_finish (CoglTexture2D *tex_2d,
265
GDestroyNotify destroy);
270
#endif /* __COGL_TEXTURE_2D_H */