cgv
Loading...
Searching...
No Matches
cgv::render::texture Class Reference

the texture class encapsulates all functionality independent of the rendering api. More...

#include <texture.h>

Inheritance diagram for cgv::render::texture:
cgv::render::texture_base cgv::data::data_format cgv::render::render_component cgv::data::component_format cgv::data::packing_info

Public Member Functions

methods that can be called without context
 texture (const std::string &description="uint8[R,G,B,A]", TextureFilter _mag_filter=TF_LINEAR, TextureFilter _min_filter=TF_LINEAR, TextureWrap _wrap_s=TW_CLAMP_TO_EDGE, TextureWrap _wrap_t=TW_CLAMP_TO_EDGE, TextureWrap _wrap_r=TW_CLAMP_TO_EDGE)
 construct from description string (which defaults to rgba format) and most commonly used texture parameters.
 ~texture ()
 destruct texture, the destructor can be called without context if the destruct method has been called or no creation has taken place
bool set_data_format (const std::string &description)
 change the data format and clear internal format
void set_component_format (const component_format &cf)
 change component format and clear internal format
void set_component_format (const std::string &description)
 change component format and clear internal format
void set_wrap_s (TextureWrap _wrap_s)
 set the texture wrap behaviour in s direction
void set_wrap_t (TextureWrap _wrap_t)
 set the texture wrap behaviour in t direction
void set_wrap_r (TextureWrap _wrap_r)
 set the texture wrap behaviour in r direction
TextureWrap get_wrap_s () const
 return the texture wrap behaviour in s direction
TextureWrap get_wrap_t () const
 return the texture wrap behaviour in t direction
TextureWrap get_wrap_r () const
 return the texture wrap behaviour in r direction
void set_border_color (const float *rgba)
 set the border color
void set_border_color (float r, float g, float b, float a=1.0f)
 set the border color
cgv::vec4 get_border_color () const
 return the texture border color
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 parameter specifies the degree of anisotropy
TextureFilter get_min_filter () const
 return the minification filter
float get_anisotropy () const
 return the currently set anisotropy
void set_mag_filter (TextureFilter _mag_filter)
 set the magnification filter
TextureFilter get_mag_filter () const
 return the magnification filter
void set_priority (float _priority)
 set priority with which texture is kept in GPU memory
float get_priority () const
 return the priority with which texture is kept in GPU memory
void set_compare_mode (bool use_compare_function)
 set the texture compare mode and function
bool get_compare_mode () const
 get the texture compare mode and function
void set_compare_function (CompareFunction compare_function)
 set the texture compare function
CompareFunction get_compare_function () const
 get the texture compare function
bool mipmaps_created () const
 check whether mipmaps have been created
void set_nr_multi_samples (unsigned _nr_samples)
 set the number of multi samples for textures of type TT_MULTISAMPLE_2D and TT_MULTISAMPLE_2D_ARRAY
unsigned get_nr_multi_samples () const
 return number of multi samples for textures of type TT_MULTISAMPLE_2D and TT_MULTISAMPLE_2D_ARRAY
bool use_fixed_sample_locations () const
 whether multi sampling uses fixed sample locations
void set_fixed_sample_locations (bool use)
 set whether multi sampling uses fixed sample locations
void ensure_state (const context &ctx) const
 ensure the the texture state is synchronized with the GPU settings
bool is_enabled () const
 check whether textue is enabled
int get_tex_unit () const
 return the currently used texture unit and -1 for current
methods that change the current gpu context
bool enable (const context &ctx, int tex_unit=-1)
 enable this texture in the given texture unit, -1 corresponds to the current unit.
bool disable (const context &ctx)
 disable texture and restore state from before last enable call
bool bind_as_image (const context &ctx, int tex_unit, int level=0, bool bind_array=false, int layer=0, AccessType access=AT_WRITE_ONLY)
 Binds this texture as an image texture to the given texture unit.
Public Member Functions inherited from cgv::render::texture_base
 texture_base (TextureType _tt=TT_UNDEF)
 initialize members
Public Member Functions inherited from cgv::render::render_component
 render_component ()
 initialize members
virtual bool is_created () const
 return whether component has been created
void put_id_void (void *ptr) const
 copy the rendering api specific id the component to the memory location of the given pointer.
template<typename T>
void put_id (T &id) const
 cast the refence to rendering api specific representation of component id to the specified type
Public Member Functions inherited from cgv::data::data_format
 data_format ()
 construct an undefined data format
 data_format (const std::string &description)
 construct from description string, see set_data_format for docu
