All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jme3.renderer.Caps Maven / Gradle / Ivy

There is a newer version: 3.7.0-stable
Show newest version
/*
 * Copyright (c) 2009-2021 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.jme3.renderer;

import com.jme3.shader.Shader;
import com.jme3.shader.Shader.ShaderSource;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.FrameBuffer.RenderBuffer;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import java.util.Collection;

/**
 * Specifies a capability that the {@link Renderer}
 * supports.
 *
 * @author Kirill Vainer
 */
public enum Caps {

    /**
     * Supports {@link FrameBuffer FrameBuffers}.
     *
     * 

OpenGL: Renderer exposes the GL_EXT_framebuffer_object extension.
* OpenGL ES: Renderer supports OpenGL ES 2.0. */ FrameBuffer, /** * Supports framebuffer Multiple Render Targets (MRT). * *

OpenGL: Renderer exposes the GL_ARB_draw_buffers extension */ FrameBufferMRT, /** * Supports framebuffer multi-sampling. * *

OpenGL: Renderer exposes the GL EXT framebuffer multisample extension
* OpenGL ES: Renderer exposes GL_APPLE_framebuffer_multisample or * GL_ANGLE_framebuffer_multisample. */ FrameBufferMultisample, /** * Supports texture multi-sampling. * *

OpenGL: Renderer exposes the GL_ARB_texture_multisample extension
* OpenGL ES: Renderer exposes the GL_IMG_multisampled_render_to_texture * extension. */ TextureMultisample, /** * Supports OpenGL 2.0 or OpenGL ES 2.0. */ OpenGL20, /** * Supports OpenGL 2.1. */ OpenGL21, /** * Supports OpenGL 3.0. */ OpenGL30, /** * Supports OpenGL 3.1. */ OpenGL31, /** * Supports OpenGL 3.2. */ OpenGL32, /** * Supports OpenGL 3.3. */ OpenGL33, /** * Supports OpenGL 4.0. */ OpenGL40, /** * Supports OpenGL 4.1. */ OpenGL41, /** * Supports OpenGL 4.2. */ OpenGL42, /** * Supports OpenGL 4.3. */ OpenGL43, /** * Supports OpenGL 4.4. */ OpenGL44, /** * Supports OpenGL 4.5. */ OpenGL45, /** * Do not use. * * @deprecated do not use. */ @Deprecated Reserved0, /** * Supports GLSL 1.0. */ GLSL100, /** * Supports GLSL 1.1. */ GLSL110, /** * Supports GLSL 1.2. */ GLSL120, /** * Supports GLSL 1.3. */ GLSL130, /** * Supports GLSL 1.4. */ GLSL140, /** * Supports GLSL 1.5. */ GLSL150, /** * Supports GLSL 3.3. */ GLSL330, /** * Supports GLSL 4.0. */ GLSL400, /** * Supports GLSL 4.1. */ GLSL410, /** * Supports GLSL 4.2. */ GLSL420, /** * Supports GLSL 4.3. */ GLSL430, /** * Supports GLSL 4.4. */ GLSL440, /** * Supports GLSL 4.5. */ GLSL450, /** * Supports reading from textures inside the vertex shader. */ VertexTextureFetch, /** * Supports geometry shader. */ GeometryShader, /** * Supports Tessellation shader. */ TesselationShader, /** * Supports texture arrays. */ TextureArray, /** * Supports texture buffers. */ TextureBuffer, /** * Supports floating point and half textures (Format.RGB16F). */ FloatTexture, /** * Supports integer textures. */ IntegerTexture, /** * Supports floating point FBO color buffers (Format.RGB16F). */ FloatColorBuffer, /** * Supports floating point depth buffer. */ FloatDepthBuffer, /** * Supports Format.RGB111110F for textures. */ PackedFloatTexture, /** * Supports Format.RGB9E5 for textures. */ SharedExponentTexture, /** * Supports Format.RGB111110F for FBO color buffers. */ PackedFloatColorBuffer, /** * Supports Format.RGB9E5 for FBO color buffers. */ SharedExponentColorBuffer, /** * Do not use. * * @deprecated do not use. */ @Deprecated Reserved1, /** * Supports Non-Power-Of-Two (NPOT) textures and framebuffers. */ NonPowerOfTwoTextures, /** * Supports geometry instancing. */ MeshInstancing, /** * Supports VAO, or vertex buffer arrays. */ VertexBufferArray, /** * Supports multisampling on the screen. */ Multisample, /** * Supports FBO with Depth24Stencil8 image format. */ PackedDepthStencilBuffer, /** * Supports sRGB framebuffers and sRGB texture format. */ Srgb, /** * Supports blitting framebuffers. */ FrameBufferBlit, /** * Supports {@link Format#DXT1} and sister formats. */ TextureCompressionS3TC, /** * Supports anisotropic texture filtering. */ TextureFilterAnisotropic, /** * Supports {@link Format#ETC1} texture compression. */ TextureCompressionETC1, /** * Supports {@link Format#ETC1} texture compression by uploading * the texture as ETC2 (they are backwards compatible). */ TextureCompressionETC2, /** * Supports BPTC and sister formats. */ TextureCompressionBPTC, /** * Supports {@link Format#RGTC1} and other RGTC compressed formats. */ TextureCompressionRGTC, /** * Supports OpenGL ES 2. */ OpenGLES20, /** * Supports RGB8 / RGBA8 textures. */ Rgba8, /** * Supports depth textures. */ DepthTexture, /** * Supports 32-bit index buffers. */ IntegerIndexBuffer, /** * Partial support for non-power-of-2 textures, typically found * on OpenGL ES 2 devices. * *

Use of NPOT textures is allowed iff: *

    *
  • The {@link com.jme3.texture.Texture.WrapMode} is set to * {@link com.jme3.texture.Texture.WrapMode#EdgeClamp}.
  • *
  • Mip-mapping is not used, meaning * {@link com.jme3.texture.Texture.MinFilter} is set to * {@link com.jme3.texture.Texture.MinFilter#BilinearNoMipMaps} or * {@link com.jme3.texture.Texture.MinFilter#NearestNoMipMaps}
  • *
*/ PartialNonPowerOfTwoTextures, /** * When sampling cubemap edges, interpolates between the adjacent faces * instead of just sampling one face. * *

Improves the quality of environment mapping. */ SeamlessCubemap, /** * Running with OpenGL 3.2+ core profile. * * Compatibility features will not be available. */ CoreProfile, /** * GPU support for binary shaders. */ BinaryShader, /** * Supporting working with UniformBufferObject. */ UniformBufferObject, /** * Supporting working with ShaderStorageBufferObjects. */ ShaderStorageBufferObject, /** * Supports OpenGL ES 3.0. */ OpenGLES30, /** * Supports GLSL 3.0. */ GLSL300, /** * Supports OpenGL ES 3.1. */ OpenGLES31, /** * Supports GLSL 3.1. */ GLSL310, /** * Supports OpenGL ES 3.2. */ OpenGLES32, /** * Supports GLSL 3.2. */ GLSL320, /** * Explicit support of depth 24 textures. */ Depth24, /** * Supports unpack row length (stride). */ UnpackRowLength ; /** * Returns true if given the renderer capabilities, the texture * can be supported by the renderer. * *

This only checks the format of the texture, non-power-of-2 * textures are scaled automatically inside the renderer * if are not supported natively. * * @param caps The collection of renderer capabilities {@link Renderer#getCaps() }. * @param tex The texture to check * @return True if it is supported, false otherwise. */ public static boolean supports(Collection caps, Texture tex) { if (tex.getType() == Texture.Type.TwoDimensionalArray && !caps.contains(Caps.TextureArray)) { return false; } Image img = tex.getImage(); if (img == null) { return true; } Format fmt = img.getFormat(); switch (fmt) { case Depth24Stencil8: return caps.contains(Caps.PackedDepthStencilBuffer); case Depth32F: return caps.contains(Caps.FloatDepthBuffer); case RGB16F_to_RGB111110F: case RGB111110F: return caps.contains(Caps.PackedFloatTexture); case RGB16F_to_RGB9E5: case RGB9E5: return caps.contains(Caps.SharedExponentTexture); default: if (fmt.isFloatingPont()) { return caps.contains(Caps.FloatTexture); } return true; } } private static boolean supportsColorBuffer(Collection caps, RenderBuffer colorBuf) { Format colorFmt = colorBuf.getFormat(); if (colorFmt.isDepthFormat()) { return false; } if (colorFmt.isCompressed()) { return false; } switch (colorFmt) { case RGB111110F: return caps.contains(Caps.PackedFloatColorBuffer); case RGB16F_to_RGB111110F: case RGB16F_to_RGB9E5: case RGB9E5: return false; default: if (colorFmt.isFloatingPont()) { return caps.contains(Caps.FloatColorBuffer); } return true; } } /** * Returns true if given the renderer capabilities, the framebuffer * can be supported by the renderer. * * @param caps The collection of renderer capabilities {@link Renderer#getCaps() }. * @param fb The framebuffer to check * @return True if it is supported, false otherwise. */ public static boolean supports(Collection caps, FrameBuffer fb) { if (!caps.contains(Caps.FrameBuffer)) { return false; } if (fb.getSamples() > 1 && !caps.contains(Caps.FrameBufferMultisample)) { return false; } RenderBuffer depthBuf = fb.getDepthBuffer(); if (depthBuf != null) { Format depthFmt = depthBuf.getFormat(); if (!depthFmt.isDepthFormat()) { return false; } else { if (depthFmt == Format.Depth32F && !caps.contains(Caps.FloatDepthBuffer)) { return false; } if (depthFmt == Format.Depth24Stencil8 && !caps.contains(Caps.PackedDepthStencilBuffer)) { return false; } } } for (int i = 0; i < fb.getNumColorBuffers(); i++) { if (!supportsColorBuffer(caps, fb.getColorBuffer(i))) { return false; } } return true; } /** * Returns true if given the renderer capabilities, the shader * can be supported by the renderer. * * @param caps The collection of renderer capabilities {@link Renderer#getCaps() }. * @param shader The shader to check * @return True if it is supported, false otherwise. */ public static boolean supports(Collection caps, Shader shader) { for (ShaderSource source : shader.getSources()) { if (source.getLanguage().startsWith("GLSL")) { int ver = Integer.parseInt(source.getLanguage().substring(4)); switch (ver) { case 100: if (!caps.contains(Caps.GLSL100)) { return false; } // fall through case 110: if (!caps.contains(Caps.GLSL110)) { return false; } // fall through case 120: if (!caps.contains(Caps.GLSL120)) { return false; } // fall through case 130: if (!caps.contains(Caps.GLSL130)) { return false; } // fall through case 140: if (!caps.contains(Caps.GLSL140)) { return false; } // fall through case 150: if (!caps.contains(Caps.GLSL150)) { return false; } // fall through case 330: if (!caps.contains(Caps.GLSL330)) { return false; } // fall through case 400: if (!caps.contains(Caps.GLSL400)) { return false; } // fall through case 410: if (!caps.contains(Caps.GLSL410)) { return false; } // fall through case 420: if (!caps.contains(Caps.GLSL420)) { return false; } // fall through case 430: if (!caps.contains(Caps.GLSL430)) { return false; } // fall through case 440: if (!caps.contains(Caps.GLSL440)) { return false; } // fall through case 450: if (!caps.contains(Caps.GLSL450)) { return false; } // fall through default: return false; } } } return true; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy