shader_object.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 
31 
32 #pragma once
33 
34 #include <memory>
35 #include "../../Core/IOData/file_system.h"
36 #include "graphic_context.h"
37 #include "../api_display.h"
38 #include <vector>
39 
40 namespace clan
41 {
44 
45 class GraphicContextProvider;
46 class XMLResourceDocument;
47 class ShaderObject_Impl;
48 class ShaderObjectProvider;
49 
52 {
60 };
61 
69 class CL_API_DISPLAY ShaderObject
70 {
73 
74 public:
76  ShaderObject();
77 
83  ShaderObject(GraphicContext &gc, ShaderType type, const std::string &source);
84 
86  ShaderObject(GraphicContext &gc, ShaderType type, const void *source, int source_size);
87 
93  ShaderObject(GraphicContext &gc, ShaderType type, const std::vector<std::string> &sources);
94 
100  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::string &source);
101 
107  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::vector<std::string> &sources);
108 
116  static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources);
117 
126  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
127 
135  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &fullname);
136 
144  static ShaderObject load(GraphicContext &gc, ShaderType type, IODevice &file);
145 
154  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
155 
163  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename);
164 
172  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, IODevice &file);
173 
174  virtual ~ShaderObject();
175 
179 
180 public:
182  unsigned int get_handle() const;
183 
185  ShaderType get_shader_type() const;
186 
188  std::string get_info_log() const;
189 
191  std::string get_shader_source() const;
192 
194  bool is_null() const { return !impl; }
195 
197  void throw_if_null() const;
198 
202  ShaderObjectProvider *get_provider() const;
203 
207 
208 public:
210  bool operator==(const ShaderObject &other) const;
211 
213 
214  bool compile();
215 
219 
220 private:
221  std::shared_ptr<ShaderObject_Impl> impl;
223 };
224 
225 }
226 
Shader Object.
Definition: shader_object.h:69
Definition: shader_object.h:54
Definition: shader_object.h:56
I/O Device interface.
Definition: iodevice.h:51
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:87
Definition: shader_object.h:57
Definition: shader_object.h:59
bool is_null() const
Returns true if this object is invalid.
Definition: shader_object.h:194
Shader Object provider.
Definition: shader_object_provider.h:42
Virtual File System (VFS).
Definition: file_system.h:48
ShaderType
Shader Type.
Definition: shader_object.h:51
Definition: shader_object.h:55
Interface to drawing graphics.
Definition: graphic_context.h:257
XML Resource Document.
Definition: xml_resource_document.h:49
Definition: shader_object.h:58
Definition: shader_object.h:53