PrevUpHomeNext

Programs

#include <oglplus/program.hpp>

Common program operations

template <>
class ObjCommonOps<tag::Program>
 : public ProgramName
{
public:
	static ProgramName Binding(void); 1

	static void Bind(ProgramName program); 2
	void Bind(void) const; 3

	void Use(void); 4
};

1

Returns the currently bound program. See glGet, GL_PROGRAM_BINDING.

2

Binds the specified program object. See glBindProgram.

3

Binds this program object. See glBindProgram.

4

Makes this program current. See glUseProgram.

Operations with direct state access

template <>
class ObjectOps<tag::DirectState, tag::Program>
 : public ObjZeroOps<tag::DirectState, tag::Program>
{
public:
	ObjectOps& AttachShader(ShaderName shader); 1

	ObjectOps& AttachShaders(const Sequence<ShaderName>& shaders); 2

	ObjectOps& DetachShader(ShaderName shader); 3

	Boolean IsLinked(void) const; 4

	String GetInfoLog(void) const; 5

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

	Outcome<ObjectOps&> Build(void); 7

#if GL_ARB_shading_language_include
	Outcome<ObjectOps&> BuildInclude(
		SizeType count,
		const GLchar* const* paths,
		const GLint* lengths
	); 8
	Outcome<ObjectOps&> BuildInclude(GLSLString&& incl);
	Outcome<ObjectOps&> BuildInclude(GLSLStrings&& incl);
	Outcome<ObjectOps&> BuildInclude(const GLSLSource&& incl);
#endif

	Boolean IsValid(void) const; 9

	ObjectOps& Validate(void); 10
	Outcome<ObjectOps&> Validate(std::nothrow_t);

1

Attaches a shader to this program. See glAttachShader.

2

Attaches a set of shaders to this program. See glAttachShader.

3

Detaches a shader from this program. See glDetachShader.

4

Returns true if this program is already linked, false otherwise. See glGetProgram, GL_LINK_STATUS.

5

Returns the linker output if the program is linked. See glGetProgramInfoLog.

6

Links this shading language program. Throws LinkError if the program cannot be linked. See glLinkProgram.

7

Checks if all attached shaders are compiled and if they are not the it compiles them and then links this Program. Throws CompileError if any of the shaders cannot be compiled, throws LinkError if the program cannot be linked. See glCompileShader, glLinkProgram.

8

Checks if all attached shaders are compiled and if they are not the it compiles them and using the specified include paths and then links this Program. See glCompileShader, glLinkProgram.

9

Returns true if this program is validated, false otherwise. See glGetProgram, GL_VALIDATE_STATUS.

10

Validates this shading language program. Throws ValidationError if the program is not valid. See glValidateProgram.

	void TransformFeedbackVarying(const GLchar* varying); 1

	void TransformFeedbackVaryings(
		SizeType count,
		const GLchar** varyings,
		TransformFeedbackMode mode
	); 2

	template <typename std::size_t N>
	void TransformFeedbackVaryings(
		const GLchar* (&varyings)[N],
		TransformFeedbackMode mode
	);

	void TransformFeedbackVaryings(
		const std::vector<String>& varyings,
		TransformFeedbackMode mode
	) const;


#if GL_VERSION_4_1 || GL_ARB_separate_shader_objects
	ObjectOps& MakeSeparable(Boolean para = true); 3
#endif

#if GL_VERSION_4_1 || GL_ARB_get_program_binary
	ObjectOps& MakeRetrievable(Boolean para = true); 4

	void GetBinary(std::vector<GLubyte>& binary, GLenum& format) const; 5

	void Binary(const std::vector<GLubyte>& binary, GLenum format); 6
#endif

	typedef <Unspecified> InterfaceContext; 7

#if GL_VERSION_4_3
	typedef Range<ProgramResource> ActiveResourceRange; 8

	InterfaceContext ActiveResourceContext(ProgramInterface intf) const; 9

	ActiveResourceRange ActiveResources(ProgramInterface intf) const; 10
#endif

1

Sets the variables that will be captured during transform feedback See glTransformFeedbackVaryings.

2

Sets the variables that will be captured during transform feedback See glTransformFeedbackVaryings.

3

Makes this program separable (or non-separable). See glProgramParameter.

4

Makes this program retrievable (or non-retrievable) in binary form. See glProgramParameter.

5

Gets the program code in binary form. See glGetProgramBinary.

6

Specifies the program code in binary form. See glProgramBinary.

7

Helper class for efficient iteration of Program interface items. Instances of this class are created by a program for its specific interfaces (uniform, vertex attributes, subroutines, etc.) or stages (vertex, geometry, fragment, etc.). Instances of an interface context can be used (mostly internally) for efficient iteration of individual items of a particular interface (uniforms, subroutines, etc.). Contexts for various programs and various interfaces are not interchangeable. The InterfaceContext type should be treated as opaque and only used with appropriate functions.

8

The type of the range for traversing program resource information.

9

Returns the context for traversal of Program's active resources.

10

Returns a range allowing to do the traversal of interface's resources. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

	class ActiveVariableInfo 1
	{
	public:
		GLuint Index(void) const; 2

		const String& Name(void) const; 3

		const GLint Size(void) const; 4

		const SLDataType Type(void) const; 5
	};

	typedef Range<ActiveVariableInfo> ActiveAttribRange; 6

	InterfaceContext ActiveAttribContext(void) const; 7

	ActiveAttribRange ActiveAttribs(void) const; 8


	typedef Range<ActiveVariableInfo> ActiveUniformRange; 9

	InterfaceContext ActiveUniformContext(void) const; 10

	ActiveUniformRange ActiveUniforms(void) const; 11

1

Class providing information about a single active vertex attribute or uniform. Note that the Program's functions documented as returning instances of ActiveVariableInfo actually return types convertible to ActiveVariableInfo.

2

Returns the index of the attribute or uniform.

3

Returns the name (identifier) of the attribute or uniform.

4

Returns the size in units of Type.

5

Returns the data type of the variable.

6

The type of the range for traversing active vertex attributes.

7

Returns the context for traversal of Program's active vertex attributes.

8

Returns a range allowing to do the traversal of active attributes. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

9

The type of the range for traversing active uniforms.

10

Returns the context for traversal of Program's active uniforms.

11

Returns a range allowing to do the traversal of active uniforms. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

#if GL_VERSION_4_0 || GL_ARB_shader_subroutine
	typedef Range<ActiveVariableInfo> ActiveSubroutineRange; 1

	InterfaceContext ActiveSubroutineContext(ShaderType stage) const; 2

	ActiveSubroutineRange ActiveSubroutines(ShaderType stage) const; 3

	typedef Range<ActiveVariableInfo> ActiveSubroutineUniformRange; 4

	InterfaceContext ActiveSubroutineUniformContext(ShaderType stage) const; 5

	ActiveSubroutineUniformRange ActiveSubroutineUniforms(ShaderType stage) const; 6
#endif

	typedef Range<ActiveVariableInfo> TransformFeedbackVaryingRange; 7

	InterfaceContext TransformFeedbackVaryingContext(void) const; 8

	TransformFeedbackVaryingRange TransformFeedbackVaryings(void) const; 9


	ShaderRange AttachedShaders(void) const; 10

1

The type of the range for traversing active subroutines.

2

Returns the context for traversal of Program's active subroutines.

3

Returns a range allowing to do the traversal of subroutines. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

4

The type of the range for traversing active subroutine uniforms.

5

Returns the context for traversal of Program's active subroutine uniforms.

6

Returns a range allowing to do the traversal of subroutine uniforms. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

7

The type of the range for traversing transform feedback varyings.

8

Returns the context for traversal of Program's active transform feedback varyings.

9

Returns a range allowing to do the traversal of transform feedback varyings. This instance of Program must be kept alive during the whole lifetime of the returned range, i.e. the returned range must not be used after the Program goes out of scope and is destroyed.

10

Returns a range allowing to traverse shaders attached to this program.

	TransformFeedbackMode TransformFeedbackBufferMode(void) const; 1

#if GL_VERSION_3_2
	GLint GeometryVerticesOut(void) const; 2

	PrimitiveType GeometryInputType(void) const; 3
	PrimitiveType GeometryOutputType(void) const; 4
#endif

#if GL_VERSION_4_1 || GL_ARB_gpu_shader5
	GLint GeometryShaderInvocations(void) const; 5
#endif

#if GL_VERSION_4_0 || GL_ARB_tessellation_shader
	FaceOrientation TessGenVertexOrder(void) const; 6

	TessGenPrimitiveType TessGenMode(void) const; 7

	TessGenPrimitiveSpacing TessGenSpacing(void) const; 8

	Boolean TessGenPointMode(void) const; 9
#endif

	void BindLocation(
		VertexAttribSlot vertex_attrib_slot,
		StrCRef identifier
	); 10
};

