internal void Apply(Shader shader, IntPtr offset)
{
int hashCode = shader.GetHashCode();
VertexDeclaration.VertexDeclarationAttributeInfo declarationAttributeInfo;
if (!this.shaderAttributeInfo.TryGetValue(hashCode, out declarationAttributeInfo))
{
declarationAttributeInfo = new VertexDeclaration.VertexDeclarationAttributeInfo(this.GraphicsDevice.MaxVertexAttributes);
foreach (VertexElement element in this._elements)
{
int attribLocation = shader.GetAttribLocation(element.VertexElementUsage, element.UsageIndex);
if (attribLocation >= 0)
{
declarationAttributeInfo.Elements.Add(new VertexDeclaration.VertexDeclarationAttributeInfo.Element()
{
Offset = element.Offset,
AttributeLocation = attribLocation,
NumberOfElements = GraphicsExtensions.OpenGLNumberOfElements(element.VertexElementFormat),
VertexAttribPointerType = GraphicsExtensions.OpenGLVertexAttribPointerType(element.VertexElementFormat),
Normalized = GraphicsExtensions.OpenGLVertexAttribNormalized(element)
});
declarationAttributeInfo.EnabledAttributes[attribLocation] = true;
}
}
this.shaderAttributeInfo.Add(hashCode, declarationAttributeInfo);
}
foreach (VertexDeclaration.VertexDeclarationAttributeInfo.Element element in declarationAttributeInfo.Elements)
{
GL.VertexAttribPointer(element.AttributeLocation, element.NumberOfElements, element.VertexAttribPointerType, element.Normalized, this.VertexStride, (IntPtr)(offset.ToInt64() + (long)element.Offset));
}
this.GraphicsDevice.SetVertexAttributeArray(declarationAttributeInfo.EnabledAttributes);
}