cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
OPGL.hpp
Go to the documentation of this file.
1///
2/// @file OPGL.hpp
3/// @brief This file contains the OPGL class declaration
4/// @namespace cae
5///
6
7#pragma once
8
10
12
13#include <memory>
14#include <unordered_map>
15
16namespace cae
17{
18
19 struct Mesh
20 {
21 GLuint vao = 0;
22 GLuint vbo = 0;
23 GLuint ebo = 0;
24 GLsizei vertexCount = 0;
25 };
26
27 ///
28 /// @class OPGL
29 /// @brief Class for the OpenGL plugin
30 /// @namespace cae
31 ///
32 class OPGL final : public ARenderer
33 {
34 public:
35 OPGL() = default;
36 ~OPGL() override = default;
37
38 OPGL(const OPGL &) = delete;
39 OPGL &operator=(const OPGL &) = delete;
40 OPGL(OPGL &&) = delete;
41 OPGL &operator=(OPGL &&) = delete;
42
43 [[nodiscard]] std::string getName() const override { return "OpenGL"; }
44 [[nodiscard]] utl::PluginType getType() const override { return utl::PluginType::RENDERER; }
45 [[nodiscard]] utl::PluginPlatform getPlatform() const override { return utl::PluginPlatform::ALL; }
46
47 void setVSyncEnabled(const bool enabled) override { m_context->setVSyncEnabled(enabled); }
48 void setClearColor(const Color &color) override
49 {
50 auto &gl = m_context->gl;
51 gl.ClearColor(color.r, color.g, color.b, color.a);
52 }
53
54 [[nodiscard]] bool isVSyncEnabled() const override { return m_context->isVSyncEnabled(); }
55
56 void initialize(const NativeWindowHandle &nativeWindowHandle, const Color &clearColor) override;
57 void createPipeline(const ShaderID &id, const ShaderIRModule &vertex,
58 const ShaderIRModule &fragment) override;
59 void draw(const WindowSize &windowSize, const ShaderID &shaderId, glm::mat4 mvp) override;
60 void createMesh(const std::vector<float> &vertices) override;
61
62 private:
63 std::unique_ptr<IContext> m_context;
64 std::unordered_map<ShaderID, GLuint> m_programs;
66
67 GLuint m_ubo;
68 static GLuint createGLShader(GLenum type, const ShaderIRModule &data, const GladGLContext &gl);
69
70 }; // class OPGL
71
72} // namespace cae
This file contains the Renderer abstract class.
This file contains the IContext interface.
Abstract class for renderer.
Definition ARenderer.hpp:20
Class for the OpenGL plugin.
Definition OPGL.hpp:33
utl::PluginType getType() const override
Get the type of the plugin.
Definition OPGL.hpp:44
std::unordered_map< ShaderID, GLuint > m_programs
Definition OPGL.hpp:64
void initialize(const NativeWindowHandle &nativeWindowHandle, const Color &clearColor) override
Initialize the renderer with a native window handle and clear color.
Definition opgl.cpp:15
std::string getName() const override
Get the name of the plugin.
Definition OPGL.hpp:43
OPGL & operator=(const OPGL &)=delete
utl::PluginPlatform getPlatform() const override
Get the handled platform of the plugin.
Definition OPGL.hpp:45
static GLuint createGLShader(GLenum type, const ShaderIRModule &data, const GladGLContext &gl)
Definition opgl.cpp:108
void draw(const WindowSize &windowSize, const ShaderID &shaderId, glm::mat4 mvp) override
Draw the scene using the specified shader and window size.
Definition opgl.cpp:38
void setVSyncEnabled(const bool enabled) override
Enable or disable VSync.
Definition OPGL.hpp:47
OPGL & operator=(OPGL &&)=delete
OPGL(OPGL &&)=delete
GLuint m_ubo
Definition OPGL.hpp:67
OPGL(const OPGL &)=delete
~OPGL() override=default
bool isVSyncEnabled() const override
Check if VSync is enabled.
Definition OPGL.hpp:54
void createMesh(const std::vector< float > &vertices) override
Create a mesh with the given vertex data.
Definition opgl.cpp:83
std::unique_ptr< IContext > m_context
Definition OPGL.hpp:63
void setClearColor(const Color &color) override
Set the clear color.
Definition OPGL.hpp:48
OPGL()=default
void createPipeline(const ShaderID &id, const ShaderIRModule &vertex, const ShaderIRModule &fragment) override
Create a rendering pipeline with vertex and fragment shaders.
Definition opgl.cpp:56
Mesh m_mesh
Definition OPGL.hpp:65
std::string ShaderID
PluginPlatform
Definition IPlugin.hpp:33
PluginType
Definition IPlugin.hpp:22
Struct for color.
Definition IRenderer.hpp:23
GLuint ebo
Definition OPGL.hpp:23
GLuint vbo
Definition OPGL.hpp:22
GLsizei vertexCount
Definition OPGL.hpp:24
GLuint vao
Definition OPGL.hpp:21
Struct for native window handle.
Definition IWindow.hpp:34
Struct for shader intermediate representation module.
Struct for window size.
Definition IWindow.hpp:23