1

Returns the transform feedback buffer mode. See glGetProgram, GL_TRANSFORM_FEEDBACK_BUFFER_MODE.

2

Returns the number of vertices that the geometry shader will output. See glGetProgram, GL_GEOMETRY_VERTICES_OUT.

3

Returns the geometry shader input primitive type See glGetProgram, GL_GEOMETRY_INPUT_TYPE.

4

Returns the geometry shader output primitive type See glGetProgram, GL_GEOMETRY_OUTPUT_TYPE.

5

Returns the number of invocations of geometry shader per primitive. See glGetProgram, GL_GEOMETRY_SHADER_INVOCATIONS.

6

Returns the vertex order in tesselation evaluation shader. See glGetProgram, GL_TESS_GEN_VERTEX_ORDER.

7

Returns the tesselation generator output primitive type. See glGetProgram, GL_TESS_GEN_MODE.

8

Returns the tesselation generator primitive spacing mode. See glGetProgram, GL_TESS_GEN_SPACING.

9

Returns true if point mode is enabled in tesslation eval. shader. See glGetProgram, GL_TESS_GEN_POINT_MODE.

10

Binds the location of a shading language variable to a vertex attribute.

Definition

typedef ObjectOps<tag::DirectState, tag::Program>
	ProgramOps;

