Java Code Examples for com.jme3.renderer.Renderer#setTexture()

The following examples show how to use com.jme3.renderer.Renderer#setTexture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) {
    for (MatParamOverride override : overrides.getArray()) {
        VarType type = override.getVarType();

        MatParam paramDef = def.getMaterialParam(override.getName());

        if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
            continue;
        }

        Uniform uniform = shader.getUniform(override.getPrefixedName());

        if (override.getValue() != null) {
            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) override.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, override.getValue());
            }
        } else {
            uniform.clearValue();
        }
    }
    return unit;
}
 
Example 2
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Preloads this material for the given render manager.
 * <p>
 * Preloading the material can ensure that when the material is first
 * used for rendering, there won't be any delay since the material has
 * been already been setup for rendering.
 *
 * @param rm The render manager to preload for
 */
public void preload(RenderManager rm) {
    autoSelectTechnique(rm);

    Renderer r = rm.getRenderer();
    TechniqueDef techDef = technique.getDef();

    Collection<MatParam> params = paramValues.values();
    for (MatParam param : params) {
        if (param instanceof MatParamTexture) {
            MatParamTexture texParam = (MatParamTexture) param;
            r.setTexture(0, texParam.getTextureValue());
        } else {
            if (!techDef.isUsingShaders()) {
                continue;
            }

            technique.updateUniformParam(param.getName(),
                    param.getVarType(),
                    param.getValue(), true);
        }
    }

    Shader shader = technique.getShader();
    if (techDef.isUsingShaders()) {
        r.setShader(shader);
    }
}
 
Example 3
Source File: MatParamTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void apply(Renderer r, Technique technique) {
    TechniqueDef techDef = technique.getDef();
    r.setTexture(getUnit(), getTextureValue());
    if (techDef.isUsingShaders()) {
        technique.updateUniformParam(getPrefixedName(), getVarType(), getUnit(), true);
    }
}
 
Example 4
Source File: MatParamTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void apply(Renderer r, Technique technique, int paramIndex) {
    TechniqueDef techDef = technique.getDef();
    r.setTexture(getUnit(), getTextureValue());
    if (techDef.isUsingShaders()) {
        technique.updateUniformParam(paramIndex, getVarType(), getUnit(), true);
    }
}
 
Example 5
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private int updateShaderMaterialParameters(Renderer renderer, Shader shader,
                                           SafeArrayList<MatParamOverride> worldOverrides, SafeArrayList<MatParamOverride> forcedOverrides) {

    int unit = 0;
    if (worldOverrides != null) {
        unit = applyOverrides(renderer, shader, worldOverrides, unit);
    }
    if (forcedOverrides != null) {
        unit = applyOverrides(renderer, shader, forcedOverrides, unit);
    }

    for (int i = 0; i < paramValues.size(); i++) {

        MatParam param = paramValues.getValue(i);
        VarType type = param.getVarType();

        if (isBO(type)) {

            final ShaderBufferBlock bufferBlock = shader.getBufferBlock(param.getPrefixedName());
            bufferBlock.setBufferObject((BufferObject) param.getValue());

        } else {

            Uniform uniform = shader.getUniform(param.getPrefixedName());
            if (uniform.isSetByCurrentMaterial()) {
                continue;
            }

            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) param.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, param.getValue());
            }
        }
    }

    //TODO HACKY HACK remove this when texture unit is handled by the uniform.
    return unit;
}