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

The following examples show how to use com.jme3.texture.Image#getMultiSamples() . 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: SkyFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void checkImage(Image image) {
//        if (image.getDepth() != 1)
//            throw new IllegalArgumentException("3D/Array images not allowed");

        if (image.getWidth() != image.getHeight()) {
            throw new IllegalArgumentException("Image width and height must be the same");
        }

        if (image.getMultiSamples() != 1) {
            throw new IllegalArgumentException("Multisample textures not allowed");
        }
    }
 
Example 2
Source File: SkyFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void checkImage(Image image) {
//        if (image.getDepth() != 1)
//            throw new IllegalArgumentException("3D/Array images not allowed");

        if (image.getWidth() != image.getHeight()) {
            throw new IllegalArgumentException("Image width and height must be the same");
        }

        if (image.getMultiSamples() != 1) {
            throw new IllegalArgumentException("Multisample textures not allowed");
        }
    }
 
Example 3
Source File: TextureUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void uploadTexture(Image image,
                          int target,
                          int index,
                          boolean linearizeSrgb) {

    boolean getSrgbFormat = image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb;
    Image.Format jmeFormat = image.getFormat();
    GLImageFormat oglFormat = getImageFormatWithError(jmeFormat, getSrgbFormat);

    ByteBuffer data = null;
    int sliceCount = 1;
    
    if (index >= 0) {
        data = image.getData(index);
    }
    
    if (image.getData() != null && image.getData().size() > 0) {
        sliceCount = image.getData().size();
    }

    int width = image.getWidth();
    int height = image.getHeight();
    int depth = image.getDepth();
    
    int[] mipSizes = image.getMipMapSizes();
    int pos = 0;
    // TODO: Remove unnecessary allocation
    if (mipSizes == null) {
        if (data != null) {
            mipSizes = new int[]{data.capacity()};
        } else {
            mipSizes = new int[]{width * height * jmeFormat.getBitsPerPixel() / 8};
        }
    }

    int samples = image.getMultiSamples();
    
    // For OGL3 core: setup texture swizzle.
    if (oglFormat.swizzleRequired) {
        setupTextureSwizzle(target, jmeFormat);
    }

    for (int i = 0; i < mipSizes.length; i++) {
        int mipWidth = Math.max(1, width >> i);
        int mipHeight = Math.max(1, height >> i);
        int mipDepth = Math.max(1, depth >> i);

        if (data != null) {
            data.position(pos);
            data.limit(pos + mipSizes[i]);
        }

        uploadTextureLevel(oglFormat, target, i, index, sliceCount, mipWidth, mipHeight, mipDepth, samples, data);

        pos += mipSizes[i];
    }
}
 
Example 4
Source File: TextureUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @deprecated Use uploadSubTexture(int target,  Image src, int index,int targetX, int targetY,int srcX,int srcY,  int areaWidth,int areaHeight, boolean linearizeSrgb) 
 */
@Deprecated
public void uploadSubTexture(Image image, int target, int index, int x, int y, boolean linearizeSrgb) {
    if (target != GL.GL_TEXTURE_2D || image.getDepth() > 1) {
        throw new UnsupportedOperationException("Updating non-2D texture is not supported");
    }
    
    if (image.getMipMapSizes() != null) {
        throw new UnsupportedOperationException("Updating mip-mapped images is not supported");
    }
    
    if (image.getMultiSamples() > 1) {
        throw new UnsupportedOperationException("Updating multisampled images is not supported");
    }
    
    Image.Format jmeFormat = image.getFormat();
    
    if (jmeFormat.isCompressed()) {
        throw new UnsupportedOperationException("Updating compressed images is not supported");
    } else if (jmeFormat.isDepthFormat()) {
        throw new UnsupportedOperationException("Updating depth images is not supported");
    }
    
    boolean getSrgbFormat = image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb;
    GLImageFormat oglFormat = getImageFormatWithError(jmeFormat, getSrgbFormat);
    
    ByteBuffer data = null;
    
    if (index >= 0) {
        data = image.getData(index);
    }
    
    if (data == null) {
        throw new IndexOutOfBoundsException("The image index " + index + " is not valid for the given image");
    }

    data.position(0);
    data.limit(data.capacity());
    
    gl.glTexSubImage2D(target, 0, x, y, image.getWidth(), image.getHeight(), 
                       oglFormat.format, oglFormat.dataType, data);
}
 
Example 5
Source File: TextureUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void uploadSubTexture(int target, Image src, int index, int targetX, int targetY, int areaX, int areaY, int areaWidth, int areaHeight, boolean linearizeSrgb) {
    if (target != GL.GL_TEXTURE_2D || src.getDepth() > 1) {
        throw new UnsupportedOperationException("Updating non-2D texture is not supported");
    }

    if (src.getMipMapSizes() != null) {
        throw new UnsupportedOperationException("Updating mip-mappped images is not supported");
    }

    if (src.getMultiSamples() > 1) {
        throw new UnsupportedOperationException("Updating multisampled images is not supported");
    }

    Image.Format jmeFormat = src.getFormat();

    if (jmeFormat.isCompressed()) {
        throw new UnsupportedOperationException("Updating compressed images is not supported");
    } else if (jmeFormat.isDepthFormat()) {
        throw new UnsupportedOperationException("Updating depth images is not supported");
    }

    boolean getSrgbFormat = src.getColorSpace() == ColorSpace.sRGB && linearizeSrgb;
    GLImageFormat oglFormat = getImageFormatWithError(jmeFormat, getSrgbFormat);

    ByteBuffer data = src.getData(index);

    if (data == null) {
        throw new IndexOutOfBoundsException("The image index " + index + " is not valid for the given image");
    }

    int Bpp = src.getFormat().getBitsPerPixel() / 8;

    int srcWidth = src.getWidth();
    int cpos = data.position();
    int skip = areaX;
    skip += areaY * srcWidth;
    skip *= Bpp;

    data.position(skip);

    boolean needsStride = srcWidth != areaWidth;

    if (needsStride && (!supportUnpackRowLength)) { // doesn't support stride, copy row by row (slower).
        for (int i = 0; i < areaHeight; i++) {
            data.position(skip + (srcWidth * Bpp * i));
            gl.glTexSubImage2D(target, 0, targetX, targetY + i, areaWidth, 1, oglFormat.format, oglFormat.dataType, data);
        }
    } else {
        if (needsStride)
            gl2.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, srcWidth);
        gl.glTexSubImage2D(target, 0, targetX, targetY, areaWidth, areaHeight, oglFormat.format, oglFormat.dataType, data);
        if (needsStride)
            gl2.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, 0);
    }
    data.position(cpos);

}
 
Example 6
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);
}