neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
vertex_shader.hpp
Go to the documentation of this file.
1// vertex_shader.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 <neogfx/gfx/shader.hpp>
27
28namespace neogfx
29{
30 template <typename Base = i_vertex_shader>
31 class vertex_shader : public shader<Base>
32 {
33 typedef shader<Base> base_type;
34 public:
36 public:
37 vertex_shader(std::string const& aName) :
39 {
40 }
41 public:
42 const attribute_map& attributes() const final
43 {
44 return iAttributes;
45 }
46 void clear_attribute(const i_string& aName) final
47 {
48 auto a = iAttributes.find(aName);
49 if (a != iAttributes.end())
50 {
51 iAttributes.erase(a);
52 auto v = base_type::in_variables().find(*a->second());
53 if (v != base_type::in_variables().end())
54 base_type::in_variables().erase(v);
56 }
57 }
58 using base_type::add_attribute;
59 i_shader_variable& add_attribute(const i_string& aName, uint32_t aLocation, bool aFlat, shader_data_type aType) final
60 {
62 shader_variable
63 {
64 aName,
65 aLocation,
67 aType
68 });
69 iAttributes.emplace(aName, &in);
71 return in;
72 }
73 private:
74 attribute_map iAttributes;
75 };
76
77 class standard_vertex_shader : public vertex_shader<i_standard_vertex_shader>
78 {
79 public:
80 standard_vertex_shader(std::string const& aName = "standard_vertex_shader");
81 public:
82 void set_projection_matrix(const optional_mat44& aProjectionMatrix) final;
83 void set_transformation_matrix(const optional_mat44& aTransformationMatrix) final;
84 void set_opacity(scalar aOpacity) final;
85 public:
86 void prepare_uniforms(const i_rendering_context& aContext, i_shader_program& aProgram) override;
87 void generate_code(const i_shader_program& aProgram, shader_language aLanguage, i_string& aOutput) const override;
88 private:
89 optional_mat44 iProjectionMatrix;
90 optional_mat44 iTransformationMatrix;
91 scalar iOpacity;
92 private:
93 cache_uniform(uProjectionMatrix)
94 cache_uniform(uTransformationMatrix)
95 cache_uniform(uOpacity)
96 optional_logical_coordinates iLogicalCoordinates;
97 optional_vec2 iOffset;
98 };
99
101 {
102 public:
103 standard_texture_vertex_shader(std::string const& aName = "standard_texture_vertex_shader");
104 public:
105 void generate_code(const i_shader_program& aProgram, shader_language aLanguage, i_string& aOutput) const override;
106 };
107}
void set_dirty() final
Definition shader.hpp:148
i_shader_variable & add_variable(const i_shader_variable &aVariable) final
Definition shader.hpp:247
const variable_list & in_variables() const final
Definition shader.hpp:224
void generate_code(const i_shader_program &aProgram, shader_language aLanguage, i_string &aOutput) const override
standard_texture_vertex_shader(std::string const &aName="standard_texture_vertex_shader")
void prepare_uniforms(const i_rendering_context &aContext, i_shader_program &aProgram) override
standard_vertex_shader(std::string const &aName="standard_vertex_shader")
void set_projection_matrix(const optional_mat44 &aProjectionMatrix) final
void set_transformation_matrix(const optional_mat44 &aTransformationMatrix) final
void generate_code(const i_shader_program &aProgram, shader_language aLanguage, i_string &aOutput) const override
void set_opacity(scalar aOpacity) final
const attribute_map & attributes() const final
i_shader_variable & add_attribute(const i_string &aName, uint32_t aLocation, bool aFlat, shader_data_type aType) final
void clear_attribute(const i_string &aName) final
neolib::map< string, abstract_t< shader_variable > * > attribute_map
vertex_shader(std::string const &aName)
value_type & emplace(Key2 &&aKey, Args &&... aArgs)
Definition map.hpp:180
shader_data_type
Definition i_shader.hpp:69
basic_length< T > in(T aValue)
Definition units.hpp:732
shader_language
Definition i_shader.hpp:64
double scalar
Definition numerical.hpp:63
#define cache_uniform(uniformName)
Definition shader.hpp:32