1#include "color_scale_adapter.h"
7 return uniform_buffer_.create(ctx);
11 uniform_buffer_.destruct(ctx);
22 uniform_buffer_.bind(ctx, 0);
24 return texture_.
enable(ctx, texture_unit);
28 uniform_buffer_.unbind(ctx, 0);
36 prog.
set_uniform(ctx,
"color_scale_texture", texture_unit);
37 prog.set_uniform_block_binding(ctx,
"color_scale_argument_block", 0);
39 for(
size_t i = 0; i < color_scales_.size(); ++i)
40 uniforms_[i] = color_scales_[i]->get_arguments();
42 uniform_buffer_.resize_or_replace(ctx, uniforms_);
49 if(!color_scales_.size() == 1 || color_scales_.front() != color_scale) {
50 auto g = cgv::data::time_point::min();
52 color_scales_ = { color_scale };
53 uniforms_ = std::vector<device_color_scale_arguments>(1);
58 if(color_scales_ != color_scales) {
60 color_scales_ = color_scales;
61 if(color_scales_.size() > k_max_color_scale_count_)
62 color_scales_.resize(k_max_color_scale_count_);
63 uniforms_ = std::vector<device_color_scale_arguments>(color_scales_.size());
72cgv::data::time_point color_scale_adapter::get_latest_color_scale_modification_time()
const {
73 cgv::data::time_point time;
74 for(
const auto& color_scale : color_scales_)
75 time = std::max(time, color_scale->get_modified_time());
79bool color_scale_adapter::create_texture(
const context& ctx) {
80 if(color_scales_.empty())
83 if(!build_time_.is_valid() || get_latest_color_scale_modification_time() > build_time_.get_modified_time()) {
84 std::vector<cgv::rgba8> texture_data;
86 for(
const auto& color_scale : color_scales_) {
87 size_t offset = texture_data.size();
88 texture_data.resize(texture_data.size() + k_texture_width_);
89 std::vector<rgba> colors = color_scale->get_texture_data(k_texture_width_);
90 std::transform(colors.begin(), colors.end(), texture_data.begin() + offset, [](
const cgv::rgba& color) {
91 return cgv::rgba8(color);
102 build_time_.modified();
103 return texture_.
create(ctx, data_view, 0);
the data view gives access to a data array of one, two, three or four dimensions.
void set_color_scales(const std::vector< std::shared_ptr< const device_color_scale > > &color_scales)
Set a reference to multiple device_color_scales to be managed by this color_scale_adapter.
bool destruct(const context &ctx)
Destruct the color_scale_adapter.
bool disable(const context &ctx)
Disable the managed render resources after rendering.
bool enable(const context &ctx, int texture_unit)
Enable the managed render resources to prepare for rendering.
texture & get_texture(const context &ctx)
Get the texture containing the device_color_scales' color data.
void set_uniforms_in_program(context &ctx, shader_program &prog, int texture_unit)
Set texture unit and uniform buffer location in the given shader_program and prepare uniform buffer.
bool init(const context &ctx)
Initialize the color_scale_adapter.
void set_color_scale(std::shared_ptr< const device_color_scale > color_scale)
Set a reference to a single device_color_scale to be managed by this color_scale_adapter.
base class for all drawables, which is independent of the used rendering API.
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool is_enabled() const
check whether program is currently enabled
the texture class encapsulates all functionality independent of the rendering api.
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
bool create(const context &ctx, TextureType _tt=TT_UNDEF, unsigned width=-1, unsigned height=-1, unsigned depth=-1)
create the texture of dimension and resolution specified in the data format base class.
bool disable(const context &ctx)
disable texture and restore state from before last enable call
bool enable(const context &ctx, int tex_unit=-1)
enable this texture in the given texture unit, -1 corresponds to the current unit.
bool destruct(const context &ctx)
destruct the texture and free texture memory and handle
void set_min_filter(TextureFilter _min_filter, float _anisotropy=2.0f)
set the minification filters, if minification is set to TF_ANISOTROP, the second floating point param...
@ CF_RGBA
color format with components R, G and B
TextureFilter
different texture filter
@ TI_UINT8
signed integer stored in 64 bits
this header is dependency free