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
50 enum ShaderType
51 {
52 shadertype_vertex,
53 shadertype_geometry,
54 shadertype_fragment,
55 shadertype_tess_evaluation,
56 shadertype_tess_control,
57 shadertype_compute,
58 shadertype_num_types
59 };
60
68 class ShaderObject
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
171 static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, IODevice &file);
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
190 std::string get_shader_source() const;
191
193 bool is_null() const { return !impl; }
194
196 void throw_if_null() const;
197
201 ShaderObjectProvider *get_provider() const;
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
clan::ShaderObject
Shader Object.
Definition: shader_object.h:68
clan::ShaderObject::compile
bool compile()
Compile program.
clan
Definition: clanapp.h:35
clan::shadertype_geometry
Definition: shader_object.h:53
clan::shadertype_tess_evaluation
Definition: shader_object.h:55
clan::IODevice
I/O Device interface.
Definition: iodevice.h:50
clan::GraphicContextProvider
Interface for implementing a GraphicContext target.
Definition: graphic_context_provider.h:86
clan::ShaderObject::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::ShaderObject::load
static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources)
Load.
clan::ShaderObject::get_shader_source
std::string get_shader_source() const
Get shader source code.
clan::shadertype_tess_control
Definition: shader_object.h:56
clan::shadertype_num_types
Definition: shader_object.h:58
clan::StyleTokenType::string
@ keyword
clan::ShaderObject::~ShaderObject
virtual ~ShaderObject()
clan::ShaderObject::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: shader_object.h:193
clan::ShaderObjectProvider
Shader Object provider.
Definition: shader_object_provider.h:42
clan::FileSystem
Virtual File System (VFS).
Definition: file_system.h:47
clan::ShaderType
ShaderType
Shader Type.
Definition: shader_object.h:50
clan::shadertype_fragment
Definition: shader_object.h:54
clan::ShaderObject::get_shader_type
ShaderType get_shader_type() const
Gets the shader type.
clan::ShaderObject::ShaderObject
ShaderObject()
Constructs a null instance.
clan::ShaderObject::get_provider
ShaderObjectProvider * get_provider() const
Get Provider.
clan::ShaderObject::operator==
bool operator==(const ShaderObject &other) const
Handle comparison operator.
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::ShaderObject::get_info_log
std::string get_info_log() const
Get shader object's info log.
clan::ShaderObject::get_handle
unsigned int get_handle() const
Returns the OpenGL shader handle.
clan::XMLResourceDocument
XML Resource Document.
Definition: xml_resource_document.h:48
clan::ShaderObject::load_and_compile
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load and compile.
clan::shadertype_compute
Definition: shader_object.h:57
clan::shadertype_vertex
Definition: shader_object.h:52