2013-04-09 13:31:46 +00:00
|
|
|
#include "opengl/opengl.hpp"
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
|
|
|
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
|
|
|
|
|
2019-07-07 09:44:09 +00:00
|
|
|
static LRESULT CALLBACK VideoOpenGL32_WindowProcedure(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
2019-09-06 14:54:58 +00:00
|
|
|
if(msg == WM_SYSKEYDOWN && wparam == VK_F4) return false;
|
2019-07-07 09:44:09 +00:00
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2018-08-05 09:00:15 +00:00
|
|
|
struct VideoWGL : VideoDriver, OpenGL {
|
|
|
|
VideoWGL& self = *this;
|
2019-07-07 09:44:09 +00:00
|
|
|
VideoWGL(Video& super) : VideoDriver(super) { construct(); }
|
|
|
|
~VideoWGL() { destruct(); }
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2018-08-05 09:00:15 +00:00
|
|
|
auto create() -> bool override {
|
|
|
|
return initialize();
|
|
|
|
}
|
|
|
|
|
2018-08-09 04:15:56 +00:00
|
|
|
auto driver() -> string override { return "OpenGL 3.2"; }
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto ready() -> bool override { return _ready; }
|
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
auto hasFullScreen() -> bool override { return true; }
|
|
|
|
auto hasMonitor() -> bool override { return true; }
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto hasContext() -> bool override { return true; }
|
|
|
|
auto hasBlocking() -> bool override { return true; }
|
|
|
|
auto hasFlush() -> bool override { return true; }
|
|
|
|
auto hasShader() -> bool override { return true; }
|
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
auto setFullScreen(bool fullScreen) -> bool override {
|
|
|
|
return initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto setMonitor(string monitor) -> bool override {
|
2019-07-07 09:44:09 +00:00
|
|
|
return initialize();
|
|
|
|
}
|
|
|
|
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto setContext(uintptr context) -> bool override {
|
2017-07-24 05:23:40 +00:00
|
|
|
return initialize();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto setBlocking(bool blocking) -> bool override {
|
|
|
|
if(wglSwapInterval) wglSwapInterval(blocking);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto setFlush(bool flush) -> bool override {
|
2017-07-24 05:23:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2018-08-21 03:17:12 +00:00
|
|
|
auto setShader(string shader) -> bool override {
|
2018-08-05 09:00:15 +00:00
|
|
|
OpenGL::setShader(self.shader);
|
2017-07-24 05:23:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2020-02-23 11:23:25 +00:00
|
|
|
auto focused() -> bool override {
|
|
|
|
if(self.fullScreen && self.exclusive) return true;
|
|
|
|
auto focused = GetFocus();
|
|
|
|
return _context == focused || IsChild(_context, focused);
|
|
|
|
}
|
|
|
|
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto clear() -> void override {
|
2017-07-24 05:23:40 +00:00
|
|
|
OpenGL::clear();
|
|
|
|
SwapBuffers(_display);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
auto size(uint& width, uint& height) -> void override {
|
|
|
|
if(self.fullScreen) {
|
|
|
|
width = _monitorWidth;
|
|
|
|
height = _monitorHeight;
|
|
|
|
} else {
|
|
|
|
RECT rectangle;
|
|
|
|
GetClientRect(_context, &rectangle);
|
|
|
|
width = rectangle.right - rectangle.left;
|
|
|
|
height = rectangle.bottom - rectangle.top;
|
|
|
|
}
|
2019-07-07 09:44:09 +00:00
|
|
|
}
|
|
|
|
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto acquire(uint32_t*& data, uint& pitch, uint width, uint height) -> bool override {
|
2013-04-09 13:31:46 +00:00
|
|
|
OpenGL::size(width, height);
|
2010-08-09 13:28:56 +00:00
|
|
|
return OpenGL::lock(data, pitch);
|
|
|
|
}
|
|
|
|
|
Update to 20180729 release.
byuu wrote:
Sigh ...
asio.hpp needs #include <nall/windows/registry.hpp>
[Since the last WIP, byuu also posted the following message. -Ed.]
ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.
I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.
Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.
I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.
I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 13:24:38 +00:00
|
|
|
auto release() -> void override {
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 09:44:09 +00:00
|
|
|
auto output(uint width, uint height) -> void override {
|
|
|
|
uint windowWidth, windowHeight;
|
|
|
|
size(windowWidth, windowHeight);
|
2019-08-16 10:44:16 +00:00
|
|
|
|
2019-07-07 09:44:09 +00:00
|
|
|
OpenGL::absoluteWidth = width;
|
|
|
|
OpenGL::absoluteHeight = height;
|
2019-08-16 10:44:16 +00:00
|
|
|
OpenGL::outputX = 0;
|
|
|
|
OpenGL::outputY = 0;
|
2019-07-07 09:44:09 +00:00
|
|
|
OpenGL::outputWidth = windowWidth;
|
|
|
|
OpenGL::outputHeight = windowHeight;
|
2017-07-24 05:23:40 +00:00
|
|
|
OpenGL::output();
|
2019-08-16 10:44:16 +00:00
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
SwapBuffers(_display);
|
2018-08-05 09:00:15 +00:00
|
|
|
if(self.flush) glFinish();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
private:
|
2019-07-07 09:44:09 +00:00
|
|
|
auto construct() -> void {
|
|
|
|
WNDCLASS windowClass{};
|
|
|
|
windowClass.cbClsExtra = 0;
|
|
|
|
windowClass.cbWndExtra = 0;
|
|
|
|
windowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
windowClass.hCursor = LoadCursor(0, IDC_ARROW);
|
|
|
|
windowClass.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
|
|
|
|
windowClass.hInstance = GetModuleHandle(0);
|
|
|
|
windowClass.lpfnWndProc = VideoOpenGL32_WindowProcedure;
|
|
|
|
windowClass.lpszClassName = L"VideoOpenGL32_Window";
|
|
|
|
windowClass.lpszMenuName = 0;
|
|
|
|
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
RegisterClass(&windowClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto destruct() -> void {
|
|
|
|
terminate();
|
|
|
|
}
|
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
auto initialize() -> bool {
|
|
|
|
terminate();
|
2019-08-16 10:44:16 +00:00
|
|
|
if(!self.fullScreen && !self.context) return false;
|
|
|
|
|
|
|
|
auto monitor = Video::monitor(self.monitor);
|
|
|
|
_monitorX = monitor.x;
|
|
|
|
_monitorY = monitor.y;
|
|
|
|
_monitorWidth = monitor.width;
|
|
|
|
_monitorHeight = monitor.height;
|
|
|
|
|
|
|
|
if(self.fullScreen) {
|
|
|
|
_context = _window = CreateWindowEx(WS_EX_TOPMOST, L"VideoOpenGL32_Window", L"", WS_VISIBLE | WS_POPUP,
|
|
|
|
_monitorX, _monitorY, _monitorWidth, _monitorHeight,
|
2019-07-07 09:44:09 +00:00
|
|
|
nullptr, nullptr, GetModuleHandle(0), nullptr);
|
|
|
|
} else {
|
|
|
|
_context = (HWND)self.context;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2019-07-07 09:44:09 +00:00
|
|
|
PIXELFORMATDESCRIPTOR descriptor{};
|
2017-07-24 05:23:40 +00:00
|
|
|
descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
descriptor.nVersion = 1;
|
|
|
|
descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
|
|
descriptor.iPixelType = PFD_TYPE_RGBA;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2019-07-07 09:44:09 +00:00
|
|
|
_display = GetDC(_context);
|
2017-07-24 05:23:40 +00:00
|
|
|
GLuint pixelFormat = ChoosePixelFormat(_display, &descriptor);
|
|
|
|
SetPixelFormat(_display, pixelFormat, &descriptor);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
_wglContext = wglCreateContext(_display);
|
|
|
|
wglMakeCurrent(_display, _wglContext);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
wglCreateContextAttribs = (HGLRC (APIENTRY*)(HDC, HGLRC, const int*))glGetProcAddress("wglCreateContextAttribsARB");
|
|
|
|
wglSwapInterval = (BOOL (APIENTRY*)(int))glGetProcAddress("wglSwapIntervalEXT");
|
|
|
|
|
|
|
|
if(wglCreateContextAttribs) {
|
2017-07-24 05:23:40 +00:00
|
|
|
int attributeList[] = {
|
2013-07-29 09:42:45 +00:00
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
|
|
|
0
|
|
|
|
};
|
2017-07-24 05:23:40 +00:00
|
|
|
HGLRC context = wglCreateContextAttribs(_display, 0, attributeList);
|
2013-07-29 09:42:45 +00:00
|
|
|
if(context) {
|
2017-07-09 02:23:17 +00:00
|
|
|
wglMakeCurrent(nullptr, nullptr);
|
2017-07-24 05:23:40 +00:00
|
|
|
wglDeleteContext(_wglContext);
|
|
|
|
wglMakeCurrent(_display, _wglContext = context);
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2018-08-05 09:00:15 +00:00
|
|
|
if(wglSwapInterval) wglSwapInterval(self.blocking);
|
2018-08-21 03:17:12 +00:00
|
|
|
return _ready = OpenGL::initialize(self.shader);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
auto terminate() -> void {
|
|
|
|
_ready = false;
|
|
|
|
OpenGL::terminate();
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2017-07-24 05:23:40 +00:00
|
|
|
if(_wglContext) {
|
|
|
|
wglDeleteContext(_wglContext);
|
|
|
|
_wglContext = nullptr;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2019-07-07 09:44:09 +00:00
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
if(_window) {
|
|
|
|
DestroyWindow(_window);
|
|
|
|
_window = nullptr;
|
2019-07-07 09:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_context = nullptr;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2017-07-24 05:23:40 +00:00
|
|
|
|
|
|
|
auto (APIENTRY* wglCreateContextAttribs)(HDC, HGLRC, const int*) -> HGLRC = nullptr;
|
|
|
|
auto (APIENTRY* wglSwapInterval)(int) -> BOOL = nullptr;
|
|
|
|
|
|
|
|
bool _ready = false;
|
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
int _monitorX = 0;
|
|
|
|
int _monitorY = 0;
|
|
|
|
int _monitorWidth = 0;
|
|
|
|
int _monitorHeight = 0;
|
2019-07-07 09:44:09 +00:00
|
|
|
|
2019-08-16 10:44:16 +00:00
|
|
|
HWND _window = nullptr;
|
2019-07-07 09:44:09 +00:00
|
|
|
HWND _context = nullptr;
|
2017-07-24 05:23:40 +00:00
|
|
|
HDC _display = nullptr;
|
|
|
|
HGLRC _wglContext = nullptr;
|
|
|
|
HINSTANCE _glWindow = nullptr;
|
2010-08-09 13:28:56 +00:00
|
|
|
};
|