From 30b9fe9b24f721d254974cae187003c1b5a57248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Tue, 26 Nov 2024 11:57:30 +0100 Subject: [PATCH] Starting a new rendering system --- assets/shaders/FrameBuffer-Instanced.frag | 7 +- assets/shaders/Sprite.frag | 18 +++ assets/shaders/Sprite.vert | 16 +++ assets/textures/Neera.png | Bin 0 -> 8304 bytes .../engine/graphics/front/engine/Engine.cpp | 41 ++---- .../engine/graphics/front/engine/Engine.hpp | 17 +-- source/engine/graphics/front/engine/Layer.cpp | 35 +---- source/engine/graphics/front/engine/Layer.hpp | 33 +++-- .../engine/graphics/front/engine/Priority.hpp | 3 + .../engine/graphics/front/engine/Renderer.cpp | 4 - .../engine/graphics/front/engine/Renderer.hpp | 8 +- .../engine/graphics/front/group/DrawGroup.cpp | 5 - .../engine/graphics/front/group/DrawGroup.hpp | 12 -- .../graphics/front/group/FrameBufferGroup.hpp | 24 ---- .../graphics/front/group/ImageGroup.cpp | 84 ------------ .../graphics/front/group/ImageGroup.hpp | 36 ----- .../graphics/front/group/VertexArrayGroup.cpp | 42 ------ .../graphics/front/group/VertexArrayGroup.hpp | 33 ----- .../FrameBufferModule.cpp} | 10 +- .../front/module/FrameBufferModule.hpp | 25 ++++ .../graphics/front/module/ImageModule.cpp | 44 ++++++ .../graphics/front/module/ImageModule.hpp | 23 ++++ source/engine/graphics/front/object/Image.hpp | 4 +- .../graphics/front/object/Renderable.hpp | 15 ++ .../engine/graphics/front/object/Sprite.cpp | 14 ++ .../engine/graphics/front/object/Sprite.hpp | 27 ++++ .../graphics/utility/isometric_sorter.cpp | 17 +++ .../graphics/utility/isometric_sorter.hpp | 6 + source/engine/graphics/utility/module.hpp | 16 +++ source/engine/graphics/utility/ref_set.hpp | 9 ++ source/main.cpp | 129 ++++++++++++++---- 31 files changed, 399 insertions(+), 358 deletions(-) create mode 100644 assets/shaders/Sprite.frag create mode 100644 assets/shaders/Sprite.vert create mode 100644 assets/textures/Neera.png delete mode 100644 source/engine/graphics/front/group/DrawGroup.cpp delete mode 100644 source/engine/graphics/front/group/DrawGroup.hpp delete mode 100644 source/engine/graphics/front/group/FrameBufferGroup.hpp delete mode 100644 source/engine/graphics/front/group/ImageGroup.cpp delete mode 100644 source/engine/graphics/front/group/ImageGroup.hpp delete mode 100644 source/engine/graphics/front/group/VertexArrayGroup.cpp delete mode 100644 source/engine/graphics/front/group/VertexArrayGroup.hpp rename source/engine/graphics/front/{group/FrameBufferGroup.cpp => module/FrameBufferModule.cpp} (76%) create mode 100644 source/engine/graphics/front/module/FrameBufferModule.hpp create mode 100644 source/engine/graphics/front/module/ImageModule.cpp create mode 100644 source/engine/graphics/front/module/ImageModule.hpp create mode 100644 source/engine/graphics/front/object/Renderable.hpp create mode 100644 source/engine/graphics/front/object/Sprite.cpp create mode 100644 source/engine/graphics/front/object/Sprite.hpp create mode 100644 source/engine/graphics/utility/module.hpp create mode 100644 source/engine/graphics/utility/ref_set.hpp diff --git a/assets/shaders/FrameBuffer-Instanced.frag b/assets/shaders/FrameBuffer-Instanced.frag index 736ee8a..2db481d 100644 --- a/assets/shaders/FrameBuffer-Instanced.frag +++ b/assets/shaders/FrameBuffer-Instanced.frag @@ -6,21 +6,20 @@ in vec2 Texture; uniform sampler2D uSampler[32]; uniform uint uTexturesCount; -uniform vec3 uClearColor; void main() { vec4 color = vec4(0.0, 0.0, 0.0, 1.0); for(uint i = 0; i < uTexturesCount; ++i) { vec4 tcolor = texture(uSampler[i], Texture); - if(tcolor.r != uClearColor.r) { + if(tcolor.r != 0.0) { color.r = tcolor.r; } - if(tcolor.g != uClearColor.g) { + if(tcolor.g != 0.0) { color.g = tcolor.g; } - if(tcolor.b != uClearColor.b) { + if(tcolor.b != 0.0) { color.b = tcolor.b; } } diff --git a/assets/shaders/Sprite.frag b/assets/shaders/Sprite.frag new file mode 100644 index 0000000..31804e3 --- /dev/null +++ b/assets/shaders/Sprite.frag @@ -0,0 +1,18 @@ +#version 450 core +out vec4 FragColor; + +uniform sampler2D uSampler[32]; +uniform int uTextures[128]; +uniform vec4 uFrames[128]; +uniform vec2 uSizes[128]; + +in vec2 Texture; +flat in int Id; + +void main() { + vec2 coord = vec2( + (uFrames[Id].x / uSizes[Id].x) + (uFrames[Id].z / uSizes[Id].x) * Texture.x, + (uFrames[Id].y / uSizes[Id].y) + (uFrames[Id].w / uSizes[Id].y) * Texture.y + ); + FragColor = texture(uSampler[uTextures[Id]], coord); +} \ No newline at end of file diff --git a/assets/shaders/Sprite.vert b/assets/shaders/Sprite.vert new file mode 100644 index 0000000..fc9545f --- /dev/null +++ b/assets/shaders/Sprite.vert @@ -0,0 +1,16 @@ +#version 450 core +layout (location = 0) in vec2 aPos; +layout (location = 1) in vec2 aTex; + +uniform mat4 uModel[128]; +uniform mat4 uView; +uniform mat4 uProj; + +out vec2 Texture; +flat out int Id; + +void main() { + Texture = aTex; + Id = gl_InstanceID; + gl_Position = uProj * uView * uModel[gl_InstanceID] * vec4(aPos.x, aPos.y, 0.0, 1.0); +} \ No newline at end of file diff --git a/assets/textures/Neera.png b/assets/textures/Neera.png new file mode 100644 index 0000000000000000000000000000000000000000..01d777dca4146f5ff1d41da072aa59c744c5cc5b GIT binary patch literal 8304 zcmeAS@N?(olHy`uVBq!ia0y~yV3^6kz;J|vnSp^}_oU*53=E7dna<7up3cq+0Y&*~ znK`Kp3>xRBPPFwn93ax_AM83&tUXPj@I=7eH;a_|RJ&X^1l;0UYc*rf7yel$Dw=wI zP1y$z&Of@UxqI_EzI9CsKbRlAd9dV#lIp$bB2g_|aTR;|Ki{*wQ!cMyvf5|+??(-J z7GYM3-aG%SGWo#8DA*#{u)^TBPny`~7m@MbOZs2w9ozh2KUX&EY(~aTi*r7w74Ip` zyIbOO?)MQTZEdNKmLHe6@(S4(#eV(STYNIPF}*9y%+_B=$a|??*zOrqb>~*JS*&`= z_LSRlzUjH>IbXBpZvFj4pGUN3D$n)IUd2XLm5EI(qNO1L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u?~5jpgL>{r7Ianw8+D%sM0U z{^KqF7v3-Z;AR^9hOc4T)z^U+?j@)t?G>C-Q@J+i%)bch_9nZ$#heb?FKv*OtKwKz z5WBI6?{q)YnJe*kbg%FE`~6SC1-{PET&<-UoJvJ<8>~I|+zi`dd`{%a&s7&Va-sz~ zS0+8`d&52R+i~kZSzOA?!o0-x)-jxV^`raK@gryUSe`vo#dE}O8%XY%#2W8XvnwB7 zSN@Qzc^dU<uVc&269>y|PQFph(ur~NGfHk}d*URPxNPqZW!;mi`)9D2uPIzGMf$>q z)$AYglYTrFPUBk<aP_=QW}%Vu*B>_pJ<fJ64Y5m^*48s8%`Jf0qtwtdZOdoP&1bKu z@M{UwAARF9&r;{?gYNnA&0I&8Z}k-YdbzHSCB1ADtAGSY%M`C!GtcM#`NNUcvhPQ$ z^Pa8Go*O(BH@jiHS$jsF#OA~9v#&i3p5pt=<w8wCP0y_luO~0CbxJc^m2vM>;N7UN zADzQR6J<q~?Pqu7-X>#vk4NhEOuy~Px9rkp6`rVPYIe+%nDf4JxnKDvu7|r)Lsot4 zwW@eCO`<xj=?w$#ukUy6RL=ZpWjf1q%1*YX?;BPyZhRZ9le)F=R^Qg1V?k37U)ghK z#)b~|*$3|{hi$*~kvlV@a{8)@p7&f)zRjG8Q*LI3FW2?h5k9YedP>ccRmZ}1yY>A} zZv8v&J8QT9owd~)W48u4z9@I(PT_o)xK!0bSv$FGsqV#0!*^HirQZuySZ$FjX8P*E gjb*=#>+1hA-%P3DWtHEr1eyc(boFyt=akR{09(1Z6#xJL literal 0 HcmV?d00001 diff --git a/source/engine/graphics/front/engine/Engine.cpp b/source/engine/graphics/front/engine/Engine.cpp index 7551656..1984061 100644 --- a/source/engine/graphics/front/engine/Engine.cpp +++ b/source/engine/graphics/front/engine/Engine.cpp @@ -4,23 +4,21 @@ namespace megu { GraphicEngine::GraphicEngine(Window & window, float w, float h) - : _window(window), _renderer(w, h) { + : _window(window), _view(0, 0, w, h) { glViewport(0, 0, window.width(), window.height()); - this->_renderer.setClearColor(NORMALIZE(135.f), NORMALIZE(170.f), NORMALIZE(255.f)); } GraphicEngine::GraphicEngine(Window & window) - : _window(window), _renderer(window.width(), window.height()) { + : _window(window), _view(0, 0, window.width(), window.height()) { glViewport(0, 0, window.width(), window.height()); - this->_renderer.setClearColor(NORMALIZE(135.f), NORMALIZE(170.f), NORMALIZE(255.f)); } - void GraphicEngine::push(Priority priority, const Renderer & renderer) { + void GraphicEngine::push(Priority priority, Renderer & renderer) { this->_layers[priority] = std::make_unique<Layer>(renderer); } - void GraphicEngine::push(Priority layer_priority, Priority draw_priority, const DrawGroup & group) { - this->_layers[layer_priority]->push(draw_priority, group); + void GraphicEngine::push(Priority layer_priority, Priority object_priority, Renderable & object) { + this->_layers[layer_priority].get()->push(object_priority, object); } void GraphicEngine::remove(Priority priority) { @@ -30,13 +28,6 @@ namespace megu { } } - void GraphicEngine::remove(Priority layer_priority, Priority draw_priority) { - auto it = this->_layers.find(layer_priority); - if(it != this->_layers.end()) { - it->second->remove(draw_priority); - } - } - std::optional<std::reference_wrapper<const Layer>> GraphicEngine::get(Priority priority) const { const auto it = this->_layers.find(priority); if(it != this->_layers.end()) { @@ -45,37 +36,27 @@ namespace megu { return {}; } - std::optional<std::reference_wrapper<const DrawGroup>> GraphicEngine::get(Priority layer_priority, Priority draw_priority) const { - const auto it = this->_layers.find(layer_priority); - if(it != this->_layers.end()) { - return it->second->get(draw_priority); - } - return {}; - } - void GraphicEngine::step() { if(this->_window.isOpen()) { // Draw Layers TextureArray textures; for(auto & [priority, layer] : this->_layers) { - if(!layer.get()->empty()) { - const glm::vec2 & dimension = layer->renderer().dimension(); - glViewport(0, 0, static_cast<GLsizei>(dimension.x), static_cast<GLsizei>(dimension.y)); - textures.push_back(layer->draw(this->_window, textures)); - } + const glm::vec2 & dimension = layer->renderer().dimension(); + glViewport(0, 0, static_cast<GLsizei>(dimension.x), static_cast<GLsizei>(dimension.y)); + textures.push_back(layer->draw(this->_window, textures)); } // Merge Textures FrameBuffer::BindDefaultFrameBuffer(); glViewport(0, 0, static_cast<GLsizei>(this->_window.width()), static_cast<GLsizei>(this->_window.height())); - this->_renderer.render(this->_window, this->_group, textures); + glClear(GL_COLOR_BUFFER_BIT); + std::any any = 1; + this->_module.render(this->_window, this->_view, any, textures); this->_window.swapBuffers(); } } void GraphicEngine::setClearColor(float x, float y, float z) { - this->_renderer.setClearColor(x, y, z); - this->_group.setClearColor(x, y, z); for(auto & [priority, layer] : this->_layers) { layer.get()->renderer().setClearColor(x, y, z); } diff --git a/source/engine/graphics/front/engine/Engine.hpp b/source/engine/graphics/front/engine/Engine.hpp index aa721f0..b9525b4 100644 --- a/source/engine/graphics/front/engine/Engine.hpp +++ b/source/engine/graphics/front/engine/Engine.hpp @@ -2,10 +2,10 @@ #include <map> #include <optional> -#include <engine/graphics/front/group/DrawGroup.hpp> -#include <engine/graphics/front/group/FrameBufferGroup.hpp> -#include "Renderer.hpp" +#include <engine/graphics/front/module/FrameBufferModule.hpp> +#include <engine/graphics/back/cameras/View.hpp> + #include "Layer.hpp" namespace megu { @@ -16,17 +16,14 @@ namespace megu { GraphicEngine(Window &); ~GraphicEngine() = default; - void push(Priority, const Renderer &); - void push(Priority, Priority, const DrawGroup &); + void push(Priority, Renderer &); + void push(Priority, Priority, Renderable &); void remove(Priority); - void remove(Priority, Priority); std::optional<std::reference_wrapper<const Layer>> get(Priority) const; - std::optional<std::reference_wrapper<const DrawGroup>> get(Priority, Priority) const; inline bool empty() const {return this->_layers.empty();} - inline const Renderer & renderer() const {return this->_renderer;} inline const std::map<Priority, std::unique_ptr<Layer>> & layers() const {return this->_layers;} void step(); @@ -34,9 +31,9 @@ namespace megu { private: std::map<Priority, std::unique_ptr<Layer>> _layers; - Renderer _renderer; - FrameBufferGroup _group; + FrameBuffer_Module _module; Window & _window; + View _view; }; } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Layer.cpp b/source/engine/graphics/front/engine/Layer.cpp index 22a78dc..70130ad 100644 --- a/source/engine/graphics/front/engine/Layer.cpp +++ b/source/engine/graphics/front/engine/Layer.cpp @@ -3,37 +3,10 @@ #include <iostream> namespace megu { - Layer::Layer(const Renderer & renderer) - : _renderer(renderer), - _frameBuffer(static_cast<GLuint>(renderer.dimension().x), static_cast<GLuint>(renderer.dimension().y)) {} + Layer::Layer(Renderer & renderer) + : _renderer(renderer), _frameBuffer(static_cast<GLuint>(renderer.dimension().x), static_cast<GLuint>(renderer.dimension().y)) {} - void Layer::push(Priority priority, const DrawGroup & group) { - this->_objects[priority] = &group; + void Layer::push(Priority priority, Renderable & object) { + this->_objects[typeid(object)].insert(object); } - - void Layer::remove(Priority priority) { - auto it = this->_objects.find(priority); - if(it != this->_objects.end()) { - this->_objects.erase(it); - } - } - - std::optional<std::reference_wrapper<const DrawGroup>> Layer::get(Priority priority) const { - const auto it = this->_objects.find(priority); - if(it != this->_objects.end()) { - return *it->second; - } - return {}; - } - - const Texture & Layer::draw(const Window & window, const TextureArray & textures) const { - this->_frameBuffer.bind(); - - for(auto &[priority, group] : this->_objects) { - this->_renderer.render(window, *group, textures); - } - - return this->_frameBuffer.texture(); - } - } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Layer.hpp b/source/engine/graphics/front/engine/Layer.hpp index ee585b7..a81e881 100644 --- a/source/engine/graphics/front/engine/Layer.hpp +++ b/source/engine/graphics/front/engine/Layer.hpp @@ -2,8 +2,12 @@ #include <map> #include <optional> +#include <typeindex> +#include <any> + #include <engine/graphics/back/buffers/FrameBuffer.hpp> -#include <engine/graphics/front/group/DrawGroup.hpp> +#include <engine/graphics/front/object/Renderable.hpp> +#include <engine/graphics/utility/reference_sorter.hpp> #include "Priority.hpp" #include "Renderer.hpp" @@ -12,22 +16,29 @@ namespace megu { class Layer { public: Layer() = delete; - Layer(const Renderer &); + Layer(Renderer &); ~Layer() = default; - void push(Priority, const DrawGroup &); - void remove(Priority); - std::optional<std::reference_wrapper<const DrawGroup>> get(Priority) const; - - inline bool empty() const {return this->_objects.empty();} + inline const Renderer & renderer() const {return this->_renderer;} - inline const std::map<Priority, DrawGroup const *> & groups() const {return this->_objects;} - virtual const Texture & draw(const Window &, const TextureArray &) const; + void push(Priority, Renderable &); + + const Texture & draw(const Window & w, const TextureArray & a) { + this->_frameBuffer.bind(); + for(const auto & [type, objects] : this->_objects) { + if(!objects.empty()) { + //std::cout << typeid((*objects.begin()).get()).name() << std::endl; + this->_renderer.render(w, (*objects.begin()).get(), a); + } + } + + return this->_frameBuffer.texture(); + } private: - const Renderer & _renderer; + Renderer & _renderer; FrameBuffer _frameBuffer; - std::map<Priority, DrawGroup const*> _objects; + std::map<std::type_index, std::set<std::reference_wrapper<Renderable>>> _objects; }; } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Priority.hpp b/source/engine/graphics/front/engine/Priority.hpp index 1b628a4..6651bc7 100644 --- a/source/engine/graphics/front/engine/Priority.hpp +++ b/source/engine/graphics/front/engine/Priority.hpp @@ -11,4 +11,7 @@ namespace megu { return p1 != p2 ? p1 > p2 : &p1 > &p2; } }; + + template <class T> + using priority_map = std::map<Priority, T>; } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Renderer.cpp b/source/engine/graphics/front/engine/Renderer.cpp index be10866..edf40a7 100644 --- a/source/engine/graphics/front/engine/Renderer.cpp +++ b/source/engine/graphics/front/engine/Renderer.cpp @@ -7,10 +7,6 @@ namespace megu { glEnable(GL_BLEND); } - void Renderer::render(const Window & window, const DrawGroup & group, const TextureArray & textures) const { - group.draw(window, this->_view, textures); - } - void Renderer::clear() const { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/source/engine/graphics/front/engine/Renderer.hpp b/source/engine/graphics/front/engine/Renderer.hpp index f7624fa..3115f09 100644 --- a/source/engine/graphics/front/engine/Renderer.hpp +++ b/source/engine/graphics/front/engine/Renderer.hpp @@ -6,7 +6,7 @@ #include <engine/graphics/back/buffers/FrameBuffer.hpp> #include <engine/graphics/back/cameras/View.hpp> -#include <engine/graphics/front/group/DrawGroup.hpp> +#include <engine/graphics/front/module/ImageModule.hpp> namespace megu { class Renderer { @@ -15,7 +15,10 @@ namespace megu { Renderer(float, float); ~Renderer() = default; - virtual void render(const Window &, const DrawGroup &, const TextureArray &) const; + void render(const Window & w, Renderable & r, const TextureArray & a) { + this->clear(); + r.accept(w, this->_view, this->_module, a); + } const glm::vec2 dimension() const {return this->_view.dimension();} @@ -26,5 +29,6 @@ namespace megu { private: View _view; + Image_Module _module; }; } \ No newline at end of file diff --git a/source/engine/graphics/front/group/DrawGroup.cpp b/source/engine/graphics/front/group/DrawGroup.cpp deleted file mode 100644 index 75db3f7..0000000 --- a/source/engine/graphics/front/group/DrawGroup.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "DrawGroup.hpp" - -namespace megu { - -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/DrawGroup.hpp b/source/engine/graphics/front/group/DrawGroup.hpp deleted file mode 100644 index f2d8ca3..0000000 --- a/source/engine/graphics/front/group/DrawGroup.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include <engine/graphics/back/cameras/Camera.hpp> -#include <engine/graphics/front/engine/TextureArray.hpp> -#include <engine/io/Window.hpp> - -namespace megu { - class DrawGroup { - public: - virtual void draw(const Window &, const Camera &, const TextureArray &) const = 0; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/FrameBufferGroup.hpp b/source/engine/graphics/front/group/FrameBufferGroup.hpp deleted file mode 100644 index 40858d4..0000000 --- a/source/engine/graphics/front/group/FrameBufferGroup.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <engine/graphics/back/buffers/VertexArray.hpp> -#include <engine/graphics/back/buffers/VerticeBuffer.hpp> -#include <engine/graphics/back/shaders/Program.hpp> - -#include <engine/graphics/front/group/DrawGroup.hpp> - -namespace megu { - class FrameBufferGroup : public DrawGroup { - public: - FrameBufferGroup(); - ~FrameBufferGroup() = default; - - virtual void draw(const Window &, const Camera &, const TextureArray &) const; - inline void setClearColor(float x, float y, float z) {this->_clear = {x, y, z};} - - private: - VertexArray _vao; - VerticeBuffer _vbo; - Program _program; - glm::vec3 _clear; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/ImageGroup.cpp b/source/engine/graphics/front/group/ImageGroup.cpp deleted file mode 100644 index 32db991..0000000 --- a/source/engine/graphics/front/group/ImageGroup.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "ImageGroup.hpp" - -#include <tuple> - -#include <engine/graphics/utility/array_generator.hpp> - -namespace megu { - ImageGroup::ImageGroup() - : _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) { - Source vert("assets/shaders/Image-Instanced-Fat.vert", Source::Categorie::VERTEX); - this->_program.attach(vert); - - Source frag("assets/shaders/Texture-Fat.frag", Source::Categorie::FRAGMENT); - this->_program.attach(frag); - - this->_program.link(); - - this->_vbo << Quads::Vertices(); - - vert.release(); - frag.release(); - } - - void ImageGroup::add(const Image & image) { - this->_images.insert(image); - } - - void ImageGroup::update() { - std::set<std::reference_wrapper<const Image>, isometric_sorter> source = this->_images; - this->_images.clear(); - for(auto & i : source) { - this->_images.insert(i); - } - } - - void ImageGroup::draw(const Window & window, const Camera & camera, const TextureArray &) const { - this->_vao.bind(); - this->_program.use(); - - this->_program.setUniform("uProj", camera.projection()); - this->_program.setUniform("uView", camera.view()); - - std::vector<std::reference_wrapper<const Texture>> textures; - - std::vector<glm::mat4> uModels; - std::vector<GLint> uTextures; - - static auto uSampler = array_generator<GLint, 32>().array; - this->_program.setUniform("uSampler", uSampler); - - for(auto & image : this->_images) { - - std::vector<std::reference_wrapper<const Texture>>::iterator it = std::find(textures.begin(), textures.end(), image.get().texture()); - if(it != textures.end()) { - uModels.push_back(image.get().transformation().model()); - uTextures.push_back(static_cast<GLint>(it - textures.begin())); - } - else { - if(textures.size() >= 8 || uModels.size() >= 124) { - this->_program.setUniform("uModel", uModels); - this->_program.setUniform("uTextures", uTextures); - - glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size())); - - textures.clear(); - uModels.clear(); - uTextures.clear(); - } - - textures.push_back(image.get().texture()); - image.get().texture().bind(static_cast<GLint>(textures.size()-1)); - uTextures.push_back(static_cast<GLint>(textures.size()-1)); - uModels.push_back(image.get().transformation().model()); - } - } - - if(!textures.empty()) { - this->_program.setUniform("uModel", uModels); - this->_program.setUniform("uTextures", uTextures); - - glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size())); - } - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/ImageGroup.hpp b/source/engine/graphics/front/group/ImageGroup.hpp deleted file mode 100644 index 4293a7f..0000000 --- a/source/engine/graphics/front/group/ImageGroup.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "DrawGroup.hpp" - - -#include <map> -#include <list> -#include <set> - -#include <engine/graphics/utility/isometric_sorter.hpp> - -#include <engine/graphics/back/buffers/VertexArray.hpp> -#include <engine/graphics/back/buffers/VerticeBuffer.hpp> -#include <engine/graphics/back/shaders/Program.hpp> - -#include <engine/graphics/front/object/Image.hpp> - -namespace megu { - class ImageGroup : public DrawGroup { - public: - ImageGroup(); - ~ImageGroup() = default; - - void draw(const Window &, const Camera &, const TextureArray &) const override; - - void add(const Image &); - void update(); - - private: - std::set<std::reference_wrapper<const Image>, isometric_sorter> _images; - - VertexArray _vao; - VerticeBuffer _vbo; - Program _program; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/VertexArrayGroup.cpp b/source/engine/graphics/front/group/VertexArrayGroup.cpp deleted file mode 100644 index 26c5bda..0000000 --- a/source/engine/graphics/front/group/VertexArrayGroup.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "VertexArrayGroup.hpp" - -#include <engine/graphics/utility/array_generator.hpp> - -namespace megu { - VertexArrayGroup::VertexArrayGroup() - : _vbo(this->_vao, Quads::Layout(), Quads::Vertices(), megu::EditMode::STATIC) { - Source vert("assets/shaders/Grid-Instanced.vert", Source::Categorie::VERTEX); - this->_program.attach(vert); - - Source frag("assets/shaders/Grid-Instanced.frag", Source::Categorie::FRAGMENT); - this->_program.attach(frag); - - this->_program.link(); - - vert.release(); - frag.release(); - } - - void VertexArrayGroup::add(const Texture & texture, const VerticesArray & grid) { - this->_objects[texture].push_back(grid); - } - - void VertexArrayGroup::draw(const Window &, const Camera & camera, const TextureArray &) const { - this->_vao.bind(); - this->_program.use(); - - this->_program.setUniform("uProj", camera.projection()); - this->_program.setUniform("uView", camera.view()); - - for(const auto & [texture, grids] : this->_objects) { - texture.get().bind(0); - for(const auto & grid : grids) { - this->_program.setUniform("uModel", grid.get().transformation().model()); - this->_program.setUniform("uSampler", 0); - this->_program.setUniform("uData", static_cast<const void *>(grid.get().vertices().data()), grid.get().size()); - - glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(grid.get().size())); - } - } - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/VertexArrayGroup.hpp b/source/engine/graphics/front/group/VertexArrayGroup.hpp deleted file mode 100644 index 65efa65..0000000 --- a/source/engine/graphics/front/group/VertexArrayGroup.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "DrawGroup.hpp" - -#include <map> -#include <optional> - -#include <engine/graphics/back/textures/Texture.hpp> -#include <engine/graphics/back/buffers/VertexArray.hpp> -#include <engine/graphics/back/buffers/VerticeBuffer.hpp> -#include <engine/graphics/back/shaders/Program.hpp> - -#include <engine/graphics/front/object/VerticesArray.hpp> - -#include <engine/graphics/utility/texture_comparator.hpp> - -namespace megu { - class VertexArrayGroup : public DrawGroup { - public: - VertexArrayGroup(); - ~VertexArrayGroup() = default; - - void add(const Texture &, const VerticesArray &); - void draw(const Window &, const Camera &, const TextureArray &) const override; - - private: - std::map<std::reference_wrapper<const Texture>, std::vector<std::reference_wrapper<const VerticesArray>>, texture_comparator> _objects; - - VertexArray _vao; - VerticeBuffer _vbo; - Program _program; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/group/FrameBufferGroup.cpp b/source/engine/graphics/front/module/FrameBufferModule.cpp similarity index 76% rename from source/engine/graphics/front/group/FrameBufferGroup.cpp rename to source/engine/graphics/front/module/FrameBufferModule.cpp index c9052ed..8da4da8 100644 --- a/source/engine/graphics/front/group/FrameBufferGroup.cpp +++ b/source/engine/graphics/front/module/FrameBufferModule.cpp @@ -1,12 +1,11 @@ -#include "FrameBufferGroup.hpp" +#include "FrameBufferModule.hpp" -#include <glm/gtc/matrix_transform.hpp> #include <engine/graphics/front/geometry/Plane.hpp> #include <engine/graphics/utility/array_generator.hpp> namespace megu { - FrameBufferGroup::FrameBufferGroup() - : _vbo(this->_vao, Plane::Layout(), Plane::Vertices(), megu::EditMode::STATIC), _clear(0.f) { + FrameBuffer_Module::FrameBuffer_Module() + : _vbo(this->_vao, Plane::Layout(), Plane::Vertices(), megu::EditMode::STATIC) { megu::Source vert("assets/shaders/FrameBuffer-Instanced.vert", Source::Categorie::VERTEX); this->_program.attach(vert); @@ -19,7 +18,7 @@ namespace megu { frag.release(); } - void FrameBufferGroup::draw(const Window & window, const Camera & camera, const TextureArray & textures) const { + void FrameBuffer_Module::render(const Window & window, const Camera & camera, std::any & any, const TextureArray & textures) { this->_program.use(); this->_vao.bind(); @@ -31,7 +30,6 @@ namespace megu { this->_program.setUniform("uSampler", uSampler); this->_program.setUniform("uTexturesCount", static_cast<GLuint>(textures.size())); - this->_program.setUniform("uClearColor", this->_clear); glDrawArrays(Plane::Primitive(), 0, static_cast<GLsizei>(Plane::Vertices().size())); } } \ No newline at end of file diff --git a/source/engine/graphics/front/module/FrameBufferModule.hpp b/source/engine/graphics/front/module/FrameBufferModule.hpp new file mode 100644 index 0000000..cc90570 --- /dev/null +++ b/source/engine/graphics/front/module/FrameBufferModule.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include <any> + +#include <engine/graphics/back/buffers/VertexArray.hpp> +#include <engine/graphics/back/buffers/VerticeBuffer.hpp> +#include <engine/graphics/back/shaders/Program.hpp> + +#include <engine/graphics/front/object/Image.hpp> +#include <engine/graphics/utility/module.hpp> + +namespace megu { + class FrameBuffer_Module : public Module<std::any> { + public: + FrameBuffer_Module(); + ~FrameBuffer_Module() = default; + + void render(const Window &, const Camera &, std::any &, const TextureArray &) override; + + private: + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/module/ImageModule.cpp b/source/engine/graphics/front/module/ImageModule.cpp new file mode 100644 index 0000000..c945ac2 --- /dev/null +++ b/source/engine/graphics/front/module/ImageModule.cpp @@ -0,0 +1,44 @@ +#include "ImageModule.hpp" + +#include <engine/graphics/utility/array_generator.hpp> + +namespace megu { + Image_Module::Image_Module() + : _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) { + Source vert("assets/shaders/Image-Instanced-Fat.vert", Source::Categorie::VERTEX); + this->_program.attach(vert); + + Source frag("assets/shaders/Texture-Fat.frag", Source::Categorie::FRAGMENT); + this->_program.attach(frag); + + this->_program.link(); + + this->_vbo << Quads::Vertices(); + + vert.release(); + frag.release(); + } + + void Image_Module::render(const Window &, const Camera & camera, Image & image, const TextureArray &) { + this->_vao.bind(); + this->_program.use(); + image.texture().bind(); + + this->_program.setUniform("uProj", camera.projection()); + this->_program.setUniform("uView", camera.view()); + + static auto uSampler = array_generator<GLint, 32>().array; + this->_program.setUniform("uSampler", uSampler); + + std::vector<glm::mat4> uModels; + std::vector<GLint> uTextures; + + uModels.push_back(image.transformation().model()); + uTextures.push_back(0); + + this->_program.setUniform("uModel", uModels); + this->_program.setUniform("uTextures", uTextures); + + glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), 1); + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/module/ImageModule.hpp b/source/engine/graphics/front/module/ImageModule.hpp new file mode 100644 index 0000000..ee339bd --- /dev/null +++ b/source/engine/graphics/front/module/ImageModule.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <engine/graphics/back/buffers/VertexArray.hpp> +#include <engine/graphics/back/buffers/VerticeBuffer.hpp> +#include <engine/graphics/back/shaders/Program.hpp> + +#include <engine/graphics/front/object/Image.hpp> +#include <engine/graphics/utility/module.hpp> + +namespace megu { + class Image_Module : public Module<Image> { + public: + Image_Module(); + ~Image_Module() = default; + + void render(const Window &, const Camera &, Image &, const TextureArray &) override; + + private: + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/Image.hpp b/source/engine/graphics/front/object/Image.hpp index a4f5e55..b92f031 100644 --- a/source/engine/graphics/front/object/Image.hpp +++ b/source/engine/graphics/front/object/Image.hpp @@ -1,5 +1,7 @@ #pragma once +#include "Renderable.hpp" + #include <filesystem> #include <glm/vec2.hpp> @@ -10,7 +12,7 @@ #include <engine/graphics/utility/type.hpp> namespace megu { - class Image { + class Image : public Renderable { public: Image() = default; Image(const std::filesystem::path &); diff --git a/source/engine/graphics/front/object/Renderable.hpp b/source/engine/graphics/front/object/Renderable.hpp new file mode 100644 index 0000000..441a078 --- /dev/null +++ b/source/engine/graphics/front/object/Renderable.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include <engine/io/Window.hpp> +#include <engine/graphics/utility/module.hpp> +#include <engine/graphics/front/engine/TextureArray.hpp> + +namespace megu { + class Renderable { + public: + template <class T> + void accept(const Window & window, const Camera & camera, Module<T> & modul, const TextureArray & array) { + modul.render(window, camera, *static_cast<T *>(this), array); + } + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/Sprite.cpp b/source/engine/graphics/front/object/Sprite.cpp new file mode 100644 index 0000000..82283f5 --- /dev/null +++ b/source/engine/graphics/front/object/Sprite.cpp @@ -0,0 +1,14 @@ +#include "Sprite.hpp" + +namespace megu { + Sprite::Sprite(const Texture & texture) + : _frame(0, 0, texture.width(), texture.height()), _texture(texture) { + this->_transformation.scale(static_cast<float>(texture.width()), static_cast<float>(texture.height())); + } + + Sprite::Sprite(const Texture & texture, const glm::vec4 & frame) + : _frame(frame), _texture(texture) { + this->_transformation.move(frame.x, frame.y); + this->_transformation.scale(frame.z, frame.w); + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/Sprite.hpp b/source/engine/graphics/front/object/Sprite.hpp new file mode 100644 index 0000000..3aab783 --- /dev/null +++ b/source/engine/graphics/front/object/Sprite.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include <engine/graphics/back/geometry/Transformable.hpp> +#include <engine/graphics/back/textures/Texture.hpp> +#include <engine/graphics/front/geometry/Quads.hpp> + + +namespace megu { + class Sprite { + public: + Sprite(const Texture &); + Sprite(const Texture &, const glm::vec4 &); + + inline void setFrame(const glm::vec4 & frame) {this->_frame = frame;} + + inline const glm::vec4 & frame() const {return this->_frame;} + inline const Texture & texture() const {return this->_texture;} + inline const Quads & geometry() const {return this->_geometry;} + inline const Transformable & transformation() const {return this->_transformation;} + + private: + glm::vec4 _frame; + Texture _texture; + Quads _geometry; + Transformable _transformation; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/utility/isometric_sorter.cpp b/source/engine/graphics/utility/isometric_sorter.cpp index 94ae8d0..b566738 100644 --- a/source/engine/graphics/utility/isometric_sorter.cpp +++ b/source/engine/graphics/utility/isometric_sorter.cpp @@ -1,6 +1,7 @@ #include "isometric_sorter.hpp" #include <engine/graphics/front/object/Image.hpp> +#include <engine/graphics/front/object/Sprite.hpp> namespace megu { bool isometric_sorter::operator()(const Image & img1, const Image & img2) const { @@ -18,4 +19,20 @@ namespace megu { return &img1 > &img2; } + + bool isometric_sorter_sprite::operator()(const Sprite & img1, const Sprite & img2) const { + if(img1.transformation().z() != img2.transformation().z()) { + return img1.transformation().z() > img2.transformation().z(); + } + + if(img1.transformation().y() != img2.transformation().y()) { + return img1.transformation().y() > img2.transformation().y(); + } + + if(img1.transformation().x() != img2.transformation().x()) { + return img1.transformation().x() > img2.transformation().x(); + } + + return &img1 > &img2; + } } \ No newline at end of file diff --git a/source/engine/graphics/utility/isometric_sorter.hpp b/source/engine/graphics/utility/isometric_sorter.hpp index 6c84006..1e3537d 100644 --- a/source/engine/graphics/utility/isometric_sorter.hpp +++ b/source/engine/graphics/utility/isometric_sorter.hpp @@ -2,9 +2,15 @@ namespace megu { class Image; + class Sprite; class isometric_sorter { public: bool operator()(const Image & img1, const Image & img2) const; }; + + class isometric_sorter_sprite { + public: + bool operator()(const Sprite & img1, const Sprite & img2) const; + }; } \ No newline at end of file diff --git a/source/engine/graphics/utility/module.hpp b/source/engine/graphics/utility/module.hpp new file mode 100644 index 0000000..7e90914 --- /dev/null +++ b/source/engine/graphics/utility/module.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include <engine/graphics/back/cameras/Camera.hpp> +#include <engine/graphics/front/engine/TextureArray.hpp> +#include <engine/io/Window.hpp> + +namespace megu { + template <class T> + class Module { + public: + virtual void render(const Window &, const Camera &, T &, const TextureArray &) = 0; + }; + + template <class ... Ts> + class Multi_Module : public Module<Ts> ... {}; +} \ No newline at end of file diff --git a/source/engine/graphics/utility/ref_set.hpp b/source/engine/graphics/utility/ref_set.hpp new file mode 100644 index 0000000..b394253 --- /dev/null +++ b/source/engine/graphics/utility/ref_set.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include <set> +#include "reference_sorter.hpp" + +namespace megu { + template <class T> + using ref_set = std::set<std::reference_wrapper<T>, reference_sorter<T>>; +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 67c44ff..ab619eb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,4 +1,5 @@ #include <iostream> +#include <thread> #include <GL/glew.h> #include <GLFW/glfw3.h> @@ -13,10 +14,8 @@ #include <engine/io/Window.hpp> #include <engine/graphics/back/cameras/View.hpp> #include <engine/graphics/front/object/Image.hpp> -#include <engine/graphics/front/group/ImageGroup.hpp> #include <engine/graphics/front/engine/Renderer.hpp> #include <engine/graphics/front/engine/Engine.hpp> -#include <engine/graphics/front/group/VertexArrayGroup.hpp> #include <engine/graphics/errors.hpp> const float i_x = 1.f; @@ -31,12 +30,14 @@ glm::vec2 to_screen_coordinate(const glm::vec2 & tile, float w, float h, float l }; } +/* megu::Vertex to_screen_coordinate(int x, int y, unsigned int u, unsigned int v, const megu::Texture & texture) { return {{x, y}, {static_cast<float>(u) / static_cast<float>(texture.width()), static_cast<float>(v) / static_cast<float>(texture.height())}}; } +*/ //* Isometric : -/* + int main(int argc, const char * argv[]) { try { //? Window @@ -45,10 +46,6 @@ int main(int argc, const char * argv[]) { megu::error::opengl_error::check(); std::cout << "Window Inited" << std::endl; - - //? Group - megu::ImageGroup group; - megu::ImageGroup group_2; std::cout << "Group Inited" << std::endl; @@ -117,10 +114,10 @@ int main(int argc, const char * argv[]) { ++x; } - for(auto & i : images) { + /*for(auto & i : images) { group.add(*i); i.get()->setSize({32.f, 32.f}); - } + }*/ std::cout << "Images 1 Inited" << std::endl; @@ -159,26 +156,20 @@ int main(int argc, const char * argv[]) { ++x_2; } - for(auto & i : images_2) { + /*for(auto & i : images_2) { group_2.add(*i); i.get()->setSize({32.f, 32.f}); - } + }*/ std::cout << "Images 2 Inited" << std::endl; - //? ImGui - //ImGui::CreateContext(); - //ImGui_ImplOpenGL3_Init(); - //ImGui_ImplGlfw_InitForOpenGL(window.ptr(), true); //? Engines megu::GraphicEngine engine(window); megu::Renderer basic_renderer(360, 360); engine.push(0, basic_renderer); - - engine.push(0, 0, group); - //engine.push(0, 0, group_2); + engine.push(0, 0, *images.front()); //? Render Loop std::cout << "Render Loop Begin !" << std::endl; @@ -209,8 +200,10 @@ int main(int argc, const char * argv[]) { return EXIT_SUCCESS; } -*/ + +//* Tilemap +/* int main(int argc, const char * argv[]) { try { //? Window @@ -232,10 +225,10 @@ int main(int argc, const char * argv[]) { megu::VerticesArray grid_1(megu::Quads::Primitive(), 4); - /*grid_1[0] = {{0.f, 0.f}, {0.0f, 0.0f}}; - grid_1[1] = {{16.f, 0.f}, {0.5f, 0.0f}}; - grid_1[2] = {{16.f, 16.f}, {0.5f, 0.5f}}; - grid_1[3] = {{0.f, 16.f}, {0.0f, 0.5f}};*/ + //grid_1[0] = {{0.f, 0.f}, {0.0f, 0.0f}}; + //grid_1[1] = {{16.f, 0.f}, {0.5f, 0.0f}}; + //grid_1[2] = {{16.f, 16.f}, {0.5f, 0.5f}}; + //grid_1[3] = {{0.f, 16.f}, {0.0f, 0.5f}}; @@ -291,6 +284,96 @@ int main(int argc, const char * argv[]) { std::cerr << error.what() << std::endl; } + return EXIT_SUCCESS; +}*/ + + +//* Sprite +/* +int main(int argc, const char * argv[]) { + try { + //? Window + megu::Window window; + window.open("Sprite Window", 360, 360); + megu::error::opengl_error::check(); + + std::cout << "Window Inited" << std::endl; + + //? Group + megu::SpriteGroup group; + megu::ImageGroup group_2; + + std::cout << "Group Inited" << std::endl; + + //? Grids + + megu::Texture texture_1; + texture_1.store(megu::TextureBuffer("assets/textures/Neera.png")); + + std::vector<glm::vec4> frames; + frames.push_back({0, 0, 51, 98}); + frames.push_back({51, 0, 51, 98}); + frames.push_back({102, 0, 51, 98}); + + frames.push_back({0, 98, 51, 98}); + frames.push_back({51, 98, 51, 98}); + frames.push_back({102, 98, 51, 98}); + + megu::Sprite neera(texture_1, frames[0]); + megu::Image image(texture_1); + //neera.scale(1.f, 1.f); + + + group.add(neera); + group_2.add(image); + + std::cout << "Sprite created" << std::endl; + + //? Engines + megu::GraphicEngine engine(window); + megu::Renderer basic_renderer(128, 128); + + engine.push(0, basic_renderer); + engine.push(0, 0, group); + + //? Render Loop + std::cout << "Render Loop Begin !" << std::endl; + + double previousTime = megu::Window::Time(); + int frameCount = 0; + + std::thread t([&frames, &window, &neera](){ + size_t i = 0; + while(window.isOpen()) { + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + neera.setFrame(frames[i%frames.size()]); + ++i; + } + }); + + while(window.isOpen()) { + double currentTime = megu::Window::Time(); + frameCount++; + + if(currentTime - previousTime >= 1.0) { + window.setTitle(std::to_string(frameCount)); + + frameCount = 0; + previousTime = currentTime; + } + + window.pollEvents(); + engine.step(); + } + + t.join(); + std::cout << "Render Loop End !" << std::endl; + } + catch(std::exception & error) { + std::cerr << error.what() << std::endl; + } + return EXIT_SUCCESS; } +*/ -- GitLab