Example #1
0
 void DrawRequest::SetDrawElementsCount(GLsizei drawElementsCount)
 {
     GLint lastDrawIndex = GetStartDrawIndex() + drawElementsCount - 1;
     if (lastDrawIndex < GetVerticesCount())
     {
         m_drawElementsCount = drawElementsCount;
     }
     else
     {
         Log("WARNING: Last draw index exeeds available bounds. Truncated drawing elements count");
         m_drawElementsCount = GetVerticesCount() - GetStartDrawIndex();
     }
 }
Example #2
0
 void DrawRequest::SetStartDrawIndex(GLint startDrawIndex)
 {
     if (startDrawIndex < GetVerticesCount())
     {
         m_startDrawIndex = startDrawIndex;
         
         int lastDrawIndex = startDrawIndex + GetDrawElementsCount() - 1;
         if (lastDrawIndex >= GetVerticesCount())
         {
             Log("WARNING: Last draw index exeeds available bounds. Truncated drawing elements count");
             int drawElementsCount = GetVerticesCount() - startDrawIndex;
             SetDrawElementsCount(drawElementsCount);
         }
     }
     else
     {
         Log("ERROR: Wrong start draw index");
         m_startDrawIndex = 0;
         SetDrawElementsCount(0);
     }
 }
Example #3
0
void Mesh::RecalcTangents()
{
	if (!HasNormals() || !HasTexCoords()) return;

	Vector3f *verts = (Vector3f *)vertices->Map(GL_READ_ONLY);
	Vector2f *texs = (Vector2f *)texCoords->Map(GL_READ_ONLY);
	int *inds = (int *)indices->Map(GL_READ_ONLY);
	
	int verticesCount = GetVerticesCount();
	int indicesCount = GetIndicesCount();
	Vector3f *ts = new Vector3f[verticesCount];
	Vector3f *bs = new Vector3f[verticesCount];

	for (int i = 0; i < indicesCount; i += 3)
	{
		int i1 = inds[i], i2 = inds[i+1], i3 = inds[i+2];

		Vector3f &v1 = verts[i1];
		Vector3f &v2 = verts[i2];
		Vector3f &v3 = verts[i3];

		Vector2f &t1 = texs[i1];
		Vector2f &t2 = texs[i2];
		Vector2f &t3 = texs[i3];

		Vector3f edge1 = v2 - v1;
		Vector3f edge2 = v3 - v1;
		Vector2f uv1 = t2 - t1;
		Vector2f uv2 = t3 - t1;

		float f = 1.0f / (uv1.x * uv2.y - uv2.x * uv1.y);
		Vector3f tangent = (uv2.y * edge1 - uv1.y * edge2) * f;
		Vector3f binormal = (uv1.x * edge2 - uv2.x * edge1) * f;
		tangent.Normalize();
		binormal.Normalize();

		ts[i1] = ts[i2] = ts[i3] = tangent;
		bs[i1] = bs[i2] = bs[i3] = binormal;
	}
	
	if (!tangents) tangents = new VertexBuffer(rc, GL_ARRAY_BUFFER);
	if (!binormals) binormals = new VertexBuffer(rc, GL_ARRAY_BUFFER);
	tangents->SetData(verticesCount*sizeof(Vector3f), ts, GL_STATIC_DRAW);
	binormals->SetData(verticesCount*sizeof(Vector3f), bs, GL_STATIC_DRAW);

	delete [] ts;
	delete [] bs;

	vertices->Unmap();
	texCoords->Unmap();
	indices->Unmap();
}
Example #4
0
 void DrawRequest::ResetDrawCount()
 {
     GLsizei drawCount = GetVerticesCount() - GetStartDrawIndex();
     SetDrawElementsCount(drawCount);
 }