1 | #include <vector> |
2 | |
3 | #include <fastuidraw/text/glyph_cache.hpp> |
4 | #include <fastuidraw/text/font_database.hpp> |
5 | #include <fastuidraw/painter/painter.hpp> |
6 | #include <fastuidraw/gl_backend/painter_engine_gl.hpp> |
7 | #include <fastuidraw/gl_backend/painter_surface_gl.hpp> |
8 | #include <fastuidraw/text/font_freetype.hpp> |
9 | |
10 | #include "cast_c_array.hpp" |
11 | #include "sdl_demo.hpp" |
12 | |
13 | class sdl_painter_demo:public sdl_demo |
14 | { |
15 | public: |
16 | enum pixel_count_t |
17 | { |
18 | frame_number_pixels, |
19 | frame_number_pixels_that_neighbor_helper, |
20 | total_number_pixels, |
21 | total_number_pixels_that_neighbor_helper, |
22 | }; |
23 | |
24 | explicit |
25 | sdl_painter_demo(const std::string &about_text=std::string(), |
26 | bool default_value_for_print_painter_config = false); |
27 | |
28 | ~sdl_painter_demo(); |
29 | |
30 | protected: |
31 | void |
32 | init_gl(int, int); |
33 | |
34 | virtual |
35 | void |
36 | derived_init(int, int) |
37 | {} |
38 | |
39 | void |
40 | on_resize(int, int); |
41 | |
42 | virtual |
43 | void |
44 | pre_draw_frame(void); |
45 | |
46 | virtual |
47 | void |
48 | post_draw_frame(void); |
49 | |
50 | uint64_t |
51 | pixel_count(enum pixel_count_t tp) |
52 | { |
53 | return m_pixel_counts[tp]; |
54 | } |
55 | |
56 | bool |
57 | pixel_counter_active(void) |
58 | { |
59 | return m_pixel_counter_stack.value() >= 0; |
60 | } |
61 | |
62 | fastuidraw::c_array<const unsigned int> |
63 | painter_stats(void) const |
64 | { |
65 | return cast_c_array(m_painter_stats); |
66 | } |
67 | |
68 | unsigned int |
69 | painter_stat(enum fastuidraw::Painter::query_stats_t t) |
70 | { |
71 | return (t < m_painter_stats.size()) ? |
72 | m_painter_stats[t] : |
73 | 0u; |
74 | } |
75 | |
76 | protected: |
77 | void |
78 | draw_text(const std::string &text, float pixel_size, |
79 | const fastuidraw::FontBase *font, |
80 | fastuidraw::GlyphRenderer renderer, |
81 | const fastuidraw::PainterData &draw, |
82 | enum fastuidraw::Painter::screen_orientation orientation |
83 | = fastuidraw::Painter::y_increases_downwards); |
84 | void |
85 | draw_text(const std::string &text, float pixel_size, |
86 | const fastuidraw::FontBase *font, |
87 | const fastuidraw::PainterData &draw, |
88 | enum fastuidraw::Painter::screen_orientation orientation |
89 | = fastuidraw::Painter::y_increases_downwards) |
90 | { |
91 | draw_text(text, pixel_size, font, fastuidraw::GlyphRenderer(), |
92 | draw, orientation); |
93 | } |
94 | |
95 | fastuidraw::reference_counted_ptr<fastuidraw::gl::PainterSurfaceGL> m_surface; |
96 | fastuidraw::reference_counted_ptr<fastuidraw::gl::PainterEngineGL> m_backend; |
97 | fastuidraw::reference_counted_ptr<fastuidraw::Painter> m_painter; |
98 | fastuidraw::reference_counted_ptr<fastuidraw::FontDatabase> m_font_database; |
99 | fastuidraw::reference_counted_ptr<fastuidraw::FreeTypeLib> m_ft_lib; |
100 | |
101 | private: |
102 | typedef enum fastuidraw::gl::PainterEngineGL::data_store_backing_t data_store_backing_t; |
103 | typedef enum fastuidraw::glsl::PainterShaderRegistrarGLSL::clipping_type_t clipping_type_t; |
104 | typedef enum fastuidraw::glsl::PainterShaderRegistrarGLSL::fbf_blending_type_t fbf_blending_type_t; |
105 | typedef enum fastuidraw::PainterBlendShader::shader_type shader_blend_type; |
106 | enum glyph_backing_store_t |
107 | { |
108 | glyph_backing_store_texture_buffer, |
109 | glyph_backing_store_texture_array, |
110 | glyph_backing_store_ssbo, |
111 | glyph_backing_store_auto, |
112 | }; |
113 | |
114 | enum painter_optimal_t |
115 | { |
116 | painter_no_optimal, |
117 | painter_optimal_performance, |
118 | painter_optimal_rendering, |
119 | }; |
120 | |
121 | fastuidraw::gl::PainterEngineGL::GlyphAtlasParams m_glyph_atlas_params; |
122 | fastuidraw::gl::PainterEngineGL::ColorStopAtlasParams m_colorstop_atlas_params; |
123 | fastuidraw::gl::PainterEngineGL::ImageAtlasParams m_image_atlas_params; |
124 | fastuidraw::gl::PainterEngineGL::ConfigurationGL m_painter_params; |
125 | |
126 | /* Image atlas parameters */ |
127 | command_separator m_image_atlas_options; |
128 | command_line_argument_value<unsigned int> m_log2_color_tile_size, m_log2_num_color_tiles_per_row_per_col; |
129 | command_line_argument_value<unsigned int> m_num_color_layers; |
130 | command_line_argument_value<unsigned int> m_log2_index_tile_size, m_log2_num_index_tiles_per_row_per_col; |
131 | command_line_argument_value<unsigned int> m_num_index_layers; |
132 | command_line_argument_value<bool> m_support_image_on_atlas; |
133 | |
134 | /* Glyph atlas parameters */ |
135 | command_separator m_glyph_atlas_options; |
136 | command_line_argument_value<int> m_glyph_atlas_size; |
137 | enumerated_command_line_argument_value<enum glyph_backing_store_t> m_glyph_backing_store_type; |
138 | command_line_argument_value<int> m_glyph_backing_texture_log2_w, m_glyph_backing_texture_log2_h; |
139 | |
140 | /* ColorStop atlas parameters */ |
141 | command_separator m_colorstop_atlas_options; |
142 | command_line_argument_value<int> m_color_stop_atlas_width; |
143 | command_line_argument_value<int> m_color_stop_atlas_layers; |
144 | |
145 | /* Painter params */ |
146 | command_separator m_painter_options; |
147 | command_line_argument_value<int> m_painter_attributes_per_buffer; |
148 | command_line_argument_value<int> m_painter_indices_per_buffer; |
149 | command_line_argument_value<int> m_painter_number_pools; |
150 | command_line_argument_value<bool> m_painter_break_on_shader_change; |
151 | command_line_argument_value<bool> m_uber_vert_use_switch; |
152 | command_line_argument_value<bool> m_uber_frag_use_switch; |
153 | command_line_argument_value<bool> m_use_uber_item_shader; |
154 | command_line_argument_value<bool> m_uber_blend_use_switch; |
155 | command_line_argument_value<bool> m_separate_program_for_discard; |
156 | command_line_argument_value<bool> m_allow_bindless_texture_from_surface; |
157 | |
158 | /* Painter params that can be overridden by properties of GL context */ |
159 | command_separator m_painter_options_affected_by_context; |
160 | enumerated_command_line_argument_value<clipping_type_t> m_use_hw_clip_planes; |
161 | command_line_argument_value<int> m_painter_data_blocks_per_buffer; |
162 | enumerated_command_line_argument_value<data_store_backing_t> m_data_store_backing; |
163 | command_line_argument_value<bool> m_assign_layout_to_vertex_shader_inputs; |
164 | command_line_argument_value<bool> m_assign_layout_to_varyings; |
165 | command_line_argument_value<bool> m_assign_binding_points; |
166 | command_line_argument_value<bool> m_support_dual_src_blend_shaders; |
167 | enumerated_command_line_argument_value<shader_blend_type> m_preferred_blend_type; |
168 | enumerated_command_line_argument_value<fbf_blending_type_t> m_fbf_blending_type; |
169 | enumerated_command_line_argument_value<enum painter_optimal_t> m_painter_optimal; |
170 | |
171 | command_separator m_demo_options; |
172 | command_line_argument_value<bool> m_print_painter_config; |
173 | command_line_argument_value<bool> m_print_painter_shader_ids; |
174 | |
175 | /* if we are to record pixel counts only */ |
176 | command_line_argument_value<int> m_pixel_counter_stack; |
177 | |
178 | /* glyph generation options */ |
179 | command_line_argument_value<int> m_distance_field_pixel_size; |
180 | command_line_argument_value<float> m_distance_field_max_distance; |
181 | command_line_argument_value<unsigned int> m_restricted_rays_max_recursion; |
182 | command_line_argument_value<unsigned int> m_restricted_rays_split_thresh; |
183 | command_line_argument_value<float> m_restricted_rays_expected_min_render_size; |
184 | command_line_argument_value<unsigned int> m_banded_rays_max_recursion; |
185 | command_line_argument_value<float> m_banded_rays_average_number_curves_thresh; |
186 | |
187 | std::list<GLuint> m_pixel_counter_buffers; |
188 | unsigned int m_num_pixel_counter_buffers; |
189 | unsigned int m_pixel_counter_buffer_binding_index; |
190 | fastuidraw::vecN<uint64_t, 4> m_pixel_counts; |
191 | std::vector<unsigned int> m_painter_stats; |
192 | }; |
193 | |