program_object.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 **    Kenneth Gangstoe
00029 */
00030 
00033 
00034 #pragma once
00035 
00036 #include "../api_display.h"
00037 #include "../../Core/System/sharedptr.h"
00038 #include "../../Core/Text/string_types.h"
00039 #include "../../Core/IOData/virtual_directory.h"
00040 #include "graphic_context.h"
00041 
00042 class CL_ShaderObject;
00043 class CL_ProgramAttribute;
00044 class CL_ProgramUniform;
00045 class CL_ProgramObject_Impl;
00046 class CL_GraphicContext;
00047 class CL_GraphicContextProvider;
00048 class CL_ResourceManager;
00049 class CL_ProgramObjectProvider;
00050 
00070 class CL_API_DISPLAY CL_ProgramObject
00071 {
00074 
00075 public:
00077         CL_ProgramObject();
00078 
00082         CL_ProgramObject(CL_GraphicContext &gc);
00083 
00087         CL_ProgramObject(CL_GraphicContextProvider *gc_provider);
00088 
00092         CL_ProgramObject(CL_ProgramObjectProvider *provider);
00093 
00101         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resman);
00102 
00110         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &fragment_fullname);
00111 
00120         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &geometry_fullname, const CL_StringRef &fragment_fullname);
00121 
00130         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
00131 
00141         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);
00142 
00150         static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &fragment_file);
00151 
00160         static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &geometry_file, CL_IODevice &fragment_file);
00161 
00168         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &fragment_fullname);
00169 
00177         static CL_ProgramObject load(CL_GraphicContext &gc, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
00178 
00185         static CL_ProgramObject load(CL_GraphicContext &gc, CL_IODevice &fragment_file);
00186 
00194         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &fragment_fullname);
00195 
00204         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_fullname, const CL_StringRef &geometry_fullname, const CL_StringRef &fragment_fullname);
00205 
00214         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &vertex_filename, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
00215 
00225         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);
00226 
00234         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &fragment_file);
00235 
00244         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &vertex_file, CL_IODevice &geometry_file, CL_IODevice &fragment_file);
00245 
00252         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &fragment_fullname);
00253 
00261         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, const CL_StringRef &fragment_filename, const CL_VirtualDirectory &directory);
00262 
00269         static CL_ProgramObject load_and_link(CL_GraphicContext &gc, CL_IODevice &fragment_file);
00270 
00271         virtual ~CL_ProgramObject();
00272 
00276 
00277 public:
00279         bool is_null() const { return !impl; }
00280 
00282         void throw_if_null() const;
00283 
00285         CL_ProgramObjectProvider *get_provider() const;
00286 
00288         unsigned int get_handle() const;
00289 
00291         std::vector<CL_ShaderObject> get_shaders() const;
00292 
00294         CL_String get_info_log() const;
00295 
00297         int get_attribute_count() const;
00298 
00300         std::vector<CL_ProgramAttribute> get_attributes() const;
00301 
00303         int get_attribute_location(const CL_StringRef &name) const;
00304 
00306         int get_uniform_count() const;
00307 
00309         std::vector<CL_ProgramUniform> get_uniforms() const;
00310 
00312         int get_uniform_location(const CL_StringRef &name) const;
00313 
00317 
00318 public:
00320         bool operator==(const CL_ProgramObject &other) const;
00321 
00323         void attach(const CL_ShaderObject &obj);
00324 
00326         void detach(const CL_ShaderObject &obj);
00327 
00329 
00330         void bind_attribute_location(int index, const CL_StringRef &name);
00331 
00333 
00334         void bind_frag_data_location(int color_number, const CL_StringRef &name);
00335 
00337 
00338         bool link();
00339 
00341 
00342         bool validate();
00343 
00348         void set_uniform1i(const CL_StringRef &name, int value_a);
00349 
00355         void set_uniform2i(const CL_StringRef &name, int value_a, int value_b);
00356 
00363         void set_uniform3i(const CL_StringRef &name, int value_a, int value_b, int value_c);
00364 
00372         void set_uniform4i(const CL_StringRef &name, int value_a, int value_b, int value_c, int value_d);
00373 
00380         void set_uniformiv(const CL_StringRef &name, int size, int count, int *data);
00381 
00386         void set_uniform2i(const CL_StringRef &name, CL_Vec2i vec) {set_uniform2i(name, vec.x, vec.y);}
00387 
00392         void set_uniform3i(const CL_StringRef &name, CL_Vec3i vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
00393 
00398         void set_uniform4i(const CL_StringRef &name, CL_Vec4i vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
00399 
00404         void set_uniform2s(const CL_StringRef &name, CL_Vec2s vec) {set_uniform2i(name, vec.x, vec.y);}
00405 
00410         void set_uniform3s(const CL_StringRef &name, CL_Vec3s vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
00411 
00416         void set_uniform4s(const CL_StringRef &name, CL_Vec4s vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
00417 
00422         void set_uniform2b(const CL_StringRef &name, CL_Vec2b vec) {set_uniform2i(name, vec.x, vec.y);}
00423 
00428         void set_uniform3b(const CL_StringRef &name, CL_Vec3b vec) {set_uniform3i(name, vec.x, vec.y, vec.z);}
00429 
00434         void set_uniform4b(const CL_StringRef &name, CL_Vec4b vec) {set_uniform4i(name, vec.x, vec.y, vec.z, vec.w);}
00435 
00441         void set_uniformiv(const CL_StringRef &name, int count, CL_Vec2i *data) {set_uniformiv(name, 2, count, *data);}
00442 
00448         void set_uniformiv(const CL_StringRef &name, int count, CL_Vec3i *data) {set_uniformiv(name, 3, count, *data);}
00449 
00455         void set_uniformiv(const CL_StringRef &name, int count, CL_Vec4i *data) {set_uniformiv(name, 4, count, *data);}
00456 
00461         void set_uniform1f(const CL_StringRef &name, float value_a);
00462 
00468         void set_uniform2f(const CL_StringRef &name, float value_a, float value_b);
00469 
00476         void set_uniform3f(const CL_StringRef &name, float value_a, float value_b, float value_c);
00477 
00485         void set_uniform4f(const CL_StringRef &name, float value_a, float value_b, float value_c, float value_d);
00486 
00493         void set_uniformfv(const CL_StringRef &name, int size, int count, float *data);
00494 
00499         void set_uniform2f(const CL_StringRef &name, CL_Vec2f vec) {set_uniform2f(name, vec.x, vec.y);}
00500 
00505         void set_uniform3f(const CL_StringRef &name, CL_Vec3f vec) {set_uniform3f(name, vec.x, vec.y, vec.z);}
00506 
00511         void set_uniform4f(const CL_StringRef &name, CL_Vec4f vec) {set_uniform4f(name, vec.x, vec.y, vec.z, vec.w);}
00512 
00518         void set_uniformfv(const CL_StringRef &name, int count, CL_Vec2f *data) {set_uniformfv(name, 2, count, *data);}
00519 
00525         void set_uniformfv(const CL_StringRef &name, int count, CL_Vec3f *data) {set_uniformfv(name, 3, count, *data);}
00526 
00532         void set_uniformfv(const CL_StringRef &name, int count, CL_Vec4f *data) {set_uniformfv(name, 4, count, *data);}
00533 
00535         void set_uniform_matrix(const CL_StringRef &name, int size, int count, bool transpose, float *data);
00536 
00541         void set_uniform_matrix(const CL_StringRef &name, CL_Mat2f matrix) {set_uniform_matrix(name, 2, 1, false, matrix.matrix);}
00542 
00547         void set_uniform_matrix(const CL_StringRef &name, CL_Mat3f matrix) {set_uniform_matrix(name, 3, 1, false, matrix.matrix);}
00548 
00553         void set_uniform_matrix(const CL_StringRef &name, CL_Mat4f matrix) {set_uniform_matrix(name, 4, 1, false, matrix.matrix);}
00554 
00560         void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat2f *matrix) {set_uniform_matrix(name, 2, count, false, matrix->matrix);}
00561 
00567         void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat3f *matrix) {set_uniform_matrix(name, 3, count, false, matrix->matrix);}
00568 
00574         void set_uniform_matrix(const CL_StringRef &name, int count, CL_Mat4f *matrix) {set_uniform_matrix(name, 4, count, false, matrix->matrix);}
00575 
00579 
00580 private:
00581         CL_SharedPtr<CL_ProgramObject_Impl> impl;
00583 };
00584