2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
#include "DolphinWX/GLInterface/GLX.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2013-12-30 13:22:50 +00:00
|
|
|
typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval);
|
2014-07-08 13:58:25 +00:00
|
|
|
static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
|
2013-12-30 13:22:50 +00:00
|
|
|
|
2013-01-24 16:31:08 +00:00
|
|
|
void cInterfaceGLX::SwapInterval(int Interval)
|
|
|
|
{
|
|
|
|
if (glXSwapIntervalSGI)
|
|
|
|
glXSwapIntervalSGI(Interval);
|
|
|
|
else
|
|
|
|
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
|
|
|
}
|
2014-03-17 23:17:12 +00:00
|
|
|
void* cInterfaceGLX::GetFuncAddress(const std::string& name)
|
2013-12-30 13:22:50 +00:00
|
|
|
{
|
|
|
|
return (void*)glXGetProcAddress((const GLubyte*)name.c_str());
|
|
|
|
}
|
2013-01-24 16:31:08 +00:00
|
|
|
|
2012-12-26 06:34:09 +00:00
|
|
|
void cInterfaceGLX::Swap()
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
glXSwapBuffers(dpy, win);
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create rendering window.
|
2014-02-17 04:51:41 +00:00
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2014-08-06 04:44:21 +00:00
|
|
|
bool cInterfaceGLX::Create(void *window_handle)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
|
|
|
int glxMajorVersion, glxMinorVersion;
|
|
|
|
|
|
|
|
// attributes for a single buffered visual in RGBA format with at least
|
2013-10-29 18:19:56 +00:00
|
|
|
// 8 bits per color
|
2012-12-17 21:01:52 +00:00
|
|
|
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
|
|
|
None};
|
|
|
|
|
|
|
|
// attributes for a double buffered visual in RGBA format with at least
|
2013-10-29 18:19:56 +00:00
|
|
|
// 8 bits per color
|
2012-12-17 21:01:52 +00:00
|
|
|
int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
|
|
|
|
GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
|
|
|
None };
|
|
|
|
|
|
|
|
int attrListDefault[] = {
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
None };
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
dpy = XOpenDisplay(nullptr);
|
|
|
|
int screen = DefaultScreen(dpy);
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
glXQueryVersion(dpy, &glxMajorVersion, &glxMinorVersion);
|
2012-12-17 21:01:52 +00:00
|
|
|
NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion);
|
|
|
|
|
|
|
|
// Get an appropriate visual
|
2014-08-09 13:49:45 +00:00
|
|
|
vi = glXChooseVisual(dpy, screen, attrListDbl);
|
|
|
|
if (vi == nullptr)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
vi = glXChooseVisual(dpy, screen, attrListSgl);
|
|
|
|
if (vi != nullptr)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "Only single buffered visual!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
vi = glXChooseVisual(dpy, screen, attrListDefault);
|
|
|
|
if (vi == nullptr)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "Could not choose visual (glXChooseVisual)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NOTICE_LOG(VIDEO, "Got double buffered visual!");
|
|
|
|
|
|
|
|
// Create a GLX context.
|
2014-08-09 13:49:45 +00:00
|
|
|
ctx = glXCreateContext(dpy, vi, nullptr, GL_TRUE);
|
|
|
|
if (!ctx)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
|
|
|
PanicAlert("Unable to create GLX context.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
XWindow.Initialize(dpy);
|
|
|
|
|
|
|
|
Window parent = (Window)window_handle;
|
2014-08-21 19:39:03 +00:00
|
|
|
|
|
|
|
XWindowAttributes attribs;
|
|
|
|
if (!XGetWindowAttributes(dpy, parent, &attribs))
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "Window attribute retrieval failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_backbuffer_width = attribs.width;
|
|
|
|
s_backbuffer_height = attribs.height;
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
win = XWindow.CreateXWindow(parent, vi);
|
2012-12-17 21:01:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cInterfaceGLX::MakeCurrent()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
bool success = glXMakeCurrent(dpy, win, ctx);
|
2014-02-24 11:45:02 +00:00
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
// load this function based on the current bound context
|
|
|
|
glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)GLInterface->GetFuncAddress("glXSwapIntervalSGI");
|
|
|
|
}
|
|
|
|
return success;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
2013-04-11 01:32:07 +00:00
|
|
|
|
|
|
|
bool cInterfaceGLX::ClearCurrent()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
return glXMakeCurrent(dpy, None, nullptr);
|
2013-04-11 01:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Close backend
|
|
|
|
void cInterfaceGLX::Shutdown()
|
|
|
|
{
|
2012-12-26 18:12:26 +00:00
|
|
|
XWindow.DestroyXWindow();
|
2014-08-09 13:49:45 +00:00
|
|
|
if (ctx)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
glXDestroyContext(dpy, ctx);
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
ctx = nullptr;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|