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);
                }
            }
        }
Example #2
0
        public VertexAttribute getVertexAttribute(int usage)
        {
            VertexAttributes attributes = vertices.getAttributes();
            int len = attributes.size();

            for (int i = 0; i < len; i++)
            {
                if (attributes[i].usage == usage)
                {
                    return(attributes[i]);
                }
            }

            return(null);
        }