diff --git a/source/engine/graphics/front/group/FrameBufferGroup.cpp b/source/engine/graphics/front/group/FrameBufferGroup.cpp index 80f853d5beacbfd95053403a1ab7ca6c7fbf3ec9..6653a7c71709eac75061683075d736721f24e445 100644 --- a/source/engine/graphics/front/group/FrameBufferGroup.cpp +++ b/source/engine/graphics/front/group/FrameBufferGroup.cpp @@ -2,6 +2,7 @@ #include <glm/gtc/matrix_transform.hpp> #include <engine/graphics/front/geometry/Plane.hpp> +#include <engine/graphics/utility/array_generator.hpp> namespace megu { FrameBufferGroup::FrameBufferGroup() @@ -28,7 +29,9 @@ namespace megu { textures[i].get().bind(static_cast<GLuint>(i)); } - this->_program.setUniform("uSampler", std::vector<GLint>{0, 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10}); + static auto uSampler = array_generator<GLint, 32>().array; + + this->_program.setUniform("uSampler", uSampler); this->_program.setUniform("uTexturesCount", static_cast<GLuint>(textures.size())); glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size())); } diff --git a/source/engine/graphics/front/group/ImageGroup.cpp b/source/engine/graphics/front/group/ImageGroup.cpp index 345e8d38d262bcbc9e529822ddc6e0df204222dc..8730cb99266fcba713627330571c6c30faf2165f 100644 --- a/source/engine/graphics/front/group/ImageGroup.cpp +++ b/source/engine/graphics/front/group/ImageGroup.cpp @@ -2,6 +2,8 @@ #include <tuple> +#include <engine/graphics/utility/array_generator.hpp> + namespace megu { ImageGroup::ImageGroup() : _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) { @@ -39,6 +41,8 @@ namespace megu { std::vector<glm::mat4> uModels; std::vector<GLint> uTextures; + + static auto uSampler = array_generator<GLint, 32>().array; for(auto & image : this->_images) { @@ -51,7 +55,7 @@ namespace megu { if(textures.size() >= 8 || uModels.size() >= 124) { this->_program.setUniform("uProj", camera.projection()); this->_program.setUniform("uView", camera.view()); - this->_program.setUniform("uSampler", std::vector<GLint>({0, 1, 2, 3, 4, 5, 6, 7})); + this->_program.setUniform("uSampler", uSampler); this->_program.setUniform("uModel", uModels); this->_program.setUniform("uTextures", uTextures); @@ -73,7 +77,8 @@ namespace megu { this->_program.setUniform("uProj", camera.projection()); this->_program.setUniform("uView", camera.view()); - this->_program.setUniform("uSampler", std::vector<GLint>({0, 1, 2, 3, 4, 5, 6, 7})); + + this->_program.setUniform("uSampler", uSampler); this->_program.setUniform("uModel", uModels); this->_program.setUniform("uTextures", uTextures); diff --git a/source/engine/graphics/utility/array_generator.hpp b/source/engine/graphics/utility/array_generator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9b867f5edd57ab34f2bcbb5e287b995dfe30a7ca --- /dev/null +++ b/source/engine/graphics/utility/array_generator.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include <vector> + +namespace megu { + template <typename T, T C> + struct array_generator { + public: + constexpr array_generator() { + for(T i = 0; i < C; ++i) { + this->array.push_back(i); + } + } + std::vector<T> array; + }; +} \ No newline at end of file