Euphoria
state.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <optional>
6
7namespace eu::render
8{
9
13
14
15
17// Forward declaration
18struct FrameBuffer;
19struct TextureCubemap;
20struct Texture2d;
21struct Uniform;
22
23
24
26// Enums
27
50
62
69
70enum class RenderMode
71{
75};
76
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>, kk::max_textures_supported> texture_bound;
139};
140
141
142
144// Changer
145
148{
150
151 explicit StateChanger(State* s);
152
153 StateChanger& cull_face(bool new_state);
154 StateChanger& blending(bool new_state);
155 StateChanger& depth_test(bool new_state);
156 StateChanger& depth_mask(bool new_state);
158 StateChanger& stencil_test(bool new_state);
159
162
171
181 StateChanger& bind_texture_2d(int slot, unsigned int texture);
182 StateChanger& bind_texture_cubemap(int slot, unsigned int texture);
183};
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
192
193} // namespace eu::render
StencilAction
Definition state.h:78
std::tuple< Compare, i32, u32 > StencilFunc
Stencil function state consisiting of the compare function, the ref and the state.
Definition state.h:107
void bind_texture_2d(State *states, const Uniform &uniform, const Texture2d &texture)
std::tuple< Blend, Blend > BlendMode
Blend mode state consisting of src and dst blend functions.
Definition state.h:103
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
@ increase
The stencil value is increased by 1 if it is lower than the maximum value.
Definition state.h:86
@ keep
The currently stored stencil value is kept.
Definition state.h:80
@ invert
Bitwise inverts the current stencil buffer value.
Definition state.h:94
@ replace
The stencil value is replaced with the reference value set with stencil_func.
Definition state.h:84
@ decrease
The stencil value is decreased by 1 if it is higher than the minimum value.
Definition state.h:90
@ increase_wrap
Same as increase, but wraps it back to 0 as soon as the maximum value is exceeded.
Definition state.h:88
@ decrease_wrap
Same as decrease, but wraps it to the maximum value if it ends up lower than 0.
Definition state.h:92
@ uniform
the model source is provided as a mat4 uniform.
@ one_minus_src1_alpha
Definition state.h:48
@ one_minus_dst_color
Definition state.h:35
@ one_minus_constant_color
Definition state.h:41
@ one_minus_dst_alpha
Definition state.h:39
@ one_minus_src_alpha
Definition state.h:37
@ one_minus_src_color
Definition state.h:33
@ one_minus_src1_color
Definition state.h:46
@ one_minus_constant_alpha
Definition state.h:43
constexpr std::size_t max_textures_supported
Definition constants.h:7
Definition ui.h:4
int32_t i32
Definition ints.h:9
uint32_t u32
Definition ints.h:14
"render to texture" feature
Definition texture.h:103
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::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::array< std::optional< unsigned int >, kk::max_textures_supported > texture_bound
Definition state.h:138
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:74
A cubemap texture.
Definition texture.h:90
Represents a found shader uniform and created via ShaderProgram::GetUniform().
Definition uniform.h:9