Better framebuffer config selection with sRGB.
This commit is contained in:
parent
ed6c852102
commit
414630ecfd
@ -27,22 +27,6 @@ static bool rk_error_occured = false;
|
|||||||
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
|
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
|
||||||
typedef GLXContext (*rk_CreateContextAttribsFunc)(Display *, GLXFBConfig, GLXContext, Bool, int const *);
|
typedef GLXContext (*rk_CreateContextAttribsFunc)(Display *, GLXFBConfig, GLXContext, Bool, int const *);
|
||||||
|
|
||||||
static int const rk_visual_attribs[] = {
|
|
||||||
GLX_CONFIG_CAVEAT, GLX_NONE,
|
|
||||||
GLX_X_RENDERABLE, True,
|
|
||||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
|
||||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
||||||
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
|
|
||||||
GLX_RED_SIZE, 8,
|
|
||||||
GLX_GREEN_SIZE, 8,
|
|
||||||
GLX_BLUE_SIZE, 8,
|
|
||||||
GLX_ALPHA_SIZE, 8,
|
|
||||||
GLX_DEPTH_SIZE, 24,
|
|
||||||
GLX_STENCIL_SIZE, 8,
|
|
||||||
GLX_DOUBLEBUFFER, True,
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
static int const rk_context_attribs[] = {
|
static int const rk_context_attribs[] = {
|
||||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
|
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
|
||||||
@ -60,7 +44,7 @@ static void rk_glx_printf(
|
|||||||
printf("[GLX] %s\n", messsage);
|
printf("[GLX] %s\n", messsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rk_extension_supported(
|
bool rk_extension_supported(
|
||||||
char const * extensions,
|
char const * extensions,
|
||||||
char const * extension) {
|
char const * extension) {
|
||||||
char const * where = strchr(extension, ' ');
|
char const * where = strchr(extension, ' ');
|
||||||
@ -142,40 +126,77 @@ rk_display_t rk_create_display(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fb_count = 0;
|
int fb_count = 0;
|
||||||
GLXFBConfig * const fb_configs = glXChooseFBConfig(
|
GLXFBConfig * fb_configs;
|
||||||
display->display, DefaultScreen(display->display), rk_visual_attribs, &fb_count);
|
bool const srgb_ext = rk_extension_supported(glx_exts, "GLX_EXT_framebuffer_sRGB");
|
||||||
|
if (srgb_ext) {
|
||||||
|
rk_glx_printf("GLX_EXT_framebuffer_sRGB extension supported.");
|
||||||
|
int const visual_attribs[] = { GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, True, GLX_DOUBLEBUFFER, True, None };
|
||||||
|
fb_configs = glXChooseFBConfig(display->display, DefaultScreen(display->display), visual_attribs, &fb_count);
|
||||||
|
} else {
|
||||||
|
int const visual_attribs[] = { GLX_DOUBLEBUFFER, True, None };
|
||||||
|
fb_configs = glXChooseFBConfig(display->display, DefaultScreen(display->display), visual_attribs, &fb_count);
|
||||||
|
}
|
||||||
printf("[GLX] Found %d framebuffer configs.\n", fb_count);
|
printf("[GLX] Found %d framebuffer configs.\n", fb_count);
|
||||||
if (!fb_configs || !fb_count) {
|
if (!fb_configs || !fb_count) {
|
||||||
rk_glx_printf("Failed to retrieve framebuffer configs.");
|
rk_glx_printf("Failed to retrieve framebuffer configs.");
|
||||||
rk_destroy_display(reinterpret_cast<rk_display_t>(display));
|
rk_destroy_display(reinterpret_cast<rk_display_t>(display));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
GLXFBConfig const fb_config = fb_configs[0];
|
GLXFBConfig fb_config;
|
||||||
XFree(fb_configs);
|
int rs = 0;
|
||||||
int red_size = 0;
|
int gs = 0;
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_RED_SIZE, &red_size);
|
int bs = 0;
|
||||||
int green_size = 0;
|
int as = 0;
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_GREEN_SIZE, &green_size);
|
int ds = 0;
|
||||||
int blue_size = 0;
|
int ss = 0;
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_BLUE_SIZE, &blue_size);
|
for (int fb_index = 0; fb_index < fb_count; ++fb_index) {
|
||||||
int alpha_size = 0;
|
GLXFBConfig _config = fb_configs[fb_index];
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_ALPHA_SIZE, &alpha_size);
|
int _rs = 0;
|
||||||
int depth_size = 0;
|
int _gs = 0;
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_DEPTH_SIZE, &depth_size);
|
int _bs = 0;
|
||||||
int stencil_size = 0;
|
int _as = 0;
|
||||||
glXGetFBConfigAttrib(display->display, fb_config, GLX_STENCIL_SIZE, &stencil_size);
|
int _ds = 0;
|
||||||
printf("[GLX] Select framebuffer config R%dG%dB%dA%d D%dS%d.\n",
|
int _ss = 0;
|
||||||
red_size, green_size, blue_size, alpha_size, depth_size, stencil_size);
|
glXGetFBConfigAttrib(display->display, _config, GLX_RED_SIZE, &_rs);
|
||||||
|
glXGetFBConfigAttrib(display->display, _config, GLX_GREEN_SIZE, &_gs);
|
||||||
|
glXGetFBConfigAttrib(display->display, _config, GLX_BLUE_SIZE, &_bs);
|
||||||
|
glXGetFBConfigAttrib(display->display, _config, GLX_ALPHA_SIZE, &_as);
|
||||||
|
glXGetFBConfigAttrib(display->display, _config, GLX_DEPTH_SIZE, &_ds);
|
||||||
|
glXGetFBConfigAttrib(display->display, _config, GLX_STENCIL_SIZE, &_ss);
|
||||||
|
if ((_rs >= rs && _gs >= gs && _bs >= bs && _as >= as && _ds >= ds && _ss >= ss) &&
|
||||||
|
(_rs > rs || _gs > gs || _bs > bs || _as > as || _ds > ds || _ss > ss)) {
|
||||||
|
XVisualInfo * const vi = glXGetVisualFromFBConfig(display->display, _config);
|
||||||
|
if (vi) {
|
||||||
|
XFree(vi);
|
||||||
|
rs = _rs;
|
||||||
|
gs = _gs;
|
||||||
|
bs = _bs;
|
||||||
|
as = _as;
|
||||||
|
ds = _ds;
|
||||||
|
ss = _ss;
|
||||||
|
fb_config = _config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("[RK] Select framebuffer config R%dG%dB%dA%d D%dS%d.\n", rs, gs, bs, as, ds, ss);
|
||||||
|
if (srgb_ext) {
|
||||||
|
int srgb = 0;
|
||||||
|
glXGetFBConfigAttrib(display->display, fb_config, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, &srgb);
|
||||||
|
if (srgb) {
|
||||||
|
rk_glx_printf("sRGB framebuffer selected.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XVisualInfo * const vi = glXGetVisualFromFBConfig(display->display, fb_config);
|
XVisualInfo * const vi = glXGetVisualFromFBConfig(display->display, fb_config);
|
||||||
display->colormap = XCreateColormap(
|
Window root = RootWindow(display->display, vi->screen);
|
||||||
display->display, RootWindow(display->display, vi->screen), vi->visual, AllocNone);
|
display->colormap = XCreateColormap(display->display, root, vi->visual, AllocNone);
|
||||||
XSetWindowAttributes swa;
|
XSetWindowAttributes win_attributes;
|
||||||
swa.colormap = display->colormap;
|
win_attributes.colormap = display->colormap;
|
||||||
swa.event_mask = RK_EVENTS_MASK;
|
win_attributes.event_mask = RK_EVENTS_MASK;
|
||||||
display->window = XCreateWindow(display->display, RootWindow(display->display, vi->screen),
|
display->window = XCreateWindow(display->display, root,
|
||||||
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
|
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &win_attributes);
|
||||||
XFree(vi);
|
XFree(vi);
|
||||||
|
XFree(fb_configs);
|
||||||
if (!display->window) {
|
if (!display->window) {
|
||||||
rk_x11_printf("Failed to create window.");
|
rk_x11_printf("Failed to create window.");
|
||||||
rk_destroy_display(reinterpret_cast<rk_display_t>(display));
|
rk_destroy_display(reinterpret_cast<rk_display_t>(display));
|
||||||
@ -199,6 +220,12 @@ rk_display_t rk_create_display(
|
|||||||
rk_glx_printf("Warning: Rendering context is indirect.");
|
rk_glx_printf("Warning: Rendering context is indirect.");
|
||||||
}
|
}
|
||||||
glXMakeCurrent(display->display, display->window, display->context);
|
glXMakeCurrent(display->display, display->window, display->context);
|
||||||
|
if (srgb_ext) {
|
||||||
|
glEnable(GL_FRAMEBUFFER_SRGB_EXT);
|
||||||
|
if (glIsEnabled(GL_FRAMEBUFFER_SRGB_EXT)) {
|
||||||
|
rk_glx_printf("sRGB framebuffer enabled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return reinterpret_cast<rk_display_t>(display);
|
return reinterpret_cast<rk_display_t>(display);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,10 @@ struct rk_display_glx : public rk_display_x11 {
|
|||||||
|
|
||||||
typedef void (*rk_func_ptr)();
|
typedef void (*rk_func_ptr)();
|
||||||
|
|
||||||
|
extern bool rk_extension_supported(
|
||||||
|
char const * extensions,
|
||||||
|
char const * extension);
|
||||||
|
|
||||||
extern rk_func_ptr rk_resolve_extension(
|
extern rk_func_ptr rk_resolve_extension(
|
||||||
char const * extensions,
|
char const * extensions,
|
||||||
char const * extension,
|
char const * extension,
|
||||||
|
Loading…
Reference in New Issue
Block a user