Files
bsnes/ruby/video/wgl.cpp
Tim Allen fbc58c70ae Update to v104r14 release.
byuu says:

Changelog:

  - Emulator::Interface::videoResolution() -\> VideoResolution renamed
    to videoInformation() -\> VideoInformation
  - added double VideoInformation::refreshRate
  - higan: added `binary := (application|library)` — set this to
    `library` to produce a dynamic link library
  - higan: removed `-march=native` for macOS application builds; and for
    all library builds
  - higan: removed `console` build flag; uncomment  `link += -mwindows`
    instead
  - nall/GNUmakefile: `macosx` platform renamed `macos`
      - still need to do this for nall/intrinsics.hpp
  - Game Gear: return region=NTSC as the only option, so that the system
    frequency is always set correctly
  - hiro/cocoa: fixed typo [Sintendo]
  - hiro/Windows: removed GetDpiForMonitor, as it's Windows 8+ only; DPI
    is no longer per-monitor aware
  - icarus: core Icarus class now has virtual functions for
    directory::create, <file::exists>, <file::copy>, <file::write>
  - icarus: Sufami Turbo can import save RAM files now
  - icarus: setting `ICARUS_LIBRARY` define will compile icarus without
    main(), GUI components
  - ruby/video/Direct3D: choose the current monitor instead of top-left
    monitor for fullscreen exclusive [Cydrak]
  - ruby/video/Direct3D: do not set `WS_EX_TOPMOST` on fullscreen
    exclusive window [Cydrak]
      - this isn't necessary for exclusive mode, and it just makes
        getting out of the application more difficult
2017-09-24 11:01:48 +10:00

132 lines
3.6 KiB
C++

#include "opengl/opengl.hpp"
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
struct VideoWGL : Video, OpenGL {
VideoWGL() { initialize(); }
~VideoWGL() { terminate(); }
auto ready() -> bool { return _ready; }
auto context() -> uintptr { return _context; }
auto blocking() -> bool { return _blocking; }
auto smooth() -> bool { return _smooth; }
auto shader() -> string { return _shader; }
auto setContext(uintptr context) -> bool {
if(_context == context) return true;
_context = context;
return initialize();
}
auto setBlocking(bool blocking) -> bool {
if(_blocking == blocking) return true;
_blocking = blocking;
if(wglSwapInterval) wglSwapInterval(_blocking);
return true;
}
auto setSmooth(bool smooth) -> bool {
if(_smooth == smooth) return true;
_smooth = smooth;
if(!_shader) OpenGL::filter = _smooth ? GL_LINEAR : GL_NEAREST;
return true;
}
auto setShader(string shader) -> bool {
if(_shader == shader) return true;
OpenGL::shader(_shader = shader);
if(!_shader) OpenGL::filter = _smooth ? GL_LINEAR : GL_NEAREST;
return true;
}
auto clear() -> void {
if(!ready()) return;
OpenGL::clear();
SwapBuffers(_display);
}
auto lock(uint32_t*& data, uint& pitch, uint width, uint height) -> bool {
if(!ready()) return false;
OpenGL::size(width, height);
return OpenGL::lock(data, pitch);
}
auto unlock() -> void {
if(!ready()) return;
}
auto output() -> void {
if(!ready()) return;
RECT rectangle;
GetClientRect((HWND)_context, &rectangle);
OpenGL::outputWidth = rectangle.right - rectangle.left;
OpenGL::outputHeight = rectangle.bottom - rectangle.top;
OpenGL::output();
SwapBuffers(_display);
}
private:
auto initialize() -> bool {
terminate();
if(!_context) return false;
PIXELFORMATDESCRIPTOR descriptor = {};
descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR);
descriptor.nVersion = 1;
descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
descriptor.iPixelType = PFD_TYPE_RGBA;
_display = GetDC((HWND)_context);
GLuint pixelFormat = ChoosePixelFormat(_display, &descriptor);
SetPixelFormat(_display, pixelFormat, &descriptor);
_wglContext = wglCreateContext(_display);
wglMakeCurrent(_display, _wglContext);
wglCreateContextAttribs = (HGLRC (APIENTRY*)(HDC, HGLRC, const int*))glGetProcAddress("wglCreateContextAttribsARB");
wglSwapInterval = (BOOL (APIENTRY*)(int))glGetProcAddress("wglSwapIntervalEXT");
if(wglCreateContextAttribs) {
int attributeList[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
0
};
HGLRC context = wglCreateContextAttribs(_display, 0, attributeList);
if(context) {
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(_wglContext);
wglMakeCurrent(_display, _wglContext = context);
}
}
if(wglSwapInterval) wglSwapInterval(_blocking);
return _ready = OpenGL::initialize();
}
auto terminate() -> void {
_ready = false;
OpenGL::terminate();
if(_wglContext) {
wglDeleteContext(_wglContext);
_wglContext = nullptr;
}
}
auto (APIENTRY* wglCreateContextAttribs)(HDC, HGLRC, const int*) -> HGLRC = nullptr;
auto (APIENTRY* wglSwapInterval)(int) -> BOOL = nullptr;
bool _ready = false;
uintptr _context = 0;
bool _blocking = false;
bool _smooth = true;
string _shader;
HDC _display = nullptr;
HGLRC _wglContext = nullptr;
HINSTANCE _glWindow = nullptr;
};