...
This commit is contained in:
parent
3cbc20005b
commit
6d960e4130
@ -98,7 +98,7 @@ free_texture_impl(GLuint *tex_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_image_to_gpu_impl(GLuint *tex_id, const void* data, GLsizei width, GLsizei height, bool is_rgb, bool is_4byte_aligned) {
|
send_image_to_gpu_impl(GLuint *tex_id, const void* data, GLsizei width, GLsizei height, bool is_opaque, bool is_4byte_aligned) {
|
||||||
if (!(*tex_id)) { glGenTextures(1, tex_id); check_gl(); }
|
if (!(*tex_id)) { glGenTextures(1, tex_id); check_gl(); }
|
||||||
glBindTexture(GL_TEXTURE_2D, *tex_id); check_gl();
|
glBindTexture(GL_TEXTURE_2D, *tex_id); check_gl();
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, is_4byte_aligned ? 4 : 1); check_gl();
|
glPixelStorei(GL_UNPACK_ALIGNMENT, is_4byte_aligned ? 4 : 1); check_gl();
|
||||||
@ -106,7 +106,7 @@ send_image_to_gpu_impl(GLuint *tex_id, const void* data, GLsizei width, GLsizei
|
|||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_gl();
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_gl();
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, is_rgb ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, data); check_gl();
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, is_opaque ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, data); check_gl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -338,7 +338,7 @@ handle_add_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_
|
|||||||
case PNG:
|
case PNG:
|
||||||
if (g->data_sz > MAX_DATA_SZ) ABRT(EINVAL, "PNG data size too large");
|
if (g->data_sz > MAX_DATA_SZ) ABRT(EINVAL, "PNG data size too large");
|
||||||
img->load_data.is_4byte_aligned = true;
|
img->load_data.is_4byte_aligned = true;
|
||||||
img->load_data.is_rgb = false;
|
img->load_data.is_opaque = false;
|
||||||
img->load_data.data_sz = g->data_sz ? g->data_sz : 1024 * 100;
|
img->load_data.data_sz = g->data_sz ? g->data_sz : 1024 * 100;
|
||||||
break;
|
break;
|
||||||
case RGB:
|
case RGB:
|
||||||
@ -346,7 +346,7 @@ handle_add_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_
|
|||||||
img->load_data.data_sz = g->data_width * g->data_height * (fmt / 8);
|
img->load_data.data_sz = g->data_width * g->data_height * (fmt / 8);
|
||||||
if (!img->load_data.data_sz) ABRT(EINVAL, "Zero width/height not allowed");
|
if (!img->load_data.data_sz) ABRT(EINVAL, "Zero width/height not allowed");
|
||||||
img->load_data.is_4byte_aligned = fmt == RGBA || (img->width % 4 == 0);
|
img->load_data.is_4byte_aligned = fmt == RGBA || (img->width % 4 == 0);
|
||||||
img->load_data.is_rgb = fmt == RGB;
|
img->load_data.is_opaque = fmt == RGB;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ABRT(EINVAL, "Unknown image format: %u", fmt);
|
ABRT(EINVAL, "Unknown image format: %u", fmt);
|
||||||
@ -448,10 +448,10 @@ handle_add_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_
|
|||||||
} else img->load_data.data = img->load_data.mapped_file;
|
} else img->load_data.data = img->load_data.mapped_file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t required_sz = (img->load_data.is_rgb ? 3 : 4) * img->width * img->height;
|
size_t required_sz = (img->load_data.is_opaque ? 3 : 4) * img->width * img->height;
|
||||||
if (img->load_data.data_sz != required_sz) ABRT(EINVAL, "Image dimensions: %ux%u do not match data size: %zu, expected size: %zu", img->width, img->height, img->load_data.data_sz, required_sz);
|
if (img->load_data.data_sz != required_sz) ABRT(EINVAL, "Image dimensions: %ux%u do not match data size: %zu, expected size: %zu", img->width, img->height, img->load_data.data_sz, required_sz);
|
||||||
if (LIKELY(img->data_loaded && send_to_gpu)) {
|
if (LIKELY(img->data_loaded && send_to_gpu)) {
|
||||||
send_image_to_gpu(&img->texture_id, img->load_data.data, img->width, img->height, img->load_data.is_rgb, img->load_data.is_4byte_aligned);
|
send_image_to_gpu(&img->texture_id, img->load_data.data, img->width, img->height, img->load_data.is_opaque, img->load_data.is_4byte_aligned);
|
||||||
free_load_data(&img->load_data);
|
free_load_data(&img->load_data);
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ typedef struct {
|
|||||||
size_t data_sz;
|
size_t data_sz;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
bool is_4byte_aligned;
|
bool is_4byte_aligned;
|
||||||
bool is_rgb;
|
bool is_opaque;
|
||||||
} LoadData;
|
} LoadData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -102,4 +102,4 @@ EXTERNAL_FUNC(draw_cells, void, ssize_t, float, float, float, float, Screen *, C
|
|||||||
EXTERNAL_FUNC(draw_cursor, void, CursorRenderInfo *);
|
EXTERNAL_FUNC(draw_cursor, void, CursorRenderInfo *);
|
||||||
EXTERNAL_FUNC(update_viewport_size, void, int, int);
|
EXTERNAL_FUNC(update_viewport_size, void, int, int);
|
||||||
EXTERNAL_FUNC(free_texture, void, uint32_t*);
|
EXTERNAL_FUNC(free_texture, void, uint32_t*);
|
||||||
EXTERNAL_FUNC(send_image_to_gpu, void, uint32_t*, const void*, int32_t width, int32_t height, bool is_rgba, bool is_4byte_aligned);
|
EXTERNAL_FUNC(send_image_to_gpu, void, uint32_t*, const void*, int32_t, int32_t, bool, bool);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user