3#include <cgv/media/image/image_reader.h>
5#include <cgv/render/context.h>
6#include <cgv/render/shader_program.h>
7#include <cgv_gl/gl/gl.h>
9#ifndef GL_CLAMP_TO_EDGE
10#define GL_CLAMP_TO_EDGE 0x812F
22 static unsigned material_side_mapping[] = { GL_FALSE, GL_FRONT, GL_BACK, GL_FRONT_AND_BACK };
23 return material_side_mapping[ms];
27unsigned int read_image_to_texture(
const std::string& file_name,
bool mipmaps,
double* aspect_ptr,
bool* has_alpha_ptr)
29 std::vector<data_format> palette_formats;
30 std::vector<data_view> palettes;
42 *has_alpha_ptr = palette_formats[0].get_component_index(
"A") != (
unsigned int)-1;
49bool 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)
51 std::vector<data_format> palette_formats;
52 std::vector<data_view> palettes;
57 if (!ir.
open(file_name)) {
61 palettes.resize(palette_formats.size());
66 glGenTextures(nr,&tex_ids.front());
69 for (
unsigned i=0; i<nr; ++i) {
71 for (
unsigned j=0; j<palette_formats.size(); ++j) {
76 if (durations.back() == 0)
77 durations.back() = 0.04f;
88 *has_alpha_ptr = palette_formats[0].get_component_index(
"A") != (
unsigned int)-1;
99 glGetIntegerv(GL_LIGHT_MODEL_LOCAL_VIEWER, &lv);
100 prog.
set_uniform(ctx,
"local_viewer", (
bool)(lv != 0));
103 for (
unsigned i=0; i<n; ++i)
104 glGetIntegerv(GL_LIGHT0+i, &enabled(i));
109std::vector<shader_program*>& ref_shader_prog_stack()
111 static std::vector<shader_program*> sps;
118 ref_shader_prog_stack().push_back(&prog);
124 ref_shader_prog_stack().pop_back();
130 if (!ref_shader_prog_stack().empty())
131 return *ref_shader_prog_stack().back();
132 std::cerr <<
"call to deprecated function ref_textured_material_prog()" << std::endl;
136static GLenum interface_ids[] = {
141 GL_VERTEX_SUBROUTINE, GL_TESS_CONTROL_SUBROUTINE, GL_TESS_EVALUATION_SUBROUTINE, GL_GEOMETRY_SUBROUTINE, GL_FRAGMENT_SUBROUTINE, GL_COMPUTE_SUBROUTINE,
142 GL_VERTEX_SUBROUTINE_UNIFORM, GL_TESS_CONTROL_SUBROUTINE_UNIFORM, GL_TESS_EVALUATION_SUBROUTINE_UNIFORM, GL_GEOMETRY_SUBROUTINE_UNIFORM, GL_FRAGMENT_SUBROUTINE_UNIFORM, GL_COMPUTE_SUBROUTINE_UNIFORM,
143 GL_TRANSFORM_FEEDBACK_VARYING,
145 GL_SHADER_STORAGE_BLOCK
153 GLenum interface_id = interface_ids[prog_intf];
154 glGetProgramInterfaceiv(prog_id, interface_id, GL_ACTIVE_RESOURCES, &nr);
157 for (GLuint i = 0; i < GLuint(nr); ++i) {
160 glGetProgramResourceName(prog_id, interface_id, i, 512, &length, name);
161 std::cout << interface_name <<
"(" << i <<
")=" << name << std::endl;
the data view gives access to a data array of one, two, three or four dimensions.
base class for all drawables, which is independent of the used rendering API.
virtual unsigned get_max_nr_enabled_light_sources() const
return maximum number of light sources, that can be enabled in parallel
void put_id(T &id) const
cast the refence to rendering api specific representation of component id to the specified type
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool set_uniform_array(const context &ctx, const std::string &name, const T &array)
set uniform array from array array where number elements can be derived from array through array_desc...
namespace for data management components
void push_textured_material_prog(shader_program &prog)
push a shader program onto the textured material stack
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
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
void print_program_ressources(shader_program &prog, const std::string &interface_name, ProgramInterface prog_intf)
print program resources for given interface
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.
shader_program & ref_textured_material_prog(context &ctx)
return a reference to the singleton textured material shader program, which is constructed on demand ...
ProgramInterface
different program interfaces
void pop_textured_material_prog()
pop a shader program from the textured material stack
MaterialSide
different sides of a material