64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
#include "XcbGlWindowInterface.h"
|
|
|
|
#include "OpenGlInterface.h"
|
|
#include "XcbGlInterface.h"
|
|
#include "FileLogger.h"
|
|
|
|
#include <GL/gl.h>
|
|
|
|
XcbGlWindowInterface::XcbGlWindowInterface(XcbGlInterface* glInterface)
|
|
: mGlInterface(glInterface),
|
|
mDrawable(),
|
|
mWindow()
|
|
{
|
|
|
|
}
|
|
|
|
XcbGlWindowInterface::~XcbGlWindowInterface()
|
|
{
|
|
if (mWindow)
|
|
{
|
|
destroyWindow();
|
|
}
|
|
}
|
|
|
|
void XcbGlWindowInterface::draw()
|
|
{
|
|
OpenGlInterface::draw(nullptr);
|
|
swapBuffers();
|
|
}
|
|
|
|
void XcbGlWindowInterface::swapBuffers()
|
|
{
|
|
glXSwapBuffers(mGlInterface->getDisplay(), mDrawable);
|
|
}
|
|
|
|
bool XcbGlWindowInterface::initialize(xcb_window_t window)
|
|
{
|
|
if (mWindow)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/* Create GLX Window */
|
|
mWindow = glXCreateWindow(mGlInterface->getDisplay(), mGlInterface->getConfig(), window, 0);
|
|
if (!mWindow)
|
|
{
|
|
MLOG_ERROR("glXCreateWindow failed");
|
|
return false;
|
|
}
|
|
mDrawable = mWindow;
|
|
|
|
/* make OpenGL context current */
|
|
if (!glXMakeContextCurrent(mGlInterface->getDisplay(), mDrawable, mDrawable, mGlInterface->getContext()))
|
|
{
|
|
MLOG_ERROR("glXMakeContextCurrent failed");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void XcbGlWindowInterface::destroyWindow()
|
|
{
|
|
glXDestroyWindow(mGlInterface->getDisplay(), mWindow);
|
|
}
|