ClanLib  2.3.7
program_object.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 ** Harry Storbacka
28 ** Kenneth Gangstoe
29 */
30 
33 
34 #pragma once
35 
36 #include "../api_display.h"
37 #include "../../Core/System/sharedptr.h"
38 #include "../../Core/Text/string_types.h"
39 #include "../../Core/IOData/virtual_directory.h"
40 #include "graphic_context.h"
41 
42 class CL_ShaderObject;
44 class CL_ProgramUniform;
45 class CL_ProgramObject_Impl;
46 class CL_GraphicContext;
48 class CL_ResourceManager;
50 
71 {
74 
75 public:
78 
83 
88 
93 
101  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resman);
102 
110  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &fragment_fullname);
111 
120  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &geometry_fullname, const CL_StringRef &fragment_fullname);
121 
130  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
131 
141  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &geometry_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
142 
150  static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &fragment_file);
151 
160  static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &geometry_file, CL_IODevice &fragment_file);
161 
168  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &fragment_fullname);
169 
177  static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
178 
185  static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &fragment_file);
186 
194  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &fragment_fullname);
195 
204  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &geometry_fullname, const CL_StringRef &fragment_fullname);
205 
214  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
215 
225  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &geometry_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
226 
234  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &fragment_file);
235 
244  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &geometry_file, CL_IODevice &fragment_file);
245 
252  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &fragment_fullname);
253 
261  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
262 
269  static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &fragment_file);
270 
271  virtual ~CL_ProgramObject();
272 
276 
277 public:
279  bool is_null() const { return !impl; }
280 
282  void throw_if_null() const;
283 
285  CL_ProgramObjectProvider *get_provider() const;
286 
288  unsigned int get_handle() const;
289 
291  std::vector<CL_ShaderObject> get_shaders() const;
292 
294  CL_String get_info_log() const;
295 
297  int get_attribute_count() const;
298 
300  std::vector<CL_ProgramAttribute> get_attributes() const;
301 
303  int get_attribute_location(const CL_StringRef &name) const;
304 
306  int get_uniform_count() const;
307 
309  std::vector<CL_ProgramUniform> get_uniforms() const;
310 
312  int get_uniform_location(const CL_StringRef &name) const;
313 
317 
318 public:
320  bool operator==(const CL_ProgramObject &other) const;
321 
323  void attach(const CL_ShaderObject &obj);
324 
326  void detach(const CL_ShaderObject &obj);
327 
329 
330  void bind_attribute_location(int index, const CL_StringRef &name);
331 
333 
334  void bind_frag_data_location(int color_number, const CL_StringRef &name);
335 
337 
338  bool link();
339 
341 
342  bool validate();
343 
348  void set_uniform1i(const CL_StringRef &name, int value_a);
349 
355  void set_uniform2i(const CL_StringRef &name, int value_a, int value_b);
356 
363  void set_uniform3i(const CL_StringRef &name, int value_a, int value_b, int value_c);
364 
372  void set_uniform4i(const CL_StringRef &name, int value_a, int value_b, int value_c, int value_d);
373 
380  void set_uniformiv(const CL_StringRef &name, int size, int count, int *data);
381 
386  void set_uniform2i(const CL_StringRef &name, CL_Vec2i vec) {set_uniform2i(name, vec.x, vec.y);}
387 
392  void set_uniform3i(const CL_StringRef &name, CL_Vec3i vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
393 
398  void set_uniform4i(const CL_StringRef &name, CL_Vec4i vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
399 
404  void set_uniform2s(const CL_StringRef &name, CL_Vec2s vec) {set_uniform2i(name, vec.x, vec.y);}
405 
410  void set_uniform3s(const CL_StringRef &name, CL_Vec3s vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
411 
416  void set_uniform4s(const CL_StringRef &name, CL_Vec4s vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
417 
422  void set_uniform2b(const CL_StringRef &name, CL_Vec2b vec) {set_uniform2i(name, vec.x, vec.y);}
423 
428  void set_uniform3b(const CL_StringRef &name, CL_Vec3b vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
429 
434  void set_uniform4b(const CL_StringRef &name, CL_Vec4b vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
435 
441  void set_uniformiv(const CL_StringRef &name, int count, CL_Vec2i *data) {set_uniformiv(name, 2, count, *data);}
442 
448  void set_uniformiv(const CL_StringRef &name, int count, CL_Vec3i *data) {set_uniformiv(name, 3, count, *data);}
449 
455  void set_uniformiv(const CL_StringRef &name, int count, CL_Vec4i *data) {set_uniformiv(name, 4, count, *data);}
456 
461  void set_uniform1f(const CL_StringRef &name, float value_a);
462 
468  void set_uniform2f(const CL_StringRef &name, float value_a, float value_b);
469 
476  void set_uniform3f(const CL_StringRef &name, float value_a, float value_b, float value_c);
477 
485  void set_uniform4f(const CL_StringRef &name, float value_a, float value_b, float value_c, float value_d);
486 
493  void set_uniformfv(const CL_StringRef &name, int size, int count, float *data);
494 
499  void set_uniform2f(const CL_StringRef &name, CL_Vec2f vec) {set_uniform2f(name, vec.x, vec.y);}
500 
505  void set_uniform3f(const CL_StringRef &name, CL_Vec3f vec) {set_uniform3f(name, vec.x, vec.y, vec.z);}
506 
511  void set_uniform4f(const CL_StringRef &name, CL_Vec4f vec) {set_uniform4f(name, vec.x, vec.y, vec.z, vec.w);}
512 
518  void set_uniformfv(const CL_StringRef &name, int count, CL_Vec2f *data) {set_uniformfv(name, 2, count, *data);}
519 
525  void set_uniformfv(const CL_StringRef &name, int count, CL_Vec3f *data) {set_uniformfv(name, 3, count, *data);}
526 
532  void set_uniformfv(const CL_StringRef &name, int count, CL_Vec4f *data) {set_uniformfv(name, 4, count, *data);}
533 
535  void set_uniform_matrix(const CL_StringRef &name, int size, int count, bool transpose, float *data);
536 
541  void set_uniform_matrix(const CL_StringRef &name, CL_Mat2f matrix) {set_uniform_matrix(name, 2, 1, false, matrix.matrix);}
542 
547  void set_uniform_matrix(const CL_StringRef &name, CL_Mat3f matrix) {set_uniform_matrix(name, 3, 1, false, matrix.matrix);}
548 
553  void set_uniform_matrix(const CL_StringRef &name, CL_Mat4f matrix) {set_uniform_matrix(name, 4, 1, false, matrix.matrix);}
554 
560  void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat2f *matrix) {set_uniform_matrix(name, 2, count, false, matrix->matrix);}
561 
567  void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat3f *matrix) {set_uniform_matrix(name, 3, count, false, matrix->matrix);}
568 
574  void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat4f *matrix) {set_uniform_matrix(name, 4, count, false, matrix->matrix);}
575 
579 
580 private:
581  CL_SharedPtr<CL_ProgramObject_Impl> impl;
583 };
584