private void bindAttributes(ShaderProgram shader, int[] locations)
        {
            var stillValid    = this.cachedLocations.Count != 0;
            var numAttributes = attributes.size();

            if (stillValid)
            {
                if (locations == null)
                {
                    for (int i = 0; stillValid && i < numAttributes; i++)
                    {
                        VertexAttribute attribute = attributes[i];
                        int             location  = shader.getAttributeLocation(attribute.alias);
                        stillValid = location == this.cachedLocations[i];
                    }
                }
                else
                {
                    stillValid = locations.Length == this.cachedLocations.Count;
                    for (int i = 0; stillValid && i < numAttributes; i++)
                    {
                        stillValid = locations[i] == this.cachedLocations[i];
                    }
                }
            }

            if (!stillValid)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
                unbindAttributes(shader);
                this.cachedLocations.Clear();

                for (int i = 0; i < numAttributes; i++)
                {
                    VertexAttribute attribute = attributes[i];
                    if (locations == null)
                    {
                        this.cachedLocations.Add(shader.getAttributeLocation(attribute.alias));
                    }
                    else
                    {
                        this.cachedLocations.Add(locations[i]);
                    }

                    int location = this.cachedLocations[i];
                    if (location < 0)
                    {
                        continue;
                    }

                    shader.enableVertexAttribute(location);
                    shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
                }
            }
        }
Esempio n. 2
0
 public bool equals(VertexAttribute other)
 {
     return(other != null && usage == other.usage && numComponents == other.numComponents &&
            type == other.type && normalized == other.normalized && alias == other.alias &&
            unit == other.unit);
 }