Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/Engine/src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cae::Engine::Engine(const EngineConfig &config, const std::function<std::shared_

m_windowPlugin->create(config.window_name, {.width = config.window_width, .height = config.window_height});
m_rendererPlugin->initialize(m_windowPlugin->getNativeHandle());
m_rendererPlugin->createMesh({-0.5F, -0.5F, 1.F, 0.F, 0.F, 0.5F, -0.5F, 0.F, 1.F, 0.F, 0.F, 0.5F, 0.F, 0.F, 1.F});
initShaders(shaderIRFactory, shaderFrontendFactories);
}

Expand All @@ -52,7 +53,7 @@ void cae::Engine::run() const
int fpsIndex = 0;
while (!m_windowPlugin->shouldClose())
{
m_rendererPlugin->draw(m_windowPlugin->getWindowSize());
m_rendererPlugin->draw(m_windowPlugin->getWindowSize(), "basic");
m_windowPlugin->pollEvents();
printFps(fpsBuffer, fpsIndex, m_clock->getDeltaSeconds());
m_clock->restart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace cae
protected:

private:

}; // interface ARenderer

} // namespace cae
24 changes: 17 additions & 7 deletions modules/Interfaces/include/Interfaces/Renderer/IRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
namespace cae
{

struct Color
{
float r;
float g;
float b;
float a;
};

///
/// @interface IRenderer
/// @brief Interface for renderer
Expand All @@ -23,15 +31,17 @@ namespace cae
public:
~IRenderer() override = default;

virtual void initialize(const NativeWindowHandle &nativeWindowHandle) = 0;
virtual void createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
const ShaderIRModule &fragment) = 0;

virtual void draw(const WindowSize &windowSize) = 0;

virtual void setVSyncEnabled(bool enabled) = 0;
virtual bool isVSyncEnabled() const = 0;
virtual void setClearColor(const Color &color) = 0;

[[nodiscard]] virtual bool isVSyncEnabled() const = 0;

virtual void initialize(const NativeWindowHandle &nativeWindowHandle,
const Color &clearColor = {.r = 1.F, .g = 1.F, .b = 1.F, .a = 1.F}) = 0;
virtual void createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
const ShaderIRModule &fragment) = 0;
virtual void draw(const WindowSize &windowSize, const ShaderID &shaderId) = 0;
virtual void createMesh(const std::vector<float> &vertices) = 0;
}; // interface IRenderer

} // namespace cae
25 changes: 17 additions & 8 deletions plugins/Renderer/OpenGL/include/OPGL/OPGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
namespace cae
{

struct Mesh
{
GLuint vao = 0;
GLuint vbo = 0;
GLuint ebo = 0;
GLsizei vertexCount = 0;
};

///
/// @class OPGL
/// @brief Class for the OpenGL plugin
Expand All @@ -36,22 +44,23 @@ namespace cae
[[nodiscard]] utl::PluginType getType() const override { return utl::PluginType::RENDERER; }
[[nodiscard]] utl::PluginPlatform getPlatform() const override { return utl::PluginPlatform::ALL; }

void initialize(const NativeWindowHandle &nativeWindowHandle) override;
void setVSyncEnabled(const bool enabled) override { m_context->setVSyncEnabled(enabled); }
void setClearColor(const Color &color) override { glClearColor(color.r, color.g, color.b, color.a); }

[[nodiscard]] bool isVSyncEnabled() const override { return m_context->isVSyncEnabled(); }

void initialize(const NativeWindowHandle &nativeWindowHandle, const Color &clearColor) override;
void createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
const ShaderIRModule &fragment) override;
void draw(const WindowSize &windowSize) override;

void setVSyncEnabled(bool enabled) override;
[[nodiscard]] bool isVSyncEnabled() const override;
void draw(const WindowSize &windowSize, const ShaderID &shaderId) override;
void createMesh(const std::vector<float>& vertices) override;

private:
std::unique_ptr<IContext> m_context;
std::unordered_map<ShaderID, GLuint> m_programs;
GLuint gVAO = 0;
GLuint gVBO = 0;
Mesh m_mesh;

static GLuint createGLShader(GLenum type, const ShaderIRModule &data);
void createTriangle();

}; // class OPGL

Expand Down
39 changes: 18 additions & 21 deletions plugins/Renderer/OpenGL/src/opgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

