Search in sources :

Example 1 with AttributeSource

use of io.xol.chunkstories.api.rendering.vertex.AttributeSource in project chunkstories by Hugobros3.

the class AttributesConfigurationImplementation method setup.

public void setup(RenderingInterface renderingInterface) {
    ShaderGL shaderProgram = (ShaderGL) renderingInterface.currentShader();
    Set<Integer> unusedAttributes = enabledVertexAttributes;
    enabledVertexAttributes = new HashSet<Integer>(enabledVertexAttributes);
    for (Entry<String, AttributeSource> e : attributes.entrySet()) {
        String attributeName = e.getKey();
        AttributeSource attributeSource = e.getValue();
        int attributeLocation = shaderProgram.getVertexAttributeLocation(attributeName);
        if (attributeLocation == -1)
            continue;
        unusedAttributes.remove(attributeLocation);
        // Enable only when it wasn't
        if (enabledVertexAttributes.add(attributeLocation))
            glEnableVertexAttribArray(attributeLocation);
        attributeSource.setup(attributeLocation);
    }
    // Disable and forget about unused ones
    for (int unused : unusedAttributes) {
        glDisableVertexAttribArray(unused);
        enabledVertexAttributes.remove(unused);
    }
}
Also used : AttributeSource(io.xol.chunkstories.api.rendering.vertex.AttributeSource) ShaderGL(io.xol.chunkstories.renderer.opengl.shader.ShaderGL)

Aggregations

AttributeSource (io.xol.chunkstories.api.rendering.vertex.AttributeSource)1 ShaderGL (io.xol.chunkstories.renderer.opengl.shader.ShaderGL)1