Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • LayeredRendering
  • NewGraphicSystem
  • main
3 results

Target

Select target project
No results found
Select Git revision
  • LayeredRendering
  • NewGraphicSystem
  • main
3 results
Show changes
53 files
+ 740
229
Compare changes
  • Side-by-side
  • Inline

Files

+4 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
if(WIN32)
	option(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
elseif(UNIX)
	#option(CMAKE_TOOLCHAIN_FILE "/amuhome/b20017738/Bureau/vcpkg/scripts/buildsystems/vcpkg.cmake")	
	option(CMAKE_TOOLCHAIN_FILE "/amuhome/b20017738/Bureau/vcpkg/scripts/buildsystems/vcpkg.cmake")	
endif()

#==============================================================
@@ -59,9 +59,9 @@ set_property(TARGET ${CURRENT_TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY $<1:${CM

target_include_directories(${CURRENT_TARGET} PRIVATE ${INCLUDE})

#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glew_x64-linux")
#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glm_x64-linux")
#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/imgui_x64-linux")
list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glew_x64-linux")
list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glm_x64-linux")
list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/imgui_x64-linux")

find_package(glfw3  REQUIRED)
find_package(GLEW   REQUIRED)
+4 −1
Original line number Diff line number Diff line
@@ -20,3 +20,6 @@ Release Mode :
```shell
cmake --build ./build --config Release
```

## Source 
Type Erasure Inspiration : [Type Erasure - CppCon 2021 - Klaus Iglberger](https://www.youtube.com/watch?v=4eeESJQk-mw&ab_channel=CppCon)
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
#version 450 core
out vec4 FragColor;

in vec2 Texture;

uniform sampler2D uSampler;

void main() {
    FragColor = texture(uSampler, Texture);
}
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
#version 450 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTex;

uniform mat4 uProj;
uniform mat4 uView;
uniform mat4 uModel;

uniform vec4 uData[254];

out vec2 Texture;
out vec2 Color;

void main() {
    vec4 usedData = uData[gl_VertexID];
    Texture = usedData.zw;

    gl_Position = uProj * uView * uModel * vec4(aPos.x + usedData.x, aPos.y + usedData.y, 0.0, 1.0);
}
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
#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
+16 −0
Original line number Diff line number Diff line
#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
+25 −0
Original line number Diff line number Diff line
#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

old2/ImageModule.cpp

0 → 100644
+26 −0
Original line number Diff line number Diff line
#include "ImageModule.hpp"

#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/utility/array_generator.hpp>

namespace megu {
    ImageModule::ImageModule()
    : _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 ImageModule::render(Image & image) {
        std::cout << "Image !" << std::endl;
    }
}
 No newline at end of file
Original line number Diff line number Diff line
#pragma once

#include "QuadGraphicModule.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/group/DrawGroup.hpp>

namespace megu {
    class FrameBufferGroup : public DrawGroup {
    class ImageModule : public virtual QuadGraphicModule {
        public:
            FrameBufferGroup();
           ~FrameBufferGroup() = default;
            ImageModule();
           ~ImageModule() = default;

            virtual void draw(const Window &, const Camera &, const TextureArray &) const;
            virtual void render(Image &) override;

        private:
            VertexArray _vao;

old2/SpriteModule.cpp

0 → 100644
+16 −0
Original line number Diff line number Diff line
#include "SpriteModule.hpp"

#include <engine/graphics/utility/array_generator.hpp>
#include <engine/graphics/front/object/Sprite.hpp>

#include <iostream>

namespace megu {
    SpriteModule::SpriteModule() {
       
    }

    void SpriteModule::render(Sprite & sprite) {
        std::cout << "Sprite !" << std::endl;
    }
}
 No newline at end of file

old2/SpriteModule.hpp

0 → 100644
+17 −0
Original line number Diff line number Diff line
#pragma once

#include "QuadGraphicModule.hpp"

#include <engine/graphics/back/buffers/VertexArray.hpp>
#include <engine/graphics/back/buffers/VerticeBuffer.hpp>
#include <engine/graphics/back/shaders/Program.hpp>

namespace megu {
    class SpriteModule : public virtual QuadGraphicModule {
        public:
            SpriteModule();
           ~SpriteModule() = default;

           virtual void render(Sprite &) override;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ namespace megu {

            static Layout_t Layout() {return Counter<megu::layout::Value>::Count<L...>();}
            static const Vertices_t & Vertices()  {return T::Vertices();}
            static const size_t & Count() {return T::Count();}
    };

    template <class T, Primitive_t P, layout::Value ... L>
Original line number Diff line number Diff line
@@ -181,4 +181,15 @@ namespace megu {
    void Program::setUniform(const std::string & name, const std::set<std::reference_wrapper<const glm::mat4>> & value) const {
        glUniformMatrix4fv(this->_locations.at(name), static_cast<GLsizei>(value.size()), GL_FALSE, glm::value_ptr(value.begin()->get()));
    }

    void Program::setUniform(const std::string & name, const void * data, size_t size, GLenum type) const {
        switch (type) {
            case GL_FLOAT:
                glUniform4fv(this->_locations.at(name), static_cast<GLsizei>(size), static_cast<const float*>(data));
                break;
            
            default:
                break;
        }
    }
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -71,5 +71,7 @@ namespace megu {

            void setUniform(const std::string &, const std::vector<std::reference_wrapper<const glm::mat4>> &) const;
            void setUniform(const std::string &, const std::set<std::reference_wrapper<const glm::mat4>> &) const;

            void setUniform(const std::string &, const void *, size_t, GLenum = GL_FLOAT) const;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -4,24 +4,22 @@

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, GraphicObject & object) {
    //    this->_layers[layer_priority].get()->push(object_priority, object);
    //}

    void GraphicEngine::remove(Priority priority) {
        auto it = this->_layers.find(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,28 +36,29 @@ 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));
            }
            }

            // Merge Textures
            FrameBuffer::BindDefaultFrameBuffer();
            this->_renderer.render(this->_window, this->_group, textures);
            glViewport(0, 0, static_cast<GLsizei>(this->_window.width()), static_cast<GLsizei>(this->_window.height()));
            glClear(GL_COLOR_BUFFER_BIT);
            std::any any = 1;
            this->_module.render(textures);
            this->_window.swapBuffers();
        }
    }

    void GraphicEngine::setClearColor(float x, float y, float z) {
        for(auto & [priority, layer] : this->_layers) {
            layer.get()->renderer().setClearColor(x, y, z);
        }
    } 
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -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,26 +16,28 @@ namespace megu {
            GraphicEngine(Window &);
           ~GraphicEngine() = default;

            void push(Priority, const Renderer &);
            void push(Priority, Priority, const DrawGroup &);
            void push(Priority, Renderer &);

            template <class T>
            void push(Priority layer_priority, Priority object_priority, T & object) {
                this->_layers[layer_priority].get()->push<T>(object_priority, object);
            }

            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();
            void setClearColor(float, float, float);

        private:
            std::map<Priority, std::unique_ptr<Layer>> _layers;
            Renderer _renderer;
            FrameBufferGroup _group;
            FrameBufferModule _module;
            Window & _window;
            View _view;

    };
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -3,37 +3,6 @@
#include <iostream>

namespace megu {
    Layer::Layer(const 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::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();
    }

    Layer::Layer(Renderer & renderer) 
    : _renderer(renderer), _frameBuffer(static_cast<GLuint>(renderer.dimension().x), static_cast<GLuint>(renderer.dimension().y)) {}
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -2,8 +2,15 @@

#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 <engine/graphics/front/object/Renderable.hpp>
#include <engine/graphics/front/module/QuadGraphicModule.hpp>

#include "Priority.hpp" 
#include "Renderer.hpp"
@@ -12,22 +19,30 @@ 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;
            template <class T>
            void push(Priority priority, T & object) {
                this->_objects.insert({priority, Renderable(object, this->_module)});
            }

            const Texture & draw(const Window & w, const TextureArray & a) {
                this->_frameBuffer.bind();
                for(auto & [type, object] : this->_objects) {
                    this->_renderer.render(w, object, a);
                }
               
                return this->_frameBuffer.texture();
            }

        private:
            const Renderer & _renderer;
            Renderer & _renderer;
            FrameBuffer _frameBuffer;
            std::map<Priority, DrawGroup const*> _objects;
            QuadGraphicModule _module;
            std::map<Priority, Renderable> _objects;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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);
    }
Original line number Diff line number Diff line
@@ -6,7 +6,11 @@
#include <engine/graphics/back/buffers/FrameBuffer.hpp>
#include <engine/graphics/back/cameras/View.hpp>

#include <engine/graphics/front/group/DrawGroup.hpp> 
#include <engine/io/Window.hpp>
#include <engine/graphics/front/object/Renderable.hpp>
#include <engine/graphics/front/engine/TextureArray.hpp>

#include <engine/graphics/front/object/Renderable.hpp>

namespace megu {
    class Renderer {
@@ -15,7 +19,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();
                render_ext(r, w, this->_view, a);
            }

            const glm::vec2 dimension() const {return this->_view.dimension();}

Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ namespace megu {
    class Plane : public Static_Geometry<Plane, QUADS, layout::FLAT, layout::TEXTURE> {
        public:
            inline static const Vertices_t & Vertices() {return Plane::_Vertices;}
            inline static const size_t & Count() {return 4;}
            
        private:
            static Vertices_t _Vertices;
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ namespace megu {
    class Quads : public Static_Geometry<Quads, QUADS, layout::FLAT, layout::TEXTURE> {
        public:
            inline static const Vertices_t & Vertices() {return Quads::_Vertices;}
            inline static const size_t & Count() {return 4;}
            
        private:
            static Vertices_t _Vertices;
Original line number Diff line number Diff line
#pragma once

#include <glm/glm.hpp>

namespace megu {
    struct Vertex {
        glm::vec2 _position;
        glm::vec2 _texture;
    };
}
 No newline at end of file
+0 −12
Original line number Diff line number Diff line
#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
+0 −88
Original line number Diff line number Diff line
#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();

        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;         
    
        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("uProj", camera.projection());
                    this->_program.setUniform("uView", camera.view());
                    this->_program.setUniform("uSampler", uSampler);
                    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("uProj", camera.projection());
            this->_program.setUniform("uView", camera.view());
            
            
            this->_program.setUniform("uSampler", uSampler);
            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
Original line number Diff line number Diff line
#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().size(), megu::EditMode::STATIC) {
    FrameBufferModule::FrameBufferModule()
    : _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);

@@ -15,13 +14,11 @@ namespace megu {

        this->_program.link();

        this->_vbo << Plane::Vertices();

        vert.release();
        frag.release();
    }

    void FrameBufferGroup::draw(const Window & window, const Camera & camera, const TextureArray & textures) const {
    void FrameBufferModule::render(const TextureArray & textures) {
        this->_program.use();
        this->_vao.bind();

Original line number Diff line number Diff line
#pragma once

#include "DrawGroup.hpp"


#include <map>
#include <list>
#include <set>

#include <engine/graphics/utility/isometric_sorter.hpp>
#include <any>

#include <engine/graphics/back/buffers/VertexArray.hpp>
#include <engine/graphics/back/buffers/VerticeBuffer.hpp>
@@ -15,20 +8,17 @@

#include <engine/graphics/front/object/Image.hpp>

#include "Module.hpp"

namespace megu {
    class ImageGroup : public DrawGroup {
    class FrameBufferModule {
       public:
            ImageGroup();
           ~ImageGroup() = default;

            void draw(const Window &, const Camera &, const TextureArray &) const override;
            FrameBufferModule();
           ~FrameBufferModule() = default;

            void add(const Image &);
            void update();
            void render(const TextureArray &);

        private:
            std::set<std::reference_wrapper<const Image>, isometric_sorter> _images;
            
            VertexArray _vao;
            VerticeBuffer _vbo;
            Program _program;
Original line number Diff line number Diff line
#pragma once

#include <engine/graphics/back/cameras/Camera.hpp>
#include <engine/graphics/front/engine/TextureArray.hpp>
#include <engine/graphics/utility/reference_sorter.hpp>
#include <engine/io/Window.hpp>

namespace megu {
    template <class T>
    class Module {
        public:
            virtual void draw(T &, const Window &, const Camera &, const TextureArray &) const = 0;
    };

    template <class ... Ts>
    class Multy_Module : public Module<Ts> ... {};

    template <class T>
    using ref_set = std::set<std::reference_wrapper<T>, reference_sorter<T>>;

    template <class T>
    using Module_Array = Module<ref_set<T>>;

    template <class ... Ts>
    class Multy_Module_Array : public Module_Array<Ts> ... {};
}
 No newline at end of file
Original line number Diff line number Diff line
#include "QuadGraphicModule.hpp"

#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/object/Sprite.hpp>

#include <iostream>

namespace megu {
    void QuadGraphicModule::draw(Image &, const Window &, const Camera &, const TextureArray &) const {
        std::cout << "Image !" << std::endl;
    }

    void QuadGraphicModule::draw(Sprite &, const Window &, const Camera &, const TextureArray &) const {
        std::cout << "Sprite !" << std::endl;
    }
}
 No newline at end of file
Original line number Diff line number Diff line
#pragma once

#include "Module.hpp"



namespace megu {
    class Image;
    class Sprite;

    class QuadGraphicModule : public Module<Image>, public Module<Sprite> {
        public:
            void draw(Image &, const Window &, const Camera &, const TextureArray &) const override;
            void draw(Sprite &, const Window &, const Camera &, const TextureArray &) const override;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@

#include <engine/graphics/back/geometry/Transformable.hpp>
#include <engine/graphics/back/textures/Texture.hpp> 

#include <engine/graphics/front/geometry/Quads.hpp>
#include <engine/graphics/utility/type.hpp>

Original line number Diff line number Diff line
#pragma once

#include <memory>
#include <iostream>

#include <engine/graphics/front/module/Module.hpp>

namespace megu {
    class Renderable {
        public:
            Renderable() = delete;

            template <class T, class M>
            Renderable(T & object, M & module) 
            : _pimpl(std::make_unique<RenderableModel<T, M>>(object, module)) {}

            Renderable(const Renderable & src) {
                this->_pimpl = src._pimpl->clone();
            }

            Renderable & operator=(const Renderable & src) {
                this->_pimpl = src._pimpl->clone();
                return *this;
            }

            Renderable(Renderable &&) = default;
            Renderable & operator=(Renderable &&) = default;

        private:
            struct RenderableConcept {
                virtual ~RenderableConcept() {};

                virtual void render(const Window &, const Camera &, const TextureArray &) const = 0;
                virtual std::unique_ptr<RenderableConcept> clone() const = 0;
            };

            template <class T, class M>
            struct RenderableModel : public RenderableConcept {
                RenderableModel(T & v, M & m) 
                : _object{ v }, _module{ m } {}

                void render(const Window & window, const Camera & camera, const TextureArray & array) const override {
                    this->_module.draw(this->_object, window, camera, array);
                    
                }

                std::unique_ptr<RenderableConcept> clone() const override {
                    return std::make_unique<RenderableModel>(*this);
                }

                T & _object;
                M & _module;
            };

            friend void render_ext(Renderable & renderable, const Window & window, const Camera & camera, const TextureArray & array) {
                renderable._pimpl->render(window, camera, array);
            }

            std::unique_ptr<RenderableConcept> _pimpl;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
#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
Original line number Diff line number Diff line
#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
Original line number Diff line number Diff line
#include "VerticesArray.hpp"

namespace megu {
    VerticesArray::VerticesArray(Primitive_t primitive, size_t size)
    : _primitive(primitive), _vertices(size) {}

    VerticesArray::VerticesArray(const VerticesArray & src)
    : _transformation(src._transformation), _primitive(src._primitive), _vertices(src._vertices) {}

    VerticesArray VerticesArray::operator=(const VerticesArray & src) {
        this->_transformation = src._transformation;
        this->_primitive = src._primitive;
        this->_vertices = src._vertices;
        return *this;
    }

    void VerticesArray::append(const Vertex & vertex) {
        this->_vertices.push_back(vertex);
    }
}
 No newline at end of file
Original line number Diff line number Diff line
#pragma once

#include <array>

#include <engine/graphics/back/geometry/Transformable.hpp>
#include <engine/graphics/back/textures/Texture.hpp> 
#include <engine/graphics/front/geometry/Quads.hpp>
#include <engine/graphics/front/geometry/Vertex.hpp>

namespace megu {
    class VerticesArray {
        public:
            VerticesArray(Primitive_t, size_t);
            VerticesArray(const VerticesArray &);
            VerticesArray operator=(const VerticesArray &);
            ~VerticesArray() = default;

            inline size_t size() const {return this->_vertices.size();}

            void scale(float x, float y) {this->_transformation.scale(x, y);}

            void append(const Vertex &);

            const Transformable & transformation() const {return this->_transformation;}
            const Primitive_t & primitive() const {return this->_primitive;}
            const std::vector<Vertex> & vertices() const {return this->_vertices;}
            
            Vertex & operator[](size_t index) {return this->_vertices[index];}
            const Vertex & operator[](size_t index) const {return this->_vertices[index];}

        private:
            Transformable _transformation;
            Primitive_t _primitive;
            std::vector<Vertex> _vertices;
    };
}
 No newline at end of file
Original line number Diff line number Diff line
#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
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
#pragma once

namespace megu {
    template <class... Ts>
    struct overloaded : Ts ... {
        using Ts::operator()...;
    };

    template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
}
 No newline at end of file
Original line number Diff line number Diff line
#pragma once

#include <engine/graphics/back/textures/Texture.hpp>

namespace megu {
    struct texture_comparator {
        bool operator()(const Texture & t1, const Texture & t2) const {
            return t1.identifier() > t2.identifier();
        }
    };
}
 No newline at end of file
+189 −14
Original line number Diff line number Diff line
#include <iostream>
#include <thread>

#include <GL/glew.h>
#include <GLFW/glfw3.h>
@@ -13,7 +14,6 @@
#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/errors.hpp>
@@ -30,6 +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
@@ -39,10 +47,6 @@ int main(int argc, const char * argv[]) {

        std::cout << "Window Inited" << std::endl;
       
        //? Group
        megu::ImageGroup group;
        megu::ImageGroup group_2;
       
        std::cout << "Group Inited" << std::endl;

        //? Image 1
@@ -83,7 +87,6 @@ int main(int argc, const char * argv[]) {
                ++y;
            }


            if(id != 0) {
                switch (id % 4) {
                    case 1:
@@ -111,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;

@@ -153,13 +156,97 @@ 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;


        //? Engines
        megu::GraphicEngine engine(window);
        megu::Renderer basic_renderer(360, 360);

        engine.push(0, basic_renderer);

        engine.push<megu::Image>(0, 0, *((images.front()).get()));

        //? Render Loop
        std::cout << "Render Loop Begin !" << std::endl;
        glm::vec2 xy = {0, 0};

        double previousTime = megu::Window::Time();
        int frameCount = 0;

        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();
        }
        std::cout << "Render Loop End !" << std::endl;
    }
    catch(std::exception & error) {
        std::cerr << error.what() << std::endl;
    }

    return EXIT_SUCCESS;
}


//* Tilemap
/*
int main(int argc, const char * argv[]) {
    try {
        //? Window
        megu::Window window;
        window.open("Isometric Window", 360, 360);
        megu::error::opengl_error::check();

        std::cout << "Window Inited" << std::endl;

        //? Group
        megu::VertexArrayGroup group;
       
        std::cout << "Group Inited" << std::endl;

        //? Grids

        megu::Texture texture_1;
        texture_1.store(megu::TextureBuffer("assets/textures/Tile_Test_3.png"));

        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] = to_screen_coordinate(0,  0,  0,  0,  texture_1);
        grid_1[1] = to_screen_coordinate(16, 0,  16, 0,  texture_1);
        grid_1[2] = to_screen_coordinate(16, 16, 16, 16, texture_1);
        grid_1[3] = to_screen_coordinate(0,  16, 0,  16, texture_1);


        grid_1.scale(1.f, 1.f);

        

        group.add(texture_1, grid_1);

        std::cout << "Grid created" << std::endl;

        //? ImGui
        //ImGui::CreateContext();
        //ImGui_ImplOpenGL3_Init();
@@ -167,20 +254,104 @@ int main(int argc, const char * argv[]) {

        //? Engines
        megu::GraphicEngine engine(window);
        megu::Renderer basic_renderer(360, 360);
        megu::Renderer basic_renderer(100, 100);

        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;

        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();
        }
        std::cout << "Render Loop End !" << std::endl;
    }
    catch(std::exception & error) {
        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);
        //engine.push(0, 0, group_2);

        //? Render Loop
        std::cout << "Render Loop Begin !" << std::endl;
        glm::vec2 xy = {0, 0};

        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++;
@@ -195,6 +366,8 @@ int main(int argc, const char * argv[]) {
            window.pollEvents();
            engine.step();
        }

        t.join();
        std::cout << "Render Loop End !" << std::endl;
    }
    catch(std::exception & error) {
@@ -203,3 +376,5 @@ int main(int argc, const char * argv[]) {

    return EXIT_SUCCESS;
}
*/