Skip to content

Commit

Permalink
graphics api version
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Mar 26, 2024
1 parent 0bc5553 commit 20ddb00
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 181 deletions.
55 changes: 5 additions & 50 deletions src/ruisapp/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <utki/destructable.hpp>
#include <utki/flags.hpp>
#include <utki/singleton.hpp>
#include <utki/util.hpp>

#include "config.hpp"

Expand All @@ -48,7 +49,7 @@ struct window_params {

// TODO: add window title string

enum class buffer_type {
enum class buffer {
depth,
stencil,

Expand All @@ -59,56 +60,10 @@ struct window_params {
* @brief Flags describing desired buffers for rendering context.
* Color buffer is always there implicitly.
*/
utki::flags<buffer_type> buffers = false;

enum class graphics_api_version {
v_default,
v_2_0,
v_2_1,
v_3_0,
v_3_1,
v_3_2,
v_3_3,
v_4_0,
v_4_1,
v_4_2,
v_4_3,
v_4_4,
v_4_5,
v_4_6
};

// TODO: remove in favor of graphics_api_version
enum class graphics_api {
gl_2_0,
gl_2_1,
gl_3_0,
gl_3_1,
gl_3_2,
gl_3_3,
gl_4_0,
gl_4_1,
gl_4_2,
gl_4_3,
gl_4_4,
gl_4_5,
gl_4_6,
gles_2_0,
gles_3_0,

enum_size
};
utki::flags<buffer> buffers = false;

// TODO: use graphics_api_version
graphics_api graphics_api_request =
#if CFG_OS_NAME == CFG_OS_NAME_ANDROID || CFG_OS_NAME == CFG_OS_NAME_IOS
graphics_api::gles_2_0
#elif CFG_OS == CFG_OS_WINDOWS || CFG_OS == CFG_OS_LINUX || CFG_OS == CFG_OS_MACOSX
graphics_api::gl_2_0
#else
# error "unknown OS"
#endif
;
// version 0.0 means default version
utki::version_duplet graphics_api_version = {0, 0};

window_params(r4::vector2<unsigned> dims) :
dims(dims)
Expand Down
4 changes: 2 additions & 2 deletions src/ruisapp/glue/ios/glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ - (void)viewDidLoad{

{
const window_params& wp = windowParams;
if(wp.buffers.get(window_params::buffer_type::depth)){
if(wp.buffers.get(window_params::buffer::depth)){
view.drawableDepthFormat = GLKViewDrawableDepthFormat16;
}else{
view.drawableDepthFormat = GLKViewDrawableDepthFormatNone;
}
if(wp.buffers.get(window_params::buffer_type::stencil)){
if(wp.buffers.get(window_params::buffer::stencil)){
view.drawableStencilFormat = GLKViewDrawableStencilFormat8;
}else{
view.drawableStencilFormat = GLKViewDrawableStencilFormatNone;
Expand Down
27 changes: 19 additions & 8 deletions src/ruisapp/glue/linux/glue_x11.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../../application.hpp"
#include "../friend_accessors.cxx" // NOLINT(bugprone-suspicious-include)
#include "../unix_common.cxx" // NOLINT(bugprone-suspicious-include)
#include "../util.hxx"

using namespace std::string_view_literals;

Expand Down Expand Up @@ -279,11 +278,11 @@ struct window_wrapper : public utki::destructable {
visual_attribs.push_back(GLX_ALPHA_SIZE);
visual_attribs.push_back(utki::byte_bits);

if (wp.buffers.get(window_params::buffer_type::depth)) {
if (wp.buffers.get(window_params::buffer::depth)) {
visual_attribs.push_back(GLX_DEPTH_SIZE);
visual_attribs.push_back(utki::byte_bits * 3); // 24 bits per pixel for depth buffer
}
if (wp.buffers.get(window_params::buffer_type::stencil)) {
if (wp.buffers.get(window_params::buffer::stencil)) {
visual_attribs.push_back(GLX_STENCIL_SIZE);
visual_attribs.push_back(utki::byte_bits);
}
Expand Down Expand Up @@ -378,13 +377,15 @@ struct window_wrapper : public utki::destructable {
EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE,
[&wp]() {
switch (wp.graphics_api_request) {
const auto& ver = wp.graphics_api_version;
switch (ver.to_uint32_t()) {
default:
std::cout << "Requested default rendering API: OpenGL ES 2" << std::endl;
throw std::logic_error(utki::cat("unknown OpenGL ES version requested: ", ver.major, '.', ver.minor));
case 0: // default version
[[fallthrough]];
case ruisapp::window_params::graphics_api::gles_2_0:
case utki::version_duplet{2, 0}.to_uint32_t():
return EGL_OPENGL_ES2_BIT;
case ruisapp::window_params::graphics_api::gles_3_0:
case utki::version_duplet{3, 0}.to_uint32_t():
return EGL_OPENGL_ES3_BIT;
}
}(),
Expand Down Expand Up @@ -561,7 +562,17 @@ struct window_wrapper : public utki::destructable {
throw std::runtime_error("glXCreateContextAttribsARB() not found");
}

auto ver = get_opengl_version_duplet(wp.graphics_api_request);
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;
}
}();

static const std::array<int, 7> context_attribs = {
GLX_CONTEXT_MAJOR_VERSION_ARB,
Expand Down
4 changes: 2 additions & 2 deletions src/ruisapp/glue/macosx/glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ -(CocoaView*)view{return self->v;}
std::vector<NSOpenGLPixelFormatAttribute> attributes;
attributes.push_back(NSOpenGLPFAAccelerated);
attributes.push_back(NSOpenGLPFAColorSize); attributes.push_back(24);
if(wp.buffers.get(window_params::buffer_type::depth)){
if(wp.buffers.get(window_params::buffer::depth)){
attributes.push_back(NSOpenGLPFADepthSize); attributes.push_back(16);
}
if(wp.buffers.get(window_params::buffer_type::stencil)){
if(wp.buffers.get(window_params::buffer::stencil)){
attributes.push_back(NSOpenGLPFAStencilSize); attributes.push_back(8);
}
attributes.push_back(NSOpenGLPFADoubleBuffer);
Expand Down
79 changes: 0 additions & 79 deletions src/ruisapp/glue/util.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/ruisapp/glue/util.hxx

This file was deleted.

4 changes: 2 additions & 2 deletions src/ruisapp/glue/windows/glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ window_wrapper::window_wrapper(const window_params& wp)
BYTE(0),
BYTE(0),
BYTE(0), // accumulation bits ignored
wp.buffers.get(window_params::buffer_type::depth) ? BYTE(utki::byte_bits * 2)
wp.buffers.get(window_params::buffer::depth) ? BYTE(utki::byte_bits * 2)
: BYTE(0), // 16 bit depth buffer
wp.buffers.get(window_params::buffer_type::stencil) ? BYTE(utki::byte_bits) : BYTE(0),
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
BYTE(0), // reserved
Expand Down
4 changes: 1 addition & 3 deletions tests/app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ class application : public ruisapp::application{
ruisapp::application("ruis-tests", [](){
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
ruisapp::window_params wp(r4::vector2<unsigned>(1024, 800));
// wp.graphics_api_request = ruisapp::window_params::graphics_api::gl_4_5;

return wp;
return wp;
}())
{
this->gui.init_standard_widgets(*this->get_res_file("../../res/ruis_res/"));
Expand Down

0 comments on commit 20ddb00

Please sign in to comment.