void application_window::display(const gl::render_context_ptr& context) { using namespace scm::gl; using namespace scm::math; { // image rendering pass context_program_guard cpg(context); context_state_objects_guard csg(context); context_texture_units_guard ctg(context); context_uniform_buffer_guard cug(context); context_atomic_counter_buffer_guard acg(context); context_image_units_guard cig(context); _atomic_test_prog->uniform("screen_res", vec2f(_viewport_size)); context->bind_atomic_counter_buffer(_atomic_counter, 0); context->bind_uniform_buffer(_camera_block->block().block_buffer(), 0); context->bind_program(_atomic_test_prog); context->set_rasterizer_state(_rstate_cback); context->set_depth_stencil_state(_dstate_less); context->set_blend_state(_bstate_off); _model_geometry->draw_raw(context, geometry::MODE_SOLID); } }
void coordinate_cross::draw_overlay( const gl::render_context_ptr& context, const math::mat4f& proj_matrix, const math::mat4f& view_matrix, const float line_width) { using namespace scm; using namespace scm::gl; using namespace scm::math; context_state_objects_guard csg(context); context_program_guard cpg(context); context_vertex_input_guard vig(context); _coord_program->uniform("in_mvp", proj_matrix * view_matrix); context->set_depth_stencil_state(_dstate_overlay); context->set_blend_state(_no_blend); context->set_rasterizer_state(_raster_no_cull, line_width); context->bind_program(_coord_program); context->bind_vertex_array(_vertex_array); context->apply(); context->draw_arrays(_prim_topology, 0, _vertex_count); }
void texture_output::draw_texture_2d_uint(const gl::render_context_ptr& context, const gl::texture_2d_ptr& tex, const math::vec4f& scale, const math::vec2ui& position, const math::vec2ui& extend) const { using namespace scm::gl; using namespace scm::math; context_state_objects_guard csg(context); context_texture_units_guard tug(context); context_framebuffer_guard fbg(context); vec2ui tile_size = vec2ui(0); float aspect = static_cast<float>(tex->descriptor()._size.x) / static_cast<float>(tex->descriptor()._size.y); tile_size.x = extend.x; tile_size.y = static_cast<unsigned>(tile_size.x / aspect); if (tile_size.y > extend.y) { tile_size.y = extend.y; tile_size.x = static_cast<unsigned>(tile_size.y * aspect); } context->set_depth_stencil_state(_dstate_no_z_write); context->set_blend_state(_bstate_no_blend); context->set_rasterizer_state(_rstate_cull_back); context->set_viewport(viewport(position, tile_size)); if (channel_count(tex->descriptor()._format) > 1) { _fs_program_color_uint->uniform("in_scale", scale); context->bind_program(_fs_program_color_uint); } else { _fs_program_gray_uint->uniform("in_scale", scale); context->bind_program(_fs_program_gray_uint); } context->bind_texture(tex, _filter_nearest, 0/*texture unit 0*/); _quad_geom->draw(context, geometry::MODE_SOLID); }
void volume_renderer::draw(const gl::render_context_ptr& context, const volume_data_ptr& vdata, const vr_mode mode) const { using namespace scm; using namespace scm::gl; using namespace scm::math; switch (mode) { case volume_raw: _program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "volume_color_lookup", "raw_lookup"); break; case volume_color_map: _program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "volume_color_lookup", "raw_color_map_lookup"); break; } _program->uniform("volume_lod", vdata->selected_lod()); context_state_objects_guard csg(context); context_texture_units_guard tug(context); context_uniform_buffer_guard ubg(context); context->reset_state_objects(); context->set_depth_stencil_state(_dstate); context->set_blend_state(_bstate); context->set_rasterizer_state(_rstate); context->bind_uniform_buffer(_camera_block->block().block_buffer(), 0); context->bind_uniform_buffer(vdata->volume_block().block_buffer(), 1); context->bind_program(_program); context->reset_texture_units(); #if SCM_TEXT_NV_BINDLESS_TEXTURES != 1 context->bind_texture(vdata->volume_raw(), _sstate_lin_mip, 0); context->bind_texture(vdata->color_alpha_map(), _sstate_lin, 2); #else context->bind_texture(vdata->texture_handles(), _sstate_nearest, 4); #endif SCM_TEXT_NV_BINDLESS_TEXTURES != 1 vdata->bbox_geometry()->draw(context, geometry::MODE_SOLID); }
void height_field_tessellator::draw(const gl::render_context_ptr& context, const height_field_data_ptr& hf_data, bool super_sample, const mesh_mode hf_mesh_mode, const draw_mode hf_draw_mode) const { using namespace scm::gl; using namespace scm::math; static float tessellation_factor = 1.2f; static float tessellation_inc = 0.01f; context_state_objects_guard csg(context); context_program_guard cpg(context); context_uniform_buffer_guard ubg(context); context_texture_units_guard tug(context); tessellation_factor += tessellation_inc; if (tessellation_factor >= 32.0) tessellation_inc = -tessellation_inc; if (tessellation_factor < 1.1) tessellation_inc = -tessellation_inc; context->bind_uniform_buffer(_main_camera_block->block().block_buffer(), 0); context->bind_texture(hf_data->height_map(), _sstate_linear_mip, 0); context->bind_texture(hf_data->height_map(), _sstate_nearest, 1); context->bind_texture(hf_data->density_map(), _sstate_nearest, 2); context->bind_texture(hf_data->color_map(), _sstate_linear, 3); context->set_depth_stencil_state(_dstate_less); context->set_blend_state(_bstate_no_blend); //context->set_blend_state(_bstate_omsa); if (hf_draw_mode == MODE_SOLID) { context->set_rasterizer_state(super_sample ? _rstate_ms_solid_ss : _rstate_ms_solid); } else if (hf_draw_mode == MODE_WIRE_FRAME) { context->set_rasterizer_state(_rstate_ms_wire); } if (hf_mesh_mode == MODE_QUAD_PATCHES) { _hf_quad_tessellation_program->uniform("tessellation_factor", 5.0f);//tessellation_factor); _hf_quad_tessellation_program->uniform("model_matrix", hf_data->transform()); _hf_quad_tessellation_program->uniform("height_scale", hf_data->extends().z); _hf_quad_tessellation_program->uniform("pixel_tolerance", _pixel_tolerance); _hf_quad_tessellation_program->uniform("screen_size", vec2f(1920.0f, 1200.0f)); context->bind_program(_hf_quad_tessellation_program); hf_data->patch_mesh()->draw(context, patch_grid_mesh::MODE_QUAD_PATCHES); } else if (hf_mesh_mode == MODE_TRIANGLE_PATCHES) { _hf_triangle_tessellation_program->uniform("tessellation_factor", 5.0f);//tessellation_factor); _hf_triangle_tessellation_program->uniform("model_matrix", hf_data->transform()); _hf_triangle_tessellation_program->uniform("height_scale", hf_data->extends().z); _hf_triangle_tessellation_program->uniform("pixel_tolerance", _pixel_tolerance); _hf_triangle_tessellation_program->uniform("screen_size", vec2f(1920.0f, 1200.0f)); context->bind_texture(hf_data->triangle_edge_density_buffer(), _sstate_nearest, 4); context->bind_program(_hf_triangle_tessellation_program); hf_data->patch_mesh()->draw(context, patch_grid_mesh::MODE_TRIANGLE_PATCHES); } else { err() << log::warning << "height_field_tessellator::draw(): unknown mesh mode." << log::end; } }