cgv
Loading...
Searching...
No Matches
texture.cxx
1#include "texture.h"
2#include "frame_buffer.h"
3
4#include <cgv/media/image/image_reader.h>
5#include <cgv/media/image/image_writer.h>
6#include <cgv/utils/tokenizer.h>
7#include <cgv/utils/file.h>
8#include <cgv/utils/statistics.h>
9
10using namespace cgv::data;
11using namespace cgv::media::image;
12using namespace cgv::utils;
13using namespace cgv::utils::file;
14
15namespace cgv {
16 namespace render {
17
22texture::texture(const std::string& description,
23 TextureFilter _mag_filter,
24 TextureFilter _min_filter,
25 TextureWrap _wrap_s,
26 TextureWrap _wrap_t,
27 TextureWrap _wrap_r) : data::data_format(description)
28{
29 mag_filter = _mag_filter;
30 min_filter = _min_filter;
31 wrap_s = _wrap_s;
32 wrap_t = _wrap_t;
33 wrap_r = _wrap_r;
34 state_out_of_date = true;
35 have_mipmaps = false;
36 tex_unit = -1;
37}
38
43{
46
47 if(handle != 0)
48 std::cerr << "could not destruct texture properly" << std::endl;
49}
50
52bool texture::set_data_format(const std::string& description)
53{
54 bool res = data_format::set_data_format(description);
55 internal_format = 0;
56 state_out_of_date = true;
57 return res;
58}
59
62{
64 internal_format = 0;
65 state_out_of_date = true;
66}
67
69void texture::set_component_format(const std::string& description)
70{
72 internal_format = 0;
73 state_out_of_date = true;
74}
75
78{
79 wrap_s = _wrap_s;
80 state_out_of_date = true;
81}
84{
85 wrap_t = _wrap_t;
86 state_out_of_date = true;
87}
90{
91 wrap_r = _wrap_r;
92 state_out_of_date = true;
93}
96{
97 return wrap_s;
98}
101{
102 return wrap_t;
103}
106{
107 return wrap_r;
108}
110void texture::set_border_color(float r, float g, float b, float a)
111{
112 border_color[0] = r;
113 border_color[1] = g;
114 border_color[2] = b;
115 border_color[3] = a;
116 state_out_of_date = true;
117}
120{
121 return cgv::vec4(4, border_color);
122}
125void texture::set_min_filter(TextureFilter _min_filter, float _anisotropy)
126{
127 min_filter = _min_filter;
128 anisotropy = _anisotropy;
129 state_out_of_date = true;
130}
131
134{
135 return min_filter;
136}
139{
140 return anisotropy;
141}
144{
145 mag_filter = _mag_filter;
146 state_out_of_date = true;
147}
150{
151 return mag_filter;
152}
154void texture::set_priority(float _priority)
155{
156 priority = _priority;
157 state_out_of_date = true;
158}
161{
162 return priority;
163}
165void texture::set_compare_mode(bool _use_compare_function)
166{
167 use_compare_function = _use_compare_function;
168 state_out_of_date = true;
169}
172{
173 return use_compare_function;
174}
175
178{
179 compare_function = _compare_function;
180 state_out_of_date = true;
181}
182
185{
186 return compare_function;
187}
188
189
191
195void texture::find_best_format(const context& ctx, const std::vector<data_view>* palettes)
196{
197 cgv::data::component_format cf = ctx.texture_find_best_format(*this, *this, palettes);
198 void* tmp = internal_format;
200 internal_format = tmp;
201}
202
203void texture::ensure_state(const context& ctx) const
204{
205 if (state_out_of_date) {
206 ctx.texture_set_state(*this);
207 state_out_of_date = false;
208 }
209}
210
213bool texture::create(const context& ctx, TextureType _tt, unsigned width, unsigned height, unsigned depth)
214{
215 if (is_created())
216 destruct(ctx);
217 if (_tt != TT_UNDEF)
218 tt = _tt;
219 if (width != -1)
220 set_width(width);
221 if (height != -1)
222 set_height(height);
223 if (depth != -1)
224 set_depth(depth);
225 if (!internal_format)
226 find_best_format(ctx);
227 return complete_create(ctx, ctx.texture_create(*this, *this));
228}
229
230void texture::set_nr_multi_samples(unsigned _nr_samples)
231{
232 nr_multi_samples = _nr_samples;
233}
234
236{
237 fixed_sample_locations = use;
238}
239
240template <class int_type>
241bool is_power_of_two(int_type i)
242{
243 do {
244 if (i == 1)
245 return true;
246 if ((i & 1) != 0)
247 return false;
248 i /= 2;
249 }
250 while (true);
251 return false;
252}
253
254template <class int_type>
255int_type power_of_two_ub(int_type i)
256{
257 int_type res = 2;
258 while (res < i)
259 res *= 2;
260 return res;
261}
262
264 const std::string& file_name, unsigned char* clear_color_ptr, int level, int cube_side)
265{
266 bool ensure_power_of_two = clear_color_ptr != 0;
267 std::string fn = file_name;
268 if (df.empty()) {
269 if (fn.empty()) {
270 cgv::render::render_component::last_error = "attempt to create texture from empty file name";
271 return false;
272 }
273 }
274 std::vector<data_format> palette_formats;
275 std::vector<data_view> palettes;
276 if (!fn.empty()) {
277 image_reader ir(df, &palette_formats);
278 if (!ir.read_image(fn, dv)) {
279 cgv::render::render_component::last_error = "error reading image file ";
283 return false;
284 }
285 for (unsigned i=0; i<palette_formats.size(); ++i) {
286 palettes.push_back(data_view());
287 if (!ir.read_palette(i, palettes.back())) {
288 cgv::render::render_component::last_error = "error reading palette";
289 return false;
290 }
291 }
292 }
293 if (cube_side < 1)
294 destruct(ctx);
295 size_t w = df.get_width(), h = df.get_height();
296 size_t W = w, H = h;
297 data_format df1(df);
298 if (ensure_power_of_two && (!is_power_of_two(w) || !is_power_of_two(h))) {
299 W = power_of_two_ub(df.get_width());
300 H = power_of_two_ub(df.get_height());
301 df1.set_width(W);
302 df1.set_height(H);
303 }
304 //float ext[2] = { (float)w/W, (float)h/H };
305 data_view dv1(&df1);
306 unsigned entry_size = df.get_entry_size();
307 const unsigned char* src_ptr = dv.get_ptr<unsigned char>();
308 unsigned char* dest_ptr = dv1.get_ptr<unsigned char>();
309 unsigned char* dest_ptr_end = dest_ptr + entry_size * W*H;
310 for (unsigned y = 0; y < h; ++y) {
311 dest_ptr_end -= W * entry_size;
312 memcpy(dest_ptr_end, src_ptr, w*entry_size);
313 if (clear_color_ptr) {
314 for (size_t x = w; x < W; ++x)
315 memcpy(dest_ptr_end + x * entry_size, clear_color_ptr, entry_size);
316 }
317 else
318 std::fill(dest_ptr_end + w * entry_size, dest_ptr_end + W*entry_size, 0);
319 src_ptr += w * entry_size;
320 }
321 if (H > h) {
322 size_t N = (H - h)*W;
323 if (clear_color_ptr) {
324 for (size_t i = 0; i < N; ++i)
325 memcpy(dest_ptr + i * entry_size, clear_color_ptr, entry_size);
326 }
327 else
328 std::fill(dest_ptr, dest_ptr + N*entry_size, 0);
329 }
330 return create(ctx, dv1, level, cube_side, false, &palettes);
331}
332
333
336 const std::string& file_name, int* image_width_ptr, int* image_height_ptr,
337 unsigned char* clear_color_ptr, int level, int cube_side)
338{
339 data_format df;
340 data_view dv;
341 if (!create_from_image(df,dv,ctx,file_name,clear_color_ptr,level,cube_side))
342 return false;
343 if (image_width_ptr)
344 *image_width_ptr = int(df.get_width());
345 if (image_height_ptr)
346 *image_height_ptr = int(df.get_height());
347 return true;
348}
349
350bool texture::deduce_file_names(const std::string& file_names, std::vector<std::string>& deduced_names)
351{
352 if (std::find(file_names.begin(), file_names.end(), '{') != file_names.end()) {
353 std::vector<token> toks;
354 deduced_names.resize(6);
355 tokenizer(file_names).set_ws("").set_sep("{,}").bite_all(toks);
356 int selection = -1;
357 for (unsigned i=0; i<toks.size(); ++i) {
358 if (toks[i] == "{") {
359 if (selection != -1) {
360 std::cerr << "warning: nested {} not allowed in cubemap file names specification " << file_names << std::endl;
361 return false;
362 }
363 selection = 0;
364 }
365 else if (toks[i] == "}") {
366 if (selection == -1) {
367 std::cerr << "warning: } without opening { in cubemap file names specification " << file_names << std::endl;
368 return false;
369 }
370 if (selection != 5) {
371 std::cerr << "warning: no 6 file names specified for creating cubemap from images " << file_names << std::endl;
372 return false;
373 }
374 selection = -1;
375 }
376 else if (toks[i] == ",") {
377 if (selection == -1) {
378 std::cerr << "warning: , arising outside {} in cubemap file names specification " << file_names << std::endl;
379 return false;
380 }
381 ++selection;
382 }
383 else {
384 if (selection == -1) {
385 for (unsigned j=0; j<6; ++j)
386 deduced_names[j] += to_string(toks[i]);
387 }
388 else {
389 if (selection == 6) {
390 std::cerr << "warning: more than 6 files names specified for cubemap creation " << file_names << std::endl;
391 return false;
392 }
393 deduced_names[selection] += to_string(toks[i]);
394 }
395 }
396 }
397 }
398 else {
399 std::string path_prefix = get_path(file_names);
400 if (!path_prefix.empty())
401 path_prefix += '/';
402 void* handle = find_first(file_names);
403 while (handle != 0) {
404 deduced_names.push_back(path_prefix+find_name(handle));
405 handle = find_next(handle);
406 }
407 if (deduced_names.size() != 6) {
408 std::cerr << "warning: not exactly 6 files names specified for cubemap creation " << file_names << std::endl;
409 return false;
410 }
411 }
412 return true;
413}
414
415bool texture::create_from_images(const context& ctx, const std::string& file_names, int level)
416{
417 std::vector<std::string> deduced_names;
418 if (!deduce_file_names(file_names, deduced_names))
419 return false;
420 bool success = true;
421 for (unsigned i=0; success && i<6; ++i)
422 if (!create_from_image(ctx, deduced_names[i],0,0,0,level,i)) {
423 success = false;
424 std::cerr << "could not create cubemap side " << i << " from image " << deduced_names[i] << std::endl;
425 }
426 if (!success)
427 destruct(ctx);
428 return success;
429}
430
432bool 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
433{
434 std::string& last_error = static_cast<const cgv::render::texture_base*>(this)->last_error;
435 if (!is_created()) {
436 last_error = "texture must be created for write_to_file";
437 return false;
438 }
439 frame_buffer fb;
440 if (!fb.create(ctx,int(get_width()), int(get_height()))) {
441 last_error = "could not create frame buffer object for write_to_file";
442 return false;
443 }
444 if (z_or_cube_size != -1) {
445 if (!fb.attach(ctx,*this,z_or_cube_size,0,0)) {
446 last_error = "could not attach texture for write_to_file";
447 return false;
448 }
449 }
450 else {
451 if (!fb.attach(ctx,*this)) {
452 last_error = "could not attach texture for write_to_file";
453 return false;
454 }
455 }
456 bool is_depth = get_standard_component_format() == CF_D;
457 data_format df("uint8[R,G,B]");
458 if (is_depth) {
459 render_buffer rb("[R,G,B]");
460 df = data_format("uint32[D]");
461 rb.create(ctx, int(get_width()), int(get_height()));
462 if (!fb.attach(ctx, rb)) {
463 last_error = "could not attach color buffer for write_to_file";
464 return false;
465 }
466 }
467 if (!fb.is_complete(ctx)) {
468 last_error = "frame buffer object not complete for write_to_file due to\n";
470 return false;
471 }
472 fb.enable(ctx);
473 df.set_width(get_width());
475 data_view dv(&df);
476 ctx.read_frame_buffer(dv, 0, 0, cgv::render::FB_0);
477 fb.disable(ctx);
478
479 if (is_depth) {
481 size_t i, n = get_width()*get_height();
482 for (i = 0; i < n; ++i)
483 stats.update(dv.get_ptr<cgv::type::uint32_type>()[i]);
487 data_view dv2(&df2);
488 for (i = 0; i < n; ++i) {
489 double mapped_value = pow(double(dv.get_ptr<cgv::type::uint32_type>()[i] - min_val) / (max_val - min_val), depth_map_gamma);
490 cgv::type::uint8_type v = cgv::type::uint8_type(255 * mapped_value);
492 }
493 image_writer w(file_name);
494 if (!w.write_image(dv2)) {
495 last_error = "could not write image file ";
496 last_error += file_name;
497 return false;
498 }
499 return true;
500 }
501 image_writer w(file_name);
502 w.multi_set(options);
503 if (!w.write_image(dv)) {
504 last_error = "could not write image file ";
505 last_error += file_name;
506 return false;
507 }
508 return true;
509}
510
513{
514 if(!is_created()) {
515 render_component::last_error = "attempt to create mipmap levels for texture that is not created";
516 return false;
517 }
518 return ctx.texture_create_mipmaps(*this, *this);
519}
520
524{
525 return ctx.texture_generate_mipmaps(*this, get_nr_dimensions());
526}
527
528bool texture::complete_create(const context& ctx, bool created)
529{
530 state_out_of_date = true;
531 ctx_ptr = &ctx;
532 if (created)
533 ensure_state(ctx);
534 return created;
535}
536
537
543bool texture::create_from_buffer(const context& ctx, int x, int y, int width, int height, int level)
544{
545 if (is_created() && level < 1)
546 return replace_from_buffer(ctx, 0, 0, x, y, width, height, level);
547
548 if (level <= 0) {
549 destruct(ctx);
551 set_width(width);
552 set_height(height);
553 }
554 if (level == -1 && !internal_format)
555 find_best_format(ctx);
556 return complete_create(ctx, ctx.texture_create_from_buffer(*this, *this, x, y, level));
557}
558
571bool 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)
572{
573 const data_format& f = *data.get_format();
575
576 if(cube_side > -1) {
577 if(tt == TT_2D)
578 tt = TT_CUBEMAP;
579 } else if(num_array_layers != 0) {
580 if(num_array_layers < 0) {
581 // automatic inference of layers from texture dimensions
582 unsigned n_dims = f.get_nr_dimensions();
583 if(n_dims == 2)
584 tt = TT_1D_ARRAY;
585 if(n_dims == 3)
586 tt = TT_2D_ARRAY;
587 } else {
588 switch(tt) {
589 case TT_1D: tt = TT_1D_ARRAY; break;
590 case TT_2D: tt = TT_2D_ARRAY; break;
591 case TT_3D: tt = TT_2D_ARRAY; break;
592 }
593 }
594 }
595 // 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.
596 if ((tt == TT_1D || tt == TT_2D || tt == TT_3D) && is_created()) {
597 bool replace_allowed = tt == this->tt;
598 for(unsigned i = 0; replace_allowed && i < get_nr_dimensions(); ++i)
599 if(get_resolution(i) != f.get_resolution(i))
600 replace_allowed = false;
601 if (replace_allowed && level < 1) {
602 switch (tt) {
603 case TT_1D : return replace(ctx, 0, data, level, palettes);
604 case TT_2D : return replace(ctx, 0, 0, data, level, palettes);
605 case TT_3D : return replace(ctx, 0, 0, 0, data, level, palettes);
606 }
607 return false;
608 }
609 destruct(ctx);
610 }
611 if (level < 1) {
613 for(unsigned int i = 0; i < get_nr_dimensions(); ++i)
616 static_cast<component_format&>(*this) = *data.get_format();
617 if (level == -1 || !internal_format)
618 find_best_format(ctx, palettes);
619 }
620 return complete_create(ctx, ctx.texture_create(*this, *this, data, level, cube_side, num_array_layers, palettes));
621}
622
626bool texture::replace(const context& ctx, int x, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
627{
628 if (!is_created()) {
629 render_component::last_error = "attempt to replace in a not created 1d texture";
630 return false;
631 }
632 if (data.get_format()->get_nr_dimensions() > 1) {
633 render_component::last_error = "cannot replace block in 1d texture with 2d or 3d data block";
634 return false;
635 }
636 return ctx.texture_replace(*this,x,-1,-1,data,level, palettes);
637}
638
642bool texture::replace(const context& ctx, int x, int y, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
643{
644 if (!is_created()) {
645 render_component::last_error = "attempt to replace in a not created 1d texture";
646 return false;
647 }
648 if (data.get_format()->get_nr_dimensions() > 2) {
649 render_component::last_error = "cannot replace block in 2d texture with 3d data block";
650 return false;
651 }
652 return ctx.texture_replace(*this,x,y,-1,data,level, palettes);
653}
654
659bool 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)
660{
661 if (!is_created()) {
662 render_component::last_error = "attempt to replace in a not created 1d texture";
663 return false;
664 }
665 bool res = ctx.texture_replace(*this,x,y,z_or_cube_side,data,level, palettes);
666 if (res && level == -1 && !have_mipmaps)
667 have_mipmaps = true;
668 return res;
669}
670
672bool texture::replace_from_buffer(const context& ctx, int x, int y, int x_buffer,
673 int y_buffer, int width, int height, int level)
674{
675 if (!is_created()) {
676 render_component::last_error = "attempt to replace in a not created 1d texture";
677 return false;
678 }
679 if (get_nr_dimensions() != 2) {
680 render_component::last_error = "attempt to replace a 2d block in a not 2d texture";
681 return false;
682 }
683 return ctx.texture_replace_from_buffer(*this,x,y,-1,x_buffer,y_buffer,width,height,level);
684}
685
687bool texture::replace_from_buffer(const context& ctx, int x, int y, int z_or_cube_side, int x_buffer,
688 int y_buffer, int width, int height, int level)
689{
690 if (!is_created()) {
691 render_component::last_error = "attempt to replace in a not created texture";
692 return false;
693 }
694 if (tt != TT_3D && tt != TT_CUBEMAP) {
695 render_component::last_error = "replacing a 2d block in a slice / cube side of a not 3d texture / cubemap";
696 return false;
697 }
698 return ctx.texture_replace_from_buffer(*this,x,y,z_or_cube_side,x_buffer,y_buffer,width,height,level);
699}
700
702bool texture::replace_from_image(const context& ctx, const std::string& file_name, int x, int y, int z_or_cube_side, int level)
703{
704 data_format df;
705 data_view dv;
706 return replace_from_image(df,dv,ctx,file_name,x,y,z_or_cube_side,level);
707}
708
712 const std::string& file_name, int x, int y, int z_or_cube_side,
713 int level)
714{
715 std::string fn = file_name;
716 if (fn.empty()) {
717 return false;
718 }
719 std::vector<data_format> palette_formats;
720 image_reader ir(df, &palette_formats);
721 if (!ir.read_image(fn, dv))
722 return false;
723 std::vector<data_view> palettes;
724 for (unsigned i=0; i<palette_formats.size(); ++i) {
725 palettes.push_back(data_view());
726 if (!ir.read_palette(i, palettes.back()))
727 return false;
728 }
729 replace(ctx, x, y, z_or_cube_side, dv, level, &palettes);
730 return true;
731}
732
733bool texture::copy(const context& ctx, cgv::data::data_view& dv, int level) const
734{
735 if(!is_created()) {
736 render_component::last_error = "texture must be created for copy";
737 return false;
738 }
739
741 dv = cgv::data::data_view(df);
742 dv.manage_format();
743
744 return ctx.texture_copy_back(*this, level, dv);
745}
746
749{
750 state_out_of_date = true;
751 internal_format = 0;
752 if(handle != 0)
753 return ctx.texture_destruct(*this);
754 return true;
755}
756
758
763bool texture::enable(const context& ctx, int _tex_unit)
764{
765 if (!handle) {
766 render_component::last_error = "attempt to enable texture that is not created";
767 return false;
768 }
769 ensure_state(ctx);
770 tex_unit = _tex_unit;
771 return ctx.texture_enable(*this, tex_unit, get_nr_dimensions());
772}
774bool texture::disable(const context& ctx)
775{
776 return ctx.texture_disable(*this, tex_unit, get_nr_dimensions());
777}
778
779bool texture::bind_as_image(const context& ctx, int _tex_unit, int level, bool bind_array, int layer, AccessType access) {
780 if(!handle) {
781 render_component::last_error = "attempt to bind texture that is not created";
782 return false;
783 }
784 ensure_state(ctx);
785 tex_unit = _tex_unit;
786 //binding_index = ...
787
788 return ctx.texture_bind_as_image(*this, tex_unit, level, bind_array, layer, access);
789}
790
793{
794 return have_mipmaps;
795}
798{
799 return user_data != 0;
800}
803{
804 return tex_unit;
805}
806
807
809 }
810}
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:2152
const context * ctx_ptr
keep pointer to my context
Definition context.h:359
std::string last_error
a string that contains the last error
Definition context.h:361
base interface for a texture
Definition context.h:384
bool generate_mipmaps(const context &ctx)
generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU
Definition texture.cxx:523
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
Definition texture.cxx:143
TextureWrap get_wrap_s() const
return the texture wrap behaviour in s direction
Definition texture.cxx:95
TextureFilter get_mag_filter() const
return the magnification filter
Definition texture.cxx:149
bool set_data_format(const std::string &description)
change the data format and clear internal format
Definition texture.cxx:52
TextureFilter get_min_filter() const
return the minification filter
Definition texture.cxx:133
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:213
~texture()
destruct texture, the destructor can be called without context if the destruct method has been called...
Definition texture.cxx:42
void set_compare_function(CompareFunction compare_function)
set the texture compare function
Definition texture.cxx:177
int get_tex_unit() const
return the currently used texture unit and -1 for current
Definition texture.cxx:802
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:335
TextureWrap get_wrap_r() const
return the texture wrap behaviour in r direction
Definition texture.cxx:105
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:543
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:350
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:672
void set_priority(float _priority)
set priority with which texture is kept in GPU memory
Definition texture.cxx:154
float get_priority() const
return the priority with which texture is kept in GPU memory
Definition texture.cxx:160
void set_fixed_sample_locations(bool use)
set whether multi sampling uses fixed sample locations
Definition texture.cxx:235
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:22
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:702
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:230
bool disable(const context &ctx)
disable texture and restore state from before last enable call
Definition texture.cxx:774
void ensure_state(const context &ctx) const
ensure the the texture state is synchronized with the GPU settings
Definition texture.cxx:203
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:763
void set_wrap_t(TextureWrap _wrap_t)
set the texture wrap behaviour in t direction
Definition texture.cxx:83
bool destruct(const context &ctx)
destruct the texture and free texture memory and handle
Definition texture.cxx:748
std::string last_error
a string that contains the last error
Definition context.h:361
CompareFunction get_compare_function() const
get the texture compare function
Definition texture.cxx:184
bool get_compare_mode() const
get the texture compare mode and function
Definition texture.cxx:171
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:432
bool mipmaps_created() const
check whether mipmaps have been created
Definition texture.cxx:792
void set_wrap_s(TextureWrap _wrap_s)
set the texture wrap behaviour in s direction
Definition texture.cxx:77
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:626
cgv::vec4 get_border_color() const
return the texture border color
Definition texture.cxx:119
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:195
void set_component_format(const component_format &cf)
change component format and clear internal format
Definition texture.cxx:61
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:797
TextureWrap get_wrap_t() const
return the texture wrap behaviour in t direction
Definition texture.cxx:100
bool create_mipmaps(const context &ctx)
create storage for mipmaps without computing the mipmap contents
Definition texture.cxx:512
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:733
void set_wrap_r(TextureWrap _wrap_r)
set the texture wrap behaviour in r direction
Definition texture.cxx:89
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:125
void set_compare_mode(bool use_compare_function)
set the texture compare mode and function
Definition texture.cxx:165
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:415
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:779
float get_anisotropy() const
return the currently set anisotropy
Definition texture.cxx:138
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:318
TextureFilter
different texture filter
Definition context.h:241
TextureWrap
different texture wrap modes
Definition context.h:225
TextureType
different texture types
Definition context.h:253
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:306
@ 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
the cgv namespace
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:636