diff --git a/assets/shaders/Basic.frag b/assets/shaders/Basic.frag new file mode 100644 index 0000000000000000000000000000000000000000..4048d9720ee7274e633c5a3e888db3bea75d822f --- /dev/null +++ b/assets/shaders/Basic.frag @@ -0,0 +1,8 @@ +#version 330 core +out vec4 FragColor; + +in vec3 Color; + +void main() { + FragColor = vec4(Color, 1.0); +} \ No newline at end of file diff --git a/assets/shaders/Basic.vert b/assets/shaders/Basic.vert new file mode 100644 index 0000000000000000000000000000000000000000..fa168554ca6d40134b6e7e868647b9e6f56e2f72 --- /dev/null +++ b/assets/shaders/Basic.vert @@ -0,0 +1,10 @@ +#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 diff --git a/assets/shaders/Texture.frag b/assets/shaders/Texture.frag new file mode 100644 index 0000000000000000000000000000000000000000..12cf126653c7fd8da978dd9885b697d9ebfed335 --- /dev/null +++ b/assets/shaders/Texture.frag @@ -0,0 +1,10 @@ +#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 diff --git a/assets/shaders/Texture.vert b/assets/shaders/Texture.vert new file mode 100644 index 0000000000000000000000000000000000000000..d1fd061936383f140ce073ae5c8fed33a14d6e5d --- /dev/null +++ b/assets/shaders/Texture.vert @@ -0,0 +1,10 @@ +#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 diff --git a/source/engine/graphics/back/shaders/Program.cpp b/source/engine/graphics/back/shaders/Program.cpp index 5a915e1aa7e6dc48613a2ce2f86105eb3d834ca1..f4f9860b4f24ffc369e34d283e7e098a7f3ae892 100644 --- a/source/engine/graphics/back/shaders/Program.cpp +++ b/source/engine/graphics/back/shaders/Program.cpp @@ -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 { diff --git a/source/engine/graphics/back/shaders/Program.hpp b/source/engine/graphics/back/shaders/Program.hpp index ab545d3992a90eed6722b438d7cbd3f6955ea85e..5e4b08d0d2d2833296a0487c5cdbecab6d5931ba 100644 --- a/source/engine/graphics/back/shaders/Program.hpp +++ b/source/engine/graphics/back/shaders/Program.hpp @@ -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 { diff --git a/source/main.cpp b/source/main.cpp index 9f510b97bce2164b08a3946fc5725c9f5a55fc0b..c879050c0cf9fb2742be9efd1082d247def572f3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -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);