GLX tweaks

This commit is contained in:
Jack Andersen 2015-10-27 15:47:55 -10:00
parent 55bf4bbdea
commit 3db5a7e211
9 changed files with 55 additions and 35 deletions

View File

@ -44,7 +44,7 @@ public:
};
virtual EPlatformType getPlatformType() const=0;
virtual void pump()=0;
virtual int run()=0;
virtual const SystemString& getUniqueName() const=0;
virtual const SystemString& getFriendlyName() const=0;
virtual const SystemString& getProcessName() const=0;

View File

@ -40,6 +40,7 @@ public:
virtual EPixelFormat getPixelFormat() const=0;
virtual void setPixelFormat(EPixelFormat pf)=0;
virtual void initializeContext()=0;
virtual void makeCurrent()=0;
};

View File

@ -10,7 +10,7 @@
#include <dbus/dbus.h>
#include <stdio.h>
DBusConnection* registerDBus(const char* appName, bool& isFirst)
DBusConnection* RegisterDBus(const char* appName, bool& isFirst)
{
isFirst = true;
DBusError err = {};

View File

@ -5,12 +5,12 @@
#include "boo/IApplication.hpp"
#include <dbus/dbus.h>
DBusConnection* registerDBus(const char* appName, bool& isFirst);
DBusConnection* RegisterDBus(const char* appName, bool& isFirst);
namespace boo
{
IWindow* _CWindowWaylandNew(const std::string& title);
IWindow* _WindowWaylandNew(const std::string& title);
class ApplicationWayland final : public IApplication
{
@ -46,7 +46,7 @@ public:
return PLAT_WAYLAND;
}
void pump()
int run()
{
}
@ -73,7 +73,7 @@ public:
IWindow* newWindow(const std::string& title)
{
return _CWindowWaylandNew(title);
return _WindowWaylandNew(title);
}
};

View File

@ -18,7 +18,7 @@
#include <GL/glxext.h>
#include <dbus/dbus.h>
DBusConnection* registerDBus(const char* appName, bool& isFirst);
DBusConnection* RegisterDBus(const char* appName, bool& isFirst);
#include <sys/param.h>
@ -31,7 +31,7 @@ PFNGLXWAITVIDEOSYNCSGIPROC FglXWaitVideoSyncSGI = nullptr;
int XCB_GLX_EVENT_BASE = 0;
int XINPUT_OPCODE = 0;
static xcb_window_t getWindowOfEvent(xcb_generic_event_t* event, bool& windowEvent)
static xcb_window_t GetWindowOfEvent(xcb_generic_event_t* event, bool& windowEvent)
{
switch (XCB_EVENT_RESPONSE_TYPE(event))
{
@ -122,7 +122,7 @@ static xcb_window_t getWindowOfEvent(xcb_generic_event_t* event, bool& windowEve
return 0;
}
IWindow* _CWindowXCBNew(const std::string& title, xcb_connection_t* conn);
IWindow* _WindowXCBNew(const std::string& title, xcb_connection_t* conn);
class ApplicationXCB final : public IApplication
{
@ -163,7 +163,7 @@ public:
{
/* DBus single instance registration */
bool isFirst;
m_dbus = registerDBus(uniqueName.c_str(), isFirst);
m_dbus = RegisterDBus(uniqueName.c_str(), isFirst);
if (m_singleInstance)
{
if (!isFirst)
@ -248,10 +248,10 @@ public:
return PLAT_XCB;
}
void pump()
int run()
{
if (!m_xcbConn)
return;
return 1;
xcb_generic_event_t* event;
fd_set fds;
@ -266,7 +266,7 @@ public:
if (event)
{
bool windowEvent;
xcb_window_t evWindow = getWindowOfEvent(event, windowEvent);
xcb_window_t evWindow = GetWindowOfEvent(event, windowEvent);
//fprintf(stderr, "EVENT %d\n", XCB_EVENT_RESPONSE_TYPE(event));
if (windowEvent)
{
@ -327,7 +327,7 @@ public:
IWindow* newWindow(const std::string& title)
{
IWindow* newWindow = _CWindowXCBNew(title, m_xcbConn);
IWindow* newWindow = _WindowXCBNew(title, m_xcbConn);
m_windows[(xcb_window_t)newWindow->getPlatformHandle()] = newWindow;
return newWindow;
}

View File

@ -52,6 +52,10 @@ public:
}
void makeCurrent()
{
}
};
IGraphicsContext* _GraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,

View File

@ -11,7 +11,7 @@ namespace boo
extern PFNGLXGETVIDEOSYNCSGIPROC FglXGetVideoSyncSGI;
extern PFNGLXWAITVIDEOSYNCSGIPROC FglXWaitVideoSyncSGI;
IGraphicsContext* _CGraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,
IGraphicsContext* _GraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
struct WindowWayland : IWindow
@ -99,7 +99,7 @@ struct WindowWayland : IWindow
};
IWindow* _CWindowWaylandNew(const std::string& title)
IWindow* _WindowWaylandNew(const std::string& title)
{
return new WindowWayland(title);
}

View File

@ -169,13 +169,13 @@ struct GraphicsContextXCB : IGraphicsContext
public:
IWindowCallback* m_callback;
GraphicsContextXCB(EGraphicsAPI api, IWindow* parentWindow, xcb_connection_t* conn, uint32_t& visualIdOut)
GraphicsContextXCB(EGraphicsAPI api, IWindow* parentWindow,
xcb_connection_t* conn, uint32_t& visualIdOut)
: m_api(api),
m_pf(PF_RGBA8),
m_parentWindow(parentWindow),
m_xcbConn(conn)
{
/* WTF freedesktop?? Fix this awful API and your nonexistant docs */
xcb_glx_get_fb_configs_reply_t* fbconfigs =
xcb_glx_get_fb_configs_reply(m_xcbConn, xcb_glx_get_fb_configs(m_xcbConn, 0), NULL);
@ -246,7 +246,10 @@ public:
~GraphicsContextXCB()
{
if (m_glxCtx)
xcb_glx_destroy_context(m_xcbConn, m_glxCtx);
if (m_glxWindow)
xcb_glx_delete_window(m_xcbConn, m_glxWindow);
}
void _setCallback(IWindowCallback* cb)
@ -277,6 +280,17 @@ public:
xcb_glx_create_window(m_xcbConn, 0, m_fbconfig,
m_parentWindow->getPlatformHandle(),
m_glxWindow, 0, NULL);
m_glxCtx = xcb_generate_id(m_xcbConn);
xcb_glx_create_context(m_xcbConn, m_glxCtx, m_visualid, 0, 0, 1);
}
void makeCurrent()
{
xcb_generic_error_t* err = nullptr;
xcb_glx_make_context_current_reply_t* reply =
xcb_glx_make_context_current_reply(m_xcbConn,
xcb_glx_make_context_current(m_xcbConn, 0, m_glxWindow, m_glxWindow, m_glxCtx), &err);
free(reply);
}
};
@ -285,6 +299,7 @@ struct WindowXCB : IWindow
{
xcb_connection_t* m_xcbConn;
IWindowCallback* m_callback;
xcb_colormap_t m_colormapId;
xcb_window_t m_windowId;
GraphicsContextXCB m_gfxCtx;
uint32_t m_visualId;
@ -316,9 +331,9 @@ public:
m_pixelFactor = screen->width_in_pixels / (float)screen->width_in_millimeters / REF_DPMM;
/* Create colormap */
xcb_colormap_t colormap = xcb_generate_id(m_xcbConn);
m_colormapId = xcb_generate_id(m_xcbConn);
xcb_create_colormap(m_xcbConn, XCB_COLORMAP_ALLOC_NONE,
colormap, screen->root, m_visualId);
m_colormapId, screen->root, m_visualId);
/* Create window */
int x, y, w, h;
@ -330,7 +345,7 @@ public:
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
colormap,
m_colormapId,
XCB_NONE
};
m_windowId = xcb_generate_id(conn);
@ -388,7 +403,7 @@ public:
strlen(c_title), c_title);
/* Initialize context */
xcb_map_window(m_xcbConn, m_windowId);
//xcb_map_window(m_xcbConn, m_windowId);
xcb_flush(m_xcbConn);
m_gfxCtx.initializeContext();
@ -396,6 +411,9 @@ public:
~WindowXCB()
{
xcb_unmap_window(m_xcbConn, m_windowId);
xcb_destroy_window(m_xcbConn, m_windowId);
xcb_free_colormap(m_xcbConn, m_colormapId);
APP->_deletedWindow(this);
}
@ -623,7 +641,7 @@ public:
{
int specialKey;
int modifierKey;
wchar_t charCode = translateKeysym(xcb_key_press_lookup_keysym(S_ATOMS->m_keySyms, ev, 0),
uint32_t charCode = translateKeysym(xcb_key_press_lookup_keysym(S_ATOMS->m_keySyms, ev, 0),
specialKey, modifierKey);
int modifierMask = translateModifiers(ev->state);
if (charCode)
@ -644,7 +662,7 @@ public:
{
int specialKey;
int modifierKey;
wchar_t charCode = translateKeysym(xcb_key_release_lookup_keysym(S_ATOMS->m_keySyms, ev, 0),
uint32_t charCode = translateKeysym(xcb_key_release_lookup_keysym(S_ATOMS->m_keySyms, ev, 0),
specialKey, modifierKey);
int modifierMask = translateModifiers(ev->state);
if (charCode)
@ -897,7 +915,7 @@ public:
};
IWindow* _CWindowXCBNew(const std::string& title, xcb_connection_t* conn)
IWindow* _WindowXCBNew(const std::string& title, xcb_connection_t* conn)
{
return new WindowXCB(title, conn);
}

View File

@ -210,11 +210,8 @@ int main(int argc, const char** argv)
std::unique_ptr<boo::IApplication> app =
ApplicationBootstrap(boo::IApplication::PLAT_AUTO,
appCb, _S("rwk"), _S("RWK"), argc, argv);
while (true)
{
app->pump();
}
int ret = app->run();
printf("IM DYING!!\n");
return 0;
return ret;
}