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)
17 if(include_binding_points) {
19 options.define_macro_if_not_default(
"HEAD_POINTERS_BINDING_POINT", head_pointers_binding_point, 0);
20 options.define_macro_if_not_default(
"NODES_BINDING_POINT", nodes_binding_point, 1);
25 update_shader_program_options(options,
true);
27 a_buffer::a_buffer(
unsigned _fragments_per_pixel,
unsigned _nodes_per_pixel,
int _depth_tex_unit,
28 int _node_counter_binding_point,
int _head_pointers_binding_point,
int _nodes_binding_point)
38 head_pointers_binding_point = _head_pointers_binding_point;
39 nodes_binding_point = _nodes_binding_point;
41 init_frame_called =
false;
45 if (!clear_ssbo_prog.
build_files(ctx,
"a_buffer_clear",
true))
47 update_shader_program_options(prog_options,
false);
48 if (!a_buffer_prog.
build_program(ctx,
"a_buffer.glpr", prog_options,
true))
50 last_prog_options = prog_options;
74 const GLuint zero = 0;
78 head_pointer_buffer.
bind(ctx, 0);
80 clear_ssbo_prog.
enable(ctx);
81 clear_ssbo_prog.
set_uniform(ctx,
"size", buffer_size);
82 clear_ssbo_prog.
set_uniform(ctx,
"clear_value", -1);
83 glDispatchCompute(GLuint(ceil(buffer_size / 4)), 1, 1);
84 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
86 head_pointer_buffer.
unbind(ctx, 0);
89 update_shader_program_options(prog_options,
false);
90 if (prog_options != last_prog_options) {
93 if (a_buffer_prog.
build_program(ctx,
"a_buffer.glpr", prog_options,
true)) {
94 last_prog_options = prog_options;
95 std::cout <<
"a_buffer: rebuilt shader program" << std::endl;
98 init_frame_called =
true;
103 if (init_frame_called) {
105 init_frame_called =
false;
109 std::cerr <<
"ERROR in a_buffer::enable(): uniform ivec2 viewport_dims not found in program." << std::endl;
113 std::cerr <<
"ERROR in a_buffer::enable(): uniform int nodes_per_pixel not found in program." << std::endl;
120 if (!prog.
set_uniform(ctx,
"depth_tex", tex_unit)) {
121 std::cerr <<
"ERROR in a_buffer::enable(): uniform sampler2D depth_tex not found in program." << std::endl;
126 head_pointer_buffer.
bind(ctx, head_pointers_binding_point);
127 node_buffer.
bind(ctx, nodes_binding_point);
138 head_pointer_buffer.
unbind(ctx, head_pointers_binding_point);
139 node_buffer.
unbind(ctx, nodes_binding_point);
154 head_pointer_buffer.
bind(ctx, 0);
155 node_buffer.
bind(ctx, 1);
157 a_buffer_prog.
enable(ctx);
160 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
163 head_pointer_buffer.
unbind(ctx, 0);
164 node_buffer.
unbind(ctx, 1);
unsigned nodes_per_pixel
to be reserved number of fragment nodes per pixel (changes are applied when in init_frame() function)
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
void destruct(context &ctx)
destruct all render objects
bool init(context &ctx)
construct internally used programs
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...
void bind(context &ctx, VertexBufferType type=VBT_UNDEF) const
Bind buffer to appropriate target.
bool create_or_resize(const context &ctx, size_t size_in_bytes)
Convenience wrapper to either create() or resize() the buffer.
void unbind(context &ctx, VertexBufferType type=VBT_UNDEF) const
Unbind buffer from the appropriate target.
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 destruct(const context &ctx)
destruct the render buffer
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_...
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors