Example usage for org.lwjgl.opengl GL13 glActiveTexture

List of usage examples for org.lwjgl.opengl GL13 glActiveTexture

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL13 glActiveTexture.

Prototype

public static void glActiveTexture(@NativeType("GLenum") int texture) 

Source Link

Document

Selects which texture unit subsequent texture state calls will affect.

Usage

From source file:org.terasology.rendering.shader.ShaderParametersInitialPost.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    // TODO: often used objects: perhaps to be obtained in BaseMaterial?
    DisplayResolutionDependentFBOs displayResolutionDependentFBOs = CoreRegistry
            .get(DisplayResolutionDependentFBOs.class); // TODO: switch from CoreRegistry to Context.
    Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);

    // TODO: move what follows into material and/or node
    Vector3f tint = worldProvider.getBlock(activeCamera.getPosition()).getTint();
    program.setFloat3("inLiquidTint", tint.x, tint.y, tint.z, true);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    displayResolutionDependentFBOs.bindFboColorTexture(DefaultDynamicFBOs.READ_ONLY_GBUFFER.getName());
    program.setInt("texScene", texId++, true);

    // TODO: monitor config parameter by subscribing to it
    if (CoreRegistry.get(Config.class).getRendering().isBloom()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(BloomBlurNode.ONE_8TH_SCALE_FBO);
        program.setInt("texBloom", texId++, true);

        program.setFloat("bloomFactor", bloomFactor, true);
    }//from  w  w w .  j ava 2s.  c o m

    program.setFloat2("aberrationOffset", aberrationOffsetX, aberrationOffsetY, true);

    // TODO: monitor config parameter by subscribing to it
    if (CoreRegistry.get(Config.class).getRendering().isLightShafts()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(LightShaftsNode.LIGHT_SHAFTS_FBO);
        program.setInt("texLightShafts", texId++, true);
    }

    // TODO: obtain once, monitor using Texture.subscribeToDisposal(Runnable)
    Optional<? extends Texture> vignetteTexture = Assets.getTexture("engine:vignette");

    if (vignetteTexture.isPresent()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        glBindTexture(GL11.GL_TEXTURE_2D, vignetteTexture.get().getId());
        program.setInt("texVignette", texId++, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersLightGeometryPass.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO sceneOpaque = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    int texId = 0;
    if (sceneOpaque != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneOpaque.bindDepthTexture();//from  w w w  .  j  a  v a 2s  . c o m
        program.setInt("texSceneOpaqueDepth", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneOpaque.bindNormalsTexture();
        program.setInt("texSceneOpaqueNormals", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneOpaque.bindLightBufferTexture();
        program.setInt("texSceneOpaqueLightBuffer", texId++, true);
    }

    if (CoreRegistry.get(Config.class).getRendering().isDynamicShadows()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().bindFboDepthTexture("sceneShadowMap");
        program.setInt("texSceneShadowMap", texId++, true);

        Camera lightCamera = CoreRegistry.get(WorldRenderer.class).getLightCamera();
        Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();

        if (lightCamera != null && activeCamera != null) {
            program.setMatrix4("lightViewProjMatrix", lightCamera.getViewProjectionMatrix(), true);
            program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);

            Vector3f activeCameraToLightSpace = new Vector3f();
            activeCameraToLightSpace.sub(activeCamera.getPosition(), lightCamera.getPosition());
            program.setFloat3("activeCameraToLightSpace", activeCameraToLightSpace.x,
                    activeCameraToLightSpace.y, activeCameraToLightSpace.z, true);
        }

        if (CoreRegistry.get(Config.class).getRendering().isCloudShadows()) {
            Texture clouds = Assets.getTexture("engine:perlinNoiseTileable");

            GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
            glBindTexture(GL11.GL_TEXTURE_2D, clouds.getId());
            program.setInt("texSceneClouds", texId++, true);
        }
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersLightShaft.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO scene = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    int texId = 0;

    if (scene != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindTexture();/*from w w w.  j a va2 s . c om*/
        program.setInt("texScene", texId++, true);
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindDepthTexture();
        program.setInt("texDepth", texId++, true);
    }

    program.setFloat("density", density, true);
    program.setFloat("exposure", exposure, true);
    program.setFloat("weight", weight, true);
    program.setFloat("decay", decay, true);

    WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
    if (worldRenderer != null) {
        Vector3f sunDirection = worldRenderer.getSkysphere().getSunDirection(true);

        Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();

        Vector4f sunPositionWorldSpace4 = new Vector4f(sunDirection.x * 10000.0f, sunDirection.y * 10000.0f,
                sunDirection.z * 10000.0f, 1.0f);
        Vector4f sunPositionScreenSpace = new Vector4f();
        activeCamera.getViewProjectionMatrix().transform(sunPositionWorldSpace4, sunPositionScreenSpace);

        sunPositionScreenSpace.x /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.y /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.z /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.w = 1.0f;

        program.setFloat("lightDirDotViewDir", activeCamera.getViewingDirection().dot(sunDirection), true);
        program.setFloat2("lightScreenPos", (sunPositionScreenSpace.x + 1.0f) / 2.0f,
                (sunPositionScreenSpace.y + 1.0f) / 2.0f, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersLightShafts.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    // TODO: obtain once in superclass and monitor from there?
    DisplayResolutionDependentFBOs displayResolutionDependentFBOs = CoreRegistry
            .get(DisplayResolutionDependentFBOs.class); // TODO: switch from CoreRegistry to Context.
    FBO scene = displayResolutionDependentFBOs.get(DefaultDynamicFBOs.READ_ONLY_GBUFFER.getName());

    int texId = 0;

    // TODO: - move into node
    // TODO: - many null checks are happening in these shader parameter classes. I feel they are unnecessary
    // TODO:   as those objects should never be null. If they are I'd be happy receiving an NPE and debugging as needed.
    if (scene != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindTexture();/*w w  w .ja va  2 s  . co  m*/
        program.setInt("texScene", texId++, true);
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        scene.bindDepthTexture();
        program.setInt("texDepth", texId++, true);
    }

    // TODO: move into Material?
    program.setFloat("density", density, true);
    program.setFloat("exposure", exposure, true);
    program.setFloat("weight", weight, true);
    program.setFloat("decay", decay, true);

    WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
    BackdropProvider backdropProvider = CoreRegistry.get(BackdropProvider.class);

    // TODO: eliminate null check?
    if (worldRenderer != null) {
        // TODO: move into Material?
        Vector3f sunDirection = backdropProvider.getSunDirection(true);

        Camera activeCamera = worldRenderer.getActiveCamera();

        Vector4f sunPositionWorldSpace4 = new Vector4f(sunDirection.x * 10000.0f, sunDirection.y * 10000.0f,
                sunDirection.z * 10000.0f, 1.0f);
        Vector4f sunPositionScreenSpace = new Vector4f(sunPositionWorldSpace4);
        activeCamera.getViewProjectionMatrix().transform(sunPositionScreenSpace);

        sunPositionScreenSpace.x /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.y /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.z /= sunPositionScreenSpace.w;
        sunPositionScreenSpace.w = 1.0f;

        program.setFloat("lightDirDotViewDir", activeCamera.getViewingDirection().dot(sunDirection), true);
        program.setFloat2("lightScreenPos", (sunPositionScreenSpace.x + 1.0f) / 2.0f,
                (sunPositionScreenSpace.y + 1.0f) / 2.0f, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersOcDistortion.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneFinal");
    program.setInt("texSceneFinal", texId++, true);
}

From source file:org.terasology.rendering.shader.ShaderParametersParticle.java

License:Apache License

@Override
public void applyParameters(ShaderProgram program) {
    Texture terrainTex = Assets.getTexture("engine:terrain");
    if (terrainTex == null) {
        return;/*from   w w  w  .j  ava 2s  .  co  m*/
    }

    LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    glBindTexture(GL11.GL_TEXTURE_2D, terrainTex.getId());

    if (localPlayer != null)
        program.setInt("carryingTorch", localPlayer.isCarryingTorch() ? 1 : 0);
}

From source file:org.terasology.rendering.shader.ShaderParametersPost.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    CameraTargetSystem cameraTargetSystem = CoreRegistry.get(CameraTargetSystem.class);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneToneMapped");
    program.setInt("texScene", texId++, true);

    if (CoreRegistry.get(Config.class).getRendering().getBlurIntensity() != 0) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().getFBO("sceneBlur1").bindTexture();
        program.setInt("texBlur", texId++, true);

        if (cameraTargetSystem != null) {
            program.setFloat("blurFocusDistance", cameraTargetSystem.getFocalDistance(), true);
        }/*from  www  . j a va 2 s.  com*/

        program.setFloat("blurStart", blurStart, true);
        program.setFloat("blurLength", blurLength, true);
    }

    Texture colorGradingLut = Assets.getTexture("engine:colorGradingLut1");

    if (colorGradingLut != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        glBindTexture(GL12.GL_TEXTURE_3D, colorGradingLut.getId());
        program.setInt("texColorGradingLut", texId++, true);
    }

    DefaultRenderingProcess.FBO sceneCombined = DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    if (sceneCombined != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneCombined.bindDepthTexture();
        program.setInt("texDepth", texId++, true);

        Texture filmGrainNoiseTexture = Assets.getTexture("engine:noise");

        if (CoreRegistry.get(Config.class).getRendering().isFilmGrain()) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
            glBindTexture(GL11.GL_TEXTURE_2D, filmGrainNoiseTexture.getId());
            program.setInt("texNoise", texId++, true);
            program.setFloat("grainIntensity", filmGrainIntensity, true);
            program.setFloat("noiseOffset", rand.nextFloat(), true);

            program.setFloat2("noiseSize", filmGrainNoiseTexture.getWidth(), filmGrainNoiseTexture.getHeight(),
                    true);
            program.setFloat2("renderTargetSize", sceneCombined.width, sceneCombined.height, true);
        }
    }

    Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
    if (activeCamera != null && CoreRegistry.get(Config.class).getRendering().isMotionBlur()) {
        program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
        program.setMatrix4("prevViewProjMatrix", activeCamera.getPrevViewProjectionMatrix(), true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersPrePost.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    Vector3f tint = CoreRegistry.get(WorldRenderer.class).getTint();
    program.setFloat3("inLiquidTint", tint.x, tint.y, tint.z, true);

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    DefaultRenderingProcess.getInstance().bindFboTexture("sceneOpaque");
    program.setInt("texScene", texId++, true);

    if (CoreRegistry.get(Config.class).getRendering().isBloom()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().bindFboTexture("sceneBloom2");
        program.setInt("texBloom", texId++, true);

        program.setFloat("bloomFactor", bloomFactor, true);
    }//from w ww.  j  ava2s  .co m

    program.setFloat2("aberrationOffset", aberrationOffsetX, aberrationOffsetY, true);

    if (CoreRegistry.get(Config.class).getRendering().isLightShafts()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        DefaultRenderingProcess.getInstance().bindFboTexture("lightShafts");
        program.setInt("texLightShafts", texId++, true);
    }

    Texture vignetteTexture = Assets.getTexture("engine:vignette");

    if (vignetteTexture != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        glBindTexture(GL11.GL_TEXTURE_2D, vignetteTexture.getId());
        program.setInt("texVignette", texId++, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersPrePostComposite.java

License:Apache License

@Override
public void applyParameters(Material program) {
    super.applyParameters(program);

    int texId = 0;
    // TODO: obtain these objects once in superclass and add there monitoring functionality as needed?
    DisplayResolutionDependentFBOs displayResolutionDependentFBOs = CoreRegistry
            .get(DisplayResolutionDependentFBOs.class); // TODO: switch from CoreRegistry to Context.

    // TODO: move texture bindings to the appropriate nodes
    if (READ_ONLY_GBUFFER.getFbo() != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindTexture();
        program.setInt("texSceneOpaque", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindDepthTexture();
        program.setInt("texSceneOpaqueDepth", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindNormalsTexture();
        program.setInt("texSceneOpaqueNormals", texId++, true);

        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        READ_ONLY_GBUFFER.bindLightBufferTexture();
        program.setInt("texSceneOpaqueLightBuffer", texId++, true);
    }/* w  w  w.j a  v a  2  s.  co  m*/

    FBO sceneReflectiveRefractive = displayResolutionDependentFBOs
            .get(RefractiveReflectiveBlocksNode.REFRACTIVE_REFLECTIVE);

    if (sceneReflectiveRefractive != null) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        sceneReflectiveRefractive.bindTexture();
        program.setInt("texSceneReflectiveRefractive", texId++, true);
    }

    RenderingConfig renderingConfig = CoreRegistry.get(Config.class).getRendering();
    Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();

    // TODO: review - unnecessary? Probably from a time when shaders were initialized
    // TODO:          on application startup rather than renderer startup.
    if (renderingConfig == null || activeCamera == null) {
        return;
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isLocalReflections()) {
        if (sceneReflectiveRefractive != null) {
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
            sceneReflectiveRefractive.bindNormalsTexture();
            program.setInt("texSceneReflectiveRefractiveNormals", texId++, true);
        }

        program.setMatrix4("invProjMatrix", activeCamera.getInverseProjectionMatrix(), true);
        program.setMatrix4("projMatrix", activeCamera.getProjectionMatrix(), true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isSsao()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(BlurredAmbientOcclusionNode.SSAO_BLURRED_FBO);
        program.setInt("texSsao", texId++, true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isOutline()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(OutlineNode.OUTLINE);
        program.setInt("texEdges", texId++, true);

        program.setFloat("outlineDepthThreshold", outlineDepthThreshold, true);
        program.setFloat("outlineThickness", outlineThickness, true);
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isVolumetricFog()) {
        program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
        //TODO: Other parameters and volumetric fog test case is needed
    }

    // TODO: monitor the property subscribing to it
    if (renderingConfig.isInscattering()) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
        displayResolutionDependentFBOs.bindFboColorTexture(HazeNode.FINAL_HAZE);
        program.setInt("texSceneSkyBand", texId++, true);

        Vector4f skyInscatteringSettingsFrag = new Vector4f();
        skyInscatteringSettingsFrag.y = skyInscatteringStrength;
        skyInscatteringSettingsFrag.z = skyInscatteringLength;
        skyInscatteringSettingsFrag.w = skyInscatteringThreshold;
        program.setFloat4("skyInscatteringSettingsFrag", skyInscatteringSettingsFrag, true);
    }
}

From source file:org.terasology.rendering.shader.ShaderParametersScreenCombine.java

License:Apache License

@Override
public void applyParameters(ShaderProgram program) {
    PostProcessingRenderer.FBO scene = PostProcessingRenderer.getInstance().getFBO("scene");

    if (Config.getInstance().isSSAO()) {
        PostProcessingRenderer.FBO ssao = PostProcessingRenderer.getInstance().getFBO("ssaoBlurred1");
        GL13.glActiveTexture(GL13.GL_TEXTURE1);
        ssao.bindTexture();/*from w w w . j a va  2s.c  o  m*/
        program.setInt("texSsao", 1);
    }

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    scene.bindTexture();
    program.setInt("texScene", 0);
}