cogl: Turn TextureDriver into an abstract object
The motivation is to ease sharing bits between the various texture drivers implementations. The same thing would be done for DriverVtable & WinsysVtable. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4163>
This commit is contained in:

committed by
Marge Bot

parent
9181fdf5c2
commit
4f16f6df3b
@ -193,6 +193,8 @@ _cogl_atlas_get_initial_size (CoglContext *ctx,
|
|||||||
unsigned int *map_width,
|
unsigned int *map_width,
|
||||||
unsigned int *map_height)
|
unsigned int *map_height)
|
||||||
{
|
{
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
GLenum gl_intformat;
|
GLenum gl_intformat;
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
@ -219,12 +221,13 @@ _cogl_atlas_get_initial_size (CoglContext *ctx,
|
|||||||
/* Some platforms might not support this large size so we'll
|
/* Some platforms might not support this large size so we'll
|
||||||
decrease the size until it can */
|
decrease the size until it can */
|
||||||
while (size > 1 &&
|
while (size > 1 &&
|
||||||
!ctx->texture_driver->size_supported (ctx,
|
!tex_driver->size_supported (ctx->texture_driver,
|
||||||
GL_TEXTURE_2D,
|
ctx,
|
||||||
gl_intformat,
|
GL_TEXTURE_2D,
|
||||||
gl_format,
|
gl_intformat,
|
||||||
gl_type,
|
gl_format,
|
||||||
size, size))
|
gl_type,
|
||||||
|
size, size))
|
||||||
size >>= 1;
|
size >>= 1;
|
||||||
|
|
||||||
*map_width = size;
|
*map_width = size;
|
||||||
@ -239,6 +242,8 @@ _cogl_atlas_create_map (CoglContext *ctx,
|
|||||||
unsigned int n_textures,
|
unsigned int n_textures,
|
||||||
CoglAtlasRepositionData *textures)
|
CoglAtlasRepositionData *textures)
|
||||||
{
|
{
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
GLenum gl_intformat;
|
GLenum gl_intformat;
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
GLenum gl_type;
|
GLenum gl_type;
|
||||||
@ -251,12 +256,13 @@ _cogl_atlas_create_map (CoglContext *ctx,
|
|||||||
|
|
||||||
/* Keep trying increasingly larger atlases until we can fit all of
|
/* Keep trying increasingly larger atlases until we can fit all of
|
||||||
the textures */
|
the textures */
|
||||||
while (ctx->texture_driver->size_supported (ctx,
|
while (tex_driver->size_supported (ctx->texture_driver,
|
||||||
GL_TEXTURE_2D,
|
ctx,
|
||||||
gl_intformat,
|
GL_TEXTURE_2D,
|
||||||
gl_format,
|
gl_intformat,
|
||||||
gl_type,
|
gl_format,
|
||||||
map_width, map_height))
|
gl_type,
|
||||||
|
map_width, map_height))
|
||||||
{
|
{
|
||||||
CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width,
|
CoglRectangleMap *new_atlas = _cogl_rectangle_map_new (map_width,
|
||||||
map_height,
|
map_height,
|
||||||
|
@ -73,7 +73,7 @@ struct _CoglContext
|
|||||||
|
|
||||||
/* vtables for the driver functions */
|
/* vtables for the driver functions */
|
||||||
const CoglDriverVtable *driver_vtable;
|
const CoglDriverVtable *driver_vtable;
|
||||||
const CoglTextureDriver *texture_driver;
|
CoglTextureDriver *texture_driver;
|
||||||
|
|
||||||
void *driver_context;
|
void *driver_context;
|
||||||
|
|
||||||
|
@ -462,7 +462,10 @@ gboolean
|
|||||||
cogl_context_format_supports_upload (CoglContext *ctx,
|
cogl_context_format_supports_upload (CoglContext *ctx,
|
||||||
CoglPixelFormat format)
|
CoglPixelFormat format)
|
||||||
{
|
{
|
||||||
return ctx->texture_driver->format_supports_upload (ctx, format);
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
|
|
||||||
|
return tex_driver->format_supports_upload (ctx->texture_driver, ctx, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -49,7 +49,7 @@ struct _CoglRenderer
|
|||||||
gboolean connected;
|
gboolean connected;
|
||||||
CoglDriver driver_override;
|
CoglDriver driver_override;
|
||||||
const CoglDriverVtable *driver_vtable;
|
const CoglDriverVtable *driver_vtable;
|
||||||
const CoglTextureDriver *texture_driver;
|
CoglTextureDriver *texture_driver;
|
||||||
const CoglWinsysVtable *winsys_vtable;
|
const CoglWinsysVtable *winsys_vtable;
|
||||||
void *custom_winsys_user_data;
|
void *custom_winsys_user_data;
|
||||||
CoglCustomWinsysVtableGetter custom_winsys_vtable_getter;
|
CoglCustomWinsysVtableGetter custom_winsys_vtable_getter;
|
||||||
|
@ -53,16 +53,21 @@
|
|||||||
#include "cogl/winsys/cogl-winsys-glx-private.h"
|
#include "cogl/winsys/cogl-winsys-glx-private.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_GL
|
||||||
|
#include "cogl/driver/gl/gl/cogl-texture-driver-gl3-private.h"
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GLES2
|
||||||
|
#include "cogl/driver/gl/gles/cogl-texture-driver-gles2-private.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
#include "cogl/cogl-xlib-renderer.h"
|
#include "cogl/cogl-xlib-renderer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GL
|
#ifdef HAVE_GL
|
||||||
extern const CoglTextureDriver _cogl_texture_driver_gl;
|
|
||||||
extern const CoglDriverVtable _cogl_driver_gl;
|
extern const CoglDriverVtable _cogl_driver_gl;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_GLES2
|
#ifdef HAVE_GLES2
|
||||||
extern const CoglTextureDriver _cogl_texture_driver_gles;
|
|
||||||
extern const CoglDriverVtable _cogl_driver_gles;
|
extern const CoglDriverVtable _cogl_driver_gles;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -79,7 +84,6 @@ typedef struct _CoglDriverDescription
|
|||||||
* driver. */
|
* driver. */
|
||||||
const CoglPrivateFeature private_features[8];
|
const CoglPrivateFeature private_features[8];
|
||||||
const CoglDriverVtable *vtable;
|
const CoglDriverVtable *vtable;
|
||||||
const CoglTextureDriver *texture_driver;
|
|
||||||
const char *libgl_name;
|
const char *libgl_name;
|
||||||
} CoglDriverDescription;
|
} CoglDriverDescription;
|
||||||
|
|
||||||
@ -92,7 +96,6 @@ static CoglDriverDescription _cogl_drivers[] =
|
|||||||
{ COGL_PRIVATE_FEATURE_ANY_GL,
|
{ COGL_PRIVATE_FEATURE_ANY_GL,
|
||||||
-1 },
|
-1 },
|
||||||
&_cogl_driver_gl,
|
&_cogl_driver_gl,
|
||||||
&_cogl_texture_driver_gl,
|
|
||||||
COGL_GL_LIBNAME,
|
COGL_GL_LIBNAME,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
@ -103,7 +106,6 @@ static CoglDriverDescription _cogl_drivers[] =
|
|||||||
{ COGL_PRIVATE_FEATURE_ANY_GL,
|
{ COGL_PRIVATE_FEATURE_ANY_GL,
|
||||||
-1 },
|
-1 },
|
||||||
&_cogl_driver_gles,
|
&_cogl_driver_gles,
|
||||||
&_cogl_texture_driver_gles,
|
|
||||||
COGL_GLES2_LIBNAME,
|
COGL_GLES2_LIBNAME,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
@ -112,7 +114,6 @@ static CoglDriverDescription _cogl_drivers[] =
|
|||||||
"nop",
|
"nop",
|
||||||
{ -1 },
|
{ -1 },
|
||||||
&_cogl_driver_nop,
|
&_cogl_driver_nop,
|
||||||
NULL, /* texture driver */
|
|
||||||
NULL /* libgl_name */
|
NULL /* libgl_name */
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -165,6 +166,8 @@ cogl_renderer_dispose (GObject *object)
|
|||||||
g_slist_free_full (renderer->event_filters,
|
g_slist_free_full (renderer->event_filters,
|
||||||
(GDestroyNotify) native_filter_closure_free);
|
(GDestroyNotify) native_filter_closure_free);
|
||||||
|
|
||||||
|
g_clear_object (&renderer->texture_driver);
|
||||||
|
|
||||||
G_OBJECT_CLASS (cogl_renderer_parent_class)->dispose (object);
|
G_OBJECT_CLASS (cogl_renderer_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +377,26 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
|
|||||||
desc = state.driver_description;
|
desc = state.driver_description;
|
||||||
renderer->driver = desc->id;
|
renderer->driver = desc->id;
|
||||||
renderer->driver_vtable = desc->vtable;
|
renderer->driver_vtable = desc->vtable;
|
||||||
renderer->texture_driver = desc->texture_driver;
|
|
||||||
|
switch (renderer->driver)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GL
|
||||||
|
case COGL_DRIVER_GL3:
|
||||||
|
renderer->texture_driver = g_object_new (COGL_TYPE_TEXTURE_DRIVER_GL3, NULL);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GLES2
|
||||||
|
case COGL_DRIVER_GLES2:
|
||||||
|
renderer->texture_driver = g_object_new (COGL_TYPE_TEXTURE_DRIVER_GLES2, NULL);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case COGL_DRIVER_NOP:
|
||||||
|
default:
|
||||||
|
renderer->texture_driver = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
libgl_name = desc->libgl_name;
|
libgl_name = desc->libgl_name;
|
||||||
|
|
||||||
memset(renderer->private_features, 0, sizeof (renderer->private_features));
|
memset(renderer->private_features, 0, sizeof (renderer->private_features));
|
||||||
|
45
cogl/cogl/cogl-texture-driver.c
Normal file
45
cogl/cogl/cogl-texture-driver.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Cogl
|
||||||
|
*
|
||||||
|
* A Low Level GPU Graphics and Utilities API
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Red Hat.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "cogl/cogl-texture-driver.h"
|
||||||
|
|
||||||
|
G_DEFINE_ABSTRACT_TYPE (CoglTextureDriver, cogl_texture_driver, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_texture_driver_class_init (CoglTextureDriverClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_texture_driver_init (CoglTextureDriver *driver)
|
||||||
|
{
|
||||||
|
}
|
@ -30,19 +30,33 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef struct _CoglTextureDriver CoglTextureDriver;
|
#include <glib-object.h>
|
||||||
|
|
||||||
struct _CoglTextureDriver
|
#include "cogl/cogl-gl-header.h"
|
||||||
|
#include "cogl/cogl-pixel-format.h"
|
||||||
|
#include "cogl/cogl-types.h"
|
||||||
|
|
||||||
|
G_DECLARE_DERIVABLE_TYPE (CoglTextureDriver,
|
||||||
|
cogl_texture_driver,
|
||||||
|
COGL,
|
||||||
|
TEXTURE_DRIVER,
|
||||||
|
GObject)
|
||||||
|
|
||||||
|
#define COGL_TYPE_TEXTURE_DRIVER (cogl_texture_driver_get_type ())
|
||||||
|
|
||||||
|
struct _CoglTextureDriverClass
|
||||||
{
|
{
|
||||||
|
GObjectClass parent_class;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A very small wrapper around glGenTextures() that ensures we default to
|
* A very small wrapper around glGenTextures() that ensures we default to
|
||||||
* non-mipmap filters when creating textures. This is to save some memory as
|
* non-mipmap filters when creating textures. This is to save some memory as
|
||||||
* the driver will not allocate room for the mipmap tree.
|
* the driver will not allocate room for the mipmap tree.
|
||||||
*/
|
*/
|
||||||
GLuint
|
GLuint (* gen) (CoglTextureDriver *driver,
|
||||||
(* gen) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
GLenum gl_target,
|
GLenum gl_target,
|
||||||
CoglPixelFormat internal_format);
|
CoglPixelFormat internal_format);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This uploads a sub-region from source_bmp to a single GL texture
|
* This uploads a sub-region from source_bmp to a single GL texture
|
||||||
@ -57,20 +71,20 @@ struct _CoglTextureDriver
|
|||||||
*
|
*
|
||||||
* XXX: sorry for the ridiculous number of arguments :-(
|
* XXX: sorry for the ridiculous number of arguments :-(
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean (* upload_subregion_to_gl) (CoglTextureDriver *driver,
|
||||||
(* upload_subregion_to_gl) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
CoglTexture *texture,
|
CoglTexture *texture,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int dst_x,
|
int dst_x,
|
||||||
int dst_y,
|
int dst_y,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int level,
|
int level,
|
||||||
CoglBitmap *source_bmp,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLuint source_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_type,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replaces the contents of the GL texture with the entire bitmap. On
|
* Replaces the contents of the GL texture with the entire bitmap. On
|
||||||
@ -78,15 +92,15 @@ struct _CoglTextureDriver
|
|||||||
* to copy the bitmap if the rowstride is not a multiple of a possible
|
* to copy the bitmap if the rowstride is not a multiple of a possible
|
||||||
* alignment value because there is no GL_UNPACK_ROW_LENGTH
|
* alignment value because there is no GL_UNPACK_ROW_LENGTH
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean (* upload_to_gl) (CoglTextureDriver *driver,
|
||||||
(* upload_to_gl) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
GLenum gl_target,
|
GLenum gl_target,
|
||||||
GLuint gl_handle,
|
GLuint gl_handle,
|
||||||
CoglBitmap *source_bmp,
|
CoglBitmap *source_bmp,
|
||||||
GLint internal_gl_format,
|
GLint internal_gl_format,
|
||||||
GLuint source_gl_format,
|
GLuint source_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_type,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This sets up the glPixelStore state for an download to a destination with
|
* This sets up the glPixelStore state for an download to a destination with
|
||||||
@ -95,11 +109,11 @@ struct _CoglTextureDriver
|
|||||||
/* NB: GLES can't download pixel data into a sub region of a larger
|
/* 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
|
* destination buffer, the GL driver has a more flexible version of
|
||||||
* this function that it uses internally. */
|
* this function that it uses internally. */
|
||||||
void
|
void (* prep_gl_for_pixels_download) (CoglTextureDriver *driver,
|
||||||
(* prep_gl_for_pixels_download) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
int image_width,
|
int image_width,
|
||||||
int pixels_rowstride,
|
int pixels_rowstride,
|
||||||
int pixels_bpp);
|
int pixels_bpp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This driver abstraction is needed because GLES doesn't support
|
* This driver abstraction is needed because GLES doesn't support
|
||||||
@ -108,29 +122,29 @@ struct _CoglTextureDriver
|
|||||||
* renders the texture and reads it back from the framebuffer. (See
|
* renders the texture and reads it back from the framebuffer. (See
|
||||||
* _cogl_texture_draw_and_read () )
|
* _cogl_texture_draw_and_read () )
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean (* gl_get_tex_image) (CoglTextureDriver *driver,
|
||||||
(* gl_get_tex_image) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
GLenum gl_target,
|
GLenum gl_target,
|
||||||
GLenum dest_gl_format,
|
GLenum dest_gl_format,
|
||||||
GLenum dest_gl_type,
|
GLenum dest_gl_type,
|
||||||
uint8_t *dest);
|
uint8_t *dest);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It may depend on the driver as to what texture sizes are supported...
|
* It may depend on the driver as to what texture sizes are supported...
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean (* size_supported) (CoglTextureDriver *driver,
|
||||||
(* size_supported) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
GLenum gl_target,
|
GLenum gl_target,
|
||||||
GLenum gl_intformat,
|
GLenum gl_intformat,
|
||||||
GLenum gl_format,
|
GLenum gl_format,
|
||||||
GLenum gl_type,
|
GLenum gl_type,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean (* format_supports_upload) (CoglTextureDriver *driver,
|
||||||
(* format_supports_upload) (CoglContext *ctx,
|
CoglContext *ctx,
|
||||||
CoglPixelFormat format);
|
CoglPixelFormat format);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The driver may impose constraints on what formats can be used to store
|
* The driver may impose constraints on what formats can be used to store
|
||||||
@ -138,9 +152,9 @@ struct _CoglTextureDriver
|
|||||||
* RGBA_8888, and so we need to manually convert the data if the final
|
* RGBA_8888, and so we need to manually convert the data if the final
|
||||||
* destination has another format.
|
* destination has another format.
|
||||||
*/
|
*/
|
||||||
CoglPixelFormat
|
CoglPixelFormat (* find_best_gl_get_data_format) (CoglTextureDriver *driver,
|
||||||
(* find_best_gl_get_data_format) (CoglContext *context,
|
CoglContext *context,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
GLenum *closest_gl_format,
|
GLenum *closest_gl_format,
|
||||||
GLenum *closest_gl_type);
|
GLenum *closest_gl_type);
|
||||||
};
|
};
|
||||||
|
@ -811,6 +811,7 @@ cogl_texture_get_data (CoglTexture *texture,
|
|||||||
uint8_t *data)
|
uint8_t *data)
|
||||||
{
|
{
|
||||||
CoglContext *ctx;
|
CoglContext *ctx;
|
||||||
|
CoglTextureDriverClass *tex_driver;
|
||||||
int bpp;
|
int bpp;
|
||||||
int byte_size;
|
int byte_size;
|
||||||
CoglPixelFormat closest_format;
|
CoglPixelFormat closest_format;
|
||||||
@ -848,11 +849,13 @@ cogl_texture_get_data (CoglTexture *texture,
|
|||||||
return byte_size;
|
return byte_size;
|
||||||
|
|
||||||
ctx = cogl_texture_get_context (texture);
|
ctx = cogl_texture_get_context (texture);
|
||||||
|
tex_driver = COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
closest_format =
|
closest_format =
|
||||||
ctx->texture_driver->find_best_gl_get_data_format (ctx,
|
tex_driver->find_best_gl_get_data_format (ctx->texture_driver,
|
||||||
format,
|
ctx,
|
||||||
&closest_gl_format,
|
format,
|
||||||
&closest_gl_type);
|
&closest_gl_format,
|
||||||
|
&closest_gl_type);
|
||||||
|
|
||||||
/* We can assume that whatever data GL gives us will have the
|
/* We can assume that whatever data GL gives us will have the
|
||||||
premult status of the original texture */
|
premult status of the original texture */
|
||||||
|
@ -463,6 +463,8 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
|
|||||||
int bpp, rowstride;
|
int bpp, rowstride;
|
||||||
uint8_t *tmp_data;
|
uint8_t *tmp_data;
|
||||||
gboolean succeeded;
|
gboolean succeeded;
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
|
|
||||||
if (_cogl_pixel_format_can_have_premult (read_format))
|
if (_cogl_pixel_format_can_have_premult (read_format))
|
||||||
{
|
{
|
||||||
@ -480,10 +482,11 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
|
|||||||
bpp = cogl_pixel_format_get_bytes_per_pixel (read_format, 0);
|
bpp = cogl_pixel_format_get_bytes_per_pixel (read_format, 0);
|
||||||
rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
|
rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
|
||||||
|
|
||||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
tex_driver->prep_gl_for_pixels_download (ctx->texture_driver,
|
||||||
rowstride,
|
ctx,
|
||||||
width,
|
rowstride,
|
||||||
bpp);
|
width,
|
||||||
|
bpp);
|
||||||
|
|
||||||
/* Note: we don't worry about catching errors here since we know
|
/* Note: we don't worry about catching errors here since we know
|
||||||
* we won't be lazily allocating storage for this buffer so it
|
* we won't be lazily allocating storage for this buffer so it
|
||||||
@ -522,6 +525,8 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
|
|||||||
gboolean succeeded = FALSE;
|
gboolean succeeded = FALSE;
|
||||||
uint8_t *pixels;
|
uint8_t *pixels;
|
||||||
GError *internal_error = NULL;
|
GError *internal_error = NULL;
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
|
|
||||||
rowstride = cogl_bitmap_get_rowstride (bitmap);
|
rowstride = cogl_bitmap_get_rowstride (bitmap);
|
||||||
|
|
||||||
@ -544,10 +549,11 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
|
|||||||
|
|
||||||
bpp = cogl_pixel_format_get_bytes_per_pixel (bmp_format, 0);
|
bpp = cogl_pixel_format_get_bytes_per_pixel (bmp_format, 0);
|
||||||
|
|
||||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
tex_driver->prep_gl_for_pixels_download (ctx->texture_driver,
|
||||||
rowstride,
|
ctx,
|
||||||
width,
|
rowstride,
|
||||||
bpp);
|
width,
|
||||||
|
bpp);
|
||||||
|
|
||||||
pixels = _cogl_bitmap_gl_bind (shared_bmp,
|
pixels = _cogl_bitmap_gl_bind (shared_bmp,
|
||||||
COGL_BUFFER_ACCESS_WRITE,
|
COGL_BUFFER_ACCESS_WRITE,
|
||||||
|
@ -78,6 +78,8 @@ _cogl_texture_2d_gl_can_create (CoglContext *ctx,
|
|||||||
int height,
|
int height,
|
||||||
CoglPixelFormat internal_format)
|
CoglPixelFormat internal_format)
|
||||||
{
|
{
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
GLenum gl_intformat;
|
GLenum gl_intformat;
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
GLenum gl_type;
|
GLenum gl_type;
|
||||||
@ -93,13 +95,14 @@ _cogl_texture_2d_gl_can_create (CoglContext *ctx,
|
|||||||
&gl_type);
|
&gl_type);
|
||||||
|
|
||||||
/* Check that the driver can create a texture with that size */
|
/* Check that the driver can create a texture with that size */
|
||||||
if (!ctx->texture_driver->size_supported (ctx,
|
if (!tex_driver->size_supported (ctx->texture_driver,
|
||||||
GL_TEXTURE_2D,
|
ctx,
|
||||||
gl_intformat,
|
GL_TEXTURE_2D,
|
||||||
gl_format,
|
gl_intformat,
|
||||||
gl_type,
|
gl_format,
|
||||||
width,
|
gl_type,
|
||||||
height))
|
width,
|
||||||
|
height))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -132,6 +135,8 @@ allocate_with_size (CoglTexture2D *tex_2d,
|
|||||||
int width = loader->src.sized.width;
|
int width = loader->src.sized.width;
|
||||||
int height = loader->src.sized.height;
|
int height = loader->src.sized.height;
|
||||||
CoglContext *ctx = cogl_texture_get_context (tex);
|
CoglContext *ctx = cogl_texture_get_context (tex);
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
GLenum gl_intformat;
|
GLenum gl_intformat;
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
GLenum gl_type;
|
GLenum gl_type;
|
||||||
@ -158,7 +163,10 @@ allocate_with_size (CoglTexture2D *tex_2d,
|
|||||||
&gl_format,
|
&gl_format,
|
||||||
&gl_type);
|
&gl_type);
|
||||||
|
|
||||||
gl_texture = ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
|
gl_texture = tex_driver->gen (ctx->texture_driver,
|
||||||
|
ctx,
|
||||||
|
GL_TEXTURE_2D,
|
||||||
|
internal_format);
|
||||||
|
|
||||||
tex_2d->gl_internal_format = gl_intformat;
|
tex_2d->gl_internal_format = gl_intformat;
|
||||||
|
|
||||||
@ -195,6 +203,8 @@ allocate_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
||||||
CoglBitmap *bmp = loader->src.bitmap.bitmap;
|
CoglBitmap *bmp = loader->src.bitmap.bitmap;
|
||||||
CoglContext *ctx = _cogl_bitmap_get_context (bmp);
|
CoglContext *ctx = _cogl_bitmap_get_context (bmp);
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
CoglPixelFormat internal_format;
|
CoglPixelFormat internal_format;
|
||||||
int width = cogl_bitmap_get_width (bmp);
|
int width = cogl_bitmap_get_width (bmp);
|
||||||
int height = cogl_bitmap_get_height (bmp);
|
int height = cogl_bitmap_get_height (bmp);
|
||||||
@ -235,16 +245,19 @@ allocate_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
tex_2d->gl_texture =
|
tex_2d->gl_texture = tex_driver->gen (ctx->texture_driver,
|
||||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
|
ctx,
|
||||||
if (!ctx->texture_driver->upload_to_gl (ctx,
|
GL_TEXTURE_2D,
|
||||||
GL_TEXTURE_2D,
|
internal_format);
|
||||||
tex_2d->gl_texture,
|
if (!tex_driver->upload_to_gl (ctx->texture_driver,
|
||||||
upload_bmp,
|
ctx,
|
||||||
gl_intformat,
|
GL_TEXTURE_2D,
|
||||||
gl_format,
|
tex_2d->gl_texture,
|
||||||
gl_type,
|
upload_bmp,
|
||||||
error))
|
gl_intformat,
|
||||||
|
gl_format,
|
||||||
|
gl_type,
|
||||||
|
error))
|
||||||
{
|
{
|
||||||
g_object_unref (upload_bmp);
|
g_object_unref (upload_bmp);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -270,9 +283,13 @@ allocate_from_egl_image (CoglTexture2D *tex_2d,
|
|||||||
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
||||||
CoglContext *ctx = cogl_texture_get_context (tex);
|
CoglContext *ctx = cogl_texture_get_context (tex);
|
||||||
CoglPixelFormat internal_format = loader->src.egl_image.format;
|
CoglPixelFormat internal_format = loader->src.egl_image.format;
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
|
|
||||||
tex_2d->gl_texture =
|
tex_2d->gl_texture = tex_driver->gen (ctx->texture_driver,
|
||||||
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
|
ctx,
|
||||||
|
GL_TEXTURE_2D,
|
||||||
|
internal_format);
|
||||||
|
|
||||||
if (!cogl_texture_2d_gl_bind_egl_image (tex_2d,
|
if (!cogl_texture_2d_gl_bind_egl_image (tex_2d,
|
||||||
loader->src.egl_image.image,
|
loader->src.egl_image.image,
|
||||||
@ -567,6 +584,8 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
{
|
{
|
||||||
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
||||||
CoglContext *ctx = cogl_texture_get_context (tex);
|
CoglContext *ctx = cogl_texture_get_context (tex);
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
CoglBitmap *upload_bmp;
|
CoglBitmap *upload_bmp;
|
||||||
CoglPixelFormat upload_format;
|
CoglPixelFormat upload_format;
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
@ -596,16 +615,17 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
|
|||||||
if (cogl_texture_get_max_level_set (tex) < level)
|
if (cogl_texture_get_max_level_set (tex) < level)
|
||||||
cogl_texture_gl_set_max_level (tex, level);
|
cogl_texture_gl_set_max_level (tex, level);
|
||||||
|
|
||||||
status = ctx->texture_driver->upload_subregion_to_gl (ctx,
|
status = tex_driver->upload_subregion_to_gl (ctx->texture_driver,
|
||||||
tex,
|
ctx,
|
||||||
src_x, src_y,
|
tex,
|
||||||
dst_x, dst_y,
|
src_x, src_y,
|
||||||
width, height,
|
dst_x, dst_y,
|
||||||
level,
|
width, height,
|
||||||
upload_bmp,
|
level,
|
||||||
gl_format,
|
upload_bmp,
|
||||||
gl_type,
|
gl_format,
|
||||||
error);
|
gl_type,
|
||||||
|
error);
|
||||||
|
|
||||||
g_object_unref (upload_bmp);
|
g_object_unref (upload_bmp);
|
||||||
|
|
||||||
@ -625,6 +645,8 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
|
|||||||
uint8_t *data)
|
uint8_t *data)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
|
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
|
||||||
|
CoglTextureDriverClass *tex_driver =
|
||||||
|
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||||
uint8_t bpp;
|
uint8_t bpp;
|
||||||
int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
|
int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
|
||||||
GLenum gl_format;
|
GLenum gl_format;
|
||||||
@ -641,17 +663,19 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
|
|||||||
&gl_format,
|
&gl_format,
|
||||||
&gl_type);
|
&gl_type);
|
||||||
|
|
||||||
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
tex_driver->prep_gl_for_pixels_download (ctx->texture_driver,
|
||||||
rowstride,
|
ctx,
|
||||||
width,
|
rowstride,
|
||||||
bpp);
|
width,
|
||||||
|
bpp);
|
||||||
|
|
||||||
_cogl_bind_gl_texture_transient (ctx, tex_2d->gl_target,
|
_cogl_bind_gl_texture_transient (ctx, tex_2d->gl_target,
|
||||||
tex_2d->gl_texture);
|
tex_2d->gl_texture);
|
||||||
|
|
||||||
ctx->texture_driver->gl_get_tex_image (ctx,
|
tex_driver->gl_get_tex_image (ctx->texture_driver,
|
||||||
tex_2d->gl_target,
|
ctx,
|
||||||
gl_format,
|
tex_2d->gl_target,
|
||||||
gl_type,
|
gl_format,
|
||||||
data);
|
gl_type,
|
||||||
|
data);
|
||||||
}
|
}
|
||||||
|
40
cogl/cogl/driver/gl/gl/cogl-texture-driver-gl3-private.h
Normal file
40
cogl/cogl/driver/gl/gl/cogl-texture-driver-gl3-private.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Cogl
|
||||||
|
*
|
||||||
|
* A Low Level GPU Graphics and Utilities API
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Red Hat.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cogl/cogl-texture-driver.h"
|
||||||
|
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (CoglTextureDriverGL3,
|
||||||
|
cogl_texture_driver_gl3,
|
||||||
|
COGL,
|
||||||
|
TEXTURE_DRIVER_GL3,
|
||||||
|
CoglTextureDriver)
|
||||||
|
|
||||||
|
#define COGL_TYPE_TEXTURE_DRIVER_GL3 (cogl_texture_driver_gl3_get_type ())
|
@ -42,6 +42,7 @@
|
|||||||
#include "cogl/cogl-texture-private.h"
|
#include "cogl/cogl-texture-private.h"
|
||||||
#include "cogl/cogl-pipeline.h"
|
#include "cogl/cogl-pipeline.h"
|
||||||
#include "cogl/cogl-context-private.h"
|
#include "cogl/cogl-context-private.h"
|
||||||
|
#include "cogl/driver/gl/gl/cogl-texture-driver-gl3-private.h"
|
||||||
#include "cogl/driver/gl/cogl-pipeline-opengl-private.h"
|
#include "cogl/driver/gl/cogl-pipeline-opengl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-texture-gl-private.h"
|
#include "cogl/driver/gl/cogl-texture-gl-private.h"
|
||||||
@ -55,10 +56,20 @@
|
|||||||
#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
|
#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct _CoglTextureDriverGL3
|
||||||
|
{
|
||||||
|
CoglTextureDriver parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_FINAL_TYPE (CoglTextureDriverGL3,
|
||||||
|
cogl_texture_driver_gl3,
|
||||||
|
COGL_TYPE_TEXTURE_DRIVER)
|
||||||
|
|
||||||
static GLuint
|
static GLuint
|
||||||
_cogl_texture_driver_gen (CoglContext *ctx,
|
cogl_texture_driver_gl3_gen (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
CoglPixelFormat internal_format)
|
GLenum gl_target,
|
||||||
|
CoglPixelFormat internal_format)
|
||||||
{
|
{
|
||||||
GLuint tex;
|
GLuint tex;
|
||||||
|
|
||||||
@ -149,10 +160,11 @@ prep_gl_for_pixels_download_full (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
cogl_texture_driver_gl3_prep_gl_for_pixels_download (CoglTextureDriver *driver,
|
||||||
int image_width,
|
CoglContext *ctx,
|
||||||
int pixels_rowstride,
|
int image_width,
|
||||||
int pixels_bpp)
|
int pixels_rowstride,
|
||||||
|
int pixels_bpp)
|
||||||
{
|
{
|
||||||
prep_gl_for_pixels_download_full (ctx,
|
prep_gl_for_pixels_download_full (ctx,
|
||||||
pixels_rowstride,
|
pixels_rowstride,
|
||||||
@ -163,19 +175,20 @@ _cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
cogl_texture_driver_gl3_upload_subregion_to_gl (CoglTextureDriver *driver,
|
||||||
CoglTexture *texture,
|
CoglContext *ctx,
|
||||||
int src_x,
|
CoglTexture *texture,
|
||||||
int src_y,
|
int src_x,
|
||||||
int dst_x,
|
int src_y,
|
||||||
int dst_y,
|
int dst_x,
|
||||||
int width,
|
int dst_y,
|
||||||
int height,
|
int width,
|
||||||
int level,
|
int height,
|
||||||
CoglBitmap *source_bmp,
|
int level,
|
||||||
GLuint source_gl_format,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_format,
|
||||||
GError **error)
|
GLuint source_gl_type,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GLenum gl_target;
|
GLenum gl_target;
|
||||||
GLuint gl_handle;
|
GLuint gl_handle;
|
||||||
@ -280,14 +293,15 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
cogl_texture_driver_gl3_upload_to_gl (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLuint gl_handle,
|
GLenum gl_target,
|
||||||
CoglBitmap *source_bmp,
|
GLuint gl_handle,
|
||||||
GLint internal_gl_format,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLint internal_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_format,
|
||||||
GError **error)
|
GLuint source_gl_type,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||||
@ -343,11 +357,12 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
cogl_texture_driver_gl3_gl_get_tex_image (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLenum dest_gl_format,
|
GLenum gl_target,
|
||||||
GLenum dest_gl_type,
|
GLenum dest_gl_format,
|
||||||
uint8_t *dest)
|
GLenum dest_gl_type,
|
||||||
|
uint8_t *dest)
|
||||||
{
|
{
|
||||||
GE (ctx, glGetTexImage (gl_target,
|
GE (ctx, glGetTexImage (gl_target,
|
||||||
0, /* level */
|
0, /* level */
|
||||||
@ -358,13 +373,14 @@ _cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
cogl_texture_driver_gl3_size_supported (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLenum gl_intformat,
|
GLenum gl_target,
|
||||||
GLenum gl_format,
|
GLenum gl_intformat,
|
||||||
GLenum gl_type,
|
GLenum gl_format,
|
||||||
int width,
|
GLenum gl_type,
|
||||||
int height)
|
int width,
|
||||||
|
int height)
|
||||||
{
|
{
|
||||||
GLenum proxy_target;
|
GLenum proxy_target;
|
||||||
GLint new_width = 0;
|
GLint new_width = 0;
|
||||||
@ -389,8 +405,9 @@ _cogl_texture_driver_size_supported (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_supported (CoglContext *ctx,
|
cogl_texture_driver_gl3_upload_supported (CoglTextureDriver *driver,
|
||||||
CoglPixelFormat format)
|
CoglContext *ctx,
|
||||||
|
CoglPixelFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -458,11 +475,11 @@ _cogl_texture_driver_upload_supported (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
cogl_texture_driver_gl3_find_best_gl_get_data_format (CoglTextureDriver *driver,
|
||||||
(CoglContext *context,
|
CoglContext *context,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
GLenum *closest_gl_format,
|
GLenum *closest_gl_format,
|
||||||
GLenum *closest_gl_type)
|
GLenum *closest_gl_type)
|
||||||
{
|
{
|
||||||
return context->driver_vtable->pixel_format_to_gl (context,
|
return context->driver_vtable->pixel_format_to_gl (context,
|
||||||
format,
|
format,
|
||||||
@ -471,15 +488,22 @@ _cogl_texture_driver_find_best_gl_get_data_format
|
|||||||
closest_gl_type);
|
closest_gl_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CoglTextureDriver
|
static void
|
||||||
_cogl_texture_driver_gl =
|
cogl_texture_driver_gl3_class_init (CoglTextureDriverGL3Class *klass)
|
||||||
{
|
{
|
||||||
_cogl_texture_driver_gen,
|
CoglTextureDriverClass *driver_klass = COGL_TEXTURE_DRIVER_CLASS (klass);
|
||||||
_cogl_texture_driver_upload_subregion_to_gl,
|
|
||||||
_cogl_texture_driver_upload_to_gl,
|
driver_klass->gen = cogl_texture_driver_gl3_gen;
|
||||||
_cogl_texture_driver_prep_gl_for_pixels_download,
|
driver_klass->upload_subregion_to_gl = cogl_texture_driver_gl3_upload_subregion_to_gl;
|
||||||
_cogl_texture_driver_gl_get_tex_image,
|
driver_klass->upload_to_gl = cogl_texture_driver_gl3_upload_to_gl;
|
||||||
_cogl_texture_driver_size_supported,
|
driver_klass->prep_gl_for_pixels_download = cogl_texture_driver_gl3_prep_gl_for_pixels_download;
|
||||||
_cogl_texture_driver_upload_supported,
|
driver_klass->gl_get_tex_image = cogl_texture_driver_gl3_gl_get_tex_image;
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_texture_driver_gl3_init (CoglTextureDriverGL3 *driver)
|
||||||
|
{
|
||||||
|
}
|
40
cogl/cogl/driver/gl/gles/cogl-texture-driver-gles2-private.h
Normal file
40
cogl/cogl/driver/gl/gles/cogl-texture-driver-gles2-private.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Cogl
|
||||||
|
*
|
||||||
|
* A Low Level GPU Graphics and Utilities API
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Red Hat.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cogl/cogl-texture-driver.h"
|
||||||
|
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (CoglTextureDriverGLES2,
|
||||||
|
cogl_texture_driver_gles2,
|
||||||
|
COGL,
|
||||||
|
TEXTURE_DRIVER_GLES2,
|
||||||
|
CoglTextureDriver)
|
||||||
|
|
||||||
|
#define COGL_TYPE_TEXTURE_DRIVER_GLES2 (cogl_texture_driver_gles2_get_type ())
|
@ -42,6 +42,7 @@
|
|||||||
#include "cogl/cogl-texture-private.h"
|
#include "cogl/cogl-texture-private.h"
|
||||||
#include "cogl/cogl-pipeline.h"
|
#include "cogl/cogl-pipeline.h"
|
||||||
#include "cogl/cogl-context-private.h"
|
#include "cogl/cogl-context-private.h"
|
||||||
|
#include "cogl/driver/gl/gles/cogl-texture-driver-gles2-private.h"
|
||||||
#include "cogl/driver/gl/cogl-pipeline-opengl-private.h"
|
#include "cogl/driver/gl/cogl-pipeline-opengl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-texture-gl-private.h"
|
#include "cogl/driver/gl/cogl-texture-gl-private.h"
|
||||||
@ -70,10 +71,21 @@
|
|||||||
#define GL_UNPACK_SKIP_PIXELS 0x0CF4
|
#define GL_UNPACK_SKIP_PIXELS 0x0CF4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct _CoglTextureDriverGLES2
|
||||||
|
{
|
||||||
|
CoglTextureDriver parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_FINAL_TYPE (CoglTextureDriverGLES2,
|
||||||
|
cogl_texture_driver_gles2,
|
||||||
|
COGL_TYPE_TEXTURE_DRIVER)
|
||||||
|
|
||||||
static GLuint
|
static GLuint
|
||||||
_cogl_texture_driver_gen (CoglContext *ctx,
|
cogl_texture_driver_gles2_gen (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
CoglPixelFormat internal_format)
|
GLenum gl_target,
|
||||||
|
CoglPixelFormat internal_format)
|
||||||
{
|
{
|
||||||
GLuint tex;
|
GLuint tex;
|
||||||
|
|
||||||
@ -134,10 +146,11 @@ _cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
cogl_texture_driver_gles2_prep_gl_for_pixels_download (CoglTextureDriver *driver,
|
||||||
int pixels_rowstride,
|
CoglContext *ctx,
|
||||||
int image_width,
|
int pixels_rowstride,
|
||||||
int pixels_bpp)
|
int image_width,
|
||||||
|
int pixels_bpp)
|
||||||
{
|
{
|
||||||
_cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
|
_cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
|
||||||
pixels_bpp,
|
pixels_bpp,
|
||||||
@ -180,19 +193,20 @@ prepare_bitmap_alignment_for_upload (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
cogl_texture_driver_gles2_upload_subregion_to_gl (CoglTextureDriver *driver,
|
||||||
CoglTexture *texture,
|
CoglContext *ctx,
|
||||||
int src_x,
|
CoglTexture *texture,
|
||||||
int src_y,
|
int src_x,
|
||||||
int dst_x,
|
int src_y,
|
||||||
int dst_y,
|
int dst_x,
|
||||||
int width,
|
int dst_y,
|
||||||
int height,
|
int width,
|
||||||
int level,
|
int height,
|
||||||
CoglBitmap *source_bmp,
|
int level,
|
||||||
GLuint source_gl_format,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_format,
|
||||||
GError **error)
|
GLuint source_gl_type,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GLenum gl_target;
|
GLenum gl_target;
|
||||||
GLuint gl_handle;
|
GLuint gl_handle;
|
||||||
@ -335,14 +349,15 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
cogl_texture_driver_gles2_upload_to_gl (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLuint gl_handle,
|
GLenum gl_target,
|
||||||
CoglBitmap *source_bmp,
|
GLuint gl_handle,
|
||||||
GLint internal_gl_format,
|
CoglBitmap *source_bmp,
|
||||||
GLuint source_gl_format,
|
GLint internal_gl_format,
|
||||||
GLuint source_gl_type,
|
GLuint source_gl_format,
|
||||||
GError **error)
|
GLuint source_gl_type,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
||||||
int bpp;
|
int bpp;
|
||||||
@ -411,23 +426,25 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
|||||||
* fallback to a generic render + readpixels approach to downloading
|
* fallback to a generic render + readpixels approach to downloading
|
||||||
* texture data. (See _cogl_texture_draw_and_read() ) */
|
* texture data. (See _cogl_texture_draw_and_read() ) */
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
cogl_texture_driver_gles2_gl_get_tex_image (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLenum dest_gl_format,
|
GLenum gl_target,
|
||||||
GLenum dest_gl_type,
|
GLenum dest_gl_format,
|
||||||
uint8_t *dest)
|
GLenum dest_gl_type,
|
||||||
|
uint8_t *dest)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
cogl_texture_driver_gles2_size_supported (CoglTextureDriver *driver,
|
||||||
GLenum gl_target,
|
CoglContext *ctx,
|
||||||
GLenum gl_intformat,
|
GLenum gl_target,
|
||||||
GLenum gl_format,
|
GLenum gl_intformat,
|
||||||
GLenum gl_type,
|
GLenum gl_format,
|
||||||
int width,
|
GLenum gl_type,
|
||||||
int height)
|
int width,
|
||||||
|
int height)
|
||||||
{
|
{
|
||||||
GLint max_size;
|
GLint max_size;
|
||||||
|
|
||||||
@ -439,8 +456,9 @@ _cogl_texture_driver_size_supported (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cogl_texture_driver_upload_supported (CoglContext *ctx,
|
cogl_texture_driver_gles2_upload_supported (CoglTextureDriver *driver,
|
||||||
CoglPixelFormat format)
|
CoglContext *ctx,
|
||||||
|
CoglPixelFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -527,11 +545,11 @@ _cogl_texture_driver_upload_supported (CoglContext *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
cogl_texture_driver_gles2_find_best_gl_get_data_format (CoglTextureDriver *driver,
|
||||||
(CoglContext *context,
|
CoglContext *context,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
GLenum *closest_gl_format,
|
GLenum *closest_gl_format,
|
||||||
GLenum *closest_gl_type)
|
GLenum *closest_gl_type)
|
||||||
{
|
{
|
||||||
/* Find closest format that's supported by GL
|
/* Find closest format that's supported by GL
|
||||||
(Can't use _cogl_pixel_format_to_gl since available formats
|
(Can't use _cogl_pixel_format_to_gl since available formats
|
||||||
@ -541,15 +559,22 @@ _cogl_texture_driver_find_best_gl_get_data_format
|
|||||||
return COGL_PIXEL_FORMAT_RGBA_8888;
|
return COGL_PIXEL_FORMAT_RGBA_8888;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CoglTextureDriver
|
static void
|
||||||
_cogl_texture_driver_gles =
|
cogl_texture_driver_gles2_class_init (CoglTextureDriverGLES2Class *klass)
|
||||||
{
|
{
|
||||||
_cogl_texture_driver_gen,
|
CoglTextureDriverClass *driver_klass = COGL_TEXTURE_DRIVER_CLASS (klass);
|
||||||
_cogl_texture_driver_upload_subregion_to_gl,
|
|
||||||
_cogl_texture_driver_upload_to_gl,
|
driver_klass->gen = cogl_texture_driver_gles2_gen;
|
||||||
_cogl_texture_driver_prep_gl_for_pixels_download,
|
driver_klass->upload_subregion_to_gl = cogl_texture_driver_gles2_upload_subregion_to_gl;
|
||||||
_cogl_texture_driver_gl_get_tex_image,
|
driver_klass->upload_to_gl = cogl_texture_driver_gles2_upload_to_gl;
|
||||||
_cogl_texture_driver_size_supported,
|
driver_klass->prep_gl_for_pixels_download = cogl_texture_driver_gles2_prep_gl_for_pixels_download;
|
||||||
_cogl_texture_driver_upload_supported,
|
driver_klass->gl_get_tex_image = cogl_texture_driver_gles2_gl_get_tex_image;
|
||||||
_cogl_texture_driver_find_best_gl_get_data_format
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_texture_driver_gles2_init (CoglTextureDriverGLES2 *driver)
|
||||||
|
{
|
||||||
|
}
|
@ -109,12 +109,14 @@ cogl_common_driver_sources = [
|
|||||||
|
|
||||||
gl_driver_sources = [
|
gl_driver_sources = [
|
||||||
'driver/gl/gl/cogl-driver-gl.c',
|
'driver/gl/gl/cogl-driver-gl.c',
|
||||||
'driver/gl/gl/cogl-texture-driver-gl.c',
|
'driver/gl/gl/cogl-texture-driver-gl3.c',
|
||||||
|
'driver/gl/gl/cogl-texture-driver-gl3-private.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
gles_driver_sources = [
|
gles_driver_sources = [
|
||||||
'driver/gl/gles/cogl-driver-gles.c',
|
'driver/gl/gles/cogl-driver-gles.c',
|
||||||
'driver/gl/gles/cogl-texture-driver-gles.c',
|
'driver/gl/gles/cogl-texture-driver-gles2.c',
|
||||||
|
'driver/gl/gles/cogl-texture-driver-gles2-private.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
cogl_driver_sources = [
|
cogl_driver_sources = [
|
||||||
@ -255,6 +257,7 @@ cogl_sources = [
|
|||||||
'cogl-texture-2d-sliced-private.h',
|
'cogl-texture-2d-sliced-private.h',
|
||||||
'cogl-texture-2d-sliced.c',
|
'cogl-texture-2d-sliced.c',
|
||||||
'cogl-texture-2d.c',
|
'cogl-texture-2d.c',
|
||||||
|
'cogl-texture-driver.c',
|
||||||
'cogl-texture-driver.h',
|
'cogl-texture-driver.h',
|
||||||
'cogl-texture-private.h',
|
'cogl-texture-private.h',
|
||||||
'cogl-texture.c',
|
'cogl-texture.c',
|
||||||
|
Reference in New Issue
Block a user