cogl: Add a TextureDriverGL
Abstract away the common bits between GL3 and GLES2 TextureDriver implementations by sharing the common bits in a parent class. Ideally, we would move the various vfuncs that are GL specific from the abstract TextureDriver type but that can be done at a later stage once there is actual work on adding a Vulkan driver. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4163>
This commit is contained in:

committed by
Marge Bot

parent
cde6a447b4
commit
f3430ff1c5
@@ -117,10 +117,3 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTextureDriver *driver,
|
||||
int dst_y,
|
||||
int level,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
_cogl_texture_2d_gl_get_data (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
int rowstride,
|
||||
uint8_t *data);
|
||||
|
@@ -641,46 +641,3 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTextureDriver *driver,
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_texture_2d_gl_get_data (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
int rowstride,
|
||||
uint8_t *data)
|
||||
{
|
||||
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
|
||||
CoglTextureDriverClass *tex_driver =
|
||||
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||
uint8_t bpp;
|
||||
int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
|
||||
GLenum gl_format;
|
||||
GLenum gl_type;
|
||||
|
||||
g_return_if_fail (format != COGL_PIXEL_FORMAT_ANY);
|
||||
g_return_if_fail (cogl_pixel_format_get_n_planes (format) == 1);
|
||||
|
||||
bpp = cogl_pixel_format_get_bytes_per_pixel (format, 0);
|
||||
|
||||
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
||||
format,
|
||||
NULL, /* internal format */
|
||||
&gl_format,
|
||||
&gl_type);
|
||||
|
||||
tex_driver->prep_gl_for_pixels_download (ctx->texture_driver,
|
||||
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);
|
||||
}
|
||||
|
44
cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h
Normal file
44
cogl/cogl/driver/gl/cogl-texture-driver-gl-private.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
struct _CoglTextureDriverGLClass
|
||||
{
|
||||
CoglTextureDriverClass parent_class;
|
||||
};
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (CoglTextureDriverGL,
|
||||
cogl_texture_driver_gl,
|
||||
COGL,
|
||||
TEXTURE_DRIVER_GL,
|
||||
CoglTextureDriver)
|
||||
|
||||
#define COGL_TYPE_TEXTURE_DRIVER_GL (cogl_texture_driver_gl_get_type ())
|
54
cogl/cogl/driver/gl/cogl-texture-driver-gl.c
Normal file
54
cogl/cogl/driver/gl/cogl-texture-driver-gl.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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/driver/gl/cogl-texture-driver-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-texture-2d-gl-private.h"
|
||||
|
||||
G_DEFINE_TYPE (CoglTextureDriverGL, cogl_texture_driver_gl, COGL_TYPE_TEXTURE_DRIVER)
|
||||
|
||||
static void
|
||||
cogl_texture_driver_gl_class_init (CoglTextureDriverGLClass *klass)
|
||||
{
|
||||
CoglTextureDriverClass *driver_klass = COGL_TEXTURE_DRIVER_CLASS (klass);
|
||||
|
||||
driver_klass->texture_2d_free = _cogl_texture_2d_gl_free;
|
||||
driver_klass->texture_2d_can_create = _cogl_texture_2d_gl_can_create;
|
||||
driver_klass->texture_2d_init = _cogl_texture_2d_gl_init;
|
||||
driver_klass->texture_2d_allocate = _cogl_texture_2d_gl_allocate;
|
||||
driver_klass->texture_2d_copy_from_framebuffer = _cogl_texture_2d_gl_copy_from_framebuffer;
|
||||
driver_klass->texture_2d_get_gl_handle = _cogl_texture_2d_gl_get_gl_handle;
|
||||
driver_klass->texture_2d_generate_mipmap = _cogl_texture_2d_gl_generate_mipmap;
|
||||
driver_klass->texture_2d_copy_from_bitmap = _cogl_texture_2d_gl_copy_from_bitmap;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_texture_driver_gl_init (CoglTextureDriverGL *driver)
|
||||
{
|
||||
}
|
@@ -28,13 +28,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cogl/cogl-texture-driver.h"
|
||||
#include "cogl/driver/gl/cogl-texture-driver-gl-private.h"
|
||||
|
||||
|
||||
G_DECLARE_FINAL_TYPE (CoglTextureDriverGL3,
|
||||
cogl_texture_driver_gl3,
|
||||
COGL,
|
||||
TEXTURE_DRIVER_GL3,
|
||||
CoglTextureDriver)
|
||||
CoglTextureDriverGL)
|
||||
|
||||
#define COGL_TYPE_TEXTURE_DRIVER_GL3 (cogl_texture_driver_gl3_get_type ())
|
||||
|
@@ -47,7 +47,6 @@
|
||||
#include "cogl/driver/gl/cogl-pipeline-opengl-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-2d-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -60,12 +59,12 @@
|
||||
|
||||
struct _CoglTextureDriverGL3
|
||||
{
|
||||
CoglTextureDriver parent_instance;
|
||||
CoglTextureDriverGL parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (CoglTextureDriverGL3,
|
||||
cogl_texture_driver_gl3,
|
||||
COGL_TYPE_TEXTURE_DRIVER)
|
||||
COGL_TYPE_TEXTURE_DRIVER_GL)
|
||||
|
||||
static GLuint
|
||||
cogl_texture_driver_gl3_gen (CoglTextureDriver *driver,
|
||||
@@ -491,12 +490,55 @@ cogl_texture_driver_gl3_find_best_gl_get_data_format (CoglTextureDriver *driver,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cogl_gl_texture_driver_is_get_data_supported (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d)
|
||||
cogl_texture_driver_gl3_is_get_data_supported (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d)
|
||||
{
|
||||
return tex_2d->is_get_data_supported;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_texture_driver_gl3_texture_2d_gl_get_data (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
int rowstride,
|
||||
uint8_t *data)
|
||||
{
|
||||
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
|
||||
CoglTextureDriverClass *tex_driver =
|
||||
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
|
||||
uint8_t bpp;
|
||||
int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
|
||||
GLenum gl_format;
|
||||
GLenum gl_type;
|
||||
|
||||
g_return_if_fail (format != COGL_PIXEL_FORMAT_ANY);
|
||||
g_return_if_fail (cogl_pixel_format_get_n_planes (format) == 1);
|
||||
|
||||
bpp = cogl_pixel_format_get_bytes_per_pixel (format, 0);
|
||||
|
||||
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
||||
format,
|
||||
NULL, /* internal format */
|
||||
&gl_format,
|
||||
&gl_type);
|
||||
|
||||
tex_driver->prep_gl_for_pixels_download (ctx->texture_driver,
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_texture_driver_gl3_class_init (CoglTextureDriverGL3Class *klass)
|
||||
{
|
||||
@@ -510,16 +552,8 @@ cogl_texture_driver_gl3_class_init (CoglTextureDriverGL3Class *klass)
|
||||
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_free = _cogl_texture_2d_gl_free;
|
||||
driver_klass->texture_2d_can_create = _cogl_texture_2d_gl_can_create;
|
||||
driver_klass->texture_2d_init = _cogl_texture_2d_gl_init;
|
||||
driver_klass->texture_2d_allocate = _cogl_texture_2d_gl_allocate;
|
||||
driver_klass->texture_2d_copy_from_framebuffer = _cogl_texture_2d_gl_copy_from_framebuffer;
|
||||
driver_klass->texture_2d_get_gl_handle = _cogl_texture_2d_gl_get_gl_handle;
|
||||
driver_klass->texture_2d_generate_mipmap = _cogl_texture_2d_gl_generate_mipmap;
|
||||
driver_klass->texture_2d_copy_from_bitmap = _cogl_texture_2d_gl_copy_from_bitmap;
|
||||
driver_klass->texture_2d_is_get_data_supported = cogl_gl_texture_driver_is_get_data_supported;
|
||||
driver_klass->texture_2d_get_data = _cogl_texture_2d_gl_get_data;
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -28,13 +28,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cogl/cogl-texture-driver.h"
|
||||
#include "cogl/driver/gl/cogl-texture-driver-gl-private.h"
|
||||
|
||||
|
||||
G_DECLARE_FINAL_TYPE (CoglTextureDriverGLES2,
|
||||
cogl_texture_driver_gles2,
|
||||
COGL,
|
||||
TEXTURE_DRIVER_GLES2,
|
||||
CoglTextureDriver)
|
||||
CoglTextureDriverGL)
|
||||
|
||||
#define COGL_TYPE_TEXTURE_DRIVER_GLES2 (cogl_texture_driver_gles2_get_type ())
|
||||
|
@@ -46,7 +46,6 @@
|
||||
#include "cogl/driver/gl/cogl-pipeline-opengl-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-2d-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -75,12 +74,12 @@
|
||||
|
||||
struct _CoglTextureDriverGLES2
|
||||
{
|
||||
CoglTextureDriver parent_instance;
|
||||
CoglTextureDriverGL parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (CoglTextureDriverGLES2,
|
||||
cogl_texture_driver_gles2,
|
||||
COGL_TYPE_TEXTURE_DRIVER)
|
||||
COGL_TYPE_TEXTURE_DRIVER_GL)
|
||||
|
||||
static GLuint
|
||||
cogl_texture_driver_gles2_gen (CoglTextureDriver *driver,
|
||||
@@ -561,7 +560,7 @@ cogl_texture_driver_gles2_find_best_gl_get_data_format (CoglTextureDriver *drive
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cogl_gles2_texture_driver_texture_2d_is_get_data_supported (CoglTextureDriver *driver,
|
||||
cogl_texture_driver_gles2_texture_2d_is_get_data_supported (CoglTextureDriver *driver,
|
||||
CoglTexture2D *tex_2d)
|
||||
{
|
||||
return FALSE;
|
||||
@@ -580,15 +579,7 @@ cogl_texture_driver_gles2_class_init (CoglTextureDriverGLES2Class *klass)
|
||||
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_free = _cogl_texture_2d_gl_free;
|
||||
driver_klass->texture_2d_can_create = _cogl_texture_2d_gl_can_create;
|
||||
driver_klass->texture_2d_init = _cogl_texture_2d_gl_init;
|
||||
driver_klass->texture_2d_allocate = _cogl_texture_2d_gl_allocate;
|
||||
driver_klass->texture_2d_copy_from_framebuffer = _cogl_texture_2d_gl_copy_from_framebuffer;
|
||||
driver_klass->texture_2d_get_gl_handle = _cogl_texture_2d_gl_get_gl_handle;
|
||||
driver_klass->texture_2d_generate_mipmap = _cogl_texture_2d_gl_generate_mipmap;
|
||||
driver_klass->texture_2d_copy_from_bitmap = _cogl_texture_2d_gl_copy_from_bitmap;
|
||||
driver_klass->texture_2d_is_get_data_supported = cogl_gles2_texture_driver_texture_2d_is_get_data_supported;
|
||||
driver_klass->texture_2d_is_get_data_supported = cogl_texture_driver_gles2_texture_2d_is_get_data_supported;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -100,6 +100,8 @@ cogl_common_driver_sources = [
|
||||
'driver/gl/cogl-texture-2d-gl-private.h',
|
||||
'driver/gl/cogl-texture-2d-gl.c',
|
||||
'driver/gl/cogl-texture-gl-private.h',
|
||||
'driver/gl/cogl-texture-driver-gl.c',
|
||||
'driver/gl/cogl-texture-driver-gl-private.h',
|
||||
'driver/gl/cogl-texture-gl.c',
|
||||
'driver/gl/cogl-util-gl-private.h',
|
||||
'driver/gl/cogl-util-gl.c',
|
||||
|
Reference in New Issue
Block a user