3#include <cgv/data/optional.h>
8#define CGV_RDB_TRANSFER_ARRAY(NAME, DATA) \
9if(DATA.size() == super::size()) \
10 r.set_##NAME##_array(ctx, DATA); \
11else if(DATA.empty()) \
12 r.remove_##NAME##_array(ctx);
65template <
class RendererType,
class RenderStyleType,
typename ColorType = rgb>
69 bool state_out_of_date =
true;
86 state_out_of_date =
false;
93 r.set_color_array(ctx,
colors);
95 r.remove_color_array(ctx);
102 r.remove_indices(ctx);
138 void fill(std::vector<T>& vector,
const T& value) {
139 if(vector.size() <
size())
140 vector.resize(
size(), value);
177 state_out_of_date =
true;
187 state_out_of_date =
true;
236 r.enable_attribute_array_manager(ctx, this->attribute_array);
237 if(this->state_out_of_date)
239 r.disable_attribute_array_manager(ctx, this->attribute_array);
252 if(this->
size() > 0) {
253 r.set_render_style(s);
254 r.enable_attribute_array_manager(ctx, this->attribute_array);
256 if(this->state_out_of_date)
260 return r.validate_and_enable(ctx);
261 }
else if(this->state_out_of_date) {
272 bool res = r.disable(ctx);
273 r.disable_attribute_array_manager(ctx, this->attribute_array);
293 offset = std::min(offset,
static_cast<unsigned>(draw_count));
294 draw_count = std::min(offset + (count < 0 ? draw_count : count), draw_count) - offset;
296 r.
draw(ctx, offset, draw_count);
318 void render(
context& ctx,
const RenderStyleType& s,
unsigned offset = 0,
int count = -1) {
330 void render(
context& ctx, RendererType& r,
unsigned offset = 0,
int count = -1) {
343 void render(
context& ctx, RendererType& r,
const RenderStyleType& s,
unsigned offset = 0,
int count = -1) {
345 this->
draw(ctx, r, offset, count);
350 void add_index(
const uint32_t index) {
354 void add_position(
const vec3& position) {
358 void add_color(
const ColorType& color) {
362 void add(
const vec3& position,
const ColorType& color) {
363 add_position(position);
367 void fill_colors(
const ColorType& color) {
A simple and naiive implementation of an optional value.
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
A base class for storing render data and style usable with the default renderers provided in the cgv:...
const attribute_array_manager & ref_attribute_array_manager() const
Constant access to the private attribute_array_manager.
bool disable(context &ctx, RendererType &r)
Disable the renderer and attribute_array.
void render(context &ctx, const RenderStyleType &s, unsigned offset=0, int count=-1)
Render the stored geometry using the given style.
void early_transfer(context &ctx, RendererType &r)
Perform a transfer of the stored data to the attribute_array right now.
cgv::data::optional< ColorType > const_color
optional constant color used for all elements
size_t render_count()
Return the number of vertices that will be rendered.
void render(context &ctx, unsigned offset=0, int count=-1)
Render the stored geometry.
size_t size()
Return the number of stored positions.
std::vector< ColorType > colors
array of colors
virtual bool transfer(context &ctx, RendererType &r)
Transfers the data stored in members to the attribute array.
std::vector< vec3 > positions
array of positions
std::vector< uint32_t > indices
array of indices used for optional indexed rendering
bool init(context &ctx)
Initialize the attribute array manager.
void render(context &ctx, RendererType &r, unsigned offset=0, int count=-1)
Render the stored geometry using the given renderer.
void destruct(context &ctx)
Destruct the attribute array manager and decrease the reference count of the used renderer.
void render(context &ctx, RendererType &r, const RenderStyleType &s, unsigned offset=0, int count=-1)
Render the stored geometry using the given renderer and style.
void clear()
Clear the stored data and set state out of date.
bool empty() const
Return whether this render data is empty.
void draw(context &ctx, renderer &r, unsigned offset=0, int count=-1)
Draw the stored geometry using the given renderer.
void fill(std::vector< T > &vector, const T &value)
Template for filling a member array to the size of the render data.
RenderStyleType style
the default render style
bool enable(context &ctx, RendererType &r, const RenderStyleType &s)
Enable the render data for rendering.
virtual void set_const_attributes(context &ctx, RendererType &r)
Set constant vertex attributes if present.
void set_out_of_date()
Notify the render data about state changes.
virtual RendererType & ref_renderer_singleton(context &ctx, int ref_count_change=0)=0
Manage the singleton of the used renderer.
abstract base class for all renderers that handles a shader program and position / color attribute
virtual void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
Draw a range of vertices or indexed elements.
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors