1
0
Fork 0

cogl/indices: Add a IndicesType.get_size

To de-duplicate that code

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3910>
This commit is contained in:
Bilal Elmoussaoui 2024-07-31 17:06:55 +02:00 committed by Marge Bot
parent 609f7e3fe1
commit e43d9d7e75
3 changed files with 8 additions and 19 deletions

View file

@ -46,3 +46,6 @@ struct _CoglIndices
CoglIndicesType type; CoglIndicesType type;
}; };
size_t
cogl_indices_type_get_size (CoglIndicesType type);

View file

@ -67,8 +67,8 @@ cogl_indices_class_init (CoglIndicesClass *class)
object_class->dispose = cogl_indices_dispose; object_class->dispose = cogl_indices_dispose;
} }
static size_t size_t
sizeof_indices_type (CoglIndicesType type) cogl_indices_type_get_size (CoglIndicesType type)
{ {
switch (type) switch (type)
{ {
@ -103,7 +103,7 @@ cogl_indices_new (CoglContext *context,
const void *indices_data, const void *indices_data,
int n_indices) int n_indices)
{ {
size_t buffer_bytes = sizeof_indices_type (type) * n_indices; size_t buffer_bytes = cogl_indices_type_get_size (type) * n_indices;
CoglIndexBuffer *index_buffer = cogl_index_buffer_new (context, buffer_bytes); CoglIndexBuffer *index_buffer = cogl_index_buffer_new (context, buffer_bytes);
CoglBuffer *buffer = COGL_BUFFER (index_buffer); CoglBuffer *buffer = COGL_BUFFER (index_buffer);
CoglIndices *indices; CoglIndices *indices;

View file

@ -34,6 +34,7 @@
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-framebuffer-private.h"
#include "cogl/cogl-framebuffer.h" #include "cogl/cogl-framebuffer.h"
#include "cogl/cogl-indices-private.h"
#include "cogl/cogl-offscreen-private.h" #include "cogl/cogl-offscreen-private.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
#include "cogl/driver/gl/cogl-util-gl-private.h" #include "cogl/driver/gl/cogl-util-gl-private.h"
@ -324,21 +325,6 @@ cogl_gl_framebuffer_draw_attributes (CoglFramebufferDriver *driver,
glDrawArrays ((GLenum)mode, first_vertex, n_vertices)); glDrawArrays ((GLenum)mode, first_vertex, n_vertices));
} }
static size_t
sizeof_index_type (CoglIndicesType type)
{
switch (type)
{
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
return 1;
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
return 2;
case COGL_INDICES_TYPE_UNSIGNED_INT:
return 4;
}
g_return_val_if_reached (0);
}
static void static void
cogl_gl_framebuffer_draw_indexed_attributes (CoglFramebufferDriver *driver, cogl_gl_framebuffer_draw_indexed_attributes (CoglFramebufferDriver *driver,
CoglPipeline *pipeline, CoglPipeline *pipeline,
@ -371,7 +357,7 @@ cogl_gl_framebuffer_draw_indexed_attributes (CoglFramebufferDriver *driver,
base = _cogl_buffer_gl_bind (buffer, base = _cogl_buffer_gl_bind (buffer,
COGL_BUFFER_BIND_TARGET_INDEX_BUFFER, NULL); COGL_BUFFER_BIND_TARGET_INDEX_BUFFER, NULL);
buffer_offset = cogl_indices_get_offset (indices); buffer_offset = cogl_indices_get_offset (indices);
index_size = sizeof_index_type (cogl_indices_get_indices_type (indices)); index_size = cogl_indices_type_get_size (cogl_indices_get_indices_type (indices));
switch (cogl_indices_get_indices_type (indices)) switch (cogl_indices_get_indices_type (indices))
{ {