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}
120void texture::set_min_filter(TextureFilter _min_filter, float _anisotropy)
121{
122 min_filter = _min_filter;
123 anisotropy = _anisotropy;
124 state_out_of_date = true;
125}
126
129{
130 return min_filter;
131}
134{
135 return anisotropy;
136}
139{
140 mag_filter = _mag_filter;
141 state_out_of_date = true;
142}
145{
146 return mag_filter;
147}
149void texture::set_priority(float _priority)
150{
151 priority = _priority;
152 state_out_of_date = true;
153}
156{
157 return priority;
158}
160void texture::set_compare_mode(bool _use_compare_function)
161{
162 use_compare_function = _use_compare_function;
163 state_out_of_date = true;
164}
167{
168 return use_compare_function;
169}
170
173{
174 compare_function = _compare_function;
175 state_out_of_date = true;
176}
177
180{
181 return compare_function;
182}
183
184
186
190void texture::find_best_format(const context& ctx, const std::vector<data_view>* palettes)
191{
192 cgv::data::component_format cf = ctx.texture_find_best_format(*this, *this, palettes);
193 void* tmp = internal_format;
195 internal_format = tmp;
196}
197
198void texture::ensure_state(const context& ctx) const
199{
200 if (state_out_of_date) {
201 ctx.texture_set_state(*this);
202 state_out_of_date = false;
203 }
204}
205
208bool texture::create(const context& ctx, TextureType _tt, unsigned width, unsigned height, unsigned depth)
209{
210 if (is_created())
211 destruct(ctx);
212 if (_tt != TT_UNDEF)
213 tt = _tt;
214 if (width != -1)
215 set_width(width);
216 if (height != -1)
217 set_height(height);
218 if (depth != -1)
219 set_depth(depth);
220 if (!internal_format)
221 find_best_format(ctx);
222 return complete_create(ctx, ctx.texture_create(*this, *this));
223}
224
225void texture::set_nr_multi_samples(unsigned _nr_samples)
226{
227 nr_multi_samples = _nr_samples;
228}
229
231{
232 fixed_sample_locations = use;
233}
234
235template <class int_type>
236bool is_power_of_two(int_type i)
237{
238 do {
239 if (i == 1)
240 return true;
241 if ((i & 1) != 0)
242 return false;
243 i /= 2;
244 }
245 while (true);
246 return false;
247}
248
249template <class int_type>
250int_type power_of_two_ub(int_type i)
251{
252 int_type res = 2;
253 while (res < i)
254 res *= 2;
255 return res;
256}
257
259 const std::string& file_name, unsigned char* clear_color_ptr, int level, int cube_side)
260{
261 bool ensure_power_of_two = clear_color_ptr != 0;
262 std::string fn = file_name;
263 if (df.empty()) {
264 if (fn.empty()) {
265 cgv::render::render_component::last_error = "attempt to create texture from empty file name";
266 return false;
267 }
268 }
269 std::vector<data_format> palette_formats;
270 std::vector<data_view> palettes;
271 if (!fn.empty()) {
272 image_reader ir(df, &palette_formats);
273 if (!ir.read_image(fn, dv)) {
274 cgv::render::render_component::last_error = "error reading image file ";
278 return false;
279 }
280 for (unsigned i=0; i<palette_formats.size(); ++i) {
281 palettes.push_back(data_view());
282 if (!ir.read_palette(i, palettes.back())) {
283 cgv::render::render_component::last_error = "error reading palette";
284 return false;
285 }
286 }
287 }
288 if (cube_side < 1)
289 destruct(ctx);
290 size_t w = df.get_width(), h = df.get_height();
291 size_t W = w, H = h;
292 data_format df1(df);
293 if (ensure_power_of_two && (!is_power_of_two(w) || !is_power_of_two(h))) {
294 W = power_of_two_ub(df.get_width());
295 H = power_of_two_ub(df.get_height());
296 df1.set_width(W);
297 df1.set_height(H);
298 }
299 //float ext[2] = { (float)w/W, (float)h/H };
300 data_view dv1(&df1);
301 unsigned entry_size = df.get_entry_size();
302 const unsigned char* src_ptr = dv.get_ptr<unsigned char>();
303 unsigned char* dest_ptr = dv1.get_ptr<unsigned char>();
304 unsigned char* dest_ptr_end = dest_ptr + entry_size * W*H;
305 for (unsigned y = 0; y < h; ++y) {
306 dest_ptr_end -= W * entry_size;
307 memcpy(dest_ptr_end, src_ptr, w*entry_size);
308 if (clear_color_ptr) {
309 for (size_t x = w; x < W; ++x)
310 memcpy(dest_ptr_end + x * entry_size, clear_color_ptr, entry_size);
311 }
312 else
313 std::fill(dest_ptr_end + w * entry_size, dest_ptr_end + W*entry_size, 0);
314 src_ptr += w * entry_size;
315 }
316 if (H > h) {
317 size_t N = (H - h)*W;
318 if (clear_color_ptr) {
319 for (size_t i = 0; i < N; ++i)
320 memcpy(dest_ptr + i * entry_size, clear_color_ptr, entry_size);
321 }
322 else
323 std::fill(dest_ptr, dest_ptr + N*entry_size, 0);
324 }
325 return create(ctx, dv1, level, cube_side, false, &palettes);
326}
327
328
331 const std::string& file_name, int* image_width_ptr, int* image_height_ptr,
332 unsigned char* clear_color_ptr, int level, int cube_side)
333{
334 data_format df;
335 data_view dv;
336 if (!create_from_image(df,dv,ctx,file_name,clear_color_ptr,level,cube_side))
337 return false;
338 if (image_width_ptr)
339 *image_width_ptr = int(df.get_width());
340 if (image_height_ptr)
341 *image_height_ptr = int(df.get_height());
342 return true;
343}
344
345bool texture::deduce_file_names(const std::string& file_names, std::vector<std::string>& deduced_names)
346{
347 if (std::find(file_names.begin(), file_names.end(), '{') != file_names.end()) {
348 std::vector<token> toks;
349 deduced_names.resize(6);
350 tokenizer(file_names).set_ws("").set_sep("{,}").bite_all(toks);
351 int selection = -1;
352 for (unsigned i=0; i<toks.size(); ++i) {
353 if (toks[i] == "{") {
354 if (selection != -1) {
355 std::cerr << "warning: nested {} not allowed in cubemap file names specification " << file_names << std::endl;
356 return false;
357 }
358 selection = 0;
359 }
360 else if (toks[i] == "}") {
361 if (selection == -1) {
362 std::cerr << "warning: } without opening { in cubemap file names specification " << file_names << std::endl;
363 return false;
364 }
365 if (selection != 5) {
366 std::cerr << "warning: no 6 file names specified for creating cubemap from images " << file_names << std::endl;
367 return false;
368 }
369 selection = -1;
370 }
371 else if (toks[i] == ",") {
372 if (selection == -1) {
373 std::cerr << "warning: , arising outside {} in cubemap file names specification " << file_names << std::endl;
374 return false;
375 }
376 ++selection;
377 }
378 else {
379 if (selection == -1) {
380 for (unsigned j=0; j<6; ++j)
381 deduced_names[j] += to_string(toks[i]);
382 }
383 else {
384 if (selection == 6) {
385 std::cerr << "warning: more than 6 files names specified for cubemap creation " << file_names << std::endl;
386 return false;
387 }
388 deduced_names[selection] += to_string(toks[i]);
389 }
390 }
391 }
392 }
393 else {
394 std::string path_prefix = get_path(file_names);
395 if (!path_prefix.empty())
396 path_prefix += '/';
397 void* handle = find_first(file_names);
398 while (handle != 0) {
399 deduced_names.push_back(path_prefix+find_name(handle));
400 handle = find_next(handle);
401 }
402 if (deduced_names.size() != 6) {
403 std::cerr << "warning: not exactly 6 files names specified for cubemap creation " << file_names << std::endl;
404 return false;
405 }
406 }
407 return true;
408}
409
410bool texture::create_from_images(const context& ctx, const std::string& file_names, int level)
411{
412 std::vector<std::string> deduced_names;
413 if (!deduce_file_names(file_names, deduced_names))
414 return false;
415 bool success = true;
416 for (unsigned i=0; success && i<6; ++i)
417 if (!create_from_image(ctx, deduced_names[i],0,0,0,level,i)) {
418 success = false;
419 std::cerr << "could not create cubemap side " << i << " from image " << deduced_names[i] << std::endl;
420 }
421 if (!success)
422 destruct(ctx);
423 return success;
424}
425
427bool 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
428{
429 std::string& last_error = static_cast<const cgv::render::texture_base*>(this)->last_error;
430 if (!is_created()) {
431 last_error = "texture must be created for write_to_file";
432 return false;
433 }
434 frame_buffer fb;
435 if (!fb.create(ctx,int(get_width()), int(get_height()))) {
436 last_error = "could not create frame buffer object for write_to_file";
437 return false;
438 }
439 if (z_or_cube_size != -1) {
440 if (!fb.attach(ctx,*this,z_or_cube_size,0,0)) {
441 last_error = "could not attach texture for write_to_file";
442 return false;
443 }
444 }
445 else {
446 if (!fb.attach(ctx,*this)) {
447 last_error = "could not attach texture for write_to_file";
448 return false;
449 }
450 }
451 bool is_depth = get_standard_component_format() == CF_D;
452 data_format df("uint8[R,G,B]");
453 if (is_depth) {
454 render_buffer rb("[R,G,B]");
455 df = data_format("uint32[D]");
456 rb.create(ctx, int(get_width()), int(get_height()));
457 if (!fb.attach(ctx, rb)) {
458 last_error = "could not attach color buffer for write_to_file";
459 return false;
460 }
461 }
462 if (!fb.is_complete(ctx)) {
463 last_error = "frame buffer object not complete for write_to_file due to\n";
465 return false;
466 }
467 fb.enable(ctx);
468 df.set_width(get_width());
470 data_view dv(&df);
471 ctx.read_frame_buffer(dv, 0, 0, cgv::render::FB_0);
472 fb.disable(ctx);
473
474 if (is_depth) {
476 size_t i, n = get_width()*get_height();
477 for (i = 0; i < n; ++i)
478 stats.update(dv.get_ptr<cgv::type::uint32_type>()[i]);
482 data_view dv2(&df2);
483 for (i = 0; i < n; ++i) {
484 double mapped_value = pow(double(dv.get_ptr<cgv::type::uint32_type>()[i] - min_val) / (max_val - min_val), depth_map_gamma);
485 cgv::type::uint8_type v = cgv::type::uint8_type(255 * mapped_value);
487 }
488 image_writer w(file_name);
489 if (!w.write_image(dv2)) {
490 last_error = "could not write image file ";
491 last_error += file_name;
492 return false;
493 }
494 return true;
495 }
496 image_writer w(file_name);
497 w.multi_set(options);
498 if (!w.write_image(dv)) {
499 last_error = "could not write image file ";
500 last_error += file_name;
501 return false;
502 }
503 return true;
504}
505
508{
509 if(!is_created()) {
510 render_component::last_error = "attempt to create mipmap levels for texture that is not created";
511 return false;
512 }
513 return ctx.texture_create_mipmaps(*this, *this);
514}
515
519{
520 return ctx.texture_generate_mipmaps(*this, get_nr_dimensions());
521}
522
523bool texture::complete_create(const context& ctx, bool created)
524{
525 state_out_of_date = true;
526 ctx_ptr = &ctx;
527 if (created)
528 ensure_state(ctx);
529 return created;
530}
531
532
538bool texture::create_from_buffer(const context& ctx, int x, int y, int width, int height, int level)
539{
540 if (is_created() && level < 1)
541 return replace_from_buffer(ctx, 0, 0, x, y, width, height, level);
542
543 if (level <= 0) {
544 destruct(ctx);
546 set_width(width);
547 set_height(height);
548 }
549 if (level == -1 && !internal_format)
550 find_best_format(ctx);
551 return complete_create(ctx, ctx.texture_create_from_buffer(*this, *this, x, y, level));
552}
553
566bool 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)
567{
568 const data_format& f = *data.get_format();
570
571 if(cube_side > -1) {
572 if(tt == TT_2D)
573 tt = TT_CUBEMAP;
574 } else if(num_array_layers != 0) {
575 if(num_array_layers < 0) {
576 // automatic inference of layers from texture dimensions
577 unsigned n_dims = f.get_nr_dimensions();
578 if(n_dims == 2)
579 tt = TT_1D_ARRAY;
580 if(n_dims == 3)
581 tt = TT_2D_ARRAY;
582 } else {
583 switch(tt) {
584 case TT_1D: tt = TT_1D_ARRAY; break;
585 case TT_2D: tt = TT_2D_ARRAY; break;
586 case TT_3D: tt = TT_2D_ARRAY; break;
587 }
588 }
589 }
590 // 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.
591 if ((tt == TT_1D || tt == TT_2D || tt == TT_3D) && is_created()) {
592 bool replace_allowed = tt == this->tt;
593 for(unsigned i = 0; replace_allowed && i < get_nr_dimensions(); ++i)
594 if(get_resolution(i) != f.get_resolution(i))
595 replace_allowed = false;
596 if (replace_allowed && level < 1) {
597 switch (tt) {
598 case TT_1D : return replace(ctx, 0, data, level, palettes);
599 case TT_2D : return replace(ctx, 0, 0, data, level, palettes);
600 case TT_3D : return replace(ctx, 0, 0, 0, data, level, palettes);
601 }
602 return false;
603 }
604 destruct(ctx);
605 }
606 if (level < 1) {
608 for(unsigned int i = 0; i < get_nr_dimensions(); ++i)
611 static_cast<component_format&>(*this) = *data.get_format();
612 if (level == -1 || !internal_format)
613 find_best_format(ctx, palettes);
614 }
615 return complete_create(ctx, ctx.texture_create(*this, *this, data, level, cube_side, num_array_layers, palettes));
616}
617
621bool texture::replace(const context& ctx, int x, const cgv::data::const_data_view& data, int level, const std::vector<data_view>* palettes)
622{
623 if (!is_created()) {
624 render_component::last_error = "attempt to replace in a not created 1d texture";
625 return false;
626 }
627 if (data.get_format()->get_nr_dimensions() > 1) {
628 render_component::last_error = "cannot replace block in 1d texture with 2d or 3d data block";
629 return false;
630 }
631 return ctx.texture_replace(*this,x,-1,-1,data,level, palettes);
632}
633
637bool texture::replace(const context& ctx, int x, int y, 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 if (data.get_format()->get_nr_dimensions() > 2) {
644 render_component::last_error = "cannot replace block in 2d texture with 3d data block";
645 return false;
646 }
647 return ctx.texture_replace(*this,x,y,-1,data,level, palettes);
648}
649
654bool 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)
655{
656 if (!is_created()) {
657 render_component::last_error = "attempt to replace in a not created 1d texture";
658 return false;
659 }
660 bool res = ctx.texture_replace(*this,x,y,z_or_cube_side,data,level, palettes);
661 if (res && level == -1 && !have_mipmaps)
662 have_mipmaps = true;
663 return res;
664}
665
667bool texture::replace_from_buffer(const context& ctx, int x, int y, int x_buffer,
668 int y_buffer, int width, int height, int level)
669{
670 if (!is_created()) {
671 render_component::last_error = "attempt to replace in a not created 1d texture";
672 return false;
673 }
674 if (get_nr_dimensions() != 2) {
675 render_component::last_error = "attempt to replace a 2d block in a not 2d texture";
676 return false;
677 }
678 return ctx.texture_replace_from_buffer(*this,x,y,-1,x_buffer,y_buffer,width,height,level);
679}
680
682bool texture::replace_from_buffer(const context& ctx, int x, int y, int z_or_cube_side, int x_buffer,
683 int y_buffer, int width, int height, int level)
684{
685 if (!is_created()) {
686 render_component::last_error = "attempt to replace in a not created texture";
687 return false;
688 }
689 if (tt != TT_3D && tt != TT_CUBEMAP) {
690 render_component::last_error = "replacing a 2d block in a slice / cube side of a not 3d texture / cubemap";
691 return false;
692 }
693 return ctx.texture_replace_from_buffer(*this,x,y,z_or_cube_side,x_buffer,y_buffer,width,height,level);
694}
695
697bool texture::replace_from_image(const context& ctx, const std::string& file_name, int x, int y, int z_or_cube_side, int level)
698{
699 data_format df;
700 data_view dv;
701 return replace_from_image(df,dv,ctx,file_name,x,y,z_or_cube_side,level);
702}
703
707 const std::string& file_name, int x, int y, int z_or_cube_side,
708 int level)
709{
710 std::string fn = file_name;
711 if (fn.empty()) {
712 return false;
713 }
714 std::vector<data_format> palette_formats;
715 image_reader ir(df, &palette_formats);
716 if (!ir.read_image(fn, dv))
717 return false;
718 std::vector<data_view> palettes;
719 for (unsigned i=0; i<palette_formats.size(); ++i) {
720 palettes.push_back(data_view());
721 if (!ir.read_palette(i, palettes.back()))
722 return false;
723 }
724 replace(ctx, x, y, z_or_cube_side, dv, level, &palettes);
725 return true;
726}
727
728
731{
732 state_out_of_date = true;
733 internal_format = 0;
734 if(handle != 0)
735 return ctx.texture_destruct(*this);
736 return true;
737}
738
740
745bool texture::enable(const context& ctx, int _tex_unit)
746{
747 if (!handle) {
748 render_component::last_error = "attempt to enable texture that is not created";
749 return false;
750 }
751 ensure_state(ctx);
752 tex_unit = _tex_unit;
753 return ctx.texture_enable(*this, tex_unit, get_nr_dimensions());
754}
756bool texture::disable(const context& ctx)
757{
758 return ctx.texture_disable(*this, tex_unit, get_nr_dimensions());
759}
760
761bool texture::bind_as_image(const context& ctx, int _tex_unit, int level, bool bind_array, int layer, AccessType access) {
762 if(!handle) {
763 render_component::last_error = "attempt to bind texture that is not created";
764 return false;
765 }
766 ensure_state(ctx);
767 tex_unit = _tex_unit;
768 //binding_index = ...
769
770 return ctx.texture_bind_as_image(*this, tex_unit, level, bind_array, layer, access);
771}
772
775{
776 return have_mipmaps;
777}
780{
781 return user_data != 0;
782}
785{
786 return tex_unit;
787}
788
789
791 }
792}
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
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
A vector with zero based index.
Definition fvec.h:26
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:621
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:2046
const context * ctx_ptr
keep pointer to my context
Definition context.h:307
std::string last_error
a string that contains the last error
Definition context.h:309
base interface for a texture
Definition context.h:332
bool generate_mipmaps(const context &ctx)
generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU
Definition texture.cxx:518
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
Definition texture.cxx:138
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:144
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:128
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:208
~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:172
int get_tex_unit() const
return the currently used texture unit and -1 for current
Definition texture.cxx:784
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:330
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:538
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:345
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:667
void set_priority(float _priority)
set priority with which texture is kept in GPU memory
Definition texture.cxx:149
float get_priority() const
return the priority with which texture is kept in GPU memory
Definition texture.cxx:155
void set_fixed_sample_locations(bool use)
set whether multi sampling uses fixed sample locations
Definition texture.cxx:230
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:697
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:225
bool disable(const context &ctx)
disable texture and restore state from before last enable call
Definition texture.cxx:756
void ensure_state(const context &ctx) const
ensure the the texture state is synchronized with the GPU settings
Definition texture.cxx:198
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:745
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:730
std::string last_error
a string that contains the last error
Definition context.h:309
CompareFunction get_compare_function() const
get the texture compare function
Definition texture.cxx:179
bool get_compare_mode() const
get the texture compare mode and function
Definition texture.cxx:166
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:427
bool mipmaps_created() const
check whether mipmaps have been created
Definition texture.cxx:774
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:621
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:190
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:779
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:507
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:120
void set_compare_mode(bool use_compare_function)
set the texture compare mode and function
Definition texture.cxx:160
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:410
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:761
float get_anisotropy() const
return the currently set anisotropy
Definition texture.cxx:133
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: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
@ 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