#include "Utils/Utils.hpp"

#include <array>
#include <memory>
#include <stdexcept>

void cae::OPGL::initialize(const NativeWindowHandle &nativeWindowHandle)
void cae::OPGL::initialize(const NativeWindowHandle &nativeWindowHandle, const Color &clearColor)
{
#ifdef __linux__
m_context = std::make_unique<EGLContextLinux>();
Expand All @@ -27,27 +26,22 @@ void cae::OPGL::initialize(const NativeWindowHandle &nativeWindowHandle)
m_context->initialize(nativeWindowHandle);

glEnable(GL_DEPTH_TEST);
glClearColor(1.F, 1.F, 1.F, 1.F);
createTriangle();
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
}

void cae::OPGL::draw(const WindowSize &windowSize)
void cae::OPGL::draw(const WindowSize &windowSize, const ShaderID &shaderId)
{
glViewport(0, 0, windowSize.width, windowSize.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glUseProgram(m_programs.at("basic"));
glBindVertexArray(gVAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glUseProgram(m_programs.at(shaderId));
glBindVertexArray(m_mesh.vao);
glDrawArrays(GL_TRIANGLES, 0, m_mesh.vertexCount);
glBindVertexArray(0);

m_context->swapBuffers();
}

void cae::OPGL::setVSyncEnabled(const bool enabled) { m_context->setVSyncEnabled(enabled); }

bool cae::OPGL::isVSyncEnabled() const { return m_context->isVSyncEnabled(); }

void cae::OPGL::createPipeline(const ShaderID &id, const ShaderIRModule &vertex, const ShaderIRModule &fragment)
{

Expand All @@ -62,7 +56,7 @@ void cae::OPGL::createPipeline(const ShaderID &id, const ShaderIRModule &vertex,

GLint success = 0;
glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success)
if (success == 0)
{
char log[512];
glGetProgramInfoLog(program, 512, nullptr, log);
Expand All @@ -75,25 +69,28 @@ void cae::OPGL::createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
m_programs[id] = program;
}

void cae::OPGL::createTriangle()
void cae::OPGL::createMesh(const std::vector<float> &vertices)
{
constexpr std::array vertices = {-0.5F, -0.5F, 1.F, 0.F, 0.F, 0.5F, -0.5F, 0.F,
1.F, 0.F, 0.0F, 0.5F, 0.F, 0.F, 1.F};
Mesh mesh{};
mesh.vertexCount = static_cast<GLsizei>(vertices.size() / 5);

glGenVertexArrays(1, &gVAO);
glGenBuffers(1, &gVBO);
glGenVertexArrays(1, &mesh.vao);
glGenBuffers(1, &mesh.vbo);

glBindVertexArray(gVAO);
glBindBuffer(GL_ARRAY_BUFFER, gVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices.data(), GL_STATIC_DRAW);
glBindVertexArray(mesh.vao);
glBindBuffer(GL_ARRAY_BUFFER, mesh.vbo);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), static_cast<void *>(0));
glEnableVertexAttribArray(0);

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)(2 * sizeof(float)));
glEnableVertexAttribArray(1);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

m_mesh = mesh;
}

GLuint cae::OPGL::createGLShader(const GLenum type, const ShaderIRModule &data)
Expand Down
12 changes: 8 additions & 4 deletions plugins/Renderer/Vulkan/include/VULKN/VULKN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ namespace cae
[[nodiscard]] utl::PluginType getType() const override { return utl::PluginType::RENDERER; }
[[nodiscard]] utl::PluginPlatform getPlatform() const override { return utl::PluginPlatform::ALL; }

void initialize(const NativeWindowHandle &nativeWindowHandle) override {}
void setVSyncEnabled(bool enabled) override {}
void setClearColor(const Color &color) override {}

[[nodiscard]] bool isVSyncEnabled() const override { return false; }

void initialize(const NativeWindowHandle &nativeWindowHandle, const Color &clearColor) override {}
void createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
const ShaderIRModule &fragment) override
{
}
void draw(const WindowSize &windowSize) override {}
void draw(const WindowSize &windowSize, const ShaderID &shaderId) override {}
void createMesh(const std::vector<float> &vertices) override {}

void setVSyncEnabled(bool enabled) override {}
[[nodiscard]] bool isVSyncEnabled() const override { return false; }
}; // class VULKN

} // namespace cae
Loading