| 21 | namespace ZEngine::Rendering::Textures { |
| 22 | |
| 23 | Texture2D::Texture2D(const char* path) : Texture(path) { |
| 24 | int width = 0, height = 0, channel = 0; |
| 25 | stbi_set_flip_vertically_on_load(1); |
| 26 | stbi_uc* image_data = stbi_load(path, &width, &height, &channel, 0); |
| 27 | |
| 28 | if (image_data != nullptr) { |
| 29 | |
| 30 | m_internal_format = (channel == 3) ? GL_RGB8 : GL_RGBA8; |
| 31 | m_data_format = (channel == 3) ? GL_RGB : GL_RGBA; |
| 32 | |
| 33 | #ifdef _WIN32 |
| 34 | glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id); |
| 35 | glTextureStorage2D(m_texture_id, 1, m_internal_format, width, height); |
| 36 | |
| 37 | glTextureParameterf(m_texture_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 38 | glTextureParameterf(m_texture_id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 39 | |
| 40 | glTextureParameteri(m_texture_id, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 41 | glTextureParameteri(m_texture_id, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 42 | #else |
| 43 | glGenTextures(1, &m_texture_id); |
| 44 | glBindTexture(GL_TEXTURE_2D, m_texture_id); |
| 45 | |
| 46 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 47 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 48 | |
| 49 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 50 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 51 | #endif |
| 52 | m_width = width; |
| 53 | m_height = height; |
| 54 | |
| 55 | #ifdef _WIN32 |
| 56 | glTextureSubImage2D(m_texture_id, 0, 0, 0, width, height, m_data_format, GL_UNSIGNED_BYTE, (const void*) (image_data)); |
| 57 | #else |
| 58 | glTexImage2D(GL_TEXTURE_2D, 0, m_internal_format, width, height, 0, m_data_format, GL_UNSIGNED_BYTE, (const void*) (image_data)); |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | stbi_image_free(image_data); |
| 63 | } |
| 64 | |
| 65 | Texture2D::Texture2D(unsigned int width, unsigned int height) : Texture(width, height) { |
| 66 | m_internal_format = GL_RGBA8; |
nothing calls this directly
no outgoing calls
no test coverage detected