aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-12 21:09:53 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-12 21:09:53 +0200
commit08dcbfa7772149bcdcc0ab660a897853a30103a0 (patch)
treec3789dadef191e8942993d1e8fcafc266377ed8a /src
parent4aa7273eea642bff78477b0b220c7056628b13a8 (diff)
compressed texture
Diffstat (limited to 'src')
-rw-r--r--src/graphics/texture.c13
-rw-r--r--src/window.c12
2 files changed, 18 insertions, 7 deletions
diff --git a/src/graphics/texture.c b/src/graphics/texture.c
index 3d3ea6f..ebc4e58 100644
--- a/src/graphics/texture.c
+++ b/src/graphics/texture.c
@@ -19,6 +19,16 @@ static int mgl_texture_format_to_opengl_format(mgl_texture_format format) {
return 0;
}
+static int mgl_texture_format_to_compressed_opengl_format(mgl_texture_format format) {
+ switch(format) {
+ case MGL_TEXTURE_GRAY: return GL_LUMINANCE8;
+ case MGL_TEXTURE_GRAY_ALPHA: return GL_LUMINANCE8_ALPHA8;
+ case MGL_TEXTURE_RGB: return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
+ case MGL_TEXTURE_RGB_ALPHA: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ }
+ return 0;
+}
+
static int mgl_texture_format_to_source_opengl_format(mgl_texture_format format) {
switch(format) {
case MGL_TEXTURE_GRAY: return GL_LUMINANCE8_ALPHA8;
@@ -30,6 +40,7 @@ static int mgl_texture_format_to_source_opengl_format(mgl_texture_format format)
}
/* TODO: Ensure texture is power of 2 if the hardware doesn't support non power of two textures */
+/* TODO: Verify if source format should always be 4 components (RGBA) because apparently if its another format then opengl will internally convert it to RGBA */
int mgl_texture_load_from_file(mgl_texture *self, const char *filepath) {
self->id = 0;
@@ -48,7 +59,7 @@ int mgl_texture_load_from_file(mgl_texture *self, const char *filepath) {
return -1;
}
- const int opengl_texture_format = mgl_texture_format_to_opengl_format(self->format);
+ const int opengl_texture_format = mgl_texture_format_to_compressed_opengl_format(self->format);
context->gl.glBindTexture(GL_TEXTURE_2D, self->id);
context->gl.glTexImage2D(GL_TEXTURE_2D, 0, opengl_texture_format, self->width, self->height, 0, mgl_texture_format_to_source_opengl_format(self->format), GL_UNSIGNED_BYTE, image_data);
diff --git a/src/window.c b/src/window.c
index 7d13ffe..ccfab93 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,6 +1,7 @@
#include "../include/mgl/window.h"
#include "../include/mgl/mgl.h"
#include <X11/Xutil.h>
+#include <errno.h>
#include <stdio.h>
/* TODO: check for glx swap control extension string (GLX_EXT_swap_control, etc) */
@@ -26,14 +27,13 @@ static void set_vertical_sync_enabled(Window window, int enabled) {
fprintf(stderr, "Warning: setting vertical sync failed\n");
}
-int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback, void *userdata) {
- return mgl_window_create_with_params(self, title, width, height, DefaultRootWindow(mgl_get_context()->connection), callback, userdata);
+int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback) {
+ return mgl_window_create_with_params(self, title, width, height, DefaultRootWindow(mgl_get_context()->connection), callback);
}
-int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback, void *userdata) {
+int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback) {
self->window = 0;
self->callback = *callback;
- self->callback_userdata = userdata;
mgl_context *context = mgl_get_context();
@@ -104,7 +104,7 @@ void mgl_window_events_poll(mgl_window *self) {
XNextEvent(display, &xev);
on_receive_x11_event(self, &xev);
}
- } else if(num_ready_fds == -1) {
+ } else if(num_ready_fds == -1 && errno != EINTR) {
/* TODO: */
fprintf(stderr, "Disconnected!\n");
}
@@ -121,6 +121,6 @@ void mgl_window_draw(mgl_window *self) {
context->gl.glClear(GL_COLOR_BUFFER_BIT);
context->gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
if(self->callback.draw)
- self->callback.draw(self, self->callback_userdata);
+ self->callback.draw(self, self->callback.userdata);
context->gl.glXSwapBuffers(context->connection, self->window);
}