Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
opengl.h
1#ifndef OE_CORE_RENDERER_OPENGL_H
2#define OE_CORE_RENDERER_OPENGL_H
3
4#include "config.h" // IWYU pragma: keep (Required for general configuration)
5
6#include <cassert>
7#include <glue_chan/glue_chan.h>
8#include "../../util/non_copyable.h"
9#include <memory>
10
11namespace oe::render
12{
13 class ScreenQuad;
14}
15
16namespace oe::core
17{
18 class Window;
19
25 class OpenGL : public oe::util::NonCopyable // TODO 'OpenGL : public Renderer'
26 {
27 public:
33 OpenGL(Window* context_holder);
34
35 ~OpenGL()
36 {
37 _instance = nullptr;
38 }
39
48 void resizeViewport(const int32_t x, const int32_t y, const int32_t width, const int32_t height);
49
59 void scissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
60
66 std::shared_ptr<render::ScreenQuad> getScreenQuad()
67 {
68 assert(_instance != nullptr);
69
70 return _screen_quad;
71 }
72
79 {
80 return _instance;
81 }
82
88 static bool hasContext()
89 {
90 return _instance != nullptr;
91 }
92
98 const Window& getWindow() const noexcept
99 {
100 return *_context_holder;
101 }
102
109
110 #ifdef OXYGEN_ENGINE_OPENGL_DEBUG_OUTPUT
111 static void APIENTRY debugCallback(
112 GLenum source,
113 GLenum type,
114 uint32_t id,
115 GLenum severity,
116 GLsizei length,
117 const char* message,
118 const void* userParam
119 );
120 #endif
121
122 protected:
126 std::shared_ptr<render::ScreenQuad> _screen_quad;
127
128 private:
129 // Allow only one OpenGL instance per thread
130 thread_local static OpenGL* _instance;
131
132 Window* _context_holder = nullptr;
133 };
134}
135
136#endif
static OpenGL * getInstance()
Get the OpenGL instance related to this thread.
Definition opengl.h:78
void scissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
Define the scissor area Only allow draws in this area, other draw calls are discarded.
void resizeViewport(const int32_t x, const int32_t y, const int32_t width, const int32_t height)
Resize screen viewport.
std::shared_ptr< render::ScreenQuad > getScreenQuad()
Get a screen covering quad render mesh for screen rendering.
Definition opengl.h:66
OpenGL(Window *context_holder)
Constructor.
void bindContextToWindow(Window &window)
Bind the OpenGL to a Window.
static bool hasContext()
Check if this thread has an OpenGL context.
Definition opengl.h:88
std::shared_ptr< render::ScreenQuad > _screen_quad
Mesh covering whole screen mainly used for post-processing.
Definition opengl.h:126
const Window & getWindow() const noexcept
Get a reference to the Window bound to the context.
Definition opengl.h:98
Definition window.h:24
Definition screen_quad.h:11
Prevent class to be copied.
Definition non_copyable.h:12
Core functionality (windows, event handler, logger, ...).
Definition args.h:10
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures).
Definition opengl.h:12