neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
shader_program.hpp
Go to the documentation of this file.
1// shader_program.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2019, 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>
24#include <neolib/core/map.hpp>
27
28namespace neogfx
29{
30 template <typename Base = i_shader_stage>
31 class shader_stage : public reference_counted<Base>
32 {
33 public:
38 public:
40 public:
41 shader_type type() const override;
42 shaders_t const& shaders() const override;
43 shaders_t& shaders() override;
44 private:
45 shader_type iType;
46 shaders_t iShaders;
47 };
48
49 template <typename Base = i_shader_program>
50 class shader_program : public reference_counted<Base>
51 {
52 public:
58 public:
66 private:
67 typedef std::map<neolib::string, shader_t> shader_index;
68 public:
69 shader_program(const std::string aName);
71 public:
72 const i_string& name() const override;
73 bool supports(vertex_buffer_type aBufferType) const override;
74 bool created() const override;
75 void* handle() const override;
76 const stages_t& stages() const override;
77 stages_t& stages() override;
78 const stage_t& stage(shader_type aStage) const override;
79 stage_t& stage(shader_type aStage) override;
80 const i_shader& shader(const neolib::i_string& aName) const override;
81 i_shader& shader(const neolib::i_string& aName) override;
82 const i_vertex_shader& vertex_shader() const override;
84 const i_fragment_shader& fragment_shader() const override;
86 bool is_first_in_stage(const i_shader& aShader) const override;
87 bool is_last_in_stage(const i_shader& aShader) const override;
88 const i_shader& first_in_stage(shader_type aStage) const override;
89 const i_shader& next_in_stage(const i_shader& aPreviousShader) const override;
90 const i_shader& last_in_stage(shader_type aStage) const override;
91 i_shader& add_shader(const neolib::i_ref_ptr<i_shader>& aShader) override;
92 bool dirty() const override;
93 void set_clean() override;
94 void prepare_uniforms(const i_rendering_context& aContext) override;
95 void make() override;
96 bool uniforms_changed() const override;
97 bool active() const override;
98 void activate(const i_rendering_context& aContext) override;
99 void instantiate(const i_rendering_context& aContext) override;
100 protected:
101 bool need_full_uniform_update() const;
102 void set_active();
103 void set_inactive();
104 private:
105 string iName;
106 mutable std::optional<void*> iHandle;
107 stages_t iStages;
108 shader_index iShaderIndex;
109 mutable bool iNeedFullUniformUpdate;
110 bool iActive;
111 };
112}
113
114#include "shader_program.inl"
virtual void update_uniforms(const i_rendering_context &aContext)=0
virtual void compile()=0
virtual void use()=0
virtual void update_uniform_storage()=0
virtual void update_uniform_locations()=0
bool have_stage(shader_type aStage) const
virtual void link()=0
const i_fragment_shader & fragment_shader() const override
const i_string & name() const override
const stage_t & stage(shader_type aStage) const override
i_shader & add_shader(const neolib::i_ref_ptr< i_shader > &aShader) override
bool need_full_uniform_update() const
void prepare_uniforms(const i_rendering_context &aContext) override
neolib::vector< stage_t > stages_t
const i_shader & first_in_stage(shader_type aStage) const override
bool is_first_in_stage(const i_shader &aShader) const override
void * handle() const override
bool is_last_in_stage(const i_shader &aShader) const override
const i_vertex_shader & vertex_shader() const override
bool uniforms_changed() const override
bool created() const override
bool supports(vertex_buffer_type aBufferType) const override
void activate(const i_rendering_context &aContext) override
const stages_t & stages() const override
const i_shader & last_in_stage(shader_type aStage) const override
const i_shader & next_in_stage(const i_shader &aPreviousShader) const override
neolib::ref_ptr< i_shader > shader_t
void instantiate(const i_rendering_context &aContext) override
neolib::ref_ptr< i_shader_stage > stage_t
bool dirty() const override
bool active() const override
neolib::ref_ptr< i_shader > shader_t
neolib::vector< shader_t > shaders_t
shader_type type() const override
shaders_t const & shaders() const override