summaryrefslogtreecommitdiff
path: root/cogl/cogl-texture-rectangle.h
blob: 761968608c6fc5b55562b96ef4b15cc9111ff795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * Cogl
 *
 * A Low Level GPU Graphics and Utilities API
 *
 * Copyright (C) 2011 Intel Corporation.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *
 * Authors:
 *   Robert Bragg <robert@linux.intel.com>
 */

#ifndef __COGL_TEXURE_RECTANGLE_H
#define __COGL_TEXURE_RECTANGLE_H

#include "cogl-context.h"

COGL_BEGIN_DECLS

/**
 * SECTION:cogl-texture-rectangle
 * @short_description: Functions for creating and manipulating rectangle
 *                     textures for use with non-normalized coordinates.
 *
 * These functions allow low-level "rectangle" textures to be allocated.
 * These textures are never constrained to power-of-two sizes but they
 * also don't support having a mipmap and can only be wrapped with
 * %COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE.
 *
 * The most notable difference between rectangle textures and 2D
 * textures is that rectangle textures are sampled using un-normalized
 * texture coordinates, so instead of using coordinates (0,0) and
 * (1,1) to map to the top-left and bottom right corners of the
 * texture you would instead use (0,0) and (width,height).
 *
 * The use of non-normalized coordinates can be particularly
 * convenient when writing glsl shaders that use a texture as a lookup
 * table since you don't need to upload separate uniforms to map
 * normalized coordinates to texels.
 *
 * If you want to sample from a rectangle texture from GLSL you should
 * use the sampler2DRect sampler type.
 *
 * Applications wanting to use #CoglTextureRectangle should first check
 * for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature using
 * cogl_has_feature().
 */

typedef struct _CoglTextureRectangle CoglTextureRectangle;
#define COGL_TEXTURE_RECTANGLE(X) ((CoglTextureRectangle *)X)

#ifdef COGL_HAS_GTYPE_SUPPORT
/**
 * cogl_texture_rectangle_get_gtype:
 *
 * Returns: a #GType that can be used with the GLib type system.
 */
GType cogl_texture_rectangle_get_gtype (void);
#endif

/**
 * cogl_is_texture_rectangle:
 * @object: A #CoglObject
 *
 * Gets whether the given object references an existing
 * #CoglTextureRectangle object.
 *
 * Return value: %TRUE if the object references a
 *               #CoglTextureRectangle, %FALSE otherwise.
 */
CoglBool
cogl_is_texture_rectangle (void *object);

/**
 * cogl_texture_rectangle_new_with_size:
 * @ctx: A #CoglContext pointer
 * @width: The texture width to allocate
 * @height: The texture height to allocate
 *
 * Creates a new #CoglTextureRectangle texture with a given @width,
 * and @height. This texture is a low-level texture that the GPU can
 * sample from directly unlike high-level textures such as
 * #CoglTexture2DSliced and #CoglAtlasTexture.
 *
 * <note>Unlike for #CoglTexture2D textures, coordinates for
 * #CoglTextureRectangle textures should not be normalized. So instead
 * of using the coordinate (1, 1) to sample the bottom right corner of
 * a rectangle texture you would use (@width, @height) where @width
 * and @height are the width and height of the texture.</note>
 *
 * <note>If you want to sample from a rectangle texture from GLSL you
 * should use the sampler2DRect sampler type.</note>
 *
 * <note>Applications wanting to use #CoglTextureRectangle should
 * first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
 * using cogl_has_feature().</note>
 *
 * The storage for the texture is not allocated before this function
 * returns. You can call cogl_texture_allocate() to explicitly
 * allocate the underlying storage or preferably let Cogl
 * automatically allocate storage lazily when it may know more about
 * how the texture is going to be used and can optimize how it is
 * allocated.
 *
 * Returns value: (transfer full): A pointer to a new #CoglTextureRectangle
 *          object with no storage allocated yet.
 *
 * Since: 1.10
 * Stability: unstable
 */
CoglTextureRectangle *
cogl_texture_rectangle_new_with_size (CoglContext *ctx,
                                      int width,
                                      int height);

/**
 * cogl_texture_rectangle_new_from_bitmap:
 * @bitmap: A #CoglBitmap
 *
 * Allocates a new #CoglTextureRectangle texture which will be
 * initialized with the pixel data from @bitmap. This texture is a
 * low-level texture that the GPU can sample from directly unlike
 * high-level textures such as #CoglTexture2DSliced and
 * #CoglAtlasTexture.
 *
 * <note>Unlike for #CoglTexture2D textures, coordinates for
 * #CoglTextureRectangle textures should not be normalized. So instead
 * of using the coordinate (1, 1) to sample the bottom right corner of
 * a rectangle texture you would use (@width, @height) where @width
 * and @height are the width and height of the texture.</note>
 *
 * <note>If you want to sample from a rectangle texture from GLSL you
 * should use the sampler2DRect sampler type.</note>
 *
 * <note>Applications wanting to use #CoglTextureRectangle should
 * first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
 * using cogl_has_feature().</note>
 *
 * The storage for the texture is not allocated before this function
 * returns. You can call cogl_texture_allocate() to explicitly
 * allocate the underlying storage or preferably let Cogl
 * automatically allocate storage lazily when it may know more about
 * how the texture is going to be used and can optimize how it is
 * allocated.
 *
 * Return value: (transfer full): A pointer to a new
 *               #CoglTextureRectangle texture.
 * Since: 2.0
 * Stability: unstable
 */
CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap);

/**
 * cogl_texture_rectangle_new_from_foreign:
 * @ctx: A #CoglContext
 * @gl_handle: A GL handle for a GL_TEXTURE_RECTANGLE texture object
 * @width: Width of the foreign GL texture
 * @height: Height of the foreign GL texture
 * @format: The format of the texture
 *
 * Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
 * #CoglTextureRectangle.  This can be used for integrating Cogl with
 * software using OpenGL directly.
 *
 * <note>Unlike for #CoglTexture2D textures, coordinates for
 * #CoglTextureRectangle textures should not be normalized. So instead
 * of using the coordinate (1, 1) to sample the bottom right corner of
 * a rectangle texture you would use (@width, @height) where @width
 * and @height are the width and height of the texture.</note>
 *
 * <note>The results are undefined for passing an invalid @gl_handle
 * or if @width or @height don't have the correct texture
 * geometry.</note>
 *
 * <note>If you want to sample from a rectangle texture from GLSL you
 * should use the sampler2DRect sampler type.</note>
 *
 * <note>Applications wanting to use #CoglTextureRectangle should
 * first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
 * using cogl_has_feature().</note>
 *
 * The texture is still configurable until it has been allocated so
 * for example you can declare whether the texture is premultiplied
 * with cogl_texture_set_premultiplied().
 *
 * Return value: (transfer full): A new #CoglTextureRectangle texture
 */
CoglTextureRectangle *
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
                                         unsigned int gl_handle,
                                         int width,
                                         int height,
                                         CoglPixelFormat format);

COGL_END_DECLS

#endif /* __COGL_TEXURE_RECTANGLE_H */