shader_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 "../../Core/System/sharedptr.h"
00037 #include "../../Core/IOData/virtual_directory.h"
00038 #include "graphic_context.h"
00039 #include "../api_display.h"
00040 #include <vector>
00041 
00042 class CL_GraphicContextProvider;
00043 class CL_ResourceManager;
00044 class CL_ShaderObject_Impl;
00045 class CL_ShaderObjectProvider;
00046 
00050 enum CL_ShaderType
00051 {
00052         cl_shadertype_vertex,
00053         cl_shadertype_geometry,
00054         cl_shadertype_fragment
00055 };
00056 
00065 class CL_API_DISPLAY CL_ShaderObject
00066 {
00069 
00070 public:
00072         CL_ShaderObject();
00073 
00079         CL_ShaderObject(CL_GraphicContext &gc, CL_ShaderType type, const CL_StringRef &source);
00080 
00086         CL_ShaderObject(CL_GraphicContext &gc, CL_ShaderType type, const std::vector<CL_StringRef> &sources);
00087 
00093         CL_ShaderObject(CL_GraphicContextProvider *gc_provider, CL_ShaderType type, const CL_StringRef &source);
00094 
00100         CL_ShaderObject(CL_GraphicContextProvider *gc_provider, CL_ShaderType type, const std::vector<CL_StringRef> &sources);
00101 
00109         static CL_ShaderObject load(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources);
00110 
00119         static CL_ShaderObject load(CL_GraphicContext &gc, CL_ShaderType type, const CL_StringRef &filename, const CL_VirtualDirectory &directory);
00120 
00128         static CL_ShaderObject load(CL_GraphicContext &gc, CL_ShaderType type, const CL_StringRef &fullname);
00129 
00137         static CL_ShaderObject load(CL_GraphicContext &gc, CL_ShaderType type, CL_IODevice &file);
00138 
00147         static CL_ShaderObject load_and_compile(CL_GraphicContext &gc, CL_ShaderType type, const CL_StringRef &filename, const CL_VirtualDirectory &directory);
00148 
00156         static CL_ShaderObject load_and_compile(CL_GraphicContext &gc, CL_ShaderType type, const CL_StringRef &filename);
00157 
00165         static CL_ShaderObject load_and_compile(CL_GraphicContext &gc, CL_ShaderType type, CL_IODevice &file);
00166 
00167         virtual ~CL_ShaderObject();
00168 
00172 
00173 public:
00175         unsigned int get_handle() const;
00176 
00178         CL_ShaderType get_shader_type() const;
00179 
00181         CL_String get_info_log() const;
00182 
00184         CL_String get_shader_source() const;
00185 
00187         bool is_null() const { return !impl; }
00188 
00190         void throw_if_null() const;
00191 
00195         CL_ShaderObjectProvider *get_provider() const;
00196 
00200 
00201 public:
00203         bool operator==(const CL_ShaderObject &other) const;
00204 
00206 
00207         bool compile();
00208 
00212 
00213 private:
00214         CL_SharedPtr<CL_ShaderObject_Impl> impl;
00216 };
00217