Search in sources :

Example 1 with IntAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.IntAttribute in project libgdx by libgdx.

the class DefaultShader method bindMaterial.

protected void bindMaterial(final Attributes attributes) {
    int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;
    for (final Attribute attr : attributes) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute) attr).sourceFunction, ((BlendingAttribute) attr).destFunction);
            set(u_opacity, ((BlendingAttribute) attr).opacity);
        } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace)
            cullFace = ((IntAttribute) attr).value;
        else if ((t & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
            set(u_alphaTest, ((FloatAttribute) attr).value);
        else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute) attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented)
            throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }
    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) PointLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute) Attribute(com.badlogic.gdx.graphics.g3d.Attribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute) SpotLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute)

Example 2 with IntAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.IntAttribute in project bdx by GoranM.

the class BDXShaderProvider method render.

public void render(Renderable renderable, Attributes combinedAttributes) {
    if (renderable.material.has(BlendingAttribute.Type)) {
        BlendingAttribute ba = (BlendingAttribute) renderable.material.get(BlendingAttribute.Type);
        Gdx.gl.glBlendFuncSeparate(ba.sourceFunction, ba.destFunction, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    IntAttribute shadeless = (IntAttribute) renderable.material.get(Scene.BDXIntAttribute.Shadeless);
    if (shadeless == null)
        set(u_shadeless, 0);
    else
        set(u_shadeless, shadeless.value);
    ColorAttribute tint = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Tint);
    if (tint == null)
        set(u_tintColor, new Color());
    else
        set(u_tintColor, tint.color);
    ColorAttribute emit = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Emit);
    if (emit == null)
        set(u_emitColor, new Color());
    else
        set(u_emitColor, emit.color);
    if (shaderProvider.scene != null) {
        ColorAttribute fog = (ColorAttribute) renderable.environment.get(ColorAttribute.Fog);
        if (fog == null)
            set(u_fogRange, 0f, 0f);
        else
            set(u_fogRange, shaderProvider.scene.fogRange().x, shaderProvider.scene.fogRange().y);
        set(u_camRange, shaderProvider.scene.camera.near(), shaderProvider.scene.camera.far());
    }
    super.render(renderable, combinedAttributes);
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) Color(com.badlogic.gdx.graphics.Color) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)2 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)2 IntAttribute (com.badlogic.gdx.graphics.g3d.attributes.IntAttribute)2 Color (com.badlogic.gdx.graphics.Color)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 Attribute (com.badlogic.gdx.graphics.g3d.Attribute)1 CubemapAttribute (com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute)1 DepthTestAttribute (com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute)1 DirectionalLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)1 FloatAttribute (com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute)1 PointLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute)1 SpotLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1