private void SetupVertexFormat(BatchInfo material, VertexDeclaration vertexDeclaration) { DrawTechnique technique = material.Technique.Res ?? DrawTechnique.Solid.Res; NativeShaderProgram nativeProgram = (technique.NativeShader ?? DrawTechnique.Solid.Res.NativeShader) as NativeShaderProgram; VertexElement[] elements = vertexDeclaration.Elements; for (int elementIndex = 0; elementIndex < elements.Length; elementIndex++) { int fieldIndex = nativeProgram.SelectField(ref elements[elementIndex]); if (fieldIndex == -1) { continue; } VertexAttribPointerType attribType; switch (elements[elementIndex].Type) { default: case VertexElementType.Float: attribType = VertexAttribPointerType.Float; break; case VertexElementType.Byte: attribType = VertexAttribPointerType.UnsignedByte; break; } int fieldLocation = nativeProgram.FieldLocations[fieldIndex]; GL.EnableVertexAttribArray(fieldLocation); GL.VertexAttribPointer( fieldLocation, elements[elementIndex].Count, attribType, true, vertexDeclaration.Size, elements[elementIndex].Offset); } }
private void FinishVertexFormat(BatchInfo material, VertexDeclaration vertexDeclaration) { DrawTechnique technique = material.Technique.Res ?? DrawTechnique.Solid.Res; NativeShaderProgram nativeProgram = (technique.NativeShader ?? DrawTechnique.Solid.Res.NativeShader) as NativeShaderProgram; VertexElement[] elements = vertexDeclaration.Elements; for (int elementIndex = 0; elementIndex < elements.Length; elementIndex++) { int fieldIndex = nativeProgram.SelectField(ref elements[elementIndex]); if (fieldIndex == -1) { break; } int fieldLocation = nativeProgram.FieldLocations[fieldIndex]; GL.DisableVertexAttribArray(fieldLocation); } }