Example usage for com.badlogic.gdx.graphics.g3d.materials TextureAttribute MAX_TEXTURE_UNITS

List of usage examples for com.badlogic.gdx.graphics.g3d.materials TextureAttribute MAX_TEXTURE_UNITS

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.materials TextureAttribute MAX_TEXTURE_UNITS.

Prototype

int MAX_TEXTURE_UNITS

To view the source code for com.badlogic.gdx.graphics.g3d.materials TextureAttribute MAX_TEXTURE_UNITS.

Click Source Link

Usage

From source file:com.badlogic.gdx.graphics.g3d.test.PrototypeRendererGL20.java

License:Apache License

private void flush() {

    // opaque is sorted front to back
    // transparent is sorted back to front
    drawableManager.drawables.sort(opaqueSorter);
    for (int i = drawableManager.drawables.size; --i >= 0;) {

        final Drawable drawable = drawableManager.drawables.get(i);

        final Vector3 center = drawable.sortCenter;
        lightManager.calculateLights(center.x, center.y, center.z);

        final Matrix4 modelMatrix = drawable.transform;
        normalMatrix.set(modelMatrix);//  ww  w. j av a 2 s .  c  o m

        if (drawable.isAnimated)
            ((AnimatedModel) (drawable.model)).setAnimation(drawable.animation, drawable.animationTime,
                    drawable.isLooping);

        final SubMesh subMeshes[] = drawable.model.getSubMeshes();

        boolean matrixChanged = true;
        for (int j = 0; j < subMeshes.length; j++) {

            final SubMesh subMesh = subMeshes[j];
            final Material material = drawable.materials.get(j);

            // bind new shader if material can't use old one
            final boolean shaderChanged = bindShader(material);

            if (shaderChanged || matrixChanged) {
                currentShader.setUniformMatrix("u_normalMatrix", normalMatrix, false);
                currentShader.setUniformMatrix("u_modelMatrix", modelMatrix, false);
                matrixChanged = false;
            }

            for (int k = 0, len = material.getNumberOfAttributes(); k < len; k++) {
                final MaterialAttribute atrib = material.getAttribute(k);

                // special case for textures. really important to batch these
                if (atrib instanceof TextureAttribute) {
                    final TextureAttribute texAtrib = (TextureAttribute) atrib;
                    if (!texAtrib.texturePortionEquals(lastTexture[texAtrib.unit])) {
                        lastTexture[texAtrib.unit] = texAtrib;
                        texAtrib.bind(currentShader);
                    } else {
                        // need to be done, shader textureAtribute name could be changed.
                        currentShader.setUniformi(texAtrib.name, texAtrib.unit);
                    }
                } else if (atrib instanceof GpuSkinningAttribute) {
                    GpuSkinningAttribute gpuAttrib = (GpuSkinningAttribute) atrib;
                    gpuAttrib.setModelMatrix(modelMatrix);
                    gpuAttrib.bind(currentShader);
                } else {
                    atrib.bind(currentShader);
                }
            }

            // finally render current submesh
            subMesh.getMesh().render(currentShader, subMesh.primitiveType);
        }
    }

    // if transparent queue is not empty enable blending(this force gpu to
    // flush and there is some time to sort)
    if (drawableManager.drawablesBlended.size > 0)
        renderBlended();

    // cleaning

    if (currentShader != null) {
        currentShader.end();
        currentShader = null;
    }
    for (int i = 0, len = TextureAttribute.MAX_TEXTURE_UNITS; i < len; i++)
        lastTexture[i] = null;
    // clear all queus

    drawing = false;

    drawableManager.clear();
}