Search in sources :

Example 1 with PropertySource

use of com.gempukku.libgdx.graph.shader.property.PropertySource in project gdx-graph by MarcinSc.

the class MeshParticleModel method updateParticleData.

@Override
public void updateParticleData(float[] particlesData, int particleOffset, VertexAttributes vertexAttributes, ObjectMap<String, String> attributeToPropertyMap, ObjectMap<String, PropertySource> properties, ObjectMap<String, Object> attributes) {
    int vertexLength = vertexAttributes.vertexSize / 4;
    for (VertexAttribute vertexAttribute : vertexAttributes) {
        String propertyName = attributeToPropertyMap.get(vertexAttribute.alias);
        if (propertyName != null) {
            int attributeOffset = vertexAttribute.offset / 4;
            PropertySource propertySource = properties.get(propertyName);
            Object attributeValue = attributes.get(propertyName);
            ParticlesUtil.setParticleAttribute(particlesData, particleOffset, vertexCount, vertexLength, attributeOffset, propertySource, attributeValue);
        }
    }
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource)

Example 2 with PropertySource

use of com.gempukku.libgdx.graph.shader.property.PropertySource in project gdx-graph by MarcinSc.

the class LimitedCapacitySpriteBatchModel method updateSpriteData.

private void updateSpriteData(RenderableSprite sprite, int spriteIndex) {
    int spriteDataStart = getSpriteDataStart(spriteIndex);
    for (VertexAttribute vertexAttribute : vertexAttributes) {
        PropertySource propertySource = vertexPropertySources.get(vertexAttribute);
        int attributeOffset = vertexAttribute.offset / 4;
        ShaderFieldType shaderFieldType = propertySource.getShaderFieldType();
        Object attributeValue = sprite.getPropertyContainer().getValue(propertySource.getPropertyName());
        if (attributeValue instanceof ValuePerVertex) {
            for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
                int vertexOffset = spriteDataStart + vertexIndex * floatCountPerVertex;
                Object vertexValue = ((ValuePerVertex) attributeValue).getValue(vertexIndex);
                shaderFieldType.setValueInAttributesArray(vertexData, vertexOffset + attributeOffset, propertySource.getValueToUse(vertexValue));
            }
        } else {
            attributeValue = propertySource.getValueToUse(attributeValue);
            for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
                int vertexOffset = spriteDataStart + vertexIndex * floatCountPerVertex;
                shaderFieldType.setValueInAttributesArray(vertexData, vertexOffset + attributeOffset, attributeValue);
            }
        }
    }
    markSpriteUpdated(spriteIndex);
}
Also used : ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType) ValuePerVertex(com.gempukku.libgdx.graph.util.ValuePerVertex) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource)

Example 3 with PropertySource

use of com.gempukku.libgdx.graph.shader.property.PropertySource in project gdx-graph by MarcinSc.

the class TexturePagedSpriteBatchModel method getTextureSignature.

private String getTextureSignature(RenderableSprite sprite) {
    if (textureUniforms.size == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    for (PropertySource textureUniform : textureUniforms) {
        Object region = sprite.getPropertyContainer().getValue(textureUniform.getPropertyName());
        region = textureUniform.getValueToUse(region);
        sb.append(((TextureRegion) region).getTexture().getTextureObjectHandle()).append(",");
    }
    sb.setLength(sb.length() - 1);
    return sb.toString();
}
Also used : PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource)

Example 4 with PropertySource

use of com.gempukku.libgdx.graph.shader.property.PropertySource in project gdx-graph by MarcinSc.

the class GraphModelUtil method getPropertySourceMap.

public static ObjectMap<VertexAttribute, PropertySource> getPropertySourceMap(GraphModels graphModels, String tag, VertexAttributes vertexAttributes) {
    ObjectMap<String, PropertySource> shaderProperties = graphModels.getShaderProperties(tag);
    if (shaderProperties == null)
        throw new GdxRuntimeException("Unable to locate shader with tag: " + tag);
    ObjectMap<VertexAttribute, PropertySource> result = new ObjectMap<>();
    for (VertexAttribute vertexAttribute : vertexAttributes) {
        String alias = vertexAttribute.alias;
        PropertySource propertySource = findPropertyByAttributeName(shaderProperties, alias);
        result.put(vertexAttribute, propertySource);
    }
    return result;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource)

Example 5 with PropertySource

use of com.gempukku.libgdx.graph.shader.property.PropertySource 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

PropertySource (com.gempukku.libgdx.graph.shader.property.PropertySource)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)4 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 ObjectMap (com.badlogic.gdx.utils.ObjectMap)2 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)2 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Array (com.badlogic.gdx.utils.Array)1 IntArray (com.badlogic.gdx.utils.IntArray)1 ArrayShaderFieldType (com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType)1 PropertyLocation (com.gempukku.libgdx.graph.shader.property.PropertyLocation)1 ValuePerVertex (com.gempukku.libgdx.graph.util.ValuePerVertex)1