shader_object.h Source File - ClanLib SDK
Description: shader_object.h Source File

shader_object.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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
38namespace clan
39{
42
43 class GraphicContextProvider;
44 class XMLResourceDocument;
45 class ShaderObject_Impl;
46 class ShaderObjectProvider;
47
49 enum class ShaderType
50 {
51 vertex,
52 geometry,
53 fragment,
54 tess_evaluation,
55 tess_control,
56 compute,
57 num_types
58 };
59
67 class ShaderObject
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
167 static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, IODevice &file);
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
181 std::string get_shader_source() const;
182
184 bool is_null() const { return !impl; }
185 explicit operator bool() const { return bool(impl); }
186
188 void throw_if_null() const;
189
193 ShaderObjectProvider *get_provider() const;
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}
clan::FileSystem
Virtual File System (VFS).
Definition file_system.h:47
clan::GraphicContextProvider
Interface for implementing a GraphicContext target.
Definition graphic_context_provider.h:86
clan::GraphicContext
Interface to drawing graphics.
Definition graphic_context.h:257
clan::IODevice
I/O Device interface.
Definition iodevice.h:50
clan::ShaderObjectProvider
Shader Object provider.
Definition shader_object_provider.h:42
clan::ShaderObject
Shader Object.
Definition shader_object.h:68
clan::ShaderObject::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::ShaderObject::compile
bool compile()
Compile program.
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::ShaderObject::ShaderObject
ShaderObject()
Constructs a null instance.
clan::ShaderObject::load
static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &fullname)
Load.
clan::ShaderObject::get_shader_source
std::string get_shader_source() const
Get shader source code.
clan::ShaderObject::ShaderObject
ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::string &source)
Constructs a ShaderObject.
clan::ShaderObject::get_handle
unsigned int get_handle() const
Returns the OpenGL shader handle.
clan::ShaderObject::load
static ShaderObject load(GraphicContext &gc, ShaderType type, const std::string &filename, const FileSystem &fs)
Load.
clan::ShaderObject::ShaderObject
ShaderObject(GraphicContext &gc, ShaderType type, const std::string &source)
Constructs an OpenGL shader.
clan::ShaderObject::operator==
bool operator==(const ShaderObject &other) const
Handle comparison operator.
clan::ShaderObject::load_and_compile
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, const std::string &filename)
Load and compile.
clan::ShaderObject::~ShaderObject
virtual ~ShaderObject()
clan::ShaderObject::get_info_log
std::string get_info_log() const
Get shader object's info log.
clan::ShaderObject::load
static ShaderObject load(GraphicContext &gc, ShaderType type, IODevice &file)
Load.
clan::ShaderObject::load
static ShaderObject load(GraphicContext &gc, const std::string &resource_id, const XMLResourceDocument &resources)
Load.
clan::ShaderObject::ShaderObject
ShaderObject(GraphicContext &gc, ShaderType type, const std::vector< std::string > &sources)
Constructs a ShaderObject.
clan::ShaderObject::get_provider
ShaderObjectProvider * get_provider() const
Get Provider.
clan::ShaderObject::ShaderObject
ShaderObject(GraphicContext &gc, ShaderType type, const void *source, int source_size)
Constructs a ShaderObject.
clan::ShaderObject::is_null
bool is_null() const
Returns true if this object is invalid.
Definition shader_object.h:184
clan::ShaderObject::get_shader_type
ShaderType get_shader_type() const
Gets the shader type.
clan::ShaderObject::ShaderObject
ShaderObject(GraphicContextProvider *gc_provider, ShaderType type, const std::vector< std::string > &sources)
Constructs a ShaderObject.
clan::ShaderObject::load_and_compile
static ShaderObject load_and_compile(GraphicContext &gc, ShaderType type, IODevice &file)
Load and compile.
clan::XMLResourceDocument
XML Resource Document.
Definition xml_resource_document.h:48
clan::ShaderType
ShaderType
Shader Type.
Definition shader_object.h:50
clan::ShaderType::fragment
@ fragment
clan::ShaderType::vertex
@ vertex
clan::ShaderType::tess_evaluation
@ tess_evaluation
clan::ShaderType::compute
@ compute
clan::ShaderType::tess_control
@ tess_control
clan::ShaderType::num_types
@ num_types
clan::ShaderType::geometry
@ geometry
clan
Definition clanapp.h:36