Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Mar 26, 2024
1 parent 20ddb00 commit 6fbce6c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/ruisapp/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ struct window_params {
utki::flags<buffer> buffers = false;

// version 0.0 means default version
utki::version_duplet graphics_api_version = {0, 0};
utki::version_duplet graphics_api_version = { //
.major = 0,
.minor = 0
};

window_params(r4::vector2<unsigned> dims) :
dims(dims)
Expand Down
63 changes: 38 additions & 25 deletions src/ruisapp/glue/linux/glue_x11.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ struct window_wrapper : public utki::destructable {
}

#ifdef RUISAPP_RENDER_OPENGL
auto graphics_api_version = [&ver = wp.graphics_api_version]() {
if (ver.to_uint32_t() == 0) {
// default OpenGL version is 2.0
return utki::version_duplet{
.major = 2, //
.minor = 0
};
}
return ver;
}();

{
int glx_ver_major = 0;
int glx_ver_minor = 0;
Expand Down Expand Up @@ -351,6 +362,17 @@ struct window_wrapper : public utki::destructable {
best_fb_config = fbc[best_fb_config_index];
}
#elif defined(RUISAPP_RENDER_OPENGLES)
auto graphics_api_version = [&ver = wp.graphics_api_version]() {
if (ver.to_uint32_t() == 0) {
// default OpenGL ES version is 2.0
return utki::version_duplet{
.major = 2, //
.minor = 0
};
}
return ver;
}();

// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
this->egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (this->egl_display == EGL_NO_DISPLAY) {
Expand All @@ -368,24 +390,22 @@ struct window_wrapper : public utki::destructable {

EGLConfig egl_config = nullptr;
{
// TODO: allow stencil and depth configuration etc. via window_params
// Here specify the attributes of the desired configuration.
// Below, we select an EGLConfig with at least 8 bits per color
// component compatible with on-screen windows.
const std::array<EGLint, 15> attribs = {
const std::array<EGLint, 17> attribs = {
EGL_SURFACE_TYPE,
EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE,
[&wp]() {
const auto& ver = wp.graphics_api_version;
[&ver = graphics_api_version]() {
switch (ver.to_uint32_t()) {
default:
throw std::logic_error(utki::cat("unknown OpenGL ES version requested: ", ver.major, '.', ver.minor));
case 0: // default version
[[fallthrough]];
case utki::version_duplet{2, 0}.to_uint32_t():
throw std::logic_error(
utki::cat("unknown OpenGL ES version requested: ", ver.major, '.', ver.minor)
);
case utki::version_duplet{.major = 2, .minor = 0}.to_uint32_t():
return EGL_OPENGL_ES2_BIT;
case utki::version_duplet{3, 0}.to_uint32_t():
case utki::version_duplet{.major = 3, .minor = 0}.to_uint32_t():
return EGL_OPENGL_ES3_BIT;
}
}(),
Expand All @@ -398,7 +418,9 @@ struct window_wrapper : public utki::destructable {
EGL_ALPHA_SIZE,
8,
EGL_DEPTH_SIZE,
16,
wp.buffers.get(window_params::buffer::depth) ? int(utki::byte_bits * sizeof(uint16_t)) : 0,
EGL_STENCIL_SIZE,
wp.buffers.get(window_params::buffer::stencil) ? utki::byte_bits : 0,
EGL_NONE
};

Expand Down Expand Up @@ -562,17 +584,7 @@ struct window_wrapper : public utki::destructable {
throw std::runtime_error("glXCreateContextAttribsARB() not found");
}

auto ver = [&ver = wp.graphics_api_version](){
switch(ver.to_uint32_t()){
case 0:
// default OpenGL version
[[fallthrough]];
case utki::version_duplet{2, 0}.to_uint32_t():
return utki::version_duplet{2, 0};
default:
return ver;
}
}();
const auto& ver = graphics_api_version;

static const std::array<int, 7> context_attribs = {
GLX_CONTEXT_MAJOR_VERSION_ARB,
Expand Down Expand Up @@ -736,10 +748,11 @@ struct window_wrapper : public utki::destructable {
});

{
std::array<EGLint, 3> context_attrs = {
EGL_CONTEXT_CLIENT_VERSION,
2, // this is needed at least on Android, otherwise eglCreateContext()
// thinks that we want OpenGL ES 1.1, but we want 2.0
std::array<EGLint, 5> context_attrs = {
EGL_CONTEXT_MAJOR_VERSION,
graphics_api_version.major,
EGL_CONTEXT_MINOR_VERSION,
graphics_api_version.minor,
EGL_NONE
};

Expand Down
3 changes: 1 addition & 2 deletions src/ruisapp/glue/windows/glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,7 @@ window_wrapper::window_wrapper(const window_params& wp)
BYTE(0),
BYTE(0),
BYTE(0), // accumulation bits ignored
wp.buffers.get(window_params::buffer::depth) ? BYTE(utki::byte_bits * 2)
: BYTE(0), // 16 bit depth buffer
wp.buffers.get(window_params::buffer::depth) ? BYTE(utki::byte_bits * 2) : BYTE(0), // 16 bit depth buffer
wp.buffers.get(window_params::buffer::stencil) ? BYTE(utki::byte_bits) : BYTE(0),
BYTE(0), // no auxiliary buffer
BYTE(PFD_MAIN_PLANE), // main drawing layer
Expand Down

0 comments on commit 6fbce6c

Please sign in to comment.