Example #1
0
unsigned int VertexBuffer::WriteVertices(
	const VertexArray & va,
	const unsigned int vcount,
	const unsigned int vertex_size,
	std::vector<float> & vertex_buffer)
{
	// get vertices (fixme: use VertexFormat info here)
	const int vat_count = 4;
	const void * vat_ptrs[4] = {0, 0, 0, 0};
	int vn, nn, tn, cn;
	va.GetVertices((const float *&)vat_ptrs[0], vn);
	va.GetNormals((const float *&)vat_ptrs[1], nn);
	va.GetTexCoords((const float *&)vat_ptrs[2], tn);
	va.GetColors((const unsigned char *&)vat_ptrs[3], cn);

	// calculate vertex element sizes and offsets in sizeof(float)
	int vat_sizes[4] = {3, 3, 2, 1};
	int vat_offsets[4] = {0, 3, 6, 8};
	for (int j = 0; j < vat_count; ++j)
	{
		if (vat_ptrs[j] == 0)
			vat_sizes[j] = 0;
	}
	for (int j = 1; j < vat_count; ++j)
	{
		vat_offsets[j] = vat_offsets[j - 1] + vat_sizes[j - 1];
	}

	// fill vertices
	assert((vcount + vn / 3) * vertex_size <= vertex_buffer.size());
	float * vb = &vertex_buffer[vcount * vertex_size];
	for (int j = 0; j < vn / 3 ; ++j)
	{
		float * v = vb + j * vertex_size;
		for (int k = 0; k < vat_count; ++k)
		{
			const float * vat = (const float *)vat_ptrs[k] + j * vat_sizes[k];
			for (int m = 0; m < vat_sizes[k]; ++m)
			{
				v[vat_offsets[k] + m] = vat[m];
			}
		}
	}

	return vcount + vn / 3;
}
Example #2
0
void AiCarStandard::AddLinePoint(VertexArray & va, const Vec3 & p)
{
	int vsize;
	const float* vbase;
	va.GetVertices(vbase, vsize);

	if (vsize == 0)
	{
		int vcount = 3;
		float verts[3] = {p[0], p[1], p[2]};
		va.SetVertices(verts, vcount, vsize);
	}
	else
	{
		int vcount = 6;
		float verts[6] = {p[0], p[1], p[2], p[0], p[1], p[2]};
		va.SetVertices(verts, vcount, vsize);
	}
}
Example #3
0
void RenderInputScene::DrawVertexArray(const VertexArray & va, float linesize) const
{
	const float * verts;
	int vertcount;
	va.GetVertices(verts, vertcount);
	if (verts)
	{
		glVertexPointer(3, GL_FLOAT, 0, verts);
		glEnableClientState(GL_VERTEX_ARRAY);

		const unsigned char * cols;
		int colcount;
		va.GetColors(cols, colcount);
		if (cols)
		{
			glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols);
			glEnableClientState(GL_COLOR_ARRAY);
		}

		const int * faces;
		int facecount;
		va.GetFaces(faces, facecount);
		if (faces)
		{
			const float * norms;
			int normcount;
			va.GetNormals(norms, normcount);
			if (norms)
			{
				glNormalPointer(GL_FLOAT, 0, norms);
				glEnableClientState(GL_NORMAL_ARRAY);
			}

			const float * tc = 0;
			int tccount;
			if (va.GetTexCoordSets() > 0)
			{
				va.GetTexCoords(0, tc, tccount);
				if (tc)
				{
					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
					glTexCoordPointer(2, GL_FLOAT, 0, tc);
				}
			}

			glDrawElements(GL_TRIANGLES, facecount, GL_UNSIGNED_INT, faces);

			if (tc)
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);

			if (norms)
				glDisableClientState(GL_NORMAL_ARRAY);
		}
		else if (linesize > 0)
		{
			glLineWidth(linesize);
			glDrawArrays(GL_LINES, 0, vertcount / 3);
		}

		if (cols)
			glDisableClientState(GL_COLOR_ARRAY);

		glDisableClientState(GL_VERTEX_ARRAY);
	}
}