typedef ObjectZero<ObjZeroOps<tag::DirectState, tag::Program>>
	NoProgram;

typedef Object<ProgramOps>
	Program;

Example

The following code snippet shows the basic setup of a Program.

Context gl;

VertexShader vxs;
vxs.Source(
	"#version 150\n"
	"in vec3 Position;\n"
	"void main(void)\n"
	"{\n"
	"	gl_Position = Position;\n"
	"}\n"
).Compile();

TessControlShader tcs;
tcs.Source(/* ... */).Compile();

TessEvaluationShader tes;
tes.Source(/* ... */).Compile();

GeometryShader gys;
gys.Source(/* ... */).Compile();

FragmentShader fgs;
fgs.Source(/* ... */).Compile();

Program prog;

prog
	.AttachShader(vxs)
	.AttachShader(tcs)
	.AttachShader(tes)
	.AttachShader(gys)
	.AttachShader(fgs)
	.Link();

gl.Use(prog);

Syntax sugar

ProgramOps& operator << (
	ProgramOps& program,
	ShaderName shader
); 1

struct ProgAndXFBMode
{
	ProgAndXFBMode(ProgramOps& p, TransformFeedbackMode m);
};

ProgAndXFBMode operator << (
	ProgramOps& prog,
	TransformFeedbackMode mode
);

template <std::size_t N>
ProgramOps& operator << (
	ProgAndXFBMode pam,
	const GLchar* (&varyings)[N]
);

struct ProgXFBModeAndNames
{
	ProgXFBModeAndNames(ProgAndXFBMode pam, const GLchar* name);

	ProgXFBModeAndNames(ProgXFBModeAndNames&& pman, const GLchar* name);

	ProgXFBModeAndNames(ProgXFBModeAndNames&& tmp);
};

ProgXFBModeAndNames operator << (
	ProgAndXFBMode pam,
	const GLchar* name
);

ProgXFBModeAndNames operator << (
	ProgXFBModeAndNames&& pman,
	const GLchar* name
);

1

Equivalent to program.AttachShader(shader).

Examples

The syntax sugar operators make attaching shaders to a program less verbose as shown here:

Context gl;

VertexShader vxs;
TessControlShader tcs;
TessEvaluationShader tes;
GeometryShader gys;
FragmentShader fgs;

/* ... */

Program prog;

prog << vxs << tcs << tes << gys << fgs; 1
prog.Link();

gl.Use(prog);

1

Equivalent to Program::AttachShader(...).

These operators also simplify the specification of transform feedback varyings:

Program prog;

prog << VertexShader(
	ObjectDesc("Dist"),
	"#version 150\n"
	"uniform mat4 ProjectionMatrix, CameraMatrix;\n"
	"in vec4 Position;\n"
	"out uint xfbIndex;\n"
	"out float xfbDistance;\n"
	"void main(void)\n"
	"{\n"
	"	vec4 p = ProjectionMatrix*CameraMatrix*Position;\n"
	"	xfbIndex = uint(gl_VertexID);\n"
	"	xfbDistance = p.z;\n"
	"}\n"
);

