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
|
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
namespace ruby {
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
struct pVideoWGL : OpenGL {
|
2013-07-29 09:42:45 +00:00
|
|
|
HGLRC (APIENTRY* wglCreateContextAttribs)(HDC, HGLRC, const int*) = nullptr;
|
|
|
|
BOOL (APIENTRY* wglSwapInterval)(int) = nullptr;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
HDC display;
|
|
|
|
HGLRC wglcontext;
|
|
|
|
HWND window;
|
|
|
|
HINSTANCE glwindow;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
HWND handle;
|
|
|
|
bool synchronize;
|
|
|
|
unsigned filter;
|
2010-10-23 05:08:05 +00:00
|
|
|
string shader;
|
2010-08-09 13:28:56 +00:00
|
|
|
} settings;
|
|
|
|
|
|
|
|
bool cap(const string& name) {
|
|
|
|
if(name == Video::Handle) return true;
|
|
|
|
if(name == Video::Synchronize) return true;
|
|
|
|
if(name == Video::Filter) return true;
|
2010-09-29 00:05:36 +00:00
|
|
|
if(name == Video::Shader) return true;
|
2010-08-09 13:28:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
any get(const string& name) {
|
|
|
|
if(name == Video::Handle) return (uintptr_t)settings.handle;
|
|
|
|
if(name == Video::Synchronize) return settings.synchronize;
|
|
|
|
if(name == Video::Filter) return settings.filter;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set(const string& name, const any& value) {
|
|
|
|
if(name == Video::Handle) {
|
|
|
|
settings.handle = (HWND)any_cast<uintptr_t>(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name == Video::Synchronize) {
|
|
|
|
if(settings.synchronize != any_cast<bool>(value)) {
|
|
|
|
settings.synchronize = any_cast<bool>(value);
|
2010-10-23 05:08:05 +00:00
|
|
|
if(wglcontext) {
|
|
|
|
init();
|
2013-04-09 13:31:46 +00:00
|
|
|
OpenGL::shader(settings.shader);
|
|
|
|
if(settings.shader.empty()) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST;
|
2010-10-23 05:08:05 +00:00
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name == Video::Filter) {
|
|
|
|
settings.filter = any_cast<unsigned>(value);
|
2013-04-09 13:31:46 +00:00
|
|
|
if(settings.shader.empty()) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST;
|
2010-08-09 13:28:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-29 00:05:36 +00:00
|
|
|
if(name == Video::Shader) {
|
2010-10-23 05:08:05 +00:00
|
|
|
settings.shader = any_cast<const char*>(value);
|
2013-04-09 13:31:46 +00:00
|
|
|
OpenGL::shader(settings.shader);
|
|
|
|
if(settings.shader.empty()) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST;
|
2010-08-09 13:28:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
bool lock(uint32_t*& data, unsigned& pitch, unsigned width, unsigned height) {
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlock() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
OpenGL::clear();
|
|
|
|
SwapBuffers(display);
|
|
|
|
}
|
|
|
|
|
|
|
|
void refresh() {
|
|
|
|
RECT rc;
|
|
|
|
GetClientRect(settings.handle, &rc);
|
2013-04-09 13:31:46 +00:00
|
|
|
outputWidth = rc.right - rc.left, outputHeight = rc.bottom - rc.top;
|
|
|
|
OpenGL::refresh();
|
2010-08-09 13:28:56 +00:00
|
|
|
SwapBuffers(display);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init() {
|
|
|
|
term();
|
|
|
|
|
|
|
|
GLuint pixel_format;
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
|
|
|
|
display = GetDC(settings.handle);
|
|
|
|
pixel_format = ChoosePixelFormat(display, &pfd);
|
|
|
|
SetPixelFormat(display, pixel_format, &pfd);
|
|
|
|
|
|
|
|
wglcontext = wglCreateContext(display);
|
|
|
|
wglMakeCurrent(display, wglcontext);
|
|
|
|
|
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) {
|
|
|
|
int attributes[] = {
|
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
HGLRC context = wglCreateContextAttribs(display, 0, attributes);
|
|
|
|
if(context) {
|
|
|
|
wglMakeCurrent(NULL, NULL);
|
|
|
|
wglDeleteContext(wglcontext);
|
|
|
|
wglMakeCurrent(display, wglcontext = context);
|
|
|
|
}
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
if(wglSwapInterval) {
|
|
|
|
wglSwapInterval(settings.synchronize);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
OpenGL::init();
|
2010-08-09 13:28:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void term() {
|
|
|
|
OpenGL::term();
|
|
|
|
|
|
|
|
if(wglcontext) {
|
|
|
|
wglDeleteContext(wglcontext);
|
|
|
|
wglcontext = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
pVideoWGL() {
|
2010-08-09 13:28:56 +00:00
|
|
|
settings.handle = 0;
|
|
|
|
settings.synchronize = false;
|
|
|
|
settings.filter = 0;
|
|
|
|
|
|
|
|
window = 0;
|
|
|
|
wglcontext = 0;
|
|
|
|
glwindow = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~pVideoWGL() { term(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
DeclareVideo(WGL)
|
|
|
|
|
|
|
|
};
|