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

Add Kernel + Physic Engine

parent d1f0d5c7
No related branches found
No related tags found
No related merge requests found
Showing
with 34 additions and 301 deletions
#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
#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
#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 ImageModule : public virtual QuadGraphicModule {
public:
ImageModule();
~ImageModule() = default;
virtual void render(Image &) override;
private:
VertexArray _vao;
VerticeBuffer _vbo;
Program _program;
};
}
\ No newline at end of file
#include "QuadInstanced.hpp"
#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/object/Sprite.hpp>
#include <engine/graphics/front/object/Text.hpp>
#include <engine/graphics/utility/array_generator.hpp>
#include <iostream>
namespace megu {
QuadInstancedModule::QuadInstancedModule()
: _vbo(this->_vao, Quads::Layout(), Quads::Vertices().size(), megu::EditMode::STATIC) {
{
Source vert("assets/shaders/Image-Instanced-Fat.vert", Source::Categorie::VERTEX);
this->_imageProgram.attach(vert);
Source frag("assets/shaders/Texture-Fat.frag", Source::Categorie::FRAGMENT);
this->_imageProgram.attach(frag);
this->_imageProgram.link();
vert.release();
frag.release();
}
{
Source vert("assets/shaders/Sprite.vert", Source::Categorie::VERTEX);
this->_spriteProgram.attach(vert);
Source frag("assets/shaders/Sprite.frag", Source::Categorie::FRAGMENT);
this->_spriteProgram.attach(frag);
this->_spriteProgram.link();
vert.release();
frag.release();
}
{
Source vert("assets/shaders/Text.vert", Source::Categorie::VERTEX);
this->_textProgram.attach(vert);
Source frag("assets/shaders/Text.frag", Source::Categorie::FRAGMENT);
this->_textProgram.attach(frag);
this->_textProgram.link();
vert.release();
frag.release();
}
this->_vbo << Quads::Vertices();
}
void QuadInstancedModule::draw(ref_set<Image> & images, const Window & window, const Camera & camera, const TextureArray &) const {
this->_vao.bind();
this->_imageProgram.use();
this->_imageProgram.setUniform("uProj", camera.projection());
this->_imageProgram.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->_imageProgram.setUniform("uSampler", uSampler);
for(auto & image : 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->_imageProgram.setUniform("uModel", uModels);
this->_imageProgram.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->_imageProgram.setUniform("uModel", uModels);
this->_imageProgram.setUniform("uTextures", uTextures);
glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size()));
}
}
void QuadInstancedModule::draw(ref_set<Sprite> & sprites, const Window &, const Camera & camera, const TextureArray &) const {
this->_vao.bind();
this->_spriteProgram.use();
this->_spriteProgram.setUniform("uProj", camera.projection());
this->_spriteProgram.setUniform("uView", camera.view());
std::vector<std::reference_wrapper<const Texture>> textures;
std::vector<glm::mat4> uModels;
std::vector<glm::vec4> uFrames;
std::vector<glm::vec2> uSizes;
std::vector<GLint> uTextures;
static auto uSampler = array_generator<GLint, 32>().array;
this->_spriteProgram.setUniform("uSampler", uSampler);
for(auto & image : sprites) {
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());
uFrames.push_back(image.get().frame());
uSizes.push_back({it->get().width(), it->get().height()});
uTextures.push_back(static_cast<GLint>(it - textures.begin()));
}
else {
if(textures.size() >= 8 || uModels.size() >= 124) {
this->_spriteProgram.setUniform("uModel", uModels);
this->_spriteProgram.setUniform("uTextures", uTextures);
this->_spriteProgram.setUniform("uFrames", uFrames);
this->_spriteProgram.setUniform("uSizes", uSizes);
glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size()));
textures.clear();
uModels.clear();
uTextures.clear();
uSizes.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());
uFrames.push_back(image.get().frame());
uSizes.push_back({image.get().texture().width(), image.get().texture().height()});
}
}
if(!textures.empty()) {
this->_spriteProgram.setUniform("uModel", uModels);
this->_spriteProgram.setUniform("uTextures", uTextures);
this->_spriteProgram.setUniform("uFrames", uFrames);
this->_spriteProgram.setUniform("uSizes", uSizes);
glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size()));
}
}
void QuadInstancedModule::draw(Text & text, const Window &, const Camera & camera, const TextureArray &) const {
this->_vao.bind();
this->_textProgram.use();
text.texture().bind();
this->_textProgram.setUniform("uSampler", 0);
glm::vec4 glyphFrame = text['w'];
this->_textProgram.setUniform("uSize", glm::vec2{text.texture().width(), text.texture().height()});
this->_textProgram.setUniform("uGlyphFrame", glyphFrame);
glDrawArrays(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()));
}
}
\ No newline at end of file
#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
#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
......@@ -49,6 +49,21 @@ namespace megu {
}
}
void GraphicEngine::step(Priority priority) {
if(this->_window.isOpen()) {
TextureArray textures;
auto & layer = this->_layers[priority];
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));
FrameBuffer::BindDefaultFrameBuffer();
this->_merger.render(this->_window, 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);
......
......@@ -31,6 +31,7 @@ namespace megu {
inline const std::map<Priority, std::unique_ptr<Layer>> & layers() const {return this->_layers;}
void step();
void step(Priority);
void setClearColor(float, float, float);
private:
......
#include "FrameBufferMerger.hpp"
#include <engine/graphics/front/geometry/Plane.hpp>
#include <engine/graphics/utility/array_generator.hpp>
#include <engine/utility/array_generator.hpp>
namespace megu {
FrameBufferMerger::FrameBufferMerger()
......
......@@ -7,12 +7,12 @@
#include <engine/graphics/back/buffers/FrameBuffer.hpp>
#include <engine/graphics/front/object/Renderable.hpp>
#include <engine/graphics/utility/reference_sorter.hpp>
#include <engine/utility/reference_sorter.hpp>
#include <engine/graphics/front/object/Renderable.hpp>
#include <engine/graphics/front/module/Module.hpp>
#include "Priority.hpp"
#include <engine/utility/Priority.hpp>
#include "Renderer.hpp"
namespace megu {
......
......@@ -2,7 +2,7 @@
#include <optional>
#include <engine/graphics/utility/reference_sorter.hpp>
#include <engine/utility/reference_sorter.hpp>
#include <engine/graphics/back/buffers/FrameBuffer.hpp>
#include <engine/graphics/back/cameras/View.hpp>
......
#include "Image_Module.hpp"
#include <engine/graphics/back/cameras/Camera.hpp>
#include <engine/graphics/utility/array_generator.hpp>
#include <engine/utility/array_generator.hpp>
namespace megu {
Image_Module::Image_Module()
......
......@@ -7,7 +7,7 @@
#include <engine/graphics/back/shaders/Program.hpp>
#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/utility/ref_set.hpp>
#include <engine/utility/ref_set.hpp>
namespace megu {
class Image_Module : public Module<ref_set<Image>> {
......
#include "Sprite_Module.hpp"
#include <engine/graphics/back/cameras/Camera.hpp>
#include <engine/graphics/utility/array_generator.hpp>
#include <engine/utility/array_generator.hpp>
namespace megu {
Sprite_Module::Sprite_Module()
......
......@@ -7,7 +7,7 @@
#include <engine/graphics/back/shaders/Program.hpp>
#include <engine/graphics/front/object/Sprite.hpp>
#include <engine/graphics/utility/ref_set.hpp>
#include <engine/utility/ref_set.hpp>
namespace megu {
class Sprite_Module : public Module<ref_set<Sprite>> {
......
#include "Text_Module.hpp"
#include <engine/graphics/back/cameras/Camera.hpp>
#include <engine/graphics/utility/array_generator.hpp>
#include <engine/utility/array_generator.hpp>
namespace megu {
Text_Module::Text_Module()
......
......@@ -7,7 +7,7 @@
#include <engine/graphics/back/shaders/Program.hpp>
#include <engine/graphics/front/object/Text.hpp>
#include <engine/graphics/utility/ref_set.hpp>
#include <engine/utility/ref_set.hpp>
namespace megu {
class Text_Module : public Module<Text> {
......
......@@ -9,7 +9,6 @@ namespace megu {
this->link(texture);
}
Image Image::operator=(const Image & image) {
this->_texture = image._texture;
this->_transformation = image._transformation;
......
#pragma once
#include <utility/Identifiable.hpp>
#include <filesystem>
#include <glm/vec2.hpp>
#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>
#include <engine/utility/type.hpp>
namespace megu {
class Image : public Quads {
class Image : public Quads, virtual public Identifiable {
public:
Image() = default;
Image(const std::filesystem::path &);
......
#pragma once
#include <utility/Identifiable.hpp>
#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>
#include <engine/utility/type.hpp>
namespace megu {
class Sprite : public Quads {
class Sprite : public Quads, virtual public Identifiable {
public:
using Frame = glm::vec4;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment