Unravel Engine C++ Reference
Loading...
Searching...
No Matches
unravel::gpu_program Class Reference

Class representing a GPU program. More...

#include <gpu_program.h>

Public Types

using ptr = std::shared_ptr<gpu_program>
 
using wptr = std::weak_ptr<gpu_program>
 
using uptr = std::unique_ptr<gpu_program>
 

Public Member Functions

 gpu_program ()=default
 Default constructor.
 
 gpu_program (asset_handle< gfx::shader > compute_shader)
 Constructor to create a program from a compute shader asset.
 
 gpu_program (asset_handle< gfx::shader > vertex_shader, asset_handle< gfx::shader > fragment_shader)
 Constructor to create a program from vertex and fragment shader assets.
 
auto begin () -> bool
 Begins usage of the program. Checks validity of attached shaders and recreates the internal program if necessary.
 
void end ()
 Indicates the end of working with a program.
 
void set_texture (std::uint8_t stage, const hpp::string_view &sampler, const gfx::frame_buffer *handle, uint8_t attachment=0, std::uint32_t flags=std::numeric_limits< std::uint32_t >::max())
 Sets the texture for a specific stage using a frame buffer.
 
void set_texture (std::uint8_t stage, const hpp::string_view &sampler, const gfx::texture *texture, std::uint32_t flags=std::numeric_limits< std::uint32_t >::max())
 Sets the texture for a specific stage using a texture.
 
void set_uniform (const hpp::string_view &name, const void *value, std::uint16_t num=1)
 Sets a uniform value in the shader program.
 
void set_uniform (const hpp::string_view &name, const math::vec4 &value, std::uint16_t num=1)
 Sets a uniform value in the shader program.
 
void set_uniform (const hpp::string_view &name, const math::vec3 &value, std::uint16_t num=1)
 Sets a uniform value in the shader program.
 
void set_uniform (const hpp::string_view &name, const math::vec2 &value, std::uint16_t num=1)
 Sets a uniform value in the shader program.
 
auto get_uniform (const hpp::string_view &name) -> gfx::program::uniform_ptr
 Retrieves a uniform from the shader program.
 
auto native_handle () const -> gfx::program::handle_type_t
 Retrieves the native handle of the internal shader program.
 
auto get_shaders () const -> const std::vector< asset_handle< gfx::shader > > &
 Retrieves the shader assets that created the shader program.
 
auto is_valid () const -> bool
 Checks if the GPU program is valid.
 
void populate ()
 Populates the GPU program.
 
void attach_shader (asset_handle< gfx::shader > shader)
 Attaches a shader to the GPU program.
 

Detailed Description

Class representing a GPU program.

Definition at line 16 of file gpu_program.h.

Member Typedef Documentation

◆ ptr

using unravel::gpu_program::ptr = std::shared_ptr<gpu_program>

Definition at line 19 of file gpu_program.h.

◆ uptr

using unravel::gpu_program::uptr = std::unique_ptr<gpu_program>

Definition at line 21 of file gpu_program.h.

◆ wptr

using unravel::gpu_program::wptr = std::weak_ptr<gpu_program>

Definition at line 20 of file gpu_program.h.

Constructor & Destructor Documentation

◆ gpu_program() [1/3]

unravel::gpu_program::gpu_program ( )
default

Default constructor.

◆ gpu_program() [2/3]

unravel::gpu_program::gpu_program ( asset_handle< gfx::shader > compute_shader)

Constructor to create a program from a compute shader asset.

Parameters
compute_shaderThe compute shader asset.

Definition at line 6 of file gpu_program.cpp.

◆ gpu_program() [3/3]

unravel::gpu_program::gpu_program ( asset_handle< gfx::shader > vertex_shader,
asset_handle< gfx::shader > fragment_shader )

Constructor to create a program from vertex and fragment shader assets.

Parameters
vertex_shaderThe vertex shader asset.
fragment_shaderThe fragment shader asset.

Definition at line 12 of file gpu_program.cpp.

Member Function Documentation

◆ attach_shader()

