aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/texture.c41
-rw-r--r--src/window/key.c4
-rw-r--r--src/window/window.c2
3 files changed, 33 insertions, 14 deletions
diff --git a/src/graphics/texture.c b/src/graphics/texture.c
index 9a13314..d33bf58 100644
--- a/src/graphics/texture.c
+++ b/src/graphics/texture.c
@@ -70,7 +70,7 @@ int mgl_texture_init(mgl_texture *self) {
self->max_width = 0;
self->max_height = 0;
self->pixel_coordinates = false;
- self->mipmap = false;
+ self->scale_type = MGL_TEXTURE_SCALE_LINEAR;
self->owned = true;
mgl_context *context = mgl_get_context();
@@ -96,7 +96,7 @@ int mgl_texture_init_reference_existing_gl_texture(mgl_texture *self, unsigned i
self->max_width = 0;
self->max_height = 0;
self->pixel_coordinates = reference_options && reference_options->pixel_coordinates;
- self->mipmap = false;
+ self->scale_type = reference_options ? reference_options->scale_type : MGL_TEXTURE_SCALE_LINEAR;
self->owned = false;
gl_get_texture_size(self->id, &self->width, &self->height);
@@ -137,7 +137,7 @@ int mgl_texture_load_from_memory(mgl_texture *self, const unsigned char *data, i
self->height = height;
self->format = mgl_image_format_to_mgl_texture_format(format);
self->pixel_coordinates = load_options && load_options->pixel_coordinates;
- self->mipmap = load_options && load_options->mipmap && context->gl.glGenerateMipmap; /* TODO: Check if glGenerateMipmap is actually available */
+ self->scale_type = load_options ? load_options->scale_type : MGL_TEXTURE_SCALE_LINEAR; /* TODO: Check if glGenerateMipmap is actually available */
int opengl_texture_format = mgl_texture_format_to_opengl_format(self->format);
if(load_options && load_options->compressed)
@@ -147,13 +147,28 @@ int mgl_texture_load_from_memory(mgl_texture *self, const unsigned char *data, i
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, data);
context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if(self->mipmap) {
- context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- context->gl.glGenerateMipmap(GL_TEXTURE_2D);
- } else {
- context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ switch(self->scale_type) {
+ default:
+ case MGL_TEXTURE_SCALE_LINEAR: {
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ break;
+ }
+ case MGL_TEXTURE_SCALE_NEAREST: {
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ break;
+ }
+ case MGL_TEXTURE_SCALE_LINEAR_MIPMAP: {
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ if(context->gl.glGenerateMipmap) {
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ context->gl.glGenerateMipmap(GL_TEXTURE_2D);
+ } else {
+ context->gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ }
+ break;
+ }
}
context->gl.glBindTexture(GL_TEXTURE_2D, 0);
@@ -168,9 +183,8 @@ int mgl_texture_update(mgl_texture *self, const unsigned char *data, int offset_
context->gl.glBindTexture(GL_TEXTURE_2D, self->id);
const mgl_texture_format texture_format = mgl_image_format_to_mgl_texture_format(format);
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);
- if(self->mipmap) {
+ if(self->scale_type == MGL_TEXTURE_SCALE_LINEAR_MIPMAP && context->gl.glGenerateMipmap)
context->gl.glGenerateMipmap(GL_TEXTURE_2D);
- }
context->gl.glBindTexture(GL_TEXTURE_2D, 0);
return 0;
}
@@ -193,9 +207,8 @@ int mgl_texture_resize(mgl_texture *self, int new_width, int new_height, const m
mgl_context *context = mgl_get_context();
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, NULL);
- if(self->mipmap) {
+ if(self->scale_type == MGL_TEXTURE_SCALE_LINEAR_MIPMAP && context->gl.glGenerateMipmap)
context->gl.glGenerateMipmap(GL_TEXTURE_2D);
- }
context->gl.glBindTexture(GL_TEXTURE_2D, 0);
return 0;
}
diff --git a/src/window/key.c b/src/window/key.c
index b68270a..ffef2b4 100644
--- a/src/window/key.c
+++ b/src/window/key.c
@@ -127,6 +127,8 @@ const char* mgl_key_to_string(mgl_key key) {
case MGL_KEY_F20: return "F20";
case MGL_KEY_F21: return "F21";
case MGL_KEY_F22: return "F22";
+ case MGL_KEY_F23: return "F23";
+ case MGL_KEY_F24: return "F24";
case __MGL_NUM_KEYS__: return "";
}
return "";
@@ -206,6 +208,8 @@ uint64_t mgl_key_to_x11_keysym(mgl_key key) {
case MGL_KEY_F20: return XK_F20;
case MGL_KEY_F21: return XK_F21;
case MGL_KEY_F22: return XK_F22;
+ case MGL_KEY_F23: return XK_F23;
+ case MGL_KEY_F24: return XK_F24;
default: return XK_VoidSymbol;
}
return XK_VoidSymbol;
diff --git a/src/window/window.c b/src/window/window.c
index e7f737d..55efffd 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -1170,6 +1170,8 @@ static mgl_key x11_keysym_to_mgl_key(KeySym key_sym) {
case XK_F20: return MGL_KEY_F20;
case XK_F21: return MGL_KEY_F21;
case XK_F22: return MGL_KEY_F22;
+ case XK_F23: return MGL_KEY_F23;
+ case XK_F24: return MGL_KEY_F24;
}
return MGL_KEY_UNKNOWN;
}