Skip to content

Commit

Permalink
Add glimpl_get_pixel_size
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaivel committed Jul 6, 2024
1 parent 94945e2 commit 1e0e31c
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/client/glimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,54 +520,49 @@ static struct gl_vertex_attrib_pointer *glimpl_get_enabled_vap()
return NULL;
}

static void glimpl_upload_texture(GLsizei width, GLsizei height, GLsizei depth, GLenum format, const void* pixels)
static inline size_t glimpl_get_pixel_size(GLenum format)
{
if (pixels == NULL) {
pb_push(SGL_CMD_VP_NULL);
return;
}

size_t pixel_size;
size_t total_size;

switch (format) {
case GL_RGBA:
case GL_RGBA8:
case GL_BGRA:
case GL_COMPRESSED_SRGB_ALPHA:
pixel_size = 4;
break;
return 4;
case GL_RGB:
case GL_BGR:
case GL_RGB8:
pixel_size = 3;
break;
return 3;
case GL_LUMINANCE_ALPHA:
case GL_RG:
case GL_RG8:
pixel_size = 2;
break;
return 2;
case GL_LUMINANCE:
case GL_ALPHA:
case GL_RED:
case GL_R8:
pixel_size = 1;
break;
return 1;
case GL_RGB16F:
case GL_RGB16I:
case GL_RGB16UI:
pixel_size = 6;
break;
return 6;
case GL_RGBA16F:
case GL_RGBA16I:
case GL_RGBA16UI:
pixel_size = 8;
break;
return 8;
default:
return 1;
}
}

static void glimpl_upload_texture(GLsizei width, GLsizei height, GLsizei depth, GLenum format, const void* pixels)
{
if (pixels == NULL) {
pb_push(SGL_CMD_VP_NULL);
return;
}

total_size = width * height * depth * pixel_size;
size_t total_size = width * height * depth * glimpl_get_pixel_size(format);

pb_push(SGL_CMD_VP_UPLOAD);
pb_push(CEIL_DIV(total_size, 4));
pb_memcpy((void*)pixels, total_size);
Expand Down Expand Up @@ -595,18 +590,8 @@ static inline void glimpl_push_client_pointers(int mode, int max_index)
if (glimpl_color_ptr.in_use) {
int true_size = glimpl_color_ptr.size;

if (true_size > 4) {
switch (true_size) {
case GL_RGB:
case GL_BGR:
true_size = 3;
break;
case GL_RGBA:
case GL_BGRA:
true_size = 4;
break;
}
}
if (true_size > 8)
true_size = glimpl_get_pixel_size(true_size);

pb_push(SGL_CMD_VP_UPLOAD);
pb_push(max_index);
Expand Down

0 comments on commit 1e0e31c

Please sign in to comment.