Blame c++/contourgl/test.cpp

93cbac
/*
93cbac
    ......... 2015 Ivan Mahonin
93cbac
93cbac
    This program is free software: you can redistribute it and/or modify
93cbac
    it under the terms of the GNU General Public License as published by
93cbac
    the Free Software Foundation, either version 3 of the License, or
93cbac
    (at your option) any later version.
93cbac
93cbac
    This program is distributed in the hope that it will be useful,
93cbac
    but WITHOUT ANY WARRANTY; without even the implied warranty of
93cbac
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
93cbac
    GNU General Public License for more details.
93cbac
93cbac
    You should have received a copy of the GNU General Public License
93cbac
    along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
93cbac
*/
93cbac
93cbac
#include <fstream></fstream>
93cbac
#include <iostream></iostream>
c7fa36
#include <iomanip></iomanip>
93cbac
93cbac
#include "test.h"
93cbac
#include "contourbuilder.h"
8cd87e
#include "triangulator.h"
49e693
#include "measure.h"
49e693
#include "utils.h"
d989ab
#include "clrender.h"
93cbac
93cbac
93cbac
using namespace std;
93cbac
93cbac
49e693
void Test::draw_contour(int start, int count, bool even_odd, bool invert, const Color &color) {
49e693
	glEnable(GL_STENCIL_TEST);
93cbac
49e693
	// render mask
a04770
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
49e693
	glClear(GL_STENCIL_BUFFER_BIT);
49e693
	glStencilFunc(GL_ALWAYS, 0, 0);
49e693
	if (even_odd) {
49e693
		glStencilOp(GL_INCR_WRAP, GL_INCR_WRAP, GL_INCR_WRAP);
93cbac
	} else {
49e693
		glStencilOpSeparate(GL_FRONT, GL_INCR_WRAP, GL_INCR_WRAP, GL_INCR_WRAP);
49e693
		glStencilOpSeparate(GL_BACK, GL_DECR_WRAP, GL_DECR_WRAP, GL_DECR_WRAP);
49e693
	}
49e693
	e.shaders.simple();
49e693
	glDrawArrays(GL_TRIANGLE_STRIP, start, count);
a04770
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
49e693
49e693
	// fill mask
49e693
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
49e693
	if (!even_odd && !invert)
49e693
		glStencilFunc(GL_NOTEQUAL, 0, -1);
49e693
	if (!even_odd &&  invert)
49e693
		glStencilFunc(GL_EQUAL, 0, -1);
49e693
	if ( even_odd && !invert)
49e693
		glStencilFunc(GL_EQUAL, 1, 1);
49e693
	if ( even_odd &&  invert)
49e693
		glStencilFunc(GL_EQUAL, 0, 1);
49e693
49e693
	e.shaders.color(color);
49e693
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
49e693
49e693
	glDisable(GL_STENCIL_TEST);
7c6b57
}
7c6b57
9edf2e
void Test::load(std::vector<contourinfo> &contours, const std::string &filename) {</contourinfo>
9edf2e
	vector<vector> groups;</vector>
9edf2e
	groups.push_back(Vector());
9edf2e
9edf2e
	ifstream f("data/contours.txt");
9edf2e
	int vertices_count = 0;
9edf2e
	while(f) {
9edf2e
		string s;
9edf2e
		f >> s;
9edf2e
		if (s == "g") {
9edf2e
			Vector t;
9edf2e
			f >> t.x >> t.y;
9edf2e
			groups.push_back(groups.back() + t);
9edf2e
		} else
9edf2e
		if (s == "end") {
9edf2e
			groups.pop_back();
9edf2e
			if ((int)groups.size() == 1)
9edf2e
				break;
9edf2e
		} else
9edf2e
		if (s == "path") {
9edf2e
			contours.push_back(ContourInfo());
9edf2e
			ContourInfo &ci = contours.back();
9edf2e
			f >> ci.invert
9edf2e
			  >> ci.antialias
9edf2e
			  >> ci.evenodd
9edf2e
			  >> ci.color.r
9edf2e
			  >> ci.color.g
9edf2e
			  >> ci.color.b
9edf2e
			  >> ci.color.a;
9edf2e
			bool closed = true;
9edf2e
			while(true) {
9edf2e
				f >> s;
9edf2e
				Vector p1;
9edf2e
				if (s == "M") {
9edf2e
					f >> p1.x >> p1.y;
9edf2e
					ci.contour.move_to(p1 + groups.back());
9edf2e
					closed = false;
9edf2e
				} else
9edf2e
				if (s == "L") {
9edf2e
					f >> p1.x >> p1.y;
9edf2e
					if (closed) {
9edf2e
						ci.contour.move_to(p1 + groups.back());
9edf2e
						closed = false;
9edf2e
					}
9edf2e
					ci.contour.line_to(p1 + groups.back());
9edf2e
				} else
9edf2e
				if (s == "Z") {
9edf2e
					ci.contour.close();
9edf2e
					closed = true;
9edf2e
				} else
9edf2e
				if (s == "end") {
9edf2e
					break;
9edf2e
				} else {
9edf2e
					cout << "bug " << s << endl;
9edf2e
					if (!f) break;
9edf2e
				}
9edf2e
			}
9edf2e
			if (!closed)
9edf2e
				ci.contour.close();
9edf2e
			if (ci.color.a < 0.9999)
9edf2e
				contours.pop_back();
9edf2e
			else
9edf2e
				vertices_count += ci.contour.get_chunks().size();
9edf2e
		} else
9edf2e
		if (s != "") {
9edf2e
			cout << "bug " << s << endl;
9edf2e
		}
9edf2e
	}
9edf2e
	if ((int)groups.size() != 1)
9edf2e
		cout << "bug groups " << groups.size() << endl;
9edf2e
9edf2e
	cout << contours.size() << " contours" << endl;
9edf2e
	cout << vertices_count << " vertices" << endl;
9edf2e
}
9edf2e
9edf2e
93cbac
void Test::test2() {
93cbac
	Contour c, cc;
93cbac
	ContourBuilder::build(cc);
93cbac
	cout << cc.get_chunks().size() << " commands" << endl;
93cbac
49e693
	Vector frame_size = Utils::get_frame_size();
831e90
93cbac
	Rect bounds;
93cbac
	bounds.p0 = Vector(-1.0, -1.0);
93cbac
	bounds.p1 = Vector( 1.0,  1.0);
831e90
	Vector min_size(1.75/frame_size.x, 1.75/frame_size.y);
93cbac
93cbac
	{
49e693
		Measure t("test_2_split");
93cbac
		cc.split(c, bounds, min_size);
93cbac
	}
93cbac
93cbac
	const Contour::ChunkList &chunks = c.get_chunks();
93cbac
	cout << chunks.size() << " vertices" << endl;
93cbac
7c6b57
	GLuint buffer_id = 0;
7c6b57
	GLuint array_id = 0;
8de121
	int count = 0;
a04770
	vector<vec2f> vertices;</vec2f>
8de121
8de121
	{
49e693
		Measure t("test_2_init_buffer");
7c6b57
		vertices.resize(4+4*chunks.size());
7c6b57
		glGenBuffers(1, &buffer_id);
7c6b57
		glBindBuffer(GL_ARRAY_BUFFER, buffer_id);
8de121
		glBufferData( GL_ARRAY_BUFFER,
a04770
				      vertices.size()*sizeof(vec2f),
8de121
					  &vertices.front(),
8de121
					  GL_DYNAMIC_DRAW );
7c6b57
7c6b57
		glGenVertexArrays(1, &array_id);
7c6b57
		glBindVertexArray(array_id);
8de121
7c6b57
		glEnableVertexAttribArray(0);
7c6b57
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_TRUE, 0, NULL);
7704aa
49e693
		e.shaders.color(Color(0.f, 0.f, 1.f, 1.f));
7c6b57
		glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
7c6b57
		glFinish();
a80036
		glClear(GL_COLOR_BUFFER_BIT);
a80036
		glFinish();
a04770
a04770
		vertices.clear();
a04770
		vertices.reserve(4+4*chunks.size());
a80036
	}
