cgv
cgv::render::render_buffer Class Reference

#include <render_buffer.h>

Inheritance diagram for cgv::render::render_buffer:
cgv::render::render_component cgv::data::component_format cgv::data::packing_info

Public Member Functions

 render_buffer (const std::string &description="[R,G,B,A]")
 construct from description of component format, where the default format specifies a color buffer with alpha channel
 
void destruct (const context &ctx)
 destruct the render buffer
 
bool create (const context &ctx, int width=-1, int height=-1)
 
bool is_created () const override
 check whether the buffer has been created
 
 ~render_buffer ()
 calls the destruct method if necessary
 
int get_width () const
 return the width in pixels of the buffer
 
int get_height () const
 return the height in pixels of the buffer
 
bool is_depth_buffer () const
 return whether the component format corresponds to a depth buffer format
 
bool is_color_buffer () const
 return whether the component format corresponds to a color buffer format
 
void put_id_void (void *ptr) const
 
template<typename T >
void put_id (T &id) const
 cast the refence to rendering api specific representation of component id to the specified type
 
bool set_component_format (const std::string &description)
 set the component format from a description string More...
 
void set_component_format (ComponentFormat _cf)
 set the component names from a standard component format More...
 
void set_components (const std::string &_components)
 comma separated list of component descriptors, for example "R,G,B"
 
void set_integer_interpretation (ComponentIntegerInterpretation cii)
 set the integer interpretation
 
ComponentIntegerInterpretation get_integer_interpretation () const
 return current integer interpretation
 
template<typename T >
get (int ci, const void *ptr) const
 constant access to the i-th component stored at the given location
 
template<typename T >
bool set (int ci, void *ptr, const T &v) const
 write access to the i-th component, return whether write was successful
 
bool empty () const
 return whether the component format is defined
 
void clear ()
 clear the component format
 
const packing_infoget_packing_info () const
 return the packing info by simple conversion of the this pointer
 
void set_packing_info (const packing_info &pi)
 set packing info by simply assigning to a converted this pointer
 
unsigned int get_nr_components () const
 return the number of components More...
 
unsigned int get_component_index (const std::string &name) const
 return the index of a component given by name or -1 if not found
 
std::string get_component_name (unsigned int i) const
 return the name of the component with index i
 
ComponentFormat get_standard_component_format () const
 return whether the component format is one of the standard formats
 
void set_component_names (const std::string &_component_name_list)
 set component names from a comma or colon separated list of names
 
TypeId get_component_type () const
 return the component type
 
void set_component_type (TypeId _type_id)
 set the component type
 
unsigned int get_entry_size () const
 return the size of one entry of components in bytes More...
 
bool operator== (const component_format &cf) const
 comparison between component formats
 
bool operator== (const packing_info &pi) const
 equal comparison
 
bool operator!= (const component_format &cf) const
 comparison between component formats
 
bool operator!= (const packing_info &pi) const
 unequal comparison
 
unsigned int get_bit_depth (unsigned int ci) const
 return the bit depth of the ci-th component
 
void set_bit_depth (unsigned int ci, unsigned int depth)
 set the bit depth of the ci-th component
 
bool is_packing () const
 return whether packing is enabled
 
void set_packing (bool enable=true)
 set the packing flag
 
unsigned int get_component_alignment () const
 return the component alignment in bits in the packed case and in bytes in the unpacked case
 
void set_component_alignment (unsigned int a)
 set the component alignment in bits in the packed case and in bytes in the unpacked case
 
int get_signed (unsigned int ci, const void *ptr) const
 return the ci-th component of the data entry pointed to by the given pointer of a signed packed component
 
unsigned int get_unsigned (unsigned int ci, const void *ptr) const
 return the ci-th component of the data entry pointed to by the given pointer of an unsigned packed component
 
bool set_signed (unsigned int ci, void *ptr, int v) const
 set the ci-th component of the data entry pointed to by the given pointer of a signed packed component
 
