Gamp v0.0.7-54-gccdc599
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 <cstdio>
19
20#include <jau/basic_types.hpp>
21#include <jau/debug.hpp>
22#include <jau/io/file_util.hpp>
23
24#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
47
48int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerRef& demo, int argc, char *argv[]) // NOLINT(bugprone-exception-escape)
49{
50 std::string demo_name = std::string("Gamp ").append(jau::io::fs::basename(sfile, {{".cpp"}, {".hpp"}}));
51 std::cout << "Launching: " << demo_name << ", source " << sfile << " , exe " << argv[0] << "\n";
52
53 #if defined(__EMSCRIPTEN__)
54 int win_width = 1024, win_height = 576; // 16:9
55 #else
56 int win_width = 1920, win_height = 1000;
57 #endif
58 {
59 for(int i=1; i<argc; ++i) {
60 if( 0 == strcmp("-gl", argv[i]) && i+1<argc) {
62 props.profile = gamp::render::gl::GLProfile(argv[i+1]);
63 }
64 } else if( 0 == strcmp("-width", argv[i]) && i+1<argc) {
65 win_width = atoi(argv[i+1]);
66 ++i;
67 } else if( 0 == strcmp("-height", argv[i]) && i+1<argc) {
68 win_height = atoi(argv[i+1]);
69 ++i;
70 } else if( 0 == strcmp("-fps", argv[i]) && i+1<argc) {
71 gamp::set_gpu_forced_fps( atoi(argv[i+1]) );
72 ++i;
73 }
74 }
75 std::cout << "-profile " << props.profile << ", context flags " << props.contextFlags << "\n";
76 printf("-window %d x %d, fps %d\n", win_width, win_height, gamp::gpu_forced_fps());
77 }
78
79 if( !gamp::init_gfx_subsystem(argv[0]) ) {
80 printf("Exit (0)...");
81 return 1;
82 }
84 WindowRef main_win = Window::create(demo_name.c_str(), win_width, win_height, verbose);
85 if( !main_win ) {
86 printf("Exit (1): Failed to create window.\n");
87 return 1;
88 }
89 {
90 const int w = main_win->surfaceSize().x;
91 const int h = main_win->surfaceSize().y;
92 const float a = (float)w / (float)h;
93 printf("FB %d x %d [w x h], aspect %f [w/h]; Win %s\n", w, h, a, main_win->windowBounds().toString().c_str());
94 }
95 // main_win->createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags);
96
97 if( !main_win->createContext(props.profile, props.contextFlags) ) {
98 printf("Exit (2): Failed to create context\n");
99 main_win->dispose(jau::getMonotonicTime());
100 return 1;
101 }
102 printf("Window: %s\n", main_win->toString().c_str());
103 {
105
106 printf("GL Context: %s\n", gl.toString().c_str());
107
108 #if !defined(__EMSCRIPTEN__)
109 // TODO: Should be hooked with a GLDebugListener manager
111 ::glDebugMessageCallback(GLDebugCallback, nullptr);
112 GLuint ids[] = { 0 };
113 ::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, ids, GL_TRUE);
114 }
115 #endif
116 }
117 main_win->addRenderListener(demo);
118
119 #if defined(__EMSCRIPTEN__)
120 emscripten_set_main_loop(gamp::mainloop_void, 0, 1);
121 #else
122 while( gamp::mainloop_default() ) { }
123 #endif
124 printf("Exit: %s\n", main_win->toString().c_str());
125 return 0;
126}
127
128#endif // #define GAMP_DEMOS_LAUNCHER01_HPP_
int launch(std::string_view sfile, GLLaunchProps props, const RenderListenerRef &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
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:129
constexpr const Vec2i & surfaceSize() const noexcept
Returns the surface size of the client area excluding insets (window decorations) in pixel units.
Definition Surface.hpp:171
bool createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags)
Definition Surface.hpp:115
void addRenderListener(const RenderListenerRef &l)
Definition Window.hpp:333
static WindowRef create(const char *title, int wwidth, int wheight, 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
std::string toString() const noexcept
Definition recti.hpp:137
value_type y
Definition vec2i.hpp:64
value_type x
Definition vec2i.hpp:63
constexpr bool is_set(const E mask, const E bits) noexcept
std::string basename(const 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< RenderListener > RenderListenerRef
Definition Window.hpp:122
std::shared_ptr< Window > WindowRef
Definition Event.hpp:36
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
void PLAIN_PRINT(const bool printPrefix, const char *format,...) noexcept
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
Definition debug.cpp:264
gamp::render::RenderContextFlags contextFlags
gamp::render::gl::GLProfile profile
int printf(const char *format,...)
Operating Systems predefined macros.