Beispiel #1
0
void VertexBuffer::UploadStaticVertexData(
	std::vector<Object> & objects,
	const std::vector<const VertexArray *> & varrays,
	std::vector<unsigned int> & index_buffer,
	std::vector<float> & vertex_buffer)
{
	unsigned int varray_index = 0;
	for (unsigned int i = 1; i < objects.size(); ++i)
	{
		Object & ob = objects[i];
		const VertexFormat & vf = VertexFormat::Get(ob.vformat);
		const unsigned int vertex_size = vf.stride / sizeof(float);

		// fill staging buffers
		index_buffer.resize(ob.icount);
		vertex_buffer.resize(ob.vcount * vertex_size);
		unsigned int icount = 0;
		unsigned int vcount = 0;
		while (vcount < ob.vcount)
		{
			assert(varray_index < varrays.size());
			const VertexArray & va = *varrays[varray_index];

			icount = WriteIndices(va, icount, vcount, index_buffer);
			vcount = WriteVertices(va, vcount, vertex_size, vertex_buffer);
			varray_index++;
		}
		assert(icount == ob.icount);
		assert(vcount == ob.vcount);

		UploadBuffers(ob, index_buffer, vertex_buffer);
	}
}
Beispiel #2
0
void MultiLineComp::Write (ostream& out) {
    VerticesComp::Write(out);
    SF_MultiLine* ml = GetMultiLine();
    const Coord* x, *y;
    int count = ml->GetOriginal(x, y);

    WriteVertices(x, y, count, out);

    WriteBgFilled(ml->BgFilled(), out);
    WriteColor(ml->GetFgColor(), out);
    WriteColor(ml->GetBgColor(), out);
    WriteBrush(ml->GetBrush(), out);
    WritePattern(ml->GetPattern(), out);
    WriteTransformer(ml->GetTransformer(), out);
}
Beispiel #3
0
void SplineComp::Write (ostream& out) {
    VerticesComp::Write(out);
    SFH_OpenBSpline* spline = GetSpline();
    const Coord* x, *y;
    int count = spline->GetOriginal(x, y);

    WriteVertices(x, y, count, out);

    WriteBgFilled(spline->BgFilled(), out);
    WriteColor(spline->GetFgColor(), out);
    WriteColor(spline->GetBgColor(), out);
    WriteBrush(spline->GetBrush(), out);
    WritePattern(spline->GetPattern(), out);
    WriteTransformer(spline->GetTransformer(), out);
}
Beispiel #4
0
	void operator() (Drawable & drawable)
	{
		if (!drawable.GetDrawEnable())
			return;

		assert(drawable.GetVertArray());
		const VertexArray & va = *drawable.GetVertArray();
		const VertexFormat::Enum vf = va.GetVertexFormat();
		const unsigned int vsize = VertexFormat::Get(vf).stride / sizeof(float);
		const unsigned int vcount = va.GetNumVertices();
		const unsigned int icount = va.GetNumIndices();

		// FIXME: text drawables can contain empty vertex arrays,
		// they should be culled before getting here
		if (vcount == 0)
		{
			// reset segment as we might miss text drawable vcount change
			// happens with Tracks/Cars scroll onfocus tooltip update
			// need to investigate this
			if (drawable.GetVertexBufferSegment().age)
				drawable.SetVertexBufferSegment(Segment());
			return;
		}

		// get dynamic vertex data object (first object in the vector)
		const unsigned int obindex = 0;
		assert(!ctx.objects[vf].empty());
		Object & ob = ctx.objects[vf][obindex];

		// gen object buffers
		if (ob.vbuffer == 0)
		{
			glGenBuffers(1, &ob.ibuffer);
			glGenBuffers(1, &ob.vbuffer);
			if (ctx.use_vao)
			{
				glGenVertexArrays(1, &ob.varray);
				if (ob.varray == 0)
					ctx.use_vao = ctx.good_vao = false;
			}
			ob.vformat = vf;
		}

		// set segment
		Segment sg;
		sg.ioffset = ob.icount * sizeof(unsigned int);
		sg.icount = icount;
		sg.voffset = ob.vcount;
		sg.vcount = vcount;
		sg.vbuffer = ob.varray ? ob.varray : ob.vbuffer;
		sg.vformat = vf;
		sg.object = obindex;
		sg.age = ctx.age_dynamic;
		drawable.SetVertexBufferSegment(sg);

		// upload data into staging buffers
		std::vector<unsigned int> & index_buffer = ctx.staging_index_buffer[vf];
		std::vector<float> & vertex_buffer = ctx.staging_vertex_buffer[vf];
		const unsigned int ibn = (ob.icount + icount);
		const unsigned int vbn = (ob.vcount + vcount) * vsize;
		if (index_buffer.size() < ibn)
		{
			const unsigned int ibmin = min_dynamic_index_buffer_size / sizeof(unsigned int);
			index_buffer.resize(std::max(ibn, ibmin));
		}
		if (vertex_buffer.size() < vbn)
		{
			const unsigned int vbmin = min_dynamic_vertex_buffer_size / sizeof(float);
			vertex_buffer.resize(std::max(vbn, vbmin));
		}
		ob.icount = WriteIndices(va, ob.icount, ob.vcount, index_buffer);
		ob.vcount = WriteVertices(va, ob.vcount, vsize, vertex_buffer);
	}
