Skip to content

Commit

Permalink
Merge pull request #11 from ProtectedVariable/renderpass
Browse files Browse the repository at this point in the history
Renderpass
  • Loading branch information
ProtectedVariable authored Dec 12, 2024
2 parents 4762d3a + f891886 commit 34ba853
Show file tree
Hide file tree
Showing 32 changed files with 463 additions and 242 deletions.
10 changes: 10 additions & 0 deletions Assets/Shaders/lastpass.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330 core

out vec4 fragColor;

in vec2 fUV;
uniform sampler2D uTexture;

void main() {
fragColor = texture(uTexture, fUV);
}
10 changes: 10 additions & 0 deletions Assets/Shaders/lastpass.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aUV;

out vec2 fUV;

void main() {
gl_Position = vec4(aPos, 1.0);
fUV = aUV;
}
6 changes: 2 additions & 4 deletions ICE/Core/include/ICEEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Created by Thomas Ibanez on 25.11.20.
//

#ifndef ICE_ICEENGINE_H
#define ICE_ICEENGINE_H
#pragma once

#include <AssetBank.h>
#include <EngineConfig.h>
Expand Down Expand Up @@ -63,6 +62,7 @@ class ICEEngine {
std::shared_ptr<RendererAPI> api;
std::shared_ptr<Framebuffer> internalFB;
std::shared_ptr<Framebuffer> m_target_fb = nullptr;
std::shared_ptr<Window> m_window;

std::shared_ptr<Camera> camera;
std::shared_ptr<Project> project = nullptr;
Expand All @@ -71,5 +71,3 @@ class ICEEngine {
Registry registry;
};
} // namespace ICE

