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,
|
||||
"context", context,
|
||||
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||
"size", (uint64_t) bytes,
|
||||
"default-target", COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
|
||||
"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 "cogl/cogl-buffer.h"
|
||||
#include "cogl/cogl-buffer-impl-private.h"
|
||||
#include "cogl/cogl-context.h"
|
||||
#include "cogl/cogl-gl-header.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -60,7 +59,8 @@ struct _CoglBuffer
|
||||
|
||||
CoglBufferFlags flags;
|
||||
|
||||
GLuint gl_handle; /* OpenGL handle */
|
||||
CoglBufferImpl *impl;
|
||||
|
||||
unsigned int size; /* size of the buffer, in bytes */
|
||||
CoglBufferUpdateHint update_hint;
|
||||
|
||||
|
@ -57,6 +57,7 @@ enum
|
||||
PROP_0,
|
||||
|
||||
PROP_CONTEXT,
|
||||
PROP_IMPL,
|
||||
PROP_SIZE,
|
||||
PROP_DEFAULT_TARGET,
|
||||
PROP_UPDATE_HINT,
|
||||
@ -108,15 +109,17 @@ cogl_buffer_dispose (GObject *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
|
||||
{
|
||||
g_free (buffer->data);
|
||||
}
|
||||
|
||||
g_clear_object (&buffer->impl);
|
||||
|
||||
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);
|
||||
break;
|
||||
|
||||
case PROP_IMPL:
|
||||
buffer->impl = g_value_get_object (value);
|
||||
break;
|
||||
|
||||
case PROP_SIZE:
|
||||
buffer->size = g_value_get_uint64 (value);
|
||||
break;
|
||||
@ -157,9 +164,10 @@ cogl_buffer_set_property (GObject *gobject,
|
||||
}
|
||||
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;
|
||||
}
|
||||
@ -189,6 +197,11 @@ cogl_buffer_class_init (CoglBufferClass *klass)
|
||||
COGL_TYPE_CONTEXT,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||
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] =
|
||||
g_param_spec_uint64 ("size", NULL, NULL,
|
||||
0, G_MAXINT64, 0,
|
||||
@ -295,15 +308,15 @@ cogl_buffer_map_range (CoglBuffer *buffer,
|
||||
}
|
||||
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,
|
||||
offset,
|
||||
size,
|
||||
access,
|
||||
hints,
|
||||
error);
|
||||
buffer->data = impl_klass->map_range (buffer->impl,
|
||||
buffer,
|
||||
offset,
|
||||
size,
|
||||
access,
|
||||
hints,
|
||||
error);
|
||||
}
|
||||
|
||||
return buffer->data;
|
||||
@ -323,9 +336,9 @@ cogl_buffer_unmap (CoglBuffer *buffer)
|
||||
}
|
||||
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
|
||||
{
|
||||
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,
|
||||
buffer,
|
||||
offset,
|
||||
data,
|
||||
size,
|
||||
&ignore_error);
|
||||
status = impl_klass->set_data (buffer->impl,
|
||||
buffer,
|
||||
offset,
|
||||
data,
|
||||
size,
|
||||
&ignore_error);
|
||||
}
|
||||
|
||||
g_clear_error (&ignore_error);
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cogl/cogl-buffer-impl-private.h"
|
||||
#include "cogl/cogl-context.h"
|
||||
#include "cogl/cogl-offscreen-private.h"
|
||||
#include "cogl/cogl-framebuffer-private.h"
|
||||
@ -94,36 +95,7 @@ struct _CoglDriverClass
|
||||
CoglClipStack *stack,
|
||||
CoglFramebuffer *framebuffer);
|
||||
|
||||
/* Enables the driver to create some meta data to represent a buffer
|
||||
* 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);
|
||||
CoglBufferImpl * (* create_buffer_impl) (CoglDriver *driver);
|
||||
|
||||
void (*sampler_init) (CoglDriver *driver,
|
||||
CoglContext *context,
|
||||
@ -155,6 +127,8 @@ struct _CoglDriverClass
|
||||
|
||||
#define COGL_TYPE_DRIVER (cogl_driver_get_type ())
|
||||
|
||||
CoglBufferImpl * cogl_driver_create_buffer_impl (CoglDriver *driver);
|
||||
|
||||
#define COGL_DRIVER_ERROR (_cogl_driver_error_quark ())
|
||||
|
||||
typedef enum /*< prefix=COGL_DRIVER_ERROR >*/
|
||||
|
@ -33,12 +33,27 @@
|
||||
|
||||
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
|
||||
cogl_driver_class_init (CoglDriverClass *klass)
|
||||
{
|
||||
klass->create_buffer_impl = cogl_driver_default_create_buffer_impl;
|
||||
}
|
||||
|
||||
static void
|
||||
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,
|
||||
"context", context,
|
||||
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||
"size", (uint64_t) bytes,
|
||||
"default-target", COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
|
||||
"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,
|
||||
"context", context,
|
||||
"impl", cogl_driver_create_buffer_impl (context->driver),
|
||||
"size", (uint64_t) size,
|
||||
"default-target", COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
|
||||
"update-hint", COGL_BUFFER_UPDATE_HINT_STATIC,
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "cogl/cogl-attribute.h"
|
||||
#include "cogl/cogl-attribute-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-progend-glsl-private.h"
|
||||
#include "cogl/driver/gl/cogl-util-gl-private.h"
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "cogl/cogl-buffer-private.h"
|
||||
#include "cogl/cogl-pixel-buffer.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"
|
||||
|
||||
uint8_t *
|
||||
|
@ -38,35 +38,15 @@
|
||||
#include "cogl/cogl-context.h"
|
||||
#include "cogl/cogl-buffer.h"
|
||||
#include "cogl/cogl-buffer-private.h"
|
||||
#include "cogl/cogl-buffer-impl-private.h"
|
||||
|
||||
void
|
||||
_cogl_buffer_gl_create (CoglDriver *driver,
|
||||
CoglBuffer *buffer);
|
||||
#define COGL_TYPE_BUFFER_IMPL_GL (cogl_buffer_impl_gl_get_type ())
|
||||
|
||||
void
|
||||
_cogl_buffer_gl_destroy (CoglDriver *driver,
|
||||
CoglBuffer *buffer);
|
||||
|
||||
void *
|
||||
_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);
|
||||
G_DECLARE_FINAL_TYPE (CoglBufferImplGL,
|
||||
cogl_buffer_impl_gl,
|
||||
COGL,
|
||||
BUFFER_IMPL_GL,
|
||||
CoglBufferImpl)
|
||||
|
||||
void *
|
||||
_cogl_buffer_gl_bind (CoglBuffer *buffer,
|
@ -35,9 +35,18 @@
|
||||
#include "config.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"
|
||||
|
||||
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:
|
||||
*/
|
||||
@ -76,20 +85,23 @@
|
||||
#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
|
||||
#endif
|
||||
|
||||
void
|
||||
_cogl_buffer_gl_create (CoglDriver *driver,
|
||||
CoglBuffer *buffer)
|
||||
static void
|
||||
cogl_buffer_impl_gl_create (CoglBufferImpl *impl,
|
||||
CoglBuffer *buffer)
|
||||
{
|
||||
CoglBufferImplGL *gl_impl = COGL_BUFFER_IMPL_GL (impl);
|
||||
CoglContext *ctx = buffer->context;
|
||||
|
||||
GE (ctx, glGenBuffers (1, &buffer->gl_handle));
|
||||
GE (ctx, glGenBuffers (1, &gl_impl->gl_handle));
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_gl_destroy (CoglDriver *driver,
|
||||
CoglBuffer *buffer)
|
||||
static void
|
||||
cogl_buffer_impl_gl_destroy (CoglBufferImpl *impl,
|
||||
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
|
||||
@ -168,8 +180,9 @@ _cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
|
||||
}
|
||||
|
||||
static void *
|
||||
_cogl_buffer_bind_no_create (CoglBuffer *buffer,
|
||||
CoglBufferBindTarget target)
|
||||
cogl_buffer_impl_gl_bind_no_create (CoglBufferImplGL *gl_impl,
|
||||
CoglBuffer *buffer,
|
||||
CoglBufferBindTarget target)
|
||||
{
|
||||
CoglContext *ctx = buffer->context;
|
||||
|
||||
@ -188,21 +201,21 @@ _cogl_buffer_bind_no_create (CoglBuffer *buffer,
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
void *
|
||||
_cogl_buffer_gl_map_range (CoglDriver *driver,
|
||||
CoglBuffer *buffer,
|
||||
size_t offset,
|
||||
size_t size,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints,
|
||||
GError **error)
|
||||
static void *
|
||||
cogl_buffer_impl_gl_map_range (CoglBufferImpl *impl,
|
||||
CoglBuffer *buffer,
|
||||
size_t offset,
|
||||
size_t size,
|
||||
CoglBufferAccess access,
|
||||
CoglBufferMapHint hints,
|
||||
GError **error)
|
||||
{
|
||||
uint8_t *data;
|
||||
CoglBufferBindTarget target;
|
||||
@ -222,7 +235,9 @@ _cogl_buffer_gl_map_range (CoglDriver *driver,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -328,13 +343,15 @@ _cogl_buffer_gl_map_range (CoglDriver *driver,
|
||||
return data;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_gl_unmap (CoglDriver *driver,
|
||||
CoglBuffer *buffer)
|
||||
static void
|
||||
cogl_buffer_impl_gl_unmap (CoglBufferImpl *impl,
|
||||
CoglBuffer *buffer)
|
||||
{
|
||||
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
|
||||
(buffer->last_target)) );
|
||||
@ -343,13 +360,13 @@ _cogl_buffer_gl_unmap (CoglDriver *driver,
|
||||
_cogl_buffer_gl_unbind (buffer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_cogl_buffer_gl_set_data (CoglDriver *driver,
|
||||
CoglBuffer *buffer,
|
||||
unsigned int offset,
|
||||
const void *data,
|
||||
unsigned int size,
|
||||
GError **error)
|
||||
static gboolean
|
||||
cogl_buffer_impl_gl_set_data (CoglBufferImpl *impl,
|
||||
CoglBuffer *buffer,
|
||||
unsigned int offset,
|
||||
const void *data,
|
||||
unsigned int size,
|
||||
GError **error)
|
||||
{
|
||||
CoglBufferBindTarget target;
|
||||
GLenum gl_target;
|
||||
@ -393,7 +410,9 @@ _cogl_buffer_gl_bind (CoglBuffer *buffer,
|
||||
{
|
||||
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
|
||||
* 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;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "cogl/driver/gl/cogl-buffer-impl-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-buffer-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-gl-framebuffer-fbo.h"
|
||||
@ -296,6 +296,12 @@ cogl_driver_gl_flush_framebuffer_state (CoglDriver *driver,
|
||||
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
|
||||
cogl_driver_gl_sampler_init_init (CoglDriver *driver,
|
||||
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_attributes_state = _cogl_gl_flush_attributes_state;
|
||||
driver_klass->clip_stack_flush = _cogl_clip_stack_gl_flush;
|
||||
driver_klass->buffer_create = _cogl_buffer_gl_create;
|
||||
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->create_buffer_impl = cogl_driver_gl_create_buffer_impl;
|
||||
driver_klass->sampler_init = cogl_driver_gl_sampler_init_init;
|
||||
driver_klass->sampler_free = cogl_driver_gl_sampler_free;
|
||||
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-framebuffer-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-buffer-impl-gl-private.h"
|
||||
#include "cogl/driver/gl/cogl-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-bitmap-gl-private.h',
|
||||
'driver/gl/cogl-bitmap-gl.c',
|
||||
'driver/gl/cogl-buffer-gl-private.h',
|
||||
'driver/gl/cogl-buffer-gl.c',
|
||||
'driver/gl/cogl-buffer-impl-gl-private.h',
|
||||
'driver/gl/cogl-buffer-impl-gl.c',
|
||||
'driver/gl/cogl-clip-stack-gl-private.h',
|
||||
'driver/gl/cogl-clip-stack-gl.c',
|
||||
'driver/gl/cogl-driver-gl.c',
|
||||
@ -159,8 +159,10 @@ cogl_sources = [
|
||||
'cogl-blit.h',
|
||||
'cogl-boxed-value.c',
|
||||
'cogl-boxed-value.h',
|
||||
'cogl-buffer-impl-private.h',
|
||||
'cogl-buffer-private.h',
|
||||
'cogl-buffer.c',
|
||||
'cogl-buffer-impl.c',
|
||||
'cogl-clip-stack.c',
|
||||
'cogl-clip-stack.h',
|
||||
'cogl-closure-list-private.h',
|
||||
|
Loading…
x
Reference in New Issue
Block a user