cgv
texture.h
1 #pragma once
2 
3 #include <cgv/data/data_format.h>
4 #include <cgv/data/data_view.h>
5 #include <cgv/render/context.h>
6 
7 #include "lib_begin.h"
8 
9 namespace cgv {
10  namespace render {
11 
14 class CGV_API texture : public texture_base, public cgv::data::data_format
15 {
16 protected:
17  mutable bool state_out_of_date;
18  int tex_unit;
19  bool complete_create(const context& ctx, bool created);
20 public:
22 
29  texture(const std::string& description = "uint8[R,G,B,A]",
30  TextureFilter _mag_filter = TF_LINEAR,
31  TextureFilter _min_filter = TF_LINEAR,
32  TextureWrap _wrap_s = TW_CLAMP_TO_EDGE,
33  TextureWrap _wrap_t = TW_CLAMP_TO_EDGE,
34  TextureWrap _wrap_r = TW_CLAMP_TO_EDGE);
38  ~texture();
40  bool set_data_format(const std::string& description);
42  void set_component_format(const component_format& cf);
44  void set_component_format(const std::string& description);
46  void set_wrap_s(TextureWrap _wrap_s);
48  void set_wrap_t(TextureWrap _wrap_t);
50  void set_wrap_r(TextureWrap _wrap_r);
52  TextureWrap get_wrap_s() const;
54  TextureWrap get_wrap_t() const;
56  TextureWrap get_wrap_r() const;
58  void set_border_color(const float* rgba) { set_border_color(rgba[0],rgba[1],rgba[2],rgba[3]); }
60  void set_border_color(float r, float g, float b, float a = 1.0f);
63  void set_min_filter(TextureFilter _min_filter, float _anisotropy = 2.0f);
65  TextureFilter get_min_filter() const;
67  float get_anisotropy() const;
69  void set_mag_filter(TextureFilter _mag_filter);
71  TextureFilter get_mag_filter() const;
73  void set_priority(float _priority);
75  float get_priority() const;
77  void set_compare_mode(bool use_compare_function);
79  bool get_compare_mode() const;
81  void set_compare_function(CompareFunction compare_function);
83  CompareFunction get_compare_function() const;
85  bool mipmaps_created() const;
87  void ensure_state(const context& ctx) const;
89  bool is_enabled() const;
91  int get_tex_unit() const;
93 
96  void find_best_format(const context& ctx, const std::vector<cgv::data::data_view>* palettes = 0);
102  bool create(const context& ctx, TextureType _tt = TT_UNDEF, unsigned width=-1, unsigned height=-1, unsigned depth=-1);
112  bool create_from_image(const context& ctx, const std::string& file_name = "",
113  int* image_width_ptr = 0, int* image_height_ptr = 0,
114  unsigned char* clear_color_ptr = 0, int level = -1, int cube_side = -1);
118  bool create_from_image(cgv::data::data_format& df, cgv::data::data_view& dv, const context& ctx, const std::string& file_name = "",
119  unsigned char* clear_color_ptr = 0, int level = -1, int cube_side = -1);
121 
123  static bool deduce_file_names(const std::string& file_names, std::vector<std::string>& deduced_names);
125 
142  bool create_from_images(const context& ctx, const std::string& file_names, int level = -1);
144  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;
147  bool generate_mipmaps(const context& ctx);
153  bool create_from_buffer(const context& ctx, int x, int y, int width, int height, int level = -1);
166  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);
170  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);
174  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);
179  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);
181  bool replace_from_buffer(const context& ctx, int x, int y, int x_buffer,
182  int y_buffer, int width, int height, int level = -1);
184  bool replace_from_buffer(const context& ctx, int x, int y, int z_or_cube_side, int x_buffer,
185  int y_buffer, int width, int height, int level);
187  bool replace_from_image(const context& ctx, const std::string& file_name, int x, int y, int z_or_cube_side, int level);
190  bool replace_from_image(cgv::data::data_format& df, cgv::data::data_view& dv, const context& ctx,
191  const std::string& file_name, int x, int y, int z_or_cube_side, int level);
193  bool destruct(const context& ctx);
195 
200  bool enable(const context& ctx, int tex_unit = -1);
202  bool disable(const context& ctx);
204 };
205 
206  }
207 }
208 
209 #include <cgv/config/lib_end.h>
cgv::render::render_component::last_error
std::string last_error
a string that contains the last error
Definition: context.h:254
cgv::data::const_data_view
Definition: data_view.h:211
cgv::render::texture_base
base interface for a texture
Definition: context.h:269
cgv::render::texture
Definition: texture.h:15
cgv::render::CompareFunction
CompareFunction
different sampling strategies for rendering to textures that steer the computation of the tex_coord i...
Definition: context.h:206
cgv::render::TextureFilter
TextureFilter
different texture filter
Definition: context.h:143
cgv::data::data_view
Definition: data_view.h:155
cgv::render::texture::set_border_color
void set_border_color(const float *rgba)
set the border color
Definition: texture.h:58
cgv::data::data_format
Definition: data_format.h:18
cgv::render::TextureWrap
TextureWrap
different texture wrap modes
Definition: context.h:127
cgv::render::TextureType
TextureType
different texture types
Definition: context.h:155
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::render::context
Definition: context.h:525