当前位置: 首页>>代码示例>>C++>>正文


C++ GraphicContext::reset_frame_buffer方法代码示例

本文整理汇总了C++中GraphicContext::reset_frame_buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphicContext::reset_frame_buffer方法的具体用法?C++ GraphicContext::reset_frame_buffer怎么用?C++ GraphicContext::reset_frame_buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicContext的用法示例。


在下文中一共展示了GraphicContext::reset_frame_buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

void ShaderEffect::draw(GraphicContext &gc)
{
	gc.set_program_object(impl->program);

	if (!impl->fb.is_null())
		gc.set_frame_buffer(impl->fb);

	if (!impl->rasterizer_state.is_null())
		gc.set_rasterizer_state(impl->rasterizer_state);

	if (!impl->blend_state.is_null())
		gc.set_blend_state(impl->blend_state);

	if (!impl->depth_stencil_state.is_null())
		gc.set_depth_stencil_state(impl->depth_stencil_state);

	for (auto & elem : impl->uniform_bindings)
	{
		gc.set_uniform_buffer(elem.first, elem.second);
	}

	for (auto & elem : impl->storage_bindings)
	{
		gc.set_storage_buffer(elem.first, elem.second);
	}

	for (auto & elem : impl->image_bindings)
	{
		gc.set_image_texture(elem.first, elem.second);
	}

	for (auto & elem : impl->texture_bindings)
	{
		gc.set_texture(elem.first, elem.second);
	}

	if (!impl->elements.is_null())
	{
		gc.set_primitives_elements(impl->elements);
		gc.set_primitives_array(impl->prim_array);
		gc.draw_primitives_elements(type_triangles, impl->num_vertices, impl->elements_type);
		gc.reset_primitives_array();
		gc.reset_primitives_elements();
	}
	else
	{
		gc.set_primitives_array(impl->prim_array);
		gc.draw_primitives_array(type_triangles, 0, impl->num_vertices);
		gc.reset_primitives_array();
	}

	for (auto & elem : impl->uniform_bindings)
	{
		gc.reset_uniform_buffer(elem.first);
	}

	for (auto & elem : impl->storage_bindings)
	{
		gc.reset_storage_buffer(elem.first);
	}

	for (auto & elem : impl->image_bindings)
	{
		gc.reset_image_texture(elem.first);
	}

	for (auto & elem : impl->texture_bindings)
	{
		gc.reset_texture(elem.first);
	}

	if (!impl->rasterizer_state.is_null())
		gc.reset_rasterizer_state();

	if (!impl->blend_state.is_null())
		gc.reset_blend_state();

	if (!impl->depth_stencil_state.is_null())
		gc.reset_depth_stencil_state();

	if (!impl->fb.is_null())
		gc.reset_frame_buffer();

	gc.reset_program_object();
}
开发者ID:punkkeks,项目名称:ClanLib,代码行数:85,代码来源:shader_effect.cpp

示例2: run

