2023-08-21 00:18:37 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskglbufferprivate.h"
|
|
|
|
|
|
|
|
struct _GskGLBuffer
|
|
|
|
{
|
|
|
|
GskGpuBuffer parent_instance;
|
|
|
|
|
|
|
|
GLenum target;
|
|
|
|
GLuint buffer_id;
|
2023-10-04 19:42:36 +00:00
|
|
|
guchar *data;
|
2023-08-21 00:18:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskGLBuffer, gsk_gl_buffer, GSK_TYPE_GPU_BUFFER)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_buffer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GskGLBuffer *self = GSK_GL_BUFFER (object);
|
|
|
|
|
2023-10-04 19:42:36 +00:00
|
|
|
g_free (self->data);
|
2023-08-21 00:18:37 +00:00
|
|
|
glDeleteBuffers (1, &self->buffer_id);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_gl_buffer_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static guchar *
|
|
|
|
gsk_gl_buffer_map (GskGpuBuffer *buffer)
|
|
|
|
{
|
|
|
|
GskGLBuffer *self = GSK_GL_BUFFER (buffer);
|
|
|
|
|
2023-10-04 19:42:36 +00:00
|
|
|
return self->data;
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-03-08 21:54:53 +00:00
|
|
|
gsk_gl_buffer_unmap (GskGpuBuffer *buffer,
|
|
|
|
gsize used)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
|
|
|
GskGLBuffer *self = GSK_GL_BUFFER (buffer);
|
|
|
|
|
2024-03-08 21:54:53 +00:00
|
|
|
if (used == 0)
|
|
|
|
return;
|
|
|
|
|
2023-08-21 00:18:37 +00:00
|
|
|
gsk_gl_buffer_bind (self);
|
|
|
|
|
2024-03-08 21:54:53 +00:00
|
|
|
glBufferSubData (self->target, 0, used, self->data);
|
2023-08-21 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_buffer_class_init (GskGLBufferClass *klass)
|
|
|
|
{
|
|
|
|
GskGpuBufferClass *buffer_class = GSK_GPU_BUFFER_CLASS (klass);
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
buffer_class->map = gsk_gl_buffer_map;
|
|
|
|
buffer_class->unmap = gsk_gl_buffer_unmap;
|
|
|
|
|
|
|
|
gobject_class->finalize = gsk_gl_buffer_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_gl_buffer_init (GskGLBuffer *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GskGpuBuffer *
|
|
|
|
gsk_gl_buffer_new (GLenum target,
|
2024-03-16 18:46:37 +00:00
|
|
|
gsize size)
|
2023-08-21 00:18:37 +00:00
|
|
|
{
|
|
|
|
GskGLBuffer *self;
|
|
|
|
|
|
|
|
self = g_object_new (GSK_TYPE_GL_BUFFER, NULL);
|
|
|
|
|
|
|
|
gsk_gpu_buffer_setup (GSK_GPU_BUFFER (self), size);
|
|
|
|
|
|
|
|
self->target = target;
|
|
|
|
|
|
|
|
glGenBuffers (1, &self->buffer_id);
|
|
|
|
glBindBuffer (target, self->buffer_id);
|
|
|
|
glBufferData (target, size, NULL, GL_STATIC_DRAW);
|
2023-10-04 19:42:36 +00:00
|
|
|
self->data = malloc (size);
|
2023-08-21 00:18:37 +00:00
|
|
|
|
|
|
|
return GSK_GPU_BUFFER (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_gl_buffer_bind (GskGLBuffer *self)
|
|
|
|
{
|
|
|
|
glBindBuffer (self->target, self->buffer_id);
|
|
|
|
}
|
|
|
|
|
2023-08-30 19:57:41 +00:00
|
|
|
void
|
|
|
|
gsk_gl_buffer_bind_base (GskGLBuffer *self,
|
|
|
|
GLuint index)
|
|
|
|
{
|
|
|
|
glBindBufferBase (self->target, index, self->buffer_id);
|
|
|
|
}
|
|
|
|
|