Beispiel #5
0
int main( int argc, char *argv[] )
{
	char	*height_name;
	char	*edge_name;

	tga_t	*heightmap;
	tga_t	*edgemap;

	int		i, j;
	int		num;


	FILE	*h;

	printf( "===== envpot - build and optimize a environment data =====\n" );
	SetCmdArgs( argc, argv );


	height_name = GetCmdOpt2( "-h" );
	edge_name = GetCmdOpt2( "-e" );

	if ( !height_name )
		Error( "no heightmap.\n" );
	if ( !edge_name )
		Error( "no edgemap.\n" );

	h = fopen( height_name, "r" );
	if ( !h )
		Error( "can't open heightmap.\n" );
	heightmap = TGA_Read( h );
	fclose( h );

	h = fopen( edge_name, "r" );
	if ( !h )
		Error( "can't open edgemap.\n" );
	edgemap = TGA_Read( h );
	fclose( h );

	InitEdgeMap( edgemap );
//	InitHeightMap( heightmap );
//	SetupCells();

#if 0	
	num = 0;
	for ( i = 0; i < 10; i++ )
	{
		for ( j = 0; j < 10; j++ )
		{
//			Vec3dInit( vertices[num++], (random()%1000)/1000.0, 0.0, (random()%1000)/1000.0 );
			Vec3dInit( vertices[num++], j/10.0, 0.0, i/10.0 );
		}
	}

	for ( i = 0; i < 5; i++ )
	{
		for ( j = 0; j < 5; j++ )
		{
//			Vec3dInit( vertices[num++], (random()%1000)/1000.0, 0.0, (random()%1000)/1000.0 );
			Vec3dInit( vertices[num++], 0.05+j/10.0, 0.0, 0.05+i/10.0 );
		}
	}

	vertexnum = num;
#endif

//	Vec2dInit( vertices[0].v, 0.0, 0.0 );
//	Vec2dInit( vertices[1].v, 0.0, 1.0 );
//	Vec2dInit( vertices[2].v, -1.0, 0.5 );
//	Vec2dInit( vertices[3].v, 1.0, 0.5 );
//	Vec2dInit( vertices[4].v, 2.0, 0.5 );
//	vertexnum = 5;


	Init2();
	handle = fopen( "env_tris", "w" );
	Test2();
	fprintf( handle, "end" );
	fclose( handle );

	handle = fopen( "env_vertices", "w" );
	WriteVertices();
	fclose( handle );

}