4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2007,2008,2009 Intel Corporation.
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.
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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef __COGL_TEXTURE_PRIVATE_H
25 #define __COGL_TEXTURE_PRIVATE_H
27 #include "cogl-bitmap-private.h"
28 #include "cogl-handle.h"
29 #include "cogl-pipeline-private.h"
30 #include "cogl-spans.h"
31 #include "cogl-meta-texture.h"
32 #include "cogl-framebuffer.h"
34 typedef struct _CoglTextureVtable CoglTextureVtable;
36 /* Encodes three possibiloities result of transforming a quad */
38 /* quad doesn't cross the boundaries of a texture */
39 COGL_TRANSFORM_NO_REPEAT,
40 /* quad crosses boundaries, hardware wrap mode can handle */
41 COGL_TRANSFORM_HARDWARE_REPEAT,
42 /* quad crosses boundaries, needs software fallback;
43 * for a sliced texture, this might not actually involve
44 * repeating, just a quad crossing multiple slices */
45 COGL_TRANSFORM_SOFTWARE_REPEAT,
46 } CoglTransformResult;
48 /* Flags given to the pre_paint method */
50 /* The texture is going to be used with filters that require
51 mipmapping. This gives the texture the opportunity to
52 automatically update the mipmap tree */
53 COGL_TEXTURE_NEEDS_MIPMAP = 1
54 } CoglTexturePrePaintFlags;
56 struct _CoglTextureVtable
58 /* Virtual functions that must be implemented for a texture
61 /* This should update the specified sub region of the texture with a
62 sub region of the given bitmap. The bitmap is not converted
63 before being passed so the implementation is expected to call
64 _cogl_texture_prepare_for_upload with a suitable destination
65 format before uploading */
66 gboolean (* set_region) (CoglTexture *tex,
71 unsigned int dst_width,
72 unsigned int dst_height,
75 /* This should copy the image data of the texture into @data. The
76 requested format will have been first passed through
77 ctx->texture_driver->find_best_gl_get_data_format so it should
78 always be a format that is valid for GL (ie, no conversion should
80 gboolean (* get_data) (CoglTexture *tex,
81 CoglPixelFormat format,
82 unsigned int rowstride,
85 void (* foreach_sub_texture_in_region) (CoglTexture *tex,
90 CoglMetaTextureCallback callback,
93 int (* get_max_waste) (CoglTexture *tex);
95 gboolean (* is_sliced) (CoglTexture *tex);
97 gboolean (* can_hardware_repeat) (CoglTexture *tex);
99 void (* transform_coords_to_gl) (CoglTexture *tex,
102 CoglTransformResult (* transform_quad_coords_to_gl) (CoglTexture *tex,
105 gboolean (* get_gl_texture) (CoglTexture *tex,
106 GLuint *out_gl_handle,
107 GLenum *out_gl_target);
109 void (* set_filters) (CoglTexture *tex,
113 void (* pre_paint) (CoglTexture *tex, CoglTexturePrePaintFlags flags);
114 void (* ensure_non_quad_rendering) (CoglTexture *tex);
116 void (* set_wrap_mode_parameters) (CoglTexture *tex,
121 CoglPixelFormat (* get_format) (CoglTexture *tex);
122 GLenum (* get_gl_format) (CoglTexture *tex);
123 int (* get_width) (CoglTexture *tex);
124 int (* get_height) (CoglTexture *tex);
126 CoglTextureType (* get_type) (CoglTexture *tex);
128 gboolean (* is_foreign) (CoglTexture *tex);
135 const CoglTextureVtable *vtable;
138 typedef enum _CoglTextureChangeFlags
140 /* Whenever the internals of a texture are changed such that the
141 * underlying GL textures that represent the CoglTexture change then
142 * we notify cogl-material.c via
143 * _cogl_pipeline_texture_pre_change_notify
145 COGL_TEXTURE_CHANGE_GL_TEXTURES
147 } CoglTextureChangeFlags;
149 typedef struct _CoglTexturePixel CoglTexturePixel;
151 /* This is used by the texture backends to store the first pixel of
152 each GL texture. This is only used when glGenerateMipmap is not
153 available so that we can temporarily set GL_GENERATE_MIPMAP and
155 struct _CoglTexturePixel
157 /* We need to store the format of the pixel because we store the
158 data in the source format which might end up being different for
159 each slice if a subregion is updated with a different format */
166 _cogl_texture_init (CoglTexture *texture,
167 const CoglTextureVtable *vtable);
170 _cogl_texture_free (CoglTexture *texture);
172 /* This is used to register a type to the list of handle types that
173 will be considered a texture in cogl_is_texture() */
175 _cogl_texture_register_texture_type (const CoglObjectClass *klass);
177 #define COGL_TEXTURE_DEFINE(TypeName, type_name) \
178 COGL_HANDLE_DEFINE_WITH_CODE \
179 (TypeName, type_name, \
180 _cogl_texture_register_texture_type (&_cogl_##type_name##_class))
182 #define COGL_TEXTURE_INTERNAL_DEFINE(TypeName, type_name) \
183 COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE \
184 (TypeName, type_name, \
185 _cogl_texture_register_texture_type (&_cogl_##type_name##_class))
188 _cogl_texture_can_hardware_repeat (CoglTexture *texture);
191 _cogl_texture_transform_coords_to_gl (CoglTexture *texture,
195 _cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture,
199 _cogl_texture_get_gl_format (CoglTexture *texture);
202 _cogl_texture_set_wrap_mode_parameters (CoglTexture *texture,
209 _cogl_texture_set_filters (CoglTexture *texture,
214 _cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags);
217 _cogl_texture_ensure_non_quad_rendering (CoglTexture *texture);
219 /* Utility function to determine which pixel format to use when
220 dst_format is COGL_PIXEL_FORMAT_ANY. If dst_format is not ANY then
221 it will just be returned directly */
223 _cogl_texture_determine_internal_format (CoglPixelFormat src_format,
224 CoglPixelFormat dst_format);
226 /* Utility function to help uploading a bitmap. If the bitmap needs
227 premult conversion then it will be copied and *copied_bitmap will
228 be set to TRUE. Otherwise dst_bmp will be set to a shallow copy of
229 src_bmp. The GLenums needed for uploading are returned */
232 _cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
233 CoglPixelFormat dst_format,
234 CoglPixelFormat *dst_format_out,
235 GLenum *out_glintformat,
236 GLenum *out_glformat,
240 _cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride);
243 _cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride);
245 /* Utility function to use as a fallback for getting the data of any
246 texture via the framebuffer */
249 _cogl_texture_draw_and_read (CoglTexture *texture,
250 CoglBitmap *target_bmp,
251 GLuint target_gl_format,
252 GLuint target_gl_type);
255 _cogl_texture_is_foreign (CoglTexture *texture);
258 _cogl_texture_associate_framebuffer (CoglTexture *texture,
259 CoglFramebuffer *framebuffer);
262 _cogl_texture_get_associated_framebuffers (CoglTexture *texture);
265 _cogl_texture_flush_journal_rendering (CoglTexture *texture);
268 _cogl_texture_spans_foreach_in_region (CoglSpan *x_spans,
272 CoglTexture **textures,
273 float *virtual_coords,
274 float x_normalize_factor,
275 float y_normalize_factor,
276 CoglPipelineWrapMode wrap_x,
277 CoglPipelineWrapMode wrap_y,
278 CoglMetaTextureCallback callback,
282 * _cogl_texture_get_type:
283 * @texture: a #CoglTexture pointer
285 * Retrieves the texture type of the underlying hardware texture that
286 * this #CoglTexture will use.
288 * Return value: The type of the hardware texture.
291 _cogl_texture_get_type (CoglTexture *texture);
293 #endif /* __COGL_TEXTURE_PRIVATE_H */