6 void a_buffer::ensure_buffers(
context& ctx)
8 unsigned num_pixels = ctx.get_width() * ctx.get_height();
11 head_pointer_buffer.create_or_resize(ctx, num_pixels *
sizeof(GLuint));
12 node_buffer.create_or_resize(ctx,
nodes_per_pixel * 3 * num_pixels *
sizeof(GLuint));
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;
57 clear_ssbo_prog.destruct(ctx);
58 a_buffer_prog.destruct(ctx);
61 head_pointer_buffer.destruct(ctx);
62 node_buffer.destruct(ctx);
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);
87 clear_ssbo_prog.disable(ctx);
88 head_pointer_buffer.unbind(ctx, 0);
91 update_shader_program_options(prog_options,
false);
92 if (prog_options != last_prog_options) {
93 if (a_buffer_prog.is_created())
94 a_buffer_prog.destruct(ctx);
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);
168 a_buffer_prog.disable(ctx);
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
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 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,...
namespace for api independent GPU programming
this header is dependency free
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors