shader_effect_description.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Kenneth Gangstoe
28 */
29
30
31 #pragma once
32
33 #include <memory>
34 #include "../Render/graphic_context.h"
35 #include "../Render/rasterizer_state_description.h"
36 #include "../Render/blend_state_description.h"
37 #include "../Render/depth_stencil_state_description.h"
38 #include "../Render/storage_buffer.h"
39 #include "../Render/uniform_buffer.h"
40 #include "../Render/texture.h"
41 #include "../Render/render_buffer.h"
42 #include "../../Core/Resources/resource.h"
43
44 namespace clan
45 {
48
49 class ShaderEffectDescription_Impl;
50
54 class ShaderEffectDescription
55 {
58 public:
59 ShaderEffectDescription();
61
64 public:
66
69 public:
70 void set_glsl_version(int version = 330);
71
72 void set_define(std::string name, std::string value = "1");
73
74 void set_vertex_shader(std::string code, ShaderLanguage language = shader_glsl);
75 void set_fragment_shader(std::string code, ShaderLanguage language = shader_glsl);
76 void set_compute_shader(std::string code, ShaderLanguage language = shader_glsl);
77
78 RasterizerStateDescription &rasterizer();
79 BlendStateDescription &blend();
80 DepthStencilStateDescription &depth_stencil();
81
82 void set_frag_data(std::string name, RenderBuffer buffer);
83 void set_frag_data(std::string name, Texture texture);
84 void set_frag_data_to_back_buffer(std::string name);
85
86 void set_depth_data(RenderBuffer buffer);
87 void set_depth_data(Texture texture);
88
89 void set_stencil_data(RenderBuffer buffer);
90 void set_stencil_data(Texture texture);
91
92 void set_texture(std::string name, Resource<Texture> texture);
93 void set_image(std::string name, Resource<Texture> texture);
94
95 void set_storage(std::string name, Resource<StorageBuffer> values);
96
97 void set_uniform_block(std::string name, Resource<UniformBuffer> values);
98
99 void set_attribute(std::string name, VertexArrayBuffer &buffer, int size, VertexAttributeDataType type, size_t offset = 0, int stride = 0, bool normalize = false);
100
101 void set_attribute(std::string name, VertexArrayVector<unsigned char> &buffer, int size, bool normalize = false)
102 {
103 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_byte, 0, 0, normalize);
104 }
105
106 void set_attribute(std::string name, VertexArrayVector<char> &buffer, int size, bool normalize = false)
107 {
108 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_byte, 0, 0, normalize);
109 }
110
111 void set_attribute(std::string name, VertexArrayVector<unsigned short> &buffer, int size, bool normalize = false)
112 {
113 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_short, 0, 0, normalize);
114 }
115
116 void set_attribute(std::string name, VertexArrayVector<short> &buffer, int size, bool normalize = false)
117 {
118 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_short, 0, 0, normalize);
119 }
120
121 void set_attribute(std::string name, VertexArrayVector<unsigned int> &buffer, int size, bool normalize = false)
122 {
123 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_int, 0, 0, normalize);
124 }
125
126 void set_attribute(std::string name, VertexArrayVector<int> &buffer, int size, bool normalize = false)
127 {
128 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_int, 0, 0, normalize);
129 }
130
131 void set_attribute(std::string name, VertexArrayVector<float> &buffer, int size, bool normalize = false)
132 {
133 set_attribute(name, (VertexArrayBuffer&)buffer, size, type_float, 0, 0, normalize);
134 }
135
136 void set_attribute(std::string name, VertexArrayVector<unsigned char> &buffer, bool normalize = false)
137 {
138 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_byte, 0, sizeof(unsigned char), normalize);
139 }
140
141 void set_attribute(std::string name, VertexArrayVector<signed char> &buffer, bool normalize = false)
142 {
143 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_byte, 0, sizeof(signed char), normalize);
144 }
145
146 void set_attribute(std::string name, VertexArrayVector<unsigned short> &buffer, bool normalize = false)
147 {
148 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_short, 0, sizeof(unsigned short), normalize);
149 }
150
151 void set_attribute(std::string name, VertexArrayVector<signed short> &buffer, bool normalize = false)
152 {
153 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_short, 0, sizeof(signed short), normalize);
154 }
155
156 void set_attribute(std::string name, VertexArrayVector<unsigned int> &buffer, bool normalize = false)
157 {
158 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_int, 0, sizeof(unsigned int), normalize);
159 }
160
161 void set_attribute(std::string name, VertexArrayVector<signed int> &buffer, bool normalize = false)
162 {
163 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_int, 0, sizeof(signed int), normalize);
164 }
165
166 void set_attribute(std::string name, VertexArrayVector<float> &buffer)
167 {
168 set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_float, 0, sizeof(float), false);
169 }
170
171 void set_attribute(std::string name, VertexArrayVector<Vec2ub> &buffer, bool normalize = false)
172 {
173 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_byte, 0, sizeof(Vec2ub), normalize);
174 }
175
176 void set_attribute(std::string name, VertexArrayVector<Vec2b> &buffer, bool normalize = false)
177 {
178 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_byte, 0, sizeof(Vec2b), normalize);
179 }
180
181 void set_attribute(std::string name, VertexArrayVector<Vec2us> &buffer, bool normalize = false)
182 {
183 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_short, 0, sizeof(Vec2us), normalize);
184 }
185
186 void set_attribute(std::string name, VertexArrayVector<Vec2s> &buffer, bool normalize = false)
187 {
188 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_short, 0, sizeof(Vec2s), normalize);
189 }
190
191 void set_attribute(std::string name, VertexArrayVector<Vec2ui> &buffer, bool normalize = false)
192 {
193 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_int, 0, sizeof(Vec2ui), normalize);
194 }
195
196 void set_attribute(std::string name, VertexArrayVector<Vec2i> &buffer, bool normalize = false)
197 {
198 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_int, 0, sizeof(Vec2i), normalize);
199 }
200
201 void set_attribute(std::string name, VertexArrayVector<Vec2f> &buffer)
202 {
203 set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_float, 0, sizeof(Vec2f), false);
204 }
205
206 void set_attribute(std::string name, VertexArrayVector<Vec3ub> &buffer, bool normalize = false)
207 {
208 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_byte, 0, sizeof(Vec3ub), normalize);
209 }
210
211 void set_attribute(std::string name, VertexArrayVector<Vec3b> &buffer, bool normalize = false)
212 {
213 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_byte, 0, sizeof(Vec3b), normalize);
214 }
215
216 void set_attribute(std::string name, VertexArrayVector<Vec3us> &buffer, bool normalize = false)
217 {
218 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_short, 0, sizeof(Vec3us), normalize);
219 }
220
221 void set_attribute(std::string name, VertexArrayVector<Vec3s> &buffer, bool normalize = false)
222 {
223 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_short, 0, sizeof(Vec3s), normalize);
224 }
225
226 void set_attribute(std::string name, VertexArrayVector<Vec3ui> &buffer, bool normalize = false)
227 {
228 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_int, 0, sizeof(Vec3ui), normalize);
229 }
230
231 void set_attribute(std::string name, VertexArrayVector<Vec3i> &buffer, bool normalize = false)
232 {
233 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_int, 0, sizeof(Vec3i), normalize);
234 }
235
236 void set_attribute(std::string name, VertexArrayVector<Vec3f> &buffer)
237 {
238 set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_float, 0, sizeof(Vec3f), false);
239 }
240
241 void set_attribute(std::string name, VertexArrayVector<Vec4ub> &buffer, bool normalize = false)
242 {
243 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_byte, 0, sizeof(Vec4ub), normalize);
244 }
245
246 void set_attribute(std::string name, VertexArrayVector<Vec4b> &buffer, bool normalize = false)
247 {
248 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_byte, 0, sizeof(Vec4b), normalize);
249 }
250
251 void set_attribute(std::string name, VertexArrayVector<Vec4us> &buffer, bool normalize = false)
252 {
253 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_short, 0, sizeof(Vec4us), normalize);
254 }
255
256 void set_attribute(std::string name, VertexArrayVector<Vec4s> &buffer, bool normalize = false)
257 {
258 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_short, 0, sizeof(Vec4s), normalize);
259 }
260
261 void set_attribute(std::string name, VertexArrayVector<Vec4ui> &buffer, bool normalize = false)
262 {
263 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_int, 0, sizeof(Vec4ui), normalize);
264 }
265
266 void set_attribute(std::string name, VertexArrayVector<Vec4i> &buffer, bool normalize = false)
267 {
268 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_int, 0, sizeof(Vec4i), normalize);
269 }
270
271 void set_attribute(std::string name, VertexArrayVector<Vec4f> &buffer)
272 {
273 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_float, 0, sizeof(Vec4f), false);
274 }
275
276 void set_attribute(std::string name, VertexArrayVector<Colorf> &buffer)
277 {
278 set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_float, 0, sizeof(Colorf), false);
279 }
280
281 void set_attribute_screen_quad(std::string name);
282 void set_attribute_uv_quad(std::string name);
283
284 void set_elements(ElementArrayBuffer &element_array, VertexAttributeDataType indices_type);
285
286 void set_elements(ElementArrayVector<unsigned int> &element_array)
287 {
288 set_elements(element_array, type_unsigned_int);
289 }
290
291 void set_elements(ElementArrayVector<unsigned short> &element_array)
292 {
293 set_elements(element_array, type_unsigned_short);
294 }
295
296 void set_elements(ElementArrayVector<unsigned char> &element_array)
297 {
298 set_elements(element_array, type_unsigned_byte);
299 }
300
301 void set_draw_count(int count);
302
304
307 private:
308 std::shared_ptr<ShaderEffectDescription_Impl> impl;
310
311 friend class ShaderEffect;
312 };
313
314 }
315
clan::RasterizerStateDescription
Rasterizer state description.
Definition: rasterizer_state_description.h:42
clan
Definition: clanapp.h:35
clan::Colorf
Floating point color description class (for float).
Definition: color.h:660
clan::type_float
Definition: primitives_array.h:64
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:206
clan::ShaderEffectDescription::set_elements
void set_elements(ElementArrayVector< unsigned char > &element_array)
Definition: shader_effect_description.h:296
clan::ShaderEffectDescription::depth_stencil
DepthStencilStateDescription & depth_stencil()
clan::Resource
Resource proxy of a specific type.
Definition: resource.h:58
clan::ShaderEffectDescription::set_uniform_block
void set_uniform_block(std::string name, Resource< UniformBuffer > values)
clan::ShaderEffectDescription::blend
BlendStateDescription & blend()
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:191
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< char > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:106
clan::VertexArrayBuffer
Vertex Array Buffer.
Definition: vertex_array_buffer.h:46
clan::BlendStateDescription
Blend state description.
Definition: blend_state_description.h:42
clan::Texture
Texture object class.
Definition: texture.h:103
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< float > &buffer)
Definition: shader_effect_description.h:166
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:186
clan::ShaderEffectDescription::set_frag_data_to_back_buffer
void set_frag_data_to_back_buffer(std::string name)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Colorf > &buffer)
Definition: shader_effect_description.h:276
clan::ShaderEffectDescription::set_texture
void set_texture(std::string name, Resource< Texture > texture)
clan::ElementArrayVector
Element Array Vector.
Definition: element_array_vector.h:43
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< signed char > &buffer, bool normalize=false)
Definition: shader_effect_description.h:141
clan::type_short
Definition: primitives_array.h:62
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:221
clan::ShaderEffectDescription::set_stencil_data
void set_stencil_data(RenderBuffer buffer)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned short > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:111
clan::ShaderEffectDescription
Shader Effect Description.
Definition: shader_effect_description.h:54
clan::ShaderEffectDescription::set_glsl_version
void set_glsl_version(int version=330)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned int > &buffer, bool normalize=false)
Definition: shader_effect_description.h:156
clan::ShaderEffectDescription::set_elements
void set_elements(ElementArrayBuffer &element_array, VertexAttributeDataType indices_type)
clan::ShaderEffectDescription::set_draw_count
void set_draw_count(int count)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayBuffer &buffer, int size, VertexAttributeDataType type, size_t offset=0, int stride=0, bool normalize=false)
clan::ShaderLanguage
ShaderLanguage
Shader language used.
Definition: graphic_context.h:248
clan::ShaderEffectDescription::rasterizer
RasterizerStateDescription & rasterizer()
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned char > &buffer, bool normalize=false)
Definition: shader_effect_description.h:136
clan::ShaderEffectDescription::ShaderEffectDescription
ShaderEffectDescription()
clan::ShaderEffectDescription::set_attribute_uv_quad
void set_attribute_uv_quad(std::string name)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:196
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:261
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:251
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:181
clan::ShaderEffectDescription::set_elements
void set_elements(ElementArrayVector< unsigned short > &element_array)
Definition: shader_effect_description.h:291
clan::ShaderEffectDescription::set_depth_data
void set_depth_data(RenderBuffer buffer)
clan::StyleTokenType::string
@ keyword
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:211
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:266
clan::ShaderEffectDescription::set_compute_shader
void set_compute_shader(std::string code, ShaderLanguage language=shader_glsl)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:241
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< int > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:126
clan::type_unsigned_byte
Definition: primitives_array.h:58
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:246
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< signed int > &buffer, bool normalize=false)
Definition: shader_effect_description.h:161
clan::shader_glsl
Definition: graphic_context.h:250
clan::ShaderEffectDescription::set_frag_data
void set_frag_data(std::string name, RenderBuffer buffer)
clan::ShaderEffectDescription::set_storage
void set_storage(std::string name, Resource< StorageBuffer > values)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3f > &buffer)
Definition: shader_effect_description.h:236
clan::type_unsigned_short
Definition: primitives_array.h:59
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< signed short > &buffer, bool normalize=false)
Definition: shader_effect_description.h:151
clan::Vec2
2D vector
Definition: line.h:48
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4f > &buffer)
Definition: shader_effect_description.h:271
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned short > &buffer, bool normalize=false)
Definition: shader_effect_description.h:146
clan::type_int
Definition: primitives_array.h:63
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2f > &buffer)
Definition: shader_effect_description.h:201
clan::ShaderEffectDescription::set_elements
void set_elements(ElementArrayVector< unsigned int > &element_array)
Definition: shader_effect_description.h:286
clan::type_unsigned_int
Definition: primitives_array.h:60
clan::ElementArrayBuffer
Element Array Buffer.
Definition: element_array_buffer.h:46
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:171
clan::Vec3
3D vector
Definition: line_ray.h:48
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:226
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec2b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:176
clan::DepthStencilStateDescription
DepthStencil state description.
Definition: depth_stencil_state_description.h:42
clan::VertexAttributeDataType
VertexAttributeDataType
Primitives array description.
Definition: primitives_array.h:56
clan::ShaderEffectDescription::set_image
void set_image(std::string name, Resource< Texture > texture)
clan::ShaderEffectDescription::set_attribute_screen_quad
void set_attribute_screen_quad(std::string name)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< float > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:131
clan::ShaderEffectDescription::set_fragment_shader
void set_fragment_shader(std::string code, ShaderLanguage language=shader_glsl)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:216
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned char > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:101
clan::ShaderEffectDescription::set_vertex_shader
void set_vertex_shader(std::string code, ShaderLanguage language=shader_glsl)
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec4s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:256
clan::Vec4
4D vector
Definition: size.h:47
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< Vec3i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:231
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< short > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:116
clan::RenderBuffer
Render-buffer object class.
Definition: render_buffer.h:47
clan::type_byte
Definition: primitives_array.h:61
clan::VertexArrayVector
Vertex Array Vector.
Definition: vertex_array_vector.h:43
clan::ShaderEffectDescription::set_define
void set_define(std::string name, std::string value="1")
clan::ShaderEffectDescription::set_attribute
void set_attribute(std::string name, VertexArrayVector< unsigned int > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:121
clan::ShaderEffect
Shader Feffect.
Definition: shader_effect.h:45