diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-16 23:03:58 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-16 23:03:58 +0100 |
commit | e0b1d92dd4ab93ac0f75dda7adc0f5274558dec1 (patch) | |
tree | 4411b002118dfd6fdcc1537e1d48595d9a520075 | |
parent | 62a89c4bf63357fb95c34898a37ff663293a8dea (diff) |
Texture: only do one glTexSubImage2D in mgl_texture_update instead of |height| number of times
-rw-r--r-- | include/mgl/gl.h | 1 | ||||
-rw-r--r-- | include/mgl/gl_macro.h | 2 | ||||
-rw-r--r-- | src/gl.c | 1 | ||||
-rw-r--r-- | src/graphics/texture.c | 9 |
4 files changed, 6 insertions, 7 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h index 7dc1dd7..894e57b 100644 --- a/include/mgl/gl.h +++ b/include/mgl/gl.h @@ -73,6 +73,7 @@ typedef struct { unsigned int (*glGetError)(void); const unsigned char* (*glGetString)(unsigned int name); void (*glGetIntegerv)(unsigned int pname, int *params); + void (*glPixelStorei)(unsigned int pname, int param); /* Optional*/ void (*glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval); diff --git a/include/mgl/gl_macro.h b/include/mgl/gl_macro.h index 5e634df..0db0a60 100644 --- a/include/mgl/gl_macro.h +++ b/include/mgl/gl_macro.h @@ -85,6 +85,8 @@ #define GL_LINK_STATUS 0x8B82 #define GL_COMPILE_STATUS 0x8B81 +#define GL_UNPACK_ALIGNMENT 0x0CF5 + #define GL_FALSE 0 #define GL_TRUE 1 @@ -87,6 +87,7 @@ int mgl_gl_load(mgl_gl *self) { { &self->glGetError, "glGetError" }, { &self->glGetString, "glGetString" }, { &self->glGetIntegerv, "glGetIntegerv" }, + { &self->glPixelStorei, "glPixelStorei" }, { NULL, NULL } }; diff --git a/src/graphics/texture.c b/src/graphics/texture.c index 2387fa7..0ae21cf 100644 --- a/src/graphics/texture.c +++ b/src/graphics/texture.c @@ -122,14 +122,9 @@ int mgl_texture_update(mgl_texture *self, const unsigned char *data, int offset_ mgl_context *context = mgl_get_context(); context->gl.glBindTexture(GL_TEXTURE_2D, self->id); const mgl_texture_format texture_format = mgl_image_format_to_mgl_texture_format(format); - /* TODO: TODO: Only do one glTexSubImage2D */ -#if 1 - for(int i = 0; i < height; ++i) { - context->gl.glTexSubImage2D(GL_TEXTURE_2D, 0, offset_x, offset_y + i, width, 1, mgl_texture_format_to_source_opengl_format(texture_format), GL_UNSIGNED_BYTE, data + (i * width)); - } -#else + context->gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); context->gl.glTexSubImage2D(GL_TEXTURE_2D, 0, offset_x, offset_y, width, height, mgl_texture_format_to_source_opengl_format(texture_format), GL_UNSIGNED_BYTE, data); -#endif + context->gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 0); context->gl.glBindTexture(GL_TEXTURE_2D, 0); return 0; } |