bool set_unsigned (unsigned int ci, void *ptr, unsigned int v) const
 set the ci-th component of the data entry pointed to by the given pointer of an unsigned packed component
 

Static Public Member Functions

static const std::string & get_last_error ()
 returns an error string after parsing of description string has failed
 
static unsigned int align (unsigned int v, unsigned int a)
 return the next integer larger or equal to v which is dividable by a
 

Public Attributes

std::string last_error
 a string that contains the last error
 
const contextctx_ptr
 keep pointer to my context
 

Protected Member Functions

void extract_components ()
 extract components from component string More...
 

Protected Attributes

TypeId component_type
 store the type id of the component type
 
ComponentIntegerInterpretation component_interpretation
 interpretation of integer typed components
 
std::string component_string
 store all component names in one string separated with 0-chars
 
std::vector< unsigned short > component_positions
 store the position of each component in the component string
 

Detailed Description

this class encapsulate render buffers that live on the GPU which must support frame buffer objects for this to work.

Member Function Documentation

◆ create()

bool cgv::render::render_buffer::create ( const context ctx,
int  width = -1,
int  height = -1 
)

create a render buffer. If no extent is specified it is copied from the current viewport.

◆ extract_components()

void cgv::data::component_format::extract_components ( )
protectedinherited

extract components from component string

extract component_positions from component string

◆ get_entry_size()

unsigned int cgv::data::component_format::get_entry_size ( ) const
inherited

return the size of one entry of components in bytes

return the size of one entry of component_positions in bytes

◆ get_nr_components()

unsigned int cgv::data::component_format::get_nr_components ( ) const
inherited

return the number of components

return the number of component_positions

◆ put_id_void()

void cgv::render::render_component::put_id_void ( void *  ptr) const
inherited

copy the rendering api specific id the component to the memory location of the given pointer. For opengl this the passed pointer should be of type GLint or GLuint.

◆ set_component_format() [1/2]

void cgv::data::component_format::set_component_format ( ComponentFormat  _cf)
inherited

set the component names from a standard component format

set the component names from a given component format

◆ set_component_format() [2/2]

bool cgv::data::component_format::set_component_format ( const std::string &  description)
inherited

set the component format from a description string

set component format from description string, which has the following syntax. If a parse error arises, return false and set the static last_error member, which can be queried with get_last_error():

component_format <- [type] [attributes] '[' component [',' component]* ']'

component <- component_name [attributes]

attributes <- [':' bit_depth]['|' alignment]

type <- "undef" | "bool" | 
                "int8"  | "int16"  | "int32"  | "int64"  | "uint8"  | "uint16"  | "uint32"  | "uint64" |
                "sint8" | "sint16" | "sint32" | "sint64" |                                                // same as int* types but in snorm interpretation
                "_int8" | "_int16" | "_int32" | "_int64" | "_uint8" | "_uint16" | "_uint32" | "_uint64" | // same as [u]int* but in integer interpretation
                "flt16" | "flt32"  | "flt64"  | "string"

component_name : string ... name of component, i.e. "R", "Cb", "px", ...

bit_depth : unsigned int ... number of bits used to represent a component

alignment : unsigned int ... number of bits to which a component is aligned

Some examples of valid component format description strings:

  • "uint8:3|4[R,G,B,A]" ... four components represented as unsigned integers with no more than 8 bits. Actually, each component is stored with 3 bits and aligned to a bit index which is a multiple of 4
  • "uint8[R:5,G:6,B:5]" ... three components packed into 16 bits with 5 bits for R, 6 for G and 5 for B.
  • "sint8[R,G]" ... two component format of type int8 in snorm interpretation,
  • "_uint16[R]" ... one component format of type uint16 in integer interpretation,
  • "flt32[px,py]" ... two components of 32 bit floats
  • "[D]" ... one depth component without specified type, which defaults to "undef" and implies that the default depth format should be used.

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