Exemple #1
0
 std::shared_ptr<sample_type const> acquire(std::string const& name)
 {
     auto sample = get_sampler(name)->acquire();
     if (sample->type() != (sample_type::gpu ? typeid(gpu_sample<typename sample_type::data_type>) : typeid(typename sample_type::data_type))) {
         throw std::runtime_error("invalid sample data type");
     }
     return std::static_pointer_cast<sample_type const>(sample);
 }
void init (char **argv) {
    int argc = 0;
    while (argv[++argc]);
    if (3 > argc) usage(argv[0]);
    /* convert degrees to rotation matrix and store for later */
    theta = strtold(argv[1], NULL) * M_PI / 180;
    theta = COS(theta) + SIN(theta) * I;
    real_sample = (sampler())get_sampler(&argv[2]);
}
void noob::graphics::init(uint32_t width, uint32_t height)
{
	uint32_t reset = BGFX_RESET_VSYNC;
	bgfx::reset(width, height, reset);
	
	bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
	bgfx::setViewClear(1, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
	bgfx::setState(BGFX_STATE_DEFAULT);
	/// Predefined uniforms (declared in `bgfx_shader.sh`):
	///   - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
	///     view.
	///   - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
	///     width and height
	///   - `u_view mat4` - view matrix
	///   - `u_invView mat4` - inverted view matrix
	///   - `u_proj mat4` - projection matrix
	///   - `u_invProj mat4` - inverted projection matrix
	///   - `u_viewProj mat4` - concatenated view projection matrix
	///   - `u_invViewProj mat4` - concatenated inverted view projection matrix
	///   - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
	///   - `u_modelView mat4` - concatenated model view matrix, only first
	///     model matrix from array is used.
	///   - `u_modelViewProj mat4` - concatenated model view projection matrix.
	///   - `u_alphaRef float` - alpha reference value for alpha test.	
	// Add initial defaults (invalid stuff) to map
	
	bgfx::ProgramHandle h;
	h.idx = bgfx::invalidHandle;
	noob::graphics::shader shad;
	shad.program = h;

	noob::graphics::add_shader(std::string("invalid"), shad);

	noob::graphics::add_uniform(std::string("invalid"), bgfx::UniformType::Enum::Int1, 0);
	invalid_uniform = get_uniform("invalid");
	noob::graphics::add_uniform(std::string("colour_0"), bgfx::UniformType::Enum::Vec4, 1);
	colour_0 = get_uniform("colour_0");
	noob::graphics::add_uniform(std::string("colour_1"), bgfx::UniformType::Enum::Vec4, 1);
	colour_1 = get_uniform("colour_1");
	noob::graphics::add_uniform(std::string("colour_2"), bgfx::UniformType::Enum::Vec4, 1);
	colour_2 = get_uniform("colour_2");
	noob::graphics::add_uniform(std::string("colour_3"), bgfx::UniformType::Enum::Vec4, 1);
	colour_3 = get_uniform("colour_3");
	noob::graphics::add_uniform(std::string("blend_0"), bgfx::UniformType::Enum::Vec4, 1);
	blend_0 = get_uniform("blend_0");
	noob::graphics::add_uniform(std::string("blend_1"), bgfx::UniformType::Enum::Vec4, 1);
	blend_1 = get_uniform("blend_1");
	noob::graphics::add_uniform(std::string("scales"), bgfx::UniformType::Enum::Vec4, 1);
	scales = get_uniform("scales");
	noob::graphics::add_uniform(std::string("basic_light_0"), bgfx::UniformType::Enum::Vec4, 1);
	basic_light_0 = get_uniform("basic_light_0");
	noob::graphics::add_uniform(std::string("basic_light_1"), bgfx::UniformType::Enum::Vec4, 1);
	basic_light_1 = get_uniform("basic_light_1");
	noob::graphics::add_uniform(std::string("normal_mat"), bgfx::UniformType::Enum::Mat4, 1);
	normal_mat = get_uniform("normal_mat");

	noob::graphics::add_sampler(std::string("invalid"));
	invalid_texture = get_sampler("invalid");
	noob::graphics::add_sampler("texture_0");
	texture_0 = get_sampler("texture_0");

}
Exemple #4
0
 void set(std::string const& name, std::shared_ptr<sample_base const> sample) {
     get_sampler(name)->set(sample);
 }