prog	<< TransformFeedbackMode::SeparateAttribs 1
	<< "xfbIndex"
	<< "xfbDistance";

prog.Link();

1

Equivalent to calling Program::TransformFeedbackVaryings(...).

Shader program

#if GL_VERSION_4_1 || GL_ARB_separate_shader_objects
class ShaderProgram 1
 : public Program
{
public:
	ShaderProgram(
		ShaderType shader_type,
		GLSLString&& source
	); 2

	ShaderProgram(
		ShaderType shader_type,
		GLSLString&& source,
		ObjectDesc&& object_desc
	); 3

	ShaderProgram(
		ShaderType shader_type,
		GLSLStrings&& source
	); 4

	ShaderProgram(
		ShaderType shader_type,
		GLSLStrings&& source,
		ObjectDesc&& object_desc
	); 5

	ShaderProgram(
		ShaderType shader_type,
		const GLSLSource& glsl_source
	); 6

	ShaderProgram(
		ShaderType shader_type,
		const GLSLSource& glsl_source,
		ObjectDesc&& object_desc
	); 7
};
#endif

1

See glCreateShaderProgram.

2

Creates a program with a single shader with specified type and source. Throws ValidationError.

3

Creates a program with a single shader with specified type, source and description. Throws ValidationError.

4

Creates a program with a single shader with specified type and source. Throws ValidationError.

5

Creates a program with a single shader with specified type, source and description. Throws ValidationError.

6

Creates a program with a single shader with specified type and source. Throws ValidationError.

7

Creates a program with a single shader with specified type, source and description. Throws ValidationError.

Quick program

This class allows to supply a list of shaders and other parameters to the constructor. The shaders are attached to the Program and it is linked and made active. Optionally the program can also be made separable.

class QuickProgram
 : public Program
{
public:
	QuickProgram(const Sequence<ShaderName>& shaders); 1

	QuickProgram(
		ObjectDesc&& object_desc,
		const Sequence<ShaderName>& shaders
	); 2

#if GL_VERSION_4_1 || GL_ARB_separate_shader_objects
	QuickProgram(bool separable, const Sequence<ShaderName>& shaders); 3

	QuickProgram(
		ObjectDesc&& object_desc,
		bool separable,
		const Sequence<ShaderName>& shaders
	); 4
#endif
};

1

Attaches shaders, links and uses the program.

2

Attaches shaders, links, uses and describes the program.

3

Attaches shaders, makes the program separable, links and uses it.

4

Attaches shaders, makes the program separable, links, uses and describes it.

Program resource

#include <oglplus/program_resource.hpp>

class ProgramResource
{
public:
	GLint GetIntParam(ProgramResourceProperty property) const; 1
	Boolean GetBoolParam(ProgramResourceProperty property) const; 2

	bool Has(ProgramResourceProperty property) const; 3

	ProgramInterface Interface(void) const; 4

	const String& Name(void) const; 5

	GLuint Index(void) const; 6

	bool HasType(void) const; 7

	SLDataType Type(void) const; 8

	GLint Location(void) const; 9

	GLint LocationIndex(void) const; 10

	GLint ArraySize(void) const; 11

	Boolean IsPerPatch(void) const; 12

	Boolean ReferencedBy(ShaderType shader_type) const; 13
};

1

Gets the value of a single property (as a GLint). See glGetProgramResource.

2

Gets the value of a single property (as a boolean value).

3

Checks if this resource has the specified property.

4

Returns the interface of the resource.

5

Returns the name of the resource. See glGetProgramResourceName.

6

Returns the index of the resource.

7

Returns true if the resource has a type.

8

Returns the data type of the resource (if applicable). See glGetProgramResource, GL_TYPE.

9

Returns the program resource location (if applicable). See glGetProgramResource, GL_LOCATION.

10

Returns the program resource location index (if applicable). See glGetProgramResource, GL_LOCATION_INDEX.

11

Returns the array size of the resource (if applicable). See glGetProgramResource, GL_ARRAY_SIZE.

12

Returns true if the resource is per-patch (if applicable). See glGetProgramResource, GL_IS_PER_PATCH.

13

Returns true if the resource is referenced by shader of the specified type (if applicable).


PrevUpHomeNext