Java Code Examples for com.jme3.texture.Texture#Type

The following examples show how to use com.jme3.texture.Texture#Type . 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: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/*********************************************************************\
|* Textures                                                          *|
\*********************************************************************/
private int convertTextureType(Texture.Type type, int samples) {
    switch (type) {
        case TwoDimensional:
            if (samples > 1) {
                return ARBTextureMultisample.GL_TEXTURE_2D_MULTISAMPLE;
            } else {
                return GL_TEXTURE_2D;
            }
        case TwoDimensionalArray:
            if (samples > 1) {
                return ARBTextureMultisample.GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
            } else {
                return EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT;
            }
        case ThreeDimensional:
            return GL_TEXTURE_3D;
        case CubeMap:
            return GL_TEXTURE_CUBE_MAP;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + type);
    }
}
 
Example 2
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) {
    int imageID = image.getId();
    if (imageID == -1) {
        throw new IllegalArgumentException("image was not yet uploaded to the GPU");
    }
    long memFlags = Utils.getMemoryAccessFlags(access);
    int textureTarget = convertTextureType(textureType);
    Utils.errorBuffer.rewind();
    CLMem mem = CL12GL.clCreateFromGLTexture(context, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer);
    Utils.checkError(Utils.errorBuffer, "clCreateFromGLTexture");
    return new LwjglImage(mem);
}
 
Example 3
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int convertTextureType(Texture.Type textureType) {
    switch (textureType) {
        case TwoDimensional: return GL11.GL_TEXTURE_2D;
        case TwoDimensionalArray: return GL30.GL_TEXTURE_2D_ARRAY;
        case ThreeDimensional: return GL12.GL_TEXTURE_3D;
        case CubeMap: return GL13.GL_TEXTURE_CUBE_MAP;
        default: throw new IllegalArgumentException("unknown texture type "+textureType);
    }
}
 
Example 4
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) {
    Utils.assertSharingPossible();
    int imageID = image.getId();
    if (imageID == -1) {
        throw new IllegalArgumentException("image was not yet uploaded to the GPU");
    }
    long memFlags = Utils.getMemoryAccessFlags(access);
    int textureTarget = convertTextureType(textureType);
    Utils.errorBuffer.rewind();
    long mem = CL12GL.clCreateFromGLTexture(context, memFlags, textureTarget, miplevel, imageID, Utils.errorBuffer);
    Utils.checkError(Utils.errorBuffer, "clCreateFromGLTexture");
    return new LwjglImage(mem);
}
 
Example 5
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int convertTextureType(Texture.Type textureType) {
    switch (textureType) {
        case TwoDimensional: return GL11.GL_TEXTURE_2D;
        case TwoDimensionalArray: return GL30.GL_TEXTURE_2D_ARRAY;
        case ThreeDimensional: return GL12.GL_TEXTURE_3D;
        case CubeMap: return GL13.GL_TEXTURE_CUBE_MAP;
        default: throw new IllegalArgumentException("unknown texture type "+textureType);
    }
}
 
Example 6
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/*********************************************************************\
     |* Textures                                                          *|
     \*********************************************************************/
    private int convertTextureType(Texture.Type type) {
        switch (type) {
            case TwoDimensional:
                return GL20.GL_TEXTURE_2D;
            //        case TwoDimensionalArray:
            //            return EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT;
//            case ThreeDimensional:
            //               return GLES20.GL_TEXTURE_3D;
            case CubeMap:
                return GL20.GL_TEXTURE_CUBE_MAP;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + type);
        }
    }
 
Example 7
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int convertTextureType(Texture.Type type) {
    switch (type) {
        case TwoDimensional:
            return gl.GL_TEXTURE_2D;
        case TwoDimensionalArray:
            return gl.GL_TEXTURE_2D_ARRAY_EXT;
        case ThreeDimensional:
            return gl.GL_TEXTURE_3D;
        case CubeMap:
            return gl.GL_TEXTURE_CUBE_MAP;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + type);
    }
}
 
Example 8
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 9
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/*********************************************************************\
    |* Textures                                                          *|
    \*********************************************************************/
    private int convertTextureType(Texture.Type type) {
        switch (type) {
            case TwoDimensional:
                return GLES20.GL_TEXTURE_2D;
            //        case TwoDimensionalArray:
            //            return EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT;
//            case ThreeDimensional:
            //               return GLES20.GL_TEXTURE_3D;
            case CubeMap:
                return GLES20.GL_TEXTURE_CUBE_MAP;
            default:
                throw new UnsupportedOperationException("Unknown texture type: " + type);
        }
    }
 
Example 10
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected int convertTextureType(Texture.Type type) {
    switch (type) {
        case TwoDimensional:
            return GL.GL_TEXTURE_2D;
        case TwoDimensionalArray:
            return GL.GL_TEXTURE_2D_ARRAY;
        case ThreeDimensional:
            return GL2GL3.GL_TEXTURE_3D;
        case CubeMap:
            return GL.GL_TEXTURE_CUBE_MAP;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + type);
    }
}
 
Example 11
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/*********************************************************************\
 |* Textures                                                          *|
 \*********************************************************************/
private int convertTextureType(Texture.Type type, int samples, int face) {
    if (samples > 1 && !caps.contains(Caps.TextureMultisample)) {
        throw new RendererException("Multisample textures are not supported" +
                " by the video hardware.");
    }

    switch (type) {
        case TwoDimensional:
            if (samples > 1) {
                return GLExt.GL_TEXTURE_2D_MULTISAMPLE;
            } else {
                return GL.GL_TEXTURE_2D;
            }
        case TwoDimensionalArray:
            if (!caps.contains(Caps.TextureArray)) {
                throw new RendererException("Array textures are not supported"
                        + " by the video hardware.");
            }
            if (samples > 1) {
                return GLExt.GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
            } else {
                return GLExt.GL_TEXTURE_2D_ARRAY_EXT;
            }
        case ThreeDimensional:
            if (!caps.contains(Caps.OpenGL20) && !caps.contains(Caps.OpenGLES30)) {
                throw new RendererException("3D textures are not supported" +
                        " by the video hardware.");
            }
            return GL2.GL_TEXTURE_3D;
        case CubeMap:
            if (face < 0) {
                return GL.GL_TEXTURE_CUBE_MAP;
            } else if (face < 6) {
                return GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
            } else {
                throw new UnsupportedOperationException("Invalid cube map face index: " + face);
            }
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + type);
    }
}
 
Example 12
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 13
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();
}
 
Example 14
Source File: Context.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Creates a shared image object from a jME3-image.
 * The returned image shares the same memory with the jME3-image, changes
 * in one view are visible in the other view.
 * This can be used to modify textures and images directly from OpenCL
 * (e.g. for post processing effects and other texture effects).
 * <br>
 * <b>Note:</b> The image must already been uploaded to the GPU,
 * i.e. it must be used at least once for drawing.
 * <p>
 * Before the returned image can be used, it must be acquired explicitly
 * by {@link Image#acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) }
 * and after modifying it, released by {@link Image#releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) }
 * This is needed so that OpenGL and OpenCL operations do not interfere with each other.
 *
 * @param image the jME3 image object
 * @param textureType the texture type (1D, 2D, 3D), since this is not stored in the image
 * @param miplevel the mipmap level that should be shared
 * @param access the allowed memory access for kernels
 * @return the OpenCL image
 */
public abstract Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access);
 
Example 15
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License votes vote down vote up
protected abstract int convertTextureType(Texture.Type type);