-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrender_context.cpp
73 lines (61 loc) · 1.93 KB
/
render_context.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "render_context.hpp"
#include <bnb/effect_player/utility.hpp>
namespace bnb::oep
{
/* interfaces::render_context::create */
render_context_sptr bnb::oep::interfaces::render_context::create()
{
return std::make_shared<bnb::oep::render_context>();
}
/* render_context::render_context */
render_context::render_context()
{
// Init glfw for glfw_window
if (!glfwInit()) {
throw std::runtime_error("glfwInit() error");
}
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
m_context = glfwCreateWindow(1, 1, "", nullptr, nullptr);
if (!m_context) {
throw std::runtime_error("glfwCreateWindow() error");
}
}
/* render_context::~render_context */
render_context::~render_context()
{
glfwDestroyWindow(m_context);
}
/* render_context::create_context */
void render_context::create_context()
{
glfwMakeContextCurrent(m_context);
if (0 == gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
throw std::runtime_error("gladLoadGLLoader error");
}
bnb::utility::load_gl_functions();
}
/* render_context::activate */
void render_context::activate()
{
if (m_context) {
glfwMakeContextCurrent(m_context);
}
}
/* render_context::deactivate */
void render_context::deactivate()
{
glfwMakeContextCurrent(nullptr);
}
/* render_context::delete_context */
void render_context::delete_context()
{}
/* render_context::get_sharing_context */
void * render_context::get_sharing_context()
{
return m_context;
}
} /* namespace bnb::oep */