예제 #1
0
fcppt::signal::auto_connection
quit_on_escape(
	sge::systems::instance<
		Choices
	> const &_instance
)
{
	return
		sge::systems::detail::quit_on_escape(
			_instance.keyboard_collector(),
			_instance.window_system()
		);
}
예제 #2
0
int
main()
try
{
    sge::systems::instance<
    boost::mpl::vector2<
    sge::systems::with_audio_loader,
        sge::systems::with_audio_player
        >
        > const sys(
            sge::systems::make_list
            (
                sge::systems::audio_player_default()
            )
            (
                sge::systems::audio_loader(
                    sge::media::optional_extension_set(
    sge::media::extension_set{
        sge::media::extension(
            FCPPT_TEXT("wav")
        )
    }
                    )
                )
            )
        );

    sge::audio::file_unique_ptr const file(
        sge::audio::load_exn(
            sys.audio_loader(),
            sge::config::media_path()
            /	FCPPT_TEXT("sounds")
            / FCPPT_TEXT("ding.wav")
        )
    );

    sge::audio::sound::positional_unique_ptr const sound(
        sys.audio_player().create_positional_stream(
            *file,
    sge::audio::sound::positional_parameters{
        sge::audio::position{
            fcppt::math::vector::null<
            sge::audio::vector
            >()
        }
    }
        )
    );

    sound->play(
        sge::audio::sound::repeat::loop
    );

    sge::timer::basic<
    sge::timer::clocks::standard
    > frame_timer(
        sge::timer::parameters<
        sge::timer::clocks::standard
        >(
            std::chrono::seconds(
                1
            )
        )
    );

    sge::audio::scalar const rpm(
        fcppt::literal<
        sge::audio::scalar
        >(
            1
        )
    );

    sge::audio::scalar const speed(
        fcppt::math::twopi<
        sge::audio::scalar
        >()
        *
        rpm
    );

    for(;;)
    {
        sge::audio::scalar const angle(
            sge::timer::elapsed_fractional<
            sge::audio::scalar
            >(
                frame_timer
            )
            *
            speed
        );

        sound->position(
            sge::audio::vector2_to_vector(
        sge::audio::vector2{
            std::sin(
                angle
            ),
            std::cos(
                angle
            )
        }
            )
        );

        sound->update();
    }
}
catch(
        fcppt::exception const &_error
    )
{
    fcppt::io::cerr()
            << _error.string()
            << FCPPT_TEXT('\n');

    return
        EXIT_FAILURE;
}
catch(
        std::exception const &_error
    )
{
    std::cerr
            << _error.what()
            << '\n';

    return
        EXIT_FAILURE;
}
예제 #3
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &_main_function_context
)
try
{
	if(
		_main_function_context.argc() > 2
	)
	{
		fcppt::io::cerr()
			<< FCPPT_TEXT("Pass exactly one argument to show a given text")
			FCPPT_TEXT(" or pass nothing to see the default text.\n");

		return
			awl::main::exit_failure();
	}

	sge::systems::instance<
		boost::mpl::vector4<
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_window,
			sge::systems::with_input<
				boost::mpl::vector1<
					sge::systems::keyboard_collector
				>
			>,
			sge::systems::with_image2d
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge animtest")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::center_on_resize(
						sge::window::dim{
							1024u,
							768u
						}
					)
				}
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
		(
			sge::systems::image2d(
				sge::media::optional_extension_set(
					sge::media::extension_set{
						sge::media::extension(
							FCPPT_TEXT("png")
						)
					}
				)
			)
		)
	);

	sge::font::object_unique_ptr const font_object(
		sge::font::bitmap::create(
			sys.log_context(),
			sge::config::media_path()
			/ FCPPT_TEXT("fonts")
			/ FCPPT_TEXT("bitmap")
			/ FCPPT_TEXT("font.json"),
			sys.image_system()
		)
	);

	fcppt::signal::auto_connection const escape_connection(
		sge::systems::quit_on_escape(
			sys
		)
	);

	sge::font::string const string(
		_main_function_context.argc() == 2
		?
			sge::font::from_fcppt_string(
				fcppt::from_std_string(
					_main_function_context.argv()[1]
				)
			)
		:
			SGE_FONT_LIT("test abcd e 123456789 10 11")
	);

	sge::font::draw::static_text static_text_left(
		sys.renderer_device_ffp(),
		*font_object,
		string,
		sge::font::text_parameters(
			sge::font::align_h::variant(
				sge::font::align_h::left(
					sge::font::align_h::max_width(
						300
					)
				)
			)
		),
		sge::font::vector(
			100,
			100
		),
		sge::image::color::predef::white(),
		sge::renderer::texture::emulate_srgb::yes
	);

	sge::font::draw::static_text static_text_center(
		sys.renderer_device_ffp(),
		*font_object,
		string,
		sge::font::text_parameters(
			sge::font::align_h::variant(
				sge::font::align_h::center(
					sge::font::align_h::max_width(
						300
					)
				)
			)
		),
		sge::font::vector(
			400,
			100
		),
		sge::image::color::predef::white(),
		sge::renderer::texture::emulate_srgb::yes
	);

	sge::font::draw::static_text static_text_right(
		sys.renderer_device_ffp(),
		*font_object,
		string,
		sge::font::text_parameters(
			sge::font::align_h::variant(
				sge::font::align_h::right(
					sge::font::align_h::max_width(
						300
					)
				)
			)
		),
		sge::font::vector(
			700,
			100
		),
		sge::image::color::predef::white(),
		sge::renderer::texture::emulate_srgb::yes
	);

	while(
		sys.window_system().poll()
	)
	{
		sge::renderer::context::scoped_ffp const scoped_block(
			sys.renderer_device_ffp(),
			sys.renderer_device_ffp().onscreen_target()
		);

		scoped_block.get().clear(
			sge::renderer::clear::parameters()
			.back_buffer(
				sge::image::color::predef::black()
			)
		);

		static_text_left.draw(
			scoped_block.get()
		);

		static_text_center.draw(
			scoped_block.get()
		);

		static_text_right.draw(
			scoped_block.get()
		);
	}

	return
		sys.window_system().exit_code();
}
catch(
	fcppt::exception const &_exception
)
{
	fcppt::io::cerr()
		<< _exception.string()
		<< FCPPT_TEXT('\n');

	return awl::main::exit_failure();
}
catch(
	std::exception const &_exception
)
{
	std::cerr << _exception.what() << '\n';

	return awl::main::exit_failure();
}
예제 #4
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &)
try
{
	sge::systems::instance<
		boost::mpl::vector2<
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_window
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("graph example")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::fill_on_resize()
				}
			)
		)
		(
			sge::systems::config()
			.log_settings(
				sge::systems::log_settings(
					sge::log::option_container{
						sge::log::option{
							sge::log::location(),
							fcppt::log::level::debug
						}
					}
				)
			)
		)
	);

	sge::graph::object graph(
		sge::graph::position(
			sge::renderer::vector2(
				100.f,
				100.f
			)
		),
		sge::image2d::dim(
			512u,
			128u
		),
		sys.renderer_device_ffp(),
		sge::graph::baseline(
			20.0),
		sge::graph::optional_axis_constraint(),
		sge::graph::color_schemes::bright()
	);

	typedef fcppt::random::generator::minstd_rand generator_type;

	generator_type generator(
		fcppt::random::generator::seed_from_chrono<
			generator_type::seed
		>()
	);

	typedef fcppt::random::distribution::basic<
		fcppt::random::distribution::parameters::uniform_real<
			double
		>
	> uniform_real;

	typedef fcppt::random::variate<
		generator_type,
		uniform_real
	> variate;

	variate rng(
		generator,
		uniform_real(
			uniform_real::param_type::min(
				-100.
			),
			uniform_real::param_type::sup(
				100.
			)
		)
	);

	while(
		sys.window_system().poll()
	)
	{
		sge::renderer::context::scoped_ffp const scoped_block(
			sys.renderer_device_ffp(),
			sys.renderer_device_ffp().onscreen_target()
		);

		sge::renderer::context::ffp &context(
			scoped_block.get());

		context.clear(
			sge::renderer::clear::parameters()
			.back_buffer(
				sge::image::color::predef::black()
			));

		graph.push(rng());

		graph.render(
			scoped_block.get()
		);
	}

	return sys.window_system().exit_code();
}
catch(fcppt::exception const &e)
{
	fcppt::io::cerr() << e.string() << FCPPT_TEXT("\n");
	return awl::main::exit_failure();
}
catch(
	std::exception const &_error
)
{
	std::cerr << _error.what() << '\n';
	return awl::main::exit_failure();
}
예제 #5
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &
)
try
{
	sge::systems::instance<
		boost::mpl::vector5<
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_window,
			sge::systems::with_input<
				boost::mpl::vector2<
					sge::systems::focus_collector,
					sge::systems::keyboard_collector
				>
			>,
			sge::systems::with_image2d,
			sge::systems::with_font
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge console test")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::center_on_resize(
						sge::window::dim{
							1024u,
							768u
						}
					)
				}
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
		(
			sge::systems::image2d(
				sge::media::optional_extension_set(
					sge::media::extension_set{
						sge::media::extension(
							FCPPT_TEXT("png")
						)
					}
				)
			)
		)
	);

	fcppt::signal::auto_connection const escape_connection(
		sge::systems::quit_on_escape(
			sys
		)
	);

	sge::console::object object(
		sge::console::prefix(
			SGE_FONT_LIT('/')
		)
	);

	fcppt::signal::auto_connection const c0(
		object.insert(
			sge::console::callback::convenience<
				void()
			>(
				[
					&sys
				]{
					sys.window_system().quit(
						awl::main::exit_success()
					);
				},
				sge::console::callback::name(
					SGE_FONT_LIT("quit")
				),
				sge::console::callback::short_description(
					SGE_FONT_LIT("Usage: /quit")
				)
			)
		)
	);

	fcppt::signal::auto_connection const c1(
		object.register_fallback(
			sge::console::fallback{
				[](
					sge::font::string const &_arg
				)
				{
					fcppt::io::cout()
						<< FCPPT_TEXT("fallback called with argument:")
						<< sge::font::to_fcppt_string(
							_arg
						)
						<< FCPPT_TEXT('\n');
				}
			}
		)
	);

	fcppt::signal::auto_connection const c2(
		object.insert(
			sge::console::callback::convenience<
				void(float)
			>(
				[
					&object
				](
					float const _value
				)
				{
					object.emit_message(
						SGE_FONT_LIT("New value is ")
						+
						fcppt::insert_to_string<
							sge::font::string
						>(
							_value
							+
							1.f
						)
					);
				},
				sge::console::callback::name(
					SGE_FONT_LIT("increment")
				),
				sge::console::callback::short_description(
					SGE_FONT_LIT("Usage: /increment <float-value>")
				)
			)
			.long_description(
				SGE_FONT_LIT("Increments the float value (extremely useful!)")
			)
		)
	);

	sge::texture::part_raw_ptr const tex_bg(
		sge::renderer::texture::create_planar_from_path(
			sge::config::media_path()
			/ FCPPT_TEXT("images")
			/ FCPPT_TEXT("grass.png"),
			sys.renderer_device_ffp(),
			sys.image_system(),
			sge::renderer::texture::mipmap::off(),
			sge::renderer::resource_flags_field::null(),
			sge::renderer::texture::emulate_srgb_from_caps(
				sys.renderer_device_ffp().caps()
			)
		)
	);

	sge::font::object_unique_ptr const font_object(
		sys.font_system().create_font(
			sge::font::parameters()
		)
	);

	sge::console::gfx::object gfx(
		object,
		sys.renderer_device_ffp(),
		sge::console::gfx::font_color(
			sge::image::color::predef::white()
		),
		*font_object,
		sys.focus_collector(),
		sge::font::rect{
			fcppt::math::vector::null<
				sge::font::rect::vector
			>(),
			sge::font::rect::dim{
				400,
				300
			}
		},
		sge::console::gfx::output_line_limit(
			100u
		)
	);

	sge::console::muxing_narrow_streambuf stdout_streambuf(
		std::cout,
		object,
		sge::console::muxing::enabled);

	std::cout << "Test for console muxer (cout).\n";
	std::cout << "You should see this message in the console and in the terminal (if available)\n";

	sge::console::muxing_narrow_streambuf stderr_streambuf(
		std::cerr,
		object,
		sge::console::muxing::disabled);

	std::cerr << "Test for console muxer (cerr).\n";
	std::cerr << "You should see this message _only_ in the console and _not_ in the terminal (if available)\n";

	gfx.active(
		true
	);

	while(
		sys.window_system().poll()
	)
	{
		sge::renderer::context::scoped_ffp const scoped_block(
			sys.renderer_device_ffp(),
			sys.renderer_device_ffp().onscreen_target()
		);

		scoped_block.get().clear(
			sge::renderer::clear::parameters()
			.back_buffer(
				sge::image::color::predef::black()
			)
		);

		gfx.render(
			scoped_block.get()
		);
	}

	return
		sys.window_system().exit_code();
}
catch(
	fcppt::exception const &_error
)
{
	fcppt::io::cerr()
		<< _error.string()
		<< FCPPT_TEXT('\n');

	return awl::main::exit_failure();
}
catch(
	std::exception const &_error
)
{
	std::cerr
		<< _error.what()
		<< '\n';

	return awl::main::exit_failure();
}
예제 #6
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &
)
try
{
	sge::systems::instance<
		brigand::list<
			sge::systems::with_window,
			sge::systems::with_renderer<
				sge::systems::renderer_caps::core
			>,
			sge::systems::with_input
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge cg simple test")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::fill_on_resize()
				}
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
	);

	sge::cg::context::object const cg_context{};

	sge::cg::profile::object const vertex_profile(
		sys.renderer_device_core().create_cg_profile(
			sge::cg::profile::shader_type::vertex
		)
	);

	sge::cg::string const vertex_shader_source(
		"// This is C2E1v_green from \"The Cg Tutorial\" (Addison-Wesley, ISBN\n"
		"// 0321194969) by Randima Fernando and Mark J. Kilgard.  See page 38.\n"
		"\n"
		"struct C2E1v_Output {\n"
		"	float4 position : POSITION;\n"
		"};\n"
		"\n"
		"C2E1v_Output C2E1v_green(float2 position : POSITION)\n"
		"{\n"
		"	C2E1v_Output OUT;\n"
		"\n"
		"	OUT.position = float4(position,0,1);\n"
		"\n"
		"	return OUT;\n"
		"}\n"
	);

	sge::cg::program::object vertex_program(
		sge::cg::program::from_string_parameters(
			cg_context,
			sge::cg::program::source_type::text,
			vertex_profile,
			sge::cg::program::source(
				vertex_shader_source
			),
			sge::cg::program::main_function(
				"C2E1v_green"
			),
			sys.renderer_device_core().cg_compile_options(
				cg_context,
				vertex_profile
			)
		)
	);

	sge::renderer::cg::loaded_program_unique_ptr const loaded_vertex_program(
		sys.renderer_device_core().load_cg_program(
			vertex_program
		)
	);

	sge::cg::profile::object const pixel_profile(
		sys.renderer_device_core().create_cg_profile(
			sge::cg::profile::shader_type::pixel
		)
	);

	sge::cg::string const pixel_shader_source(
		"struct C3E3f_Output {\n"
		"	float4 color : COLOR;\n"
		"};\n"
		"C3E3f_Output\n"
		"C3E3f_simple()\n"
		"{\n"
		"	C3E3f_Output OUT;\n"
		"\n"
		"	OUT.color = float4(0,1,0,1);\n"
		"	return OUT;\n"
		"}\n"
	);

	sge::cg::program::object pixel_program(
		sge::cg::program::from_string_parameters(
			cg_context,
			sge::cg::program::source_type::text,
			pixel_profile,
			sge::cg::program::source(
				pixel_shader_source
			),
			sge::cg::program::main_function(
				"C3E3f_simple"
			),
			sys.renderer_device_core().cg_compile_options(
				cg_context,
				pixel_profile
			)
		)
	);

	sge::renderer::cg::loaded_program_unique_ptr const loaded_pixel_program(
		sys.renderer_device_core().load_cg_program(
			pixel_program
		)
	);

	typedef
	sge::renderer::vf::pos<
		float,
		3
	>
	pos3_type;

	typedef
	sge::renderer::vf::part<
		brigand::list<
			pos3_type
		>
	>
	format_part;

	typedef
	sge::renderer::vf::format<
		brigand::list<
			format_part
		>
	>
	format;

	sge::renderer::vertex::declaration_unique_ptr const vertex_declaration(
		sys.renderer_device_core().create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format<
					format
				>()
			)
		)
	);

	sge::renderer::vertex::buffer_unique_ptr const vertex_buffer(
		sys.renderer_device_core().create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				*vertex_declaration,
				sge::renderer::vf::dynamic::make_part_index<
					format,
					format_part
				>(),
				sge::renderer::vertex::count(
					3u
				),
				sge::renderer::resource_flags_field::null()
			)
		)
	);

	{
		sge::renderer::vertex::scoped_lock const vblock(
			*vertex_buffer,
			sge::renderer::lock_mode::writeonly
		);

		typedef
		sge::renderer::vf::view<
			format_part
		>
		vertex_view;

		vertex_view const vertices(
			vblock.value()
		);

		vertex_view::iterator vb_it(
			vertices.begin()
		);

		typedef
		pos3_type::packed_type
		vec3;

		(*vb_it).set<
			pos3_type
		>(
			vec3(
				-1.f,
				1.f,
				0.f
			)
		);

		++vb_it;

		(*vb_it).set<
			pos3_type
		>(
			vec3(
				-1.f,
				-1.f,
				0.f
			)
		);

		++vb_it;

		(*vb_it).set<
			pos3_type
		>(
			vec3(
				1.f,
				1.f,
				0.f
			)
		);
	}

	auto const draw(
		[
			&loaded_pixel_program,
			&loaded_vertex_program,
			&sys,
			&vertex_buffer,
			&vertex_declaration
		]{
			sge::renderer::context::scoped_core const scoped_block(
				sys.renderer_device_core(),
				sys.renderer_device_core().onscreen_target()
			);

			scoped_block.get().clear(
				sge::renderer::clear::parameters()
				.back_buffer(
					sge::image::color::any::object{
						sge::image::color::predef::black()
					}
				)
			);

			sge::renderer::vertex::scoped_declaration_and_buffers const vb_context(
				scoped_block.get(),
				*vertex_declaration,
				sge::renderer::vertex::const_buffer_ref_container{
					fcppt::make_cref(
						*vertex_buffer
					)
				}
			);

			sge::renderer::cg::scoped_program const scoped_vertex_program(
				scoped_block.get(),
				*loaded_vertex_program
			);

			sge::renderer::cg::scoped_program const scoped_pixel_program(
				scoped_block.get(),
				*loaded_pixel_program
			);

			scoped_block.get().render_nonindexed(
				sge::renderer::vertex::first(
					0u
				),
				sge::renderer::vertex::count(
					3u
				),
				sge::renderer::primitive_type::triangle_list
			);
		}
	);

	return
		sge::window::loop(
			sys.window_system(),
			sge::window::loop_function{
				[
					&sys,
					&draw
				](
					awl::event::base const &_event
				)
				{

					sge::systems::quit_on_escape(
						sys,
						_event
					);

					fcppt::optional::maybe_void(
						fcppt::cast::dynamic<
							sge::renderer::event::render const
						>(
							_event
						),
						[
							&draw
						](
							fcppt::reference<
								sge::renderer::event::render const
							>
						)
						{
							draw();
						}
					);
				}
			}
		);
}
catch(
	fcppt::exception const &_error
)
{
	awl::show_error(
		_error.string()
	);

	return
		awl::main::exit_failure();
}
catch(
	std::exception const &_error
)
{
	awl::show_error_narrow(
		_error.what()
	);

	return
		awl::main::exit_failure();
}
예제 #7
0
int
main()
try
{
	sge::opencl::system opencl_system;

	fcppt::io::cout()
		<< FCPPT_TEXT("Querying the number of available platforms...\n");

	sge::opencl::platform::object_sequence &platforms(
		opencl_system.platforms());

	if(platforms.empty())
	{
		fcppt::io::cerr()
			<< FCPPT_TEXT("Couldn't find any OpenCL platforms on your system.\n");
		return EXIT_FAILURE;
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Number of OpenCL platforms: ") << platforms.size() << FCPPT_TEXT("\n")
		<< FCPPT_TEXT("Platform listing begin:\n")
		<< FCPPT_TEXT("-----------------------\n");

	sge::opencl::platform::object_sequence::size_type platform_index = 0;
	for(
		sge::opencl::platform::object const &current_platform
		:
		platforms
	)
	{
		fcppt::io::cout()
			<< FCPPT_TEXT("\tPlatform ")
			<< platform_index++
			<< FCPPT_TEXT(":\n")
			<< FCPPT_TEXT("\tName: ")
			<< fcppt::from_std_string(
				current_platform.name()
			)
			<< FCPPT_TEXT("\n")
			<< FCPPT_TEXT("\tVendor: ")
			<< fcppt::from_std_string(
				current_platform.vendor()
			)
			<< FCPPT_TEXT("\n")
			<< FCPPT_TEXT("Profile type: ")
			<<
				(current_platform.profile() == sge::opencl::platform::profile_type::full
				?
					fcppt::string(FCPPT_TEXT("full"))
				:
					fcppt::string(FCPPT_TEXT("embedded")))
			<< FCPPT_TEXT("\n")
			<< FCPPT_TEXT("\tVersion: ")
			<< current_platform.version().major_part()
			<< FCPPT_TEXT(".")
			<< current_platform.version().minor_part()
			<< FCPPT_TEXT("\n");

		if(!current_platform.version().platform_specific().empty())
			fcppt::io::cout()
				<< FCPPT_TEXT("\tPlatform specific version info: ")
				<< fcppt::from_std_string(current_platform.version().platform_specific())
				<< FCPPT_TEXT("\n");

		fcppt::io::cout()
			<< FCPPT_TEXT("\tExtension list begin:\n")
			<< FCPPT_TEXT("\t*********************\n")
			<< FCPPT_TEXT("\t\t")
			<<
				fcppt::from_std_string(
					boost::algorithm::join(
						current_platform.extensions(),
						std::string("\n\t\t")))
			<< FCPPT_TEXT("\r\t*********************\n")
			<< FCPPT_TEXT("-----------------------\n");
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Platform listing end\n");

	sge::opencl::platform::object_sequence::size_type chosen_platform_index;
	if(platforms.size() == 1)
	{
		chosen_platform_index = 0;
	}
	else
	{
		fcppt::io::cout()
			<< FCPPT_TEXT("Your choice: ");
		do
			chosen_platform_index =
				query_value_from_user<sge::opencl::platform::object_sequence::size_type>(
					fcppt::io::cin());
		while(chosen_platform_index >= platforms.size());
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("List devices with properties? [y/n] ");

	fcppt::char_type list_devices;
	do
		list_devices =
			query_value_from_user<fcppt::char_type>(
				fcppt::io::cin());
	while(list_devices != FCPPT_TEXT('y') && list_devices != FCPPT_TEXT('n'));

	sge::opencl::platform::object &chosen_platform =
		platforms[chosen_platform_index];

	if(list_devices == FCPPT_TEXT('y'))
	{
		fcppt::io::cout()
			<< FCPPT_TEXT("Number of devices on this platform: ")
			<< chosen_platform.devices().size()
			<< FCPPT_TEXT('\n')
			<< FCPPT_TEXT("Device listing begin:\n")
			<< FCPPT_TEXT("-----------------------\n");

		for(
			sge::opencl::device::object const &current_device
			:
			chosen_platform.devices()
		)
		{
			current_device.output_info(
				std::cout);
			fcppt::io::cout()
				<< FCPPT_TEXT("-----------------------\n");
		}

		fcppt::io::cout()
			<< FCPPT_TEXT("-----------------------\n")
			<< FCPPT_TEXT("Device listing end\n");
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Creating sge::systems object...\n");

	sge::window::dim const window_dim{
		1024u,
		768u
	};

	sge::systems::instance<
		brigand::list<
			sge::systems::with_window,
			sge::systems::with_renderer<
				sge::systems::renderer_caps::core
			>
		>
	> const sys(
		sge::systems::make_list
		(
			// FIXME: Move this higher?
			sge::systems::config()
			.log_settings(
				sge::systems::log_settings{
					sge::log::option_container{
						sge::log::option{
							sge::opencl::log_location(),
							fcppt::log::level::verbose
						}
					}
				}
			)
		)
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("Simple OpenCL example")
						)
					)
				)
			)
			.dont_show()
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::center_on_resize(
						window_dim
					)
				}
			)
		)
	);

	fcppt::io::cout()
		<< FCPPT_TEXT("Done. Creating a context with all devices on this platform...\n");

	sge::opencl::device::object_ref_sequence const device_refs(
		fcppt::algorithm::map<
			sge::opencl::device::object_ref_sequence
		>(
			chosen_platform.devices(),
			[](
				sge::opencl::device::object &_device
			)
			{
				return
					fcppt::make_ref(
						_device
					);
			}
		)
	);

	sge::opencl::context::object main_context(
		sge::opencl::context::parameters(
			chosen_platform,
			device_refs
		)
		.share_with(
			sys.renderer_device_core())
		.error_callback(
			sge::opencl::context::error_callback{
				&opencl_error_callback
			}
		)
	);

	fcppt::io::cout()
		<< FCPPT_TEXT("Context created, listing available planar image formats (read/write)\n");

	sge::opencl::memory_object::image::format_sequence const planar_image_formats =
		main_context.supported_planar_image_formats(
			CL_MEM_READ_WRITE);

	for(
		auto const format
		:
		planar_image_formats
	)
	{
		sge::opencl::memory_object::image::format_output(
			std::cout,
			format
		);

		std::cout << '\n';
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Listing available volume image formats (read/write)...\n");

	sge::opencl::memory_object::image::format_sequence const volume_image_formats =
		main_context.supported_volume_image_formats(
			CL_MEM_READ_WRITE);

	for(
		auto const format
		:
		volume_image_formats
	)
	{
		sge::opencl::memory_object::image::format_output(
			std::cout,
			format
		);

		std::cout << '\n';
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Done, now creating a program...");

	sge::opencl::program::object main_program(
		sys.log_context(),
		main_context,
		sge::opencl::program::source_string_sequence{
			std::string(
				"__kernel void hello_kernel("
				"float const multiplier,"
				"__global float *input)"
				"{"
				"int gid = get_global_id(0);"
				"int lid = get_local_id(0);"
				"input[gid] = lid * multiplier;"
				"}"
			)
		},
		sge::opencl::program::optional_build_parameters());

	fcppt::io::cout()
		<< FCPPT_TEXT("Program created, building the program...\n");

	volatile bool build_finished =
		false;

	main_program.build(
		sge::opencl::program::build_parameters()
		.notification_callback(
			sge::opencl::program::notification_callback{
				std::bind(
					&program_build_finished,
					std::ref(
						build_finished
					)
				)
			}
		)
	);

	std::cout << "Waiting for build completion\n";
	while(!build_finished)
		std::cout << "Build not finished yet\n";

	fcppt::io::cout()
		<< FCPPT_TEXT("Program built, now creating a kernel...\n");

	sge::opencl::kernel::object main_kernel(
		main_program,
		sge::opencl::kernel::name(
			"hello_kernel"));

	fcppt::io::cout()
		<< FCPPT_TEXT("Kernel created, now creating a vertex buffer...\n");

	sge::renderer::vertex::declaration_unique_ptr const vertex_declaration(
		sys.renderer_device_core().create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format<vf::format>())));

	sge::renderer::vertex::buffer_unique_ptr const vb(
		sys.renderer_device_core().create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				*vertex_declaration,
				sge::renderer::vf::dynamic::make_part_index<
					vf::format,
					vf::part
				>(),
				sge::renderer::vertex::count(
					6u),
				sge::renderer::resource_flags_field{
					sge::renderer::resource_flags::readable})));

	fcppt::io::cout()
		<< FCPPT_TEXT("Done, now creating OpenCL buffer from it\n");

	sge::opencl::memory_object::buffer cl_vb(
		main_context,
		*vb,
		sge::opencl::memory_object::renderer_buffer_lock_mode::write_only);

	main_kernel.argument(
		sge::opencl::kernel::argument_index(
			1u),
		cl_vb);

	main_kernel.argument(
		sge::opencl::kernel::argument_index(
			0u),
		sge::opencl::kernel::numeric_type(
			static_cast<cl_float>(
				2.0
			)
		)
	);

	fcppt::io::cout()
		<< FCPPT_TEXT("Done, now creating a command queue\n");

	sge::opencl::command_queue::object main_queue(
		device_refs[0].get(),
		main_context,
		sge::opencl::command_queue::execution_mode::out_of_order,
		sge::opencl::command_queue::profiling_mode::disabled);

	fcppt::io::cout()
		<< FCPPT_TEXT("Done, now enqueueing kernel and running it\n");

	{
		sge::opencl::memory_object::scoped_objects scoped_vb(
			main_queue,
			sge::opencl::memory_object::base_ref_sequence{
				fcppt::reference_to_base<
					sge::opencl::memory_object::base
				>(
					fcppt::make_ref(
						cl_vb
					)
				)
			}
		);

		sge::opencl::command_queue::enqueue_kernel(
			main_queue,
			main_kernel,
			sge::opencl::command_queue::global_dim1(
				sge::opencl::dim1(
					vb->linear_size()
					* 2u
				)
			),
			sge::opencl::command_queue::local_dim1(
				sge::opencl::dim1(
					2u
				)
			),
			sge::opencl::event::sequence()
		);
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Now locking the vb for reading and printing the values\n");

	{
		sge::renderer::vertex::scoped_lock const scoped_vb(
			*vb,
			sge::renderer::lock_mode::readwrite);

		typedef
		sge::renderer::vf::view<vf::part>
		vertex_view;

		vertex_view const vertices(
			scoped_vb.value());

		for(
			auto const vertex
			:
			vertices
		)
		{
			fcppt::io::cout()
				<< vertex.get<vf::scalar_quantity>()
				<< FCPPT_TEXT('\n');
		}
	}

	fcppt::io::cout()
		<< FCPPT_TEXT("Done\n");
}
catch(
	fcppt::exception const &_error
)
{
	fcppt::io::cerr()
		<< _error.string()
		<< FCPPT_TEXT('\n');

	return EXIT_FAILURE;
}
catch(
	std::exception const &_error
)
{
	std::cerr
		<< _error.what()
		<< '\n';

	return EXIT_FAILURE;
}
awl::main::exit_code const
example_main(
	awl::main::function_context const &
)
try
{
	sge::systems::instance<
		brigand::list<
			sge::systems::with_window,
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_input,
			sge::systems::with_image2d
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge sprite color texture example")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::fill_on_resize()
				}
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
		(
			sge::systems::image2d(
				sge::media::optional_extension_set(
					sge::media::extension_set{
						sge::media::extension(
							FCPPT_TEXT("png")
						)
					}
				)
			)
		)
		(
			sge::systems::config()
			.log_settings(
				sge::systems::log_settings(
					sge::log::option_container{
						sge::log::option{
							sge::log::location(),
							fcppt::log::level::debug
						}
					}
				)
			)
		)
	);

	typedef
	sge::image::color::rgba8_format
	color_format;

	typedef
	sge::sprite::config::choices<
		sge::sprite::config::type_choices<
			sge::sprite::config::unit_type<
				int
			>,
			sge::sprite::config::float_type<
				float
			>
		>,
		sge::sprite::config::pos<
			sge::sprite::config::pos_option::pos
		>,
		sge::sprite::config::normal_size<
			sge::sprite::config::texture_size_option::always
		>,
		brigand::list<
			sge::sprite::config::with_color<
				color_format
			>,
			sge::sprite::config::with_texture<
				sge::sprite::config::texture_level_count<
					1u
				>,
				sge::sprite::config::texture_coordinates::automatic,
				sge::sprite::config::texture_ownership::shared
			>
		>
	>
	sprite_choices;

	typedef
	sge::sprite::buffers::with_declaration<
		sge::sprite::buffers::single<
			sprite_choices
		>
	>
	sprite_buffers_type;

	typedef
	sge::sprite::object<
		sprite_choices
	>
	sprite_object;

	typedef
	sge::sprite::state::all_choices
	sprite_state_choices;

	typedef
	sge::sprite::state::object<
		sprite_state_choices
	>
	sprite_state_object;

	typedef
	sge::sprite::state::parameters<
		sprite_state_choices
	>
	sprite_state_parameters;

	sprite_state_object sprite_state(
		sys.renderer_device_ffp(),
		sprite_state_parameters()
	);

	sge::renderer::texture::planar_unique_ptr const texture(
		sge::renderer::texture::create_planar_from_path(
			sge::config::media_path()
			/ FCPPT_TEXT("images")
			/ FCPPT_TEXT("grass.png"),
			sys.renderer_device_core(),
			sys.image_system(),
			sge::renderer::texture::mipmap::off(),
			sge::renderer::resource_flags_field::null(),
			sge::renderer::texture::emulate_srgb_from_caps(
				sys.renderer_device_ffp().caps()
			)
		)
	);

	sprite_buffers_type sprite_buffers(
		sys.renderer_device_ffp(),
		sge::sprite::buffers::option::dynamic
	);

	sprite_object const spr{
		sge::sprite::roles::pos{} =
			fcppt::math::vector::null<
				sprite_object::vector
			>(),
		sge::sprite::roles::color{} =
			sge::image::color::convert<
				color_format
			>(
				sge::image::color::predef::red()
			),
		sge::sprite::roles::texture0{} =
			sprite_object::texture_type{
				fcppt::make_shared_ptr<
					sge::texture::part_raw_ref
				>(
					*texture
				)
			}
	};

	auto const draw(
		[
			&spr,
			&sprite_buffers,
			&sprite_state,
			&sys
		]{
			sge::renderer::context::scoped_ffp const scoped_block(
				sys.renderer_device_ffp(),
				sys.renderer_device_ffp().onscreen_target()
			);

			scoped_block.get().clear(
				sge::renderer::clear::parameters()
				.back_buffer(
					sge::image::color::any::object{
						sge::image::color::predef::black()
					}
				)
			);

			sge::sprite::process::one(
				scoped_block.get(),
				spr,
				sprite_buffers,
				sprite_state
			);
		}
	);

	return
		sge::window::loop(
			sys.window_system(),
			sge::window::loop_function{
				[
					&sys,
					&draw
				](
					awl::event::base const &_event
				)
				{
					sge::systems::quit_on_escape(
						sys,
						_event
					);

					fcppt::optional::maybe_void(
						fcppt::cast::dynamic<
							sge::renderer::event::render const
						>(
							_event
						),
						[
							&draw
						](
							fcppt::reference<
								sge::renderer::event::render const
							>
						)
						{
							draw();
						}
					);
				}
			}
		);
}
catch(
	fcppt::exception const &_error
)
{
	awl::show_error(
		_error.string()
	);

	return
		awl::main::exit_failure();
}
catch(
	std::exception const &_error
)
{
	awl::show_error_narrow(
		_error.what()
	);

	return
		awl::main::exit_failure();
}
예제 #9
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &
)
try
{
	sge::systems::instance<
		boost::mpl::vector4<
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_window,
			sge::systems::with_input<
				boost::mpl::vector1<
					sge::systems::keyboard_collector
				>
			>,
			sge::systems::with_image2d
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge lighting example")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::fill_on_resize()
				}
			)
		)
		(
			sge::systems::image2d(
				sge::media::optional_extension_set(
					sge::media::extension_set{
						sge::media::extension(
							FCPPT_TEXT("png")
						)
					}
				)
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
	);

	typedef
	sge::sprite::config::choices<
		sge::sprite::config::type_choices<
			sge::sprite::config::unit_type<
				int
			>,
			sge::sprite::config::float_type<
				float
			>
		>,
		sge::sprite::config::pos<
			sge::sprite::config::pos_option::pos
		>,
		sge::sprite::config::normal_size<
			sge::sprite::config::texture_size_option::always
		>,
		boost::mpl::vector1<
			sge::sprite::config::with_texture<
				sge::sprite::config::texture_level_count<
					1u
				>,
				sge::sprite::config::texture_coordinates::automatic,
				sge::sprite::config::texture_ownership::reference
			>
		>
	>
	sprite_choices;

	typedef
	sge::sprite::object<
		sprite_choices
	>
	sprite_object;

	typedef
	sge::sprite::buffers::with_declaration<
		sge::sprite::buffers::single<
			sprite_choices
		>
	>
	sprite_buffers_type;

	sprite_buffers_type sprite_buffers(
		sys.renderer_device_ffp(),
		sge::sprite::buffers::option::dynamic
	);

	typedef
	sge::sprite::state::all_choices
	sprite_state_choices;

	typedef
	sge::sprite::state::object<
		sprite_state_choices
	>
	sprite_state_object;

	typedef
	sge::sprite::state::parameters<
		sprite_state_choices
	>
	sprite_state_parameters;

	sprite_state_object sprite_state(
		sys.renderer_device_ffp(),
		sprite_state_parameters()
	);

	sge::image2d::file_unique_ptr const image(
		sge::image2d::load_exn(
			sys.image_system(),
			sge::config::media_path()
			/ FCPPT_TEXT("images")
			/ FCPPT_TEXT("grass.png")
		)
	);

	sge::renderer::texture::planar_unique_ptr const image_texture(
		sge::renderer::texture::create_planar_from_view(
			sys.renderer_device_ffp(),
			image->view(),
			sge::renderer::texture::mipmap::off(),
			sge::renderer::resource_flags_field::null(),
			sge::renderer::texture::emulate_srgb_from_caps(
				sys.renderer_device_ffp().caps()
			)
		)
	);

	sge::texture::part_raw_ref const texture_part(
		*image_texture
	);

	sprite_object const my_object(
		sge::sprite::roles::pos{} =
			fcppt::math::vector::null<
				sprite_object::vector
			>(),
		sge::sprite::roles::texture0{} =
			sprite_object::texture_type{
				texture_part
			}
	);

	fcppt::signal::auto_connection const escape_connection{
		sge::systems::quit_on_escape(
			sys
		)
	};

	sge::renderer::state::ffp::lighting::object_unique_ptr const light_state{
		sys.renderer_device_ffp().create_lighting_state(
			sge::renderer::state::ffp::lighting::parameters{
				sge::renderer::state::ffp::lighting::variant{
					sge::renderer::state::ffp::lighting::enabled{
						sge::renderer::state::ffp::lighting::ambient_color{
							sge::image::color::predef::black()
						},
						sge::renderer::state::ffp::lighting::diffuse_from_vertex{
							false
						}
					}
				}
			}
		)
	};

	sge::renderer::state::ffp::lighting::light::object_unique_ptr const light{
		sys.renderer_device_ffp().create_light_state(
			sge::renderer::state::ffp::lighting::light::parameters{
				sge::renderer::state::ffp::lighting::diffuse_color{
					sge::image::color::predef::black()
				},
				sge::renderer::state::ffp::lighting::specular_color{
					sge::image::color::predef::black()
				},
				sge::renderer::state::ffp::lighting::ambient_color{
					sge::image::color::predef::yellow()
				},
				sge::renderer::state::ffp::lighting::light::variant{
					sge::renderer::state::ffp::lighting::light::point{
						sge::renderer::state::ffp::lighting::light::position{
							fcppt::math::vector::construct(
								fcppt::math::vector::structure_cast<
									sge::renderer::vector2,
									fcppt::cast::int_to_float_fun
								>(
									my_object.center()
								),
								-1.f
							)
						},
						sge::renderer::state::ffp::lighting::light::attenuation{
							sge::renderer::state::ffp::lighting::light::constant_attenuation{
								1.f
							},
							sge::renderer::state::ffp::lighting::light::linear_attenuation{
								0.f
							},
							sge::renderer::state::ffp::lighting::light::quadratic_attenuation{
								0.f
							}
						}
					}
				}
			}
		)
	};

	while(
		sys.window_system().poll()
	)
	{
		sge::renderer::context::scoped_ffp const scoped_block(
			sys.renderer_device_ffp(),
			sys.renderer_device_ffp().onscreen_target()
		);

		scoped_block.get().clear(
			sge::renderer::clear::parameters()
			.back_buffer(
				sge::image::color::predef::black()
			)
		);

		sge::renderer::state::ffp::lighting::scoped const scoped_lighting{
			scoped_block.get(),
			*light_state
		};

		sge::renderer::state::ffp::lighting::light::scoped const scoped_lights{
			scoped_block.get(),
			sge::renderer::state::ffp::lighting::light::const_object_ref_vector{
				fcppt::make_cref(
					*light
				)
			}
		};

		sge::sprite::process::one(
			scoped_block.get(),
			my_object,
			sprite_buffers,
			sprite_state
		);
	}

	return
		sys.window_system().exit_code();
}
catch(
	fcppt::exception const &_exception
)
{
	fcppt::io::cerr()
		<< FCPPT_TEXT("caught sge exception: ")
		<< _exception.string()
		<< FCPPT_TEXT('\n');

	return
		awl::main::exit_failure();
}
catch(
	std::exception const &_exception
)
{
	std::cerr
		<< "caught std exception: "
		<< _exception.what()
		<< '\n';

	return
		awl::main::exit_failure();
}
예제 #10
0
int
main()
try
{
	sge::systems::instance<
		boost::mpl::vector2<
			sge::systems::with_window,
			sge::systems::with_renderer<
				sge::systems::renderer_caps::core
			>
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge opengl example")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{}
			)
			.caps(
				sge::renderer::caps::system_field{
					sge::renderer::caps::system::opengl
				}
			)
		)
	);

	sge::renderer::texture::planar_unique_ptr const texture(
		sys.renderer_device_core().create_planar_texture(
			sge::renderer::texture::planar_parameters(
				sge::renderer::dim2(
					256u,
					256u
				),
				sge::renderer::texture::color_format(
					sge::image::color::format::rgba8,
					sge::renderer::texture::emulate_srgb::no
				),
				sge::renderer::texture::mipmap::off(),
				sge::renderer::resource_flags_field::null(),
				sge::renderer::texture::capabilities_field::null()
			)
		)
	);

	sge::renderer::opengl::texture::base const &opengl_texture(
		dynamic_cast<
			sge::renderer::opengl::texture::base const &
		>(
			*texture
		)
	);

	fcppt::io::cout()
		<< FCPPT_TEXT("Opengl texture id is ")
		<< opengl_texture.id()
		<< FCPPT_TEXT('\n');

	typedef sge::renderer::vf::part<
		boost::mpl::vector1<
			sge::renderer::vf::pos<
				float,
				3
			>
		>
	> vf_part;

	typedef sge::renderer::vf::format<
		boost::mpl::vector1<
			vf_part
		>
	> vf_format;

	sge::renderer::vertex::declaration_unique_ptr const vertex_declaration(
		sys.renderer_device_core().create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format<
					vf_format
				>()
			)
		)
	);

	sge::renderer::vertex::buffer_unique_ptr const vertex_buffer(
		sys.renderer_device_core().create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				*vertex_declaration,
				sge::renderer::vf::dynamic::make_part_index<
					vf_format,
					vf_part
				>(),
				sge::renderer::vertex::count(
					3u
				),
				sge::renderer::resource_flags_field::null()
			)
		)
	);

	sge::renderer::opengl::buffer::base const &opengl_buffer(
		dynamic_cast<
			sge::renderer::opengl::buffer::base const &
		>(
			*vertex_buffer
		)
	);

	fcppt::io::cout()
		<< FCPPT_TEXT("Opengl buffer id is ")
		<< opengl_buffer.id()
		<< FCPPT_TEXT(" and native is ")
		<< std::boolalpha
		<< opengl_buffer.native()
		<< FCPPT_TEXT('\n');
}
catch(
	fcppt::exception const &_error
)
{
	fcppt::io::cerr()
		<< _error.string()
		<< FCPPT_TEXT('\n');

	return EXIT_FAILURE;
}
catch(
	std::exception const &_error
)
{
	std::cerr
		<< _error.what()
		<< '\n';

	return EXIT_FAILURE;
}
예제 #11
0
awl::main::exit_code const
example_main(
	awl::main::function_context const &
)
try
{
	sge::systems::instance<
		brigand::list<
			sge::systems::with_window,
			sge::systems::with_renderer<
				sge::systems::renderer_caps::ffp
			>,
			sge::systems::with_input,
			sge::systems::with_image2d
		>
	> const sys(
		sge::systems::make_list
		(
			sge::systems::window(
				sge::systems::window_source(
					sge::systems::original_window(
						sge::window::title(
							FCPPT_TEXT("sge cg point sprites test")
						)
					)
				)
			)
		)
		(
			sge::systems::renderer(
				sge::renderer::pixel_format::object(
					sge::renderer::pixel_format::color::depth32,
					sge::renderer::pixel_format::depth_stencil::off,
					sge::renderer::pixel_format::optional_multi_samples(),
					sge::renderer::pixel_format::srgb::no
				),
				sge::renderer::display_mode::parameters(
					sge::renderer::display_mode::vsync::on,
					sge::renderer::display_mode::optional_object()
				),
				sge::viewport::optional_resize_callback{
					sge::viewport::fill_on_resize()
				}
			)
		)
		(
			sge::systems::image2d(
				sge::media::optional_extension_set(
					sge::media::extension_set{
						sge::media::extension(
							FCPPT_TEXT("png")
						)
					}
				)
			)
		)
		(
			sge::systems::input(
				sge::systems::cursor_option_field::null()
			)
		)
	);

	typedef
	sge::renderer::vf::pos<
		float,
		3
	>
	pos3_type;

	typedef
	sge::renderer::vf::texpos<
		float,
		2,
		sge::renderer::vf::index<
			0u
		>
	>
	texpos_type;

	typedef
	sge::renderer::vf::extra<
		sge::renderer::vf::vector<
			float,
			1u
		>,
		sge::renderer::vf::index<
			0u
		>
	>
	point_size_type;

	typedef
	sge::renderer::vf::part<
		brigand::list<
			pos3_type,
			texpos_type,
			point_size_type
		>
	>
	format_part;

	typedef
	sge::renderer::vf::format<
		brigand::list<
			format_part
		>
	>
	format;

	sge::renderer::vertex::declaration_unique_ptr const vertex_declaration(
		sys.renderer_device_core().create_vertex_declaration(
			sge::renderer::vertex::declaration_parameters(
				sge::renderer::vf::dynamic::make_format<
					format
				>()
			)
		)
	);

	sge::cg::context::object const cg_context;

	sge::cg::profile::object const vertex_profile(
		sys.renderer_device_core().create_cg_profile(
			sge::cg::profile::shader_type::vertex
		)
	);

	sge::cg::string const vertex_shader_source(
		"struct vertex_outputs\n"
		"{\n"
		"	float2 position : POSITION;\n"
		"	float point_size : PSIZE;\n"
		"	float2 external_texpos : COLOR0;\n"
		"};\n"
		"vertex_outputs\n"
		"vertex_main(\n"
		"	float2 position : POSITION,\n"
		"	float2 texpos : TEXCOORD0,\n"
		"	float point_size : $0$\n"
		")\n"
		"{\n"
		"	vertex_outputs outs;\n"
		"	outs.position = float4(position,0.0,1.0);\n"
		"	outs.point_size = point_size;\n"
		"	outs.external_texpos = texpos;\n"
		"	return outs;\n"
		"}\n"
	);

	sge::cg::string const pixel_shader_source(
		"float4\n"
		"pixel_main(\n"
		"	float2 external_texpos : COLOR0,\n"
		"	float2 texCoord : TEXCOORD0,\n"
		"	uniform sampler2D decal : TEX0\n"
		") : COLOR\n"
		"{\n"
		"	return tex2D(decal,external_texpos.xy + texCoord.xy / 2.0);\n"
		"}\n"
	);

	sge::cg::program::object vertex_program(
		sge::cg::program::from_string_parameters(
			cg_context,
			sge::cg::program::source_type::text,
			vertex_profile,
			sys.renderer_device_core().transform_cg_vertex_program(
				*vertex_declaration,
				sge::cg::program::source(
					vertex_shader_source
				)
			),
			sge::cg::program::main_function(
				"vertex_main"
			),
			sys.renderer_device_core().cg_compile_options(
				cg_context,
				vertex_profile
			)
		)
	);

	sge::renderer::cg::loaded_program_unique_ptr const loaded_vertex_program(
		sys.renderer_device_core().load_cg_program(
			vertex_program
		)
	);

	sge::cg::profile::object const pixel_profile(
		sys.renderer_device_core().create_cg_profile(
			sge::cg::profile::shader_type::pixel
		)
	);

	sge::cg::program::object pixel_program(
		sge::cg::program::from_string_parameters(
			cg_context,
			sge::cg::program::source_type::text,
			pixel_profile,
			sge::cg::program::source(
				pixel_shader_source
			),
			sge::cg::program::main_function(
				"pixel_main"
			),
			sys.renderer_device_core().cg_compile_options(
				cg_context,
				pixel_profile
			)
		)
	);

	sge::renderer::cg::loaded_program_unique_ptr const loaded_pixel_program(
		sys.renderer_device_core().load_cg_program(
			pixel_program
		)
	);

	sge::renderer::vertex::buffer_unique_ptr const vertex_buffer(
		sys.renderer_device_core().create_vertex_buffer(
			sge::renderer::vertex::buffer_parameters(
				*vertex_declaration,
				sge::renderer::vf::dynamic::make_part_index<
					format,
					format_part
				>(),
				sge::renderer::vertex::count(
					1u
				),
				sge::renderer::resource_flags_field::null()
			)
		)
	);

	{
		sge::renderer::vertex::scoped_lock const vblock(
			*vertex_buffer,
			sge::renderer::lock_mode::writeonly
		);

		typedef
		sge::renderer::vf::view<
			format_part
		>
		vertex_view;

		vertex_view const vertices(
			vblock.value()
		);

		vertex_view::iterator vb_it(
			vertices.begin()
		);

		typedef
		pos3_type::packed_type
		pos3;

		typedef
		texpos_type::packed_type texpos;

		typedef
		point_size_type::packed_type
		point_size;


		(*vb_it).set<
			pos3_type
		>(
			pos3(
				0.f,
				0.f,
				0.f
			)
		);

		(*vb_it).set<
			texpos_type
		>(
			texpos(
				0.5f,
				0.5f
			)
		);

		(*vb_it).set<
			point_size_type
		>(
			point_size(
				200.0f
			)
		);
	}

	sge::renderer::texture::planar_unique_ptr const texture(
		sge::renderer::texture::create_planar_from_path(
			sge::config::media_path()
			/ FCPPT_TEXT("images")
			/ FCPPT_TEXT("uvtestgrid.png"),
			sys.renderer_device_core(),
			sys.image_system(),
			sge::renderer::texture::mipmap::off(),
			sge::renderer::resource_flags_field::null(),
			sge::renderer::texture::emulate_srgb_from_caps(
				sys.renderer_device_ffp().caps()
			)
		)
	);

	sge::renderer::cg::loaded_texture_unique_ptr const loaded_texture(
		sys.renderer_device_core().load_cg_texture(
			pixel_program.parameter(
				"decal"
			).object(),
			*texture
		)
	);

	sge::renderer::state::ffp::misc::object_unique_ptr const misc_state(
		sys.renderer_device_ffp().create_misc_state(
			sge::renderer::state::ffp::misc::parameters(
				sge::renderer::state::ffp::misc::enable_point_sprites(
					true
				),
				sge::renderer::state::ffp::misc::local_viewer(
					false
				),
				sge::renderer::state::ffp::misc::normalize_normals(
					false
				)
			)
		)
	);

	auto const draw(
		[
			&loaded_pixel_program,
			&loaded_texture,
			&loaded_vertex_program,
			&misc_state,
			&sys,
			&vertex_buffer,
			&vertex_declaration
		]{
			sge::renderer::context::scoped_ffp const scoped_block(
				sys.renderer_device_ffp(),
				sys.renderer_device_ffp().onscreen_target()
			);

			scoped_block.get().clear(
				sge::renderer::clear::parameters()
				.back_buffer(
					sge::image::color::any::object{
						sge::image::color::predef::blue()
					}
				)
			);

			sge::renderer::state::ffp::misc::scoped const scoped_misc(
				scoped_block.get(),
				*misc_state
			);

			sge::renderer::vertex::scoped_declaration_and_buffers const vb_context(
				scoped_block.get(),
				*vertex_declaration,
				sge::renderer::vertex::const_buffer_ref_container{
					fcppt::make_cref(
						*vertex_buffer
					)
				}
			);

			sge::renderer::cg::scoped_program const scoped_vertex_program(
				scoped_block.get(),
				*loaded_vertex_program
			);

			sge::renderer::cg::scoped_program const scoped_pixel_program(
				scoped_block.get(),
				*loaded_pixel_program
			);

			sge::renderer::cg::scoped_texture const scoped_texture(
				scoped_block.get(),
				*loaded_texture
			);

			scoped_block.get().render_nonindexed(
				sge::renderer::vertex::first(
					0u
				),
				sge::renderer::vertex::count{
					vertex_buffer->linear_size()
				},
				sge::renderer::primitive_type::point_list
			);
		}
	);

	return
		sge::window::loop(
			sys.window_system(),
			sge::window::loop_function{
				[
					&sys,
					&draw
				](
					awl::event::base const &_event
				)
				{
					sge::systems::quit_on_escape(
						sys,
						_event
					);

					fcppt::optional::maybe_void(
						fcppt::cast::dynamic<
							sge::renderer::event::render const
						>(
							_event
						),
						[
							&draw
						](
							fcppt::reference<
								sge::renderer::event::render const
							>
						)
						{
							draw();
						}
					);
				}
			}
		);
}
catch(
	fcppt::exception const &_error
)
{
	awl::show_error(
		_error.string()
	);

	return
		awl::main::exit_failure();
}
catch(
	std::exception const &_error
)
{
	awl::show_error_narrow(
		_error.what()
	);

	return
		awl::main::exit_failure();
}