8de121
8de121
	{
49e693
		Measure t("test_2_prepare_data");
a04770
		vertices.push_back(vec2f(bounds.p0.x, bounds.p0.y));
a04770
		vertices.push_back(vec2f(bounds.p0.x, bounds.p1.y));
a04770
		vertices.push_back(vec2f(bounds.p1.x, bounds.p0.y));
a04770
		vertices.push_back(vec2f(bounds.p1.x, bounds.p1.y));
a04770
		vertices.push_back(vec2f());
a04770
		vertices.push_back(vec2f());
8de121
		for(Contour::ChunkList::const_iterator i = chunks.begin(); i != chunks.end(); ++i) {
8de121
			if ( i->type == Contour::LINE
8de121
			  || i->type == Contour::CLOSE)
8de121
			{
a04770
				vertices.push_back(vec2f(i->p1));
a04770
				vertices.push_back(vec2f(-1.f, (float)i->p1.y));
8de121
			} else {
8de121
				vertices.push_back(vertices.back());
a80036
				vertices.push_back(vertices.back());
a04770
				vertices.push_back(vec2f(i->p1));
a80036
				vertices.push_back(vertices.back());
8de121
			}
8de121
		}
7c6b57
		count = vertices.size() - 4;
8de121
	}
8de121
8de121
	{
49e693
		Measure t("test_2_send_data");
a80036
		glBufferSubData( GL_ARRAY_BUFFER,
a80036
						 0,
7c6b57
					     vertices.size()*sizeof(vertices.front()),
a80036
					     &vertices.front() );
8de121
	}
8de121
93cbac
	{
49e693
		Measure t("test_2_simple_fill.tga");
7c6b57
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
93cbac
	}
93cbac
6e407d
	{
49e693
		Measure t("test_2_array.tga");
7c6b57
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
7c6b57
		glDrawArrays(GL_TRIANGLE_STRIP, 4, count);
7c6b57
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
6e407d
	}
6e407d
93cbac
	{
49e693
		Measure t("test_2_contour_fill.tga");
49e693
		draw_contour(4, count, false, false, Color(0.f, 0.f, 1.f, 1.f));
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_2_contour_fill_invert.tga");
49e693
		draw_contour(4, count, false, true, Color(0.f, 0.f, 1.f, 1.f));
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_2_contour_evenodd.tga");
49e693
		draw_contour(4, count, true, false, Color(0.f, 0.f, 1.f, 1.f));
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_2_contour_evenodd_invert.tga");
49e693
		draw_contour(4, count, true, true, Color(0.f, 0.f, 1.f, 1.f));
93cbac
	}
93cbac
a80036
	glBindBuffer(GL_ARRAY_BUFFER, 0);
7c6b57
	glDeleteBuffers(1, &buffer_id);
93cbac
}
93cbac
93cbac
void Test::test3() {
93cbac
	Contour c;
93cbac
	ContourBuilder::build(c);
93cbac
	cout << c.get_chunks().size() << " commands" << endl;
93cbac
49e693
	Vector frame_size = Utils::get_frame_size();
831e90
	int width = (int)frame_size.x;
831e90
	int height = (int)frame_size.y;
831e90
93cbac
	Rect bounds;
93cbac
	bounds.p0 = Vector(-1.0, -1.0);
93cbac
	bounds.p1 = Vector( 1.0,  1.0);
93cbac
	Rect pixel_bounds;
831e90
	pixel_bounds.p0 = Vector::zero();
831e90
	pixel_bounds.p1 = frame_size;
93cbac
93cbac
	c.transform(bounds, pixel_bounds);
93cbac
93cbac
	Polyspan polyspan;
831e90
	polyspan.init(0, 0, width, height);
93cbac
831e90
	Surface surface(width, height);
93cbac
	Color color(0.f, 0.f, 1.f, 1.f);
93cbac
93cbac
	{
49e693
		Measure t("test_3_build_polyspan");
93cbac
		c.to_polyspan(polyspan);
93cbac
	}
93cbac
93cbac
	cout << polyspan.get_covers().size() << " covers" << endl;
93cbac
93cbac
	glPushAttrib(GL_ALL_ATTRIB_BITS);
93cbac
	glColor4d(0.0, 0.0, 1.0, 1.0);
93cbac
	{
49e693
		Measure t("test_3_polyspan_gl_lines.tga");
93cbac
		glBegin(GL_LINE_STRIP);
93cbac
		for(Polyspan::cover_array::const_iterator i = polyspan.get_covers().begin(); i != polyspan.get_covers().end(); ++i)
93cbac
			glVertex2d((double)i->x/1024.0*2.0 - 1.0, (double)i->y/1024.0*2.0 - 1.0);
93cbac
		glEnd();
93cbac
	}
93cbac
	glPopAttrib();
93cbac
93cbac
93cbac
	{
49e693
		Measure t("test_3_polyspan_sort");
93cbac
		polyspan.sort_marks();
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_3_polyspan_fill.tga", surface);
572d9c
		SwRender::polyspan(surface, polyspan, color, false, false);
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_3_polyspan_fill_invert.tga", surface);
572d9c
		SwRender::polyspan(surface, polyspan, color, false, true);
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_3_polyspan_evenodd.tga", surface);
572d9c
		SwRender::polyspan(surface, polyspan, color, true, false);
93cbac
	}
93cbac
93cbac
	{
49e693
		Measure t("test_3_polyspan_evenodd_invert.tga", surface);
572d9c
		SwRender::polyspan(surface, polyspan, color, true, true);
93cbac
	}
93cbac
}
93cbac
9edf2e
void Test::test4() {
49e693
	Vector frame_size = Utils::get_frame_size();
9edf2e
	int width = (int)frame_size.x;
9edf2e
	int height = (int)frame_size.y;
9edf2e
9edf2e
	Rect bounds_gl;
9edf2e
	bounds_gl.p0 = Vector(-1.0, -1.0);
9edf2e
	bounds_gl.p1 = Vector( 1.0,  1.0);
9edf2e
9edf2e
	Rect bounds_sw;
9edf2e
	bounds_sw.p0 = Vector();
9edf2e
	bounds_sw.p1 = frame_size;
9edf2e
c7fa36
	Rect bounds_cl = bounds_sw;
c7fa36
9edf2e
	Rect bounds_file;
9edf2e
	bounds_file.p0 = Vector(0.0, 450.0);
9edf2e
	bounds_file.p1 = Vector(500.0, -50.0);
9edf2e
9edf2e
	vector<contourinfo> contours;</contourinfo>
9edf2e
	load(contours, "contours.txt");
9edf2e
9edf2e
	{
9edf2e
		// opengl
9edf2e
9edf2e
		vector<contourinfo> contours_gl = contours;</contourinfo>
9edf2e
		int commands_count = 0;
9edf2e
		for(vector<contourinfo>::iterator i = contours_gl.begin(); i != contours_gl.end(); ++i) {</contourinfo>
9edf2e
			i->contour.transform(bounds_file, bounds_gl);
9edf2e
			commands_count += i->contour.get_chunks().size();
9edf2e
		}
9edf2e
8cd87e
		// gl_stencil
8cd87e
9edf2e
		{
a04770
			Measure t("test_4_gl_stencil", true);
9edf2e
a04770
			GLuint buffer_id = 0;
a04770
			GLuint array_id = 0;
a04770
			vector<vec2f> vertices;</vec2f>
a04770
			vector<int> starts(contours_gl.size());</int>
a04770
			vector<int> counts(contours_gl.size());</int>
9edf2e
a04770
			{
a04770
				//Measure t("test_4_gl_init_buffer");
a04770
				vertices.resize(4 + 4*commands_count + 2*contours_gl.size());
a04770
				glGenBuffers(1, &buffer_id);
a04770
				glBindBuffer(GL_ARRAY_BUFFER, buffer_id);
a04770
				glBufferData( GL_ARRAY_BUFFER,
a04770
							  vertices.size()*sizeof(vec2f),
a04770
							  &vertices.front(),
a04770
							  GL_DYNAMIC_DRAW );
a04770
				vertices.clear();
a04770
				vertices.reserve(4 + 4*commands_count);
a04770
a04770
				glGenVertexArrays(1, &array_id);
a04770
				glBindVertexArray(array_id);
a04770
a04770
				glEnableVertexAttribArray(0);
a04770
				glVertexAttribPointer(0, 2, GL_FLOAT, GL_TRUE, 0, NULL);
a04770
a04770
				e.shaders.color(Color(0.f, 0.f, 1.f, 1.f));
a04770
				glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
a04770
				glFinish();
a04770
				glClear(GL_COLOR_BUFFER_BIT);
a04770
				glFinish();
a04770
			}
9edf2e
a04770
			{
a04770
				//Measure t("test_4_gl_stencil_prepare_data");
a04770
				vertices.push_back(vec2f(bounds_gl.p0.x, bounds_gl.p0.y));
a04770
				vertices.push_back(vec2f(bounds_gl.p0.x, bounds_gl.p1.y));
a04770
				vertices.push_back(vec2f(bounds_gl.p1.x, bounds_gl.p0.y));
a04770
				vertices.push_back(vec2f(bounds_gl.p1.x, bounds_gl.p1.y));
a04770
				for(int i = 0; i < (int)contours_gl.size(); ++i) {
a04770
					starts[i] = (int)vertices.size();
a04770
					const Contour::ChunkList &chunks = contours_gl[i].contour.get_chunks();
a04770
					for(Contour::ChunkList::const_iterator j = chunks.begin(); j != chunks.end(); ++j) {
a04770
						if (j->type == Contour::LINE) {
a04770
							vertices.push_back(vec2f(j->p1));
a04770
							vertices.push_back(vec2f(-1.f, (float)j->p1.y));
a04770
						} else
a04770
						if (j->type == Contour::CLOSE) {
a04770
							vertices.push_back(vec2f(j->p1));
a04770
							vertices.push_back(vec2f(-1.f, (float)j->p1.y));
a04770
						} else {
a04770
							vertices.push_back(vertices.back());
a04770
							vertices.push_back(vec2f(j->p1));
a04770
							vertices.push_back(vertices.back());
a04770
							vertices.push_back(vec2f(-1.f, (float)j->p1.y));
a04770
						}
9edf2e
					}
a04770
					counts[i] = (int)vertices.size() - starts[i];
9edf2e
				}
9edf2e
			}
9edf2e
a04770
			{
c7fa36
				//Measure t("test_4_gl_stencil_send_data");
a04770
				glBufferSubData( GL_ARRAY_BUFFER,
a04770
								 0,
a04770
								 vertices.size()*sizeof(vertices.front()),
a04770
								 &vertices.front() );
a04770
			}
9edf2e
a04770
			{
a04770
				//Measure t("test_4_gl_stencil_points.tga");
a04770
				//glDrawArrays(GL_POINTS, 0, vertices.size());
a04770
			}
8cd87e
a04770
			{
c7fa36
				Measure t("test_4_gl_stencil_render.tga");
a04770
				for(int i = 0; i < (int)contours_gl.size(); ++i) {
a04770
					draw_contour(
a04770
						starts[i],
a04770
						counts[i],
a04770
						contours_gl[i].invert,
a04770
						contours_gl[i].evenodd,
a04770
						contours_gl[i].color );
a04770
				}
9edf2e
			}
9edf2e
		}
8cd87e
8cd87e
		// gl_triangles
028154
		/*
c7fa36
8cd87e
		{
c7fa36
			Measure t("test_4_gl_triangles", false);
8cd87e
a04770
			GLuint index_buffer_id = 0;
a04770
			vector<int> triangle_starts(contours_gl.size());</int>
a04770
			vector<int> triangle_counts(contours_gl.size());</int>
a04770
			vector<int> triangles;</int>
c7fa36
			vector<vec2f> vertices;</vec2f>
a04770
			vertices.reserve(commands_count);
a04770
a04770
			{
a04770
				//Measure t("test_4_gl_init_index_buffer");
a04770
				triangles.resize(3*commands_count);
a04770
				glGenBuffers(1, &index_buffer_id);
a04770
				glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id);
a04770
				glBufferData( GL_ELEMENT_ARRAY_BUFFER,
a04770
							  triangles.size()*sizeof(triangles.front()),
a04770
							  &triangles.front(),
a04770
							  GL_DYNAMIC_DRAW );
a04770
				triangles.clear();
a04770
				triangles.reserve(3*commands_count);
a04770
			}
a04770
a04770
			{
a04770
				Measure t("test_4_gl_triangulate");
a04770
				int index_offset = 4;
a04770
				for(int i = 0; i < (int)contours_gl.size(); ++i) {
a04770
					triangle_starts[i] = (int)triangles.size();
a04770
					Triangulator::triangulate(contours_gl[i].contour, triangles, index_offset);
a04770
					triangle_counts[i] = (int)triangles.size() - triangle_starts[i];
a04770
					index_offset += (int)contours_gl[i].contour.get_chunks().size();
a04770
				}
8cd87e
			}
8cd87e
c7fa36
			cout << triangles.size() << " triangles" << endl;
8cd87e
a04770
			{
a04770
				//Measure t("test_4_gl_triangles_prepare_vertices");
a04770
				for(int i = 0; i < (int)contours_gl.size(); ++i) {
a04770
					const Contour::ChunkList &chunks = contours_gl[i].contour.get_chunks();
a04770
					for(Contour::ChunkList::const_iterator j = chunks.begin(); j != chunks.end(); ++j)
a04770
						vertices.push_back(vec2f(j->p1));
a04770
				}
8cd87e
			}
8cd87e
a04770
			{
a04770
				Measure t("test_4_gl_triangles_send_data");
a04770
				glBufferSubData( GL_ARRAY_BUFFER,
a04770
								 4*sizeof(vertices.front()),
a04770
								 vertices.size()*sizeof(vertices.front()),
a04770
								 &vertices.front() );
a04770
				glBufferSubData( GL_ELEMENT_ARRAY_BUFFER,
a04770
								 0,
a04770
								 triangles.size()*sizeof(triangles.front()),
a04770
								 &triangles.front() );
a04770
			}
8cd87e
a04770
			{
c7fa36
				Measure t("test_4_gl_triangles.tga");
a04770
				for(int i = 0; i < (int)contours_gl.size(); ++i) {
a04770
					e.shaders.color(contours_gl[i].color);
a04770
					glDrawElements(GL_TRIANGLES, triangle_counts[i], GL_UNSIGNED_INT, (char*)NULL + triangle_starts[i]*sizeof(int));
a04770
				}
8cd87e
			}
c7fa36
8cd87e
		}
028154
		*/
9edf2e
	}
9edf2e
9edf2e
	{
9edf2e
		// software
9edf2e
a04770
		Surface surface(width, height);
c7fa36
		Measure t("test_4_sw.tga", surface, false);
a04770
9edf2e
		vector<contourinfo> contours_sw = contours;</contourinfo>
9edf2e
		for(vector<contourinfo>::iterator i = contours_sw.begin(); i != contours_sw.end(); ++i)</contourinfo>
9edf2e
			i->contour.transform(bounds_file, bounds_sw);
9edf2e
c7fa36
		int count = 0;
9edf2e
		vector<polyspan> polyspans(contours_sw.size());</polyspan>
9edf2e
		{
49e693
			Measure t("test_4_sw_build_polyspans");
9edf2e
			for(int i = 0; i < (int)contours_sw.size(); ++i) {
9edf2e
				polyspans[i].init(0, 0, width, height);
9edf2e
				contours_sw[i].contour.to_polyspan(polyspans[i]);
c7fa36
				count += polyspans[i].get_covers().size();
9edf2e
				polyspans[i].sort_marks();
9edf2e
			}
9edf2e
		}
9edf2e
c7fa36
		cout << setbase(10) << count << endl;
c7fa36
9edf2e
		{
a04770
			Measure t("test_4_sw_render_polyspans");
9edf2e
			for(int i = 0; i < (int)contours_sw.size(); ++i)
572d9c
				SwRender::polyspan(surface, polyspans[i], contours_sw[i].color, contours_sw[i].evenodd, contours_sw[i].invert);
9edf2e
		}
9edf2e
	}
d989ab
d989ab
	{
d989ab
		// cl
d989ab
a04770
		Surface surface(width, height);
c7fa36
c7fa36
		Measure t("test_4_cl.tga", surface, true);
c7fa36
d989ab
		vector<contourinfo> contours_cl = contours;</contourinfo>
c7fa36
		vector<vec2f> paths;</vec2f>
c7fa36
		vector<int> starts(contours_cl.size());</int>
c7fa36
		vector<int> counts(contours_cl.size());</int>
c7fa36
		for(int i = 0; i < (int)contours_cl.size(); ++i) {
c7fa36
			contours_cl[i].contour.transform(bounds_file, bounds_cl);
c7fa36
			starts[i] = paths.size();
c7fa36
			for(Contour::ChunkList::const_iterator j = contours_cl[i].contour.get_chunks().begin(); j != contours_cl[i].contour.get_chunks().end(); ++j)
c7fa36
				paths.push_back(vec2f(j->p1));
c7fa36
			paths.push_back(paths[starts[i]]);
c7fa36
			counts[i] = paths.size() - starts[i];
c7fa36
		}
c7fa36
d989ab
		ClRender clr(e.cl);
c7fa36
		clr.send_surface(&surface);
c7fa36
		clr.send_path(&paths.front(), paths.size());
c7fa36
67876c
		{
c7fa36
			Measure t("test_4_cl_render");
c7fa36
			for(int i = 0; i < (int)contours_cl.size(); ++i)
c7fa36
				clr.path(starts[i], counts[i], contours_cl[i].color, contours_cl[i].invert, contours_cl[i].evenodd);
c7fa36
			clr.wait();
67876c
		}
c7fa36
c7fa36
		clr.receive_surface();
c7fa36
	}
c7fa36
}
c7fa36
c7fa36
void ClRender::wait() {
c7fa36
	if (prev_event) {
c7fa36
		clWaitForEvents(1, &prev_event);
c7fa36
		prev_event = NULL;
d989ab
	}
9edf2e
}