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
No related branches found
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 @@
#include "../../errors/Shader_Error.hpp"
#include <iostream>
namespace megu {
Program::Program()
: _id(0), _usable(false), _attached(NONE) {
......@@ -74,9 +76,11 @@ namespace megu {
for(size_t i = 0; i < count; ++i) {
GLint length, size;
GLenum type;
GLchar* name;
glGetActiveUniform(this->_id, static_cast<GLuint>(i), 32, &length, &size, &type, name);
this->_locations[name] = glGetUniformLocation(this->_id, name);
GLchar name[64];
glGetActiveUniform(this->_id, static_cast<GLuint>(i), 64, &length, &size, &type, name);
std::string var_name(name);
this->_locations[var_name.substr(0, var_name.find("["))] = glGetUniformLocation(this->_id, name);
}
}
else {
......
......@@ -3,7 +3,7 @@
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <vector>
#include <map>
#include <unordered_map>
#include "Source.hpp"
......@@ -13,7 +13,7 @@ namespace megu {
GLuint _id;
bool _usable;
uint8_t _attached;
std::map<std::string, GLuint> _locations;
mutable std::unordered_map<std::string, GLuint> _locations;
protected:
enum Bit_Categorie {
......
......@@ -80,6 +80,8 @@ int main(int argc, const char * argv) {
vbo << vertices;
std::cout << "VBO" << std::endl;
megu::VertexArray vao_2;
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) {
vbo_F << vertices_F;
std::cout << "VBO - FBO" << std::endl;
//? FBO
megu::FrameBuffer fbo(WINDOW_WIDTH, WINDOW_HEIGHT);
......@@ -124,6 +128,8 @@ int main(int argc, const char * argv) {
program.link();
}
std::cout << "Shader - FBO" << std::endl;
megu::Program program_F;
......@@ -137,6 +143,8 @@ int main(int argc, const char * argv) {
program_F.link();
}
std::cout << "Shader" << std::endl;
//? Render Loop
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