Search in sources :

Example 1 with ShaderProgramFeature

use of org.terasology.rendering.assets.shader.ShaderProgramFeature in project Terasology by MovingBlocks.

the class GLSLShader method updateAvailableFeatures.

private void updateAvailableFeatures() {
    availableFeatures.clear();
    // Check which features are used in the shaders and update the available features mask accordingly
    for (ShaderProgramFeature feature : ShaderProgramFeature.values()) {
        // TODO: Have our own shader language and parse this stuff out properly
        if (shaderProgramBase.getFragmentProgram().contains(feature.toString())) {
            logger.debug("Fragment shader feature '" + feature.toString() + "' is available...");
            availableFeatures.add(feature);
        } else if (shaderProgramBase.getVertexProgram().contains(feature.toString())) {
            logger.debug("Vertex shader feature '" + feature.toString() + "' is available...");
            availableFeatures.add(feature);
        }
    }
}
Also used : ShaderProgramFeature(org.terasology.rendering.assets.shader.ShaderProgramFeature)

Example 2 with ShaderProgramFeature

use of org.terasology.rendering.assets.shader.ShaderProgramFeature in project Terasology by MovingBlocks.

the class GLSLShader method assembleShader.

private String assembleShader(int type, Set<ShaderProgramFeature> features) {
    StringBuilder shader = createShaderBuilder();
    // Add the activated features for this shader
    for (ShaderProgramFeature feature : features) {
        shader.append("#define ").append(feature.name()).append("\n");
    }
    shader.append("\n");
    shader.append(includedDefines);
    shader.append(includedUniforms);
    if (type == GL20.GL_FRAGMENT_SHADER) {
        shader.append(includedFunctionsFragment);
        shader.append("\n");
        shader.append(shaderProgramBase.getFragmentProgram());
    } else {
        shader.append(includedFunctionsVertex);
        shader.append("\n");
        shader.append(shaderProgramBase.getVertexProgram());
    }
    return shader.toString();
}
Also used : ShaderProgramFeature(org.terasology.rendering.assets.shader.ShaderProgramFeature)

Example 3 with ShaderProgramFeature

use of org.terasology.rendering.assets.shader.ShaderProgramFeature in project Terasology by MovingBlocks.

the class GLSLMaterial method recompile.

@Override
public void recompile() {
    TIntIntIterator it = disposalAction.shaderPrograms.iterator();
    while (it.hasNext()) {
        it.advance();
        GL20.glDeleteProgram(it.value());
    }
    disposalAction.shaderPrograms.clear();
    uniformLocationMap.clear();
    bindMap.clear();
    disposalAction.shaderPrograms.put(0, shader.linkShaderProgram(0));
    for (Set<ShaderProgramFeature> permutation : Sets.powerSet(shader.getAvailableFeatures())) {
        int featureMask = ShaderProgramFeature.getBitset(permutation);
        disposalAction.shaderPrograms.put(featureMask, shader.linkShaderProgram(featureMask));
    }
    // resolves #966
    // Some of the uniforms are not updated constantly between frames
    // this function will rebind any uniforms that are not bound
    rebindVariables(materialData);
}
Also used : ShaderProgramFeature(org.terasology.rendering.assets.shader.ShaderProgramFeature) TIntIntIterator(gnu.trove.iterator.TIntIntIterator)

Aggregations

ShaderProgramFeature (org.terasology.rendering.assets.shader.ShaderProgramFeature)3 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)1