Add a context parameter to all of the texture driver virtuals
All of the texture driver virtual functions now take an explicit CoglContext parameter as a step towards removing the global context.
This commit is contained in:
parent
60812e6a0e
commit
d6ca75fbec
@ -196,7 +196,8 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format,
|
||||
/* Some platforms might not support this large size so we'll
|
||||
decrease the size until it can */
|
||||
while (size > 1 &&
|
||||
!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
|
||||
!ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
size, size))
|
||||
@ -226,7 +227,8 @@ _cogl_atlas_create_map (CoglPixelFormat format,
|
||||
|
||||
/* Keep trying increasingly larger atlases until we can fit all of
|
||||
the textures */
|
||||
while (ctx->texture_driver->size_supported (GL_TEXTURE_2D,
|
||||
while (ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
map_width, map_height))
|
||||
|
@ -2062,7 +2062,7 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
|
||||
bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format);
|
||||
rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
|
||||
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx, rowstride, bpp);
|
||||
|
||||
tmp_data = _cogl_bitmap_bind (tmp_bmp,
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
@ -2110,7 +2110,7 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
|
||||
|
||||
bpp = _cogl_pixel_format_get_bytes_per_pixel (bmp_format);
|
||||
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx, rowstride, bpp);
|
||||
|
||||
pixels = _cogl_bitmap_bind (shared_bmp,
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
|
@ -651,7 +651,8 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
|
||||
CoglSpan span;
|
||||
|
||||
/* Check if size supported else bail out */
|
||||
if (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
|
||||
if (!ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
max_width,
|
||||
@ -685,7 +686,8 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
|
||||
else
|
||||
{
|
||||
/* Decrease the size of largest slice until supported by GL */
|
||||
while (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
|
||||
while (!ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
max_width,
|
||||
|
@ -127,7 +127,8 @@ _cogl_texture_2d_can_create (unsigned int width,
|
||||
&gl_type);
|
||||
|
||||
/* Check that the driver can create a texture with that size */
|
||||
if (!ctx->texture_driver->size_supported (GL_TEXTURE_2D,
|
||||
if (!ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
width,
|
||||
@ -202,7 +203,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
|
||||
tex_2d = _cogl_texture_2d_create_base (width, height, COGL_TEXTURE_NONE,
|
||||
internal_format);
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
||||
tex_2d->gl_texture,
|
||||
tex_2d->is_foreign);
|
||||
@ -278,8 +279,9 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
|
||||
_cogl_bitmap_unmap (dst_bmp);
|
||||
}
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
ctx->texture_driver->upload_to_gl (GL_TEXTURE_2D,
|
||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
ctx->texture_driver->upload_to_gl (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
tex_2d->gl_texture,
|
||||
FALSE,
|
||||
dst_bmp,
|
||||
@ -347,7 +349,7 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
|
||||
GLenum gl_int_format = 0;
|
||||
CoglTexture2D *tex_2d;
|
||||
|
||||
if (!ctx->texture_driver->allows_foreign_gl_target (GL_TEXTURE_2D))
|
||||
if (!ctx->texture_driver->allows_foreign_gl_target (ctx, GL_TEXTURE_2D))
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
/* Make sure it is a valid GL texture object */
|
||||
@ -474,7 +476,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
|
||||
tex_2d = _cogl_texture_2d_create_base (width, height, COGL_TEXTURE_NONE,
|
||||
format);
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
||||
tex_2d->gl_texture,
|
||||
FALSE);
|
||||
@ -716,7 +718,7 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
available we'll fallback to temporarily enabling
|
||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
||||
ctx->texture_driver->gl_generate_mipmaps (GL_TEXTURE_2D);
|
||||
ctx->texture_driver->gl_generate_mipmaps (ctx, GL_TEXTURE_2D);
|
||||
#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GL)
|
||||
else
|
||||
{
|
||||
@ -784,7 +786,8 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
|
||||
}
|
||||
|
||||
/* Send data to GL */
|
||||
ctx->texture_driver->upload_subregion_to_gl (GL_TEXTURE_2D,
|
||||
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
tex_2d->gl_texture,
|
||||
FALSE,
|
||||
src_x, src_y,
|
||||
@ -822,12 +825,13 @@ _cogl_texture_2d_get_data (CoglTexture *tex,
|
||||
&gl_format,
|
||||
&gl_type);
|
||||
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx, rowstride, bpp);
|
||||
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
||||
tex_2d->gl_texture,
|
||||
tex_2d->is_foreign);
|
||||
return ctx->texture_driver->gl_get_tex_image (GL_TEXTURE_2D,
|
||||
return ctx->texture_driver->gl_get_tex_image (ctx,
|
||||
GL_TEXTURE_2D,
|
||||
gl_format,
|
||||
gl_type,
|
||||
data);
|
||||
|
@ -174,7 +174,8 @@ _cogl_texture_3d_can_create (CoglContext *ctx,
|
||||
&gl_type);
|
||||
|
||||
/* Check that the driver can create a texture with that size */
|
||||
if (!ctx->texture_driver->size_supported_3d (GL_TEXTURE_3D,
|
||||
if (!ctx->texture_driver->size_supported_3d (ctx,
|
||||
GL_TEXTURE_3D,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
width,
|
||||
@ -224,7 +225,7 @@ cogl_texture_3d_new_with_size (CoglContext *ctx,
|
||||
width, height, depth,
|
||||
internal_format);
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
|
||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
|
||||
tex_3d->gl_texture,
|
||||
FALSE);
|
||||
@ -296,9 +297,10 @@ _cogl_texture_3d_new_from_bitmap (CoglContext *ctx,
|
||||
_cogl_bitmap_unmap (dst_bmp);
|
||||
}
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
|
||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_3D, 1, &tex_3d->gl_texture);
|
||||
|
||||
ctx->texture_driver->upload_to_gl_3d (GL_TEXTURE_3D,
|
||||
ctx->texture_driver->upload_to_gl_3d (ctx,
|
||||
GL_TEXTURE_3D,
|
||||
tex_3d->gl_texture,
|
||||
FALSE, /* is_foreign */
|
||||
height,
|
||||
@ -510,7 +512,7 @@ _cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||
available we'll fallback to temporarily enabling
|
||||
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
||||
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
||||
ctx->texture_driver->gl_generate_mipmaps (GL_TEXTURE_3D);
|
||||
ctx->texture_driver->gl_generate_mipmaps (ctx, GL_TEXTURE_3D);
|
||||
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
||||
else if (ctx->driver != COGL_DRIVER_GLES2)
|
||||
{
|
||||
|
@ -34,9 +34,10 @@ struct _CoglTextureDriver
|
||||
* the driver will not allocate room for the mipmap tree.
|
||||
*/
|
||||
void
|
||||
(* gen) (GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures);
|
||||
(* gen) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures);
|
||||
|
||||
/*
|
||||
* This sets up the glPixelStore state for an upload to a destination with
|
||||
@ -46,7 +47,8 @@ struct _CoglTextureDriver
|
||||
* buffer which is why this interface is limited. The GL driver has a more
|
||||
* flexible version of this function that is uses internally */
|
||||
void
|
||||
(* prep_gl_for_pixels_upload) (int pixels_rowstride,
|
||||
(* prep_gl_for_pixels_upload) (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp);
|
||||
|
||||
/*
|
||||
@ -63,18 +65,19 @@ struct _CoglTextureDriver
|
||||
* XXX: sorry for the ridiculous number of arguments :-(
|
||||
*/
|
||||
void
|
||||
(* upload_subregion_to_gl) (GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
int width,
|
||||
int height,
|
||||
CoglBitmap *source_bmp,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
(* upload_subregion_to_gl) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
int width,
|
||||
int height,
|
||||
CoglBitmap *source_bmp,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
|
||||
/*
|
||||
* Replaces the contents of the GL texture with the entire bitmap. On
|
||||
@ -83,13 +86,14 @@ struct _CoglTextureDriver
|
||||
* alignment value because there is no GL_UNPACK_ROW_LENGTH
|
||||
*/
|
||||
void
|
||||
(* upload_to_gl) (GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
CoglBitmap *source_bmp,
|
||||
GLint internal_gl_format,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
(* upload_to_gl) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
CoglBitmap *source_bmp,
|
||||
GLint internal_gl_format,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
|
||||
/*
|
||||
* Replaces the contents of the GL texture with the entire bitmap. The
|
||||
@ -99,15 +103,16 @@ struct _CoglTextureDriver
|
||||
* height of the bitmap by the depth.
|
||||
*/
|
||||
void
|
||||
(* upload_to_gl_3d) (GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
GLint height,
|
||||
GLint depth,
|
||||
CoglBitmap *source_bmp,
|
||||
GLint internal_gl_format,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
(* upload_to_gl_3d) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
GLint height,
|
||||
GLint depth,
|
||||
CoglBitmap *source_bmp,
|
||||
GLint internal_gl_format,
|
||||
GLuint source_gl_format,
|
||||
GLuint source_gl_type);
|
||||
|
||||
/*
|
||||
* This sets up the glPixelStore state for an download to a destination with
|
||||
@ -117,7 +122,8 @@ struct _CoglTextureDriver
|
||||
* destination buffer, the GL driver has a more flexible version of
|
||||
* this function that it uses internally. */
|
||||
void
|
||||
(* prep_gl_for_pixels_download) (int pixels_rowstride,
|
||||
(* prep_gl_for_pixels_download) (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp);
|
||||
|
||||
/*
|
||||
@ -128,36 +134,39 @@ struct _CoglTextureDriver
|
||||
* _cogl_texture_draw_and_read () )
|
||||
*/
|
||||
gboolean
|
||||
(* gl_get_tex_image) (GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
(* gl_get_tex_image) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
guint8 *dest);
|
||||
|
||||
/*
|
||||
* It may depend on the driver as to what texture sizes are supported...
|
||||
*/
|
||||
gboolean
|
||||
(* size_supported) (GLenum gl_target,
|
||||
(* size_supported) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height);
|
||||
int width,
|
||||
int height);
|
||||
|
||||
gboolean
|
||||
(* size_supported_3d) (GLenum gl_target,
|
||||
(* size_supported_3d) (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height,
|
||||
int depth);
|
||||
int width,
|
||||
int height,
|
||||
int depth);
|
||||
|
||||
/*
|
||||
* This driver abstraction is needed because GLES doesn't support setting
|
||||
* a texture border color.
|
||||
*/
|
||||
void
|
||||
(* try_setting_gl_border_color) (
|
||||
GLuint gl_target,
|
||||
(* try_setting_gl_border_color) (CoglContext *ctx,
|
||||
GLuint gl_target,
|
||||
const GLfloat *transparent_color);
|
||||
|
||||
/*
|
||||
@ -166,7 +175,8 @@ struct _CoglTextureDriver
|
||||
* but GLES doesn't
|
||||
*/
|
||||
gboolean
|
||||
(* allows_foreign_gl_target) (GLenum gl_target);
|
||||
(* allows_foreign_gl_target) (CoglContext *ctx,
|
||||
GLenum gl_target);
|
||||
|
||||
/*
|
||||
* glGenerateMipmap semantics may need to be emulated for some
|
||||
@ -174,7 +184,8 @@ struct _CoglTextureDriver
|
||||
* number of known texels.
|
||||
*/
|
||||
void
|
||||
(* gl_generate_mipmaps) (GLenum texture_target);
|
||||
(* gl_generate_mipmaps) (CoglContext *ctx,
|
||||
GLenum texture_target);
|
||||
|
||||
/*
|
||||
* The driver may impose constraints on what formats can be used to store
|
||||
@ -184,9 +195,9 @@ struct _CoglTextureDriver
|
||||
*/
|
||||
CoglPixelFormat
|
||||
(* find_best_gl_get_data_format) (CoglContext *context,
|
||||
CoglPixelFormat format,
|
||||
GLenum *closest_gl_format,
|
||||
GLenum *closest_gl_type);
|
||||
CoglPixelFormat format,
|
||||
GLenum *closest_gl_format,
|
||||
GLenum *closest_gl_type);
|
||||
};
|
||||
|
||||
#endif /* __COGL_TEXTURE_DRIVER_H */
|
||||
|
@ -135,7 +135,8 @@ _cogl_texture_rectangle_can_create (unsigned int width,
|
||||
&gl_type);
|
||||
|
||||
/* Check that the driver can create a texture with that size */
|
||||
if (!ctx->texture_driver->size_supported (GL_TEXTURE_RECTANGLE_ARB,
|
||||
if (!ctx->texture_driver->size_supported (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
gl_intformat,
|
||||
gl_type,
|
||||
width,
|
||||
@ -206,7 +207,10 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
|
||||
tex_rect = _cogl_texture_rectangle_create_base (width, height,
|
||||
internal_format);
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_RECTANGLE_ARB, 1, &tex_rect->gl_texture);
|
||||
ctx->texture_driver->gen (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
1, /* num textures */
|
||||
&tex_rect->gl_texture);
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
||||
tex_rect->gl_texture,
|
||||
tex_rect->is_foreign);
|
||||
@ -255,8 +259,12 @@ _cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
|
||||
cogl_bitmap_get_height (bmp),
|
||||
internal_format);
|
||||
|
||||
ctx->texture_driver->gen (GL_TEXTURE_RECTANGLE_ARB, 1, &tex_rect->gl_texture);
|
||||
ctx->texture_driver->upload_to_gl (GL_TEXTURE_RECTANGLE_ARB,
|
||||
ctx->texture_driver->gen (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
1, /* num textures */
|
||||
&tex_rect->gl_texture);
|
||||
ctx->texture_driver->upload_to_gl (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
tex_rect->gl_texture,
|
||||
FALSE,
|
||||
dst_bmp,
|
||||
@ -288,7 +296,8 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
if (!ctx->texture_driver->allows_foreign_gl_target (GL_TEXTURE_RECTANGLE_ARB))
|
||||
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB))
|
||||
return NULL;
|
||||
|
||||
/* Make sure it is a valid GL texture object */
|
||||
@ -506,7 +515,8 @@ _cogl_texture_rectangle_set_region (CoglTexture *tex,
|
||||
&gl_type);
|
||||
|
||||
/* Send data to GL */
|
||||
ctx->texture_driver->upload_subregion_to_gl (GL_TEXTURE_RECTANGLE_ARB,
|
||||
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
tex_rect->gl_texture,
|
||||
FALSE,
|
||||
src_x, src_y,
|
||||
@ -542,12 +552,13 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex,
|
||||
&gl_format,
|
||||
&gl_type);
|
||||
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx, rowstride, bpp);
|
||||
|
||||
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
||||
tex_rect->gl_texture,
|
||||
tex_rect->is_foreign);
|
||||
return ctx->texture_driver->gl_get_tex_image (GL_TEXTURE_RECTANGLE_ARB,
|
||||
return ctx->texture_driver->gl_get_tex_image (ctx,
|
||||
GL_TEXTURE_RECTANGLE_ARB,
|
||||
gl_format,
|
||||
gl_type,
|
||||
data);
|
||||
|
@ -46,14 +46,13 @@
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_gen (GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures)
|
||||
_cogl_texture_driver_gen (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
GE (ctx, glGenTextures (n, textures));
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
@ -86,14 +85,13 @@ _cogl_texture_driver_gen (GLenum gl_target,
|
||||
/* OpenGL - unlike GLES - can upload a sub region of pixel data from a larger
|
||||
* source buffer */
|
||||
static void
|
||||
prep_gl_for_pixels_upload_full (int pixels_rowstride,
|
||||
prep_gl_for_pixels_upload_full (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int image_height,
|
||||
int pixels_src_x,
|
||||
int pixels_src_y,
|
||||
int pixels_bpp)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,
|
||||
pixels_rowstride / pixels_bpp) );
|
||||
|
||||
@ -107,23 +105,23 @@ prep_gl_for_pixels_upload_full (int pixels_rowstride,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (int pixels_rowstride,
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp)
|
||||
{
|
||||
prep_gl_for_pixels_upload_full (pixels_rowstride, 0, 0, 0, pixels_bpp);
|
||||
prep_gl_for_pixels_upload_full (ctx, pixels_rowstride, 0, 0, 0, pixels_bpp);
|
||||
}
|
||||
|
||||
/* OpenGL - unlike GLES - can download pixel data into a sub region of
|
||||
* a larger destination buffer */
|
||||
static void
|
||||
prep_gl_for_pixels_download_full (int pixels_rowstride,
|
||||
prep_gl_for_pixels_download_full (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int image_height,
|
||||
int pixels_src_x,
|
||||
int pixels_src_y,
|
||||
int pixels_bpp)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
GE( ctx, glPixelStorei (GL_PACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) );
|
||||
|
||||
GE( ctx, glPixelStorei (GL_PACK_SKIP_PIXELS, pixels_src_x) );
|
||||
@ -136,14 +134,16 @@ prep_gl_for_pixels_download_full (int pixels_rowstride,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_prep_gl_for_pixels_download (int pixels_rowstride,
|
||||
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp)
|
||||
{
|
||||
prep_gl_for_pixels_download_full (pixels_rowstride, 0, 0, 0, pixels_bpp);
|
||||
prep_gl_for_pixels_download_full (ctx, pixels_rowstride, 0, 0, 0, pixels_bpp);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
int src_x,
|
||||
@ -160,12 +160,11 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
|
||||
/* Setup gl alignment to match rowstride and top-left corner */
|
||||
prep_gl_for_pixels_upload_full (cogl_bitmap_get_rowstride (source_bmp),
|
||||
prep_gl_for_pixels_upload_full (ctx,
|
||||
cogl_bitmap_get_rowstride (source_bmp),
|
||||
0,
|
||||
src_x,
|
||||
src_y,
|
||||
@ -184,7 +183,8 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
CoglBitmap *source_bmp,
|
||||
@ -196,12 +196,11 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
|
||||
/* Setup gl alignment to match rowstride and top-left corner */
|
||||
prep_gl_for_pixels_upload_full (cogl_bitmap_get_rowstride (source_bmp),
|
||||
prep_gl_for_pixels_upload_full (ctx,
|
||||
cogl_bitmap_get_rowstride (source_bmp),
|
||||
0, 0, 0, bpp);
|
||||
|
||||
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
||||
@ -219,7 +218,8 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
GLint height,
|
||||
@ -233,12 +233,11 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
|
||||
/* Setup gl alignment to match rowstride and top-left corner */
|
||||
prep_gl_for_pixels_upload_full (cogl_bitmap_get_rowstride (source_bmp),
|
||||
prep_gl_for_pixels_upload_full (ctx,
|
||||
cogl_bitmap_get_rowstride (source_bmp),
|
||||
(cogl_bitmap_get_height (source_bmp) /
|
||||
depth),
|
||||
0, 0, bpp);
|
||||
@ -260,13 +259,12 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_gl_get_tex_image (GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
guint8 *dest)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
GE (ctx, glGetTexImage (gl_target,
|
||||
0, /* level */
|
||||
dest_gl_format,
|
||||
@ -276,18 +274,17 @@ _cogl_texture_driver_gl_get_tex_image (GLenum gl_target,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_size_supported_3d (GLenum gl_target,
|
||||
_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height,
|
||||
int depth)
|
||||
int width,
|
||||
int height,
|
||||
int depth)
|
||||
{
|
||||
GLenum proxy_target;
|
||||
GLint new_width = 0;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
if (gl_target == GL_TEXTURE_3D)
|
||||
proxy_target = GL_PROXY_TEXTURE_3D;
|
||||
else
|
||||
@ -306,17 +303,16 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_size_supported (GLenum gl_target,
|
||||
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height)
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
GLenum proxy_target;
|
||||
GLint new_width = 0;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
if (gl_target == GL_TEXTURE_2D)
|
||||
proxy_target = GL_PROXY_TEXTURE_2D;
|
||||
#if HAVE_COGL_GL
|
||||
@ -339,12 +335,11 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_try_setting_gl_border_color (
|
||||
GLuint gl_target,
|
||||
const GLfloat *transparent_color)
|
||||
_cogl_texture_driver_try_setting_gl_border_color
|
||||
(CoglContext *ctx,
|
||||
GLuint gl_target,
|
||||
const GLfloat *transparent_color)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* Use a transparent border color so that we can leave the
|
||||
color buffer alone when using texture co-ordinates
|
||||
outside of the texture */
|
||||
@ -353,7 +348,8 @@ _cogl_texture_driver_try_setting_gl_border_color (
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
||||
_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
||||
GLenum gl_target)
|
||||
{
|
||||
/* GL_ARB_texture_rectangle textures are supported if they are
|
||||
created from foreign because some chipsets have trouble with
|
||||
@ -369,10 +365,9 @@ _cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
|
||||
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
||||
GLenum gl_target)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
GE( ctx, glGenerateMipmap (gl_target) );
|
||||
}
|
||||
|
||||
|
@ -53,14 +53,13 @@
|
||||
#endif
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_gen (GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures)
|
||||
_cogl_texture_driver_gen (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLsizei n,
|
||||
GLuint *textures)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
GE (ctx, glGenTextures (n, textures));
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
@ -84,21 +83,24 @@ _cogl_texture_driver_gen (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (int pixels_rowstride,
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *context,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp)
|
||||
{
|
||||
_cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_prep_gl_for_pixels_download (int pixels_rowstride,
|
||||
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
||||
int pixels_rowstride,
|
||||
int pixels_bpp)
|
||||
{
|
||||
_cogl_texture_prep_gl_alignment_for_pixels_download (pixels_rowstride);
|
||||
}
|
||||
|
||||
static CoglBitmap *
|
||||
prepare_bitmap_alignment_for_upload (CoglBitmap *src_bmp)
|
||||
prepare_bitmap_alignment_for_upload (CoglContext *ctx,
|
||||
CoglBitmap *src_bmp)
|
||||
{
|
||||
CoglPixelFormat format = cogl_bitmap_get_format (src_bmp);
|
||||
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
||||
@ -124,7 +126,8 @@ prepare_bitmap_alignment_for_upload (CoglBitmap *src_bmp)
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
int src_x,
|
||||
@ -143,8 +146,6 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
CoglBitmap *slice_bmp;
|
||||
int rowstride;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* If we are copying a sub region of the source bitmap then we need
|
||||
to copy it because GLES does not support GL_UNPACK_ROW_LENGTH */
|
||||
if (src_x != 0 || src_y != 0 ||
|
||||
@ -162,12 +163,12 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
width, height);
|
||||
}
|
||||
else
|
||||
slice_bmp = prepare_bitmap_alignment_for_upload (source_bmp);
|
||||
slice_bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp);
|
||||
|
||||
rowstride = cogl_bitmap_get_rowstride (slice_bmp);
|
||||
|
||||
/* Setup gl alignment to match rowstride and top-left corner */
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
||||
|
||||
data = _cogl_bitmap_bind (slice_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
|
||||
@ -186,7 +187,8 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
CoglBitmap *source_bmp,
|
||||
@ -202,13 +204,11 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
CoglBitmap *bmp;
|
||||
guint8 *data;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
bmp = prepare_bitmap_alignment_for_upload (source_bmp);
|
||||
bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp);
|
||||
rowstride = cogl_bitmap_get_rowstride (bmp);
|
||||
|
||||
/* Setup gl alignment to match rowstride and top-left corner */
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
||||
|
||||
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
||||
|
||||
@ -228,7 +228,8 @@ _cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLuint gl_handle,
|
||||
gboolean is_foreign,
|
||||
GLint height,
|
||||
@ -245,8 +246,6 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
int bmp_height = cogl_bitmap_get_height (source_bmp);
|
||||
guint8 *data;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
||||
|
||||
/* If the rowstride or image height can't be specified with just
|
||||
@ -260,7 +259,7 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
CoglPixelFormat source_bmp_format = cogl_bitmap_get_format (source_bmp);
|
||||
int i;
|
||||
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (bmp_width * bpp, bpp);
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, bmp_width * bpp, bpp);
|
||||
|
||||
/* Initialize the texture with empty data and then upload each
|
||||
image with a sub-region update */
|
||||
@ -314,7 +313,7 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
{
|
||||
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
||||
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
|
||||
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
||||
|
||||
GE( ctx, glTexImage3D (gl_target,
|
||||
0, /* level */
|
||||
@ -335,26 +334,26 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
||||
* fallback to a generic render + readpixels approach to downloading
|
||||
* texture data. (See _cogl_texture_draw_and_read() ) */
|
||||
static gboolean
|
||||
_cogl_texture_driver_gl_get_tex_image (GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum dest_gl_format,
|
||||
GLenum dest_gl_type,
|
||||
guint8 *dest)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_size_supported_3d (GLenum gl_target,
|
||||
_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height,
|
||||
int depth)
|
||||
int width,
|
||||
int height,
|
||||
int depth)
|
||||
{
|
||||
GLint max_size;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
/* GLES doesn't support a proxy texture target so let's at least
|
||||
check whether the size is greater than
|
||||
GL_MAX_3D_TEXTURE_SIZE_OES */
|
||||
@ -364,16 +363,15 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_size_supported (GLenum gl_target,
|
||||
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
||||
GLenum gl_target,
|
||||
GLenum gl_format,
|
||||
GLenum gl_type,
|
||||
int width,
|
||||
int height)
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
GLint max_size;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
/* GLES doesn't support a proxy texture target so let's at least
|
||||
check whether the size is greater than GL_MAX_TEXTURE_SIZE */
|
||||
GE( ctx, glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
|
||||
@ -382,15 +380,17 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_try_setting_gl_border_color (
|
||||
GLuint gl_target,
|
||||
const GLfloat *transparent_color)
|
||||
_cogl_texture_driver_try_setting_gl_border_color
|
||||
(CoglContext *ctx,
|
||||
GLuint gl_target,
|
||||
const GLfloat *transparent_color)
|
||||
{
|
||||
/* FAIL! */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
||||
_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
||||
GLenum gl_target)
|
||||
{
|
||||
/* Allow 2-dimensional textures only */
|
||||
if (gl_target != GL_TEXTURE_2D)
|
||||
@ -399,10 +399,9 @@ _cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
||||
}
|
||||
|
||||
static void
|
||||
_cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
|
||||
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
||||
GLenum gl_target)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (ctx->driver == COGL_DRIVER_GLES2)
|
||||
GE( ctx, glGenerateMipmap (gl_target) );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user