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