blob: d2055060bd64a0bbaf9138055261234aa0bc0633 (
plain) (
blame)
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
|
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
//============================================================
//
// sdlglcontext.h - SDL-specific GL context
//
// SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================
#ifndef MAME_RENDER_SDLGLCONTEXT_H
#define MAME_RENDER_SDLGLCONTEXT_H
#pragma once
#include "modules/opengl/osd_opengl.h"
#include "strformat.h"
#include <SDL2/SDL.h>
#include <string>
class sdl_gl_context : public osd_gl_context
{
public:
sdl_gl_context(SDL_Window *window) : m_context(0), m_window(window)
{
m_context = SDL_GL_CreateContext(window);
if (!m_context)
{
try { m_error = util::string_format("OpenGL not supported on this driver: %s", SDL_GetError()); }
catch (...) { m_error.clear(); }
}
}
virtual ~sdl_gl_context()
{
if (m_context)
SDL_GL_DeleteContext(m_context);
}
virtual explicit operator bool() const override
{
return bool(m_context);
}
virtual void make_current() override
{
SDL_GL_MakeCurrent(m_window, m_context);
}
virtual bool set_swap_interval(const int swap) override
{
return 0 == SDL_GL_SetSwapInterval(swap);
}
virtual const char *last_error_message() override
{
if (!m_error.empty())
return m_error.c_str();
else
return nullptr;
}
virtual void *get_proc_address(const char *proc) override
{
return SDL_GL_GetProcAddress(proc);
}
virtual void swap_buffer() override
{
SDL_GL_SwapWindow(m_window);
}
private:
SDL_GLContext m_context;
SDL_Window *const m_window;
std::string m_error;
};
#endif // MAME_RENDER_SDLGLCONTEXT_H
|