File: BGL.cpp

package info (click to toggle)
dolphin-emu 2503%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 111,624 kB
  • sloc: cpp: 787,747; ansic: 217,914; xml: 31,400; python: 4,226; yacc: 3,985; javascript: 2,430; makefile: 777; asm: 726; sh: 281; pascal: 257; perl: 97; objc: 75
file content (95 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "Common/GL/GLInterface/BGL.h"

#include <GLView.h>
#include <Size.h>
#include <Window.h>

#include "Common/Assert.h"

BGLView* GLContextBGL::s_current = nullptr;

GLContextBGL::~GLContextBGL()
{
  if (!m_window)
    delete m_gl;
}

bool GLContextBGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
{
  m_window = static_cast<BWindow*>(wsi.render_window);

  m_gl = new BGLView(m_window ? m_window->Bounds() : BRect(), "GLContextBGL", B_FOLLOW_ALL_SIDES, 0,
                     BGL_RGB | BGL_DOUBLE | BGL_ALPHA);
  if (m_window)
    m_window->AddChild(m_gl);

  m_opengl_mode = Mode::OpenGL;

  m_gl->LockLooper();
  BRect size = m_gl->Frame();
  m_gl->UnlockLooper();

  m_backbuffer_width = size.IntegerWidth();
  m_backbuffer_height = size.IntegerHeight();

  MakeCurrent();

  return true;
}

bool GLContextBGL::IsHeadless() const
{
  return m_window == nullptr;
}

bool GLContextBGL::MakeCurrent()
{
  if (s_current)
    s_current->UnlockGL();
  m_gl->LockGL();
  s_current = m_gl;
  return true;
}

bool GLContextBGL::ClearCurrent()
{
  if (!s_current)
    return true;

  ASSERT(m_gl == s_current);
  s_current->UnlockGL();
  s_current = nullptr;
  return true;
}

void GLContextBGL::Swap()
{
  m_gl->SwapBuffers();
}

void GLContextBGL::Update()
{
  m_gl->LockLooper();
  BRect size = m_gl->Frame();
  if (m_backbuffer_width == size.IntegerWidth() && m_backbuffer_height == size.IntegerHeight())
  {
    m_gl->UnlockLooper();
    return;
  }

  ClearCurrent();
  m_gl->FrameResized(size.Width(), size.Height());
  MakeCurrent();
  m_gl->UnlockLooper();

  m_backbuffer_width = size.IntegerWidth();
  m_backbuffer_height = size.IntegerHeight();
}

void* GLContextBGL::GetFuncAddress(const std::string& name)
{
  return m_gl->GetGLProcAddress(name.c_str());
}