1 | /*! |
2 | * \file sdl_demo.hpp |
3 | * \brief file sdl_demo.hpp |
4 | * |
5 | * Adapted from: sdl_demo.hpp of WRATH: |
6 | * |
7 | * Copyright 2013 by Nomovok Ltd. |
8 | * Contact: info@nomovok.com |
9 | * This Source Code Form is subject to the |
10 | * terms of the Mozilla Public License, v. 2.0. |
11 | * If a copy of the MPL was not distributed with |
12 | * this file, You can obtain one at |
13 | * http://mozilla.org/MPL/2.0/. |
14 | * |
15 | * \author Kevin Rogovin <kevin.rogovin@nomovok.com> |
16 | * \author Kevin Rogovin <kevin.rogovin@gmail.com> |
17 | * |
18 | */ |
19 | |
20 | |
21 | #ifndef FASTUIDRAW_DEMO_SDL_DEMO_HPP |
22 | #define FASTUIDRAW_DEMO_SDL_DEMO_HPP |
23 | |
24 | #include <iostream> |
25 | #include <iomanip> |
26 | #include <set> |
27 | #include <list> |
28 | #include <map> |
29 | #include <algorithm> |
30 | #include <vector> |
31 | |
32 | #include <SDL.h> |
33 | |
34 | #include <fastuidraw/util/util.hpp> |
35 | #include <fastuidraw/util/vecN.hpp> |
36 | #include <fastuidraw/util/math.hpp> |
37 | #include <fastuidraw/gl_backend/ngl_header.hpp> |
38 | #include <fastuidraw/gl_backend/gl_binding.hpp> |
39 | |
40 | #include "ostream_utility.hpp" |
41 | #include "generic_command_line.hpp" |
42 | #include "cast_c_array.hpp" |
43 | |
44 | /* |
45 | Notes: |
46 | ~sdl_demo() destroy the window and GL context, |
47 | thus it is safe to use GL functions in dtor |
48 | of a derived class |
49 | |
50 | sdl_demo() DOES NOT create the window or GL |
51 | context, so one cannot call GL functions |
52 | from there; rather call GL init functions |
53 | in init_gl(). |
54 | |
55 | */ |
56 | class sdl_demo:public command_line_register |
57 | { |
58 | public: |
59 | explicit |
60 | sdl_demo(const std::string &about_text=std::string(), |
61 | bool dimensions_must_match_default_value = false); |
62 | |
63 | virtual |
64 | ~sdl_demo(); |
65 | |
66 | /* |
67 | call this as your main, at main exit, demo is over. |
68 | */ |
69 | int |
70 | main(int argc, char **argv); |
71 | |
72 | protected: |
73 | |
74 | virtual |
75 | void |
76 | init_gl(int w, int h) |
77 | { |
78 | (void)w; |
79 | (void)h; |
80 | } |
81 | |
82 | virtual |
83 | void |
84 | pre_draw_frame(void) |
85 | {} |
86 | |
87 | virtual |
88 | void |
89 | draw_frame(void) |
90 | {} |
91 | |
92 | virtual |
93 | void |
94 | post_draw_frame(void) |
95 | {} |
96 | |
97 | virtual |
98 | void |
99 | handle_event(const SDL_Event&) |
100 | {} |
101 | |
102 | void |
103 | reverse_event_y(bool v); |
104 | |
105 | void |
106 | end_demo(int return_value) |
107 | { |
108 | m_run_demo = false; |
109 | m_return_value = return_value; |
110 | } |
111 | |
112 | fastuidraw::ivec2 |
113 | dimensions(void); |
114 | |
115 | void |
116 | swap_buffers(unsigned int count = 1); |
117 | |
118 | protected: |
119 | bool m_handle_events; |
120 | |
121 | private: |
122 | |
123 | enum fastuidraw::return_code |
124 | init_sdl(void); |
125 | |
126 | void |
127 | set_sdl_gl_context_attributes(void); |
128 | |
129 | void |
130 | create_sdl_gl_context(void); |
131 | |
132 | std::string m_about; |
133 | command_separator m_common_label; |
134 | command_line_argument_value<int> m_red_bits; |
135 | command_line_argument_value<int> m_green_bits; |
136 | command_line_argument_value<int> m_blue_bits; |
137 | command_line_argument_value<int> m_alpha_bits; |
138 | command_line_argument_value<int> m_depth_bits; |
139 | command_line_argument_value<int> m_stencil_bits; |
140 | command_line_argument_value<bool> m_fullscreen; |
141 | command_line_argument_value<bool> m_hide_cursor; |
142 | command_line_argument_value<bool> m_use_msaa; |
143 | command_line_argument_value<int> m_msaa; |
144 | command_line_argument_value<int> m_width; |
145 | command_line_argument_value<int> m_height; |
146 | command_line_argument_value<bool> m_dimensions_must_match; |
147 | command_line_argument_value<int> m_bpp; |
148 | command_line_argument_value<std::string> m_log_gl_commands; |
149 | command_line_argument_value<bool> m_print_gl_info; |
150 | command_line_argument_value<int> m_swap_interval; |
151 | command_line_argument_value<int> m_gl_major, m_gl_minor; |
152 | #ifndef FASTUIDRAW_GL_USE_GLES |
153 | command_line_argument_value<bool> m_gl_forward_compatible_context; |
154 | command_line_argument_value<bool> m_gl_debug_context; |
155 | command_line_argument_value<bool> m_gl_core_profile; |
156 | command_line_argument_value<bool> m_try_to_get_latest_gl_version; |
157 | #endif |
158 | command_line_argument_value<unsigned int> m_num_warm_up_frames; |
159 | command_line_argument_value<bool> m_show_framerate; |
160 | |
161 | fastuidraw::reference_counted_ptr<fastuidraw::gl_binding::CallbackGL> m_gl_logger; |
162 | |
163 | bool m_run_demo; |
164 | int m_return_value; |
165 | bool m_reverse_event_y; |
166 | |
167 | SDL_Window *m_window; |
168 | SDL_GLContext m_ctx; |
169 | }; |
170 | |
171 | #endif |
172 | |