OGLplus  (0.59.0) a C++ wrapper for rendering APIs

options.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_APPLICATION_OPTIONS_HPP
10 #define EAGINE_APPLICATION_OPTIONS_HPP
11 
12 #include "../main_ctx_object.hpp"
13 #include "../string_span.hpp"
14 #include "../valid_if/between.hpp"
15 #include "../valid_if/nonnegative.hpp"
16 #include "../valid_if/not_empty.hpp"
17 #include "../valid_if/not_equal.hpp"
18 #include "../valid_if/one_of.hpp"
19 #include "../valid_if/positive.hpp"
20 #include "fwd.hpp"
21 #include "types.hpp"
22 #include <map>
23 
24 namespace eagine::application {
25 //------------------------------------------------------------------------------
35 public:
38  video_context_kind kind,
39  string_view instance);
40 
42  main_ctx_object& obj,
43  video_context_kind kind,
44  identifier instance);
45 
47  auto video_kind() const noexcept -> video_context_kind {
48  return _video_kind;
49  }
50 
53  auto set_provider(std::string name) -> auto& {
54  _provider_name = std::move(name);
55  return *this;
56  }
57 
60  auto has_provider() const noexcept -> bool {
61  return !extract(_provider_name).empty();
62  }
63 
66  auto has_provider(string_view name) const noexcept -> bool {
67  return are_equal(string_view(_provider_name), name);
68  }
69 
71  auto provider() const noexcept -> valid_if_not_empty<string_view> {
72  return {_provider_name};
73  }
74 
79  auto display_name() const noexcept -> valid_if_not_empty<string_view> {
80  return {_display_name};
81  }
82 
87  auto driver_name() const noexcept -> valid_if_not_empty<string_view> {
88  return {_driver_name};
89  }
90 
95  auto device_path() const noexcept -> valid_if_not_empty<string_view> {
96  return {_device_path};
97  }
98 
104  auto device_kind() const noexcept
106  return {_device_kind};
107  }
108 
114  auto device_index() const noexcept -> valid_if_nonnegative<span_size_t> {
115  return _device_idx;
116  }
117 
121  auto prefer_gles() const noexcept -> bool {
122  return _prefer_gles;
123  }
124 
127 
130 
132  auto gl_version_major() const noexcept -> valid_gl_major_version {
133  return {_gl_version_major};
134  }
135 
139  auto gl_version_minor() const noexcept -> valid_gl_minor_version {
140  return {_gl_version_minor};
141  }
142 
146  auto gl_compatibility_context() const noexcept -> bool {
147  return _gl_compat_context;
148  }
149 
152  auto gl_debug_context() const noexcept -> bool {
153  return _gl_debug_context;
154  }
155 
158  auto gl_robust_access() const noexcept -> bool {
159  return _gl_robust_access;
160  }
161 
164 
167  -> auto& {
168  _surface_width = extract(width);
169  _surface_height = extract(height);
170  return *this;
171  }
172 
175  auto surface_width() const noexcept -> valid_surface_size {
176  return {_surface_width};
177  }
178 
181  auto surface_height() const noexcept -> valid_surface_size {
182  return {_surface_height};
183  }
184 
187 
190  auto samples(const valid_samples& value) noexcept -> auto& {
191  _samples = extract(value);
192  return *this;
193  }
194 
197  auto samples_dont_care() noexcept -> auto& {
198  _samples = 0;
199  return *this;
200  }
201 
203  auto samples() const noexcept -> valid_if_positive<int> {
204  return {_samples};
205  }
206 
209 
214  auto color_bits(const valid_color_bits& value) noexcept -> auto& {
215  _color_bits = extract(value);
216  return *this;
217  }
218 
220  auto color_bits() const noexcept -> valid_if_positive<int> {
221  return {_color_bits};
222  }
223 
226 
231  auto alpha_bits(const valid_alpha_bits& value) noexcept -> auto& {
232  _alpha_bits = extract(value);
233  return *this;
234  }
235 
240  auto with_alpha() noexcept -> auto& {
241  _alpha_bits = 8;
242  return *this;
243  }
244 
246  auto alpha_bits() const noexcept -> valid_if_positive<int> {
247  return {_alpha_bits};
248  }
249 
252 
257  auto depth_bits(const valid_depth_bits& value) noexcept -> auto& {
258  _depth_bits = extract(value);
259  return *this;
260  }
261 
265  auto with_depth() noexcept -> auto& {
266  _depth_bits = 24;
267  return *this;
268  }
269 
271  auto depth_bits() const noexcept -> valid_if_positive<int> {
272  return {_depth_bits};
273  }
274 
277 
282  auto stencil_bits(const valid_stencil_bits& value) noexcept -> auto& {
283  _stencil_bits = extract(value);
284  return *this;
285  }
286 
290  auto with_stencil() noexcept -> auto& {
291  _stencil_bits = 8;
292  return *this;
293  }
294 
296  auto stencil_bits() const noexcept -> valid_if_positive<int> {
297  return {_stencil_bits};
298  }
299 
302  auto offscreen(bool value) noexcept -> auto& {
303  if((_offscreen = value)) {
304  _surface_width = 0;
305  _surface_height = 0;
306  }
307  return *this;
308  }
309 
311  auto offscreen() const noexcept -> bool {
312  return _offscreen;
313  }
314 
315  auto needs_offscreen_framebuffer() const noexcept -> bool {
316  return _offscreen_framebuffer;
317  }
318 
321  auto fullscreen(bool value) noexcept -> auto& {
322  if((_fullscreen = value)) {
323  _surface_width = 0;
324  _surface_height = 0;
325  }
326  return *this;
327  }
328 
330  auto fullscreen() const noexcept -> bool {
331  return _fullscreen;
332  }
333 
335  auto framedump_prefix() const noexcept -> string_view {
336  return {_framedump_prefix};
337  }
338 
340  auto framedump_color() const noexcept -> framedump_data_type {
341  return _framedump_color;
342  }
343 
345  auto framedump_depth() const noexcept -> framedump_data_type {
346  return _framedump_depth;
347  }
348 
350  auto framedump_stencil() const noexcept -> framedump_data_type {
351  return _framedump_stencil;
352  }
353 
355  auto doing_framedump() const noexcept -> bool {
356  return (_framedump_color != framedump_data_type::none) ||
357  (_framedump_depth != framedump_data_type::none) ||
358  (_framedump_stencil != framedump_data_type::none);
359  }
360 
361 private:
362  video_context_kind _video_kind;
363 
369 
371 
372  application_config_value<int> _gl_version_major;
373  application_config_value<int> _gl_version_minor;
374 
375  application_config_value<int> _surface_width;
376  application_config_value<int> _surface_height;
377 
379  application_config_value<int> _color_bits;
380  application_config_value<int> _alpha_bits;
381  application_config_value<int> _depth_bits;
382  application_config_value<int> _stencil_bits;
383 
384  application_config_value<bool> _prefer_gles;
385  application_config_value<bool> _gl_debug_context;
386  application_config_value<bool> _gl_robust_access;
387  application_config_value<bool> _gl_compat_context;
388  application_config_value<bool> _fullscreen;
390  application_config_value<bool> _offscreen_framebuffer;
395 };
396 //------------------------------------------------------------------------------
406 public:
409  audio_context_kind kind,
410  identifier instance);
411 
413  auto audio_kind() const noexcept {
414  return _audio_kind;
415  }
416 
417 private:
418  friend class execution_context;
419 
420  audio_context_kind _audio_kind;
421 };
422 //------------------------------------------------------------------------------
432 public:
434  launch_options(main_ctx_parent parent) noexcept;
435 
437  auto application_title() const noexcept -> string_view;
438 
443  auto no_video() noexcept -> auto& {
444  _video_opts.clear();
445  return *this;
446  }
447 
454  auto require_video(
456  identifier instance = {}) -> video_options&;
457 
461  auto video_requirements() const noexcept
462  -> const std::map<identifier, video_options>& {
463  return _video_opts;
464  }
465 
470  auto no_audio() noexcept -> auto& {
471  _audio_opts.clear();
472  return *this;
473  }
474 
481  auto require_audio(
483  identifier instance = {}) -> audio_options&;
484 
488  auto audio_requirements() const noexcept
489  -> const std::map<identifier, audio_options>& {
490  return _audio_opts;
491  }
492 
497  auto no_input() noexcept -> auto& {
498  _requires_input = false;
499  return *this;
500  }
501 
505  auto require_input() noexcept -> auto& {
506  _requires_input = true;
507  return *this;
508  }
509 
511  auto required_input() const noexcept -> bool {
512  return _requires_input;
513  }
514 
516  template <typename R, typename P>
517  auto enough_run_time(std::chrono::duration<R, P> run_time) const noexcept
518  -> bool {
519  return _max_run_time && extract(_max_run_time) <= run_time;
520  }
521 
523  auto enough_frames(span_size_t frame_no) const noexcept -> bool {
524  return _max_frames && extract(_max_frames) <= frame_no;
525  }
526 
527 private:
528  friend class execution_context;
529 
530  std::string _app_title;
531 
532  std::map<identifier, video_options> _video_opts;
533  std::map<identifier, audio_options> _audio_opts;
534 
536  valid_if_positive<span_size_t> _max_frames{-1};
537  bool _requires_input{false};
538 };
539 //------------------------------------------------------------------------------
540 } // namespace eagine::application
541 
542 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
543 #include <eagine/application/options.inl>
544 #endif
545 
546 #endif
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
Helper class used to initialize main context objects.
Definition: main_ctx_object.hpp:45
auto color_bits() const noexcept -> valid_if_positive< int >
Returns the number of red, green and blue channel bits.
Definition: options.hpp:220
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
auto offscreen(bool value) noexcept -> auto &
Requests an off-screen rendering surface.
Definition: options.hpp:302
Class holding and managing video-related application options.
Definition: options.hpp:34
auto stencil_bits() const noexcept -> valid_if_positive< int >
Returns the number of stencil buffer bits.
Definition: options.hpp:296
auto enough_frames(span_size_t frame_no) const noexcept -> bool
Says if the application rendered enough frames according to the configuration.
Definition: options.hpp:523
Base class for main context objects.
Definition: main_ctx_object.hpp:71
launch_options(main_ctx_parent parent) noexcept
Constructor with parent main context object.
auto require_input() noexcept -> auto &
Specifies that user input handling is required.
Definition: options.hpp:505
auto video_kind() const noexcept -> video_context_kind
Returns the requested video rendering context kind.
Definition: options.hpp:47
Class for reading application configuration.
Definition: application_config.hpp:29
auto prefer_gles() const noexcept -> bool
Indicates that if both GL and GL|ES is available, ES should be used.
Definition: options.hpp:121
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
auto application_title() const noexcept -> string_view
Returns the title of the application.
auto samples(const valid_samples &value) noexcept -> auto &
Sets the number of per-pixel samples.
Definition: options.hpp:190
Primary template for conditionally valid values.
Definition: decl.hpp:49
auto display_name() const noexcept -> valid_if_not_empty< string_view >
Returns the display name string (this may be provider-specific).
Definition: options.hpp:79
auto depth_bits() const noexcept -> valid_if_positive< int >
Returns the number of depth buffer bits.
Definition: options.hpp:271
auto device_path() const noexcept -> valid_if_not_empty< string_view >
Returns the driver name string (this may be provider-specific).
Definition: options.hpp:95
auto no_input() noexcept -> auto &
Specifies that no user input should be used.
Definition: options.hpp:497
@ opengl
OpenGL© (or OpenGL|ES) context.
auto framedump_stencil() const noexcept -> framedump_data_type
Returns the pixel data type for stencil buffer frame dumps.
Definition: options.hpp:350
auto enough_run_time(std::chrono::duration< R, P > run_time) const noexcept -> bool
Says if the application ran long enough according to the configuration.
Definition: options.hpp:517
auto samples_dont_care() noexcept -> auto &
Sets the number of per-pixel samples to a "don't care" value.
Definition: options.hpp:197
auto with_stencil() noexcept -> auto &
Sets the number of stencil buffer bits to a default non-zero value.
Definition: options.hpp:290
auto doing_framedump() const noexcept -> bool
Indicates if a frame dump render run is requested.
Definition: options.hpp:355
auto required_input() const noexcept -> bool
Indicates if user input handling is required.
Definition: options.hpp:511
auto has_provider(string_view name) const noexcept -> bool
Indicates if video provider name is the same as the argument.
Definition: options.hpp:66
auto offscreen() const noexcept -> bool
Indicates if an off-screen rendering surface was requested.
Definition: options.hpp:311
auto set_provider(std::string name) -> auto &
Sets the video provider identifier name.
Definition: options.hpp:53
audio_context_kind
Audio / sound playback and recodring context kind.
Definition: types.hpp:37
framedump_data_type
Pixel data type used to store frame dump image data.
Definition: types.hpp:72
Class wrapping values that can be loaded from application_config.
Definition: application_config.hpp:197
auto with_alpha() noexcept -> auto &
Sets the number of alpha channel bits to a default non-zero value.
Definition: options.hpp:240
auto framedump_color() const noexcept -> framedump_data_type
Returns the pixel data type for color/alpha buffer frame dumps.
Definition: options.hpp:340
auto with_depth() noexcept -> auto &
Sets the number of depth buffer bits to a default non-zero value.
Definition: options.hpp:265
auto require_video(video_context_kind kind=video_context_kind::opengl, identifier instance={}) -> video_options &
Requests a new video rendering context and surface.
auto surface_size(valid_surface_size width, valid_surface_size height) -> auto &
Sets the rendering surface size.
Definition: options.hpp:166
auto surface_height() const noexcept -> valid_surface_size
Returns the rendering surface height (in pixels).
Definition: options.hpp:181
auto alpha_bits() const noexcept -> valid_if_positive< int >
Returns the number of alpha channel bits.
Definition: options.hpp:246
auto framedump_depth() const noexcept -> framedump_data_type
Returns the pixel data type for depth buffer frame dumps.
Definition: options.hpp:345
auto video_requirements() const noexcept -> const std::map< identifier, video_options > &
Returns all current video rendering context options.
Definition: options.hpp:461
auto gl_compatibility_context() const noexcept -> bool
Returns the preferred GL minor version number.
Definition: options.hpp:146
video_device_kind
Video rendering device kind.
Definition: types.hpp:51
auto no_video() noexcept -> auto &
Specifies that no video rendering should be used.
Definition: options.hpp:443
auto framedump_prefix() const noexcept -> string_view
Returns a filesystem prefix for framedump image files.
Definition: options.hpp:335
video_context_kind
Video / graphics rendering context kind.
Definition: types.hpp:20
auto samples() const noexcept -> valid_if_positive< int >
Returns the number of per-pixel samples.
Definition: options.hpp:203
auto audio_requirements() const noexcept -> const std::map< identifier, audio_options > &
Returns all current audio rendering context options.
Definition: options.hpp:488
@ none
None, not doing frame dump render run.
Class holding and managing audio-related application options.
Definition: options.hpp:405
auto gl_version_major() const noexcept -> valid_gl_major_version
Returns the preferred GL major version number.
Definition: options.hpp:132
auto gl_debug_context() const noexcept -> bool
Indicates if a debug GL context should be created.
Definition: options.hpp:152
auto no_audio() noexcept -> auto &
Specifies that no audio playback or recording should be used.
Definition: options.hpp:470
auto alpha_bits(const valid_alpha_bits &value) noexcept -> auto &
Sets the number of alpha channel bits.
Definition: options.hpp:231
Class managing options for an application with video / audio rendering.
Definition: options.hpp:431
auto stencil_bits(const valid_stencil_bits &value) noexcept -> auto &
Sets the number of stencil buffer bits.
Definition: options.hpp:282
auto color_bits(const valid_color_bits &value) noexcept -> auto &
Sets the number of red, green and blue channel bits.
Definition: options.hpp:214
auto driver_name() const noexcept -> valid_if_not_empty< string_view >
Returns the driver name string (this may be provider-specific).
Definition: options.hpp:87
auto gl_robust_access() const noexcept -> bool
Indicates if a GL context with robust access checks should be created.
Definition: options.hpp:158
Class holding shared video/audio rendering application support objects.
Definition: context.hpp:166
auto fullscreen() const noexcept -> bool
Indicates if an full-screen rendering surface was requested.
Definition: options.hpp:330
auto require_audio(audio_context_kind kind=audio_context_kind::openal, identifier instance={}) -> audio_options &
Requests a new audio playback and recording context.
auto gl_version_minor() const noexcept -> valid_gl_minor_version
Returns the preferred GL major version number.
Definition: options.hpp:139
auto audio_kind() const noexcept
Returns the requested audio rendering context kind.
Definition: options.hpp:413
auto has_provider() const noexcept -> bool
Indicates if video provider name is set (not empty).
Definition: options.hpp:60
auto depth_bits(const valid_depth_bits &value) noexcept -> auto &
Sets the number of depth buffer bits.
Definition: options.hpp:257
auto device_kind() const noexcept -> valid_if_not< video_device_kind, video_device_kind::dont_care >
Returns the rendering device kind (this may be provider-specific).
Definition: options.hpp:104
auto surface_width() const noexcept -> valid_surface_size
Returns the rendering surface width (in pixels).
Definition: options.hpp:175
auto device_index() const noexcept -> valid_if_nonnegative< span_size_t >
Returns the rendering device index (this may be provider-specific).
Definition: options.hpp:114
auto fullscreen(bool value) noexcept -> auto &
Requests an full-screen rendering surface.
Definition: options.hpp:321
auto provider() const noexcept -> valid_if_not_empty< string_view >
Returns the assigned provider name.
Definition: options.hpp:71

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).