Java Code Examples for com.jme3.texture.Texture#getType()

The following examples show how to use com.jme3.texture.Texture#getType() . 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 5 votes vote down vote up
/**
 * Pass a texture to the material shader.
 *
 * @param name the name of the texture defined in the material definition
 * (j3md) (for example Texture for Lighting.j3md)
 * @param value the Texture object previously loaded by the asset manager
 */
public void setTexture(String name, Texture value) {
    if (value == null) {
        // clear it
        clearParam(name);
        return;
    }

    VarType paramType = null;
    switch (value.getType()) {
        case TwoDimensional:
            paramType = VarType.Texture2D;
            break;
        case TwoDimensionalArray:
            paramType = VarType.TextureArray;
            break;
        case ThreeDimensional:
            paramType = VarType.Texture3D;
            break;
        case CubeMap:
            paramType = VarType.TextureCubeMap;
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
    }

    setTextureParam(name, paramType, value);
}
 
Example 2
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setupTextureParams(Texture tex) {
        int target = convertTextureType(tex.getType());

        // filter things
        int minFilter = convertMinFilter(tex.getMinFilter());
        int magFilter = convertMagFilter(tex.getMagFilter());
        gl.glTexParameteri(target, gl.GL_TEXTURE_MIN_FILTER, minFilter);
        gl.glTexParameteri(target, gl.GL_TEXTURE_MAG_FILTER, magFilter);

        // repeat modes
        switch (tex.getType()) {
            case ThreeDimensional:
            case CubeMap:
                gl.glTexParameteri(target, gl.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
            case TwoDimensional:
                gl.glTexParameteri(target, gl.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
                // fall down here is intentional..
//            case OneDimensional:
                gl.glTexParameteri(target, gl.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                break;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
        }

        // R to Texture compare mode
        if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
            gl.glTexParameteri(target, GL.GL_TEXTURE_COMPARE_MODE, GL.GL_COMPARE_R_TO_TEXTURE);
            gl.glTexParameteri(target, GL.GL_DEPTH_TEXTURE_MODE, GL.GL_INTENSITY);
            if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
                gl.glTexParameteri(target, GL.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
            } else {
                gl.glTexParameteri(target, GL.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
            }
        }
    }
 
Example 3
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Pass a texture to the material shader.
 *
 * @param name the name of the texture defined in the material definition
 * (j3md) (for example Texture for Lighting.j3md)
 * @param value the Texture object previously loaded by the asset manager
 */
public void setTexture(String name, Texture value) {
    if (value == null) {
        // clear it
        clearTextureParam(name);
        return;
    }

    VarType paramType = null;
    switch (value.getType()) {
        case TwoDimensional:
            paramType = VarType.Texture2D;
            break;
        case TwoDimensionalArray:
            paramType = VarType.TextureArray;
            break;
        case ThreeDimensional:
            paramType = VarType.Texture3D;
            break;
        case CubeMap:
            paramType = VarType.TextureCubeMap;
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
    }

    setTextureParam(name, paramType, value);
}
 
Example 4
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("fallthrough")
private void setupTextureParams(int unit, Texture tex) {
    Image image = tex.getImage();
    int samples = image != null ? image.getMultiSamples() : 1;
    int target = convertTextureType(tex.getType(), samples, -1);

    if (samples > 1) {
        bindTextureOnly(target, image, unit);
        return;
    }

    boolean haveMips = true;
    if (image != null) {
        haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps();
    }
    
    LastTextureState curState = image.getLastTextureState();

    if (curState.magFilter != tex.getMagFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, convertMagFilter(tex.getMagFilter()));
        curState.magFilter = tex.getMagFilter();
    }
    if (curState.minFilter != tex.getMinFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, convertMinFilter(tex.getMinFilter(), haveMips));
        curState.minFilter = tex.getMinFilter();
    }

    int desiredAnisoFilter = tex.getAnisotropicFilter() == 0
            ? defaultAnisotropicFilter
            : tex.getAnisotropicFilter();

    if (caps.contains(Caps.TextureFilterAnisotropic)
            && curState.anisoFilter != desiredAnisoFilter) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameterf(target,
                GLExt.GL_TEXTURE_MAX_ANISOTROPY_EXT,
                desiredAnisoFilter);
        curState.anisoFilter = desiredAnisoFilter;
    }

    switch (tex.getType()) {
        case ThreeDimensional:
        case CubeMap: // cubemaps use 3D coords
            if (gl2 != null && (caps.contains(Caps.OpenGL20) || caps.contains(Caps.OpenGLES30)) && curState.rWrap != tex.getWrap(WrapAxis.R)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
                curState.rWrap = tex.getWrap(WrapAxis.R);
            }
            //There is no break statement on purpose here
        case TwoDimensional:
        case TwoDimensionalArray:
            if (curState.tWrap != tex.getWrap(WrapAxis.T)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
                image.getLastTextureState().tWrap = tex.getWrap(WrapAxis.T);
            }
            if (curState.sWrap != tex.getWrap(WrapAxis.S)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                curState.sWrap = tex.getWrap(WrapAxis.S);
            }
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
    }

    ShadowCompareMode texCompareMode = tex.getShadowCompareMode();
    if ( (gl2 != null || caps.contains(Caps.OpenGLES30)) && curState.shadowCompareMode != texCompareMode) {
        bindTextureAndUnit(target, image, unit);
        if (texCompareMode != ShadowCompareMode.Off) {
            gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE);
            if (texCompareMode == ShadowCompareMode.GreaterOrEqual) {
                gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
            } else {
                gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
            }
        } else {
            gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
        }
        curState.shadowCompareMode = texCompareMode;
    }
    
    // If at this point we didn't bind the texture, bind it now
    bindTextureOnly(target, image, unit);
}
 
