diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-12 21:09:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-12 21:09:53 +0200 |
commit | 08dcbfa7772149bcdcc0ab660a897853a30103a0 (patch) | |
tree | c3789dadef191e8942993d1e8fcafc266377ed8a /src/graphics | |
parent | 4aa7273eea642bff78477b0b220c7056628b13a8 (diff) |
compressed texture
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/texture.c | 13 |
1 files changed, 12 insertions, 1 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); |