| 1994 | } |
| 1995 | |
| 1996 | LfTexture lf_load_texture_from_memory(const void* data, size_t size, bool flip, LfTextureFiltering filter) { |
| 1997 | LfTexture tex; |
| 1998 | int width, height, channels; |
| 1999 | unsigned char* image = stbi_load_from_memory(data, size, &width, &height, &channels, STBI_rgb_alpha); |
| 2000 | if (!image) { |
| 2001 | return tex; |
| 2002 | } |
| 2003 | |
| 2004 | glGenTextures(1, &tex.id); |
| 2005 | glBindTexture(GL_TEXTURE_2D, tex.id); |
| 2006 | |
| 2007 | // Set texture parameters |
| 2008 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 2009 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 2010 | switch(filter) { |
| 2011 | case LF_TEX_FILTER_LINEAR: |
| 2012 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 2013 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 2014 | break; |
| 2015 | case LF_TEX_FILTER_NEAREST: |
| 2016 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2017 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2018 | break; |
| 2019 | } |
| 2020 | |
| 2021 | // Load texture data |
| 2022 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 2023 | glGenerateMipmap(GL_TEXTURE_2D); |
| 2024 | stbi_image_free(image); // Free image data |
| 2025 | tex.width = width; |
| 2026 | tex.height = height; |
| 2027 | return tex; |
| 2028 | |
| 2029 | } |
| 2030 | LfTexture lf_load_texture_from_memory_resized(const void* data, size_t size, bool flip, LfTextureFiltering filter, uint32_t w, uint32_t h) { |
| 2031 | LfTexture tex; |
| 2032 |
nothing calls this directly
no outgoing calls
no test coverage detected