Example 5
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Validates if a potentially NPOT texture is supported by the hardware.
 * <p>
 * Textures with power-of-2 dimensions are supported on all hardware, however 
 * non-power-of-2 textures may or may not be supported depending on which
 * texturing features are used.
 *
 * @param tex The texture to validate.
 * @throws RendererException If the texture is not supported by the hardware
 */
private void checkNonPowerOfTwo(Texture tex) {
    if (!tex.getImage().isNPOT()) {
        // Texture is power-of-2, safe to use.
        return;
    }

    if (caps.contains(Caps.NonPowerOfTwoTextures)) {
        // Texture is NPOT but it is supported by video hardware.
        return;
    }

    // Maybe we have some / partial support for NPOT?
    if (!caps.contains(Caps.PartialNonPowerOfTwoTextures)) {
        // Cannot use any type of NPOT texture (uncommon)
        throw new RendererException("non-power-of-2 textures are not "
                + "supported by the video hardware");
    }

    // Partial NPOT supported..
    if (tex.getMinFilter().usesMipMapLevels()) {
        throw new RendererException("non-power-of-2 textures with mip-maps "
                + "are not supported by the video hardware");
    }

    switch (tex.getType()) {
        case CubeMap:
        case ThreeDimensional:
            if (tex.getWrap(WrapAxis.R) != Texture.WrapMode.EdgeClamp) {
                throw new RendererException("repeating non-power-of-2 textures "
                        + "are not supported by the video hardware");
            }
            // fallthrough intentional!!!
        case TwoDimensionalArray:
        case TwoDimensional:
            if (tex.getWrap(WrapAxis.S) != Texture.WrapMode.EdgeClamp
                    || tex.getWrap(WrapAxis.T) != Texture.WrapMode.EdgeClamp) {
                throw new RendererException("repeating non-power-of-2 textures "
                        + "are not supported by the video hardware");
            }
            break;
        default:
            throw new UnsupportedOperationException("unrecongized texture type");
    }
}
 
Example 6
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * <code>setupTextureParams</code> sets the OpenGL context texture parameters
     * @param tex the Texture to set the texture parameters from
     */
    private void setupTextureParams(Texture tex) {
        int target = convertTextureType(tex.getType());

        // filter things
        int minFilter = convertMinFilter(tex.getMinFilter());
        int magFilter = convertMagFilter(tex.getMagFilter());

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_MIN_FILTER, " + minFilter + ")");
        }

        Gdx.gl20.glTexParameteri(target, GL20.GL_TEXTURE_MIN_FILTER, minFilter);

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_MAG_FILTER, " + magFilter + ")");
        }

        Gdx.gl20.glTexParameteri(target, GL20.GL_TEXTURE_MAG_FILTER, magFilter);

        /*        
        if (tex.getAnisotropicFilter() > 1){
        
        if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic){
        glTexParameterf(target,
        EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
        tex.getAnisotropicFilter());
        }
        
        }
         */
        // repeat modes

        switch (tex.getType()) {
            case ThreeDimensional:
            case CubeMap: // cubemaps use 3D coords
                // GL_TEXTURE_WRAP_R is not available in api 8
                //GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
            case TwoDimensional:
            case TwoDimensionalArray:

                if (verboseLogging) {
                    logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_WRAP_T, " + convertWrapMode(tex.getWrap(WrapAxis.T)));
                }

                Gdx.gl20.glTexParameteri(target, GL20.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));

                // fall down here is intentional..
//          case OneDimensional:

                if (verboseLogging) {
                    logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_WRAP_S, " + convertWrapMode(tex.getWrap(WrapAxis.S)));
                }

                Gdx.gl20.glTexParameteri(target, GL20.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                break;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
        }

        // R to Texture compare mode
/*
        if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off){
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_MODE, GLES20.GL_COMPARE_R_TO_TEXTURE);
        GLES20.glTexParameteri(target, GLES20.GL_DEPTH_TEXTURE_MODE, GLES20.GL_INTENSITY);
        if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual){
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_GEQUAL);
        }else{
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_LEQUAL);
        }
        }
         */
    }
 
