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-material-private.h"
31
#define COGL_TEXTURE(tex) ((CoglTexture *)(tex))
33
typedef struct _CoglTexture CoglTexture;
34
typedef struct _CoglTextureVtable CoglTextureVtable;
36
typedef void (*CoglTextureSliceCallback) (CoglHandle handle,
39
const float *slice_coords,
40
const float *virtual_coords,
43
typedef void (* CoglTextureManualRepeatCallback) (const float *coords,
46
/* Encodes three possibiloities result of transforming a quad */
48
/* quad doesn't cross the boundaries of a texture */
49
COGL_TRANSFORM_NO_REPEAT,
50
/* quad crosses boundaries, hardware wrap mode can handle */
51
COGL_TRANSFORM_HARDWARE_REPEAT,
52
/* quad crosses boundaries, needs software fallback;
53
* for a sliced texture, this might not actually involve
54
* repeating, just a quad crossing multiple slices */
55
COGL_TRANSFORM_SOFTWARE_REPEAT,
56
} CoglTransformResult;
58
struct _CoglTextureVtable
60
/* Virtual functions that must be implemented for a texture
63
gboolean (* set_region) (CoglTexture *tex,
68
unsigned int dst_width,
69
unsigned int dst_height,
72
CoglPixelFormat format,
73
unsigned int rowstride,
76
int (* get_data) (CoglTexture *tex,
77
CoglPixelFormat format,
78
unsigned int rowstride,
81
void (* foreach_sub_texture_in_region) (CoglTexture *tex,
86
CoglTextureSliceCallback callback,
89
int (* get_max_waste) (CoglTexture *tex);
91
gboolean (* is_sliced) (CoglTexture *tex);
93
gboolean (* can_hardware_repeat) (CoglTexture *tex);
95
void (* transform_coords_to_gl) (CoglTexture *tex,
98
CoglTransformResult (* transform_quad_coords_to_gl) (CoglTexture *tex,
101
gboolean (* get_gl_texture) (CoglTexture *tex,
102
GLuint *out_gl_handle,
103
GLenum *out_gl_target);
105
void (* set_filters) (CoglTexture *tex,
109
void (* ensure_mipmaps) (CoglTexture *tex);
110
void (* ensure_non_quad_rendering) (CoglTexture *tex);
112
void (* set_wrap_mode_parameter) (CoglTexture *tex,
115
CoglPixelFormat (* get_format) (CoglTexture *tex);
116
GLenum (* get_gl_format) (CoglTexture *tex);
117
int (* get_width) (CoglTexture *tex);
118
int (* get_height) (CoglTexture *tex);
123
CoglHandleObject _parent;
124
const CoglTextureVtable *vtable;
128
_cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
133
CoglTextureSliceCallback callback,
137
_cogl_texture_can_hardware_repeat (CoglHandle handle);
140
_cogl_texture_transform_coords_to_gl (CoglHandle handle,
144
_cogl_texture_transform_quad_coords_to_gl (CoglHandle handle,
148
_cogl_texture_get_gl_format (CoglHandle handle);
151
_cogl_texture_set_wrap_mode_parameter (CoglHandle handle,
155
_cogl_texture_set_filters (CoglHandle handle,
160
_cogl_texture_ensure_mipmaps (CoglHandle handle);
163
_cogl_texture_ensure_non_quad_rendering (CoglHandle handle);
165
/* Utility function to determine which pixel format to use when
166
dst_format is COGL_PIXEL_FORMAT_ANY. If dst_format is not ANY then
167
it will just be returned directly */
169
_cogl_texture_determine_internal_format (CoglPixelFormat src_format,
170
CoglPixelFormat dst_format);
172
/* Utility function to help uploading a bitmap. If the bitmap needs
173
premult conversion then it will be copied and *copied_bitmap will
174
be set to TRUE. Otherwise dst_bmp will be set to a shallow copy of
175
src_bmp. The GLenums needed for uploading are returned */
178
_cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
179
CoglPixelFormat dst_format,
180
CoglPixelFormat *dst_format_out,
182
gboolean *copied_bitmap,
183
GLenum *out_glintformat,
184
GLenum *out_glformat,
188
_cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride);
191
_cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride);
193
/* Utility function for implementing manual repeating. Even texture
194
backends that always support hardware repeating need this because
195
when foreach_sub_texture_in_region is invoked Cogl will set the
196
wrap mode to GL_CLAMP_TO_EDGE so hardware repeating can't be
199
_cogl_texture_iterate_manual_repeats (CoglTextureManualRepeatCallback callback,
200
float tx_1, float ty_1,
201
float tx_2, float ty_2,
204
/* Utility function to use as a fallback for getting the data of any
205
texture via the framebuffer */
208
_cogl_texture_draw_and_read (CoglHandle handle,
209
CoglBitmap *target_bmp,
210
GLuint target_gl_format,
211
GLuint target_gl_type);
213
#endif /* __COGL_TEXTURE_PRIVATE_H */