~elementary-os/elementaryos/os-patch-mutter-bionic

« back to all changes in this revision

Viewing changes to cogl/cogl/cogl-texture-2d.h

  • Committer: RabbitBot
  • Date: 2018-04-11 14:49:36 UTC
  • Revision ID: rabbitbot@elementary.io-20180411144936-hgymqa9d8d1xfpbh
Initial import, version 3.28.0-2

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) 2011,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
 * Authors:
 
30
 *   Robert Bragg <robert@linux.intel.com>
 
31
 */
 
32
 
 
33
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
 
34
#error "Only <cogl/cogl.h> can be included directly."
 
35
#endif
 
36
 
 
37
#ifndef __COGL_TEXTURE_2D_H
 
38
#define __COGL_TEXTURE_2D_H
 
39
 
 
40
#include "cogl-context.h"
 
41
#include "cogl-bitmap.h"
 
42
 
 
43
#ifdef COGL_HAS_EGL_SUPPORT
 
44
#include "cogl-egl-defines.h"
 
45
#endif
 
46
 
 
47
COGL_BEGIN_DECLS
 
48
 
 
49
/**
 
50
 * SECTION:cogl-texture-2d
 
51
 * @short_description: Functions for creating and manipulating 2D textures
 
52
 *
 
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
 
57
 * by the GPU.
 
58
 *
 
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().
 
63
 */
 
64
 
 
65
typedef struct _CoglTexture2D CoglTexture2D;
 
66
#define COGL_TEXTURE_2D(X) ((CoglTexture2D *)X)
 
67
 
 
68
/**
 
69
 * cogl_texture_2d_get_gtype:
 
70
 *
 
71
 * Returns: a #GType that can be used with the GLib type system.
 
72
 */
 
73
GType cogl_texture_2d_get_gtype (void);
 
74
 
 
75
/**
 
76
 * cogl_is_texture_2d:
 
77
 * @object: A #CoglObject
 
78
 *
 
79
 * Gets whether the given object references an existing #CoglTexture2D
 
80
 * object.
 
81
 *
 
82
 * Return value: %TRUE if the object references a #CoglTexture2D,
 
83
 *   %FALSE otherwise
 
84
 */
 
85
CoglBool
 
86
cogl_is_texture_2d (void *object);
 
87
 
 
88
/**
 
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
 
93
 *
 
94
 * Creates a low-level #CoglTexture2D texture with a given @width and
 
95
 * @height that your GPU can texture from directly.
 
96
 *
 
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.
 
102
 *
 
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().
 
107
 *
 
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>
 
112
 *
 
113
 * Returns: (transfer full): A new #CoglTexture2D object with no storage yet allocated.
 
114
 *
 
115
 * Since: 2.0
 
116
 */
 
117
CoglTexture2D *
 
118
cogl_texture_2d_new_with_size (CoglContext *ctx,
 
119
                               int width,
 
120
                               int height);
 
121
 
 
122
/**
 
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
 
127
 *
 
128
 * Creates a low-level #CoglTexture2D texture from an image file.
 
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 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.
 
135
 *
 
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().
 
140
 *
 
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>
 
145
 *
 
146
 * Return value: (transfer full): A newly created #CoglTexture2D or %NULL on failure
 
147
 *               and @error will be updated.
 
148
 *
 
149
 * Since: 1.16
 
150
 */
 
151
CoglTexture2D *
 
152
cogl_texture_2d_new_from_file (CoglContext *ctx,
 
153
                               const char *filename,
 
154
                               CoglError **error);
 
155
 
 
156
/**
 
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
 
167
 *
 
168
 * Creates a low-level #CoglTexture2D texture based on data residing
 
169
 * in memory.
 
170
 *
 
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>
 
181
 *
 
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>
 
186
 *
 
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.
 
191
 *
 
192
 * Since: 2.0
 
193
 */
 
194
CoglTexture2D *
 
195
cogl_texture_2d_new_from_data (CoglContext *ctx,
 
196
                               int width,
 
197
                               int height,
 
198
                               CoglPixelFormat format,
 
199
                               int rowstride,
 
200
                               const uint8_t *data,
 
201
                               CoglError **error);
 
202
 
 
203
/**
 
204
 * cogl_texture_2d_new_from_bitmap:
 
205
 * @bitmap: A #CoglBitmap
 
206
 *
 
207
 * Creates a low-level #CoglTexture2D texture based on data residing
 
208
 * in a #CoglBitmap.
 
209
 *
 
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.
 
215
 *
 
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().
 
220
 *
 
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>
 
225
 *
 
226
 * Returns: (transfer full): A newly allocated #CoglTexture2D
 
227
 *
 
228
 * Since: 2.0
 
229
 * Stability: unstable
 
230
 */
 
231
CoglTexture2D *
 
232
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
 
233
 
 
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. */
 
238
CoglTexture2D *
 
239
cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
 
240
                                    int width,
 
241
                                    int height,
 
242
                                    CoglPixelFormat format,
 
243
                                    EGLImageKHR image,
 
244
                                    CoglError **error);
 
245
 
 
246
typedef gboolean (*CoglTexture2DEGLImageExternalAlloc) (CoglTexture2D *tex_2d,
 
247
                                                        gpointer user_data,
 
248
                                                        GError **error);
 
249
 
 
250
CoglTexture2D *
 
251
cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx,
 
252
                                             int width,
 
253
                                             int height,
 
254
                                             CoglTexture2DEGLImageExternalAlloc alloc,
 
255
                                             gpointer user_data,
 
256
                                             GDestroyNotify destroy,
 
257
                                             CoglError **error);
 
258
 
 
259
void
 
260
cogl_texture_2d_egl_image_external_bind (CoglTexture2D *tex_2d);
 
261
 
 
262
void
 
263
cogl_texture_2d_egl_image_external_alloc_finish (CoglTexture2D *tex_2d,
 
264
                                                 void *user_data,
 
265
                                                 GDestroyNotify destroy);
 
266
#endif
 
267
 
 
268
COGL_END_DECLS
 
269
 
 
270
#endif /* __COGL_TEXTURE_2D_H */