Exemplo n.º 1
0
void RenderBatchPoint::flush(GraphicContext &gc)
{
	if (position > 0)
	{
		gc.set_program_object(program_color_only);

		int gpu_index;
		VertexArrayVector<PointVertex> gpu_vertices(batch_buffer->get_vertex_buffer(gc, gpu_index));

		if (prim_array[gpu_index].is_null())
		{
			prim_array[gpu_index] = PrimitivesArray(gc);
			prim_array[gpu_index].set_attributes(0, gpu_vertices, cl_offsetof(PointVertex, position));
			prim_array[gpu_index].set_attributes(1, gpu_vertices, cl_offsetof(PointVertex, color));
		}

		gpu_vertices.upload_data(gc, 0, vertices, position);

		gc.draw_primitives(type_points, position, prim_array[gpu_index]);

		gc.reset_program_object();

		position = 0;
	}
}
Exemplo n.º 2
0
void RenderBatchTriangle::flush(GraphicContext &gc)
{
	if (position > 0)
	{
		gc.set_program_object(program_sprite);

		int gpu_index;
		VertexArrayVector<SpriteVertex> gpu_vertices(batch_buffer->get_vertex_buffer(gc, gpu_index));

		if (prim_array[gpu_index].is_null())
		{
			prim_array[gpu_index] = PrimitivesArray(gc);
			prim_array[gpu_index].set_attributes(0, gpu_vertices, cl_offsetof(SpriteVertex, position));
			prim_array[gpu_index].set_attributes(1, gpu_vertices, cl_offsetof(SpriteVertex, color));
			prim_array[gpu_index].set_attributes(2, gpu_vertices, cl_offsetof(SpriteVertex, texcoord));
			prim_array[gpu_index].set_attributes(3, gpu_vertices, cl_offsetof(SpriteVertex, texindex));

			if (glyph_blend.is_null())
			{
				BlendStateDescription blend_desc;
				blend_desc.set_blend_function(blend_constant_color, blend_one_minus_src_color, blend_zero, blend_one);
				glyph_blend = BlendState(gc, blend_desc);
			}
		}

		gpu_vertices.upload_data(gc, 0, vertices, position);

		for (int i = 0; i < num_current_textures; i++)
			gc.set_texture(i, current_textures[i]);

		if (use_glyph_program)
		{
			gc.set_blend_state(glyph_blend, constant_color);
			gc.draw_primitives(type_triangles, position, prim_array[gpu_index]);
			gc.reset_blend_state();
		}
		else
		{
			gc.draw_primitives(type_triangles, position, prim_array[gpu_index]);
		}

		for (int i = 0; i < num_current_textures; i++)
			gc.reset_texture(i);

		gc.reset_program_object();

		position = 0;
		for (int i = 0; i < num_current_textures; i++)
			current_textures[i] = Texture2D();
		num_current_textures = 0;

	}
}
Exemplo n.º 3
0
	void RenderBatchTriangle::flush(const GraphicContextPtr &gc)
	{
		if (position > 0)
		{
			gc->set_program_object(program_sprite);

			int gpu_index;
			VertexArrayVector<SpriteVertex> gpu_vertices(batch_buffer->get_vertex_buffer(gc, gpu_index));

			if (!prim_array[gpu_index])
			{
				prim_array[gpu_index] = PrimitivesArray::create(gc);
				prim_array[gpu_index]->set_attributes(0, gpu_vertices, cl_offsetof(SpriteVertex, position));
				prim_array[gpu_index]->set_attributes(1, gpu_vertices, cl_offsetof(SpriteVertex, color));
				prim_array[gpu_index]->set_attributes(2, gpu_vertices, cl_offsetof(SpriteVertex, texcoord));
				prim_array[gpu_index]->set_attributes(3, gpu_vertices, cl_offsetof(SpriteVertex, texindex));

				if (!glyph_blend)
				{
					BlendStateDescription blend_desc;
					blend_desc.set_blend_function(blend_constant_color, blend_one_minus_src_color, blend_zero, blend_one);
					glyph_blend = gc->create_blend_state(blend_desc);
				}
			}

			gpu_vertices.upload_data(gc, 0, vertices, position);

			for (int i = 0; i < num_current_textures; i++)
				gc->set_texture(i, current_textures[i]);

#ifdef _DEBUG // Suppress a warning when the D3D debug layer is active (to do: add a boolean on gc that can report if a debug layer is present)
			if (num_current_textures > 0)
			{
				for (int i = num_current_textures; i < max_textures; i++)
					gc->set_texture(i, current_textures[0]);
			}
#endif

			if (use_glyph_program)
			{
				gc->set_blend_state(glyph_blend, constant_color);
				gc->draw_primitives(type_triangles, position, prim_array[gpu_index]);
				gc->reset_blend_state();
			}
			else
			{
				gc->draw_primitives(type_triangles, position, prim_array[gpu_index]);
			}

			for (int i = 0; i < num_current_textures; i++)
				gc->reset_texture(i);

#ifdef _DEBUG // Suppress a warning when the D3D debug layer is active (to do: add a boolean on gc that can report if a debug layer is present)
			if (num_current_textures > 0)
			{
				for (int i = num_current_textures; i < max_textures; i++)
					gc->reset_texture(i);
			}
#endif

			gc->reset_program_object();

			position = 0;
			for (int i = 0; i < num_current_textures; i++)
				current_textures[i] = Texture2DPtr();
			num_current_textures = 0;

		}
	}