void unravel::gpu_program::attach_shader ( asset_handle< gfx::shader > shader)

Attaches a shader to the GPU program.

Parameters
shaderThe shader to attach.

Definition at line 19 of file gpu_program.cpp.

◆ begin()

auto unravel::gpu_program::begin ( ) -> bool

Begins usage of the program. Checks validity of attached shaders and recreates the internal program if necessary.

Returns
true if the program begins successfully, false otherwise.

Definition at line 122 of file gpu_program.cpp.

◆ end()

void unravel::gpu_program::end ( )

Indicates the end of working with a program.

Definition at line 148 of file gpu_program.cpp.

◆ get_shaders()

auto unravel::gpu_program::get_shaders ( ) const -> const std::vector<asset_handle<gfx::shader>>&

Retrieves the shader assets that created the shader program.

Returns
The vector of shader assets.

Definition at line 112 of file gpu_program.cpp.

◆ get_uniform()

auto unravel::gpu_program::get_uniform ( const hpp::string_view & name) -> gfx::program::uniform_ptr

Retrieves a uniform from the shader program.

Parameters
_nameThe name of the uniform.
Returns
The uniform pointer.

Definition at line 102 of file gpu_program.cpp.

◆ is_valid()

auto unravel::gpu_program::is_valid ( ) const -> bool

Checks if the GPU program is valid.

Returns
true if the program is valid, false otherwise.

Definition at line 117 of file gpu_program.cpp.

◆ native_handle()

auto unravel::gpu_program::native_handle ( ) const -> gfx::program::handle_type_t

Retrieves the native handle of the internal shader program.

Returns
The native handle of the program.

Definition at line 107 of file gpu_program.cpp.

◆ populate()

void unravel::gpu_program::populate ( )

Populates the GPU program.

Definition at line 30 of file gpu_program.cpp.

◆ set_texture() [1/2]

void unravel::gpu_program::set_texture ( std::uint8_t stage,
const hpp::string_view & sampler,
const gfx::frame_buffer * handle,
uint8_t attachment = 0,
std::uint32_t flags = std::numeric_limits< std::uint32_t >::max() )

Sets the texture for a specific stage using a frame buffer.

Parameters
_stageThe stage number.
_samplerThe sampler name.
_handleThe frame buffer handle.
_attachmentThe attachment point.
_flagsThe texture flags.

◆ set_texture() [2/2]

void unravel::gpu_program::set_texture ( std::uint8_t stage,
const hpp::string_view & sampler,
const gfx::texture * texture,
std::uint32_t flags = std::numeric_limits< std::uint32_t >::max() )

Sets the texture for a specific stage using a texture.

Parameters
_stageThe stage number.
_samplerThe sampler name.
_textureThe texture handle.
_flagsThe texture flags.

◆ set_uniform() [1/4]

void unravel::gpu_program::set_uniform ( const hpp::string_view & name,
const math::vec2 & value,
std::uint16_t num = 1 )

Sets a uniform value in the shader program.

Parameters
_nameThe name of the uniform.
_valueThe vec2 value to set.
_numThe number of elements (default is 1).

◆ set_uniform() [2/4]

void unravel::gpu_program::set_uniform ( const hpp::string_view & name,
const math::vec3 & value,
std::uint16_t num = 1 )

Sets a uniform value in the shader program.

Parameters
_nameThe name of the uniform.
_valueThe vec3 value to set.
_numThe number of elements (default is 1).

◆ set_uniform() [3/4]

void unravel::gpu_program::set_uniform ( const hpp::string_view & name,
const math::vec4 & value,
std::uint16_t num = 1 )

Sets a uniform value in the shader program.

Parameters
_nameThe name of the uniform.
_valueThe vec4 value to set.
_numThe number of elements (default is 1).

◆ set_uniform() [4/4]

void unravel::gpu_program::set_uniform ( const hpp::string_view & name,
const void * value,
std::uint16_t num = 1 )

Sets a uniform value in the shader program.

Parameters
_nameThe name of the uniform.
_valueThe value to set.
_numThe number of elements (default is 1).

The documentation for this class was generated from the following files: