shader_object.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 #pragma once
32 
33 #include <memory>
34 #include "../../Core/IOData/file_system.h"
35 #include "graphic_context.h"
36 #include <vector>
37 
38 namespace clan
39 {
42 
43  class GraphicContextProvider;
44  class XMLResourceDocument;
45  class ShaderObject_Impl;
46  class ShaderObjectProvider;
47 
50  {
58  };
59 
68  {
69  public:
71  ShaderObject();
72 
78  ShaderObject(GraphicContext &gc, ShaderType type, const std::string &source);
79 
81  ShaderObject(GraphicContext &gc, ShaderType type, const void *source, int source_size);
82 
88  ShaderObject(GraphicContext &gc, ShaderType type, const std::vector<std::string> &sources);
89 
95  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::string &source);
96 
102  ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::vector<std::string> &sources);
103 
111  static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources);
112 
121  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
122 
130  static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &fullname);
131 
139  static ShaderObject load(GraphicContext &gc, ShaderType type, IODevice &file);
140 
149  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs);
150 
158  static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename);
159 
168 
169  virtual ~ShaderObject();
170 
172  unsigned int get_handle() const;
173 
175  ShaderType get_shader_type() const;
176 
178  std::string get_info_log() const;
179 
182 
184  bool is_null() const { return !impl; }
185  explicit operator bool() const { return bool(impl); }
186 
188  void throw_if_null() const;
189 
194 
196  bool operator==(const ShaderObject &other) const;
197 
199 
200  bool compile();
201 
202  private:
203  std::shared_ptr<ShaderObject_Impl> impl;
204  };
205 
207 }
Shader Object.
Definition: shader_object.h:67
Definition: clanapp.h:35
Definition: shader_object.h:52
unsigned int get_handle() const
Returns the OpenGL shader handle.
Definition: shader_object.h:54
ShaderObjectProvider * get_provider() const
Get Provider.
I/O Device interface.
Definition: iodevice.h:49
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:85
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load and compile.
std::string get_shader_source() const
Get shader source code.
bool operator==(const ShaderObject &other) const
Handle comparison operator.
ShaderObject()
Constructs a null instance.
Definition: shader_object.h:55
Definition: shader_object.h:57
void throw_if_null() const
Throw an exception if this object is invalid.
Shader Object provider.
Definition: shader_object_provider.h:41
bool is_null() const
Returns true if this object is invalid.
Definition: shader_object.h:184
Virtual File System (VFS).
Definition: file_system.h:46
ShaderType
Shader Type.
Definition: shader_object.h:49
std::string get_info_log() const
Get shader object's info log.
Definition: shader_object.h:53
virtual ~ShaderObject()
Interface to drawing graphics.
Definition: graphic_context.h:256
ShaderType get_shader_type() const
Gets the shader type.
XML Resource Document.
Definition: xml_resource_document.h:47
static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources)
Load.
bool compile()
Compile program.
Definition: shader_object.h:56
Definition: shader_object.h:51