Java Code Examples for com.jme3.texture.Image#getId()

The following examples show how to use com.jme3.texture.Image#getId() . 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: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);

        if (verboseLogging) {
            logger.info("GLES20.glDeleteTexture(1, buffer)");
        }

        Gdx.gl20.glDeleteTextures(1, intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example 2
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);

        if (verboseLogging) {
            logger.info("GLES20.glDeleteTexture(1, buffer)");
        }

        GLES20.glDeleteTextures(1, intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example 3
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);
        gl.glDeleteTextures(intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example 4
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the sorting ID or sorting index for this material.
 *
 * <p>The sorting ID is used internally by the system to sort rendering
 * of geometries. It sorted to reduce shader switches, if the shaders
 * are equal, then it is sorted by textures.
 *
 * @return The sorting ID used for sorting geometries for rendering.
 */
public int getSortId() {
    if (sortingId == -1 && technique != null) {
        sortingId = technique.getSortId() << 16;
        int texturesSortId = 17;
        for (int i = 0; i < paramValues.size(); i++) {
            MatParam param = paramValues.getValue(i);
            if (!param.getVarType().isTextureType()) {
                continue;
            }
            Texture texture = (Texture) param.getValue();
            if (texture == null) {
                continue;
            }
            Image image = texture.getImage();
            if (image == null) {
                continue;
            }
            int textureId = image.getId();
            if (textureId == -1) {
                textureId = 0;
            }
            texturesSortId = texturesSortId * 23 + textureId;
        }
        sortingId |= texturesSortId & 0xFFFF;
    }
    return sortingId;
}
 
Example 5
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateTexImageData(Image image, Texture.Type type, boolean mips) {
    int texId = image.getId();
    if (texId == -1) {
        // create texture
        gl.glGenTextures(1, ib1);
        texId = ib1.get(0);
        image.setId(texId);
        objManager.registerForCleanup(image);

        statistics.onNewTexture();
    }

    // bind texture
    int target = convertTextureType(type);
    if (context.boundTextures[0] != image) {
        if (context.boundTextureUnit != 0) {
            gl.glActiveTexture(gl.GL_TEXTURE0);
            context.boundTextureUnit = 0;
        }

        gl.glBindTexture(target, texId);
        context.boundTextures[0] = image;
    }

    boolean generateMips = false;
    if (!image.hasMipmaps() && mips) {
        // No pregenerated mips available,
        // generate from base level if required
        if (hardwareMips) {
            gl.glTexParameteri(target, GL.GL_GENERATE_MIPMAP, gl.GL_TRUE);
        } else {
            generateMips = true;
        }
    }

    TextureUtil.uploadTexture(gl, image, 0, generateMips, powerOf2);


    image.clearUpdateNeeded();
}
 
Example 6
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        ib1.put(0, texId);
        ib1.position(0).limit(1);
        gl.glDeleteTextures(1, ib1);
        image.resetObject();
    }
}
 
Example 7
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteImage(Image image) {
    int texId = image.getId();
    if (texId != -1) {
        intBuf1.put(0, texId);
        intBuf1.position(0).limit(1);
        glDeleteTextures(intBuf1);
        image.resetObject();

        statistics.onDeleteTexture();
    }
}
 
