Gamp v0.0.7-36-g24b1eb6
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/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, const GLLaunchProps& props, const RenderListenerRef& demo, int argc, char *argv[]) // NOLINT(bugprone-exception-escape)
49{
50 std::string demo_name = std::string("Gamp ").append(jau::fs::basename(sfile, {{".cpp"}, {".hpp"}}));
51 printf("Launching: %s, source %s, exe %s\n", demo_name.c_str(), sfile.data(), argv[0]);
52
53 int win_width = 1920, win_height = 1000;
54 #if defined(__EMSCRIPTEN__)
55 win_width = 1024, win_height = 576; // 16:9
56 #endif
57 {
58 for(int i=1; i<argc; ++i) {
59 if( 0 == strcmp("-width", argv[i]) && i+1<argc) {
60 win_width = atoi(argv[i+1]);
61 ++i;
62 } else if( 0 == strcmp("-height", argv[i]) && i+1<argc) {
63 win_height = atoi(argv[i+1]);
64 ++i;
65 } else if( 0 == strcmp("-fps", argv[i]) && i+1<argc) {
66 gamp::set_gpu_forced_fps( atoi(argv[i+1]) );
67 ++i;
68 }
69 }
70 printf("-fps: %d\n", gamp::gpu_forced_fps());
71 }
72
73 if( !gamp::init_gfx_subsystem(argv[0]) ) {
74 printf("Exit (0)...");
75 return 1;
76 }
78 WindowRef main_win = Window::create(demo_name.c_str(), win_width, win_height, verbose);
79 if( !main_win ) {
80 printf("Exit (1): Failed to create window.\n");
81 return 1;
82 }
83 {
84 const int w = main_win->surfaceSize().x;
85 const int h = main_win->surfaceSize().y;
86 const float a = (float)w / (float)h;
87 printf("FB %d x %d [w x h], aspect %f [w/h]; Win %s\n", w, h, a, main_win->windowBounds().toString().c_str());
88 }
89 // main_win->createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags);
90
91 if( !main_win->createContext(props.profile, props.contextFlags) ) {
92 printf("Exit (2): Failed to create context\n");
93 main_win->dispose(jau::getMonotonicTime());
94 return 1;
95 }
96 printf("Window: %s\n", main_win->toString().c_str());
97 {
99
100 printf("GL Context: %s\n", gl.toString().c_str());
101
102 #if !defined(__EMSCRIPTEN__)
103 // TODO: Should be hooked with a GLDebugListener manager
105 ::glDebugMessageCallback(GLDebugCallback, nullptr);
106 GLuint ids[] = { 0 };
107 ::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, ids, GL_TRUE);
108 }
109 #endif
110 }
111 main_win->addRenderListener(demo);
112
113 #if defined(__EMSCRIPTEN__)
114 emscripten_set_main_loop(gamp::mainloop_void, 0, 1);
115 #else
116 while( gamp::mainloop_default() ) { }
117 #endif
118 printf("Exit: %s\n", main_win->toString().c_str());
119 return 0;
120}
121
122#endif // #define GAMP_DEMOS_LAUNCHER01_HPP_
int launch(std::string_view sfile, const 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:41
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:129
value_type x
Definition vec2i.hpp:65
value_type y
Definition vec2i.hpp:66
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:258
gamp::render::RenderContextFlags contextFlags
gamp::render::gl::GLProfile profile
int printf(const char *format,...)
Operating Systems predefined macros.