Search in sources :

Example 1 with ArrayShaderFieldType

use of com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType in project gdx-graph by MarcinSc.

the class GraphModelUtil method getShaderVertexAttributes.

public static VertexAttributes getShaderVertexAttributes(GraphModels graphModels, String tag) {
    ObjectMap<String, PropertySource> shaderProperties = graphModels.getShaderProperties(tag);
    if (shaderProperties == null)
        throw new GdxRuntimeException("Unable to locate shader with tag: " + tag);
    Array<VertexAttribute> vertexAttributeArray = new Array<>(VertexAttribute.class);
    for (ObjectMap.Entry<String, PropertySource> shaderProperty : shaderProperties) {
        PropertySource propertySource = shaderProperty.value;
        PropertyLocation propertyLocation = propertySource.getPropertyLocation();
        if (propertyLocation == PropertyLocation.Attribute) {
            ShaderFieldType shaderFieldType = propertySource.getShaderFieldType();
            if (shaderFieldType instanceof ArrayShaderFieldType) {
                int arraySize = ((ArrayShaderFieldType) shaderFieldType).getArrayLength();
                for (int i = 0; i < arraySize; i++) {
                    vertexAttributeArray.add(new VertexAttribute(1024, shaderFieldType.getNumberOfComponents(), propertySource.getAttributeName(i)));
                }
            } else {
                vertexAttributeArray.add(new VertexAttribute(1024, shaderFieldType.getNumberOfComponents(), propertySource.getAttributeName()));
            }
        }
    }
    return new VertexAttributes(vertexAttributeArray.toArray());
}
Also used : VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) ObjectMap(com.badlogic.gdx.utils.ObjectMap) PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) ArrayShaderFieldType(com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType) ArrayShaderFieldType(com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Aggregations

VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 Array (com.badlogic.gdx.utils.Array)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 IntArray (com.badlogic.gdx.utils.IntArray)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 ArrayShaderFieldType (com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType)1 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)1 PropertyLocation (com.gempukku.libgdx.graph.shader.property.PropertyLocation)1 PropertySource (com.gempukku.libgdx.graph.shader.property.PropertySource)1