cogl: Abstract GL specific bits of Buffer
By introducing a BufferImpl that handles the buffer allocation/de-allocation bits and making the driver responsible for creating the correct impl. This allow moving various Buffer specific vfuncs from Driver as well as getting rid of the gl_handle field from Buffer. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4181>
This commit is contained in:
parent
dfa3755f55
commit
6d9ef4d52a
@ -57,6 +57,7 @@ cogl_attribute_buffer_new_with_size (CoglContext *context,
|
|||||||
|
|
||||||
buffer = g_object_new (COGL_TYPE_ATTRIBUTE_BUFFER,
|
buffer = g_object_new (COGL_TYPE_ATTRIBUTE_BUFFER,
|
||||||
"context", context,
|
"context", context,
|
||||||
|
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||||
"size", (uint64_t) bytes,
|
"size", (uint64_t) bytes,
|
||||||
"default-target", COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
|
"default-target", COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
|
||||||
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
||||||
|
78
cogl/cogl/cogl-buffer-impl-private.h
Normal file
78
cogl/cogl/cogl-buffer-impl-private.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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 <glib.h>
|
||||||
|
|
||||||
|
#include "cogl/cogl-buffer.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define COGL_TYPE_BUFFER_IMPL (cogl_buffer_impl_get_type ())
|
||||||
|
|
||||||
|
G_DECLARE_DERIVABLE_TYPE (CoglBufferImpl,
|
||||||
|
cogl_buffer_impl,
|
||||||
|
COGL,
|
||||||
|
BUFFER_IMPL,
|
||||||
|
GObject)
|
||||||
|
|
||||||
|
struct _CoglBufferImplClass
|
||||||
|
{
|
||||||
|
GObjectClass parent_class;
|
||||||
|
|
||||||
|
void (* create) (CoglBufferImpl *impl,
|
||||||
|
CoglBuffer *buffer);
|
||||||
|
|
||||||
|
void (* destroy) (CoglBufferImpl *impl,
|
||||||
|
CoglBuffer *buffer);
|
||||||
|
|
||||||
|
/* Maps a buffer into the CPU */
|
||||||
|
void * (* map_range) (CoglBufferImpl *impl,
|
||||||
|
CoglBuffer *buffer,
|
||||||
|
size_t offset,
|
||||||
|
size_t size,
|
||||||
|
CoglBufferAccess access,
|
||||||
|
CoglBufferMapHint hints,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
/* Unmaps a buffer */
|
||||||
|
void (* unmap) (CoglBufferImpl *impl,
|
||||||
|
CoglBuffer *buffer);
|
||||||
|
|
||||||
|
/* Uploads data to the buffer without needing to map it necessarily
|
||||||
|
*/
|
||||||
|
gboolean (* set_data) (CoglBufferImpl *impl,
|
||||||
|
CoglBuffer *buffer,
|
||||||
|
unsigned int offset,
|
||||||
|
const void *data,
|
||||||
|
unsigned int size,
|
||||||
|
GError **error);
|
||||||
|
};
|
||||||
|
|
||||||
|
G_END_DECLS
|
43
cogl/cogl/cogl-buffer-impl.c
Normal file
43
cogl/cogl/cogl-buffer-impl.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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-buffer-impl-private.h"
|
||||||
|
|
||||||
|
G_DEFINE_ABSTRACT_TYPE (CoglBufferImpl, cogl_buffer_impl, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_buffer_impl_class_init (CoglBufferImplClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_buffer_impl_init (CoglBufferImpl *impl)
|
||||||
|
{
|
||||||
|
}
|
@ -36,9 +36,8 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "cogl/cogl-buffer.h"
|
#include "cogl/cogl-buffer-impl-private.h"
|
||||||
#include "cogl/cogl-context.h"
|
#include "cogl/cogl-context.h"
|
||||||
#include "cogl/cogl-gl-header.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -60,7 +59,8 @@ struct _CoglBuffer
|
|||||||
|
|
||||||
CoglBufferFlags flags;
|
CoglBufferFlags flags;
|
||||||
|
|
||||||
GLuint gl_handle; /* OpenGL handle */
|
CoglBufferImpl *impl;
|
||||||
|
|
||||||
unsigned int size; /* size of the buffer, in bytes */
|
unsigned int size; /* size of the buffer, in bytes */
|
||||||
CoglBufferUpdateHint update_hint;
|
CoglBufferUpdateHint update_hint;
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ enum
|
|||||||
PROP_0,
|
PROP_0,
|
||||||
|
|
||||||
PROP_CONTEXT,
|
PROP_CONTEXT,
|
||||||
|
PROP_IMPL,
|
||||||
PROP_SIZE,
|
PROP_SIZE,
|
||||||
PROP_DEFAULT_TARGET,
|
PROP_DEFAULT_TARGET,
|
||||||
PROP_UPDATE_HINT,
|
PROP_UPDATE_HINT,
|
||||||
@ -108,15 +109,17 @@ cogl_buffer_dispose (GObject *object)
|
|||||||
|
|
||||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||||
{
|
{
|
||||||
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (buffer->context->driver);
|
CoglBufferImplClass *impl_klass = COGL_BUFFER_IMPL_GET_CLASS (buffer->impl);
|
||||||
|
|
||||||
driver_klass->buffer_destroy (buffer->context->driver, buffer);
|
impl_klass->destroy (buffer->impl, buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_free (buffer->data);
|
g_free (buffer->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_clear_object (&buffer->impl);
|
||||||
|
|
||||||
G_OBJECT_CLASS (cogl_buffer_parent_class)->dispose (object);
|
G_OBJECT_CLASS (cogl_buffer_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +137,10 @@ cogl_buffer_set_property (GObject *gobject,
|
|||||||
buffer->context = g_value_get_object (value);
|
buffer->context = g_value_get_object (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_IMPL:
|
||||||
|
buffer->impl = g_value_get_object (value);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_SIZE:
|
case PROP_SIZE:
|
||||||
buffer->size = g_value_get_uint64 (value);
|
buffer->size = g_value_get_uint64 (value);
|
||||||
break;
|
break;
|
||||||
@ -157,9 +164,10 @@ cogl_buffer_set_property (GObject *gobject,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (buffer->context->driver);
|
g_assert (buffer->impl != NULL);
|
||||||
|
CoglBufferImplClass *impl_klass = COGL_BUFFER_IMPL_GET_CLASS (buffer->impl);
|
||||||
|
|
||||||
driver_klass->buffer_create (buffer->context->driver, buffer);
|
impl_klass->create (buffer->impl, buffer);
|
||||||
|
|
||||||
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
|
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
|
||||||
}
|
}
|
||||||
@ -189,6 +197,11 @@ cogl_buffer_class_init (CoglBufferClass *klass)
|
|||||||
COGL_TYPE_CONTEXT,
|
COGL_TYPE_CONTEXT,
|
||||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||||
G_PARAM_STATIC_STRINGS);
|
G_PARAM_STATIC_STRINGS);
|
||||||
|
obj_props[PROP_IMPL] =
|
||||||
|
g_param_spec_object ("impl", NULL, NULL,
|
||||||
|
COGL_TYPE_BUFFER_IMPL,
|
||||||
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||||
|
G_PARAM_STATIC_STRINGS);
|
||||||
obj_props[PROP_SIZE] =
|
obj_props[PROP_SIZE] =
|
||||||
g_param_spec_uint64 ("size", NULL, NULL,
|
g_param_spec_uint64 ("size", NULL, NULL,
|
||||||
0, G_MAXINT64, 0,
|
0, G_MAXINT64, 0,
|
||||||
@ -295,15 +308,15 @@ cogl_buffer_map_range (CoglBuffer *buffer,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (buffer->context->driver);
|
CoglBufferImplClass *impl_klass = COGL_BUFFER_IMPL_GET_CLASS (buffer->impl);
|
||||||
|
|
||||||
buffer->data = driver_klass->buffer_map_range (buffer->context->driver,
|
buffer->data = impl_klass->map_range (buffer->impl,
|
||||||
buffer,
|
buffer,
|
||||||
offset,
|
offset,
|
||||||
size,
|
size,
|
||||||
access,
|
access,
|
||||||
hints,
|
hints,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer->data;
|
return buffer->data;
|
||||||
@ -323,9 +336,9 @@ cogl_buffer_unmap (CoglBuffer *buffer)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (buffer->context->driver);
|
CoglBufferImplClass *impl_klass = COGL_BUFFER_IMPL_GET_CLASS (buffer->impl);
|
||||||
|
|
||||||
driver_klass->buffer_unmap (buffer->context->driver, buffer);
|
impl_klass->unmap (buffer->impl, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,14 +432,14 @@ cogl_buffer_set_data (CoglBuffer *buffer,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (buffer->context->driver);
|
CoglBufferImplClass *impl_klass = COGL_BUFFER_IMPL_GET_CLASS (buffer->impl);
|
||||||
|
|
||||||
status = driver_klass->buffer_set_data (buffer->context->driver,
|
status = impl_klass->set_data (buffer->impl,
|
||||||
buffer,
|
buffer,
|
||||||
offset,
|
offset,
|
||||||
data,
|
data,
|
||||||
size,
|
size,
|
||||||
&ignore_error);
|
&ignore_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error (&ignore_error);
|
g_clear_error (&ignore_error);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cogl/cogl-buffer-impl-private.h"
|
||||||
#include "cogl/cogl-context.h"
|
#include "cogl/cogl-context.h"
|
||||||
#include "cogl/cogl-offscreen-private.h"
|
#include "cogl/cogl-offscreen-private.h"
|
||||||
#include "cogl/cogl-framebuffer-private.h"
|
#include "cogl/cogl-framebuffer-private.h"
|
||||||
@ -94,36 +95,7 @@ struct _CoglDriverClass
|
|||||||
CoglClipStack *stack,
|
CoglClipStack *stack,
|
||||||
CoglFramebuffer *framebuffer);
|
CoglFramebuffer *framebuffer);
|
||||||
|
|
||||||
/* Enables the driver to create some meta data to represent a buffer
|
CoglBufferImpl * (* create_buffer_impl) (CoglDriver *driver);
|
||||||
* but with no corresponding storage allocated yet.
|
|
||||||
*/
|
|
||||||
void (* buffer_create) (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer);
|
|
||||||
|
|
||||||
void (* buffer_destroy) (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer);
|
|
||||||
|
|
||||||
/* Maps a buffer into the CPU */
|
|
||||||
void * (* buffer_map_range) (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer,
|
|
||||||
size_t offset,
|
|
||||||
size_t size,
|
|
||||||
CoglBufferAccess access,
|
|
||||||
CoglBufferMapHint hints,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
/* Unmaps a buffer */
|
|
||||||
void (* buffer_unmap) (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer);
|
|
||||||
|
|
||||||
/* Uploads data to the buffer without needing to map it necessarily
|
|
||||||
*/
|
|
||||||
gboolean (* buffer_set_data) (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer,
|
|
||||||
unsigned int offset,
|
|
||||||
const void *data,
|
|
||||||
unsigned int size,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void (*sampler_init) (CoglDriver *driver,
|
void (*sampler_init) (CoglDriver *driver,
|
||||||
CoglContext *context,
|
CoglContext *context,
|
||||||
@ -155,6 +127,8 @@ struct _CoglDriverClass
|
|||||||
|
|
||||||
#define COGL_TYPE_DRIVER (cogl_driver_get_type ())
|
#define COGL_TYPE_DRIVER (cogl_driver_get_type ())
|
||||||
|
|
||||||
|
CoglBufferImpl * cogl_driver_create_buffer_impl (CoglDriver *driver);
|
||||||
|
|
||||||
#define COGL_DRIVER_ERROR (_cogl_driver_error_quark ())
|
#define COGL_DRIVER_ERROR (_cogl_driver_error_quark ())
|
||||||
|
|
||||||
typedef enum /*< prefix=COGL_DRIVER_ERROR >*/
|
typedef enum /*< prefix=COGL_DRIVER_ERROR >*/
|
||||||
|
@ -33,12 +33,27 @@
|
|||||||
|
|
||||||
G_DEFINE_ABSTRACT_TYPE (CoglDriver, cogl_driver, G_TYPE_OBJECT)
|
G_DEFINE_ABSTRACT_TYPE (CoglDriver, cogl_driver, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static CoglBufferImpl *
|
||||||
|
cogl_driver_default_create_buffer_impl (CoglDriver *driver)
|
||||||
|
{
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cogl_driver_class_init (CoglDriverClass *klass)
|
cogl_driver_class_init (CoglDriverClass *klass)
|
||||||
{
|
{
|
||||||
|
klass->create_buffer_impl = cogl_driver_default_create_buffer_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cogl_driver_init (CoglDriver *driver)
|
cogl_driver_init (CoglDriver *driver)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoglBufferImpl *
|
||||||
|
cogl_driver_create_buffer_impl (CoglDriver *driver)
|
||||||
|
{
|
||||||
|
CoglDriverClass *klass = COGL_DRIVER_GET_CLASS (driver);
|
||||||
|
|
||||||
|
return klass->create_buffer_impl (driver);
|
||||||
|
}
|
||||||
|
@ -60,6 +60,7 @@ cogl_index_buffer_new (CoglContext *context,
|
|||||||
|
|
||||||
indices = g_object_new (COGL_TYPE_INDEX_BUFFER,
|
indices = g_object_new (COGL_TYPE_INDEX_BUFFER,
|
||||||
"context", context,
|
"context", context,
|
||||||
|
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||||
"size", (uint64_t) bytes,
|
"size", (uint64_t) bytes,
|
||||||
"default-target", COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
|
"default-target", COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
|
||||||
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
||||||
|
@ -70,6 +70,7 @@ cogl_pixel_buffer_new (CoglContext *context,
|
|||||||
|
|
||||||
pixel_buffer = g_object_new (COGL_TYPE_PIXEL_BUFFER,
|
pixel_buffer = g_object_new (COGL_TYPE_PIXEL_BUFFER,
|
||||||
"context", context,
|
"context", context,
|
||||||
|
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||||
"size", (uint64_t) size,
|
"size", (uint64_t) size,
|
||||||
"default-target", COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
|
"default-target", COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
|
||||||
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "cogl/cogl-attribute.h"
|
#include "cogl/cogl-attribute.h"
|
||||||
#include "cogl/cogl-attribute-private.h"
|
#include "cogl/cogl-attribute-private.h"
|
||||||
#include "cogl/driver/gl/cogl-attribute-gl-private.h"
|
#include "cogl/driver/gl/cogl-attribute-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
|
#include "cogl/driver/gl/cogl-buffer-impl-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-pipeline-gl-private.h"
|
#include "cogl/driver/gl/cogl-pipeline-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-pipeline-progend-glsl-private.h"
|
#include "cogl/driver/gl/cogl-pipeline-progend-glsl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
#include "cogl/cogl-buffer-private.h"
|
#include "cogl/cogl-buffer-private.h"
|
||||||
#include "cogl/cogl-pixel-buffer.h"
|
#include "cogl/cogl-pixel-buffer.h"
|
||||||
#include "cogl/cogl-context-private.h"
|
#include "cogl/cogl-context-private.h"
|
||||||
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
|
#include "cogl/driver/gl/cogl-buffer-impl-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
|
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
|
||||||
|
|
||||||
uint8_t *
|
uint8_t *
|
||||||
|
@ -38,35 +38,15 @@
|
|||||||
#include "cogl/cogl-context.h"
|
#include "cogl/cogl-context.h"
|
||||||
#include "cogl/cogl-buffer.h"
|
#include "cogl/cogl-buffer.h"
|
||||||
#include "cogl/cogl-buffer-private.h"
|
#include "cogl/cogl-buffer-private.h"
|
||||||
|
#include "cogl/cogl-buffer-impl-private.h"
|
||||||
|
|
||||||
void
|
#define COGL_TYPE_BUFFER_IMPL_GL (cogl_buffer_impl_gl_get_type ())
|
||||||
_cogl_buffer_gl_create (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer);
|
|
||||||
|
|
||||||
void
|
G_DECLARE_FINAL_TYPE (CoglBufferImplGL,
|
||||||
_cogl_buffer_gl_destroy (CoglDriver *driver,
|
cogl_buffer_impl_gl,
|
||||||
CoglBuffer *buffer);
|
COGL,
|
||||||
|
BUFFER_IMPL_GL,
|
||||||
void *
|
CoglBufferImpl)
|
||||||
_cogl_buffer_gl_map_range (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer,
|
|
||||||
size_t offset,
|
|
||||||
size_t size,
|
|
||||||
CoglBufferAccess access,
|
|
||||||
CoglBufferMapHint hints,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void
|
|
||||||
_cogl_buffer_gl_unmap (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer);
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
_cogl_buffer_gl_set_data (CoglDriver *driver,
|
|
||||||
CoglBuffer *buffer,
|
|
||||||
unsigned int offset,
|
|
||||||
const void *data,
|
|
||||||
unsigned int size,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
_cogl_buffer_gl_bind (CoglBuffer *buffer,
|
_cogl_buffer_gl_bind (CoglBuffer *buffer,
|
@ -35,9 +35,18 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "cogl/cogl-context-private.h"
|
#include "cogl/cogl-context-private.h"
|
||||||
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
|
#include "cogl/driver/gl/cogl-buffer-impl-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||||
|
|
||||||
|
struct _CoglBufferImplGL
|
||||||
|
{
|
||||||
|
CoglBufferImpl parent_instance;
|
||||||
|
|
||||||
|
GLuint gl_handle; /* OpenGL handle */
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_FINAL_TYPE (CoglBufferImplGL, cogl_buffer_impl_gl, COGL_TYPE_BUFFER_IMPL)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GL/GLES compatibility defines for the buffer API:
|
* GL/GLES compatibility defines for the buffer API:
|
||||||
*/
|
*/
|
||||||
@ -76,20 +85,23 @@
|
|||||||
#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
|
#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
static void
|
||||||
_cogl_buffer_gl_create (CoglDriver *driver,
|
cogl_buffer_impl_gl_create (CoglBufferImpl *impl,
|
||||||
CoglBuffer *buffer)
|
CoglBuffer *buffer)
|
||||||
{
|
{
|
||||||
|
CoglBufferImplGL *gl_impl = COGL_BUFFER_IMPL_GL (impl);
|
||||||
CoglContext *ctx = buffer->context;
|
CoglContext *ctx = buffer->context;
|
||||||
|
|
||||||
GE (ctx, glGenBuffers (1, &buffer->gl_handle));
|
GE (ctx, glGenBuffers (1, &gl_impl->gl_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
_cogl_buffer_gl_destroy (CoglDriver *driver,
|
cogl_buffer_impl_gl_destroy (CoglBufferImpl *impl,
|
||||||
CoglBuffer *buffer)
|
CoglBuffer *buffer)
|
||||||
{
|
{
|
||||||
GE( buffer->context, glDeleteBuffers (1, &buffer->gl_handle) );
|
CoglBufferImplGL *gl_impl = COGL_BUFFER_IMPL_GL (impl);
|
||||||
|
|
||||||
|
GE (buffer->context, glDeleteBuffers (1, &gl_impl->gl_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLenum
|
static GLenum
|
||||||
@ -168,8 +180,9 @@ _cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
_cogl_buffer_bind_no_create (CoglBuffer *buffer,
|
cogl_buffer_impl_gl_bind_no_create (CoglBufferImplGL *gl_impl,
|
||||||
CoglBufferBindTarget target)
|
CoglBuffer *buffer,
|
||||||
|
CoglBufferBindTarget target)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = buffer->context;
|
CoglContext *ctx = buffer->context;
|
||||||
|
|
||||||
@ -188,21 +201,21 @@ _cogl_buffer_bind_no_create (CoglBuffer *buffer,
|
|||||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||||
{
|
{
|
||||||
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
|
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
|
||||||
GE( ctx, glBindBuffer (gl_target, buffer->gl_handle) );
|
GE( ctx, glBindBuffer (gl_target, gl_impl->gl_handle) );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return buffer->data;
|
return buffer->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
_cogl_buffer_gl_map_range (CoglDriver *driver,
|
cogl_buffer_impl_gl_map_range (CoglBufferImpl *impl,
|
||||||
CoglBuffer *buffer,
|
CoglBuffer *buffer,
|
||||||
size_t offset,
|
size_t offset,
|
||||||
size_t size,
|
size_t size,
|
||||||
CoglBufferAccess access,
|
CoglBufferAccess access,
|
||||||
CoglBufferMapHint hints,
|
CoglBufferMapHint hints,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
CoglBufferBindTarget target;
|
CoglBufferBindTarget target;
|
||||||
@ -222,7 +235,9 @@ _cogl_buffer_gl_map_range (CoglDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
target = buffer->last_target;
|
target = buffer->last_target;
|
||||||
_cogl_buffer_bind_no_create (buffer, target);
|
cogl_buffer_impl_gl_bind_no_create (COGL_BUFFER_IMPL_GL (buffer->impl),
|
||||||
|
buffer,
|
||||||
|
target);
|
||||||
|
|
||||||
gl_target = convert_bind_target_to_gl_target (target);
|
gl_target = convert_bind_target_to_gl_target (target);
|
||||||
|
|
||||||
@ -328,13 +343,15 @@ _cogl_buffer_gl_map_range (CoglDriver *driver,
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
_cogl_buffer_gl_unmap (CoglDriver *driver,
|
cogl_buffer_impl_gl_unmap (CoglBufferImpl *impl,
|
||||||
CoglBuffer *buffer)
|
CoglBuffer *buffer)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = buffer->context;
|
CoglContext *ctx = buffer->context;
|
||||||
|
|
||||||
_cogl_buffer_bind_no_create (buffer, buffer->last_target);
|
cogl_buffer_impl_gl_bind_no_create (COGL_BUFFER_IMPL_GL (impl),
|
||||||
|
buffer,
|
||||||
|
buffer->last_target);
|
||||||
|
|
||||||
GE( ctx, glUnmapBuffer (convert_bind_target_to_gl_target
|
GE( ctx, glUnmapBuffer (convert_bind_target_to_gl_target
|
||||||
(buffer->last_target)) );
|
(buffer->last_target)) );
|
||||||
@ -343,13 +360,13 @@ _cogl_buffer_gl_unmap (CoglDriver *driver,
|
|||||||
_cogl_buffer_gl_unbind (buffer);
|
_cogl_buffer_gl_unbind (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static gboolean
|
||||||
_cogl_buffer_gl_set_data (CoglDriver *driver,
|
cogl_buffer_impl_gl_set_data (CoglBufferImpl *impl,
|
||||||
CoglBuffer *buffer,
|
CoglBuffer *buffer,
|
||||||
unsigned int offset,
|
unsigned int offset,
|
||||||
const void *data,
|
const void *data,
|
||||||
unsigned int size,
|
unsigned int size,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
CoglBufferBindTarget target;
|
CoglBufferBindTarget target;
|
||||||
GLenum gl_target;
|
GLenum gl_target;
|
||||||
@ -393,7 +410,9 @@ _cogl_buffer_gl_bind (CoglBuffer *buffer,
|
|||||||
{
|
{
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
ret = _cogl_buffer_bind_no_create (buffer, target);
|
ret = cogl_buffer_impl_gl_bind_no_create (COGL_BUFFER_IMPL_GL (buffer->impl),
|
||||||
|
buffer,
|
||||||
|
target);
|
||||||
|
|
||||||
/* create an empty store if we don't have one yet. creating the store
|
/* create an empty store if we don't have one yet. creating the store
|
||||||
* lazily allows the user of the CoglBuffer to set a hint before the
|
* lazily allows the user of the CoglBuffer to set a hint before the
|
||||||
@ -429,3 +448,20 @@ _cogl_buffer_gl_unbind (CoglBuffer *buffer)
|
|||||||
|
|
||||||
ctx->current_buffer[buffer->last_target] = NULL;
|
ctx->current_buffer[buffer->last_target] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_buffer_impl_gl_class_init (CoglBufferImplGLClass *klass)
|
||||||
|
{
|
||||||
|
CoglBufferImplClass *buffer_klass = COGL_BUFFER_IMPL_CLASS (klass);
|
||||||
|
|
||||||
|
buffer_klass->create = cogl_buffer_impl_gl_create;
|
||||||
|
buffer_klass->destroy = cogl_buffer_impl_gl_destroy;
|
||||||
|
buffer_klass->map_range = cogl_buffer_impl_gl_map_range;
|
||||||
|
buffer_klass->unmap = cogl_buffer_impl_gl_unmap;
|
||||||
|
buffer_klass->set_data = cogl_buffer_impl_gl_set_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_buffer_impl_gl_init (CoglBufferImplGL *impl)
|
||||||
|
{
|
||||||
|
}
|
@ -26,9 +26,9 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cogl/driver/gl/cogl-buffer-impl-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-pipeline-gl-private.h"
|
#include "cogl/driver/gl/cogl-pipeline-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
|
|
||||||
#include "cogl/driver/gl/cogl-clip-stack-gl-private.h"
|
#include "cogl/driver/gl/cogl-clip-stack-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-attribute-gl-private.h"
|
#include "cogl/driver/gl/cogl-attribute-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-gl-framebuffer-fbo.h"
|
#include "cogl/driver/gl/cogl-gl-framebuffer-fbo.h"
|
||||||
@ -296,6 +296,12 @@ cogl_driver_gl_flush_framebuffer_state (CoglDriver *driver,
|
|||||||
ctx->current_draw_buffer_changes &= ~state;
|
ctx->current_draw_buffer_changes &= ~state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CoglBufferImpl *
|
||||||
|
cogl_driver_gl_create_buffer_impl (CoglDriver *driver)
|
||||||
|
{
|
||||||
|
return g_object_new (COGL_TYPE_BUFFER_IMPL_GL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cogl_driver_gl_sampler_init_init (CoglDriver *driver,
|
cogl_driver_gl_sampler_init_init (CoglDriver *driver,
|
||||||
CoglContext *context,
|
CoglContext *context,
|
||||||
@ -533,11 +539,7 @@ cogl_driver_gl_class_init (CoglDriverGLClass *klass)
|
|||||||
driver_klass->flush_framebuffer_state = cogl_driver_gl_flush_framebuffer_state;
|
driver_klass->flush_framebuffer_state = cogl_driver_gl_flush_framebuffer_state;
|
||||||
driver_klass->flush_attributes_state = _cogl_gl_flush_attributes_state;
|
driver_klass->flush_attributes_state = _cogl_gl_flush_attributes_state;
|
||||||
driver_klass->clip_stack_flush = _cogl_clip_stack_gl_flush;
|
driver_klass->clip_stack_flush = _cogl_clip_stack_gl_flush;
|
||||||
driver_klass->buffer_create = _cogl_buffer_gl_create;
|
driver_klass->create_buffer_impl = cogl_driver_gl_create_buffer_impl;
|
||||||
driver_klass->buffer_destroy = _cogl_buffer_gl_destroy;
|
|
||||||
driver_klass->buffer_map_range = _cogl_buffer_gl_map_range;
|
|
||||||
driver_klass->buffer_unmap = _cogl_buffer_gl_unmap;
|
|
||||||
driver_klass->buffer_set_data = _cogl_buffer_gl_set_data;
|
|
||||||
driver_klass->sampler_init = cogl_driver_gl_sampler_init_init;
|
driver_klass->sampler_init = cogl_driver_gl_sampler_init_init;
|
||||||
driver_klass->sampler_free = cogl_driver_gl_sampler_free;
|
driver_klass->sampler_free = cogl_driver_gl_sampler_free;
|
||||||
driver_klass->set_uniform = cogl_driver_gl_set_uniform; /* XXX name is weird... */
|
driver_klass->set_uniform = cogl_driver_gl_set_uniform; /* XXX name is weird... */
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-framebuffer-gl-private.h"
|
#include "cogl/driver/gl/cogl-framebuffer-gl-private.h"
|
||||||
#include "cogl/driver/gl/cogl-bitmap-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-buffer-impl-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 "cogl/driver/gl/cogl-texture-driver-gl-private.h"
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ cogl_common_driver_sources = [
|
|||||||
'driver/gl/cogl-attribute-gl.c',
|
'driver/gl/cogl-attribute-gl.c',
|
||||||
'driver/gl/cogl-bitmap-gl-private.h',
|
'driver/gl/cogl-bitmap-gl-private.h',
|
||||||
'driver/gl/cogl-bitmap-gl.c',
|
'driver/gl/cogl-bitmap-gl.c',
|
||||||
'driver/gl/cogl-buffer-gl-private.h',
|
'driver/gl/cogl-buffer-impl-gl-private.h',
|
||||||
'driver/gl/cogl-buffer-gl.c',
|
'driver/gl/cogl-buffer-impl-gl.c',
|
||||||
'driver/gl/cogl-clip-stack-gl-private.h',
|
'driver/gl/cogl-clip-stack-gl-private.h',
|
||||||
'driver/gl/cogl-clip-stack-gl.c',
|
'driver/gl/cogl-clip-stack-gl.c',
|
||||||
'driver/gl/cogl-driver-gl.c',
|
'driver/gl/cogl-driver-gl.c',
|
||||||
@ -159,8 +159,10 @@ cogl_sources = [
|
|||||||
'cogl-blit.h',
|
'cogl-blit.h',
|
||||||
'cogl-boxed-value.c',
|
'cogl-boxed-value.c',
|
||||||
'cogl-boxed-value.h',
|
'cogl-boxed-value.h',
|
||||||
|
'cogl-buffer-impl-private.h',
|
||||||
'cogl-buffer-private.h',
|
'cogl-buffer-private.h',
|
||||||
'cogl-buffer.c',
|
'cogl-buffer.c',
|
||||||
|
'cogl-buffer-impl.c',
|
||||||
'cogl-clip-stack.c',
|
'cogl-clip-stack.c',
|
||||||
'cogl-clip-stack.h',
|
'cogl-clip-stack.h',
|
||||||
'cogl-closure-list-private.h',
|
'cogl-closure-list-private.h',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user