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:
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 
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 
185 
187  std::string get_info_log() const;
188 
190  std::string get_shader_source() const;
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 
ShaderObject(GraphicContext &gc, ShaderType type, const std::vector< std::string > &sources)
Constructs a ShaderObject.
@ shadertype_tess_control
Definition: shader_object.h:56
bool compile()
Compile program.
ShaderObject(GraphicContext &gc, ShaderType type, const std::string &source)
Constructs an OpenGL shader.
ShaderType get_shader_type() const
Gets the shader type.
@ shadertype_geometry
Definition: shader_object.h:53
static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources)
Load.
@ shadertype_tess_evaluation
Definition: shader_object.h:55
@ shadertype_num_types
Definition: shader_object.h:58
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, IODevice &file)
Load and compile.
bool operator==(const ShaderObject &other) const
Handle comparison operator.
I/O Device interface.
Definition: iodevice.h:51
static ShaderObject load(GraphicContext &gc, ShaderType type, IODevice &file)
Load.
@ shadertype_vertex
Definition: shader_object.h:52
ShaderObject(GraphicContext &gc, ShaderType type, const void *source, int source_size)
Constructs a ShaderObject.
ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::string &source)
Constructs a ShaderObject.
void throw_if_null() const
Throw an exception if this object is invalid.
static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load.
virtual ~ShaderObject()
ShaderObjectProvider * get_provider() const
Get Provider.
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename)
Load and compile.
static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &fullname)
Load.
ShaderType
Shader Type.
Definition: shader_object.h:51
Interface to drawing graphics.
Definition: graphic_context.h:258
ShaderObject()
Constructs a null instance.
Definition: clanapp.h:36
@ shadertype_fragment
Definition: shader_object.h:54
Virtual File System (VFS).
Definition: file_system.h:48
XML Resource Document.
Definition: xml_resource_document.h:49
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load and compile.
std::string get_info_log() const
Get shader object's info log.
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:87
@ shadertype_compute
Definition: shader_object.h:57
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.
Shader Object.
Definition: shader_object.h:69
std::string get_shader_source() const
Get shader source code.
ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::vector< std::string > &sources)
Constructs a ShaderObject.
Shader Object provider.
Definition: shader_object_provider.h:43