cgv
Loading...
Searching...
No Matches
gl_tools.h
1#pragma once
2
3#include <string>
4#include <cgv/data/data_view.h>
5#include <cgv/render/context.h>
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace render {
11 class context;
12 class shader_program;
13 class texture;
14 enum TextureSampling;
15
16 namespace gl {
17
18// declare some colors by name
19extern CGV_API float black[4], white[4], gray[4], green[4], brown[4], dark_red[4], cyan[4], yellow[4], red[4], blue[4];
20
22extern CGV_API unsigned map_to_gl(cgv::type::info::TypeId ti);
23
25extern CGV_API unsigned map_to_gl(cgv::data::ComponentFormat cf, cgv::data::ComponentIntegerInterpretation cii = cgv::data::CII_DEFAULT);
26
28extern CGV_API unsigned map_to_gl(MaterialSide ms);
29
31extern CGV_API unsigned get_gl_cube_map_target(unsigned side);
32
34extern CGV_API bool generate_mipmaps(unsigned int dim, bool is_cubemap, bool is_array = false, std::string* last_error = 0);
35
37extern CGV_API unsigned find_best_texture_format(const cgv::data::component_format& cf, cgv::data::component_format* best_cf = 0, const std::vector<cgv::data::data_view>* palettes = 0);
38
40extern CGV_API bool load_texture(const cgv::data::const_data_view& data, unsigned gl_tex_format, unsigned level = -1, unsigned cube_side = -1, int num_array_layers = 0, const std::vector<cgv::data::data_view>* palettes = 0);
41
43extern CGV_API unsigned int create_texture(const cgv::data::const_data_view& dv, bool mipmap = true, const std::vector<cgv::data::data_view>* palettes = 0, unsigned tex_id = -1);
44
46extern CGV_API unsigned int create_texture(const cgv::data::const_data_view& dv, unsigned level, unsigned cube_side = -1, const std::vector<cgv::data::data_view>* palettes = 0, unsigned tex_id = -1);
47
49
55extern CGV_API bool replace_texture(const cgv::data::const_data_view& data, int level = 0, int x = 0, int y = 0, int z = -1, const std::vector<cgv::data::data_view>* palettes = 0);
56
61extern CGV_API unsigned int read_image_to_texture(const std::string& file_name, bool mipmaps = true, double* aspect_ptr = 0, bool* has_alpha_ptr = 0);
62
64extern CGV_API bool read_image_to_textures(const std::string& file_name, std::vector<unsigned>& tex_ids, std::vector<float>& durations, bool mipmaps = true, double* aspect_ptr = 0, bool* has_alpha_ptr = 0);
65
66
68extern CGV_API void gl_1D_texture_to_screen(bool vary_along_x = true, float xmin = -1.0f, float ymin = -1.0f, float xmax = 1.0f, float ymax = 1.0f);
69
71
75extern CGV_API bool cover_screen(context& ctx, shader_program* prog_ptr = 0, bool flip_tex_v_coord = false, float xmin = -1.0f, float ymin = -1.0f, float xmax = 1.0f, float ymax = 1.0f,
76 float umin = 0.0f, float vmin = 0.0f, float umax = 1.0f, float vmax = 1.0f);
77
78DEPRECATED("deprecated, use cover_screen instead.") extern CGV_API void gl_texture_to_screen(float xmin = -1.0f, float ymin = -1.0f, float xmax = 1.0f, float ymax = 1.0f,
79 float umin = 0.0f, float vmin = 0.0f, float umax = 1.0f, float vmax = 1.0f);
80
82DEPRECATED("deprecated, use cgv::render::context based light management.") extern CGV_API void set_lighting_parameters(context& ctx, shader_program& prog);
83
85DEPRECATED("deprecated, use cgv::render::context::ref_surface_shader_prog() instead.") extern CGV_API shader_program& ref_textured_material_prog(context& ctx);
86
88DEPRECATED("deprecated, use automatic cgv::render::context based shader_program stack.") extern CGV_API void push_textured_material_prog(shader_program& prog);
89
91DEPRECATED("deprecated, use automatic cgv::render::context based shader_program stack.") extern CGV_API void pop_textured_material_prog();
92
94
100extern CGV_API bool complete_program_form_render_to_texture3D(cgv::render::context& ctx, cgv::render::shader_program& prog, std::string* error_message = 0);
101
103
108extern CGV_API bool render_to_texture3D(context& ctx, shader_program& prog, TextureSampling texture_sampling, texture& target_tex, texture* target_tex2 = 0, texture* target_tex3 = 0, texture* target_tex4 = 0);
109
112 PI_UNIFORM,
113 PI_UNIFORM_BLOCK,
114 PI_PROGRAM_INPUT,
115 PI_PROGRAM_OUTPUT,
116 PI_VERTEX_SUBROUTINE, PI_TESS_CONTROL_SUBROUTINE, PI_TESS_EVALUATION_SUBROUTINE, PI_GEOMETRY_SUBROUTINE, PI_FRAGMENT_SUBROUTINE, PI_COMPUTE_SUBROUTINE,
117 PI_VERTEX_SUBROUTINE_UNIFORM, PI_TESS_CONTROL_SUBROUTINE_UNIFORM, PI_TESS_EVALUATION_SUBROUTINE_UNIFORM, PI_GEOMETRY_SUBROUTINE_UNIFORM, PI_FRAGMENT_SUBROUTINE_UNIFORM, PI_COMPUTE_SUBROUTINE_UNIFORM,
118 PI_TRANSFORM_FEEDBACK_VARYING,
119 PI_BUFFER_VARIABLE,
120 PI_SHADER_STORAGE_BLOCK
121};
123extern CGV_API void print_program_ressources(shader_program& prog, const std::string& interface_name, ProgramInterface prog_intf);
124
125
126 }
127 }
128}
129
130#include <cgv/config/lib_end.h>
the component format inherits the information of a packing_info and adds information on the component...
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 shader program combines several shader code fragments to a complete definition of the shading pipel...
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
ComponentIntegerInterpretation
define different interpretations of integer components
void push_textured_material_prog(shader_program &prog)
push a shader program onto the textured material stack
Definition gl_tools.cxx:116
void gl_texture_to_screen(float xmin, float ymin, float xmax, float ymax, float umin, float vmin, float umax, float vmax)
cover the current viewport with a textured quad
bool load_texture(const cgv::data::const_data_view &data, unsigned gl_tex_format, unsigned level, unsigned cube_side, int num_array_layers, const std::vector< data_view > *palettes)
load data to a texture with the glTexImage commands and generate mipmaps if the level parameter is -1...
unsigned int create_texture(const cgv::data::const_data_view &dv, bool mipmap, const std::vector< data_view > *palettes, unsigned tex_id)
create a texture from the given data view creating a mipmap pyramid
void set_lighting_parameters(context &ctx, shader_program &prog)
set the program variables needed by the lighting.glsl shader
Definition gl_tools.cxx:96
bool read_image_to_textures(const std::string &file_name, std::vector< unsigned > &tex_ids, std::vector< float > &durations, bool mipmaps, double *aspect_ptr, bool *has_alpha_ptr)
read several images from one image file that can contain an animation
Definition gl_tools.cxx:49
bool complete_program_form_render_to_texture3D(cgv::render::context &ctx, cgv::render::shader_program &prog, std::string *error_message)
complete the given shader program that is assumed to have a working fragment shader.
void print_program_ressources(shader_program &prog, const std::string &interface_name, ProgramInterface prog_intf)
print program resources for given interface
Definition gl_tools.cxx:148
bool replace_texture(const cgv::data::const_data_view &data, int level, int x, int y, int z, const std::vector< cgv::data::data_view > *palettes)
replace part or complete data of currently bound texture with the data in the given data view
unsigned int read_image_to_texture(const std::string &file_name, bool mipmaps, double *aspect_ptr, bool *has_alpha_ptr)
read the given image file into a texture and return the texture id or -1 in case of failure.
Definition gl_tools.cxx:27
bool cover_screen(context &ctx, shader_program *prog_ptr, bool flip_tex_v_coord, float xmin, float ymin, float xmax, float ymax, float umin, float vmin, float umax, float vmax)
cover the current viewport with a textured quad using the textured default shader program or the one ...
void gl_1D_texture_to_screen(bool vary_along_x, float xmin, float ymin, float xmax, float ymax)
cover the current viewport or a rectangle with it with a quad textured by a 1D texture
shader_program & ref_textured_material_prog(context &ctx)
return a reference to the singleton textured material shader program, which is constructed on demand ...
Definition gl_tools.cxx:127
ProgramInterface
different program interfaces
Definition gl_tools.h:111
void pop_textured_material_prog()
pop a shader program from the textured material stack
Definition gl_tools.cxx:122
bool generate_mipmaps(unsigned int dim, bool is_cubemap, bool is_array, std::string *last_error)
generate mipmaps for the currently bound texture, which has the given texture dimension; optionally p...
unsigned find_best_texture_format(const cgv::data::component_format &_cf, cgv::data::component_format *best_cf, const std::vector< data_view > *palettes)
map the given component format to the best matching available gl component format
unsigned get_gl_cube_map_target(unsigned side)
return one of the six cube map sides gl enums
bool render_to_texture3D(context &ctx, shader_program &prog, TextureSampling texture_sampling, texture &target_tex, texture *target_tex2, texture *target_tex3, texture *target_tex4)
Render to the given target 3D texture with the given shader program that must be completed with the f...
MaterialSide
different sides of a material
Definition context.h:128
TextureSampling
different sampling strategies for rendering to textures that steer the computation of the tex_coord i...
Definition context.h:247
TypeId
ids for the different types and type constructs
Definition type_id.h:12
the cgv namespace
Definition print.h:11