6 void a_buffer::ensure_buffers(context& ctx)
8 unsigned num_pixels = ctx.get_width() * ctx.get_height();
14 void a_buffer::update_shader_program_options(shader_compile_options& options,
bool include_binding_points)
18 options.define_macro_if_not_default(
"Z_FIGHT_REMOVAL",
z_fight_removal, 0);
19 if(include_binding_points) {
21 options.define_macro_if_not_default(
"HEAD_POINTERS_BINDING_POINT", head_pointers_binding_point, 0);
22 options.define_macro_if_not_default(
"NODES_BINDING_POINT", nodes_binding_point, 1);
27 update_shader_program_options(options,
true);
29 a_buffer::a_buffer(
unsigned _fragments_per_pixel,
unsigned _nodes_per_pixel,
int _depth_tex_unit,
30 int _node_counter_binding_point,
int _head_pointers_binding_point,
int _nodes_binding_point)
40 head_pointers_binding_point = _head_pointers_binding_point;
41 nodes_binding_point = _nodes_binding_point;
43 init_frame_called =
false;
47 if (!clear_ssbo_prog.
build_files(ctx,
"a_buffer_clear",
true))
49 update_shader_program_options(prog_options,
false);
50 if (!a_buffer_prog.
build_program(ctx,
"a_buffer.glpr", prog_options,
true))
52 last_prog_options = prog_options;
76 const GLuint zero = 0;
80 head_pointer_buffer.
bind(ctx, 0);
82 clear_ssbo_prog.
enable(ctx);
83 clear_ssbo_prog.
set_uniform(ctx,
"size", buffer_size);
84 clear_ssbo_prog.
set_uniform(ctx,
"clear_value", -1);
85 glDispatchCompute(GLuint(ceil(buffer_size / 4)), 1, 1);
86 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
88 head_pointer_buffer.
unbind(ctx, 0);
91 update_shader_program_options(prog_options,
false);
92 if (prog_options != last_prog_options) {
95 if (a_buffer_prog.
build_program(ctx,
"a_buffer.glpr", prog_options,
true)) {
96 last_prog_options = prog_options;
97 std::cout <<
"a_buffer: rebuilt shader program" << std::endl;
100 init_frame_called =
true;
105 if (init_frame_called) {
107 init_frame_called =
false;
111 std::cerr <<
"ERROR in a_buffer::enable(): uniform ivec2 viewport_dims not found in program." << std::endl;
115 std::cerr <<
"ERROR in a_buffer::enable(): uniform int nodes_per_pixel not found in program." << std::endl;
122 if (!prog.
set_uniform(ctx,
"depth_tex", tex_unit)) {
123 std::cerr <<
"ERROR in a_buffer::enable(): uniform sampler2D depth_tex not found in program." << std::endl;
128 head_pointer_buffer.
bind(ctx, head_pointers_binding_point);
129 node_buffer.
bind(ctx, nodes_binding_point);
140 head_pointer_buffer.
unbind(ctx, head_pointers_binding_point);
141 node_buffer.
unbind(ctx, nodes_binding_point);
156 head_pointer_buffer.
bind(ctx, 0);
157 node_buffer.
bind(ctx, 1);
159 a_buffer_prog.
enable(ctx);
167 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
170 head_pointer_buffer.
unbind(ctx, 0);
171 node_buffer.
unbind(ctx, 1);
float z_fight_removal_exp
set thickness of fragments to 10^z_fight_removal_exp where this is measured in scaling of depth buffe...
unsigned nodes_per_pixel
to be reserved number of fragment nodes per pixel (changes are applied when in init_frame() function)
int z_fight_removal
whether to use volumetric blending of thickened fragments
unsigned fragments_per_pixel
to be handled fragments per pixel (changes are applied when in init_frame() function)
a_buffer(unsigned _fragments_per_pixel=32, unsigned _nodes_per_pixel=64, int _depth_tex_unit=0, int _node_counter_binding_point=0, int _head_pointers_binding_point=0, int _nodes_binding_point=1)
construct and configure
bool pre_multiply_opacity
whether to assume that fragment color is already multiplied with opacity
void destruct(context &ctx)
destruct all render objects
bool init(context &ctx)
construct internally used programs
unsigned z_fight_window_width
size of disambiguation windows
texture depth_tex
Depth texture used to emulate depth buffer.
bool enable(context &ctx, shader_program &prog, int tex_unit=-1)
Enable writing fragments to a_buffer with provided program.
void disable(context &ctx, size_t *out_node_count=nullptr)
finish writing fragments to a_buffer and return current number of nodes in node buffer
cgv::render::vertex_buffer node_counter_buffer
Buffers used to store per pixel frament lists.
int node_counter_binding_point
Buffer binding point indices.
void init_frame(context &ctx)
ensure that a_buffer size corresponds to context size
int depth_tex_unit
Default texture unit used for depth texture.
void finish_frame(context &ctx)
per fragment sort nodes and blend over current framebuffer
base class for all drawables, which is independent of the used rendering API.
void set_blend_func_back_to_front()
set the default blend function for back to front blending (source = BF_SRC_ALPHA, destination = BF_ON...
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
void pop_blend_state()
pop the top of the current culling state from the stack
virtual unsigned int get_width() const =0
return the width of the window
virtual unsigned int get_height() const =0
return the height of the window
virtual void enable_blending()
enable blending
virtual bool is_created() const
return whether component has been created
Stores preprocessor options used for conditionally compiling shader programs.
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
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,...
void destruct(const context &ctx)
destruct shader program
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false)
successively calls create, attach_program and link.
bool build_files(const context &ctx, const std::string &base_name, bool show_error=false)
successively calls create, attach_files and link.
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
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.
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.
bool disable(const context &ctx)
disable texture and restore state from before last enable call
bool enable(const context &ctx, int tex_unit=-1)
enable this texture in the given texture unit, -1 corresponds to the current unit.
bool destruct(const context &ctx)
destruct the texture and free texture memory and handle
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...
bool create_or_resize(const context &ctx, size_t size_in_bytes)
Convenience wrapper to either create() or resize() the buffer.
bool copy(const context &ctx, size_t src_offset_in_bytes, size_t size_in_bytes, vertex_buffer &dst, size_t dst_offset_in_bytes) const
Copy bytes between different vertex_buffer instances.
void unbind(const context &ctx, VertexBufferType type=VBT_UNDEF) const
Unbind buffer from the appropriate target.
void destruct(const context &ctx)
destruct the render buffer
void bind(const context &ctx, VertexBufferType type=VBT_UNDEF) const
Bind buffer to appropriate target.
bool replace(const context &ctx, size_t buffer_offset_in_bytes, const T *array_ptr, size_t nr_elements)
replace part (starting at byte offset buffer_offset_in_bytes) or whole vertex buffer content from nr_...
this header is dependency free
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors