shader_object.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 <vector>
38 
39 namespace clan
40 {
43 
44 class GraphicContextProvider;
45 class XMLResourceDocument;
46 class ShaderObject_Impl;
47 class ShaderObjectProvider;
48 
51 {
59 };
60 
69 {
72 
73 public:
75  ShaderObject();
76 
82  ShaderObject(GraphicContext &gc, ShaderType type, const std::string &source);
83 
85  ShaderObject(GraphicContext &gc, ShaderType type, const void *source, int source_size);
86 
92  ShaderObject(GraphicContext &gc, ShaderType type, const std::vector<std::string> &sources);
93 
99  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::string &source);
100 
106  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::vector<std::string> &sources);
107 
115  static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources);
116 
125  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
126 
134  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &fullname);
135 
143  static ShaderObject load(GraphicContext &gc, ShaderType type, IODevice &file);
144 
153  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
154 
162  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename);
163 
172 
173  virtual ~ShaderObject();
174 
178 
179 public:
181  unsigned int get_handle() const;
182 
184  ShaderType get_shader_type() const;
185 
187  std::string get_info_log() const;
188 
191 
193  bool is_null() const { return !impl; }
194 
196  void throw_if_null() const;
197 
202 
206 
207 public:
209  bool operator==(const ShaderObject &other) const;
210 
212 
213  bool compile();
214 
218 
219 private:
220  std::shared_ptr<ShaderObject_Impl> impl;
222 };
223 
224 }
225 
Shader Object.
Definition: shader_object.h:68
bool compile()
Compile program.
Definition: clanapp.h:35
ShaderType get_shader_type() const
Gets the shader type.
Definition: shader_object.h:53
Definition: shader_object.h:55
I/O Device interface.
Definition: iodevice.h:50
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:86
static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources)
Load.
bool operator==(const ShaderObject &other) const
Handle comparison operator.
void throw_if_null() const
Throw an exception if this object is invalid.
Definition: shader_object.h:56
Definition: shader_object.h:58
virtual ~ShaderObject()
Shader Object provider.
Definition: shader_object_provider.h:42
ShaderObjectProvider * get_provider() const
Get Provider.
Virtual File System (VFS).
Definition: file_system.h:47
ShaderType
Shader Type.
Definition: shader_object.h:50
Definition: shader_object.h:54
ShaderObject()
Constructs a null instance.
Interface to drawing graphics.
Definition: graphic_context.h:257
std::string get_info_log() const
Get shader object&#39;s info log.
XML Resource Document.
Definition: xml_resource_document.h:48
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load and compile.
bool is_null() const
Returns true if this object is invalid.
Definition: shader_object.h:193
unsigned int get_handle() const
Returns the OpenGL shader handle.
std::string get_shader_source() const
Get shader source code.
Definition: shader_object.h:57
Definition: shader_object.h:52