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 "../../common.h"
5#include "../../lib/gl3w.h"
6#include "../../util/non_copyable.h"
7#include <memory>
8
9namespace oe::render
10{
11 class ScreenQuad;
12}
13
14namespace oe::core
15{
16 class Window;
17
23 class OpenGL : public oe::util::NonCopyable // TODO 'OpenGL : public Renderer'
24 {
25 public:
31 OpenGL(Window* context_holder);
32
33 ~OpenGL()
34 {
35 _instance = nullptr;
36 }
37
46 void resizeViewport(const int32_t x, const int32_t y, const int32_t width, const int32_t height);
47
57 void scissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
58
64 std::shared_ptr<render::ScreenQuad> getScreenQuad()
65 {
66 assert(_instance != nullptr);
67
68 return _screen_quad;
69 }
70
77 {
78 return _instance;
79 }
80
86 static bool hasContext()
87 {
88 return _instance != nullptr;
89 }
90
96 const Window& getWindow() const noexcept
97 {
98 return *_context_holder;
99 }
100
107
108 #ifdef OXYGEN_ENGINE_OPENGL_DEBUG_OUTPUT
109 static void APIENTRY debugCallback(
110 GLenum source,
111 GLenum type,
112 unsigned int id,
113 GLenum severity,
114 GLsizei length,
115 const char* message,
116 const void* userParam
117 );
118 #endif
119
120 protected:
124 std::shared_ptr<render::ScreenQuad> _screen_quad;
125
126 private:
127 // Allow only one OpenGL instance per thread
128 thread_local static OpenGL* _instance;
129
130 Window* _context_holder = nullptr;
131 };
132}
133
134#endif
OpenGL renderer.
Definition opengl.h:24
static OpenGL * getInstance()
Get the OpenGL instance related to this thread.
Definition opengl.h:76
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:64
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:86
std::shared_ptr< render::ScreenQuad > _screen_quad
Mesh covering whole screen mainly used for post-processing.
Definition opengl.h:124
const Window & getWindow() const noexcept
Get a reference to the Window bound to the context.
Definition opengl.h:96
Definition window.h:24
Definition screen_quad.h:10
Prevent class to be copied.
Definition non_copyable.h:12
Core functionality (windows, event handler, logger, ...)
Definition cursor.h:8
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10