cgv
Loading...
Searching...
No Matches
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
9namespace cgv {
10 namespace render {
11
14class CGV_API texture : public texture_base, public cgv::data::data_format
15{
16protected:
17 mutable bool state_out_of_date;
18 int tex_unit;
19 bool complete_create(const context& ctx, bool created);
20public:
21 using render_component::last_error;
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 set_nr_multi_samples(unsigned _nr_samples);
89 unsigned get_nr_multi_samples() const { return nr_multi_samples; }
91 bool use_fixed_sample_locations() const { return fixed_sample_locations; }
93 void set_fixed_sample_locations(bool use);
95 void ensure_state(const context& ctx) const;
97 bool is_enabled() const;
99 int get_tex_unit() const;
101
105 void find_best_format(const context& ctx, const std::vector<cgv::data::data_view>* palettes = 0);
110 bool create(const context& ctx, TextureType _tt = TT_UNDEF, unsigned width=-1, unsigned height=-1, unsigned depth=-1);
120 bool create_from_image(const context& ctx, const std::string& file_name = "",
121 int* image_width_ptr = 0, int* image_height_ptr = 0,
122 unsigned char* clear_color_ptr = 0, int level = -1, int cube_side = -1);
126 bool create_from_image(cgv::data::data_format& df, cgv::data::data_view& dv, const context& ctx, const std::string& file_name = "",
127 unsigned char* clear_color_ptr = 0, int level = -1, int cube_side = -1);
129
131 static bool deduce_file_names(const std::string& file_names, std::vector<std::string>& deduced_names);
133
150 bool create_from_images(const context& ctx, const std::string& file_names, int level = -1);
152 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;
154 bool create_mipmaps(const context& ctx);
157 bool generate_mipmaps(const context& ctx);
163 bool create_from_buffer(const context& ctx, int x, int y, int width, int height, int level = -1);
176 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);
180 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);
184 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);
189 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);
191 bool replace_from_buffer(const context& ctx, int x, int y, int x_buffer,
192 int y_buffer, int width, int height, int level = -1);
194 bool replace_from_buffer(const context& ctx, int x, int y, int z_or_cube_side, int x_buffer,
195 int y_buffer, int width, int height, int level);
197 bool replace_from_image(const context& ctx, const std::string& file_name, int x, int y, int z_or_cube_side, int level);
200 bool replace_from_image(cgv::data::data_format& df, cgv::data::data_view& dv, const context& ctx,
201 const std::string& file_name, int x, int y, int z_or_cube_side, int level);
203 bool destruct(const context& ctx);
205
210 bool enable(const context& ctx, int tex_unit = -1);
212 bool disable(const context& ctx);
213
222 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);
224};
225
226 }
227}
228
229#include <cgv/config/lib_end.h>
The const_data_view has the functionality of the data_view but uses a const pointer and therefore doe...
Definition data_view.h:221
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
the data view gives access to a data array of one, two, three or four dimensions.
Definition data_view.h:153
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
base interface for a texture
Definition context.h:332
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
bool use_fixed_sample_locations() const
whether multi sampling uses fixed sample locations
Definition texture.h:91
void set_border_color(const float *rgba)
set the border color
Definition texture.h:58
unsigned get_nr_multi_samples() const
return number of multi samples for textures of type TT_MULTISAMPLE_2D and TT_MULTISAMPLE_2D_ARRAY
Definition texture.h:89
AccessType
different access types
Definition context.h:266
TextureFilter
different texture filter
Definition context.h:189
TextureWrap
different texture wrap modes
Definition context.h:173
TextureType
different texture types
Definition context.h:201
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:254
the cgv namespace
Definition print.h:11