Skip to content
Snippets Groups Projects
Commit 9b2c943e authored by BATON Theau's avatar BATON Theau
Browse files

Set uSampler uniform as static vector auto builed

parent d2bba1be
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <engine/graphics/front/geometry/Plane.hpp> #include <engine/graphics/front/geometry/Plane.hpp>
#include <engine/graphics/utility/array_generator.hpp>
namespace megu { namespace megu {
FrameBufferGroup::FrameBufferGroup() FrameBufferGroup::FrameBufferGroup()
...@@ -28,7 +29,9 @@ namespace megu { ...@@ -28,7 +29,9 @@ namespace megu {
textures[i].get().bind(static_cast<GLuint>(i)); 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())); this->_program.setUniform("uTexturesCount", static_cast<GLuint>(textures.size()));
glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size())); glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size()));
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <tuple> #include <tuple>
#include <engine/graphics/utility/array_generator.hpp>
namespace megu { namespace megu {
ImageGroup::ImageGroup() ImageGroup::ImageGroup()
: _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) { : _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) {
...@@ -40,6 +42,8 @@ namespace megu { ...@@ -40,6 +42,8 @@ namespace megu {
std::vector<glm::mat4> uModels; std::vector<glm::mat4> uModels;
std::vector<GLint> uTextures; std::vector<GLint> uTextures;
static auto uSampler = array_generator<GLint, 32>().array;
for(auto & image : this->_images) { for(auto & image : this->_images) {
std::vector<std::reference_wrapper<const Texture>>::iterator it = std::find(textures.begin(), textures.end(), image.get().texture()); std::vector<std::reference_wrapper<const Texture>>::iterator it = std::find(textures.begin(), textures.end(), image.get().texture());
...@@ -51,7 +55,7 @@ namespace megu { ...@@ -51,7 +55,7 @@ namespace megu {
if(textures.size() >= 8 || uModels.size() >= 124) { if(textures.size() >= 8 || uModels.size() >= 124) {
this->_program.setUniform("uProj", camera.projection()); this->_program.setUniform("uProj", camera.projection());
this->_program.setUniform("uView", camera.view()); 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("uModel", uModels);
this->_program.setUniform("uTextures", uTextures); this->_program.setUniform("uTextures", uTextures);
...@@ -73,7 +77,8 @@ namespace megu { ...@@ -73,7 +77,8 @@ namespace megu {
this->_program.setUniform("uProj", camera.projection()); this->_program.setUniform("uProj", camera.projection());
this->_program.setUniform("uView", camera.view()); 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("uModel", uModels);
this->_program.setUniform("uTextures", uTextures); this->_program.setUniform("uTextures", uTextures);
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment