Beispiel #1
0
sge::cegui::impl::batch::batch(
	sge::renderer::device::core &_renderer,
	sge::renderer::vertex::declaration const &_vertex_declaration,
	sge::renderer::texture::planar &_texture,
	sge::renderer::vertex::count const _vertex_count,
	sge::cegui::impl::clip const _clip
)
:
	texture_(
		_texture
	),
	vertex_buffer_(
		_renderer.create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				_vertex_declaration,
				sge::renderer::vf::dynamic::part_index(
					0u
				),
				_vertex_count,
				sge::renderer::resource_flags_field::null()
			)
		)
	),
	clip_(
		_clip
	)
{
}
Beispiel #2
0
sge::renderer::vertex::declaration_unique_ptr
sge::postprocessing::fullscreen_quad::create_vertex_declaration(
	sge::renderer::device::core &_renderer)
{
	return
		_renderer.create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format
				<
					sge::postprocessing::vf::format
				>()));
}
Beispiel #3
0
sge::renderer::vertex::buffer_unique_ptr
sge::renderer::vertex::create_buffer_from_view(
	sge::renderer::device::core &_device,
	sge::renderer::vertex::declaration &_vertex_declaration,
	sge::renderer::vf::dynamic::const_view const &_view,
	sge::renderer::resource_flags_field const &_resource_flags
)
{
	sge::renderer::vertex::buffer_unique_ptr buffer(
		_device.create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				_vertex_declaration,
				_view.part_index(),
				sge::renderer::vertex::count(
					_view.size()
				),
				_resource_flags
			)
		)
	);

	sge::renderer::vertex::scoped_lock const lock(
		*buffer,
		sge::renderer::lock_mode::writeonly
	);

	std::memcpy(
		lock.value().data(),
		_view.data(),
		_view.part().stride().get()
		* _view.size().get()
	);

	return
		buffer;
}
Beispiel #4
0
flake::volume::density_visualization::raycaster::object::object(
	sge::renderer::device::core &_renderer,
	sge::shader::context &_shader_context,
	sge::opencl::context::object &_context,
	sge::camera::base const &_camera,
	sge::image2d::system &_image_system,
	flakelib::volume::conversion::object &_conversion,
	flakelib::volume::grid_size const &_grid_size,
	flake::volume::density_visualization::raycaster::step_size const &_step_size,
	flake::volume::density_visualization::raycaster::debug_output const &_debug_output)
:
	renderer_(
		_renderer),
	camera_(
		_camera),
	image_system_(
		_image_system),
	conversion_(
		_conversion),
	blend_state_(
		renderer_.create_blend_state(
			sge::renderer::state::core::blend::parameters(
				sge::renderer::state::core::blend::alpha_variant(
					sge::renderer::state::core::blend::alpha_enabled(
						sge::renderer::state::core::blend::combined(
							sge::renderer::state::core::blend::source::src_alpha,
							sge::renderer::state::core::blend::dest::inv_src_alpha))),
				sge::renderer::state::core::blend::write_mask_all()))),
	sampler_state_(
		renderer_.create_sampler_state(
			sge::renderer::state::core::sampler::parameters(
				sge::renderer::state::core::sampler::address::mode_all(
					sge::renderer::state::core::sampler::address::mode::clamp),
				sge::renderer::state::core::sampler::filter::linear()))),
	grid_size_(
		_grid_size),
	debug_output_(
		_debug_output),
	vertex_declaration_(
		_renderer.create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format<vf::format>()))),
	vertex_buffer_(
		renderer_.create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				*vertex_declaration_,
				sge::renderer::vf::dynamic::make_part_index
				<
					vf::format,
					vf::format_part
				>(),
				sge::renderer::vertex::count(
					36u),
				sge::renderer::resource_flags_field::null()))),
	texture_(
		renderer_.create_planar_texture(
			sge::renderer::texture::planar_parameters(
				flakelib::volume::conversion::planar_size_from_volume_size(
					_grid_size.get()),
				sge::renderer::texture::color_format(
					sge::image::color::format::r32f,
					sge::renderer::texture::emulate_srgb::no),
				sge::renderer::texture::mipmap::off(),
				sge::renderer::resource_flags_field{
			//		sge::renderer::resource_flags_field::null()),
					sge::renderer::resource_flags::readable},
				sge::renderer::texture::capabilities_field::null()))),
	cl_texture_(
		_context,
		sge::opencl::memory_object::flags_field{
			sge::opencl::memory_object::flags::read,
			sge::opencl::memory_object::flags::write},
		*texture_),
	shader_(
		_shader_context,
		*vertex_declaration_,
		sge::shader::vertex_program_path(
			flake::media_path_from_string(
				FCPPT_TEXT("shaders/raycaster.cg"))),
		sge::shader::pixel_program_path(
			flake::media_path_from_string(
				FCPPT_TEXT("shaders/raycaster.cg"))),
		sge::shader::optional_cflags()),
	mvp_parameter_(
		shader_.vertex_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"mvp")),
		renderer_,
		sge::shader::parameter::is_projection_matrix(
			true),
		fcppt::math::matrix::identity<
			sge::renderer::matrix4
		>()
	),
	step_size_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"step_size")),
		_step_size.get()),
	elements_per_row_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"elements_per_row")),
		static_cast<int>(
			texture_->size().w() / _grid_size.get().w())),
	camera_is_inside_cube_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"camera_is_inside_cube")),
		sge::renderer::scalar()),
	slice_width_vertex_parameter_(
		shader_.vertex_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"slice_width")),
		static_cast<sge::renderer::scalar>(
			_grid_size.get().w())),
	slice_width_pixel_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"slice_width")),
		static_cast<int>(
			_grid_size.get().w())),
	texture_size_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"texture_size")),
		sge::renderer::vector2(
			static_cast<sge::renderer::scalar>(
				texture_->size().w()),
			static_cast<sge::renderer::scalar>(
				texture_->size().h()))),
	camera_position_parameter_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"camera_position")),
		fcppt::math::vector::null<
			sge::renderer::vector3
		>()
	),
	loaded_texture_(
		shader_.pixel_program(),
		sge::shader::parameter::name(
			sge::cg::string(
				"density_texture")),
		shader_,
		renderer_,
		sge::shader::parameter::planar_texture::optional_value(
			fcppt::make_ref(
				*texture_)))
{
	sge::renderer::vertex::scoped_lock vblock(
		*vertex_buffer_,
		sge::renderer::lock_mode::writeonly);

	sge::renderer::vf::view<raycaster::vf::format_part> vertices(
		vblock.value());

	sge::renderer::vf::view<raycaster::vf::format_part>::iterator vb_it(
		vertices.begin());

	// Here be dragons...
	int a = -1;
	int b = 1;

	for (unsigned side = 0u; side < 6u; ++side)
	{
		for (int tri = 0; tri < 2; ++tri)
		{
			for (int i = 0; i < 3; ++i)
			{
				int const vert =
					(tri == 0) ? i : 2 - i;

				unsigned const x =
					side % 3u;

				int
					y =
						(vert == 0) ? a : b,
					z =
						(vert == 2) ? b : a;

				if(
					((side % 2 == 0) && tri == 1) ||
					((side % 2 == 1) && tri == 0))
					std::swap(
						y,
						z);

				vf::position::packed_type res(
					0.0f,
					0.0f,
					0.0f);

				res[x] =
					static_cast<sge::renderer::scalar>(
						(side > x) ? b : a);

				res[x == 0u ? 1u : 0u] =
					static_cast<sge::renderer::scalar>(
						y);

				res[x == 2u ? 1u : 2u] =
					static_cast<sge::renderer::scalar>(
						z);

				(*vb_it++).set<vf::position>(
					res);
			}
		}
	}
}