#endif //ICE_ICEENGINE_H
22 changes: 15 additions & 7 deletions ICE/Core/src/ICEEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ ICEEngine::ICEEngine() : camera(std::make_shared<PerspectiveCamera>(60, 16.f / 9

void ICEEngine::initialize(const std::shared_ptr<GraphicsFactory> &graphics_factory, const std::shared_ptr<Window> &window) {
Logger::Log(Logger::INFO, "Core", "Engine starting up...");

m_graphics_factory = graphics_factory;
ctx = graphics_factory->createContext(window);
m_window = window;
m_window->setSwapInterval(1);
m_window->setResizeCallback([this](int w, int h) {
if (project) {
project->getCurrentScene()->getRegistry()->getSystem<RenderSystem>()->setViewport(0, 0, w, h);
}
});
ctx = graphics_factory->createContext(m_window);
ctx->initialize();
api = graphics_factory->createRendererAPI();
window->setSwapInterval(1);
api->initialize();
internalFB = graphics_factory->createFramebuffer({720, 720, 1});
}

void ICEEngine::step(const std::shared_ptr<Scene> &scene) {
project->getCurrentScene()->getRegistry()->getSystem<RenderSystem>()->setTarget(m_target_fb);

auto render_system = project->getCurrentScene()->getRegistry()->getSystem<RenderSystem>();
render_system->setTarget(m_target_fb);
render_system->setCamera(camera);
project->getCurrentScene()->getRegistry()->updateSystems(0.0);
}

Expand Down Expand Up @@ -89,13 +95,15 @@ void ICEEngine::setProject(const std::shared_ptr<Project> &project) {
this->camera->getPosition() = project->getCameraPosition();
this->camera->getRotation() = project->getCameraRotation();

auto renderer = std::make_shared<ForwardRenderer>(api, project->getCurrentScene()->getRegistry(), project->getAssetBank());
auto renderer = std::make_shared<ForwardRenderer>(api, m_graphics_factory, project->getCurrentScene()->getRegistry(), project->getAssetBank());
m_rendersystem = std::make_shared<RenderSystem>();
m_rendersystem->setCamera(camera);
m_rendersystem->setRenderer(renderer);
systems.push_back(m_rendersystem);
project->getCurrentScene()->getRegistry()->addSystem(m_rendersystem);
//Skybox::Initialize();

auto [w, h] = m_window->getSize();
renderer->resize(w, h);
}

EngineConfig &ICEEngine::getConfig() {
Expand Down
2 changes: 1 addition & 1 deletion ICE/Graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/ForwardRenderer.cpp
src/Material.cpp
src/Mesh.cpp
)
src/GeometryPass.cpp "include/RenderData.h")

target_link_libraries(${PROJECT_NAME}
PUBLIC
Expand Down
15 changes: 9 additions & 6 deletions ICE/Graphics/include/ForwardRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

#include "Camera.h"
#include "Framebuffer.h"
#include "GeometryPass.h"
#include "RenderCommand.h"
#include "Renderer.h"
#include "RendererConfig.h"

namespace ICE {
class ForwardRenderer : public Renderer {
public:
ForwardRenderer(const std::shared_ptr<RendererAPI>& api, const std::shared_ptr<Registry>& registry, const std::shared_ptr<AssetBank>& assetBank);
ForwardRenderer(const std::shared_ptr<RendererAPI>& api, const std::shared_ptr<GraphicsFactory>& factory,
const std::shared_ptr<Registry>& registry, const std::shared_ptr<AssetBank>& assetBank);

void submit(Entity e) override;
void remove(Entity e) override;
Expand All @@ -35,22 +38,22 @@ class ForwardRenderer : public Renderer {
void resize(uint32_t width, uint32_t height) override;

void setClearColor(Eigen::Vector4f clearColor) override;
void setViewport(int x, int y, int w, int h) override;

private:
std::shared_ptr<RendererAPI> m_api;
std::shared_ptr<Registry> m_registry;
std::shared_ptr<AssetBank> m_asset_bank;

std::shared_ptr<Framebuffer> target = nullptr;
std::vector<std::function<void(void)>> m_render_commands;
std::vector<RenderCommand> m_render_commands;
std::vector<Entity> m_render_queue;
std::vector<Entity> m_lights;
AssetUID m_skybox = NO_ASSET_ID;

//State
AssetUID m_current_shader = 0;
AssetUID m_current_material = 0;
AssetUID m_current_mesh = 0;
GeometryPass m_geometry_pass;

std::shared_ptr<VertexArray> m_quad_vao;

RendererConfig config;
};
Expand Down
3 changes: 2 additions & 1 deletion ICE/Graphics/include/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Framebuffer {
virtual void bind() = 0;
virtual void unbind() = 0;
virtual void resize(int width, int height) = 0;
virtual void* getTexture() = 0;
virtual int getTexture() = 0;
virtual void bindAttachment(int slot) const = 0;
virtual Eigen::Vector4i readPixel(int x, int y) = 0;

FrameBufferFormat getFormat() const { return format; }
Expand Down
24 changes: 24 additions & 0 deletions ICE/Graphics/include/GeometryPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <Entity.h>

#include "Framebuffer.h"
#include "GraphicsFactory.h"
#include "RenderCommand.h"
#include "RenderPass.h"

namespace ICE {
class GeometryPass : public RenderPass {
public:
GeometryPass(const std::shared_ptr<RendererAPI>& api, const std::shared_ptr<GraphicsFactory>& factory, const FrameBufferFormat& format);
void submit(std::vector<RenderCommand>* commands) { m_render_queue = commands; }
void execute() override;
std::shared_ptr<Framebuffer> getResult() const;
void resize(int w, int h);

private:
std::shared_ptr<RendererAPI> m_api;
std::shared_ptr<Framebuffer> m_framebuffer;
std::vector<RenderCommand>* m_render_queue;
};
} // namespace ICE
24 changes: 12 additions & 12 deletions ICE/Graphics/include/GraphicsFactory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <GraphicsFactory.h>
#include <Window.h>

#include <memory>

Expand All @@ -10,30 +11,29 @@
#include "Shader.h"
#include "Texture.h"
#include "VertexArray.h"
#include <Window.h>
#include <memory>

namespace ICE {
class GraphicsFactory {
public:
virtual std::shared_ptr<Context> createContext(const std::shared_ptr<Window> &window) = 0;
virtual std::shared_ptr<Context> createContext(const std::shared_ptr<Window>& window) const = 0;

virtual std::shared_ptr<Framebuffer> createFramebuffer(const FrameBufferFormat& format) = 0;
virtual std::shared_ptr<Framebuffer> createFramebuffer(const FrameBufferFormat& format) const = 0;

virtual std::shared_ptr<RendererAPI> createRendererAPI() = 0;
virtual std::shared_ptr<RendererAPI> createRendererAPI() const = 0;

virtual std::shared_ptr<VertexArray> createVertexArray() = 0;
virtual std::shared_ptr<VertexArray> createVertexArray() const = 0;

virtual std::shared_ptr<VertexBuffer> createVertexBuffer() = 0;
virtual std::shared_ptr<VertexBuffer> createVertexBuffer() const = 0;

virtual std::shared_ptr<IndexBuffer> createIndexBuffer() = 0;
virtual std::shared_ptr<IndexBuffer> createIndexBuffer() const = 0;

virtual std::shared_ptr<Shader> createShader(const std::string& vertexFile, const std::string& fragmentFile) = 0;
virtual std::shared_ptr<Shader> createShader(const std::string& vertexFile, const std::string& fragmentFile) const = 0;

virtual std::shared_ptr<Shader> createShader(const std::string& vertexFile, const std::string& geometryFile, const std::string& fragmentFile) = 0;
virtual std::shared_ptr<Shader> createShader(const std::string& vertexFile, const std::string& geometryFile,
const std::string& fragmentFile) const = 0;

virtual std::shared_ptr<Texture2D> createTexture2D(const std::string& file) = 0;
virtual std::shared_ptr<Texture2D> createTexture2D(const std::string& file) const = 0;

virtual std::shared_ptr<TextureCube> createTextureCube(const std::string& file) = 0;
virtual std::shared_ptr<TextureCube> createTextureCube(const std::string& file) const = 0;
};
} // namespace ICE
23 changes: 18 additions & 5 deletions ICE/Graphics/include/RenderCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
// Created by Thomas Ibanez on 19.11.20.
//

#ifndef ICE_RENDERCOMMAND_H
#define ICE_RENDERCOMMAND_H
#pragma once

namespace ICE {
#include <memory>
#include <unordered_map>

#include "Material.h"
#include "Mesh.h"
#include "Shader.h"

}
namespace ICE {
struct RenderCommand {
std::shared_ptr<Mesh> mesh;
std::shared_ptr<Material> material;
std::shared_ptr<Shader> shader;
std::unordered_map<AssetUID, std::shared_ptr<Texture>> textures;
Eigen::Matrix4f model_matrix;

#endif //ICE_RENDERCOMMAND_H
bool faceCulling = true;
bool depthTest = true;
};
} // namespace ICE
24 changes: 24 additions & 0 deletions ICE/Graphics/include/RenderData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <vector>

static std::vector<float> full_quad_v = {
-1.0f, -1.0f, 0.0f, // TOP LEFT
1.0, -1.0f, 0.0f, // TOP RIGHT
-1.0f, 1.0, 0.0f, // BOTTOM LEFT
1.0, 1.0, 0.0f, // BOTTOM RIGHT
};

static std::vector<int> full_quad_idx = {
0, 1, 2, 2, 1, 3
};


static std::vector<float> full_quad_tx = {
0, 0, // TOP LEFT
1, 0, // TOP RIGHT
0, 1, // BOTTOM LEFT
1, 1, // BOTTOM RIGHT
1, 0, // TOP RIGHT
0, 1 // BOTTOM LEFT
};
9 changes: 9 additions & 0 deletions ICE/Graphics/include/RenderPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

namespace ICE {
class RenderPass {
public:
virtual ~RenderPass() = default;
virtual void execute() = 0;
};
} // namespace ICE
1 change: 1 addition & 0 deletions ICE/Graphics/include/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class Renderer {
virtual void setTarget(const std::shared_ptr<Framebuffer> &target) = 0;
virtual void resize(uint32_t width, uint32_t height) = 0;
virtual void setClearColor(Eigen::Vector4f clearColor) = 0;
virtual void setViewport(int x, int y, int w, int h) = 0;
};
} // namespace ICE
1 change: 1 addition & 0 deletions ICE/Graphics/include/VertexArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class VertexArray {
virtual std::shared_ptr<IndexBuffer> getIndexBuffer() const = 0;
virtual int getIndexCount() const = 0;
virtual uint32_t getID() const = 0;

};
} // namespace ICE

Expand Down
Loading

0 comments on commit 34ba853

Please sign in to comment.