diff options
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); |