neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_rendering_engine.hpp
Go to the documentation of this file.
1// i_rendering_engine.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
33
34namespace neogfx
35{
36 class i_surface_manager;
37 class i_rendering_context;
38 class i_font_manager;
39 class i_texture_manager;
40 class i_render_target;
41 class i_vertex_buffer;
42 class i_vertex_provider;
43
44 enum class renderer
45 {
46 OpenGL,
47 DirectX,
48 Vulkan,
50 None
51 };
52
54 {
55 // events
56 public:
57 declare_event(subpixel_rendering_changed)
58 // exceptions
59 public:
60 struct failed_to_initialize : std::runtime_error { failed_to_initialize() : std::runtime_error("neogfx::i_rendering_engine::failed_to_initialize") {} };
61 struct context_exists : std::logic_error { context_exists() : std::logic_error("neogfx::i_rendering_engine::context_exists") {} };
62 struct context_not_found : std::logic_error { context_not_found() : std::logic_error("neogfx::i_rendering_engine::context_not_found") {} };
63 struct consumer_exists : std::logic_error { consumer_exists() : std::logic_error("neogfx::i_rendering_engine::consumer_exists") {} };
64 struct consumer_not_found : std::logic_error { consumer_not_found() : std::logic_error("neogfx::i_rendering_engine::consumer_not_found") {} };
65 struct failed_to_create_shader_program : std::runtime_error { failed_to_create_shader_program(std::string const& aReason) : std::runtime_error("neogfx::i_rendering_engine::failed_to_create_shader_program: " + aReason) {} };
66 struct no_shader_program_active : std::logic_error { no_shader_program_active() : std::logic_error("neogfx::i_rendering_engine::no_shader_program_active") {} };
67 struct shader_program_not_found : std::logic_error { shader_program_not_found() : std::logic_error("neogfx::i_rendering_engine::shader_program_not_found") {} };
68 struct shader_program_error : std::runtime_error { shader_program_error(std::string const& aError) : std::runtime_error("neogfx::i_rendering_engine::shader_program_error: " + aError) {} };
69 // types
70 public:
71 typedef void* handle;
73 // construction
74 public:
75 virtual ~i_rendering_engine() = default;
76 // operations
77 public:
78 virtual const i_device_metrics& default_screen_metrics() const = 0;
79 public:
80 virtual neogfx::renderer renderer() const = 0;
81 virtual bool vsync_enabled() const = 0;
82 virtual void enable_vsync() = 0;
83 virtual void disable_vsync() = 0;
84 virtual void initialize() = 0;
85 virtual void cleanup() = 0;
86 virtual pixel_format_t set_pixel_format(const i_render_target& aTarget) = 0;
87 virtual const i_render_target* active_target() const = 0;
88 virtual void activate_context(const i_render_target& aTarget) = 0;
89 virtual void deactivate_context() = 0;
90 virtual handle create_context(const i_render_target& aTarget) = 0;
91 virtual void destroy_context(handle aContext) = 0;
92 public:
93 virtual const shader_program_list& shader_programs() const = 0;
94 virtual const i_shader_program& shader_program(const neolib::i_string& aName) const = 0;
97 virtual bool is_shader_program_active() const = 0;
99 public:
102 public:
104 virtual void destroy_shader_program_object(handle aShaderProgramObject) = 0;
105 virtual handle create_shader_object(shader_type aShaderType) = 0;
106 virtual void destroy_shader_object(handle aShaderObject) = 0;
107 public:
108 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const video_mode& aVideoMode, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
109 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
110 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const point& aPosition, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
111 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const video_mode& aVideoMode, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
112 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
113 virtual void create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const point& aPosition, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle, i_ref_ptr<i_native_window>& aResult) = 0;
114 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const video_mode& aVideoMode, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
115 {
117 create_window(aSurfaceManager, aWindow, aVideoMode, aWindowTitle, aStyle, result);
118 return result;
119 }
120 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
121 {
123 create_window(aSurfaceManager, aWindow, aDimensions, aWindowTitle, aStyle, result);
124 return result;
125 }
126 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, const point& aPosition, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
127 {
129 create_window(aSurfaceManager, aWindow, aPosition, aDimensions, aWindowTitle, aStyle, result);
130 return result;
131 }
132 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const video_mode& aVideoMode, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
133 {
135 create_window(aSurfaceManager, aWindow, aParent, aVideoMode, aWindowTitle, aStyle, result);
136 return result;
137 }
138 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
139 {
141 create_window(aSurfaceManager, aWindow, aParent, aDimensions, aWindowTitle, aStyle, result);
142 return result;
143 }
144 ref_ptr<i_native_window> create_window(i_surface_manager& aSurfaceManager, i_surface_window& aWindow, i_native_window& aParent, const point& aPosition, const size& aDimensions, std::string const& aWindowTitle, window_style aStyle = window_style::Default)
145 {
147 create_window(aSurfaceManager, aWindow, aParent, aPosition, aDimensions, aWindowTitle, aStyle, result);
148 return result;
149 }
150 virtual bool creating_window() const = 0;
153 public:
154 virtual bool vertex_buffer_allocated(i_vertex_provider& aProvider) const = 0;
156 virtual void deallocate_vertex_buffer(i_vertex_provider& aProvider) = 0;
157 virtual const i_vertex_buffer& vertex_buffer(i_vertex_provider& aProvider) const = 0;
159 virtual void execute_vertex_buffers() = 0;
160 public:
161 virtual i_texture& ping_pong_buffer1(const size& aExtents, size& aPreviousExtents, texture_sampling aSampling = texture_sampling::Multisample) = 0;
162 virtual i_texture& ping_pong_buffer2(const size& aExtents, size& aPreviousExtents, texture_sampling aSampling = texture_sampling::Multisample) = 0;
163 public:
164 virtual bool is_subpixel_rendering_on() const = 0;
165 virtual void subpixel_rendering_on() = 0;
166 virtual void subpixel_rendering_off() = 0;
167 public:
168 virtual void render_now() = 0;
169 virtual bool frame_rate_limited() const = 0;
170 virtual void enable_frame_rate_limiter(bool aEnable) = 0;
171 virtual uint32_t frame_rate_limit() const = 0;
172 virtual void set_frame_rate_limit(uint32_t aFps) = 0;
173 virtual bool use_rendering_priority() const = 0;
174 public:
175 virtual bool process_events() = 0;
176 public:
177 virtual void register_frame_counter(i_widget& aWidget, uint32_t aDuration) = 0;
178 virtual void unregister_frame_counter(i_widget& aWidget, uint32_t aDuration) = 0;
179 virtual uint32_t frame_counter(uint32_t aDuration) const = 0;
180 public:
181 static uuid const& iid() { static uuid const sIid{ 0x692d5ef5, 0xe7b0, 0x497c, 0xaea6, { 0x3f, 0x39, 0xc9, 0xec, 0xef, 0xb4 } }; return sIid; }
182 };
183}
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual handle create_context(const i_render_target &aTarget)=0
virtual bool frame_rate_limited() const =0
virtual void cleanup()=0
virtual void destroy_shader_object(handle aShaderObject)=0
virtual bool is_subpixel_rendering_on() const =0
virtual i_shader_program & active_shader_program()=0
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const point &aPosition, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual uint32_t frame_counter(uint32_t aDuration) const =0
virtual void execute_vertex_buffers()=0
virtual void register_frame_counter(i_widget &aWidget, uint32_t aDuration)=0
virtual bool creating_window() const =0
virtual i_texture_manager & texture_manager()=0
virtual bool is_shader_program_active() const =0
virtual void destroy_context(handle aContext)=0
virtual void initialize()=0
virtual bool use_rendering_priority() const =0
virtual void disable_vsync()=0
virtual const i_device_metrics & default_screen_metrics() const =0
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const point &aPosition, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual bool vertex_buffer_allocated(i_vertex_provider &aProvider) const =0
virtual void activate_context(const i_render_target &aTarget)=0
virtual const i_vertex_buffer & vertex_buffer(i_vertex_provider &aProvider) const =0
virtual uint32_t frame_rate_limit() const =0
virtual i_texture & ping_pong_buffer1(const size &aExtents, size &aPreviousExtents, texture_sampling aSampling=texture_sampling::Multisample)=0
virtual void render_now()=0
virtual ~i_rendering_engine()=default
virtual void enable_frame_rate_limiter(bool aEnable)=0
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const point &aPosition, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual i_vertex_buffer & allocate_vertex_buffer(i_vertex_provider &aProvider, vertex_buffer_type aType=vertex_buffer_type::Default)=0
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const video_mode &aVideoMode, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual void destroy_shader_program_object(handle aShaderProgramObject)=0
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const point &aPosition, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual const i_standard_shader_program & default_shader_program() const =0
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const video_mode &aVideoMode, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual bool vsync_enabled() const =0
virtual void subpixel_rendering_off()=0
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, const video_mode &aVideoMode, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual i_shader_program & add_shader_program(const neolib::i_ref_ptr< i_shader_program > &aShaderProgram)=0
virtual i_shader_program & shader_program(const neolib::i_string &aName)=0
virtual handle create_shader_object(shader_type aShaderType)=0
virtual void deactivate_context()=0
virtual i_vertex_buffer & vertex_buffer(i_vertex_provider &aProvider)=0
virtual const shader_program_list & shader_programs() const =0
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const video_mode &aVideoMode, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual void deallocate_vertex_buffer(i_vertex_provider &aProvider)=0
virtual void subpixel_rendering_on()=0
neolib::i_vector< neolib::i_ref_ptr< i_shader_program > > shader_program_list
virtual void unregister_frame_counter(i_widget &aWidget, uint32_t aDuration)=0
virtual i_standard_shader_program & default_shader_program()=0
virtual handle create_shader_program_object()=0
virtual i_texture & ping_pong_buffer2(const size &aExtents, size &aPreviousExtents, texture_sampling aSampling=texture_sampling::Multisample)=0
virtual void create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle, i_ref_ptr< i_native_window > &aResult)=0
virtual const i_shader_program & shader_program(const neolib::i_string &aName) const =0
virtual neogfx::renderer renderer() const =0
virtual pixel_format_t set_pixel_format(const i_render_target &aTarget)=0
virtual bool process_events()=0
virtual void enable_vsync()=0
virtual const i_render_target * active_target() const =0
virtual i_font_manager & font_manager()=0
ref_ptr< i_native_window > create_window(i_surface_manager &aSurfaceManager, i_surface_window &aWindow, i_native_window &aParent, const size &aDimensions, std::string const &aWindowTitle, window_style aStyle=window_style::Default)
virtual void set_frame_rate_limit(uint32_t aFps)=0
texture_sampling
Definition i_texture.hpp:42
#define declare_event(declName,...)
Definition i_event.hpp:305