cgv
Loading...
Searching...
No Matches
texture.cxx
1#include "texture.h"
2#include "frame_buffer.h"
3
4#include <cgv/math/integer.h>
5#include <cgv/media/image/image_reader.h>
6#include <cgv/media/image/image_writer.h>
7#include <cgv/utils/tokenizer.h>
8#include <cgv/utils/file.h>
9#include <cgv/utils/statistics.h>
10
11using namespace cgv::data;
12using namespace cgv::media::image;
13using namespace cgv::utils;
14using namespace cgv::utils::file;
15
16namespace cgv {
17 namespace render {
18
23texture::texture(const std::string& description,
24 TextureFilter _mag_filter,
25 TextureFilter _min_filter,
26 TextureWrap _wrap_s,
27 TextureWrap _wrap_t,
28 TextureWrap _wrap_r) : data::data_format(description)
29{
30 mag_filter = _mag_filter;
31 min_filter = _min_filter;
32 wrap_s = _wrap_s;
33 wrap_t = _wrap_t;
34 wrap_r = _wrap_r;
35 state_out_of_date = true;
36 have_mipmaps = false;
37 tex_unit = -1;
38}
39
44{
47
48 if(handle != 0)
49 std::cerr << "could not destruct texture properly" << std::endl;
50}
51
53bool texture::set_data_format(const std::string& description)
54{
55 bool res = data_format::set_data_format(description);
56 internal_format = 0;
57 state_out_of_date = true;
58 return res;
59}
60
63{
65 internal_format = 0;
66 state_out_of_date = true;
67}
68
70void texture::set_component_format(const std::string& description)
71{
73 internal_format = 0;
74 state_out_of_date = true;
75}
76
79{
80 wrap_s = _wrap_s;
81 state_out_of_date = true;
82}
85{
86 wrap_t = _wrap_t;
87 state_out_of_date = true;
88}
91{
92 wrap_r = _wrap_r;
93 state_out_of_date = true;
94}
97{
98 return wrap_s;
99}
102{
103 return wrap_t;
104}
107{
108 return wrap_r;
109}
111void texture::set_border_color(float r, float g, float b, float a)
112{
113 border_color[0] = r;
114 border_color[1] = g;
115 border_color[2] = b;
116 border_color[3] = a;
117 state_out_of_date = true;
118}
121{
122 return cgv::vec4(4, border_color);
123}
126void texture::set_min_filter(TextureFilter _min_filter, float _anisotropy)
127{
128 min_filter = _min_filter;
129 anisotropy = _anisotropy;
130 state_out_of_date = true;
131}
132
135{
136 return min_filter;
137}
140{
141 return anisotropy;
142}
145{
146 mag_filter = _mag_filter;
147 state_out_of_date = true;
148}
151{
152 return mag_filter;
153}
155void texture::set_priority(float _priority)
156{
157 priority = _priority;
158 state_out_of_date = true;
159}
162{
163 return priority;
164}
166void texture::set_compare_mode(bool _use_compare_function)
167{
168 use_compare_function = _use_compare_function;
169 state_out_of_date = true;
170}
173{
174 return use_compare_function;
175}
176
179{
180 compare_function = _compare_function;
181 state_out_of_date = true;
182}
183
186{
187 return compare_function;
188}
189
190
192
196void texture::find_best_format(const context& ctx, const std::vector<data_view>* palettes)
197{
198 cgv::data::component_format cf = ctx.texture_find_best_format(*this, *this, palettes);
199 void* tmp = internal_format;
201 internal_format = tmp;
202}
203
204void texture::ensure_state(const context& ctx) const
205{
206 if (state_out_of_date) {
207 ctx.texture_set_state(*this);
208 state_out_of_date = false;
209 }
210}
211
214bool texture::create(const context& ctx, TextureType _tt, unsigned width, unsigned height, unsigned depth)
215{
216 if (is_created())
217 destruct(ctx);
218 if (_tt != TT_UNDEF)
219 tt = _tt;
220 if (width != -1)
221 set_width(width);
222 if (height != -1)
223 set_height(height);
224 if (depth != -1)
225 set_depth(depth);
226 if (!internal_format)
227 find_best_format(ctx);
228 return complete_create(ctx, ctx.texture_create(*this, *this));
229}
230
231void texture::set_nr_multi_samples(unsigned _nr_samples)
232{
233 nr_multi_samples = _nr_samples;
234}
235
237{
238 fixed_sample_locations = use;
239}
240
242 const std::string& file_name, unsigned char* clear_color_ptr, int level, int cube_side)
243{
244 bool ensure_power_of_two = clear_color_ptr != 0;
245 std::string fn = file_name;
246 if (df.empty()) {
247 if (fn.empty()) {
248 cgv::render::render_component::last_error = "attempt to create texture from empty file name";
249 return false;
250 }
251 }
252 std::vector<data_format> palette_formats;
253 std::vector<data_view> palettes;
254 if (!fn.empty()) {
255 image_reader ir(df, &palette_formats);
256 if (!ir.read_image(fn, dv)) {
257 cgv::render::render_component::last_error = "error reading image file ";
261 return false;
262 }
263 for (unsigned i=0; i<palette_formats.size(); ++i) {
264 palettes.push_back(data_view());
265 if (!ir.read_palette(i, palettes.back())) {
266 cgv::render::render_component::last_error = "error reading palette";
267 return false;
268 }
269 }
270 }
271 if (cube_side < 1)
272 destruct(ctx);
273 size_t w = df.get_width(), h = df.get_height();
274 size_t W = w, H = h;
275 data_format df1(df);
276 if (ensure_power_of_two && (!cgv::math::is_power_of_two(w) || !cgv::math::is_power_of_two(h))) {
277 W = cgv::math::next_power_of_two(df.get_width());
278 H = cgv::math::next_power_of_two(df.get_height());
279 df1.set_width(W);
280 df1.set_height(H);
281 }
282 //float ext[2] = { (float)w/W, (float)h/H };
283 data_view dv1(&df1);
284 unsigned entry_size = df.get_entry_size();
285 const unsigned char* src_ptr = dv.get_ptr<unsigned char>();
286 unsigned char* dest_ptr = dv1.get_ptr<unsigned char>();
287 unsigned char* dest_ptr_end = dest_ptr + entry_size * W*H;
288 for (unsigned y = 0; y < h; ++y) {
289 dest_ptr_end -= W * entry_size;
290 memcpy(dest_ptr_end, src_ptr, w*entry_size);
291 if (clear_color_ptr) {
292 for (size_t x = w; x < W; ++x)
293 memcpy(dest_ptr_end + x * entry_size, clear_color_ptr, entry_size);
294 }
295 else
296 std::fill(dest_ptr_end + w * entry_size, dest_ptr_end + W*entry_size, 0);
297 src_ptr += w * entry_size;
298 }
299 if (H > h) {
300 size_t N = (H - h)*W;
301 if (clear_color_ptr) {
302 for (size_t i = 0; i < N; ++i)
303 memcpy(dest_ptr + i * entry_size, clear_color_ptr, entry_size);
304 }
305 else
306 std::fill(dest_ptr, dest_ptr + N*entry_size, 0);
307 }
308 return create(ctx, dv1, level, cube_side, false, &palettes);
309}
310
311
314 const std::string& file_name, int* image_width_ptr, int* image_height_ptr,
315 unsigned char* clear_color_ptr, int level, int cube_side)
316{
317 data_format df;
318 data_view dv;
319 if (!create_from_image(df,dv,ctx,file_name,clear_color_ptr,level,cube_side))
320 return false;
321 if (image_width_ptr)
322 *image_width_ptr = int(df.get_width());
323 if (image_height_ptr)
324 *image_height_ptr = int(df.get_height());
325 return true;
326}
327
328bool texture::deduce_file_names(const std::string& file_names, std::vector<std::string>& deduced_names)
329{
330 if (std::find(file_names.begin(), file_names.end(), '{') != file_names.end()) {
331 std::vector<token> toks;
332 deduced_names.resize(6);
333 tokenizer(file_names).set_ws("").set_sep("{,}").bite_all(toks);
334 int selection = -1;
335 for (unsigned i=0; i<toks.size(); ++i) {
336 if (toks[i] == "{") {
337 if (selection != -1) {
338 std::cerr << "warning: nested {} not allowed in cubemap file names specification " << file_names << std::endl;
339 return false;
340 }
341 selection = 0;
342 }
343 else if (toks[i] == "}") {
344 if (selection == -1) {
345 std::cerr << "warning: } without opening { in cubemap file names specification " << file_names << std::endl;
346 return false;
347 }
348 if (selection != 5) {
349 std::cerr << "warning: no 6 file names specified for creating cubemap from images " << file_names << std::endl;
350 return false;
351 }
352 selection = -1;
353 }
354 else if (toks[i] == ",") {
355 if (selection == -1) {
356 std::cerr << "warning: , arising outside {} in cubemap file names specification " << file_names << std::endl;
357 return false;
358 }
359 ++selection;
360 }
361 else {
362 if (selection == -1) {
363 for (unsigned j=0; j<6; ++j)
364 deduced_names[j] += to_string(toks[i]);
365 }
366 else {
367 if (selection == 6) {
368 std::cerr << "warning: more than 6 files names specified for cubemap creation " << file_names << std::endl;
369 return false;
370 }
371 deduced_names[selection] += to_string(toks[i]);
372 }
373 }
374 }
375 }
376 else {
377 std::string path_prefix = get_path(file_names);
378 if (!path_prefix.empty())
379 path_prefix += '/';
380 void* handle = find_first(file_names);
381 while (handle != 0) {
382 deduced_names.push_back(path_prefix+find_name(handle));
383 handle = find_next(handle);
384 }
385 if (deduced_names.size() != 6) {
386 std::cerr << "warning: not exactly 6 files names specified for cubemap creation " << file_names << std::endl;
387 return false;
388 }
389 }
390 return true;
391}
392
393bool texture::create_from_images(const context& ctx, const std::string& file_names, int level)
394{
395 std::vector<std::string> deduced_names;
396 if (!deduce_file_names(file_names, deduced_names))
397 return false;
398 bool success = true;
399 for (unsigned i=0; success && i<6; ++i)
400 if (!create_from_image(ctx, deduced_names[i],0,0,0,level,i)) {
401 success = false;
402 std::cerr << "could not create cubemap side " << i << " from image " << deduced_names[i] << std::endl;
403 }
404 if (!success)
405 destruct(ctx);
406 return success;
407}
408
410bool texture::write_to_file(context& ctx, const std::string& file_name, unsigned int z_or_cube_size, float depth_map_gamma, const std::string& options) const
411{
412 std::string& last_error = static_cast<const cgv::render::texture_base*>(this)->last_error;
413 if (!is_created()) {
414 last_error = "texture must be created for write_to_file";
415 return false;
416 }
417 frame_buffer fb;
418 if (!fb.create(ctx,int(get_width()), int(get_height()))) {
419 last_error = "could not create frame buffer object for write_to_file";
420 return false;
421 }
422 if (z_or_cube_size != -1) {
423 if (!fb.attach(ctx,*this,z_or_cube_size,0,0)) {
424 last_error = "could not attach texture for write_to_file";
425 return false;
426 }
427 }
428 else {
429 if (!fb.attach(ctx,*this)) {
430 last_error = "could not attach texture for write_to_file";
431 return false;
432 }
433 }
434 bool is_depth = get_standard_component_format() == CF_D;
435 data_format df("uint8[R,G,B]");
436 if (is_depth) {
437 render_buffer rb("[R,G,B]");
438 df = data_format("uint32[D]");
439 rb.create(ctx, int(get_width()), int(get_height()));
440 if (!fb.attach(ctx, rb)) {
441 last_error = "could not attach color buffer for write_to_file";
442 return false;
443 }
444 }
445 if (!fb.is_complete(ctx)) {
446 last_error = "frame buffer object not complete for write_to_file due to\n";
448 return false;
449 }
450 fb.enable(ctx);
451 df.set_width(get_width());
453 data_view dv(&df);
454 ctx.read_frame_buffer(dv, 0, 0, cgv::render::FB_0);
455 fb.disable(ctx);
456
457 if (is_depth) {
459 size_t i, n = get_width()*get_height();
460 for (i = 0; i < n; ++i)
461 stats.update(dv.get_ptr<cgv::type::uint32_type>()[i]);
465 data_view dv2(&df2);
466 for (i = 0; i < n; ++i) {
467 double mapped_value = pow(double(dv.get_ptr<cgv::type::uint32_type>()[i] - min_val) / (max_val - min_val), depth_map_gamma);
468 cgv::type::uint8_type v = cgv::type::uint8_type(255 * mapped_value);
470 }
471 image_writer w(file_name);
472 if (!w.write_image(dv2)) {
473 last_error = "could not write image file ";
474 last_error += file_name;
475 return false;
476 }
477 return true;
478 }
479 image_writer w(file_name);
480 w.multi_set(options);
481 if (!w.write_image(dv)) {
482 last_error = "could not write image file ";
483 last_error += file_name;
484 return false;
485 }
486 return true;
487}
488
491{
492 if(!is_created()) {
493 render_component::last_error = "attempt to create mipmap levels for texture that is not created";
494 return false;
495 }
496 return ctx.texture_create_mipmaps(*this, *this);
497}
498
502{
503 return ctx.texture_generate_mipmaps(*this, get_nr_dimensions());
504}
505
506bool texture::complete_create(const context& ctx, bool created)
507{
508 state_out_of_date = true;
509 ctx_ptr = &ctx;
510 if (created)
511 ensure_state(ctx);
512 return created;
513}
514
515
521bool texture::create_from_buffer(const context& ctx, int x, int y, int width, int height, int level)
522{
523 if (is_created() && level < 1)
524 return replace_from_buffer(ctx, 0, 0, x, y, width, height, level);
525
526 if (level <= 0) {
527 destruct(ctx);
529 set_width(width);
530 set_height(height);
531 }
532 if (level == -1 && !internal_format)
533 find_best_format(ctx);
534 return complete_create(ctx, ctx.texture_create_from_buffer(*this, *this, x, y, level));
535}
536
549bool texture::create(const context& ctx, const cgv::data::const_data_view& data, int level, int cube_side, int num_array_layers, const std::vector<data_view>* palettes)
550{
551 const data_format& f = *data.get_format();
553
554 if(cube_side > -1) {
555 if(tt == TT_2D)
556 tt = TT_CUBEMAP;
557 } else if(num_array_layers != 0) {
558 if(num_array_layers < 0) {
559 // automatic inference of layers from texture dimensions
560 unsigned n_dims = f.get_nr_dimensions();
561 if(n_dims == 2)
562 tt = TT_1D_ARRAY;
563 if(n_dims == 3)
564 tt = TT_2D_ARRAY;
565 } else {
566 switch(tt) {
567 case TT_1D: tt = TT_1D_ARRAY; break;
568 case TT_2D: tt = TT_2D_ARRAY; break;
569 case TT_3D: tt = TT_2D_ARRAY; break;
570 }
571 }
572 }
573 // TODO: replace is currently only allowed for non-array type textures. If this changes make sure to modify the replace method accordingly including generating mipmaps.
574 if ((tt == TT_1D || tt == TT_2D || tt == TT_3D) && is_created()) {
575 bool replace_allowed = tt == this->tt;
576 for(unsigned i = 0; replace_allowed && i < get_nr_dimensions(); ++i)
577 if(get_resolution(i) != f.get_resolution(i))
578 replace_allowed = false;
579 if (replace_allowed && level < 1) {
580 switch (tt) {
581 case TT_1D : return replace(ctx, 0, data, level, palettes);
582 case TT_2D : return replace(ctx, 0, 0, data, level, palettes);
583 case TT_3D : return replace(ctx, 0, 0, 0, data, level, palettes);
584 }
585 return false;
586 }
587 destruct(ctx);
588 }
589 if (level < 1) {
591 for(unsigned int i = 0; i < get_nr_dimensions(); ++i)
594 static_cast<component_format&>(*this) = *data.get_format();
595 if (level == -1 || !internal_format)
596 find_best_format(ctx, palettes);
597 }
598 return complete_create(ctx, ctx.texture_create(*this, *this, data, level, cube_side, num_array_layers, palettes));
599}
600
604bool texture::replace(const context& ctx, int x, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
605{
606 if (!is_created()) {
607 render_component::last_error = "attempt to replace in a not created 1d texture";
608 return false;
609 }
610 if (data.get_format()->get_nr_dimensions() > 1) {
611 render_component::last_error = "cannot replace block in 1d texture with 2d or 3d data block";
612 return false;
613 }
614 return ctx.texture_replace(*this,x,-1,-1,data,level, palettes);
615}
616
620bool texture::replace(const context& ctx, int x, int y, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
621{
622 if (!is_created()) {
623 render_component::last_error = "attempt to replace in a not created 1d texture";
624 return false;
625 }
626 if (data.get_format()->get_nr_dimensions() > 2) {
627 render_component::last_error = "cannot replace block in 2d texture with 3d data block";
628 return false;
629 }
630 return ctx.texture_replace(*this,x,y,-1,data,level, palettes);
631}
632
637bool texture::replace(const context& ctx, int x, int y, int z_or_cube_side, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
638{
639 if (!is_created()) {
640 render_component::last_error = "attempt to replace in a not created 1d texture";
641 return false;
642 }
643 bool res = ctx.texture_replace(*this,x,y,z_or_cube_side,data,level, palettes);
644 if (res && level == -1 && !have_mipmaps)
645 have_mipmaps = true;
646 return res;
647}
648
650bool texture::replace_from_buffer(const context& ctx, int x, int y, int x_buffer,
651 int y_buffer, int width, int height, int level)
652{
653 if (!is_created()) {
654 render_component::last_error = "attempt to replace in a not created 1d texture";
655 return false;
656 }
657 if (get_nr_dimensions() != 2) {
658 render_component::last_error = "attempt to replace a 2d block in a not 2d texture";
659 return false;
660 }
661 return ctx.texture_replace_from_buffer(*this,x,y,-1,x_buffer,y_buffer,width,height,level);
662}
663
665bool texture::replace_from_buffer(const context& ctx, int x, int y, int z_or_cube_side, int x_buffer,
666 int y_buffer, int width, int height, int level)
667{
668 if (!is_created()) {
669 render_component::last_error = "attempt to replace in a not created texture";
670 return false;
671 }
672 if (tt != TT_3D && tt != TT_CUBEMAP) {
673 render_component::last_error = "replacing a 2d block in a slice / cube side of a not 3d texture / cubemap";
674 return false;
675 }
676 return ctx.texture_replace_from_buffer(*this,x,y,z_or_cube_side,x_buffer,y_buffer,width,height,level);
677}
678
680bool texture::replace_from_image(const context& ctx, const std::string& file_name, int x, int y, int z_or_cube_side, int level)
681{
682 data_format df;
683 data_view dv;
684 return replace_from_image(df,dv,ctx,file_name,x,y,z_or_cube_side,level);
685}
686
690 const std::string& file_name, int x, int y, int z_or_cube_side,
691 int level)
692{
693 std::string fn = file_name;
694 if (fn.empty()) {
695 return false;
696 }
697 std::vector<data_format> palette_formats;
698 image_reader ir(df, &palette_formats);
699 if (!ir.read_image(fn, dv))
700 return false;
701 std::vector<data_view> palettes;
702 for (unsigned i=0; i<palette_formats.size(); ++i) {
703 palettes.push_back(data_view());
704 if (!ir.read_palette(i, palettes.back()))
705 return false;
706 }
707 replace(ctx, x, y, z_or_cube_side, dv, level, &palettes);
708 return true;
709}
710
711bool texture::copy(const context& ctx, cgv::data::data_view& dv, int level) const
712{
713 if(!is_created()) {
714 render_component::last_error = "texture must be created for copy";
715 return false;
716 }
717
719 dv = cgv::data::data_view(df);
720 dv.manage_format();
721
722 return ctx.texture_copy_back(*this, level, dv);
723}
724
727{
728 state_out_of_date = true;
729 internal_format = 0;
730 if(handle != 0)
731 return ctx.texture_destruct(*this);
732 return true;
733}
734
736
741bool texture::enable(const context& ctx, int _tex_unit)
742{
743 if (!handle) {
744 render_component::last_error = "attempt to enable texture that is not created";
745 return false;
746 }
747 ensure_state(ctx);
748 tex_unit = _tex_unit;
749 return ctx.texture_enable(*this, tex_unit, get_nr_dimensions());
750}
752bool texture::disable(const context& ctx)
753{
754 return ctx.texture_disable(*this, tex_unit, get_nr_dimensions());
755}
756
757bool texture::bind_as_image(const context& ctx, int _tex_unit, int level, bool bind_array, int layer, AccessType access)
758{
759 if(!handle) {
760 render_component::last_error = "attempt to bind texture that is not created";
761 return false;
762 }
763 ensure_state(ctx);
764 tex_unit = _tex_unit;
765 //binding_index = ...
766
767 return ctx.texture_bind_as_image(*this, tex_unit, level, bind_array, layer, access);
768}
769
772{
773 return have_mipmaps;
774}
777{
778 return user_data != 0;
779}
782{
783 return tex_unit;
784}
785
786
788 }
789}
void multi_set(const std::string &property_assignments, bool report_error=true)
set several properties
Definition base.cxx:287
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
the component format inherits the information of a packing_info and adds information on the component...
bool set_component_format(const std::string &description)
set component format from description string, which has the following syntax.
bool set(int ci, void *ptr, const T &v) const
write access to the i-th component, return whether write was successful
ComponentFormat get_standard_component_format() const
return whether the component format is one of the standard formats
unsigned int get_entry_size() const
return the size of one entry of components in bytes
bool empty() const
return whether the component format is defined
unsigned int get_nr_components() const
return the number of components
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
unsigned get_nr_dimensions() const
return the number of dimensions of the data set
void set_component_format(const component_format &cf)
set component_format by simply assigning to a converted this pointer
void set_resolution(unsigned i, size_t resolution)
set the resolution in the i-th dimension, add dimensions if necessary
void set_height(size_t _height)
set the resolution in the second dimension, add dimensions if necessary
void set_width(size_t _width)
set the resolution in the first dimension, add dimensions if necessary
size_t get_width() const
return the resolution in the first dimension, or 1 if not defined
void set_depth(size_t _depth)
set the resolution in the third dimension, add dimensions if necessary
size_t get_height() const
return the resolution in the second dimension, or 1 if not defined
void set_nr_dimensions(unsigned _d)
set the number of dimensions of the data set
data_format()
construct an undefined data format
bool set_data_format(const std::string &description)
Set data format from description string, which adds information to the description string of the comp...
size_t get_resolution(unsigned i) const
return the resolution in the i-th dimension, or 0 if not defined
void manage_format(bool enable=true)
whether to manage the data format pointer
Definition data_view.cxx:59
const data_format * get_format() const
return the component format
Definition data_view.cxx:73
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
Definition data_view.h:61
the data view gives access to a data array of one, two, three or four dimensions.
Definition data_view.h:153
the image reader chooses a specific reader automatically based on the extension of the given file nam...
const std::string & get_last_error() const
return a reference to the last error message
bool read_image(const std::string &file_name, cgv::data::data_view &dv, std::vector< cgv::data::data_view > *palettes=0)
read the whole image into the given data view.
bool read_palette(unsigned int i, cgv::data::data_view &dv)
read the i-th palette in case of a paletted file format, and handle the data view as in the read_imag...
the image writer chooses a specific writer automatically based on the extension of the given file nam...
bool write_image(const cgv::data::const_data_view &dv, const std::vector< cgv::data::const_data_view > *palettes=0, double duration=0)
write the data stored in the data view to a file with the file name given in the constructor.
base class for all drawables, which is independent of the used rendering API.
Definition context.h:670
virtual bool read_frame_buffer(data::data_view &dv, unsigned int x=0, unsigned int y=0, FrameBufferType buffer_type=FB_BACK, cgv::type::info::TypeId type=cgv::type::info::TI_UINT8, data::ComponentFormat cf=data::CF_RGB, int w=-1, int h=-1)=0
read the current frame buffer or a rectangular region of it into the given data view.
virtual bool make_current() const =0
make the current context current if possible
this class encapsulate frame buffers that live on the GPU and can be used as destination for the rend...
bool create(const context &ctx, int _width=-1, int _height=-1)
create framebuffer if extension is supported, otherwise return false.
bool is_complete(const context &ctx) const
check for completeness, if not complete, get the reason in last_error
bool attach(const context &ctx, const render_buffer &rb, int i=0)
attach render buffer to depth buffer if it is a depth buffer, to stencil if it is a stencil buffer or...
bool enable(context &ctx, int i0=-1, int i1=-1, int i2=-1, int i3=-1, int i4=-1, int i5=-1, int i6=-1, int i7=-1, int i8=-1, int i9=-1, int i10=-1, int i11=-1, int i12=-1, int i13=-1, int i14=-1, int i15=-1)
enable the framebuffer either with all color attachments if no arguments are given or if arguments ar...
bool disable(context &ctx)
disable the framebuffer object
std::string last_error
a string that contains the last error, which is only set by the init method
this class encapsulate render buffers that live on the GPU which must support frame buffer objects fo...
bool create(const context &ctx, int width=-1, int height=-1)
create a render buffer.
virtual bool is_created() const
return whether component has been created
Definition context.cxx:2226
const context * ctx_ptr
keep pointer to my context
Definition context.h:363
std::string last_error
a string that contains the last error
Definition context.h:365
base interface for a texture
Definition context.h:389
bool generate_mipmaps(const context &ctx)
generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU
Definition texture.cxx:501
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
Definition texture.cxx:144
TextureWrap get_wrap_s() const
return the texture wrap behaviour in s direction
Definition texture.cxx:96
TextureFilter get_mag_filter() const
return the magnification filter
Definition texture.cxx:150
bool set_data_format(const std::string &description)
change the data format and clear internal format
Definition texture.cxx:53
TextureFilter get_min_filter() const
return the minification filter
Definition texture.cxx:134
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.
Definition texture.cxx:214
~texture()
destruct texture, the destructor can be called without context if the destruct method has been called...
Definition texture.cxx:43
void set_compare_function(CompareFunction compare_function)
set the texture compare function
Definition texture.cxx:178
int get_tex_unit() const
return the currently used texture unit and -1 for current
Definition texture.cxx:781
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.
Definition texture.cxx:313
TextureWrap get_wrap_r() const
return the texture wrap behaviour in r direction
Definition texture.cxx:106
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...
Definition texture.cxx:521
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.
Definition texture.cxx:328
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.
Definition texture.cxx:650
void set_priority(float _priority)
set priority with which texture is kept in GPU memory
Definition texture.cxx:155
float get_priority() const
return the priority with which texture is kept in GPU memory
Definition texture.cxx:161
void set_fixed_sample_locations(bool use)
set whether multi sampling uses fixed sample locations
Definition texture.cxx:236
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 para...
Definition texture.cxx:23
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
Definition texture.cxx:680
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
Definition texture.cxx:231
bool disable(const context &ctx)
disable texture and restore state from before last enable call
Definition texture.cxx:752
void ensure_state(const context &ctx) const
ensure the the texture state is synchronized with the GPU settings
Definition texture.cxx:204
bool enable(const context &ctx, int tex_unit=-1)
enable this texture in the given texture unit, -1 corresponds to the current unit.
Definition texture.cxx:741
void set_wrap_t(TextureWrap _wrap_t)
set the texture wrap behaviour in t direction
Definition texture.cxx:84
bool destruct(const context &ctx)
destruct the texture and free texture memory and handle
Definition texture.cxx:726
std::string last_error
a string that contains the last error
Definition context.h:365
CompareFunction get_compare_function() const
get the texture compare function
Definition texture.cxx:185
bool get_compare_mode() const
get the texture compare mode and function
Definition texture.cxx:172
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.
Definition texture.cxx:410
bool mipmaps_created() const
check whether mipmaps have been created
Definition texture.cxx:771
void set_wrap_s(TextureWrap _wrap_s)
set the texture wrap behaviour in s direction
Definition texture.cxx:78
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.
Definition texture.cxx:604
cgv::vec4 get_border_color() const
return the texture border color
Definition texture.cxx:120
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
Definition texture.cxx:196
void set_component_format(const component_format &cf)
change component format and clear internal format
Definition texture.cxx:62
void set_border_color(const float *rgba)
set the border color
Definition texture.h:58
bool is_enabled() const
check whether textue is enabled
Definition texture.cxx:776
TextureWrap get_wrap_t() const
return the texture wrap behaviour in t direction
Definition texture.cxx:101
bool create_mipmaps(const context &ctx)
create storage for mipmaps without computing the mipmap contents
Definition texture.cxx:490
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 mat...
Definition texture.cxx:711
void set_wrap_r(TextureWrap _wrap_r)
set the texture wrap behaviour in r direction
Definition texture.cxx:90
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 param...
Definition texture.cxx:126
void set_compare_mode(bool use_compare_function)
set the texture compare mode and function
Definition texture.cxx:166
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.
Definition texture.cxx:393
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.
Definition texture.cxx:757
float get_anisotropy() const
return the currently set anisotropy
Definition texture.cxx:139
incrementally accumulate statistical information
Definition statistics.h:13
void update(const double &v)
consider another value
double get_max() const
get the maximum of the considered variables
double get_min() const
get the minimum of the considered variables
the tokenizer allows to split text into tokens in a convenient way.
Definition tokenizer.h:68
tokenizer & set_sep(const std::string &sep, bool merge)
set the list of separators and specify whether succeeding separators are merged into single tokens
Definition tokenizer.cxx:59
tokenizer & set_ws(const std::string &ws)
set the list of white spaces, that separate tokens and are skipped
Definition tokenizer.cxx:38
namespace for data management components
@ CF_RGB
color format with two components R and G
@ CF_D
color format with components B, G, R and A
namespace for image processing
AccessType
different access types
Definition context.h:322
TextureFilter
different texture filter
Definition context.h:245
TextureWrap
different texture wrap modes
Definition context.h:229
TextureType
different texture types
Definition context.h:257
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:310
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
unsigned char uint8_type
this type provides an 8 bit unsigned integer type
namespace that holds tools that dont fit any other namespace
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
this header is dependency free
Definition print.h:11
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:685