23 shaders_.push_back(shader);
27 shaders_.emplace_back(std::move(shader));
32 bool all_valid = std::all_of(std::begin(shaders_),
36 return shader && shader.get()->is_valid();
45 if(shaders_.size() == 1)
47 const auto& compute_shader = shaders_[0];
48 program_ = std::make_shared<gfx::program>(*compute_shader.get());
50 else if(shaders_.size() == 2)
52 const auto& vertex_shader = shaders_[0];
53 const auto& fragment_shader = shaders_[1];
54 program_ = std::make_shared<gfx::program>(*vertex_shader.get(), *fragment_shader.get());
57 for(std::size_t i = 0; i < shaders_.size(); ++i)
59 const auto& shader = shaders_[i];
60 shaders_cached_[i] = shader.get();
66 const hpp::string_view& sampler,
71 program_->set_texture(stage, sampler, fbo, attachment, flags);
75 const hpp::string_view& sampler,
79 program_->set_texture(stage, sampler, texture, flags);
84 program_->set_uniform(
name, value, num);
104 return program_->get_uniform(
name);
109 return program_->native_handle();
119 return program_ && program_->is_valid();
124 bool repopulate =
false;
125 for(std::size_t i = 0; i < shaders_.size(); ++i)
127 auto shader_ptr = shaders_[i];
133 if(shaders_cached_[i] != shader_ptr.get())
176 std::vector<mat_type> mats;
177 mats.reserve(matrices.size());
178 for(
const auto& m : matrices)
180 mats.emplace_back(m.get_matrix());
188 auto mat4 = (
const void*)math::value_ptr(matrix);
215 std::vector<mat_type> mats;
216 mats.reserve(matrices.size());
217 for(
const auto& m : matrices)
219 mats.emplace_back(m.get_matrix());
227 auto mat4 = (
const void*)math::value_ptr(matrix);
std::shared_ptr< frame_buffer > ptr
gpu_program()=default
Default constructor.
void attach_shader(asset_handle< gfx::shader > shader)
Attaches a shader to the GPU program.
auto begin() -> bool
Begins usage of the program. Checks validity of attached shaders and recreates the internal program i...
void populate()
Populates the GPU 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_uniform(const hpp::string_view &name, const void *value, std::uint16_t num=1)
Sets a uniform value in the shader program.
auto is_valid() const -> bool
Checks if the GPU program is valid.
void end()
Indicates the end of working with a program.
auto native_handle() const -> gfx::program::handle_type_t
Retrieves the native handle of the internal shader program.
auto get_uniform(const hpp::string_view &name) -> gfx::program::uniform_ptr
Retrieves a uniform from the shader program.
auto get_shaders() const -> const std::vector< asset_handle< gfx::shader > > &
Retrieves the shader assets that created the shader program.
bgfx::Attachment attachment
void set_world_transform(const void *_mtx, uint16_t _num)
uint32_t set_transform(const void *_mtx, uint16_t _num)
void set_uniform(uniform_handle _handle, const void *_value, uint16_t _num)
void set_texture(uint8_t _stage, uniform_handle _sampler, texture_handle _handle, uint32_t _flags)
Represents a handle to an asset, providing access and management functions.
std::shared_ptr< uniform > uniform_ptr