This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
#pragma once
#include "../../assets/dynamic_read_buffers"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp"
#include "opengl/data/texture_data.hpp"
#include <vector>
namespace zgl
{
class texture_data_uploader
{
void upload(
std::span<const dynamic_texture_data> dynamic_data,
std::span<const dynamic_texture_store::id_type> dynamic_data_ids
) {
std::vector<GLuint> texture_ids;
std::vector<GLuint> 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());
}
};
}