Example 8
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * <code>updateTexImageData</code> activates and binds the texture
     * @param img
     * @param type
     * @param mips
     */
    public void updateTexImageData(Image img, Texture.Type type, boolean mips) {
        int texId = img.getId();
        if (texId == -1) {
            // create texture
            if (verboseLogging) {
                logger.info("GLES20.glGenTexture(1, buffer)");
            }

            Gdx.gl20.glGenTextures(1, intBuf1);
            texId = intBuf1.get(0);
            img.setId(texId);
            objManager.registerForCleanup(img);

            statistics.onNewTexture();
        }

        // bind texture
        int target = convertTextureType(type);
        if (context.boundTextureUnit != 0) {
            if (verboseLogging) {
                logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0)");
            }

            Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
            context.boundTextureUnit = 0;
        }
        if (context.boundTextures[0] != img) {

            if (verboseLogging) {
                logger.info("GLES20.glBindTexture(" + target + ", " + texId + ")");
            }

            Gdx.gl20.glBindTexture(target, texId);
            context.boundTextures[0] = img;
        }


        if (target == GL20.GL_TEXTURE_CUBE_MAP) {
            // Upload a cube map / sky box
            // TODO
//            @SuppressWarnings("unchecked")
//            List<Bitmap> bmps = (List<Bitmap>) img.getEfficentData();
//            if (bmps != null) {
//                // Native android bitmap
//                if (bmps.size() != 6) {
//                    throw new UnsupportedOperationException("Invalid texture: " + img
//                            + "Cubemap textures must contain 6 data units.");
//                }
//                for (int i = 0; i < 6; i++) {
//                    TextureUtilGdx.uploadTextureBitmap(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, bmps.get(i), false, powerOf2);
//                }
//            } else {
//                // Standard jme3 image data
//                List<ByteBuffer> data = img.getData();
//                if (data.size() != 6) {
//                    logger.log(Level.WARNING, "Invalid texture: {0}\n"
//                            + "Cubemap textures must contain 6 data units.", img);
//                    return;
//                }
//                for (int i = 0; i < 6; i++) {
//                    TextureUtilGdx.uploadTexture(img, GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc, false, powerOf2);
//                }
//            }
        } else {
            // TODO
            TextureUtilGdx.uploadTexture(img, target, 0, 0, tdc, false, powerOf2);

            if (verboseLogging) {
                logger.info("GLES20.glTexParameteri(" + target + "GLES11.GL_GENERATE_MIMAP, GLES20.GL_TRUE)");
            }

            if (!img.hasMipmaps() && mips) {
                // No pregenerated mips available,
                // generate from base level if required
                if (verboseLogging) {
                    logger.info("GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D)");
                }
                Gdx.gl20.glGenerateMipmap(GL20.GL_TEXTURE_2D);
            }
        }

        img.clearUpdateNeeded();
    }
 
Example 9
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * <code>updateTexImageData</code> activates and binds the texture
 * @param img
 * @param type
 * @param mips
 */
public void updateTexImageData(Image img, Texture.Type type, boolean mips) {
    int texId = img.getId();
    if (texId == -1) {
        // create texture
        if (verboseLogging) {
            logger.info("GLES20.glGenTexture(1, buffer)");
        }

        GLES20.glGenTextures(1, intBuf1);
        texId = intBuf1.get(0);
        img.setId(texId);
        objManager.registerForCleanup(img);

        statistics.onNewTexture();
    }

    // bind texture
    int target = convertTextureType(type);
    if (context.boundTextureUnit != 0) {
        if (verboseLogging) {
            logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0)");
        }

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        context.boundTextureUnit = 0;
    }
    if (context.boundTextures[0] != img) {

        if (verboseLogging) {
            logger.info("GLES20.glBindTexture(" + target + ", " + texId + ")");
        }

        GLES20.glBindTexture(target, texId);
        context.boundTextures[0] = img;
    }


    if (target == GLES20.GL_TEXTURE_CUBE_MAP) {
        // Upload a cube map / sky box
        @SuppressWarnings("unchecked")
        List<Bitmap> bmps = (List<Bitmap>) img.getEfficentData();
        if (bmps != null) {
            // Native android bitmap                                       
            if (bmps.size() != 6) {
                throw new UnsupportedOperationException("Invalid texture: " + img
                        + "Cubemap textures must contain 6 data units.");
            }
            for (int i = 0; i < 6; i++) {
                TextureUtil.uploadTextureBitmap(GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, bmps.get(i), false, powerOf2);
            }
        } else {
            // Standard jme3 image data
            List<ByteBuffer> data = img.getData();
            if (data.size() != 6) {
                logger.log(Level.WARNING, "Invalid texture: {0}\n"
                        + "Cubemap textures must contain 6 data units.", img);
                return;
            }
            for (int i = 0; i < 6; i++) {
                TextureUtil.uploadTexture(img, GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc, false, powerOf2);
            }
        }
    } else {
        TextureUtil.uploadTexture(img, target, 0, 0, tdc, false, powerOf2);

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + "GLES11.GL_GENERATE_MIMAP, GLES20.GL_TRUE)");
        }

        if (!img.hasMipmaps() && mips) {
            // No pregenerated mips available,
            // generate from base level if required
            if (verboseLogging) {
                logger.info("GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D)");
            }
            GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
        }
    }

    img.clearUpdateNeeded();
}