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
>
23
#include <
neogfx/gfx/i_rendering_context.hpp
>
24
#include <
neogfx/gfx/shader.hpp
>
25
#include <
neogfx/gfx/i_vertex_shader.hpp
>
26
#include <
neogfx/gfx/i_shader_program.hpp
>
27
28
namespace
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
:
35
typedef
neolib::map<string, abstract_t<shader_variable>
*>
attribute_map
;
36
public
:
37
vertex_shader
(std::string
const
& aName) :
38
base_type
{
shader_type
::
Vertex
, 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);
55
base_type::set_dirty
();
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
{
61
auto
&
in
=
base_type::add_variable
(
62
shader_variable
63
{
64
aName,
65
aLocation,
66
aFlat ?
shader_variable_qualifier::In
|
shader_variable_qualifier::Flat
:
shader_variable_qualifier::In
,
67
aType
68
});
69
iAttributes.
emplace
(aName, &
in
);
70
base_type::set_dirty
();
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
100
class
standard_texture_vertex_shader
:
public
standard_vertex_shader
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
}
neogfx::i_rendering_context
Definition
i_rendering_context.hpp:35
neogfx::i_shader_program
Definition
i_shader_program.hpp:69
neogfx::shader
Definition
shader.hpp:37
neogfx::shader::set_dirty
void set_dirty() final
Definition
shader.hpp:148
neogfx::shader::add_variable
i_shader_variable & add_variable(const i_shader_variable &aVariable) final
Definition
shader.hpp:247
neogfx::shader::in_variables
const variable_list & in_variables() const final
Definition
shader.hpp:224
neogfx::standard_texture_vertex_shader
Definition
vertex_shader.hpp:101
neogfx::standard_texture_vertex_shader::generate_code
void generate_code(const i_shader_program &aProgram, shader_language aLanguage, i_string &aOutput) const override
neogfx::standard_texture_vertex_shader::standard_texture_vertex_shader
standard_texture_vertex_shader(std::string const &aName="standard_texture_vertex_shader")
neogfx::standard_vertex_shader
Definition
vertex_shader.hpp:78
neogfx::standard_vertex_shader::prepare_uniforms
void prepare_uniforms(const i_rendering_context &aContext, i_shader_program &aProgram) override
neogfx::standard_vertex_shader::standard_vertex_shader
standard_vertex_shader(std::string const &aName="standard_vertex_shader")
neogfx::standard_vertex_shader::set_projection_matrix
void set_projection_matrix(const optional_mat44 &aProjectionMatrix) final
neogfx::standard_vertex_shader::set_transformation_matrix
void set_transformation_matrix(const optional_mat44 &aTransformationMatrix) final
neogfx::standard_vertex_shader::generate_code
void generate_code(const i_shader_program &aProgram, shader_language aLanguage, i_string &aOutput) const override
neogfx::standard_vertex_shader::set_opacity
void set_opacity(scalar aOpacity) final
neogfx::vertex_shader
Definition
vertex_shader.hpp:32
neogfx::vertex_shader::attributes
const attribute_map & attributes() const final
Definition
vertex_shader.hpp:42
neogfx::vertex_shader::add_attribute
i_shader_variable & add_attribute(const i_string &aName, uint32_t aLocation, bool aFlat, shader_data_type aType) final
Definition
vertex_shader.hpp:59
neogfx::vertex_shader::clear_attribute
void clear_attribute(const i_string &aName) final
Definition
vertex_shader.hpp:46
neogfx::vertex_shader::attribute_map
neolib::map< string, abstract_t< shader_variable > * > attribute_map
Definition
vertex_shader.hpp:35
neogfx::vertex_shader::vertex_shader
vertex_shader(std::string const &aName)
Definition
vertex_shader.hpp:37
neolib::i_string
Definition
i_string.hpp:49
neolib::map
Definition
map.hpp:48
neolib::map::emplace
value_type & emplace(Key2 &&aKey, Args &&... aArgs)
Definition
map.hpp:180
neolib::optional< mat44 >
i_rendering_context.hpp
i_shader_program.hpp
i_vertex_shader.hpp
neogfx
Definition
action.hpp:28
neogfx::shader_data_type
shader_data_type
Definition
i_shader.hpp:69
neogfx::shader_variable_qualifier::Flat
@ Flat
neogfx::shader_variable_qualifier::In
@ In
neogfx::in
basic_length< T > in(T aValue)
Definition
units.hpp:732
neogfx::shader_type
shader_type
Definition
i_shader.hpp:36
neogfx::shader_type::Vertex
@ Vertex
neogfx::shader_language
shader_language
Definition
i_shader.hpp:64
neolib::math::scalar
double scalar
Definition
numerical.hpp:63
neogfx.hpp
shader.hpp
cache_uniform
#define cache_uniform(uniformName)
Definition
shader.hpp:32
include
neogfx
gfx
vertex_shader.hpp
Generated by
1.9.8