void ParticleEmitterPass::run(GraphicContext &gc, Scene_Impl *scene)
{
	setup(gc);

	Size viewport_size = viewport->get_size();
	Mat4f eye_to_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 1.e10f, handed_left, gc.get_clip_z_range());
	Mat4f eye_to_cull_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 150.0f, handed_left, clip_negative_positive_w);
	FrustumPlanes frustum(eye_to_cull_projection * world_to_eye.get());

	for (size_t i = 0; i < active_emitters.size(); i++)
		active_emitters[i]->visible = false;
	scene->visit_emitters(gc, world_to_eye.get(), eye_to_projection, frustum, this);

	const int vectors_per_particle = 2;

	size_t total_particle_count = 0;
	for (size_t i = 0; i < active_emitters.size(); i++)
	{
		float depth_fade_distance = 1.0f;
		ParticleUniforms uniforms;
		uniforms.eye_to_projection = eye_to_projection;
		uniforms.object_to_eye = world_to_eye.get();
		uniforms.rcp_depth_fade_distance = 1.0f / depth_fade_distance;
		uniforms.instance_vectors_offset = total_particle_count * vectors_per_particle;
		active_emitters[i]->gpu_uniforms.upload_data(gc, &uniforms, 1);

		total_particle_count += active_emitters[i]->cpu_particles.size();
	}

	if (total_particle_count == 0)
		return;

	if (instance_texture.is_null() || instance_texture.get_width() < (int)total_particle_count)
	{
		instance_texture = Texture2D(gc, total_particle_count * vectors_per_particle, 1, tf_rgba32f);
		instance_transfer = TransferTexture(gc, total_particle_count * vectors_per_particle, 1, data_to_gpu, tf_rgba32f, 0, usage_stream_draw);
	}

	instance_transfer.lock(gc, access_write_discard);
	Vec4f *vectors = instance_transfer.get_data<Vec4f>();
	size_t vector_offset = 0;
	for (size_t j = 0; j < active_emitters.size(); j++)
	{
		Vec3f eye_pos = scene->get_camera().get_position();
		std::vector<ParticleOrderIndex> sorted_particles;
		sorted_particles.reserve(active_emitters[j]->cpu_particles.size());
		for (size_t i = 0; i < active_emitters[j]->cpu_particles.size(); i++)
		{
			Vec3f delta = active_emitters[j]->cpu_particles[i].position - eye_pos;
			sorted_particles.push_back(ParticleOrderIndex(i, Vec3f::dot(delta, delta)));
		}
		std::sort(sorted_particles.begin(), sorted_particles.end());

		for (size_t k = 0; k < sorted_particles.size(); k++)
		{
			int i = sorted_particles[k].index;
			float size = mix(active_emitters[j]->cpu_particles[i].start_size, active_emitters[j]->cpu_particles[i].end_size, active_emitters[j]->cpu_particles[i].life);
			vectors[vector_offset + k * vectors_per_particle + 0] = Vec4f(active_emitters[j]->cpu_particles[i].position, size);
			vectors[vector_offset + k * vectors_per_particle + 1] = Vec4f(active_emitters[j]->cpu_particles[i].life, 0.0f, 0.0f, 0.0f);
		}

		vector_offset += active_emitters[j]->cpu_particles.size() * vectors_per_particle;
	}
	instance_transfer.unlock();
	instance_texture.set_image(gc, instance_transfer);

	gc.set_depth_range(0.0f, 0.9f);

	gc.set_frame_buffer(fb);
	gc.set_viewport(viewport_size);
	gc.set_depth_stencil_state(depth_stencil_state);
	gc.set_blend_state(blend_state);
	gc.set_rasterizer_state(rasterizer_state);
	gc.set_primitives_array(prim_array);

	gc.set_program_object(program);
	gc.set_texture(0, normal_z_gbuffer.get());
	gc.set_texture(1, instance_texture);

	for (size_t i = 0; i < active_emitters.size(); i++)
	{
		gc.set_uniform_buffer(0, active_emitters[i]->gpu_uniforms);
		gc.set_texture(2, active_emitters[i]->particle_animation.get());
		gc.set_texture(3, active_emitters[i]->life_color_gradient.get());
		gc.draw_primitives_array_instanced(type_triangles, 0, 6, active_emitters[i]->cpu_particles.size());
	}

	gc.reset_primitives_array();
	gc.reset_rasterizer_state();
	gc.reset_depth_stencil_state();
	gc.reset_program_object();
	gc.reset_primitives_elements();
	gc.reset_texture(0);
	gc.reset_texture(1);
	gc.reset_texture(2);
	gc.reset_texture(3);
	gc.reset_uniform_buffer(0);
	gc.reset_frame_buffer();

	gc.set_depth_range(0.0f, 1.0f);
//.........这里部分代码省略.........
开发者ID:Cassie90,项目名称:ClanLib,代码行数:101,代码来源:particle_emitter_pass.cpp


注:本文中的GraphicContext::reset_frame_buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。