bool set_data_format (const std::string &description)
 Set data format from description string, which adds information to the description string of the component format and has the following syntax.
 data_format (size_t _width, cgv::type::info::TypeId _component_type, const std::string &_component_name_list, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 1d data format from width and the information needed to construct a component info
 data_format (size_t _width, cgv::type::info::TypeId _component_type, ComponentFormat _cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 1d data format from width and the information needed to construct a component info
 data_format (size_t _width, size_t _height, cgv::type::info::TypeId _component_type, const std::string &_component_name_list, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 2d data format from width and height
 data_format (size_t _width, size_t _height, cgv::type::info::TypeId _component_type, ComponentFormat _cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 2d data format from width and height
 data_format (size_t _width, size_t _height, size_t _depth, cgv::type::info::TypeId _component_type, const std::string &_component_name_list, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 3d data format from width, height and depth
 data_format (size_t _width, size_t _height, size_t _depth, cgv::type::info::TypeId _component_type, ComponentFormat _cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 3d data format from width, height and depth
 data_format (size_t _width, size_t _height, size_t _depth, size_t _count, cgv::type::info::TypeId _component_type, const std::string &_component_name_list, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 4d data format from width, height, depth and count
 data_format (size_t _width, size_t _height, size_t _depth, size_t _count, cgv::type::info::TypeId _component_type, ComponentFormat _cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct a 4d data format from width, height, depth and count
void set_dimensions (size_t _d0, size_t _d1=-1, size_t _d2=-1, size_t _d3=-1)
 set the dimensions to the given values
unsigned get_nr_dimensions () const
 return the number of dimensions of the data set
void set_nr_dimensions (unsigned _d)
 set the number of dimensions of the data set
size_t get_resolution (unsigned i) const
 return the resolution in the i-th dimension, or 0 if not defined
size_t get_width () const
 return the resolution in the first dimension, or 1 if not defined
size_t get_height () const
 return the resolution in the second dimension, or 1 if not defined
size_t get_depth () const
 return the resolution in the third dimension, or 1 if not defined
size_t get_nr_time_steps () const
 return the resolution in the highest dimension, or 1 if not defined
size_t get_nr_entries () const
 return the total number of data entries
size_t get_nr_bytes () const
 return the total number of bytes necessary to store the data
void set_resolution (unsigned i, size_t resolution)
 set the resolution in the i-th dimension, add dimensions if necessary
void set_width (size_t _width)
 set the resolution in the first dimension, add dimensions if necessary
void set_height (size_t _height)
 set the resolution in the second dimension, add dimensions if necessary
void set_depth (size_t _depth)
 set the resolution in the third dimension, add dimensions if necessary
void set_nr_time_steps (size_t _nr_time_steps)
 set the resolution in the last dimension, add dimensions if necessary
unsigned get_entry_alignment () const
 return the alignment of entries
unsigned get_alignment (unsigned i) const
 return the alignment of a given dimension, where the alignment of the last dimension is always 1 and cannot be changed.
void set_entry_alignment (unsigned _a)
 set the alignment of entries
void set_alignment (unsigned i, unsigned _a)
 set the alignment of a given dimension, add dimensions if necessary.
unsigned get_layout_dimension (unsigned dim) const
 return the layout dimension of a given dimension
void set_layout_dimension (unsigned dim, unsigned layout_dim)
 set the layout dimension of a given dimension, add dimensions if necessary
const component_format & get_component_format () const
 return the component_format info by simple conversion of the this pointer
void set_component_format (const component_format &cf)
 set component_format by simply assigning to a converted this pointer
bool operator== (const data_format &df) const
 comparison between component formats
bool operator!= (const data_format &df) const
 comparison between component formats
Public Member Functions inherited from cgv::data::component_format
 component_format (const std::string &description)
 construct from description string, see set_component_format for docu
bool set_component_format (const std::string &description)
 set component format from description string, which has the following syntax.
void set_components (const std::string &_components)
 comma separated list of component descriptors, for example "R,G,B"
 component_format (cgv::type::info::TypeId _component_type=cgv::type::info::TypeId::TI_UNDEF, const std::string &_component_name_list="", unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct component format from component type, comma or colon separated list of component names, component alignment and bit depths for packed formats
 component_format (cgv::type::info::TypeId _component_type, ComponentFormat cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct component format from component type, standard component format, component alignment and bit depths for packed formats
void set_integer_interpretation (ComponentIntegerInterpretation cii)
 set the integer interpretation
ComponentIntegerInterpretation get_integer_interpretation () const
 return current integer interpretation
template<typename T>
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_info & get_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
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
void set_component_format (ComponentFormat _cf)
 set the component names from a standard component format
cgv::type::info::TypeId get_component_type () const
 return the component type
void set_component_type (cgv::type::info::TypeId _type_id)
 set the component type
unsigned int get_entry_size () const
 return the size of one entry of components in bytes
bool operator== (const component_format &cf) const
 comparison between component formats
bool operator!= (const component_format &cf) const
 comparison between component formats
Public Member Functions inherited from cgv::data::packing_info
 packing_info (unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct packing information from alignment and bit depths.
void clear ()
 clear packing info information
unsigned get_bit_depth (unsigned ci) const
 return the bit depth of the ci-th component
void set_bit_depth (unsigned ci, unsigned 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 a)
 set the component alignment in bits in the packed case and in bytes in the unpacked case
int get_signed (unsigned 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 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 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 ci, void *ptr, unsigned v) const
 set the ci-th component of the data entry pointed to by the given pointer of an unsigned packed component
bool operator== (const packing_info &pi) const
 equal comparison
bool operator!= (const packing_info &pi) const
 unequal comparison

Public Attributes

std::string last_error
 a string that contains the last error
Public Attributes inherited from cgv::render::texture_base
TextureFilter mag_filter
TextureFilter min_filter
TextureWrap wrap_s
TextureWrap wrap_t
TextureWrap wrap_r
float anisotropy
float priority
float border_color [4]
CompareFunction compare_function
bool use_compare_function
TextureType tt
bool have_mipmaps
unsigned nr_multi_samples = 5
bool fixed_sample_locations = true
Public Attributes inherited from cgv::render::render_component
void * handle
void * internal_format
void * user_data
const context * ctx_ptr
 keep pointer to my context
std::string last_error
 a string that contains the last error

Protected Member Functions

methods that can be called only with a context
bool complete_create (const context &ctx, bool created)
Protected Member Functions inherited from cgv::data::component_format
void extract_components ()
 extract components from component string
Protected Member Functions inherited from cgv::data::packing_info
bool prepare_bit_operation (unsigned ci, void *ptr, unsigned &off, unsigned &bd, unsigned *&iptr) const
bool prepare_bit_operation (unsigned ci, const void *ptr, unsigned &off, unsigned &bd, const unsigned *&iptr) const
unsigned int get_bit_offset (unsigned ci) const

Protected Attributes

bool state_out_of_date
int tex_unit
Protected Attributes inherited from cgv::data::data_format
std::vector< dimension_info > dimensions
 store for each dimension resolution and alignment in a dimension_info struct
Protected Attributes inherited from cgv::data::component_format
cgv::type::info::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
Protected Attributes inherited from cgv::data::packing_info
bool is_packed: 1
unsigned bd0: 6
unsigned bd1: 6
unsigned bd2: 6
unsigned bd3: 6
unsigned ca: 6

methods that can be called only with a context

void find_best_format (const context &ctx, const std::vector< cgv::data::data_view > *palettes=0)
 find the format that matches the one specified in the component format best
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 create_from_image (const context &ctx, const std::string &file_name="", int *image_width_ptr=0, int *image_height_ptr=0, unsigned char *clear_color_ptr=0, int level=-1, int cube_side=-1)
 create the texture from an image file.
bool create_from_image (cgv::data::data_format &df, cgv::data::data_view &dv, const context &ctx, const std::string &file_name="", unsigned char *clear_color_ptr=0, int level=-1, int cube_side=-1)
 same as previous method but use the passed data format and data view to store the content of the image.
bool create_from_images (const context &ctx, const std::string &file_names, int level=-1)
 Create a cube map from six files specified in the file_names parameter.
bool write_to_file (context &ctx, const std::string &file_name, unsigned int z_or_cube_side=-1, float depth_map_gamma=1.0f, const std::string &options="") const
 write the content of the texture to a file. This method needs support for frame buffer objects.
bool create_mipmaps (const context &ctx)
 create storage for mipmaps without computing the mipmap contents
bool generate_mipmaps (const context &ctx)
 generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU
bool create_from_buffer (const context &ctx, int x, int y, int width, int height, int level=-1)
 create texture from the currently set read buffer, where x, y, width and height define the to be used rectangle of the read buffer.
bool create (const context &ctx, const cgv::data::const_data_view &data, int level=-1, int cube_side=-1, int num_array_layers=0, const std::vector< cgv::data::data_view > *palettes=0)
 create texture from data view.
bool replace (const context &ctx, int x, const cgv::data::const_data_view &data, int level=-1, const std::vector< cgv::data::data_view > *palettes=0)
 replace a block within a 1d texture with the given data.
bool replace (const context &ctx, int x, int y, const cgv::data::const_data_view &data, int level=-1, const std::vector< cgv::data::data_view > *palettes=0)
 replace a block within a 2d texture with the given data.
bool replace (const context &ctx, int x, int y, int z_or_cube_side, const cgv::data::const_data_view &data, int level=-1, const std::vector< cgv::data::data_view > *palettes=0)
 replace a block within a 3d texture or a side of a cube map with the given data.
bool replace_from_buffer (const context &ctx, int x, int y, int x_buffer, int y_buffer, int width, int height, int level=-1)
 replace a block within a 2d texture from the current read buffer.
bool replace_from_buffer (const context &ctx, int x, int y, int z_or_cube_side, int x_buffer, int y_buffer, int width, int height, int level)
 replace a block within a 3d texture or a side from a cube map from the current read buffer.
bool replace_from_image (const context &ctx, const std::string &file_name, int x, int y, int z_or_cube_side, int level)
 replace within a slice of a volume or a side of a cube map from the given image
bool replace_from_image (cgv::data::data_format &df, cgv::data::data_view &dv, const context &ctx, const std::string &file_name, int x, int y, int z_or_cube_side, int level)
 same as previous method but use the passed data format and data view to store the content of the image.
bool copy (const context &ctx, cgv::data::data_view &dv, int level=-1) const
 read back a texture level to CPU memory storing the content in a data view whose data format will match the one stored in this texture.
bool destruct (const context &ctx)
 destruct the texture and free texture memory and handle
static bool deduce_file_names (const std::string &file_names, std::vector< std::string > &deduced_names)
 Helper function that determins the individual file names for a cubemap.

Additional Inherited Members

Static Public Member Functions inherited from cgv::data::component_format
static const std::string & get_last_error ()
 returns an error string after parsing of description string has failed
Static Public Member Functions inherited from cgv::data::packing_info
static size_t align (size_t v, unsigned a)
 return the next integer larger or equal to v which is dividable by a
Static Protected Attributes inherited from cgv::data::component_format
static std::string last_error
 store the last error that appeared during parsing of a description

Detailed Description

the texture class encapsulates all functionality independent of the rendering api.

Definition at line 14 of file texture.h.

Constructor & Destructor Documentation

◆ texture()

cgv::render::texture::texture ( const std::string & description = "uint8[R,G,B,A]",
TextureFilter _mag_filter = TF_LINEAR,
TextureFilter _min_filter = TF_LINEAR,
TextureWrap _wrap_s = TW_CLAMP_TO_EDGE,
TextureWrap _wrap_t = TW_CLAMP_TO_EDGE,
TextureWrap _wrap_r = TW_CLAMP_TO_EDGE )

construct from description string (which defaults to rgba format) and most commonly used texture parameters.

construct from description string and most commonly used texture parameters.

The description can define a component format as described in cgv::data::component_format::set_component_format() or a data format as described in cgv::data::data_format::set_data_format().

Definition at line 23 of file texture.cxx.

References cgv::data::data_format::data_format().

◆ ~texture()

cgv::render::texture::~texture ( )

destruct texture, the destructor can be called without context if the destruct method has been called or no creation has taken place

Definition at line 43 of file texture.cxx.

References cgv::render::render_component::ctx_ptr, and destruct().

Member Function Documentation

◆ bind_as_image()

bool cgv::render::texture::bind_as_image ( const context & ctx,
int tex_unit,
int level = 0,
bool bind_array = false,
int layer = 0,
AccessType access = AT_WRITE_ONLY )

Binds this texture as an image texture to the given texture unit.

Parameters
ctxThe graphics context.
tex_unitThe texture unit the texture is bound to.
levelThe mipmap level of the texture to bind.
bind_arrayOnly for array textures. If true, the complete texture array is bound and the layer ignored. If false, a single layer as specified by layer is bound.
layerOnly for array textures. The array layer to bind.
accessThe access type: read, write, read and write.
Returns
True if the texture was successfully bound as an image, false otherwise.

Definition at line 757 of file texture.cxx.

References ensure_state(), and cgv::render::render_component::last_error.

◆ complete_create()

bool cgv::render::texture::complete_create ( const context & ctx,
bool created )
protected

Definition at line 506 of file texture.cxx.

◆ copy()

bool cgv::render::texture::copy ( const context & ctx,
cgv::data::data_view & dv,
int level = -1 ) const

read back a texture level to CPU memory storing the content in a data view whose data format will match the one stored in this texture.

Definition at line 711 of file texture.cxx.

References cgv::render::render_component::is_created(), cgv::render::render_component::last_error, and cgv::data::data_view_base::manage_format().

◆ create() [1/2]

bool cgv::render::texture::create ( const context & ctx,
const cgv::data::const_data_view & data,
int level = -1,
int cube_side = -1,
int num_array_layers = 0,
const std::vector< cgv::data::data_view > * palettes = 0 )

create texture from data view.

Use dimension and resolution of data view but the component format of the texture. If level is not specified or set to -1 mipmaps are generated. If cube_side is specified, and data view is 2D, create one of the six sides of a cubemap. If num_array_layers is not zero a texture array is created. Set num_array_layers to -1 to automatically choose the layer number based on the data view dimensions and size, e.g. a 2D/3D data view creates a 1D/2D array with layer count equal to height/depth. Set num_array_layers to > 0 to manually specify the layer count. This can be used to create a one layer 1D/2D texture array from a 1D/2D data view. Cubemap arrays are currently not suported.

Definition at line 549 of file texture.cxx.

References cgv::data::component_format::component_format(), cgv::data::data_format::data_format(), destruct(), find_best_format(), cgv::data::component_format::get_nr_components(), cgv::data::data_format::get_nr_dimensions(), cgv::data::data_format::get_resolution(), cgv::render::render_component::is_created(), replace(), cgv::data::data_format::set_nr_dimensions(), and cgv::data::data_format::set_resolution().

◆ create() [2/2]

bool cgv::render::texture::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.

create the texture of dimension and resolution specified in the data format base class

If no type is given, determine it from the format. If dimensions are given, they overwrite the dimensions in the texture format.

Definition at line 214 of file texture.cxx.

References destruct(), find_best_format(), cgv::render::render_component::is_created(), cgv::data::data_format::set_depth(), cgv::data::data_format::set_height(), and cgv::data::data_format::set_width().

Referenced by cgv::render::build_render_info(), cgv::render::gl::gl_transparent_renderer::create_and_attach_texture(), and create_from_image().

◆ create_from_buffer()

bool cgv::render::texture::create_from_buffer ( const context & ctx,
int x,
int y,
int width,
int height,
int level = -1 )

create texture from the currently set read buffer, where x, y, width and height define the to be used rectangle of the read buffer.

The dimension and resolution of the texture format are updated automatically. If level is not specified or set to -1 mipmaps are generated.

Definition at line 521 of file texture.cxx.

References destruct(), find_best_format(), cgv::render::render_component::is_created(), replace_from_buffer(), cgv::data::data_format::set_height(), cgv::data::data_format::set_nr_dimensions(), and cgv::data::data_format::set_width().

◆ create_from_image() [1/2]

bool cgv::render::texture::create_from_image ( cgv::data::data_format & df,
cgv::data::data_view & dv,
const context & ctx,
const std::string & file_name = "",
unsigned char * clear_color_ptr = 0,
int level = -1,
int cube_side = -1 )

◆ create_from_image() [2/2]

bool cgv::render::texture::create_from_image ( const context & ctx,
const std::string & file_name = "",
int * image_width_ptr = 0,
int * image_height_ptr = 0,
unsigned char * clear_color_ptr = 0,
int level = -1,
int cube_side = -1 )

create the texture from an image file.

create the texture from an image file

If the file_name is not given ask the user interactively for a file name. The image dimensions are written to the optionally passed pointers image_width_ptr and image_height_ptr. In order to support mipmapping, the width and height of the texture must be powers of two. If the clear_color_ptr is given, the texture is automatically extended in size to powers of two. clear_color_ptr points to four bytes that specify a RGBA color used to fill texels that are inserted to ensure dimensions of powers of two. For creation of a side of a cubemap specify the cube_side parameter.

Definition at line 313 of file texture.cxx.

References create_from_image(), cgv::data::data_format::data_format(), cgv::data::data_format::get_height(), and cgv::data::data_format::get_width().

Referenced by create_from_image(), create_from_images(), and cgv::render::textured_material::ensure_textures().

◆ create_from_images()

bool cgv::render::texture::create_from_images ( const context & ctx,
const std::string & file_names,
int level = -1 )

Create a cube map from six files specified in the file_names parameter.

The file_names parameter can specify different file names by the use of the wildchar symbol '' or by curly brackets. When using '' the files are loaded in alphanumerical order. The image files defining the cubemap sides must be in the order positive x, negative x, positive y, negative y, positive z and negative z. Some examples of specifying file names:

  • "cm_{xp,xn,yp,yn,zp,zn}.png" defines the file names "cm_xp.png", "cm_xn.png", "cm_yp.png", "cm_yn.png", "cm_zp.png" and "cm_zn.png"
  • "cm_*.png" issues a glob command resulting in an alphanumerically ordered file name list. Be aware that the naming of the previous example would result in a wrong ordering of the file names. Mixing of '*' and "{,}" syntax is not allowed. The static method deduce_file_names is used to deduce the individual file names from the file_names parameter and can be used also when the correct path to the cubemap files needs to be found.

Different levels of the mipmap pyramid can be created in separate calls. If the level parameter is not specified or -1, the images are load to level 0 and a mipmap pyramid is built automatically. This method has no support for rescaling to power of two dimensions. If a mipmap is used, the image files should already have power of two dimensions.

Definition at line 393 of file texture.cxx.

References create_from_image(), deduce_file_names(), and destruct().

◆ create_mipmaps()

bool cgv::render::texture::create_mipmaps ( const context & ctx)

create storage for mipmaps without computing the mipmap contents

Definition at line 490 of file texture.cxx.

References cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

◆ deduce_file_names()

bool cgv::render::texture::deduce_file_names ( const std::string & file_names,
std::vector< std::string > & deduced_names )
static

Helper function that determins the individual file names for a cubemap.

Returns whether the file_names specification was correct. See comment to create_from_images for the syntax of the file_names parameter.

Definition at line 328 of file texture.cxx.

References cgv::utils::tokenizer::set_sep(), cgv::utils::tokenizer::set_ws(), and cgv::render::to_string().

Referenced by create_from_images().

◆ destruct()

bool cgv::render::texture::destruct ( const context & ctx)

destruct the texture and free texture memory and handle

Definition at line 726 of file texture.cxx.

Referenced by create(), create(), cgv::render::gl::gl_transparent_renderer::create_and_attach_texture(), create_from_buffer(), create_from_image(), create_from_images(), and ~texture().

◆ disable()

bool cgv::render::texture::disable ( const context & ctx)

disable texture and restore state from before last enable call

disable texture and restore state before last enable call

Definition at line 752 of file texture.cxx.

References cgv::data::data_format::get_nr_dimensions().

Referenced by cgv::render::gl::gl_transparent_renderer::blend_texture_over_viewport().

◆ enable()

bool cgv::render::texture::enable ( const context & ctx,
int tex_unit = -1 )

enable this texture in the given texture unit, -1 corresponds to the current unit.

Definition at line 741 of file texture.cxx.

References ensure_state(), cgv::data::data_format::get_nr_dimensions(), and cgv::render::render_component::last_error.

Referenced by cgv::render::gl::gl_transparent_renderer::blend_texture_over_viewport().

◆ ensure_state()

void cgv::render::texture::ensure_state ( const context & ctx) const

ensure the the texture state is synchronized with the GPU settings

Definition at line 204 of file texture.cxx.

Referenced by cgv::render::frame_buffer::attach(), cgv::render::frame_buffer::attach(), bind_as_image(), and enable().

◆ find_best_format()

void cgv::render::texture::find_best_format ( const context & ctx,
const std::vector< cgv::data::data_view > * palettes = 0 )

find the format that matches the one specified in the component format best

Definition at line 196 of file texture.cxx.

References set_component_format().

Referenced by create(), create(), and create_from_buffer().

◆ generate_mipmaps()

bool cgv::render::texture::generate_mipmaps ( const context & ctx)

generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU

Definition at line 501 of file texture.cxx.

References cgv::data::data_format::get_nr_dimensions().

◆ get_anisotropy()

float cgv::render::texture::get_anisotropy ( ) const

return the currently set anisotropy

Definition at line 139 of file texture.cxx.

◆ get_border_color()

cgv::vec4 cgv::render::texture::get_border_color ( ) const

return the texture border color

Definition at line 120 of file texture.cxx.

◆ get_compare_function()

CompareFunction cgv::render::texture::get_compare_function ( ) const

get the texture compare function

Definition at line 185 of file texture.cxx.

◆ get_compare_mode()

bool cgv::render::texture::get_compare_mode ( ) const

get the texture compare mode and function

Definition at line 172 of file texture.cxx.

◆ get_mag_filter()

TextureFilter cgv::render::texture::get_mag_filter ( ) const

return the magnification filter

Definition at line 150 of file texture.cxx.

◆ get_min_filter()

TextureFilter cgv::render::texture::get_min_filter ( ) const

return the minification filter

Definition at line 134 of file texture.cxx.

◆ get_nr_multi_samples()

unsigned cgv::render::texture::get_nr_multi_samples ( ) const
inline

return number of multi samples for textures of type TT_MULTISAMPLE_2D and TT_MULTISAMPLE_2D_ARRAY

Definition at line 91 of file texture.h.

◆ get_priority()

float cgv::render::texture::get_priority ( ) const

return the priority with which texture is kept in GPU memory

Definition at line 161 of file texture.cxx.

◆ get_tex_unit()

int cgv::render::texture::get_tex_unit ( ) const

return the currently used texture unit and -1 for current

Definition at line 781 of file texture.cxx.

◆ get_wrap_r()

TextureWrap cgv::render::texture::get_wrap_r ( ) const

return the texture wrap behaviour in r direction

Definition at line 106 of file texture.cxx.

◆ get_wrap_s()

TextureWrap cgv::render::texture::get_wrap_s ( ) const

return the texture wrap behaviour in s direction

Definition at line 96 of file texture.cxx.

◆ get_wrap_t()

TextureWrap cgv::render::texture::get_wrap_t ( ) const

return the texture wrap behaviour in t direction

Definition at line 101 of file texture.cxx.

◆ is_enabled()

bool cgv::render::texture::is_enabled ( ) const

check whether textue is enabled

Definition at line 776 of file texture.cxx.

◆ mipmaps_created()

bool cgv::render::texture::mipmaps_created ( ) const

check whether mipmaps have been created

Definition at line 771 of file texture.cxx.

◆ replace() [1/3]

bool cgv::render::texture::replace ( const context & ctx,
int x,
const cgv::data::const_data_view & data,
int level = -1,
const std::vector< cgv::data::data_view > * palettes = 0 )

replace a block within a 1d texture with the given data.

If level is not specified, level 0 is set and if a mipmap has been created before, coarser levels are updated also.

Definition at line 604 of file texture.cxx.

References cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

Referenced by create(), and replace_from_image().

◆ replace() [2/3]

bool cgv::render::texture::replace ( const context & ctx,
int x,
int y,
const cgv::data::const_data_view & data,
int level = -1,
const std::vector< cgv::data::data_view > * palettes = 0 )

replace a block within a 2d texture with the given data.

If level is not specified, level 0 is set and if a mipmap has been created before, coarser levels are updated also.

Definition at line 620 of file texture.cxx.

References cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

◆ replace() [3/3]

bool cgv::render::texture::replace ( const context & ctx,
int x,
int y,
int z_or_cube_side,
const cgv::data::const_data_view & data,
int level = -1,
const std::vector< cgv::data::data_view > * palettes = 0 )

replace a block within a 3d texture or a side of a cube map with the given data.

If level is not specified, level 0 is set and if a mipmap has been created before, coarser levels are updated also.

Definition at line 637 of file texture.cxx.

References cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

◆ replace_from_buffer() [1/2]

bool cgv::render::texture::replace_from_buffer ( const context & ctx,
int x,
int y,
int x_buffer,
int y_buffer,
int width,
int height,
int level = -1 )

replace a block within a 2d texture from the current read buffer.

Definition at line 650 of file texture.cxx.

References cgv::data::data_format::get_nr_dimensions(), cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

Referenced by create_from_buffer().

◆ replace_from_buffer() [2/2]

bool cgv::render::texture::replace_from_buffer ( const context & ctx,
int x,
int y,
int z_or_cube_side,
int x_buffer,
int y_buffer,
int width,
int height,
int level )

replace a block within a 3d texture or a side from a cube map from the current read buffer.

replace a block within a 2d texture from the current read buffer.

Definition at line 665 of file texture.cxx.

References cgv::render::render_component::is_created(), and cgv::render::render_component::last_error.

◆ replace_from_image() [1/2]

bool cgv::render::texture::replace_from_image ( cgv::data::data_format & df,
cgv::data::data_view & dv,
const context & ctx,
const std::string & file_name,
int x,
int y,
int z_or_cube_side,
int level )

same as previous method but use the passed data format and data view to store the content of the image.

Definition at line 689 of file texture.cxx.

References cgv::media::image::image_reader::read_image(), cgv::media::image::image_reader::read_palette(), and replace().

◆ replace_from_image() [2/2]

bool cgv::render::texture::replace_from_image ( const context & ctx,
const std::string & file_name,
int x,
int y,
int z_or_cube_side,
int level )

replace within a slice of a volume or a side of a cube map from the given image

Definition at line 680 of file texture.cxx.

References cgv::data::data_format::data_format(), and replace_from_image().

Referenced by replace_from_image().

◆ set_border_color() [1/2]

void cgv::render::texture::set_border_color ( const float * rgba)
inline

set the border color

Definition at line 58 of file texture.h.

References set_border_color().

Referenced by set_border_color().

◆ set_border_color() [2/2]

void cgv::render::texture::set_border_color ( float r,
float g,
float b,
float a = 1.0f )

set the border color

Definition at line 111 of file texture.cxx.

◆ set_compare_function()

void cgv::render::texture::set_compare_function ( CompareFunction compare_function)

set the texture compare function

Definition at line 178 of file texture.cxx.

◆ set_compare_mode()

void cgv::render::texture::set_compare_mode ( bool use_compare_function)

set the texture compare mode and function

Definition at line 166 of file texture.cxx.

◆ set_component_format() [1/2]

void cgv::render::texture::set_component_format ( const component_format & cf)

change component format and clear internal format

Definition at line 62 of file texture.cxx.

References cgv::data::component_format::component_format(), and cgv::data::data_format::set_component_format().

Referenced by find_best_format(), and cgv::render::gl::set_gl_format().

◆ set_component_format() [2/2]

void cgv::render::texture::set_component_format ( const std::string & description)

change component format and clear internal format

Definition at line 70 of file texture.cxx.

References cgv::data::component_format::set_component_format().

◆ set_data_format()

bool cgv::render::texture::set_data_format ( const std::string & description)

change the data format and clear internal format

Definition at line 53 of file texture.cxx.

References cgv::data::data_format::set_data_format().

◆ set_fixed_sample_locations()

void cgv::render::texture::set_fixed_sample_locations ( bool use)

set whether multi sampling uses fixed sample locations

Definition at line 236 of file texture.cxx.

◆ set_mag_filter()

void cgv::render::texture::set_mag_filter ( TextureFilter _mag_filter)

set the magnification filter

Definition at line 144 of file texture.cxx.

Referenced by cgv::render::build_render_info().

◆ set_min_filter()

void cgv::render::texture::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 parameter specifies the degree of anisotropy

Definition at line 126 of file texture.cxx.

Referenced by cgv::render::build_render_info().

◆ set_nr_multi_samples()

void cgv::render::texture::set_nr_multi_samples ( unsigned _nr_samples)

set the number of multi samples for textures of type TT_MULTISAMPLE_2D and TT_MULTISAMPLE_2D_ARRAY

Definition at line 231 of file texture.cxx.

◆ set_priority()

void cgv::render::texture::set_priority ( float _priority)

set priority with which texture is kept in GPU memory

Definition at line 155 of file texture.cxx.

◆ set_wrap_r()

void cgv::render::texture::set_wrap_r ( TextureWrap _wrap_r)

set the texture wrap behaviour in r direction

Definition at line 90 of file texture.cxx.

◆ set_wrap_s()

void cgv::render::texture::set_wrap_s ( TextureWrap _wrap_s)

set the texture wrap behaviour in s direction

Definition at line 78 of file texture.cxx.

Referenced by cgv::render::build_render_info(), and cgv::render::textured_material::ensure_textures().

◆ set_wrap_t()

void cgv::render::texture::set_wrap_t ( TextureWrap _wrap_t)

set the texture wrap behaviour in t direction

Definition at line 84 of file texture.cxx.

Referenced by cgv::render::build_render_info(), and cgv::render::textured_material::ensure_textures().

◆ use_fixed_sample_locations()

bool cgv::render::texture::use_fixed_sample_locations ( ) const
inline

whether multi sampling uses fixed sample locations

Definition at line 93 of file texture.h.

◆ write_to_file()

Member Data Documentation

◆ last_error

a string that contains the last error

Definition at line 365 of file context.h.

Referenced by write_to_file().

◆ state_out_of_date

bool cgv::render::texture::state_out_of_date
mutableprotected

Definition at line 17 of file texture.h.

◆ tex_unit

int cgv::render::texture::tex_unit
protected

Definition at line 18 of file texture.h.


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