Gamp v0.0.8
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
GLLauncher01.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11
12#ifndef GAMP_DEMOS_LAUNCHER01_HPP_
13#define GAMP_DEMOS_LAUNCHER01_HPP_
14
15#include <GLES3/gl32.h>
16#include <gamp/Gamp.hpp>
17
18#include <jau/basic_types.hpp>
19#include <jau/debug.hpp>
20#include <jau/string_cfmt.hpp>
21#include <jau/io/file_util.hpp>
22
23#include <gamp/Gamp.hpp>
28
29using namespace jau::math;
30using namespace jau::math::util;
31
32using namespace gamp::wt;
33using namespace gamp::wt::event;
34
35#if !defined(__EMSCRIPTEN__)
36 // TODO: Should be moved into a GLDebugListener
37 static void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) {
38 (void)userParam;
39 jau_PLAIN_PRINT(true, "GL-Debug: src 0x%x, type 0x%x, id 0x%x, serverity 0x%x, len %zu: %s", source, type, id, severity, length, message);
40 }
41#endif
42
48
49inline int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerSRef& demo, int argc, char *argv[]) // NOLINT(bugprone-exception-escape)
50{
51 std::string demo_name = std::string("Gamp ").append(jau::io::fs::basename(sfile, {{".cpp"}, {".hpp"}}));
52 std::cout << "Launching: " << demo_name << ", source " << sfile << " , exe " << argv[0] << "\n";
53
54 #if defined(__EMSCRIPTEN__)
55 int win_width = 1024, win_height = 576; // 16:9
56 #else
57 int win_width = 1920, win_height = 1000;
58 #endif
59 {
60 for(int i=1; i<argc; ++i) {
61 if( 0 == strcmp("-gl", argv[i]) && i+1<argc) {
63 props.profile = gamp::render::gl::GLProfile(argv[i+1]);
64 }
65 } else if( 0 == strcmp("-width", argv[i]) && i+1<argc) {
66 win_width = atoi(argv[i+1]);
67 ++i;
68 } else if( 0 == strcmp("-height", argv[i]) && i+1<argc) {
69 win_height = atoi(argv[i+1]);
70 ++i;
71 } else if( 0 == strcmp("-fps", argv[i]) && i+1<argc) {
72 gamp::set_gpu_forced_fps( atoi(argv[i+1]) );
73 ++i;
74 } else if( 0 == strcmp("-smsaa", argv[i]) && i+1<argc) {
75 props.requestedCaps.setMultiSamplesCount(atoi(argv[i+1]));
76 ++i;
77 }
78 }
79 std::cout << "-profile " << props.profile << ", context flags " << props.contextFlags << "\n";
80 jau_printf("-window %d x %d, fps %d, req %s\n", win_width, win_height, gamp::gpu_forced_fps(), props.requestedCaps.toString());
81 }
82
83 if( !gamp::init_gfx_subsystem(argv[0]) ) {
84 std::cout << "Exit (0)...\n";
85 return 1;
86 }
88 WindowSRef main_win = Window::create(demo_name.c_str(), win_width, win_height, props.requestedCaps, verbose);
89 if( !main_win ) {
90 std::cout << "Exit (1): Failed to create window.\n";
91 return 1;
92 }
93 {
94 const int w = main_win->surfaceSize().x;
95 const int h = main_win->surfaceSize().y;
96 const float a = (float)w / (float)h;
97 jau_printf("FB %d x %d [w x h], aspect %f [w/h]; Win %s\n", w, h, a, main_win->windowBounds().toString());
98 }
99 // main_win->createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags);
100
101 if( !main_win->createContext(props.profile, props.contextFlags) ) {
102 std::cout << "Exit (2): Failed to create context\n";
103 main_win->dispose(jau::getMonotonicTime());
104 return 1;
105 }
106 jau_printf("Window: %s\n", main_win->toString());
107 {
109
110 jau_printf("GL Context: %s\n", gl.toString());
111
112 #if !defined(__EMSCRIPTEN__)
113 // TODO: Should be hooked with a GLDebugListener manager
115 ::glDebugMessageCallback(GLDebugCallback, nullptr);
116 GLuint ids[] = { 0 };
117 ::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, ids, GL_TRUE);
118 }
119 #endif
120 }
121 main_win->addRenderListener(demo);
122
123 #if defined(__EMSCRIPTEN__)
124 emscripten_set_main_loop(gamp::mainloop_void, 0, 1);
125 #else
126 while( gamp::mainloop_default() ) { }
127 #endif
128 jau_printf("Exit: %s\n", main_win->toString());
129 return 0;
130}
131
132#endif // #define GAMP_DEMOS_LAUNCHER01_HPP_
int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerSRef &demo, int argc, char *argv[])
static void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
constexpr RenderContextFlags contextFlags() const noexcept
Specifies a set of OpenGL capabilities.
constexpr GLCapabilities & setMultiSamplesCount(int v) noexcept
Defaults to 0, i.e.
std::string toString() const override
Returns a textual representation of this GLCapabilities object.
static GLContext & downcast(RenderContext *rc)
Downcast dereferenced given RenderContext* to GLContext&, throws exception if signature doesn't match...
std::string toString() const override
Specifies the OpenGL profile.
Definition GLContext.hpp:42
static constexpr bool isValidTag(std::string_view tag) noexcept
Definition GLContext.hpp:73
const gamp::render::RenderContext * renderContext() const noexcept
Definition Surface.hpp:131
constexpr const Vec2i & surfaceSize() const noexcept
Returns the surface size of the client area excluding insets (window decorations) in pixel units.
Definition Surface.hpp:177
bool createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags)
Definition Surface.hpp:117
static WindowSRef create(const char *title, int wwidth, int wheight, const Capabilities &requested, bool verbose=false)
Create an new instance using a native windowing toolkit.
constexpr const Recti & windowBounds() const noexcept
Returns the window client-area top-left position and size excluding insets (window decorations) in wi...
Definition Window.hpp:236
void dispose(const jau::fraction_timespec &when) noexcept override
Definition Window.hpp:355
std::string toString() const noexcept
Definition gamp_wt.cpp:145
void addRenderListener(const RenderListenerSRef &l)
Definition Window.hpp:333
std::string toString() const noexcept
Definition recti.hpp:137
value_type y
Definition vec2i.hpp:64
value_type x
Definition vec2i.hpp:63
#define jau_PLAIN_PRINT(printPrefix, fmt,...)
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
Definition debug.hpp:171
#define jau_printf(fmt,...)
Definition debug.hpp:253
constexpr bool is_set(const E mask, const E bits) noexcept
std::string basename(std::string_view path) noexcept
Return stripped leading directory components from given path separated by /.
fraction_timespec getMonotonicTime() noexcept
Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01.
RenderContextFlags
OpenGL context flags.
@ verbose
Verbose operations (debugging).
std::shared_ptr< Window > WindowSRef
Definition Event.hpp:36
std::shared_ptr< RenderListener > RenderListenerSRef
Definition Window.hpp:122
void mainloop_void() noexcept
Calls mainloop_default(), but exits application if returning false.
bool init_gfx_subsystem(const char *exe_path)
GFX Toolkit: Initialize the subsystem once.
bool mainloop_default() noexcept
Performs the whole tasks for all created gamp::wt::Window instances.
int gpu_forced_fps() noexcept
Returns optional forced frames per seconds or -1 if unset, set via set_gpu_forced_fps().
Definition gamp_sdl2.cpp:84
void set_gpu_forced_fps(int fps) noexcept
Optional forced frames per seconds, pass to swap_gpu_buffer() by default.
Definition gamp_sdl2.cpp:86
gamp::render::RenderContextFlags contextFlags
gamp::render::gl::GLProfile profile
gamp::render::gl::GLCapabilities requestedCaps