added new clang format and fixed window creation endless loops + implemented missing functions
parent
04d4e2a02f
commit
c43377a5a1
|
@ -0,0 +1,121 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 4
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
UseTab: ForContinuationAndIndentation
|
||||
...
|
||||
|
|
@ -5,110 +5,109 @@
|
|||
#include "window_xcb.h"
|
||||
|
||||
namespace gin {
|
||||
XcbDevice::XcbDevice(::Display* display, int screen,
|
||||
xcb_connection_t* xcb_connection, xcb_screen_t* xcb_screen,
|
||||
Own<InputStream>&& an)
|
||||
: display{display},
|
||||
screen{screen},
|
||||
xcb_connection{xcb_connection},
|
||||
xcb_screen{xcb_screen},
|
||||
async_notifier{std::move(an)},
|
||||
async_conveyor{async_notifier->readReady()
|
||||
.then([this]() { handleEvents(); })
|
||||
.buffer(1)} {}
|
||||
XcbDevice::XcbDevice(::Display *display, int screen,
|
||||
xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen,
|
||||
Own<InputStream> &&an)
|
||||
: display{display}, screen{screen}, xcb_connection{xcb_connection},
|
||||
xcb_screen{xcb_screen}, async_notifier{std::move(an)},
|
||||
async_conveyor{async_notifier->readReady()
|
||||
.then([this]() { handleEvents(); })
|
||||
.buffer(1)} {}
|
||||
|
||||
XcbDevice::~XcbDevice() {
|
||||
if (display) {
|
||||
xcb_flush(xcb_connection);
|
||||
::XCloseDisplay(display);
|
||||
}
|
||||
if (display) {
|
||||
xcb_flush(xcb_connection);
|
||||
::XCloseDisplay(display);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbDevice::windowDestroyed(xcb_window_t window_id) {
|
||||
windows.erase(window_id);
|
||||
windows.erase(window_id);
|
||||
}
|
||||
|
||||
Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode& video_mode,
|
||||
std::string_view title_view,
|
||||
int visual_id) {
|
||||
assert(xcb_screen);
|
||||
assert(xcb_connection);
|
||||
void XcbDevice::handleEvents() {}
|
||||
|
||||
xcb_colormap_t xcb_colormap = xcb_generate_id(xcb_connection);
|
||||
xcb_window_t xcb_window = xcb_generate_id(xcb_connection);
|
||||
Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
|
||||
std::string_view title_view,
|
||||
int visual_id) {
|
||||
assert(xcb_screen);
|
||||
assert(xcb_connection);
|
||||
|
||||
xcb_create_colormap(xcb_connection, XCB_COLORMAP_ALLOC_NONE, xcb_colormap,
|
||||
xcb_screen->root, visual_id);
|
||||
xcb_colormap_t xcb_colormap = xcb_generate_id(xcb_connection);
|
||||
xcb_window_t xcb_window = xcb_generate_id(xcb_connection);
|
||||
|
||||
uint32_t eventmask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
||||
uint32_t valuelist[] = {eventmask, xcb_colormap, 0};
|
||||
uint32_t valuemask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
|
||||
xcb_create_colormap(xcb_connection, XCB_COLORMAP_ALLOC_NONE, xcb_colormap,
|
||||
xcb_screen->root, visual_id);
|
||||
|
||||
xcb_create_window(xcb_connection, XCB_COPY_FROM_PARENT, xcb_window,
|
||||
xcb_screen->root, 0, 0, video_mode.width, video_mode.height,
|
||||
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visual_id, valuemask,
|
||||
valuelist);
|
||||
uint32_t eventmask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
||||
uint32_t valuelist[] = {eventmask, xcb_colormap, 0};
|
||||
uint32_t valuemask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
|
||||
|
||||
xcb_change_property(xcb_connection, XCB_PROP_MODE_REPLACE, xcb_window,
|
||||
XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, title_view.size(),
|
||||
title_view.data());
|
||||
xcb_create_window(xcb_connection, XCB_COPY_FROM_PARENT, xcb_window,
|
||||
xcb_screen->root, 0, 0, video_mode.width,
|
||||
video_mode.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
||||
visual_id, valuemask, valuelist);
|
||||
|
||||
xcb_flush(xcb_connection);
|
||||
xcb_change_property(xcb_connection, XCB_PROP_MODE_REPLACE, xcb_window,
|
||||
XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, title_view.size(),
|
||||
title_view.data());
|
||||
|
||||
return heap<XcbWindow>(*this, xcb_window, xcb_colormap, video_mode,
|
||||
title_view);
|
||||
xcb_flush(xcb_connection);
|
||||
|
||||
return heap<XcbWindow>(*this, xcb_window, xcb_colormap, video_mode,
|
||||
title_view);
|
||||
}
|
||||
|
||||
Own<Window> XcbDevice::createWindow(const VideoMode& video_mode,
|
||||
std::string_view title_view) {
|
||||
assert(xcb_screen);
|
||||
return createXcbWindow(video_mode, title_view, xcb_screen->root_visual);
|
||||
Own<Window> XcbDevice::createWindow(const VideoMode &video_mode,
|
||||
std::string_view title_view) {
|
||||
assert(xcb_screen);
|
||||
return createXcbWindow(video_mode, title_view, xcb_screen->root_visual);
|
||||
}
|
||||
|
||||
void XcbDevice::flush() {
|
||||
assert(xcb_connection);
|
||||
xcb_flush(xcb_connection);
|
||||
assert(xcb_connection);
|
||||
xcb_flush(xcb_connection);
|
||||
}
|
||||
|
||||
Own<XcbDevice> createXcbDevice(AsyncIoProvider& provider) {
|
||||
::Display* display = ::XOpenDisplay(nullptr);
|
||||
if (!display) {
|
||||
/// @todo log errors
|
||||
return nullptr;
|
||||
}
|
||||
Own<XcbDevice> createXcbDevice(AsyncIoProvider &provider) {
|
||||
::Display *display = ::XOpenDisplay(nullptr);
|
||||
if (!display) {
|
||||
/// @todo log errors
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int screen = ::XDefaultScreen(display);
|
||||
int screen = ::XDefaultScreen(display);
|
||||
|
||||
xcb_connection_t* xcb_connection = ::XGetXCBConnection(display);
|
||||
if (!xcb_connection) {
|
||||
/// @todo log errors
|
||||
::XCloseDisplay(display);
|
||||
return nullptr;
|
||||
}
|
||||
xcb_connection_t *xcb_connection = ::XGetXCBConnection(display);
|
||||
if (!xcb_connection) {
|
||||
/// @todo log errors
|
||||
::XCloseDisplay(display);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int fd = xcb_get_file_descriptor(xcb_connection);
|
||||
int fd = xcb_get_file_descriptor(xcb_connection);
|
||||
|
||||
Own<InputStream> fd_wrapped = provider.wrapInputFd(fd);
|
||||
if (!fd_wrapped) {
|
||||
::XCloseDisplay(display);
|
||||
return nullptr;
|
||||
}
|
||||
Own<InputStream> fd_wrapped = provider.wrapInputFd(fd);
|
||||
if (!fd_wrapped) {
|
||||
::XCloseDisplay(display);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
::XSetEventQueueOwner(display, XCBOwnsEventQueue);
|
||||
::XSetEventQueueOwner(display, XCBOwnsEventQueue);
|
||||
|
||||
xcb_screen_iterator_t screen_iter =
|
||||
xcb_setup_roots_iterator(xcb_get_setup(xcb_connection));
|
||||
for (int screen_i = screen; screen_iter.rem && screen_i > 0;
|
||||
--screen_i, xcb_screen_next(&screen_iter))
|
||||
;
|
||||
xcb_screen_iterator_t screen_iter =
|
||||
xcb_setup_roots_iterator(xcb_get_setup(xcb_connection));
|
||||
for (int screen_i = screen; screen_iter.rem && screen_i > 0;
|
||||
--screen_i, xcb_screen_next(&screen_iter))
|
||||
;
|
||||
|
||||
xcb_screen_t* xcb_screen = screen_iter.data;
|
||||
xcb_screen_t *xcb_screen = screen_iter.data;
|
||||
|
||||
return heap<XcbDevice>(display, screen, xcb_connection, xcb_screen,
|
||||
std::move(fd_wrapped));
|
||||
return heap<XcbDevice>(display, screen, xcb_connection, xcb_screen,
|
||||
std::move(fd_wrapped));
|
||||
}
|
||||
|
||||
Own<Device> createDevice(AsyncIoProvider& provider) {
|
||||
return createXcbDevice(provider);
|
||||
Own<Device> createDevice(AsyncIoProvider &provider) {
|
||||
return createXcbDevice(provider);
|
||||
}
|
||||
} // namespace gin
|
||||
} // namespace gin
|
|
@ -12,33 +12,33 @@
|
|||
|
||||
namespace gin {
|
||||
class XcbDevice final : public Device {
|
||||
public:
|
||||
::Display* display;
|
||||
int screen;
|
||||
public:
|
||||
::Display *display;
|
||||
int screen;
|
||||
|
||||
xcb_connection_t* xcb_connection;
|
||||
xcb_screen_t* xcb_screen;
|
||||
xcb_connection_t *xcb_connection;
|
||||
xcb_screen_t *xcb_screen;
|
||||
|
||||
Own<InputStream> async_notifier;
|
||||
Conveyor<void> async_conveyor;
|
||||
Own<InputStream> async_notifier;
|
||||
Conveyor<void> async_conveyor;
|
||||
|
||||
std::map<xcb_window_t, XcbWindow*> windows;
|
||||
std::map<xcb_window_t, XcbWindow *> windows;
|
||||
|
||||
public:
|
||||
XcbDevice(::Display* display, int screen, xcb_connection_t* xcb_connection,
|
||||
xcb_screen_t* xcb_screen, Own<InputStream>&& an);
|
||||
~XcbDevice();
|
||||
public:
|
||||
XcbDevice(::Display *display, int screen, xcb_connection_t *xcb_connection,
|
||||
xcb_screen_t *xcb_screen, Own<InputStream> &&an);
|
||||
~XcbDevice();
|
||||
|
||||
void windowDestroyed(xcb_window_t window_id);
|
||||
void handleEvents();
|
||||
void windowDestroyed(xcb_window_t window_id);
|
||||
void handleEvents();
|
||||
|
||||
Own<XcbWindow> createXcbWindow(const VideoMode& mode,
|
||||
std::string_view title_view, int visual_id);
|
||||
Own<Window> createWindow(const VideoMode& video_mode,
|
||||
std::string_view title_view) override;
|
||||
Own<XcbWindow> createXcbWindow(const VideoMode &mode,
|
||||
std::string_view title_view, int visual_id);
|
||||
Own<Window> createWindow(const VideoMode &video_mode,
|
||||
std::string_view title_view) override;
|
||||
|
||||
void flush() override;
|
||||
void flush() override;
|
||||
};
|
||||
|
||||
Own<XcbDevice> createXcbDevice(AsyncIoProvider& provider);
|
||||
} // namespace gin
|
||||
Own<XcbDevice> createXcbDevice(AsyncIoProvider &provider);
|
||||
} // namespace gin
|
||||
|
|
|
@ -7,178 +7,195 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "device_xcb.h"
|
||||
#include "../device_xcb.h"
|
||||
#include "gl_window_xcb.h"
|
||||
|
||||
namespace gin {
|
||||
namespace {
|
||||
GlxLibraryExtensions glxLibraryExtensions(const char* extension_string) {
|
||||
std::string_view extensions_view{extension_string};
|
||||
std::set<std::string_view> extensions;
|
||||
while (1) {
|
||||
size_t n = extensions_view.find_first_not_of(' ');
|
||||
if (n != extensions_view.npos && n < extensions_view.size()) {
|
||||
std::string_view sub_glx_ext = extensions_view.substr(0, n);
|
||||
extensions.insert(sub_glx_ext);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
GlxLibraryExtensions glxLibraryExtensions(const char *extension_string) {
|
||||
std::string_view extensions_view{extension_string};
|
||||
std::set<std::string_view> extensions;
|
||||
while (1) {
|
||||
size_t n = extensions_view.find_first_of(' ');
|
||||
if (n != extensions_view.npos && n < extensions_view.size()) {
|
||||
std::string_view sub_glx_ext = extensions_view.substr(0, n);
|
||||
extensions.insert(sub_glx_ext);
|
||||
extensions_view.remove_prefix(n + 1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto find = extensions.find("glXCreateContextAttribsARB");
|
||||
GLXContext (*glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext,
|
||||
Bool, const int*) = nullptr;
|
||||
if (find != extensions.end()) {
|
||||
glXCreateContextAttribsARB = reinterpret_cast<GLXContext (*)(
|
||||
Display*, GLXFBConfig, GLXContext, Bool, const int*)>(
|
||||
glXGetProcAddress(
|
||||
reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB")));
|
||||
}
|
||||
return {extensions_view, glXCreateContextAttribsARB};
|
||||
auto find = extensions.find("GLX_ARB_create_context");
|
||||
GLXContext (*glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext,
|
||||
Bool, const int *) = nullptr;
|
||||
if (find != extensions.end()) {
|
||||
glXCreateContextAttribsARB = reinterpret_cast<GLXContext (*)(
|
||||
Display *, GLXFBConfig, GLXContext, Bool, const int *)>(
|
||||
glXGetProcAddress(reinterpret_cast<const GLubyte *>(
|
||||
"glXCreateContextAttribsARB")));
|
||||
}
|
||||
return {extensions_view, glXCreateContextAttribsARB};
|
||||
}
|
||||
int translateRenderTypeSetting(GlSettings::RenderType cmp) {
|
||||
switch (cmp) {
|
||||
case GlSettings::RenderType::RGBA:
|
||||
return GLX_RGBA_BIT;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
switch (cmp) {
|
||||
case GlSettings::RenderType::RGBA:
|
||||
return GLX_RGBA_BIT;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int translateDrawableTypeSetting(GlSettings::DrawableType cmp) {
|
||||
int i = 0;
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::WindowBit)) {
|
||||
i |= static_cast<int32_t>(GLX_WINDOW_BIT);
|
||||
}
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::PixMapBit)) {
|
||||
i |= static_cast<int32_t>(GLX_PIXMAP_BIT);
|
||||
}
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::PBufferBit)) {
|
||||
i |= static_cast<int32_t>(GLX_PBUFFER_BIT);
|
||||
}
|
||||
return i;
|
||||
int i = 0;
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::WindowBit)) {
|
||||
i |= static_cast<int32_t>(GLX_WINDOW_BIT);
|
||||
}
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::PixMapBit)) {
|
||||
i |= static_cast<int32_t>(GLX_PIXMAP_BIT);
|
||||
}
|
||||
if (static_cast<int32_t>(cmp) &
|
||||
static_cast<int32_t>(GlSettings::DrawableType::PBufferBit)) {
|
||||
i |= static_cast<int32_t>(GLX_PBUFFER_BIT);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
XcbGlContext::XcbGlContext(const GlxLibraryExtensions& ext_lib,
|
||||
Own<XcbDevice>&& dev, int visual_id,
|
||||
GLXContext context, GLXFBConfig fb_config)
|
||||
: ext_lib{ext_lib},
|
||||
device{std::move(dev)},
|
||||
visual_id{visual_id},
|
||||
context{context},
|
||||
fb_config{fb_config} {}
|
||||
XcbGlContext::XcbGlContext(const GlxLibraryExtensions &ext_lib,
|
||||
Own<XcbDevice> &&dev, int visual_id,
|
||||
GLXContext context, GLXFBConfig fb_config)
|
||||
: ext_lib{ext_lib}, device{std::move(dev)}, visual_id{visual_id},
|
||||
context{context}, fb_config{fb_config} {}
|
||||
|
||||
XcbGlContext::~XcbGlContext() {
|
||||
assert(device);
|
||||
assert(device->display);
|
||||
if (context) {
|
||||
::glXMakeContextCurrent(device->display, None, None, nullptr);
|
||||
::glXDestroyContext(device->display, context);
|
||||
}
|
||||
device->flush();
|
||||
assert(device);
|
||||
assert(device->display);
|
||||
if (context) {
|
||||
::glXMakeContextCurrent(device->display, None, None, nullptr);
|
||||
::glXDestroyContext(device->display, context);
|
||||
}
|
||||
device->flush();
|
||||
}
|
||||
|
||||
void XcbGlContext::bind() {}
|
||||
|
||||
Own<GlWindow> XcbGlContext::createWindow(const VideoMode& video_mode,
|
||||
std::string_view title_view) {
|
||||
return nullptr;
|
||||
Own<GlWindow> XcbGlContext::createWindow(const VideoMode &video_mode,
|
||||
std::string_view title_view) {
|
||||
assert(device);
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
gin::Own<XcbWindow> window =
|
||||
device->createXcbWindow(video_mode, title_view, visual_id);
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
::GLXWindow glx_window = glXCreateWindow(device->display, fb_config,
|
||||
window->xcb_window, nullptr);
|
||||
|
||||
return gin::heap<XcbGlWindow>(std::move(window), *this, glx_window);
|
||||
}
|
||||
|
||||
void XcbGlContext::flush() {}
|
||||
|
||||
Own<GlContext> createGlContext(AsyncIoProvider& provider,
|
||||
const GlSettings& settings) {
|
||||
Own<XcbDevice> device = createXcbDevice(provider);
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate all attributes
|
||||
*/
|
||||
std::vector<int> attributes;
|
||||
attributes.reserve(33);
|
||||
|
||||
attributes.push_back(GLX_X_RENDERABLE);
|
||||
attributes.push_back(settings.renderable ? True : False);
|
||||
|
||||
attributes.push_back(GLX_RENDER_TYPE);
|
||||
attributes.push_back(translateRenderTypeSetting(settings.render_type));
|
||||
|
||||
attributes.push_back(GLX_RED_SIZE);
|
||||
attributes.push_back(settings.red_bits);
|
||||
|
||||
attributes.push_back(GLX_GREEN_SIZE);
|
||||
attributes.push_back(settings.green_bits);
|
||||
|
||||
attributes.push_back(GLX_BLUE_SIZE);
|
||||
attributes.push_back(settings.blue_bits);
|
||||
|
||||
attributes.push_back(GLX_ALPHA_SIZE);
|
||||
attributes.push_back(settings.alpha_bits);
|
||||
|
||||
attributes.push_back(GLX_DEPTH_SIZE);
|
||||
attributes.push_back(settings.depth_bits);
|
||||
|
||||
attributes.push_back(GLX_STENCIL_SIZE);
|
||||
attributes.push_back(settings.stencil_bits);
|
||||
|
||||
attributes.push_back(GLX_DOUBLEBUFFER);
|
||||
attributes.push_back(settings.double_buffer ? True : False);
|
||||
|
||||
attributes.push_back(GLX_DRAWABLE_TYPE);
|
||||
attributes.push_back(translateDrawableTypeSetting(settings.drawable_type));
|
||||
|
||||
attributes.push_back(GLX_X_VISUAL_TYPE);
|
||||
attributes.push_back(GLX_TRUE_COLOR);
|
||||
|
||||
attributes.push_back(None);
|
||||
|
||||
int num_fb_configs = 0;
|
||||
|
||||
GlxLibraryExtensions lib_ext = glxLibraryExtensions(
|
||||
glXQueryExtensionsString(device->display, device->screen));
|
||||
|
||||
GLXFBConfig* fb_configs = glXChooseFBConfig(device->display, device->screen,
|
||||
&attributes[0], &num_fb_configs);
|
||||
if (!fb_configs || num_fb_configs == 0) {
|
||||
/// @todo log errors
|
||||
return nullptr;
|
||||
}
|
||||
::GLXFBConfig fb_config = fb_configs[0];
|
||||
::XFree(fb_configs);
|
||||
|
||||
::GLXContext context;
|
||||
|
||||
if (lib_ext.glXCreateContextAttribsARB) {
|
||||
std::vector<int> glx_attribs;
|
||||
glx_attribs.reserve(11);
|
||||
|
||||
glx_attribs.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB);
|
||||
glx_attribs.push_back(settings.gl_major);
|
||||
glx_attribs.push_back(GLX_CONTEXT_MINOR_VERSION_ARB);
|
||||
glx_attribs.push_back(settings.gl_minor);
|
||||
glx_attribs.push_back(GLX_CONTEXT_PROFILE_MASK_ARB);
|
||||
glx_attribs.push_back(settings.core_profile
|
||||
? GLX_CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
: GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
|
||||
glx_attribs.push_back(None);
|
||||
|
||||
context = lib_ext.glXCreateContextAttribsARB(device->display, fb_config,
|
||||
NULL, True, &glx_attribs[0]);
|
||||
if (!context) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int visual_id = 0;
|
||||
glXGetFBConfigAttrib(device->display, fb_config, GLX_VISUAL_ID, &visual_id);
|
||||
return heap<XcbGlContext>(lib_ext, std::move(device), visual_id, context,
|
||||
fb_config);
|
||||
void XcbGlContext::flush() {
|
||||
assert(device);
|
||||
if (device) {
|
||||
device->flush();
|
||||
}
|
||||
}
|
||||
} // namespace gin
|
||||
|
||||
Own<GlContext> createGlContext(AsyncIoProvider &provider,
|
||||
const GlSettings &settings) {
|
||||
Own<XcbDevice> device = createXcbDevice(provider);
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate all attributes
|
||||
*/
|
||||
std::vector<int> attributes;
|
||||
attributes.reserve(33);
|
||||
|
||||
attributes.push_back(GLX_X_RENDERABLE);
|
||||
attributes.push_back(settings.renderable ? True : False);
|
||||
|
||||
attributes.push_back(GLX_RENDER_TYPE);
|
||||
attributes.push_back(translateRenderTypeSetting(settings.render_type));
|
||||
|
||||
attributes.push_back(GLX_RED_SIZE);
|
||||
attributes.push_back(settings.red_bits);
|
||||
|
||||
attributes.push_back(GLX_GREEN_SIZE);
|
||||
attributes.push_back(settings.green_bits);
|
||||
|
||||
attributes.push_back(GLX_BLUE_SIZE);
|
||||
attributes.push_back(settings.blue_bits);
|
||||
|
||||
attributes.push_back(GLX_ALPHA_SIZE);
|
||||
attributes.push_back(settings.alpha_bits);
|
||||
|
||||
attributes.push_back(GLX_DEPTH_SIZE);
|
||||
attributes.push_back(settings.depth_bits);
|
||||
|
||||
attributes.push_back(GLX_STENCIL_SIZE);
|
||||
attributes.push_back(settings.stencil_bits);
|
||||
|
||||
attributes.push_back(GLX_DOUBLEBUFFER);
|
||||
attributes.push_back(settings.double_buffer ? True : False);
|
||||
|
||||
attributes.push_back(GLX_DRAWABLE_TYPE);
|
||||
attributes.push_back(translateDrawableTypeSetting(settings.drawable_type));
|
||||
|
||||
attributes.push_back(GLX_X_VISUAL_TYPE);
|
||||
attributes.push_back(GLX_TRUE_COLOR);
|
||||
|
||||
attributes.push_back(None);
|
||||
|
||||
int num_fb_configs = 0;
|
||||
|
||||
GlxLibraryExtensions lib_ext = glxLibraryExtensions(
|
||||
glXQueryExtensionsString(device->display, device->screen));
|
||||
|
||||
GLXFBConfig *fb_configs = glXChooseFBConfig(
|
||||
device->display, device->screen, &attributes[0], &num_fb_configs);
|
||||
if (!fb_configs || num_fb_configs == 0) {
|
||||
/// @todo log errors
|
||||
return nullptr;
|
||||
}
|
||||
::GLXFBConfig fb_config = fb_configs[0];
|
||||
::XFree(fb_configs);
|
||||
|
||||
::GLXContext context;
|
||||
|
||||
if (lib_ext.glXCreateContextAttribsARB) {
|
||||
std::vector<int> glx_attribs;
|
||||
glx_attribs.reserve(11);
|
||||
|
||||
glx_attribs.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB);
|
||||
glx_attribs.push_back(settings.gl_major);
|
||||
glx_attribs.push_back(GLX_CONTEXT_MINOR_VERSION_ARB);
|
||||
glx_attribs.push_back(settings.gl_minor);
|
||||
glx_attribs.push_back(GLX_CONTEXT_PROFILE_MASK_ARB);
|
||||
glx_attribs.push_back(settings.core_profile
|
||||
? GLX_CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
: GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
|
||||
glx_attribs.push_back(None);
|
||||
|
||||
context = lib_ext.glXCreateContextAttribsARB(
|
||||
device->display, fb_config, NULL, True, &glx_attribs[0]);
|
||||
if (!context) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int visual_id = 0;
|
||||
glXGetFBConfigAttrib(device->display, fb_config, GLX_VISUAL_ID, &visual_id);
|
||||
return heap<XcbGlContext>(lib_ext, std::move(device), visual_id, context,
|
||||
fb_config);
|
||||
}
|
||||
} // namespace gin
|
||||
|
|
|
@ -9,30 +9,30 @@
|
|||
|
||||
namespace gin {
|
||||
struct GlxLibraryExtensions {
|
||||
public:
|
||||
std::string_view raw_extension_string;
|
||||
public:
|
||||
std::string_view raw_extension_string;
|
||||
|
||||
GLXContext (*glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext,
|
||||
Bool, const int*) = nullptr;
|
||||
GLXContext (*glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext,
|
||||
Bool, const int *) = nullptr;
|
||||
};
|
||||
|
||||
class XcbDevice;
|
||||
class XcbGlContext final : public GlContext {
|
||||
private:
|
||||
GlxLibraryExtensions ext_lib;
|
||||
Own<XcbDevice> device;
|
||||
int visual_id;
|
||||
GLXContext context;
|
||||
GLXFBConfig fb_config;
|
||||
public:
|
||||
GlxLibraryExtensions ext_lib;
|
||||
Own<XcbDevice> device;
|
||||
int visual_id;
|
||||
GLXContext context;
|
||||
GLXFBConfig fb_config;
|
||||
|
||||
public:
|
||||
XcbGlContext(const GlxLibraryExtensions&, Own<XcbDevice>&&, int, GLXContext,
|
||||
GLXFBConfig);
|
||||
~XcbGlContext();
|
||||
public:
|
||||
XcbGlContext(const GlxLibraryExtensions &, Own<XcbDevice> &&, int,
|
||||
GLXContext, GLXFBConfig);
|
||||
~XcbGlContext();
|
||||
|
||||
void bind() override;
|
||||
Own<GlWindow> createWindow(const VideoMode&, std::string_view) override;
|
||||
void bind() override;
|
||||
Own<GlWindow> createWindow(const VideoMode &, std::string_view) override;
|
||||
|
||||
void flush() override;
|
||||
void flush() override;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -1,5 +1,32 @@
|
|||
#include "gl_window_xcb.h"
|
||||
|
||||
#include "window_xcb.h"
|
||||
#include "gl_context_xcb.h"
|
||||
|
||||
namespace gin {}
|
||||
#include "../device_xcb.h"
|
||||
#include "../window_xcb.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gin {
|
||||
XcbGlWindow::XcbGlWindow(Own<XcbWindow> &&win, XcbGlContext &ctx,
|
||||
::GLXWindow glx_win)
|
||||
: window{std::move(win)}, context{ctx}, glx_window{glx_win} {}
|
||||
|
||||
XcbGlWindow::~XcbGlWindow() {
|
||||
assert(context.device);
|
||||
if (context.device) {
|
||||
glXDestroyWindow(context.device->display, glx_window);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbGlWindow::bind() {}
|
||||
|
||||
void XcbGlWindow::show() {
|
||||
assert(window);
|
||||
if (window) {
|
||||
window->show();
|
||||
}
|
||||
}
|
||||
|
||||
void XcbGlWindow::swap() {}
|
||||
} // namespace gin
|
|
@ -9,14 +9,18 @@ namespace gin {
|
|||
class XcbWindow;
|
||||
class XcbGlContext;
|
||||
class XcbGlWindow final : public GlWindow {
|
||||
public:
|
||||
Own<XcbWindow> window;
|
||||
XcbGlContext& context;
|
||||
public:
|
||||
Own<XcbWindow> window;
|
||||
XcbGlContext &context;
|
||||
|
||||
::GLXWindow glx_window;
|
||||
::GLXWindow glx_window;
|
||||
|
||||
public:
|
||||
XcbGlWindow(Own<XcbWindow>&&, XcbGlContext&, ::GLXWindow);
|
||||
~XcbGlWindow();
|
||||
public:
|
||||
XcbGlWindow(Own<XcbWindow> &&, XcbGlContext &, ::GLXWindow);
|
||||
~XcbGlWindow();
|
||||
|
||||
void bind() override;
|
||||
void swap() override;
|
||||
void show() override;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
|
@ -5,32 +5,29 @@
|
|||
#include "device_xcb.h"
|
||||
|
||||
namespace gin {
|
||||
XcbWindow::XcbWindow(XcbDevice& device, xcb_window_t xcb_window,
|
||||
xcb_colormap_t xcb_colormap, const VideoMode& video_mode,
|
||||
std::string_view title_view)
|
||||
: device{device},
|
||||
xcb_window{xcb_window},
|
||||
xcb_colormap{xcb_colormap},
|
||||
video_mode{video_mode},
|
||||
window_title{title_view} {}
|
||||
XcbWindow::XcbWindow(XcbDevice &device, xcb_window_t xcb_window,
|
||||
xcb_colormap_t xcb_colormap, const VideoMode &video_mode,
|
||||
std::string_view title_view)
|
||||
: device{device}, xcb_window{xcb_window}, xcb_colormap{xcb_colormap},
|
||||
video_mode{video_mode}, window_title{title_view} {}
|
||||
|
||||
XcbWindow::~XcbWindow() {
|
||||
device.windowDestroyed(xcb_window);
|
||||
xcb_destroy_window(device.xcb_connection, xcb_window);
|
||||
device.flush();
|
||||
device.windowDestroyed(xcb_window);
|
||||
xcb_destroy_window(device.xcb_connection, xcb_window);
|
||||
device.flush();
|
||||
}
|
||||
|
||||
void XcbWindow::show() {
|
||||
assert(device.xcb_connection);
|
||||
xcb_map_window(device.xcb_connection, xcb_window);
|
||||
assert(device.xcb_connection);
|
||||
xcb_map_window(device.xcb_connection, xcb_window);
|
||||
}
|
||||
|
||||
void XcbWindow::hide() {
|
||||
assert(device.xcb_connection);
|
||||
xcb_unmap_window(device.xcb_connection, xcb_window);
|
||||
assert(device.xcb_connection);
|
||||
xcb_unmap_window(device.xcb_connection, xcb_window);
|
||||
}
|
||||
|
||||
const VideoMode& XcbWindow::videoMode() const { return video_mode; }
|
||||
const VideoMode &XcbWindow::videoMode() const { return video_mode; }
|
||||
|
||||
const std::string_view XcbWindow::title() const { return window_title; }
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -11,25 +11,25 @@
|
|||
namespace gin {
|
||||
class XcbDevice;
|
||||
class XcbWindow final : public Window {
|
||||
public:
|
||||
XcbDevice& device;
|
||||
public:
|
||||
XcbDevice &device;
|
||||
|
||||
xcb_window_t xcb_window;
|
||||
xcb_colormap_t xcb_colormap;
|
||||
xcb_window_t xcb_window;
|
||||
xcb_colormap_t xcb_colormap;
|
||||
|
||||
VideoMode video_mode;
|
||||
std::string window_title;
|
||||
VideoMode video_mode;
|
||||
std::string window_title;
|
||||
|
||||
public:
|
||||
XcbWindow(XcbDevice& device, xcb_window_t xcb_window,
|
||||
xcb_colormap_t xcb_colormap, const VideoMode& video_mode,
|
||||
std::string_view title_view);
|
||||
~XcbWindow();
|
||||
public:
|
||||
XcbWindow(XcbDevice &device, xcb_window_t xcb_window,
|
||||
xcb_colormap_t xcb_colormap, const VideoMode &video_mode,
|
||||
std::string_view title_view);
|
||||
~XcbWindow();
|
||||
|
||||
void show() override;
|
||||
void hide() override;
|
||||
void show() override;
|
||||
void hide() override;
|
||||
|
||||
const VideoMode& videoMode() const override;
|
||||
const std::string_view title() const override;
|
||||
const VideoMode &videoMode() const override;
|
||||
const std::string_view title() const override;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
|
@ -8,14 +8,14 @@
|
|||
|
||||
namespace gin {
|
||||
class Device {
|
||||
public:
|
||||
virtual ~Device() = default;
|
||||
public:
|
||||
virtual ~Device() = default;
|
||||
|
||||
virtual Own<Window> createWindow(const VideoMode& mode,
|
||||
std::string_view title_view) = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual Own<Window> createWindow(const VideoMode &mode,
|
||||
std::string_view title_view) = 0;
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
class AsyncIoProvider;
|
||||
Own<Device> createDevice(AsyncIoProvider& provider);
|
||||
} // namespace gin
|
||||
Own<Device> createDevice(AsyncIoProvider &provider);
|
||||
} // namespace gin
|
||||
|
|
|
@ -8,55 +8,55 @@
|
|||
|
||||
namespace gin {
|
||||
class GlSettings {
|
||||
public:
|
||||
uint8_t gl_major = 3;
|
||||
uint8_t gl_minor = 3;
|
||||
public:
|
||||
uint8_t gl_major = 3;
|
||||
uint8_t gl_minor = 3;
|
||||
|
||||
enum class RenderType : int32_t { RGBA };
|
||||
enum class RenderType : int32_t { RGBA };
|
||||
|
||||
RenderType render_type = RenderType::RGBA;
|
||||
RenderType render_type = RenderType::RGBA;
|
||||
|
||||
bool renderable = true;
|
||||
bool renderable = true;
|
||||
|
||||
// gl drawable
|
||||
bool window_type = true;
|
||||
// gl drawable
|
||||
bool window_type = true;
|
||||
|
||||
// Pix and PBuffer are currently ignored.
|
||||
// Pix and PBuffer are currently ignored.
|
||||
|
||||
/// @hint don't change this unless you want to change the static cast in
|
||||
/// glcontext-xcb.cpp and other occurences
|
||||
/// Alternatively implement bitwise operations & and |
|
||||
enum class DrawableType : int32_t {
|
||||
WindowBit = 0x01,
|
||||
PixMapBit = 0x02,
|
||||
PBufferBit = 0x04
|
||||
};
|
||||
DrawableType drawable_type = DrawableType::WindowBit;
|
||||
/// @hint don't change this unless you want to change the static cast in
|
||||
/// glcontext-xcb.cpp and other occurences
|
||||
/// Alternatively implement bitwise operations & and |
|
||||
enum class DrawableType : int32_t {
|
||||
WindowBit = 0x01,
|
||||
PixMapBit = 0x02,
|
||||
PBufferBit = 0x04
|
||||
};
|
||||
DrawableType drawable_type = DrawableType::WindowBit;
|
||||
|
||||
bool double_buffer = true;
|
||||
bool double_buffer = true;
|
||||
|
||||
int red_bits = 8;
|
||||
int green_bits = 8;
|
||||
int blue_bits = 8;
|
||||
int alpha_bits = 8;
|
||||
int red_bits = 8;
|
||||
int green_bits = 8;
|
||||
int blue_bits = 8;
|
||||
int alpha_bits = 8;
|
||||
|
||||
int depth_bits = 24;
|
||||
int depth_bits = 24;
|
||||
|
||||
int stencil_bits = 8;
|
||||
int stencil_bits = 8;
|
||||
|
||||
bool core_profile = true;
|
||||
bool core_profile = true;
|
||||
};
|
||||
|
||||
class GlContext {
|
||||
public:
|
||||
virtual ~GlContext() = default;
|
||||
public:
|
||||
virtual ~GlContext() = default;
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual Own<GlWindow> createWindow(const VideoMode&, std::string_view) = 0;
|
||||
virtual void bind() = 0;
|
||||
virtual Own<GlWindow> createWindow(const VideoMode &, std::string_view) = 0;
|
||||
|
||||
virtual void flush() = 0;
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
class AsyncIoProvider;
|
||||
Own<GlContext> createGlContext(AsyncIoProvider&, const GlSettings&);
|
||||
} // namespace gin
|
||||
Own<GlContext> createGlContext(AsyncIoProvider &, const GlSettings &);
|
||||
} // namespace gin
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "video_mode.h"
|
||||
#include "../video_mode.h"
|
||||
|
||||
namespace gin {
|
||||
class GlWindow {
|
||||
public:
|
||||
virtual ~GlWindow() = default;
|
||||
public:
|
||||
virtual ~GlWindow() = default;
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual void show() = 0;
|
||||
virtual void swap() = 0;
|
||||
virtual void bind() = 0;
|
||||
virtual void show() = 0;
|
||||
virtual void swap() = 0;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
namespace gin {
|
||||
class VideoMode {
|
||||
public:
|
||||
size_t height = 128;
|
||||
size_t width = 128;
|
||||
public:
|
||||
size_t height = 128;
|
||||
size_t width = 128;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
|
||||
namespace gin {
|
||||
class Window {
|
||||
public:
|
||||
virtual ~Window() = default;
|
||||
public:
|
||||
virtual ~Window() = default;
|
||||
|
||||
virtual void show() = 0;
|
||||
virtual void hide() = 0;
|
||||
virtual void show() = 0;
|
||||
virtual void hide() = 0;
|
||||
|
||||
virtual const VideoMode& videoMode() const = 0;
|
||||
virtual const std::string_view title() const = 0;
|
||||
virtual const VideoMode &videoMode() const = 0;
|
||||
virtual const std::string_view title() const = 0;
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
Loading…
Reference in New Issue