Debian Codegraph @

Source/Core/Common/GL/GLInterface/BGL.cpp

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "Common/GL/GLInterface/BGL.h"
5
6 #include <GLView.h>
7 #include <Size.h>
8 #include <Window.h>
9
10 #include "Common/Assert.h"
11
12 BGLView* GLContextBGL::s_current = nullptr;
13
14 GLContextBGL::~GLContextBGL()
15 {
16 if (!m_window)
17 delete m_gl;
18 }
19
20 bool GLContextBGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
21 {
22 m_window = static_cast<BWindow*>(wsi.render_window);
23
24 m_gl = new BGLView(m_window ? m_window->Bounds() : BRect(), "GLContextBGL", B_FOLLOW_ALL_SIDES, 0,
25 BGL_RGB | BGL_DOUBLE | BGL_ALPHA);
26 if (m_window)
27 m_window->AddChild(m_gl);
28
29 m_opengl_mode = Mode::OpenGL;
30
31 m_gl->LockLooper();
32 BRect size = m_gl->Frame();
33 m_gl->UnlockLooper();
34
35 m_backbuffer_width = size.IntegerWidth();
36 m_backbuffer_height = size.IntegerHeight();
37
38 MakeCurrent();
39
40 return true;
41 }
42
43 bool GLContextBGL::IsHeadless() const
44 {
45 return m_window == nullptr;
46 }
47
48 bool GLContextBGL::MakeCurrent()
49 {
50 if (s_current)
51 s_current->UnlockGL();
52 m_gl->LockGL();
53 s_current = m_gl;
54 return true;
55 }
56
57 bool GLContextBGL::ClearCurrent()
58 {
59 if (!s_current)
60 return true;
61
62 ASSERT(m_gl == s_current);
63 s_current->UnlockGL();
64 s_current = nullptr;
65 return true;
66 }
67
68 void GLContextBGL::Swap()
69 {
70 m_gl->SwapBuffers();
71 }
72
73 void GLContextBGL::Update()
74 {
75 m_gl->LockLooper();
76 BRect size = m_gl->Frame();
77 if (m_backbuffer_width == size.IntegerWidth() && m_backbuffer_height == size.IntegerHeight())
78 {
79 m_gl->UnlockLooper();
80 return;
81 }
82
83 ClearCurrent();
84 m_gl->FrameResized(size.Width(), size.Height());
85 MakeCurrent();
86 m_gl->UnlockLooper();
87
88 m_backbuffer_width = size.IntegerWidth();
89 m_backbuffer_height = size.IntegerHeight();
90 }
91
92 void* GLContextBGL::GetFuncAddress(const std::string& name)
93 {
94 return m_gl->GetGLProcAddress(name.c_str());
95 }