diff --git a/source/engine/graphics/back/geometry/Transformable.cpp b/source/engine/graphics/back/geometry/Transformable.cpp index e553b6b3bdc12ec52d2d85a1ef5a37936e06784d..997deaf2f7ca9a551813c9f1e989d29b799a10b3 100644 --- a/source/engine/graphics/back/geometry/Transformable.cpp +++ b/source/engine/graphics/back/geometry/Transformable.cpp @@ -37,6 +37,26 @@ namespace megu { _origine(std::move(src._origine)), _updated(false) {} + Transformable Transformable::operator=(const Transformable & src) { + this->_model = src._model; + this->_origine = src._origine; + this->_position = src._position; + this->_rotation = src._rotation; + this->_scaling = src._scaling; + this->_updated = src._updated; + return *this; + } + + Transformable Transformable::operator=(const Transformable && src) { + this->_model = std::move(src._model); + this->_origine = std::move(src._origine); + this->_position = std::move(src._position); + this->_rotation = std::move(src._rotation); + this->_scaling = std::move(src._scaling); + this->_updated = std::move(src._updated); + return *this; + } + void Transformable::setPosition(const glm::vec3 & position) { this->_position = position; this->_updated = true; @@ -104,26 +124,37 @@ namespace megu { this->_updated = true; } - const glm::mat4x4 & Transformable::model() const { - if(this->_updated) { - glm::mat4x4 model = glm::mat4x4(1.f); + void Transformable::update() const { + glm::mat4x4 model = glm::mat4x4(1.f); - model = glm::translate(model, this->_position); - model = glm::translate(model, this->_origine); + model = glm::translate(model, this->_position); + model = glm::translate(model, this->_origine); - model = glm::rotate(model, glm::radians(this->_rotation.z), {0.f, 0.f, 1.f}); - model = glm::rotate(model, glm::radians(this->_rotation.y), {0.f, 1.f, 0.f}); - model = glm::rotate(model, glm::radians(this->_rotation.x), {1.f, 0.f, 0.f}); + model = glm::rotate(model, glm::radians(this->_rotation.z), {0.f, 0.f, 1.f}); + model = glm::rotate(model, glm::radians(this->_rotation.y), {0.f, 1.f, 0.f}); + model = glm::rotate(model, glm::radians(this->_rotation.x), {1.f, 0.f, 0.f}); - model = glm::translate(model, -this->_origine); - model = glm::scale(model, this->_scaling); + model = glm::translate(model, -this->_origine); + model = glm::scale(model, this->_scaling); - this->_model = model; - this->_updated = false; + this->_model = model; + this->_updated = false; + } + + const glm::mat4x4 & Transformable::model() const { + if(this->_updated) { + this->update(); } return this->_model; } + glm::mat4 Transformable::inverse_model() const { + if(this->_updated) { + this->update(); + } + return glm::inverse(this->_model); + } + bool Transformable::operator==(const Transformable & t) const { return this->_position == t._position; } @@ -133,18 +164,18 @@ namespace megu { } bool Transformable::operator>=(const Transformable & t) const { - return this->_position.x <= t._position.x && this->_position.y <= t._position.y; + return this->_position.x >= t._position.x && this->_position.y >= t._position.y && this->_position.z >= t._position.z; } bool Transformable::operator<=(const Transformable & t) const { - return this->_position.x >= t._position.x && this->_position.y >= t._position.y; + return this->_position.x >= t._position.x && this->_position.y >= t._position.y && this->_position.z >= t._position.z; } bool Transformable::operator>(const Transformable & t) const { - return this->_position.x < t._position.x && this->_position.y < t._position.y; + return this->_position.x > t._position.x && this->_position.y > t._position.y && this->_position.z > t._position.z; } bool Transformable::operator<(const Transformable & t) const { - return this->_position.x > t._position.x && this->_position.y > t._position.y; + return this->_position.x < t._position.x && this->_position.y < t._position.y && this->_position.z < t._position.z; } } \ No newline at end of file diff --git a/source/engine/graphics/back/geometry/Transformable.hpp b/source/engine/graphics/back/geometry/Transformable.hpp index c8582090e36a6a4f774493cbd49d4cf0215961ce..a7a127e8684caeb16bec1a981cd02a54699e2a7a 100644 --- a/source/engine/graphics/back/geometry/Transformable.hpp +++ b/source/engine/graphics/back/geometry/Transformable.hpp @@ -20,6 +20,8 @@ namespace megu { Transformable(const glm::vec3 &, const glm::vec3 & = glm::vec3(0.f)); Transformable(const Transformable &); Transformable(const Transformable &&); + Transformable operator=(const Transformable &); + Transformable operator=(const Transformable &&); ~Transformable() = default; inline const glm::vec3 & position() const {return this->_position;} @@ -69,6 +71,10 @@ namespace megu { bool operator<(const Transformable &) const; virtual const glm::mat4x4 & model() const; + glm::mat4 inverse_model() const; + + protected: + void update() const; private: mutable glm::mat4 _model; diff --git a/source/engine/graphics/back/textures/Texture.cpp b/source/engine/graphics/back/textures/Texture.cpp index 4ff4eadaf57fc36c8a572269708803a3d9660f59..319764835c56cd87b5c7e03a901598531a3bc2ab 100644 --- a/source/engine/graphics/back/textures/Texture.cpp +++ b/source/engine/graphics/back/textures/Texture.cpp @@ -142,4 +142,10 @@ namespace megu { void Texture::Unbind(GLuint type) { glBindTexture(type, 0); } + + GLint Texture::CountSlots() { + GLint units = 0; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &units); + return units; + } } \ No newline at end of file diff --git a/source/engine/graphics/back/textures/Texture.hpp b/source/engine/graphics/back/textures/Texture.hpp index 85ada6bb7585d955f89e85c0b4a3037f7394b1a6..7fe4124a59ce452f1117d7ce0d027109043cb1be 100644 --- a/source/engine/graphics/back/textures/Texture.hpp +++ b/source/engine/graphics/back/textures/Texture.hpp @@ -64,6 +64,7 @@ namespace megu { std::strong_ordering operator<=>(const Texture &) const; static void Unbind(GLuint = GL_TEXTURE_2D); + static GLint CountSlots(); private: GLuint _id; diff --git a/source/engine/graphics/front/Engine.cpp b/source/engine/graphics/front/Engine.cpp deleted file mode 100644 index 2c81b69229305ebcc27ac15a55211ee7298dca44..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/Engine.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Engine.hpp" - -namespace megu { - GraphicEngine::GraphicEngine(Window & window,float w, float h) - : _renderer(w, h), _window(window) { - glViewport(0, 0, window.width(), window.height()); - glClearColor(0.f, 0.f, 0.f, 1.f); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - } - - void GraphicEngine::step() { - if(this->_window.isOpen()) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - this->_renderer.render(this->_window); - this->_window.swapBuffers(); - } - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/Renderer.cpp b/source/engine/graphics/front/Renderer.cpp deleted file mode 100644 index e1c8f589ff988fc7fef785facd1d0eef84a8c68c..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/Renderer.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Renderer.hpp" - -namespace megu { - Renderer::Renderer(float x, float y) - : _view(0, 0, y, x) { - - } - - void Renderer::add(DrawGroup & group) { - this->_groups.insert(&group); - } - - void Renderer::render(const Window & window) const { - for(auto & group : this->_groups) { - group->draw(window, this->_view); - } - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Engine.cpp b/source/engine/graphics/front/engine/Engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff970327e2d841a49fe8119f669f54330fcfa3c7 --- /dev/null +++ b/source/engine/graphics/front/engine/Engine.cpp @@ -0,0 +1,23 @@ +#include "Engine.hpp" + +namespace megu { + GraphicEngine::GraphicEngine(Window & window,float w, float h) + : _renderer(w, h), _window(window) { + glViewport(0, 0, window.width(), window.height()); + this->_renderer.setClearColor(0.f, 0.f, 0.f); + } + + void GraphicEngine::push(DrawGroup & group, Priority priority) { + this->_objects[priority] = &group; + } + + void GraphicEngine::step() { + if(this->_window.isOpen() && !this->_objects.empty()) { + this->_renderer.clear(); + for(auto & [priority, groups] : this->_objects) { + this->_renderer.render(this->_window, *groups, {}); + } + this->_window.swapBuffers(); + } + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/Engine.hpp b/source/engine/graphics/front/engine/Engine.hpp similarity index 56% rename from source/engine/graphics/front/Engine.hpp rename to source/engine/graphics/front/engine/Engine.hpp index 9493020e963f97790b63077f812df0890b85e418..144bbdb56ebc635c72759433207b0f42915fd0cc 100644 --- a/source/engine/graphics/front/Engine.hpp +++ b/source/engine/graphics/front/engine/Engine.hpp @@ -1,6 +1,10 @@ #pragma once +#include <map> +#include <engine/graphics/front/group/DrawGroup.hpp> + #include "Renderer.hpp" +#include "FrameBufferGroup.hpp" namespace megu { class GraphicEngine { @@ -9,14 +13,16 @@ namespace megu { GraphicEngine(Window &, float, float); ~GraphicEngine() = default; + void push(DrawGroup &, Priority); + void step(); - inline void setClearColor(float r, float g, float b, float a = 1.f) const {glClearColor(r, g, b, a);} - Renderer & tmp_getRenderer() {return this->_renderer;} + Renderer & tmp_renderer() {return this->_renderer;} private: - Window & _window; Renderer _renderer; + std::map<Priority, DrawGroup *> _objects; + Window & _window; }; } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/FrameBufferGroup.cpp b/source/engine/graphics/front/engine/FrameBufferGroup.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34835f67120bd856ead2af121da1afad87d7f0a6 --- /dev/null +++ b/source/engine/graphics/front/engine/FrameBufferGroup.cpp @@ -0,0 +1,57 @@ +#include "FrameBufferGroup.hpp" + +#include <glm/gtc/matrix_transform.hpp> + +namespace megu { + FrameBufferGroup::FrameBufferGroup() + : _vbo(this->_vao, Quads::Layout(), Quads::Vertices(), EditMode::STATIC) { + megu::Source vert("assets/shaders/FrameBuffer-Instanced.vert", Source::Categorie::VERTEX); + this->_program.attach(vert); + + megu::Source frag("assets/shaders/FrameBuffer-Instanced.frag", Source::Categorie::FRAGMENT); + this->_program.attach(frag); + + this->_program.link(); + + vert.release(); + frag.release(); + } + + void FrameBufferGroup::draw(const Window & window, const Camera & camera, const TextureArray & textures) const { + if(window.isOpen()) { + std::vector<glm::mat4> uModels; + std::vector<GLint> uTextures; + + this->_vao.bind(); + + size_t i = 1; + GLint slotsCount = Texture::CountSlots(); + for(auto & texture : textures) { + if(i % slotsCount == 0) { + this->_program.use(); + + this->_program.setUniform("uModels", uModels); + this->_program.setUniform("uTextures", uTextures); + + glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(Quads::Vertices().size()), static_cast<GLsizei>(i)); + uModels.clear(); + uModels.clear(); + } + + texture.get().bind(i-1 % slotsCount); + + uTextures.push_back(i-1); + uModels.push_back(glm::translate(glm::mat4(1), glm::vec3(0.f, 0.f, static_cast<float>(i)))); + } + + if(uModels.empty()) { + this->_program.use(); + + this->_program.setUniform("uModels", uModels); + this->_program.setUniform("uTextures", uTextures); + + glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(Quads::Vertices().size()), static_cast<GLsizei>(i)); + } + } + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/engine/FrameBufferGroup.hpp b/source/engine/graphics/front/engine/FrameBufferGroup.hpp new file mode 100644 index 0000000000000000000000000000000000000000..94659e36b7f71e149f8ecd29bd2603a819326e89 --- /dev/null +++ b/source/engine/graphics/front/engine/FrameBufferGroup.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/geometry/Quads.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; + + private: + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Renderer.cpp b/source/engine/graphics/front/engine/Renderer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05663392b7f6b0e88367f9ef4596e66718da015c --- /dev/null +++ b/source/engine/graphics/front/engine/Renderer.cpp @@ -0,0 +1,21 @@ +#include "Renderer.hpp" + +namespace megu { + Renderer::Renderer(float x, float y) + : _view(0, 0, y, x) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + 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() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void Renderer::setClearColor(float r, float g, float b, float a) { + glClearColor(r, g, b, a); + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/Renderer.hpp b/source/engine/graphics/front/engine/Renderer.hpp similarity index 60% rename from source/engine/graphics/front/Renderer.hpp rename to source/engine/graphics/front/engine/Renderer.hpp index 517585960e964a001f29919925105112364ed86f..a99b6ec7df3dfc8866444d9a94af96b7d0d1a470 100644 --- a/source/engine/graphics/front/Renderer.hpp +++ b/source/engine/graphics/front/engine/Renderer.hpp @@ -1,10 +1,11 @@ #pragma once -#include <set> -#include <any> +#include <optional> #include <engine/graphics/utility/reference_sorter.hpp> +#include <engine/graphics/back/buffers/FrameBuffer.hpp> #include <engine/graphics/back/cameras/View.hpp> + #include <engine/graphics/front/group/DrawGroup.hpp> namespace megu { @@ -13,14 +14,13 @@ namespace megu { Renderer() = delete; Renderer(float, float); ~Renderer() = default; - - void add(DrawGroup & group); - virtual void render(const Window &) const; + virtual void render(const Window &, const DrawGroup &, const TextureArray &) const; + + void clear(); + void setClearColor(float, float, float, float = 1.f); private: - std::set<DrawGroup *> _groups; View _view; - }; } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/TextureArray.hpp b/source/engine/graphics/front/engine/TextureArray.hpp new file mode 100644 index 0000000000000000000000000000000000000000..174955e9b1725fda09ecd6c215219d2ee0293904 --- /dev/null +++ b/source/engine/graphics/front/engine/TextureArray.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include <set> +#include <engine/graphics/back/textures/Texture.hpp> + +namespace megu { + using TextureArray = std::set<std::reference_wrapper<const Texture>>; +} \ No newline at end of file diff --git a/source/engine/graphics/front/group/DrawGroup.cpp b/source/engine/graphics/front/group/DrawGroup.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75db3f7edf1ea52475a9edbfd61be9d915d5b989 --- /dev/null +++ b/source/engine/graphics/front/group/DrawGroup.cpp @@ -0,0 +1,5 @@ +#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 index 3c57018818bfa00ae73294798a8928bbb33b1021..f32eaf9448ca4de2d8113ff48605a492827436a6 100644 --- a/source/engine/graphics/front/group/DrawGroup.hpp +++ b/source/engine/graphics/front/group/DrawGroup.hpp @@ -1,11 +1,20 @@ #pragma once #include <engine/graphics/back/cameras/Camera.hpp> +#include <engine/graphics/front/engine/TextureArray.hpp> #include <engine/io/Window.hpp> namespace megu { + using Priority = size_t; + + struct priority_sorter { + bool operator()(const Priority & p1, const Priority & p2) { + return p1 != p2 ? p1 > p2 : &p1 > &p2; + } + }; + class DrawGroup { public: - virtual void draw(const Window &, const Camera &) const = 0; + 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/ImageGroup.cpp b/source/engine/graphics/front/group/ImageGroup.cpp index 0ecd104b0cc91354fe1247600d41adf13b251880..c1c8cf664ffad2a7b0a9e0c5ab6ee96a5c7a814d 100644 --- a/source/engine/graphics/front/group/ImageGroup.cpp +++ b/source/engine/graphics/front/group/ImageGroup.cpp @@ -32,7 +32,7 @@ namespace megu { } } - void ImageGroup::draw(const Window & window, const Camera & camera) const { + void ImageGroup::draw(const Window & window, const Camera & camera, const TextureArray &) const { this->_vao.bind(); this->_program.use(); @@ -40,7 +40,7 @@ namespace megu { std::vector<glm::mat4> uModels; std::vector<GLint> uTextures; - + for(auto & image : this->_images) { std::vector<std::reference_wrapper<const Texture>>::iterator it = std::find(textures.begin(), textures.end(), image.get().texture()); diff --git a/source/engine/graphics/front/group/ImageGroup.hpp b/source/engine/graphics/front/group/ImageGroup.hpp index fbdbbd73e11c5633ba37076492bc7cc30b433c06..4293a7f4142b4fb6e6ca022b239c47114d5f33a5 100644 --- a/source/engine/graphics/front/group/ImageGroup.hpp +++ b/source/engine/graphics/front/group/ImageGroup.hpp @@ -21,7 +21,7 @@ namespace megu { ImageGroup(); ~ImageGroup() = default; - void draw(const Window &, const Camera &) const override; + void draw(const Window &, const Camera &, const TextureArray &) const override; void add(const Image &); void update(); diff --git a/source/engine/graphics/front/object/Image.cpp b/source/engine/graphics/front/object/Image.cpp index aa830c870cd38453cc03ffc0a60ac7d02450697b..e3873efa041c7678d7d9176a9e0920f3868d09f3 100644 --- a/source/engine/graphics/front/object/Image.cpp +++ b/source/engine/graphics/front/object/Image.cpp @@ -1,29 +1,27 @@ #include "Image.hpp" namespace megu { - Image::Image() - : _texture(), - _geometry(), - _transformation() {} - - Image::Image(const std::filesystem::path & path) - : _texture(), - _geometry(), - _transformation() { + Image::Image(const std::filesystem::path & path) { this->load(path); } - Image::Image(const Texture & texture) - : _texture(), - _geometry(), - _transformation() { - this->load(texture); - } - - Image::Image(const Image & src) - : _texture(src._texture), - _geometry(src._geometry), - _transformation(src._transformation) { + Image::Image(const Texture & texture) { + this->link(texture); + } + + + Image Image::operator=(const Image & image) { + this->_texture = image._texture; + this->_transformation = image._transformation; + + return *this; + } + + Image Image::operator=(const Image && image) { + this->_texture = std::move(image._texture); + this->_transformation = std::move(image._transformation); + + return *this; } void Image::load(const std::filesystem::path & path, bool flip) { @@ -33,12 +31,12 @@ namespace megu { } void Image::load(const TextureBuffer & buffer) { - this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height())); + this->setSize({buffer.width(), buffer.height()}); this->_texture.store(buffer); } - void Image::load(const Texture & texture) { - this->setSize(static_cast<float>(texture.width()), static_cast<float>(texture.height())); + void Image::link(const Texture & texture) { + this->setSize({texture.width(), texture.height()}); this->_texture = texture; } } \ 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 ea098a320bbf9dcf16764fca034e5ee0b7bece00..a4f5e5513c73ccce56ef7bddf1348de3e1cd9427 100644 --- a/source/engine/graphics/front/object/Image.hpp +++ b/source/engine/graphics/front/object/Image.hpp @@ -7,33 +7,43 @@ #include <engine/graphics/back/textures/Texture.hpp> #include <engine/graphics/front/geometry/Quads.hpp> +#include <engine/graphics/utility/type.hpp> namespace megu { class Image { public: - Image(); + Image() = default; Image(const std::filesystem::path &); Image(const Texture &); - Image(const Image &); + Image(const Image &) = default; + Image operator=(const Image &); + Image operator=(const Image &&); ~Image() = default; - inline glm::vec2 getPosition() const {return glm::vec2(this->_transformation.x(), this->_transformation.y());} - inline glm::vec2 getSize() const {return glm::vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} + inline Vec2 getPosition() const {return Vec2(this->_transformation.x(), this->_transformation.y());} + inline Vec2 getOrigine() const {return Vec2(this->_transformation.origine().x, this->_transformation.origine().y);} + inline Vec2 getSize() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} + inline float getRotation() const {return this->_transformation.roll();} + inline float getLayer() const {return this->_transformation.z();} + + inline const Texture & texture() const {return this->_texture;} + inline const Quads & geometry() const {return this->_geometry;} + inline const Transformable & transformation() const {return this->_transformation;} - inline void setPosition(float x, float y) {this->_transformation.setPosition(x, y);} - inline void setOrigine(float x, float y) {this->_transformation.setOrigine(x, y);} - inline void setSize(float x, float y) {this->_transformation.setScaling(x, y);} - inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} - inline void setLayer(float l) {this->_transformation.setZ(l);} + inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} + inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} + inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} + inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} + inline void setLayer(float l) {this->_transformation.setZ(l);} + + inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} + inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} + inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} void load(const std::filesystem::path &, bool = false); void load(const TextureBuffer &); - void load(const Texture &); - - inline const Texture & texture() const {return this->_texture;} - inline const Quads & geometry() const {return this->_geometry;} - inline const Transformable & transformation() const {return this->_transformation;} - + void link(const Texture &); + private: Texture _texture; Quads _geometry; diff --git a/source/engine/graphics/utility/type.hpp b/source/engine/graphics/utility/type.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cacaae63afb3c6c026c5241618c89416619e49b0 --- /dev/null +++ b/source/engine/graphics/utility/type.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <glm/vec4.hpp> +#include <glm/mat4x4.hpp> + +namespace megu { + using Vec2 = glm::vec2; + using Vec3 = glm::vec4; + using Vec4 = glm::vec4; + using Color = glm::vec4; + + using Mat3 = glm::mat3; + using Mat4 = glm::mat4; +} \ No newline at end of file diff --git a/source/kernel/Kernel.hpp b/source/kernel/Kernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d4f26ce7f084c473c4f429388199a09507afb4f9 --- /dev/null +++ b/source/kernel/Kernel.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace megu { + class Kernel { + public: + virtual void initilize_io() = 0; + virtual void initilize_physics() = 0; + virtual void initilize_graphics() = 0; + }; +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 68133f00f0619342fc77e085a13fde9b59b3c920..ea1e694d08ea3224a0c3135abf6ffce126c64fce 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,8 +14,8 @@ #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/Renderer.hpp> -#include <engine/graphics/front/Engine.hpp> +#include <engine/graphics/front/engine/Renderer.hpp> +#include <engine/graphics/front/engine/Engine.hpp> #include <engine/graphics/errors.hpp> #define NORMALIZE(X) X/255.f @@ -43,21 +43,22 @@ int main(int argc, const char * argv[]) { //? Group megu::ImageGroup group; + megu::ImageGroup group_2; std::cout << "Group Inited" << std::endl; - //? Image + //? Image 1 std::vector<int> map = { - 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, + 2, 2, 1, 1, 1, 1, 1, 2, 0, 0, + 0, 0, 2, 1, 1, 1, 1, 2, 0, 0, + 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, + 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, + 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, + 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, + 0, 0, 2, 1, 1, 1, 1, 2, 0, 0, + 0, 0, 2, 1, 1, 1, 1, 2, 0, 0, + 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, + 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, }; size_t x = 0; @@ -80,9 +81,9 @@ int main(int argc, const char * argv[]) { if(id != 0) { images.push_back(std::make_unique<megu::Image>(id == 1 ? texture_1 : texture_2)); - glm::vec2 pos = to_screen_coordinate({x, y}, 32.f, 32.f); + glm::vec2 pos = to_screen_coordinate({x, y}, 32.f, 32.f, 1.f); - images.back()->setPosition(pos.x + 160, pos.y); + images.back()->setPosition({pos.x + 160, pos.y}); } ++x; @@ -90,10 +91,56 @@ int main(int argc, const char * argv[]) { for(auto & i : images) { group.add(*i); - i.get()->setSize(32.f, 32.f); + i.get()->setSize({32.f, 32.f}); } - std::cout << "Image Inited" << std::endl; + std::cout << "Image Inited 1" << std::endl; + + //? Image 1 + std::vector<int> map_2 = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + size_t x_2 = 0; + size_t y_2 = 0; + + std::vector<std::unique_ptr<megu::Image>> images_2; + + megu::Texture texture_3; + texture_3.store(megu::TextureBuffer("assets/textures/Cube_Yellow.png")); + + for(auto id : map_2) { + if(x_2 == 10) { + x_2 = 0; + ++y_2; + } + + + if(id == 0) { + images_2.push_back(std::make_unique<megu::Image>(texture_3)); + glm::vec2 pos = to_screen_coordinate({x_2, y_2}, 32.f, 32.f); + + images_2.back()->setPosition({pos.x + 160, pos.y}); + } + + ++x_2; + } + + for(auto & i : images_2) { + group_2.add(*i); + i.get()->setSize({32.f, 32.f}); + } + + std::cout << "Image Inited 2" << std::endl; //? ImGui ImGui::CreateContext(); @@ -102,15 +149,29 @@ int main(int argc, const char * argv[]) { //? Engines megu::GraphicEngine engine(window, 320, 320); - engine.setClearColor(0.f, 0.f, 0.f); + engine.tmp_renderer().setClearColor(NORMALIZE(135), NORMALIZE(150), NORMALIZE(255)); //? Render Loop std::cout << "Render Loop Begin !" << std::endl; glm::vec2 xy = {0, 0}; - engine.tmp_getRenderer().add(group); + engine.push(group, 1); + engine.push(group_2, 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(); }