diff options
author | LaG1924 <lag1924@gmail.com> | 2021-11-19 11:02:11 +0100 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-11-19 11:02:11 +0100 |
commit | b99f058de08063cb1632a9ef35e4edb10097f31b (patch) | |
tree | 1e730998ba83b06a326e356a1b3b1f5ed3ef99b7 /src/TextureAtlas.cpp | |
parent | Changed sky rendering to Gal (diff) | |
download | AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar.gz AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar.bz2 AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar.lz AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar.xz AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.tar.zst AltCraft-b99f058de08063cb1632a9ef35e4edb10097f31b.zip |
Diffstat (limited to 'src/TextureAtlas.cpp')
-rw-r--r-- | src/TextureAtlas.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/TextureAtlas.cpp b/src/TextureAtlas.cpp index 406418f..7e44a86 100644 --- a/src/TextureAtlas.cpp +++ b/src/TextureAtlas.cpp @@ -35,7 +35,7 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) { textureCoords.resize(textures.size()); - int layer = 0; + size_t layer = 0; for (;;layer++) { stbrp_context context; std::vector<stbrp_node> nodes; @@ -81,18 +81,16 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) { } LOG(INFO) << "Texture atlas size is " << textureSize << "x" << textureSize << "x" << layer; - //OpenGL + //Gal int mipLevelCount = 1; - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D_ARRAY, texture); - glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, textureSize, textureSize, layer+1); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + auto gal = Gal::GetImplementation(); + auto texConfig = gal->CreateTexture3DConfig(textureSize, textureSize, layer + 1, false, Gal::Format::R8G8B8A8); + texConfig->SetWrapping(Gal::Wrapping::Clamp); + texConfig->SetMinFilter(Gal::Filtering::Nearest); + texConfig->SetMaxFilter(Gal::Filtering::Nearest); - glCheckError(); + texture = gal->BuildTexture(texConfig); //Uploading texture data for (int i = 0; i < textureCoords.size(); i++) { @@ -105,14 +103,16 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) { std::swap(*(src + j), *(dst + j)); } } - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, textureCoords[i].pixelX, textureSize - textureCoords[i].pixelY - textureCoords[i].pixelH, textureCoords[i].layer, - textureCoords[i].pixelW, textureCoords[i].pixelH, 1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, textures[i].data.data()); - glCheckError(); + texture->SetSubData( + textureCoords[i].pixelX, + textureSize - textureCoords[i].pixelY - textureCoords[i].pixelH, + textureCoords[i].layer, + textureCoords[i].pixelW, + textureCoords[i].pixelH, + 1, + { reinterpret_cast<std::byte*>(textures[i].data.data()), reinterpret_cast<std::byte*>(textures[i].data.data()) + textures[i].data.size() } + ); } LOG(INFO) << "Texture atlas initialized"; } - -TextureAtlas::~TextureAtlas() { - glDeleteTextures(1, &texture); -} |