Example 7
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * <code>setupTextureParams</code> sets the OpenGL context texture parameters
     * @param tex the Texture to set the texture parameters from
     */
    private void setupTextureParams(Texture tex) {
        int target = convertTextureType(tex.getType());

        // filter things
        int minFilter = convertMinFilter(tex.getMinFilter());
        int magFilter = convertMagFilter(tex.getMagFilter());

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_MIN_FILTER, " + minFilter + ")");
        }

        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MIN_FILTER, minFilter);

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_MAG_FILTER, " + magFilter + ")");
        }

        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MAG_FILTER, magFilter);

        /*        
        if (tex.getAnisotropicFilter() > 1){
        
        if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic){
        glTexParameterf(target,
        EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
        tex.getAnisotropicFilter());
        }
        
        }
         */
        // repeat modes

        switch (tex.getType()) {
            case ThreeDimensional:
            case CubeMap: // cubemaps use 3D coords
            // GL_TEXTURE_WRAP_R is not available in api 8
            //GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
            case TwoDimensional:
            case TwoDimensionalArray:

                if (verboseLogging) {
                    logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_WRAP_T, " + convertWrapMode(tex.getWrap(WrapAxis.T)));
                }

                GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));

                // fall down here is intentional..
//          case OneDimensional:

                if (verboseLogging) {
                    logger.info("GLES20.glTexParameteri(" + target + ", GLES20.GL_TEXTURE_WRAP_S, " + convertWrapMode(tex.getWrap(WrapAxis.S)));
                }

                GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                break;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
        }

        // R to Texture compare mode
/*
        if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off){
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_MODE, GLES20.GL_COMPARE_R_TO_TEXTURE);
        GLES20.glTexParameteri(target, GLES20.GL_DEPTH_TEXTURE_MODE, GLES20.GL_INTENSITY);
        if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual){
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_GEQUAL);
        }else{
        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_LEQUAL);
        }
        }
         */
    }
 
Example 8
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateTextureData(Texture tex) {
    int texId = tex.getId();
    GL gl = GLContext.getCurrentGL();
    if (texId == -1) {
        // create texture
        gl.glGenTextures(1, intBuf1);
        texId = intBuf1.get(0);
        tex.setId(texId);
        objManager.registerForCleanup(tex);
    }

    // bind texture
    int target = convertTextureType(tex.getType());
    if (context.boundTextures[0] != tex) {
        if (context.boundTextureUnit != 0) {
            setActiveTexture(GL.GL_TEXTURE0);
            context.boundTextureUnit = 0;
        }

        bindTexture(target, texId);
        context.boundTextures[0] = tex;
    }

    // filter things
    int minFilter = convertMinFilter(tex.getMinFilter());
    int magFilter = convertMagFilter(tex.getMagFilter());
    gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, minFilter);
    gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, magFilter);

    // repeat modes
    switch (tex.getType()) {
        case ThreeDimensional:
        case CubeMap:
            gl.glTexParameteri(target, GL2GL3.GL_TEXTURE_WRAP_R,
                    convertWrapMode(tex.getWrap(WrapAxis.R)));
        case TwoDimensional:
            gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T,
                    convertWrapMode(tex.getWrap(WrapAxis.T)));
            // fall down here is intentional..
            // case OneDimensional:
            gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S,
                    convertWrapMode(tex.getWrap(WrapAxis.S)));
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
    }

    Image img = tex.getImage();
    if (img != null) {
        boolean generateMips = false;
        if (!img.hasMipmaps() && tex.getMinFilter().usesMipMapLevels()) {
            // No pregenerated mips available,
            // generate from base level if required
            if (hardwareMips) {
                gl.glTexParameteri(target, GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE);
            }
            else {
                generateMips = true;
            }
        }

        TextureUtil.uploadTexture(gl, img, tex.getImageDataIndex(), generateMips, powerOf2);
    }

    tex.clearUpdateNeeded();
}
 
Example 9
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("fallthrough")
    private void setupTextureParams(Texture tex) {
        Image image = tex.getImage();
        int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1);

        // filter things
        int minFilter = convertMinFilter(tex.getMinFilter());
        int magFilter = convertMagFilter(tex.getMagFilter());
        glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
        glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);

        if (tex.getAnisotropicFilter() > 1) {
            if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
                glTexParameterf(target,
                        EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
                        tex.getAnisotropicFilter());
            }
        }

        if (context.pointSprite) {
            return; // Attempt to fix glTexParameter crash for some ATI GPUs
        }
        // repeat modes
        switch (tex.getType()) {
            case ThreeDimensional:
            case CubeMap: // cubemaps use 3D coords
                glTexParameteri(target, GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
            case TwoDimensional:
            case TwoDimensionalArray:
                glTexParameteri(target, GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
                // fall down here is intentional..
//            case OneDimensional:
                glTexParameteri(target, GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                break;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
        }

        // R to Texture compare mode
        if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
            glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
            glTexParameteri(target, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
            if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
                glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
            } else {
                glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
            }
        }
    }