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

Resolve problem on shader with uniforms arrays

parent f70b339d
Branches
No related tags found
No related merge requests found
#version 330 core
out vec4 FragColor;
in vec3 Color;
void main() {
FragColor = vec4(Color, 1.0);
}
\ No newline at end of file
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aCol;
out vec3 Color;
void main() {
Color = aCol;
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
\ No newline at end of file
#version 330 core
out vec4 FragColor;
in vec2 Texture;
uniform sampler2D uSamp[2];
void main() {
FragColor = texture(uSamp[0], Texture);
}
\ No newline at end of file
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTex;
out vec2 Texture;
void main() {
Texture = aTex;
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "../../errors/Shader_Error.hpp" #include "../../errors/Shader_Error.hpp"
#include <iostream>
namespace megu { namespace megu {
Program::Program() Program::Program()
: _id(0), _usable(false), _attached(NONE) { : _id(0), _usable(false), _attached(NONE) {
...@@ -74,9 +76,11 @@ namespace megu { ...@@ -74,9 +76,11 @@ namespace megu {
for(size_t i = 0; i < count; ++i) { for(size_t i = 0; i < count; ++i) {
GLint length, size; GLint length, size;
GLenum type; GLenum type;
GLchar* name; GLchar name[64];
glGetActiveUniform(this->_id, static_cast<GLuint>(i), 32, &length, &size, &type, name); glGetActiveUniform(this->_id, static_cast<GLuint>(i), 64, &length, &size, &type, name);
this->_locations[name] = glGetUniformLocation(this->_id, name);
std::string var_name(name);
this->_locations[var_name.substr(0, var_name.find("["))] = glGetUniformLocation(this->_id, name);
} }
} }
else { else {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <vector> #include <vector>
#include <map> #include <unordered_map>
#include "Source.hpp" #include "Source.hpp"
...@@ -13,7 +13,7 @@ namespace megu { ...@@ -13,7 +13,7 @@ namespace megu {
GLuint _id; GLuint _id;
bool _usable; bool _usable;
uint8_t _attached; uint8_t _attached;
std::map<std::string, GLuint> _locations; mutable std::unordered_map<std::string, GLuint> _locations;
protected: protected:
enum Bit_Categorie { enum Bit_Categorie {
......
...@@ -80,6 +80,8 @@ int main(int argc, const char * argv) { ...@@ -80,6 +80,8 @@ int main(int argc, const char * argv) {
vbo << vertices; vbo << vertices;
std::cout << "VBO" << std::endl;
megu::VertexArray vao_2; megu::VertexArray vao_2;
megu::VerticeBuffer vbo_2(vao_2, {megu::layout::POSITION, megu::layout::COLOR}, 128, megu::EditMode::STATIC); megu::VerticeBuffer vbo_2(vao_2, {megu::layout::POSITION, megu::layout::COLOR}, 128, megu::EditMode::STATIC);
...@@ -106,6 +108,8 @@ int main(int argc, const char * argv) { ...@@ -106,6 +108,8 @@ int main(int argc, const char * argv) {
vbo_F << vertices_F; vbo_F << vertices_F;
std::cout << "VBO - FBO" << std::endl;
//? FBO //? FBO
megu::FrameBuffer fbo(WINDOW_WIDTH, WINDOW_HEIGHT); megu::FrameBuffer fbo(WINDOW_WIDTH, WINDOW_HEIGHT);
...@@ -124,6 +128,8 @@ int main(int argc, const char * argv) { ...@@ -124,6 +128,8 @@ int main(int argc, const char * argv) {
program.link(); program.link();
} }
std::cout << "Shader - FBO" << std::endl;
megu::Program program_F; megu::Program program_F;
...@@ -137,6 +143,8 @@ int main(int argc, const char * argv) { ...@@ -137,6 +143,8 @@ int main(int argc, const char * argv) {
program_F.link(); program_F.link();
} }
std::cout << "Shader" << std::endl;
//? Render Loop //? Render Loop
glClearColor(0.0f, 0.0f, 0.0f, 0.f); glClearColor(0.0f, 0.0f, 0.0f, 0.f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment