Euphoria
state.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <optional>
6
7namespace eu::render
8{
9
17// Forward declaration
18struct FrameBuffer;
19struct TextureCubemap;
20struct Texture2d;
21struct Uniform;
22
23
24
26// Enums
27
50
51enum class Compare
52{
53 always,
54 never,
55 less,
56 equal,
58 greater,
61};
62
63enum class CullFace
64{
65 front,
66 back,
68};
69
70enum class RenderMode
71{
72 fill,
73 line,
74 point
75};
76
77enum class StencilAction
78{
80 keep,
82 zero,
84 replace,
94 invert
95};
96
97
98
100// Alias
101
103using BlendMode = std::tuple<Blend, Blend>;
104
107using StencilFunc = std::tuple<Compare, i32, u32>;
108
110using StencilOp = std::tuple<StencilAction, StencilAction, StencilAction>;
111
112
113
115// State
116
118struct State
119{
120 std::optional<bool> cull_face;
121 std::optional<CullFace> cull_face_mode;
122
123 std::optional<bool> blending;
124 std::optional<BlendMode> blend_mode;
125
126 std::optional<bool> depth_test;
127 std::optional<bool> depth_mask;
128 std::optional<Compare> depth_func;
129
130 std::optional<bool> stencil_test;
131 std::optional<u32> stencil_mask;
132
133 std::optional<RenderMode> render_mode;
134 std::optional<StencilFunc> stencil_func;
135 std::optional<StencilOp> stencil_op;
136
137 std::optional<int> active_texture;
138 std::array<std::optional<unsigned int>, MAX_TEXTURES_SUPPORTED> texture_bound;
139};
140
141
142
144// Changer
145
184
185void bind_texture_2d(State* states, const Uniform& uniform, const Texture2d& texture);
186void bind_texture_2d(State* states, const Uniform& uniform, const FrameBuffer& texture);
187void bind_texture_cubemap(State* states, const Uniform& uniform, const TextureCubemap& texture);
188
193} // namespace eu::render
StencilAction
Definition state.h:78
void bind_texture_2d(State *states, const Uniform &uniform, const Texture2d &texture)
void bind_texture_cubemap(State *states, const Uniform &uniform, const TextureCubemap &texture)
std::tuple< StencilAction, StencilAction, StencilAction > StencilOp
Stencil operation state consisting of the stencil fail, depth fail and the pass action.
Definition state.h:110
std::tuple< Compare, i32, u32 > StencilFunc
Stencil function state consisiting of the compare function, the ref and the state.
Definition state.h:107
std::tuple< Blend, Blend > BlendMode
Blend mode state consisting of src and dst blend functions.
Definition state.h:103
@ increase
The stencil value is increased by 1 if it is lower than the maximum value.
@ keep
The currently stored stencil value is kept.
@ invert
Bitwise inverts the current stencil buffer value.
@ replace
The stencil value is replaced with the reference value set with stencil_func.
@ decrease
The stencil value is decreased by 1 if it is higher than the minimum value.
@ increase_wrap
Same as increase, but wraps it back to 0 as soon as the maximum value is exceeded.
@ decrease_wrap
Same as decrease, but wraps it to the maximum value if it ends up lower than 0.
@ Uniform
the model source is provided as a mat4 uniform.
Definition ui.h:4
constexpr std::size_t MAX_TEXTURES_SUPPORTED
Definition constants.h:7
std::int32_t i32
Definition ints.h:9
std::uint32_t u32
Definition ints.h:14
A (inclusive) range between two values.
Definition range.h:19
"render to texture" feature
Definition texture.h:101
A helper class to change both the opengl state and the cache.
Definition state.h:148
StateChanger & depth_func(Compare new_state)
StateChanger & blending(bool new_state)
StateChanger & cull_face(bool new_state)
StateChanger & cull_face_mode(CullFace new_state)
StateChanger & render_mode(RenderMode new_state)
StateChanger & stencil_func(Compare func, i32 ref, u32 mask)
StateChanger & depth_mask(bool new_state)
StateChanger & activate_texture(int new_texture)
StateChanger & stencil_op(StencilAction stencil_fail, StencilAction depth_fail, StencilAction pass)
StateChanger & bind_texture_cubemap(int slot, unsigned int texture)
StateChanger & bind_texture_2d(int slot, unsigned int texture)
StateChanger & stencil_test(bool new_state)
StateChanger & stencil_mask(u32 new_state)
Set a bitmask that is ANDed with the stencil value about to be written to the buffer.
StateChanger & blend_mode(Blend src, Blend dst)
StateChanger & depth_test(bool new_state)
A "cache" for the current open gl state.
Definition state.h:119
std::optional< StencilFunc > stencil_func
Definition state.h:134
std::optional< bool > blending
Definition state.h:123
std::optional< Compare > depth_func
Definition state.h:128
std::array< std::optional< unsigned int >, MAX_TEXTURES_SUPPORTED > texture_bound
Definition state.h:138
std::optional< bool > depth_test
Definition state.h:126
std::optional< RenderMode > render_mode
Definition state.h:133
std::optional< bool > cull_face
Definition state.h:120
std::optional< bool > depth_mask
Definition state.h:127
std::optional< BlendMode > blend_mode
Definition state.h:124
std::optional< int > active_texture
Definition state.h:137
std::optional< u32 > stencil_mask
Definition state.h:131
std::optional< CullFace > cull_face_mode
Definition state.h:121
std::optional< StencilOp > stencil_op
Definition state.h:135
std::optional< bool > stencil_test
Definition state.h:130
A 2d image texture.
Definition texture.h:72
A cubemap texture.
Definition texture.h:88
Represents a found shader uniform and created via ShaderProgram::GetUniform()
Definition uniform.h:9