diff --git a/cogl/cogl/cogl-atlas.c b/cogl/cogl/cogl-atlas.c index 856e0b852..60c2e1829 100644 --- a/cogl/cogl/cogl-atlas.c +++ b/cogl/cogl/cogl-atlas.c @@ -43,6 +43,7 @@ #include "cogl/cogl-blit.h" #include "cogl/cogl-private.h" #include "cogl/driver/gl/cogl-driver-gl-private.h" +#include "cogl/driver/gl/cogl-texture-driver-gl-private.h" #include @@ -196,8 +197,10 @@ _cogl_atlas_get_initial_size (CoglContext *ctx, { CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); unsigned int size; GLenum gl_intformat; GLenum gl_format; @@ -225,13 +228,13 @@ _cogl_atlas_get_initial_size (CoglContext *ctx, /* Some platforms might not support this large size so we'll decrease the size until it can */ while (size > 1 && - !tex_driver->size_supported (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - gl_intformat, - gl_format, - gl_type, - size, size)) + !tex_driver_klass->size_supported (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + gl_intformat, + gl_format, + gl_type, + size, size)) size >>= 1; *map_width = size; @@ -248,8 +251,10 @@ _cogl_atlas_create_map (CoglContext *ctx, { CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); GLenum gl_intformat; GLenum gl_format; GLenum gl_type; @@ -263,13 +268,13 @@ _cogl_atlas_create_map (CoglContext *ctx, /* Keep trying increasingly larger atlases until we can fit all of the textures */ - while (tex_driver->size_supported (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - gl_intformat, - gl_format, - gl_type, - map_width, map_height)) + while (tex_driver_klass->size_supported (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + gl_intformat, + gl_format, + gl_type, + map_width, map_height)) { CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width, map_height, diff --git a/cogl/cogl/cogl-texture-driver.h b/cogl/cogl/cogl-texture-driver.h index e894d94ff..a97bed45b 100644 --- a/cogl/cogl/cogl-texture-driver.h +++ b/cogl/cogl/cogl-texture-driver.h @@ -32,7 +32,6 @@ #include -#include "cogl/cogl-gl-header.h" #include "cogl/cogl-pixel-format.h" #include "cogl/cogl-types.h" @@ -48,116 +47,10 @@ struct _CoglTextureDriverClass { GObjectClass parent_class; - /* - * A very small wrapper around glGenTextures() that ensures we default to - * non-mipmap filters when creating textures. This is to save some memory as - * the driver will not allocate room for the mipmap tree. - */ - GLuint (* gen) (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - CoglPixelFormat internal_format); - - /* - * This uploads a sub-region from source_bmp to a single GL texture - * handle (i.e a single CoglTexture slice) - * - * It also updates the array of tex->first_pixels[slice_index] if - * dst_{x,y} == 0 - * - * The driver abstraction is in place because GLES doesn't support the pixel - * store options required to source from a subregion, so for GLES we have - * to manually create a transient source bitmap. - * - * XXX: sorry for the ridiculous number of arguments :-( - */ - gboolean (* upload_subregion_to_gl) (CoglTextureDriver *driver, - CoglContext *ctx, - CoglTexture *texture, - int src_x, - int src_y, - int dst_x, - int dst_y, - int width, - int height, - int level, - CoglBitmap *source_bmp, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error); - - /* - * Replaces the contents of the GL texture with the entire bitmap. On - * GL this just directly calls glTexImage2D, but under GLES it needs - * to copy the bitmap if the rowstride is not a multiple of a possible - * alignment value because there is no GL_UNPACK_ROW_LENGTH - */ - gboolean (* upload_to_gl) (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLuint gl_handle, - CoglBitmap *source_bmp, - GLint internal_gl_format, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error); - - /* - * This sets up the glPixelStore state for an download to a destination with - * the same size, and with no offset. - */ - /* NB: GLES can't download pixel data into a sub region of a larger - * destination buffer, the GL driver has a more flexible version of - * this function that it uses internally. */ - void (* prep_gl_for_pixels_download) (CoglTextureDriver *driver, - CoglContext *ctx, - int image_width, - int pixels_rowstride, - int pixels_bpp); - - /* - * This driver abstraction is needed because GLES doesn't support - * glGetTexImage (). On GLES this currently just returns FALSE which - * will lead to a generic fallback path being used that simply - * renders the texture and reads it back from the framebuffer. (See - * _cogl_texture_draw_and_read () ) - */ - gboolean (* gl_get_tex_image) (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum dest_gl_format, - GLenum dest_gl_type, - uint8_t *dest); - - /* - * It may depend on the driver as to what texture sizes are supported... - */ - gboolean (* size_supported) (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum gl_intformat, - GLenum gl_format, - GLenum gl_type, - int width, - int height); - - gboolean (* format_supports_upload) (CoglTextureDriver *driver, CoglContext *ctx, CoglPixelFormat format); - /* - * The driver may impose constraints on what formats can be used to store - * texture data read from textures. For example GLES currently only supports - * RGBA_8888, and so we need to manually convert the data if the final - * destination has another format. - */ - CoglPixelFormat (* find_best_gl_get_data_format) (CoglTextureDriver *driver, - CoglContext *context, - CoglPixelFormat format, - GLenum *closest_gl_format, - GLenum *closest_gl_type); - /* Destroys any driver specific resources associated with the given * 2D texture. */ diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 9fca70ba4..6d6123aba 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -54,6 +54,7 @@ #include "cogl/cogl-offscreen-private.h" #include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-sub-texture.h" +#include "cogl/driver/gl/cogl-texture-driver-gl-private.h" #include #include @@ -811,7 +812,7 @@ cogl_texture_get_data (CoglTexture *texture, uint8_t *data) { CoglContext *ctx; - CoglTextureDriverClass *tex_driver; + CoglTextureDriverGLClass *tex_driver_gl; int bpp; int byte_size; CoglPixelFormat closest_format; @@ -849,13 +850,13 @@ cogl_texture_get_data (CoglTexture *texture, return byte_size; ctx = cogl_texture_get_context (texture); - tex_driver = COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + tex_driver_gl = COGL_TEXTURE_DRIVER_GL_GET_CLASS (ctx->texture_driver); closest_format = - tex_driver->find_best_gl_get_data_format (ctx->texture_driver, - ctx, - format, - &closest_gl_format, - &closest_gl_type); + tex_driver_gl->find_best_gl_get_data_format (COGL_TEXTURE_DRIVER_GL (ctx->texture_driver), + ctx, + format, + &closest_gl_format, + &closest_gl_type); /* We can assume that whatever data GL gives us will have the premult status of the original texture */ diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c index 16350bf31..1fb8cdf77 100644 --- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c +++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c @@ -41,7 +41,8 @@ #include "cogl/driver/gl/cogl-framebuffer-gl-private.h" #include "cogl/driver/gl/cogl-bitmap-gl-private.h" #include "cogl/driver/gl/cogl-buffer-gl-private.h" -#include "cogl/driver/gl/cogl-driver-gl-private.h" + #include "cogl/driver/gl/cogl-driver-gl-private.h" + #include "cogl/driver/gl/cogl-texture-driver-gl-private.h" #include #include @@ -406,6 +407,9 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, CoglPixelFormat internal_format = cogl_framebuffer_get_internal_format (framebuffer); CoglDriverGLClass *driver_gl_klass = COGL_DRIVER_GL_GET_CLASS (ctx->driver); + CoglTextureDriverGL *tex_driver_gl = COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_gl_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); CoglPixelFormat read_format; GLenum gl_format; GLenum gl_type; @@ -466,8 +470,6 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, int bpp, rowstride; uint8_t *tmp_data; gboolean succeeded; - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); if (_cogl_pixel_format_can_have_premult (read_format)) { @@ -485,11 +487,11 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, bpp = cogl_pixel_format_get_bytes_per_pixel (read_format, 0); rowstride = cogl_bitmap_get_rowstride (tmp_bmp); - tex_driver->prep_gl_for_pixels_download (ctx->texture_driver, - ctx, - rowstride, - width, - bpp); + tex_driver_gl_klass->prep_gl_for_pixels_download (tex_driver_gl, + ctx, + rowstride, + width, + bpp); /* Note: we don't worry about catching errors here since we know * we won't be lazily allocating storage for this buffer so it @@ -528,8 +530,6 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, gboolean succeeded = FALSE; uint8_t *pixels; GError *internal_error = NULL; - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); rowstride = cogl_bitmap_get_rowstride (bitmap); @@ -552,11 +552,11 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, bpp = cogl_pixel_format_get_bytes_per_pixel (bmp_format, 0); - tex_driver->prep_gl_for_pixels_download (ctx->texture_driver, - ctx, - rowstride, - width, - bpp); + tex_driver_gl_klass->prep_gl_for_pixels_download (tex_driver_gl, + ctx, + rowstride, + width, + bpp); pixels = _cogl_bitmap_gl_bind (shared_bmp, COGL_BUFFER_ACCESS_WRITE, diff --git a/cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h b/cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h index 44eac5fd9..bc6dbeb98 100644 --- a/cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h +++ b/cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h @@ -28,17 +28,123 @@ #pragma once +#include "cogl/cogl-gl-header.h" #include "cogl/cogl-texture-driver.h" -struct _CoglTextureDriverGLClass -{ - CoglTextureDriverClass parent_class; -}; - G_DECLARE_DERIVABLE_TYPE (CoglTextureDriverGL, cogl_texture_driver_gl, COGL, TEXTURE_DRIVER_GL, CoglTextureDriver) +struct _CoglTextureDriverGLClass +{ + CoglTextureDriverClass parent_class; + + /* + * A very small wrapper around glGenTextures() that ensures we default to + * non-mipmap filters when creating textures. This is to save some memory as + * the driver will not allocate room for the mipmap tree. + */ + GLuint (* gen) (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + CoglPixelFormat internal_format); + + /* + * This uploads a sub-region from source_bmp to a single GL texture + * handle (i.e a single CoglTexture slice) + * + * It also updates the array of tex->first_pixels[slice_index] if + * dst_{x,y} == 0 + * + * The driver abstraction is in place because GLES doesn't support the pixel + * store options required to source from a subregion, so for GLES we have + * to manually create a transient source bitmap. + * + * XXX: sorry for the ridiculous number of arguments :-( + */ + gboolean (* upload_subregion_to_gl) (CoglTextureDriverGL *driver, + CoglContext *ctx, + CoglTexture *texture, + int src_x, + int src_y, + int dst_x, + int dst_y, + int width, + int height, + int level, + CoglBitmap *source_bmp, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error); + + /* + * Replaces the contents of the GL texture with the entire bitmap. On + * GL this just directly calls glTexImage2D, but under GLES it needs + * to copy the bitmap if the rowstride is not a multiple of a possible + * alignment value because there is no GL_UNPACK_ROW_LENGTH + */ + gboolean (* upload_to_gl) (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLuint gl_handle, + CoglBitmap *source_bmp, + GLint internal_gl_format, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error); + + /* + * This sets up the glPixelStore state for an download to a destination with + * the same size, and with no offset. + */ + /* NB: GLES can't download pixel data into a sub region of a larger + * destination buffer, the GL driver has a more flexible version of + * this function that it uses internally. */ + void (* prep_gl_for_pixels_download) (CoglTextureDriverGL *driver, + CoglContext *ctx, + int image_width, + int pixels_rowstride, + int pixels_bpp); + + /* + * This driver abstraction is needed because GLES doesn't support + * glGetTexImage (). On GLES this currently just returns FALSE which + * will lead to a generic fallback path being used that simply + * renders the texture and reads it back from the framebuffer. (See + * _cogl_texture_draw_and_read () ) + */ + gboolean (* gl_get_tex_image) (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum dest_gl_format, + GLenum dest_gl_type, + uint8_t *dest); + + /* + * It may depend on the driver as to what texture sizes are supported... + */ + gboolean (* size_supported) (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum gl_intformat, + GLenum gl_format, + GLenum gl_type, + int width, + int height); + + /* + * The driver may impose constraints on what formats can be used to store + * texture data read from textures. For example GLES currently only supports + * RGBA_8888, and so we need to manually convert the data if the final + * destination has another format. + */ + CoglPixelFormat (* find_best_gl_get_data_format) (CoglTextureDriverGL *driver, + CoglContext *context, + CoglPixelFormat format, + GLenum *closest_gl_format, + GLenum *closest_gl_type); +}; + #define COGL_TYPE_TEXTURE_DRIVER_GL (cogl_texture_driver_gl_get_type ()) diff --git a/cogl/cogl/driver/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/cogl-texture-driver-gl.c index c4b79ef81..29ed04bb9 100644 --- a/cogl/cogl/driver/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-driver-gl.c @@ -62,14 +62,16 @@ cogl_texture_driver_gl_texture_2d_free (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gl_texture_2d_can_create (CoglTextureDriver *driver, +cogl_texture_driver_gl_texture_2d_can_create (CoglTextureDriver *tex_driver, CoglContext *ctx, int width, int height, CoglPixelFormat internal_format) { - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); GLenum gl_intformat; @@ -88,14 +90,14 @@ cogl_texture_driver_gl_texture_2d_can_create (CoglTextureDriver *driver, &gl_type); /* Check that the driver can create a texture with that size */ - if (!tex_driver->size_supported (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - gl_intformat, - gl_format, - gl_type, - width, - height)) + if (!tex_driver_klass->size_supported (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + gl_intformat, + gl_format, + gl_type, + width, + height)) return FALSE; return TRUE; @@ -113,8 +115,10 @@ allocate_with_size (CoglTexture2D *tex_2d, CoglContext *ctx = cogl_texture_get_context (tex); CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); GLenum gl_intformat; GLenum gl_format; GLenum gl_type; @@ -143,10 +147,10 @@ allocate_with_size (CoglTexture2D *tex_2d, &gl_format, &gl_type); - gl_texture = tex_driver->gen (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - internal_format); + gl_texture = tex_driver_klass->gen (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + internal_format); tex_2d->gl_internal_format = gl_intformat; @@ -185,8 +189,10 @@ allocate_from_bitmap (CoglTexture2D *tex_2d, CoglContext *ctx = _cogl_bitmap_get_context (bmp); CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); CoglPixelFormat internal_format; int width = cogl_bitmap_get_width (bmp); int height = cogl_bitmap_get_height (bmp); @@ -230,19 +236,19 @@ allocate_from_bitmap (CoglTexture2D *tex_2d, NULL, NULL); - tex_2d->gl_texture = tex_driver->gen (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - internal_format); - if (!tex_driver->upload_to_gl (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - tex_2d->gl_texture, - upload_bmp, - gl_intformat, - gl_format, - gl_type, - error)) + tex_2d->gl_texture = tex_driver_klass->gen (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + internal_format); + if (!tex_driver_klass->upload_to_gl (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + tex_2d->gl_texture, + upload_bmp, + gl_intformat, + gl_format, + gl_type, + error)) { g_object_unref (upload_bmp); return FALSE; @@ -268,13 +274,15 @@ allocate_from_egl_image (CoglTexture2D *tex_2d, CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglContext *ctx = cogl_texture_get_context (tex); CoglPixelFormat internal_format = loader->src.egl_image.format; - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); - tex_2d->gl_texture = tex_driver->gen (ctx->texture_driver, - ctx, - GL_TEXTURE_2D, - internal_format); + tex_2d->gl_texture = tex_driver_klass->gen (tex_driver_gl, + ctx, + GL_TEXTURE_2D, + internal_format); if (!cogl_texture_2d_gl_bind_egl_image (tex_2d, loader->src.egl_image.image, @@ -471,8 +479,10 @@ cogl_texture_driver_gl_texture_2d_copy_from_bitmap (CoglTextureDriver *driver, CoglContext *ctx = cogl_texture_get_context (tex); CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); CoglBitmap *upload_bmp; CoglPixelFormat upload_format; GLenum gl_format; @@ -503,17 +513,17 @@ cogl_texture_driver_gl_texture_2d_copy_from_bitmap (CoglTextureDriver *driver, if (cogl_texture_get_max_level_set (tex) < level) cogl_texture_gl_set_max_level (tex, level); - status = tex_driver->upload_subregion_to_gl (ctx->texture_driver, - ctx, - tex, - src_x, src_y, - dst_x, dst_y, - width, height, - level, - upload_bmp, - gl_format, - gl_type, - error); + status = tex_driver_klass->upload_subregion_to_gl (tex_driver_gl, + ctx, + tex, + src_x, src_y, + dst_x, dst_y, + width, height, + level, + upload_bmp, + gl_format, + gl_type, + error); g_object_unref (upload_bmp); diff --git a/cogl/cogl/driver/gl/gl3/cogl-texture-driver-gl3.c b/cogl/cogl/driver/gl/gl3/cogl-texture-driver-gl3.c index 86b30204d..2874b4f13 100644 --- a/cogl/cogl/driver/gl/gl3/cogl-texture-driver-gl3.c +++ b/cogl/cogl/driver/gl/gl3/cogl-texture-driver-gl3.c @@ -68,10 +68,10 @@ G_DEFINE_FINAL_TYPE (CoglTextureDriverGL3, COGL_TYPE_TEXTURE_DRIVER_GL) static GLuint -cogl_texture_driver_gl3_gen (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - CoglPixelFormat internal_format) +cogl_texture_driver_gl3_gen (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + CoglPixelFormat internal_format) { GLuint tex; @@ -162,11 +162,11 @@ prep_gl_for_pixels_download_full (CoglContext *ctx, } static void -cogl_texture_driver_gl3_prep_gl_for_pixels_download (CoglTextureDriver *driver, - CoglContext *ctx, - int image_width, - int pixels_rowstride, - int pixels_bpp) +cogl_texture_driver_gl3_prep_gl_for_pixels_download (CoglTextureDriverGL *driver, + CoglContext *ctx, + int image_width, + int pixels_rowstride, + int pixels_bpp) { prep_gl_for_pixels_download_full (ctx, pixels_rowstride, @@ -177,20 +177,20 @@ cogl_texture_driver_gl3_prep_gl_for_pixels_download (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gl3_upload_subregion_to_gl (CoglTextureDriver *driver, - CoglContext *ctx, - CoglTexture *texture, - int src_x, - int src_y, - int dst_x, - int dst_y, - int width, - int height, - int level, - CoglBitmap *source_bmp, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error) +cogl_texture_driver_gl3_upload_subregion_to_gl (CoglTextureDriverGL *driver, + CoglContext *ctx, + CoglTexture *texture, + int src_x, + int src_y, + int dst_x, + int dst_y, + int width, + int height, + int level, + CoglBitmap *source_bmp, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error) { GLenum gl_target; GLuint gl_handle; @@ -295,15 +295,15 @@ cogl_texture_driver_gl3_upload_subregion_to_gl (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gl3_upload_to_gl (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLuint gl_handle, - CoglBitmap *source_bmp, - GLint internal_gl_format, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error) +cogl_texture_driver_gl3_upload_to_gl (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLuint gl_handle, + CoglBitmap *source_bmp, + GLint internal_gl_format, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error) { uint8_t *data; CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp); @@ -359,12 +359,12 @@ cogl_texture_driver_gl3_upload_to_gl (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gl3_gl_get_tex_image (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum dest_gl_format, - GLenum dest_gl_type, - uint8_t *dest) +cogl_texture_driver_gl3_gl_get_tex_image (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum dest_gl_format, + GLenum dest_gl_type, + uint8_t *dest) { GE (ctx, glGetTexImage (gl_target, 0, /* level */ @@ -375,14 +375,14 @@ cogl_texture_driver_gl3_gl_get_tex_image (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gl3_size_supported (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum gl_intformat, - GLenum gl_format, - GLenum gl_type, - int width, - int height) +cogl_texture_driver_gl3_size_supported (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum gl_intformat, + GLenum gl_format, + GLenum gl_type, + int width, + int height) { GLenum proxy_target; GLint new_width = 0; @@ -477,11 +477,11 @@ cogl_texture_driver_gl3_upload_supported (CoglTextureDriver *driver, } static CoglPixelFormat -cogl_texture_driver_gl3_find_best_gl_get_data_format (CoglTextureDriver *driver, - CoglContext *context, - CoglPixelFormat format, - GLenum *closest_gl_format, - GLenum *closest_gl_type) +cogl_texture_driver_gl3_find_best_gl_get_data_format (CoglTextureDriverGL *driver, + CoglContext *context, + CoglPixelFormat format, + GLenum *closest_gl_format, + GLenum *closest_gl_type) { CoglDriverGL *driver_gl = COGL_DRIVER_GL (context->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); @@ -509,8 +509,10 @@ cogl_texture_driver_gl3_texture_2d_gl_get_data (CoglTextureDriver *driver, uint8_t *data) { CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d)); - CoglTextureDriverClass *tex_driver = - COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver); + CoglTextureDriverGL *tex_driver_gl = + COGL_TEXTURE_DRIVER_GL (ctx->texture_driver); + CoglTextureDriverGLClass *tex_driver_klass = + COGL_TEXTURE_DRIVER_GL_GET_CLASS (tex_driver_gl); CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver); CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl); uint8_t bpp; @@ -530,38 +532,40 @@ cogl_texture_driver_gl3_texture_2d_gl_get_data (CoglTextureDriver *driver, &gl_format, &gl_type); - tex_driver->prep_gl_for_pixels_download (ctx->texture_driver, - ctx, - rowstride, - width, - bpp); + tex_driver_klass->prep_gl_for_pixels_download (tex_driver_gl, + ctx, + rowstride, + width, + bpp); _cogl_bind_gl_texture_transient (ctx, tex_2d->gl_target, tex_2d->gl_texture); - tex_driver->gl_get_tex_image (ctx->texture_driver, - ctx, - tex_2d->gl_target, - gl_format, - gl_type, - data); + tex_driver_klass->gl_get_tex_image (tex_driver_gl, + ctx, + tex_2d->gl_target, + gl_format, + gl_type, + data); } static void cogl_texture_driver_gl3_class_init (CoglTextureDriverGL3Class *klass) { CoglTextureDriverClass *driver_klass = COGL_TEXTURE_DRIVER_CLASS (klass); + CoglTextureDriverGLClass *driver_gl_klass = COGL_TEXTURE_DRIVER_GL_CLASS (klass); - driver_klass->gen = cogl_texture_driver_gl3_gen; - driver_klass->upload_subregion_to_gl = cogl_texture_driver_gl3_upload_subregion_to_gl; - driver_klass->upload_to_gl = cogl_texture_driver_gl3_upload_to_gl; - driver_klass->prep_gl_for_pixels_download = cogl_texture_driver_gl3_prep_gl_for_pixels_download; - driver_klass->gl_get_tex_image = cogl_texture_driver_gl3_gl_get_tex_image; - driver_klass->size_supported = cogl_texture_driver_gl3_size_supported; driver_klass->format_supports_upload = cogl_texture_driver_gl3_upload_supported; - driver_klass->find_best_gl_get_data_format = cogl_texture_driver_gl3_find_best_gl_get_data_format; driver_klass->texture_2d_is_get_data_supported = cogl_texture_driver_gl3_is_get_data_supported; driver_klass->texture_2d_get_data = cogl_texture_driver_gl3_texture_2d_gl_get_data; + + driver_gl_klass->gen = cogl_texture_driver_gl3_gen; + driver_gl_klass->upload_subregion_to_gl = cogl_texture_driver_gl3_upload_subregion_to_gl; + driver_gl_klass->upload_to_gl = cogl_texture_driver_gl3_upload_to_gl; + driver_gl_klass->prep_gl_for_pixels_download = cogl_texture_driver_gl3_prep_gl_for_pixels_download; + driver_gl_klass->gl_get_tex_image = cogl_texture_driver_gl3_gl_get_tex_image; + driver_gl_klass->size_supported = cogl_texture_driver_gl3_size_supported; + driver_gl_klass->find_best_gl_get_data_format = cogl_texture_driver_gl3_find_best_gl_get_data_format; } static void diff --git a/cogl/cogl/driver/gl/gles2/cogl-texture-driver-gles2.c b/cogl/cogl/driver/gl/gles2/cogl-texture-driver-gles2.c index bdc276a2f..e2ae6f00b 100644 --- a/cogl/cogl/driver/gl/gles2/cogl-texture-driver-gles2.c +++ b/cogl/cogl/driver/gl/gles2/cogl-texture-driver-gles2.c @@ -82,10 +82,10 @@ G_DEFINE_FINAL_TYPE (CoglTextureDriverGLES2, COGL_TYPE_TEXTURE_DRIVER_GL) static GLuint -cogl_texture_driver_gles2_gen (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - CoglPixelFormat internal_format) +cogl_texture_driver_gles2_gen (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + CoglPixelFormat internal_format) { GLuint tex; @@ -146,11 +146,11 @@ _cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx, } static void -cogl_texture_driver_gles2_prep_gl_for_pixels_download (CoglTextureDriver *driver, - CoglContext *ctx, - int pixels_rowstride, - int image_width, - int pixels_bpp) +cogl_texture_driver_gles2_prep_gl_for_pixels_download (CoglTextureDriverGL *driver, + CoglContext *ctx, + int pixels_rowstride, + int image_width, + int pixels_bpp) { _cogl_texture_gl_prep_alignment_for_pixels_download (ctx, pixels_bpp, @@ -193,20 +193,20 @@ prepare_bitmap_alignment_for_upload (CoglContext *ctx, } static gboolean -cogl_texture_driver_gles2_upload_subregion_to_gl (CoglTextureDriver *driver, - CoglContext *ctx, - CoglTexture *texture, - int src_x, - int src_y, - int dst_x, - int dst_y, - int width, - int height, - int level, - CoglBitmap *source_bmp, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error) +cogl_texture_driver_gles2_upload_subregion_to_gl (CoglTextureDriverGL *driver, + CoglContext *ctx, + CoglTexture *texture, + int src_x, + int src_y, + int dst_x, + int dst_y, + int width, + int height, + int level, + CoglBitmap *source_bmp, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error) { GLenum gl_target; GLuint gl_handle; @@ -349,15 +349,15 @@ cogl_texture_driver_gles2_upload_subregion_to_gl (CoglTextureDriver *driver, } static gboolean -cogl_texture_driver_gles2_upload_to_gl (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLuint gl_handle, - CoglBitmap *source_bmp, - GLint internal_gl_format, - GLuint source_gl_format, - GLuint source_gl_type, - GError **error) +cogl_texture_driver_gles2_upload_to_gl (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLuint gl_handle, + CoglBitmap *source_bmp, + GLint internal_gl_format, + GLuint source_gl_format, + GLuint source_gl_type, + GError **error) { CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp); int bpp; @@ -426,25 +426,25 @@ cogl_texture_driver_gles2_upload_to_gl (CoglTextureDriver *driver, * fallback to a generic render + readpixels approach to downloading * texture data. (See _cogl_texture_draw_and_read() ) */ static gboolean -cogl_texture_driver_gles2_gl_get_tex_image (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum dest_gl_format, - GLenum dest_gl_type, - uint8_t *dest) +cogl_texture_driver_gles2_gl_get_tex_image (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum dest_gl_format, + GLenum dest_gl_type, + uint8_t *dest) { return FALSE; } static gboolean -cogl_texture_driver_gles2_size_supported (CoglTextureDriver *driver, - CoglContext *ctx, - GLenum gl_target, - GLenum gl_intformat, - GLenum gl_format, - GLenum gl_type, - int width, - int height) +cogl_texture_driver_gles2_size_supported (CoglTextureDriverGL *driver, + CoglContext *ctx, + GLenum gl_target, + GLenum gl_intformat, + GLenum gl_format, + GLenum gl_type, + int width, + int height) { GLint max_size; @@ -545,11 +545,11 @@ cogl_texture_driver_gles2_upload_supported (CoglTextureDriver *driver, } static CoglPixelFormat -cogl_texture_driver_gles2_find_best_gl_get_data_format (CoglTextureDriver *driver, - CoglContext *context, - CoglPixelFormat format, - GLenum *closest_gl_format, - GLenum *closest_gl_type) +cogl_texture_driver_gles2_find_best_gl_get_data_format (CoglTextureDriverGL *driver, + CoglContext *context, + CoglPixelFormat format, + GLenum *closest_gl_format, + GLenum *closest_gl_type) { /* Find closest format that's supported by GL (Can't use _cogl_pixel_format_to_gl since available formats @@ -570,16 +570,18 @@ static void cogl_texture_driver_gles2_class_init (CoglTextureDriverGLES2Class *klass) { CoglTextureDriverClass *driver_klass = COGL_TEXTURE_DRIVER_CLASS (klass); + CoglTextureDriverGLClass *driver_gl_klass = COGL_TEXTURE_DRIVER_GL_CLASS (klass); - driver_klass->gen = cogl_texture_driver_gles2_gen; - driver_klass->upload_subregion_to_gl = cogl_texture_driver_gles2_upload_subregion_to_gl; - driver_klass->upload_to_gl = cogl_texture_driver_gles2_upload_to_gl; - driver_klass->prep_gl_for_pixels_download = cogl_texture_driver_gles2_prep_gl_for_pixels_download; - driver_klass->gl_get_tex_image = cogl_texture_driver_gles2_gl_get_tex_image; - driver_klass->size_supported = cogl_texture_driver_gles2_size_supported; - driver_klass->format_supports_upload = cogl_texture_driver_gles2_upload_supported; - driver_klass->find_best_gl_get_data_format = cogl_texture_driver_gles2_find_best_gl_get_data_format; driver_klass->texture_2d_is_get_data_supported = cogl_texture_driver_gles2_texture_2d_is_get_data_supported; + driver_klass->format_supports_upload = cogl_texture_driver_gles2_upload_supported; + + driver_gl_klass->gen = cogl_texture_driver_gles2_gen; + driver_gl_klass->upload_subregion_to_gl = cogl_texture_driver_gles2_upload_subregion_to_gl; + driver_gl_klass->upload_to_gl = cogl_texture_driver_gles2_upload_to_gl; + driver_gl_klass->prep_gl_for_pixels_download = cogl_texture_driver_gles2_prep_gl_for_pixels_download; + driver_gl_klass->gl_get_tex_image = cogl_texture_driver_gles2_gl_get_tex_image; + driver_gl_klass->size_supported = cogl_texture_driver_gles2_size_supported; + driver_gl_klass->find_best_gl_get_data_format = cogl_texture_driver_gles2_find_best_gl_get_data_format; } static void