Shader.h
Go to the documentation of this file.
#pragma once
#include <string>
#include <vector>
#include <map>
#include <glbinding/gl/types.h>
#include <globjects/globjects_api.h>
#include <globjects/base/Changeable.h>
#include <globjects/base/ChangeListener.h>
#include <globjects/base/ref_ptr.h>
#include <globjects/Object.h>
namespace globjects
{
class AbstractStringSource;
class GLOBJECTS_API Shader : public Object, protected ChangeListener, public Changeable
{
friend class Program;
public:
using IncludePaths = std::vector<std::string>;
public:
enum class IncludeImplementation
{
ShadingLanguageIncludeARB
, Fallback
};
static void hintIncludeImplementation(IncludeImplementation impl);
public:
static Shader * fromString(const gl::GLenum type, const std::string & sourceString, const IncludePaths & includePaths = IncludePaths());
static Shader * fromFile(const gl::GLenum type, const std::string & filename, const IncludePaths & includePaths = IncludePaths());
static void globalReplace(const std::string & search, const std::string & replacement);
static void globalReplace(const std::string & search, int i);
static void clearGlobalReplacements();
public:
Shader(const gl::GLenum type);
Shader(const gl::GLenum type, AbstractStringSource * source, const IncludePaths & includePaths = IncludePaths());
virtual void accept(ObjectVisitor& visitor) override;
gl::GLenum type() const;
void setSource(AbstractStringSource * source);
void setSource(const std::string & source);
const AbstractStringSource* source() const;
void updateSource();
const IncludePaths & includePaths() const;
void setIncludePaths(const IncludePaths & includePaths);
bool compile() const;
bool isCompiled() const;
void invalidate();
gl::GLint get(gl::GLenum pname) const;
std::string getSource() const;
bool checkCompileStatus() const;
std::string infoLog() const;
std::string typeString() const;
virtual gl::GLenum objectType() const override;
static std::string typeString(gl::GLenum type);
protected:
virtual ~Shader();
virtual void notifyChanged(const Changeable * changeable) override;
protected:
std::string shaderString() const;
protected:
gl::GLenum m_type;
ref_ptr<AbstractStringSource> m_source;
IncludePaths m_includePaths;
mutable bool m_compiled;
mutable bool m_compilationFailed;
static std::map<std::string, std::string> s_globalReplacements;
};
} // namespace globjects
globjects::Shader::m_includePaths
IncludePaths m_includePaths
Definition: Shader.h:106
ChangeListener.h
globjects::Shader::m_compilationFailed
bool m_compilationFailed
Definition: Shader.h:109
globjects::ref_ptr
The ref_ptr class provides the interface for a reference pointer.
Definition: LogMessageBuilder.h:20
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
globjects::Program
Wraps an OpenGL program.
Definition: Program.h:78
ref_ptr.h
Changeable.h
globjects::Changeable
Superclass of all objects that want others to signal that they have changed.
Definition: Changeable.h:22
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
globjects::Shader::s_globalReplacements
static std::map< std::string, std::string > s_globalReplacements
Definition: Shader.h:111
Object.h
globjects::Shader::m_source
ref_ptr< AbstractStringSource > m_source
Definition: Shader.h:105
globjects::Shader::IncludeImplementation
IncludeImplementation
Definition: Shader.h:48
globjects::Shader::IncludePaths
std::vector< std::string > IncludePaths
Definition: Shader.h:45
globjects::Shader::m_type
gl::GLenum m_type
Definition: Shader.h:104
globjects::Shader::m_compiled
bool m_compiled
Definition: Shader.h:108
globjects::ChangeListener
Allows listening to any Changeable.
Definition: ChangeListener.h:22
globjects::Shader
Encapsulates OpenGL shaders.
Definition: Shader.h:40
globjects::AbstractStringSource
Superclass for all types of static and dynamic strings, e.g. for the use as Shader code...
Definition: AbstractStringSource.h:25