shader_effect_description.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 #pragma once
31 
32 #include <memory>
33 #include "../Render/graphic_context.h"
34 #include "../Render/rasterizer_state_description.h"
35 #include "../Render/blend_state_description.h"
36 #include "../Render/depth_stencil_state_description.h"
37 #include "../Render/storage_buffer.h"
38 #include "../Render/uniform_buffer.h"
39 #include "../Render/texture.h"
40 #include "../Render/render_buffer.h"
41 #include "../../Core/Resources/resource.h"
42 
43 namespace clan
44 {
47 
48  class ShaderEffectDescription_Impl;
49 
54  {
55  public:
57 
58  void set_glsl_version(int version = 330);
59 
60  void set_define(std::string name, std::string value = "1");
61 
65 
69 
70  void set_frag_data(std::string name, RenderBuffer buffer);
71  void set_frag_data(std::string name, Texture texture);
73 
74  void set_depth_data(RenderBuffer buffer);
75  void set_depth_data(Texture texture);
76 
77  void set_stencil_data(RenderBuffer buffer);
78  void set_stencil_data(Texture texture);
79 
80  void set_texture(std::string name, Resource<Texture> texture);
81  void set_image(std::string name, Resource<Texture> texture);
82 
84 
86 
87  void set_attribute(std::string name, VertexArrayBuffer &buffer, int size, VertexAttributeDataType type, size_t offset = 0, int stride = 0, bool normalize = false);
88 
89  void set_attribute(std::string name, VertexArrayVector<unsigned char> &buffer, int size, bool normalize = false)
90  {
91  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_byte, 0, 0, normalize);
92  }
93 
94  void set_attribute(std::string name, VertexArrayVector<char> &buffer, int size, bool normalize = false)
95  {
96  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_byte, 0, 0, normalize);
97  }
98 
99  void set_attribute(std::string name, VertexArrayVector<unsigned short> &buffer, int size, bool normalize = false)
100  {
101  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_short, 0, 0, normalize);
102  }
103 
104  void set_attribute(std::string name, VertexArrayVector<short> &buffer, int size, bool normalize = false)
105  {
106  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_short, 0, 0, normalize);
107  }
108 
109  void set_attribute(std::string name, VertexArrayVector<unsigned int> &buffer, int size, bool normalize = false)
110  {
111  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_unsigned_int, 0, 0, normalize);
112  }
113 
114  void set_attribute(std::string name, VertexArrayVector<int> &buffer, int size, bool normalize = false)
115  {
116  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_int, 0, 0, normalize);
117  }
118 
119  void set_attribute(std::string name, VertexArrayVector<float> &buffer, int size, bool normalize = false)
120  {
121  set_attribute(name, (VertexArrayBuffer&)buffer, size, type_float, 0, 0, normalize);
122  }
123 
124  void set_attribute(std::string name, VertexArrayVector<unsigned char> &buffer, bool normalize = false)
125  {
126  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_byte, 0, sizeof(unsigned char), normalize);
127  }
128 
129  void set_attribute(std::string name, VertexArrayVector<signed char> &buffer, bool normalize = false)
130  {
131  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_byte, 0, sizeof(signed char), normalize);
132  }
133 
134  void set_attribute(std::string name, VertexArrayVector<unsigned short> &buffer, bool normalize = false)
135  {
136  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_short, 0, sizeof(unsigned short), normalize);
137  }
138 
139  void set_attribute(std::string name, VertexArrayVector<signed short> &buffer, bool normalize = false)
140  {
141  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_short, 0, sizeof(signed short), normalize);
142  }
143 
144  void set_attribute(std::string name, VertexArrayVector<unsigned int> &buffer, bool normalize = false)
145  {
146  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_unsigned_int, 0, sizeof(unsigned int), normalize);
147  }
148 
149  void set_attribute(std::string name, VertexArrayVector<signed int> &buffer, bool normalize = false)
150  {
151  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_int, 0, sizeof(signed int), normalize);
152  }
153 
155  {
156  set_attribute(name, (VertexArrayBuffer&)buffer, 1, type_float, 0, sizeof(float), false);
157  }
158 
159  void set_attribute(std::string name, VertexArrayVector<Vec2ub> &buffer, bool normalize = false)
160  {
161  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_byte, 0, sizeof(Vec2ub), normalize);
162  }
163 
164  void set_attribute(std::string name, VertexArrayVector<Vec2b> &buffer, bool normalize = false)
165  {
166  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_byte, 0, sizeof(Vec2b), normalize);
167  }
168 
169  void set_attribute(std::string name, VertexArrayVector<Vec2us> &buffer, bool normalize = false)
170  {
171  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_short, 0, sizeof(Vec2us), normalize);
172  }
173 
174  void set_attribute(std::string name, VertexArrayVector<Vec2s> &buffer, bool normalize = false)
175  {
176  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_short, 0, sizeof(Vec2s), normalize);
177  }
178 
179  void set_attribute(std::string name, VertexArrayVector<Vec2ui> &buffer, bool normalize = false)
180  {
181  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_unsigned_int, 0, sizeof(Vec2ui), normalize);
182  }
183 
184  void set_attribute(std::string name, VertexArrayVector<Vec2i> &buffer, bool normalize = false)
185  {
186  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_int, 0, sizeof(Vec2i), normalize);
187  }
188 
190  {
191  set_attribute(name, (VertexArrayBuffer&)buffer, 2, type_float, 0, sizeof(Vec2f), false);
192  }
193 
194  void set_attribute(std::string name, VertexArrayVector<Vec3ub> &buffer, bool normalize = false)
195  {
196  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_byte, 0, sizeof(Vec3ub), normalize);
197  }
198 
199  void set_attribute(std::string name, VertexArrayVector<Vec3b> &buffer, bool normalize = false)
200  {
201  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_byte, 0, sizeof(Vec3b), normalize);
202  }
203 
204  void set_attribute(std::string name, VertexArrayVector<Vec3us> &buffer, bool normalize = false)
205  {
206  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_short, 0, sizeof(Vec3us), normalize);
207  }
208 
209  void set_attribute(std::string name, VertexArrayVector<Vec3s> &buffer, bool normalize = false)
210  {
211  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_short, 0, sizeof(Vec3s), normalize);
212  }
213 
214  void set_attribute(std::string name, VertexArrayVector<Vec3ui> &buffer, bool normalize = false)
215  {
216  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_unsigned_int, 0, sizeof(Vec3ui), normalize);
217  }
218 
219  void set_attribute(std::string name, VertexArrayVector<Vec3i> &buffer, bool normalize = false)
220  {
221  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_int, 0, sizeof(Vec3i), normalize);
222  }
223 
225  {
226  set_attribute(name, (VertexArrayBuffer&)buffer, 3, type_float, 0, sizeof(Vec3f), false);
227  }
228 
229  void set_attribute(std::string name, VertexArrayVector<Vec4ub> &buffer, bool normalize = false)
230  {
231  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_byte, 0, sizeof(Vec4ub), normalize);
232  }
233 
234  void set_attribute(std::string name, VertexArrayVector<Vec4b> &buffer, bool normalize = false)
235  {
236  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_byte, 0, sizeof(Vec4b), normalize);
237  }
238 
239  void set_attribute(std::string name, VertexArrayVector<Vec4us> &buffer, bool normalize = false)
240  {
241  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_short, 0, sizeof(Vec4us), normalize);
242  }
243 
244  void set_attribute(std::string name, VertexArrayVector<Vec4s> &buffer, bool normalize = false)
245  {
246  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_short, 0, sizeof(Vec4s), normalize);
247  }
248 
249  void set_attribute(std::string name, VertexArrayVector<Vec4ui> &buffer, bool normalize = false)
250  {
251  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_unsigned_int, 0, sizeof(Vec4ui), normalize);
252  }
253 
254  void set_attribute(std::string name, VertexArrayVector<Vec4i> &buffer, bool normalize = false)
255  {
256  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_int, 0, sizeof(Vec4i), normalize);
257  }
258 
260  {
261  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_float, 0, sizeof(Vec4f), false);
262  }
263 
265  {
266  set_attribute(name, (VertexArrayBuffer&)buffer, 4, type_float, 0, sizeof(Colorf), false);
267  }
268 
271 
272  void set_elements(ElementArrayBuffer &element_array, VertexAttributeDataType indices_type);
273 
275  {
276  set_elements(element_array, type_unsigned_int);
277  }
278 
280  {
281  set_elements(element_array, type_unsigned_short);
282  }
283 
285  {
286  set_elements(element_array, type_unsigned_byte);
287  }
288 
289  void set_draw_count(int count);
290 
291  private:
292  std::shared_ptr<ShaderEffectDescription_Impl> impl;
293 
294  friend class ShaderEffect;
295  };
296 
298 }
BlendStateDescription & blend()
void set_attribute(std::string name, VertexArrayVector< Vec2f > &buffer)
Definition: shader_effect_description.h:189
void set_attribute(std::string name, VertexArrayVector< short > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:104
Rasterizer state description.
Definition: rasterizer_state_description.h:41
Definition: clanapp.h:35
Floating point color description class (for float).
Definition: color.h:798
Definition: primitives_array.h:63
Resource proxy of a specific type.
Definition: resource.h:57
void set_fragment_shader(std::string code, ShaderLanguage language=shader_glsl)
void set_attribute(std::string name, VertexArrayVector< float > &buffer)
Definition: shader_effect_description.h:154
4D vector
Definition: size.h:47
2D vector
Definition: line.h:46
void set_attribute(std::string name, VertexArrayVector< Vec3ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:214
Vertex Array Buffer.
Definition: vertex_array_buffer.h:45
Blend state description.
Definition: blend_state_description.h:41
Texture object class.
Definition: texture.h:102
void set_vertex_shader(std::string code, ShaderLanguage language=shader_glsl)
void set_attribute(std::string name, VertexArrayBuffer &buffer, int size, VertexAttributeDataType type, size_t offset=0, int stride=0, bool normalize=false)
Element Array Vector.
Definition: element_array_vector.h:42
Definition: primitives_array.h:61
void set_attribute(std::string name, VertexArrayVector< Vec4s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:244
void set_attribute(std::string name, VertexArrayVector< Colorf > &buffer)
Definition: shader_effect_description.h:264
void set_frag_data_to_back_buffer(std::string name)
void set_elements(ElementArrayVector< unsigned int > &element_array)
Definition: shader_effect_description.h:274
void set_attribute(std::string name, VertexArrayVector< Vec3b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:199
Shader Effect Description.
Definition: shader_effect_description.h:53
RasterizerStateDescription & rasterizer()
void set_define(std::string name, std::string value="1")
ShaderLanguage
Shader language used.
Definition: graphic_context.h:247
void set_attribute(std::string name, VertexArrayVector< Vec2i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:184
void set_draw_count(int count)
void set_glsl_version(int version=330)
void set_attribute(std::string name, VertexArrayVector< Vec2us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:169
void set_depth_data(RenderBuffer buffer)
void set_attribute(std::string name, VertexArrayVector< unsigned int > &buffer, bool normalize=false)
Definition: shader_effect_description.h:144
void set_attribute(std::string name, VertexArrayVector< unsigned int > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:109
void set_attribute(std::string name, VertexArrayVector< Vec3s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:209
void set_elements(ElementArrayBuffer &element_array, VertexAttributeDataType indices_type)
void set_attribute_uv_quad(std::string name)
void set_attribute(std::string name, VertexArrayVector< signed char > &buffer, bool normalize=false)
Definition: shader_effect_description.h:129
void set_elements(ElementArrayVector< unsigned char > &element_array)
Definition: shader_effect_description.h:284
void set_storage(std::string name, Resource< StorageBuffer > values)
void set_elements(ElementArrayVector< unsigned short > &element_array)
Definition: shader_effect_description.h:279
void set_attribute(std::string name, VertexArrayVector< Vec4i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:254
Definition: primitives_array.h:57
void set_attribute(std::string name, VertexArrayVector< Vec3f > &buffer)
Definition: shader_effect_description.h:224
void set_attribute(std::string name, VertexArrayVector< Vec2s > &buffer, bool normalize=false)
Definition: shader_effect_description.h:174
void set_attribute(std::string name, VertexArrayVector< char > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:94
void set_stencil_data(RenderBuffer buffer)
Definition: graphic_context.h:249
void set_compute_shader(std::string code, ShaderLanguage language=shader_glsl)
void set_attribute_screen_quad(std::string name)
void set_attribute(std::string name, VertexArrayVector< Vec4us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:239
Definition: primitives_array.h:58
void set_uniform_block(std::string name, Resource< UniformBuffer > values)
void set_attribute(std::string name, VertexArrayVector< signed short > &buffer, bool normalize=false)
Definition: shader_effect_description.h:139
void set_attribute(std::string name, VertexArrayVector< Vec2b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:164
Definition: primitives_array.h:62
Definition: primitives_array.h:59
Element Array Buffer.
Definition: element_array_buffer.h:45
void set_attribute(std::string name, VertexArrayVector< Vec2ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:159
void set_attribute(std::string name, VertexArrayVector< Vec4ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:249
DepthStencil state description.
Definition: depth_stencil_state_description.h:41
void set_attribute(std::string name, VertexArrayVector< unsigned short > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:99
void set_texture(std::string name, Resource< Texture > texture)
VertexAttributeDataType
Primitives array description.
Definition: primitives_array.h:55
void set_attribute(std::string name, VertexArrayVector< Vec4b > &buffer, bool normalize=false)
Definition: shader_effect_description.h:234
void set_attribute(std::string name, VertexArrayVector< Vec3ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:194
void set_attribute(std::string name, VertexArrayVector< signed int > &buffer, bool normalize=false)
Definition: shader_effect_description.h:149
void set_image(std::string name, Resource< Texture > texture)
void set_attribute(std::string name, VertexArrayVector< unsigned char > &buffer, bool normalize=false)
Definition: shader_effect_description.h:124
void set_attribute(std::string name, VertexArrayVector< Vec3us > &buffer, bool normalize=false)
Definition: shader_effect_description.h:204
void set_attribute(std::string name, VertexArrayVector< unsigned short > &buffer, bool normalize=false)
Definition: shader_effect_description.h:134
void set_frag_data(std::string name, RenderBuffer buffer)
void set_attribute(std::string name, VertexArrayVector< unsigned char > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:89
void set_attribute(std::string name, VertexArrayVector< Vec2ui > &buffer, bool normalize=false)
Definition: shader_effect_description.h:179
3D vector
Definition: line_ray.h:46
void set_attribute(std::string name, VertexArrayVector< Vec4f > &buffer)
Definition: shader_effect_description.h:259
void set_attribute(std::string name, VertexArrayVector< Vec3i > &buffer, bool normalize=false)
Definition: shader_effect_description.h:219
void set_attribute(std::string name, VertexArrayVector< float > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:119
void set_attribute(std::string name, VertexArrayVector< Vec4ub > &buffer, bool normalize=false)
Definition: shader_effect_description.h:229
Render-buffer object class.
Definition: render_buffer.h:46
DepthStencilStateDescription & depth_stencil()
Definition: primitives_array.h:60
void set_attribute(std::string name, VertexArrayVector< int > &buffer, int size, bool normalize=false)
Definition: shader_effect_description.h:114
Vertex Array Vector.
Definition: vertex_array_vector.h:42
Shader Feffect.
Definition: shader_effect.h:44