PrevUpHomeNext

Shaders

#include <oglplus/shader.hpp>

Common shader operations

template <>
struct ObjectSubtype<tag::Shader>
{
	typedef ShaderType Type;
};

template <>
class ObjCommonOps<tag::Shader>
 : public ShaderName
{
public:
#if GL_ES_VERSION_3_0 || GL_VERSION_4_1 || GL_ARB_ES2_compatibility
	static void PrecisionFormat(
		ShaderType shader_type,
		PrecisionType precision_type,
		GLint* range_log_2,
		GLint* precision_log_2
	); 1
};

1

Gets the shader precision format. See glGetShaderPrecisionFormat.

Operations with direct state access

template <>
class ObjectOps<tag::DirectState, tag::Shader>
 : public ObjZeroOps<tag::DirectState, tag::Shader> 1
{
public:
	struct Property
	{
		typedef ShaderType Type;
	};

	ShaderType Type(void) const; 2

	ObjectOps& Source(
		const SizeType count,
		const GLchar* const * srcs,
		const GLint* lens
	); 3
	ObjectOps& Source(GLSLString&& source);
	ObjectOps& Source(GLSLStrings&& source);
	ObjectOps& Source(const GLSLSource& glsl_source);

	Boolean IsCompiled(void) const; 4

	ObjectOps& Compile(void); 5
	Outcome<ObjectOps&> Compile(std::nothrow_t); 6

	String GetInfoLog(void) const; 7

#if GL_ARB_shading_language_include
	ObjectOps& CompileInclude(
		SizeType count,
		const GLchar* const* paths,
		const GLint* lengths
	); 8

	ObjectOps& CompileInclude(GLSLString&& incl);
	ObjectOps& CompileInclude(GLSLStrings&& incl);
	ObjectOps& CompileInclude(const GLSLSource& incl);

	Outcome<ObjectOps&> CompileInclude(
		SizeType count,
		const GLchar* const* paths,
		const GLint* lengths,
		std::nothrow_t
	);

	Outcome<ObjectOps&> CompileInclude(GLSLString&& incl, std::nothrow_t);
	Outcome<ObjectOps&> CompileInclude(GLSLStrings&& incl, std::nothrow_t);
	Outcome<ObjectOps&> CompileInclude(const GLSLSource& incl, std::nothrow_t);
#endif

#if GL_ES_VERSION_3_0 || GL_VERSION_4_1 || GL_ARB_ES2_compatibility
	static void ReleaseCompiler(void); 9
#endif
};

1

Indirectly inherits from ObjCommonOps<tag::Shader>.

2

Returns the type of this shader. See glGetShader, GL_SHADER_TYPE.

3

Set the source code of this shader. See glShaderSource.

4

Returns true if the shader is already compiled, returns false otherwise. See glGetShader, GL_COMPILE_STATUS.

5

Compiles this shader. Throws CompileError if the shader cannot be compiled. See glCompileShader.

6

This overload of Compile defers the error handling.

7

Returns the compiler output if the shader is compiled. See glGetShader, glGetShaderInfoLog.

8

Compiles the shader using the specified include paths. See glCompileShaderIncludeARB.

9

Indicates that the resources associated with the compiler can be freed. See glReleaseShaderCompiler.

typedef ObjectOps<tag::DirectState, tag::Shader> ShaderOps;

class Shader
 : public Object<ShaderOps>
{
public:
	Shader(ShaderType type);

	Shader(ShaderType type, ObjectDesc&& description);

	Shader(ShaderType type, GLSLString&& glsl_source);
	Shader(ShaderType type, GLSLStrings&& glsl_source);
	Shader(ShaderType type, const GLSLSource& glsl_source);

	Shader(
		ShaderType type,
		ObjectDesc&& description,
		GLSLString&& glsl_source
	);

	Shader(
		ShaderType type,
		ObjectDesc&& description,
		GLSLStrings&& glsl_source
	);

	Shader(
		ShaderType type,
		ObjectDesc&& description,
		const GLSLSource& glsl_source
	);

	Shader(const Shader&) = delete;
	Shader(Shader&&);

	Shader& operator = (Shader&&);
};

Specialized shaders

template <ShaderType Type>
class SpecShader
 : public Shader
{
public:
	SpecShader(void);

	SpecShader(ObjectDesc&& description);

	SpecShader(GLSLString&& glsl_source);
	SpecShader(GLSLStrings&& glsl_source);
	SpecShader(const GLSLSource& glsl_source);

	SpecShader(ObjectDesc&& description, GLSLString&& glsl_source);
	SpecShader(ObjectDesc&& description, GLSLStrings&& glsl_source);
	SpecShader(ObjectDesc&& description, const GLSLSource& glsl_source);

	SpecShader(const SpecShader&) = delete;
	SpecShader(SpecShader&&);
};

typedef SpecShader<ShaderType::Vertex> VertexShader;

#if GL_TESS_CONTROL_SHADER
typedef SpecShader<ShaderType::TessControl> TessControlShader;
#endif

#if GL_TESS_EVALUATION_SHADER
typedef SpecShader<ShaderType::TessEvaluation> TessEvaluationShader;
#endif

#if GL_GEOMETRY_SHADER
typedef SpecShader<ShaderType::Geometry> GeometryShader;
#endif

typedef SpecShader<ShaderType::Fragment> FragmentShader;

#if GL_COMPUTE_SHADER
typedef SpecShader<ShaderType::Compute> ComputeShader;
#endif

PrevUpHomeNext