#pragma once #include "../../assets/dynamic_read_buffers" #include "assets/dynamic_data_stores/dynamic_texture_store.hpp" #include "opengl/data/texture_data.hpp" #include namespace zgl { class texture_data_uploader { void upload( std::span dynamic_data, std::span dynamic_data_ids ) { std::vector texture_ids; std::vector invalid_texture_ids; texture_ids.resize(dynamic_data.size()); glGenTextures(texture_ids.size(), texture_ids.data()); auto texture_id_it = texture_ids.begin(); for (std::size_t i{}; i != dynamic_data.size(); ++i) { const auto& texture_id = *texture_id_it; const auto& texture = dynamic_data[i]; glBindTexture(GL_TEXTURE_2D, texture_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLenum format; switch (texture.components()) { using enum components::texture::flags; case luminance: format = GL_LUMINANCE; break; case luminance | alpha: format = GL_LUMINANCE_ALPHA; break; case red | green | blue: format = GL_RGB; break; case red | green | blue | alpha: format = GL_RGBA; break; default: format = GL_INVALID_ENUM; break; } if (format == GL_INVALID_ENUM) { invalid_texture_ids.push_back(texture_id); } else { glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, texture.width(), texture.height(), 0, format, GL_UNSIGNED_BYTE, texture.data() ); glGenerateMipmap(GL_TEXTURE_2D); } } glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(invalid_texture_ids.size(), invalid_texture_ids.data()); } }; }