8#include <unordered_map>
11#include "glm/detail/type_vec.hpp"
12#include "glm/gtc/type_ptr.hpp"
16
17
18
25 void set_bool(
const std::string& name,
const bool value)
const {
26 if (
const GLint location = get_uniform_location(name); location != -1) {
27 glUniform1i(location, value ? 1 : 0);
31 void set_int(
const std::string& name,
const int value)
const {
32 if (
const GLint location = get_uniform_location(name); location != -1) {
33 glUniform1i(location, value);
37 void set_uint(
const std::string& name,
const uint32_t value)
const {
38 if (
const GLint location = get_uniform_location(name); location != -1) {
39 glUniform1ui(location, value);
43 void set_float(
const std::string& name,
const float value)
const {
44 if (
const GLint location = get_uniform_location(name); location != -1) {
45 glUniform1f(location, value);
50 void set_vec2(
const std::string& name,
const glm::vec2& value)
const {
51 if (
const GLint location = get_uniform_location(name); location != -1) {
52 glUniform2fv(location, 1, glm::value_ptr(value));
56 void set_vec3(
const std::string& name,
const glm::vec3& value)
const {
57 if (
const GLint location = get_uniform_location(name); location != -1) {
58 glUniform3fv(location, 1, glm::value_ptr(value));
62 void set_vec4(
const std::string& name,
const glm::vec4& value)
const {
63 if (
const GLint location = get_uniform_location(name); location != -1) {
64 glUniform4fv(location, 1, glm::value_ptr(value));
69 void set_mat2(
const std::string& name,
const glm::mat2& value)
const {
70 if (
const GLint location = get_uniform_location(name); location != -1) {
71 glUniformMatrix2fv(location, 1, GL_FALSE, glm::value_ptr(value));
75 void set_mat3(
const std::string& name,
const glm::mat3& value)
const {
76 if (
const GLint location = get_uniform_location(name); location != -1) {
77 glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(value));
81 void set_mat4(
const std::string& name,
const glm::mat4& value)
const {
82 if (
const GLint location = get_uniform_location(name); location != -1) {
83 glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(value));
88 bool has_uniform(
const std::string& name)
const {
89 return get_uniform_location(name) != -1;
93 uniform_cache_.clear();
104 GLint get_uniform_location(
const std::string& name)
const {
108 if (
const auto it = uniform_cache_.find(name); it != uniform_cache_.end()) {
113 const GLint location = glGetUniformLocation(shader_program_, name.c_str());
114 uniform_cache_[name] = location;
Shader(const uint32_t program_id)
Shader & operator=(const Shader &)=delete
void set_vec3(const std::string &name, const glm::vec3 &value) const
void set_directional_light(const int index, const glm::vec3 &direction, const glm::vec3 &color, const float intensity=1.0f) const
hellfire::ShaderUniformBinder get_binder() const
static Shader from_id(const uint32_t shader_id)
void set_time(const float time) const
Shader & operator=(Shader &&other) noexcept
void set_bool(const std::string &name, const bool value) const
void set_mat2(const std::string &name, const glm::mat2 &value) const
bool has_uniform(const std::string &name) const
void set_float(const std::string &name, const float value) const
void set_view_projection(const glm::mat4 &view, const glm::mat4 &projection) const
void set_mat3(const std::string &name, const glm::mat3 &value) const
Shader(Shader &&other) noexcept
void set_transform_matrices(const glm::mat4 &model, const glm::mat4 &view, const glm::mat4 &projection) const
void set_camera_position(const glm::vec3 &position) const
void set_mat4(const std::string &name, const glm::mat4 &value) const
void set_int(const std::string &name, const int value) const
void set_vec3(const std::string &name, const float x, const float y, const float z) const
void set_point_light(const int index, const glm::vec3 &position, const glm::vec3 &color, const float constant=1.0f, const float linear=0.09f, const float quadratic=0.032f) const
void set_vec4(const std::string &name, float x, float y, float z, float w) const
void set_vec4(const std::string &name, const glm::vec4 &value) const
void set_vec2(const std::string &name, const float x, const float y) const
void set_uint(const std::string &name, const uint32_t value) const
Shader(const Shader &)=delete
void set_light_counts(const int directional_lights, const int point_lights) const
uint32_t get_program_id() const
void set_vec2(const std::string &name, const glm::vec2 &value) const
void set_texture(const std::string &name, const int texture_unit) const
std::vector< std::unique_ptr< IApplicationPlugin > > plugins_
std::function< bool()> exit_condition_
AppInfo & get_window_info()
void on_mouse_move(float x, float y) override
void set_exit_condition(std::function< bool()> condition)
ShaderManager shader_manager_
std::unique_ptr< IWindow > window_
ShaderRegistry shader_registry_
bool call_plugins_until_consumed(Func &&func)
void on_render() override
std::unique_ptr< InputManager > input_manager_
Application(int width=800, int height=600, std::string title="hellfire Application")
void handle_cursor_warping(float x, float y) const
bool handle_first_mouse_movement(float x, float y)
void on_key_up(int key) override
void on_key_down(int key) override
void on_window_minimize(bool minimized) override
void register_plugin(std::unique_ptr< IApplicationPlugin > plugin)
Method for registering plugins.
Shader * ensure_fallback_shader()
void on_mouse_button(int button, bool pressed) override
void call_plugins(Func &&func)
uint32_t create_minimal_fallback_shader()
void on_window_resize(int width, int height) override
Entity & get_owner() const
virtual bool on_mouse_move(float x, float y, float x_offset, float y_offset)
virtual bool on_mouse_button(int button, bool pressed)
virtual void on_end_frame()
virtual bool on_key_down(int key)
virtual void on_begin_frame()
virtual Entity * get_render_camera_override()
virtual void on_initialize(Application &app)
virtual void on_window_resize(int width, int height)
virtual void on_key_up(int keycode)
virtual void on_mouse_move(float x, float y)
virtual void on_window_resize(int width, int height)
virtual ~IWindowEventHandler()=default
virtual void on_key_down(int keycode)
virtual void on_window_minimize(bool minimized)
virtual void on_mouse_button(int button, bool pressed)
virtual void on_mouse_wheel(float delta)
virtual void set_event_handler(IWindowEventHandler *event_handler)=0
virtual bool is_key_pressed(int keycode) const =0
virtual bool should_close() const =0
virtual glm::vec2 get_mouse_position() const =0
virtual ~IWindow()=default
virtual void set_size(int width, int height)=0
virtual void poll_events()=0
virtual glm::ivec2 get_framebuffer_size() const =0
virtual void set_title(const std::string &title)=0
virtual void swap_buffers()=0
virtual void enable_vsync(bool vsync)=0
virtual glm::ivec2 get_size() const =0
virtual void * get_native_handle()=0
virtual void warp_cursor(double x, double y)=0
virtual void set_cursor_mode(CursorMode mode)=0
virtual bool create(int width, int height, const std::string &title)=0
virtual float get_elapsed_time()=0
virtual void wait_for_events()=0
virtual void make_current()=0
void upload_directional_to_shader(Shader &shader, const int light_index) const
void set_outer_cone_angle(const float angle)
void set_intensity(const float intensity)
float get_inner_cone_angle() const
float get_attenuation() const
void set_color(const glm::vec3 &color)
LightComponent(const LightType type=DIRECTIONAL)
float get_outer_cone_angle() const
LightType get_light_type() const
void look_at(const glm::vec3 &target)
void look_at(const float x, const float y, const float z)
void upload_to_shader(Shader &shader, const int light_index) const
void set_inner_cone_angle(const float angle)
void set_range(const float range)
void set_attenuation(const float attenuation)
bool should_cast_shadows() const
glm::mat4 light_view_proj_matrix
const glm::vec3 & get_color() const
void upload_spot_to_shader(Shader &shader, int light_index) const
void set_direction(const float x, const float y, const float z)
void set_cast_shadows(const bool cast_shadows)
void set_light_type(const LightType type)
const glm::vec3 & get_direction()
void set_light_view_proj_matrix(const glm::mat4 &lvpm)
void set_direction(const glm::vec3 &direction)
const float & get_intensity() const
void upload_point_to_shader(Shader &shader, const int light_index) const
const glm::mat4 & get_light_view_proj_matrix() const
Entity * directional_light_entities[4]
int num_directional_lights
CameraComponent * camera_component
Entity * point_light_entities[8]
void draw_render_command(const RenderCommand &cmd, const glm::mat4 &view, const glm::mat4 &projection)
ShaderRegistry & get_shader_registry()
void ensure_shadow_map(Entity *light_entity, const LightComponent &light)
Shader & get_shader_for_material(const std::shared_ptr< Material > &material)
SkyboxRenderer skybox_renderer_
ShaderRegistry shader_registry_
void set_render_to_framebuffer(bool enable)
ShadowSettings shadow_settings_
std::vector< InstancedRenderCommand > opaque_instanced_objects_
bool render_to_framebuffer_
void execute_skybox_pass(Scene *scene, const glm::mat4 &view, const glm::mat4 &projection, CameraComponent *camera_comp) const
uint32_t get_object_id_texture() const
glm::mat4 calculate_light_view_proj(Entity *light_entity, LightComponent *light, const CameraComponent &camera)
std::shared_ptr< Material > shadow_material_
void draw_instanced_command(const InstancedRenderCommand &cmd, const glm::mat4 &view, const glm::mat4 &projection)
void render(Scene &scene, const Entity *camera_override)
void collect_geometry_from_scene(Scene &scene, const glm::vec3 camera_pos)
void execute_shadow_passes(Scene &scene, CameraComponent &camera)
std::unique_ptr< Framebuffer > scene_framebuffers_[2]
Shader * fallback_shader_
uint32_t fallback_program_
std::vector< RenderCommand > opaque_objects_
uint32_t get_main_output_texture() const
void resize_main_framebuffer(uint32_t width, uint32_t height)
ShaderManager shader_manager_
void execute_transparency_pass(const glm::mat4 &view, const glm::mat4 &proj)
void reset_framebuffer_data()
void execute_main_pass(Scene &scene, CameraComponent &camera)
ShadowSettings & get_shadow_settings()
uint32_t framebuffer_width_
void render_frame(Scene &scene, CameraComponent &camera)
void execute_geometry_pass(const glm::mat4 &view, const glm::mat4 &proj)
void collect_lights_from_scene(Scene &scene, CameraComponent &camera)
void store_lights_in_context(const std::vector< Entity * > &light_entities, CameraComponent &camera)
uint32_t framebuffer_height_
std::vector< RenderCommand > transparent_objects_
void draw_shadow_geometry(const glm::mat4 &light_view_proj)
std::unordered_map< Entity *, ShadowMapData > shadow_maps_
void set_fallback_shader(Shader &fallback_shader)
std::unique_ptr< OGLRendererContext > context_
void collect_render_commands_recursive(EntityID entity_id, const glm::vec3 &camera_pos)
std::vector< InstancedRenderCommand > transparent_instanced_objects_
void create_main_framebuffer(uint32_t width, uint32_t height)
Shader * get_fallback_shader() const
uint32_t compile_material_shader(std::shared_ptr< Material > material)
ShaderManager & get_shader_manager()
bool has_active_scene() const
void destroy_scene(Scene *scene)
CameraComponent * get_active_camera() const
void save_current_scene()
bool save_scene(Scene *scene)
Scene * create_scene(const std::string &name="GameScene")
Scene * load_scene(const std::filesystem::path &filename)
void create_default_scene()
std::optional< AssetID > get_scene_asset_id(Scene *scene) const
void set_active_camera(EntityID camera) const
void set_scene_asset_id(Scene *scene, AssetID id)
std::optional< AssetID > get_active_scene_asset_id() const
SceneActivatedCallback scene_activated_callback_
Scene * get_active_scene() const
void set_active_scene(Scene *scene, bool should_play=true)
bool save_scene_as(const std::string &filename, Scene *scene)
std::vector< Scene * > scenes_
std::vector< Scene * > get_scenes()
std::unordered_map< Scene *, AssetID > scene_asset_ids_
EntityID find_entity_by_name(const std::string &name)
std::vector< EntityID > get_camera_entities() const
Scene * load_scene(AssetID asset_id, const std::filesystem::path &filename)
void set_scene_activated_callback(SceneActivatedCallback callback)
void update(float delta_time)
Manages a collection of entities and their hierarchical relationships.
bool operator<(const RenderCommand &other) const
InstancedRenderableComponent * instanced_renderable
std::shared_ptr< Material > material
std::shared_ptr< Material > material
std::shared_ptr< Mesh > mesh
bool operator<(const RenderCommand &other) const
std::unique_ptr< Framebuffer > framebuffer
glm::mat4 light_view_proj