int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas)
	{
		if (use_glyph_program != false)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = false;
		}

		if (position == 0 || position + 6 > max_vertices)
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return RenderBatchTriangle::max_textures;
	}
	int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas, int num_vertices)
	{
		if (use_glyph_program != false)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = false;
		}

		if (position + num_vertices > max_vertices)
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();

		if (num_vertices > max_vertices)
			throw Exception("Too many vertices for RenderBatchTriangle");

		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return RenderBatchTriangle::max_textures;
	}
	int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas, const Texture2DPtr &texture, bool glyph_program, const Colorf &new_constant_color)
	{
		if (use_glyph_program != glyph_program || constant_color != new_constant_color)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = glyph_program;
			constant_color = new_constant_color;
		}

		int texindex = -1;
		for (int i = 0; i < num_current_textures; i++)
		{
			if (current_textures[i] == texture)
			{
				texindex = i;
				break;
			}
		}
		if (texindex == -1 && num_current_textures < max_textures)
		{
			texindex = num_current_textures;
			current_textures[num_current_textures++] = texture;
			tex_sizes[texindex] = Sizef((float)current_textures[texindex]->width(), (float)current_textures[texindex]->height());
		}

		if (position == 0 || position + 6 > max_vertices || texindex == -1)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			texindex = 0;
			current_textures[texindex] = texture;
			num_current_textures = 1;
			tex_sizes[texindex] = Sizef((float)current_textures[texindex]->width(), (float)current_textures[texindex]->height());
		}
		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return texindex;
	}
Beispiel #4
0
	void Font_DrawFlat::draw_text(const CanvasPtr &canvas, const Pointf &position, const std::string &text, const Colorf &color, float line_spacing)
	{
		float offset_x = 0;
		float offset_y = 0;
		UTF8_Reader reader(text.data(), text.length());
		RenderBatchTriangle *batcher = static_cast<CanvasImpl*>(canvas.get())->batcher.get_triangle_batcher();

		while (!reader.is_end())
		{
			unsigned int glyph = reader.character();
			reader.next();

			if (glyph == '\n')
			{
				offset_x = 0;
				offset_y += line_spacing;
				continue;
			}

			Font_TextureGlyph *gptr = glyph_cache->get_glyph(canvas, font_engine, glyph);
			if (gptr)
			{
				if (gptr->texture)
				{
					float xp = offset_x + position.x + gptr->offset.x;
					float yp = offset_y + position.y + gptr->offset.y;
					Pointf pos = canvas->grid_fit(Pointf(xp, yp));

					Rectf dest_size(pos, gptr->size);
					batcher->draw_image(canvas, gptr->geometry, dest_size, color, gptr->texture);
				}
				offset_x += gptr->metrics.advance.width;
				offset_y += gptr->metrics.advance.height;
			}
		}
	}