"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-texture-2d.h
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2011 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
20  * <http://www.gnu.org/licenses/>.
21  *
22  *
23  * Authors:
24  *   Robert Bragg <robert@linux.intel.com>
25  */
26
27 #if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
28 #error "Only <cogl/cogl.h> can be included directly."
29 #endif
30
31 #ifndef __COGL_TEXURE_2D_H
32 #define __COGL_TEXURE_2D_H
33
34 #include "cogl-context.h"
35
36 #include <glib.h>
37
38 G_BEGIN_DECLS
39
40 /**
41  * SECTION:cogl-texture-2d
42  * @short_description: Functions for creating and manipulating 2D textures
43  *
44  * These functions allow low-level 2D textures to be allocated. These
45  * differ from sliced textures for example which may internally be
46  * made up of multiple 2D textures, or atlas textures where Cogl must
47  * internally modify user texture coordinates before they can be used
48  * by the GPU.
49  *
50  * You should be aware that many GPUs only support power of two sizes
51  * for #CoglTexture2D textures. You can check support for non power of
52  * two textures by checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature
53  * via cogl_has_feature().
54  */
55
56 typedef struct _CoglTexture2D CoglTexture2D;
57 #define COGL_TEXTURE_2D(X) ((CoglTexture2D *)X)
58
59 #define cogl_is_texture_2d cogl_is_texture_2d_EXP
60 /**
61  * cogl_is_texture_2d:
62  * @object: A #CoglObject
63  *
64  * Gets whether the given object references an existing #CoglTexture2D
65  * object.
66  *
67  * Return value: %TRUE if the object references a #CoglTexture2D,
68  *   %FALSE otherwise
69  */
70 gboolean
71 cogl_is_texture_2d (void *object);
72
73 #define cogl_texture_2d_new_with_size cogl_texture_2d_new_with_size_EXP
74 /**
75  * cogl_texture_2d_new_with_size:
76  * @ctx: A #CoglContext
77  * @width: Width of the texture to allocate
78  * @height: Height of the texture to allocate
79  * @internal_format: The format of the texture
80  * @error: A #GError for exceptions
81  *
82  * Allocates a low-level #CoglTexture2D texture that your GPU can
83  * texture from directly. This is unlike sliced textures for example
84  * which may be comprised of multiple internal textures, or atlas
85  * textures where Cogl has to modify texture coordinates before they
86  * may be used by the GPU.
87  *
88  * <note>Many GPUs only support power of two sizes for #CoglTexture2D
89  * textures. You can check support for non power of two textures by
90  * checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
91  * cogl_has_feature().</note>
92  *
93  * Returns: A newly allocated #CoglTexture2D, or if the size is not
94  *          supported (because it is too large or a non-power-of-two
95  *          size that the hardware doesn't support) it will return
96  *          %NULL and set @error.
97  *
98  * Since: 2.0
99  */
100 CoglTexture2D *
101 cogl_texture_2d_new_with_size (CoglContext *ctx,
102                                int width,
103                                int height,
104                                CoglPixelFormat internal_format,
105                                GError **error);
106
107 #define cogl_texture_2d_new_from_data cogl_texture_2d_new_from_data_EXP
108 /**
109  * cogl_texture_2d_new_from_data:
110  * @ctx: A #CoglContext
111  * @width: width of texture in pixels
112  * @height: height of texture in pixels
113  * @format: the #CoglPixelFormat the buffer is stored in in RAM
114  * @internal_format: the #CoglPixelFormat that will be used for storing
115  *    the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
116  *    premultiplied format similar to the format of the source data will
117  *    be used. The default blending equations of Cogl expect premultiplied
118  *    color data; the main use of passing a non-premultiplied format here
119  *    is if you have non-premultiplied source data and are going to adjust
120  *    the blend mode (see cogl_material_set_blend()) or use the data for
121  *    something other than straight blending.
122  * @rowstride: the memory offset in bytes between the starts of
123  *    scanlines in @data. A value of 0 will make Cogl automatically
124  *    calculate @rowstride from @width and @format.
125  * @data: pointer the memory region where the source buffer resides
126  * @error: A #GError for exceptions
127  *
128  * Creates a new #CoglTexture2D texture based on data residing in memory.
129  * These are unlike sliced textures for example which may be comprised
130  * of multiple internal textures, or atlas textures where Cogl has to
131  * modify texture coordinates before they may be used by the GPU.
132  *
133  * <note>Many GPUs only support power of two sizes for #CoglTexture2D
134  * textures. You can check support for non power of two textures by
135  * checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
136  * cogl_has_feature().</note>
137  *
138  * Returns: A newly allocated #CoglTexture2D, or if the size is not
139  *          supported (because it is too large or a non-power-of-two
140  *          size that the hardware doesn't support) it will return
141  *          %NULL and set @error.
142  *
143  * Since: 2.0
144  */
145 CoglTexture2D *
146 cogl_texture_2d_new_from_data (CoglContext *ctx,
147                                int width,
148                                int height,
149                                CoglPixelFormat format,
150                                CoglPixelFormat internal_format,
151                                int rowstride,
152                                const guint8 *data,
153                                GError **error);
154
155 #define cogl_texture_2d_new_from_foreign cogl_texture_2d_new_from_foreign_EXP
156 /**
157  * cogl_texture_2d_new_from_foreign:
158  * @ctx: A #CoglContext
159  * @gl_handle: A GL handle for a GL_TEXTURE_2D texture object
160  * @width: Width of the foreign GL texture
161  * @height: Height of the foreign GL texture
162  * @internal_format: The format of the texture
163  * @error: A #GError for exceptions
164  *
165  * Wraps an existing GL_TEXTURE_2D texture object as a #CoglTexture2D.
166  * This can be used for integrating Cogl with software using OpenGL
167  * directly.
168  *
169  * <note>The results are undefined for passing an invalid @gl_handle
170  * or if @width or @height don't have the correct texture
171  * geometry.</note>
172  *
173  * Returns: A newly allocated #CoglTexture2D, or if Cogl could not
174  *          validate the @gl_handle in some way (perhaps because of
175  *          an unsupported format) it will return %NULL and set
176  *          @error.
177  *
178  * Since: 2.0
179  */
180 CoglTexture2D *
181 cogl_texture_2d_new_from_foreign (CoglContext *ctx,
182                                   unsigned int gl_handle,
183                                   int width,
184                                   int height,
185                                   CoglPixelFormat format,
186                                   GError **error);
187
188 G_END_DECLS
189
190 #endif /* __COGL_TEXURE_2D_H */