Introduce the unified renderer architecture for the OpenGL renderer

* Similar to the OpenAL URA, OpenGL calls are now made to an interface
   which is implemented by the backends
 * Major cleanups in the texture util code to handle GLES2 texture formats
 * Split the GL interface into several interfaces depending on API and version:
   - GL (common denominator for all GL APIs)
   - GL2 (desktop GL2)
   - GL3 (desktop GL3)
   - GLFbo (framebuffer object functions)
   - GLExt (desktop GL and OpenGL ES extensions)
 * Added GLTracer class which traces OpenGL calls made by the engine when activated
experimental
shadowislord 10 years ago
parent d8b9c6dab5
commit bd318f5d1b
  1. 249
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java
  2. 82
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL2.java
  3. 48
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL3.java
  4. 103
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLExt.java
  5. 81
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLFbo.java
  6. 71
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormat.java
  7. 195
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java
  8. 2667
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  9. 229
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLTracer.java
  10. 364
      jme3-core/src/main/java/com/jme3/renderer/opengl/TextureUtil.java

@ -0,0 +1,249 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
/**
* Baseline GL methods that must be available on all platforms.
*
* This is the subset of vanilla desktop OpenGL 2 and OpenGL ES 2.
*
* @author Kirill Vainer
*/
public interface GL {
public static final int GL_ALPHA = 0x1906;
public static final int GL_ALWAYS = 0x207;
public static final int GL_ARRAY_BUFFER = 0x8892;
public static final int GL_BACK = 0x405;
public static final int GL_BLEND = 0xBE2;
public static final int GL_BYTE = 0x1400;
public static final int GL_CLAMP_TO_EDGE = 0x812F;
public static final int GL_COLOR_BUFFER_BIT = 0x4000;
public static final int GL_COMPILE_STATUS = 0x8B81;
public static final int GL_CULL_FACE = 0xB44;
public static final int GL_DECR = 0x1E03;
public static final int GL_DECR_WRAP = 0x8508;
public static final int GL_DEPTH_BUFFER_BIT = 0x100;
public static final int GL_DEPTH_COMPONENT = 0x1902;
public static final int GL_DEPTH_COMPONENT16 = 0x81A5;
public static final int GL_DEPTH_TEST = 0xB71;
public static final int GL_DOUBLE = 0x140A;
public static final int GL_DST_COLOR = 0x306;
public static final int GL_DYNAMIC_DRAW = 0x88E8;
public static final int GL_ELEMENT_ARRAY_BUFFER = 0x8893;
public static final int GL_EQUAL = 0x202;
public static final int GL_EXTENSIONS = 0x1F03;
public static final int GL_FALSE = 0x0;
public static final int GL_FLOAT = 0x1406;
public static final int GL_FRAGMENT_SHADER = 0x8B30;
public static final int GL_FRONT = 0x404;
public static final int GL_FRONT_AND_BACK = 0x408;
public static final int GL_GEQUAL = 0x206;
public static final int GL_GREATER = 0x204;
public static final int GL_INCR = 0x1E02;
public static final int GL_INCR_WRAP = 0x8507;
public static final int GL_INFO_LOG_LENGTH = 0x8B84;
public static final int GL_INT = 0x1404;
public static final int GL_INVERT = 0x150A;
public static final int GL_KEEP = 0x1E00;
public static final int GL_LEQUAL = 0x203;
public static final int GL_LESS = 0x201;
public static final int GL_LINEAR = 0x2601;
public static final int GL_LINEAR_MIPMAP_LINEAR = 0x2703;
public static final int GL_LINEAR_MIPMAP_NEAREST = 0x2701;
public static final int GL_LINES = 0x1;
public static final int GL_LINE_LOOP = 0x2;
public static final int GL_LINE_STRIP = 0x3;
public static final int GL_LINK_STATUS = 0x8B82;
public static final int GL_LUMINANCE = 0x1909;
public static final int GL_LUMINANCE_ALPHA = 0x190A;
public static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C;
public static final int GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872;
public static final int GL_MAX_TEXTURE_SIZE = 0xD33;
public static final int GL_MAX_VERTEX_ATTRIBS = 0x8869;
public static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C;
public static final int GL_MIRRORED_REPEAT = 0x8370;
public static final int GL_NEAREST = 0x2600;
public static final int GL_NEAREST_MIPMAP_LINEAR = 0x2702;
public static final int GL_NEAREST_MIPMAP_NEAREST = 0x2700;
public static final int GL_NEVER = 0x200;
public static final int GL_NONE = 0x0;
public static final int GL_NOTEQUAL = 0x205;
public static final int GL_ONE = 0x1;
public static final int GL_ONE_MINUS_DST_COLOR = 0x307;
public static final int GL_ONE_MINUS_SRC_ALPHA = 0x303;
public static final int GL_ONE_MINUS_SRC_COLOR = 0x301;
public static final int GL_POINTS = 0x0;
public static final int GL_POLYGON_OFFSET_FILL = 0x8037;
public static final int GL_REPEAT = 0x2901;
public static final int GL_REPLACE = 0x1E01;
public static final int GL_RGB = 0x1907;
public static final int GL_RGB565 = 0x8D62;
public static final int GL_RGB5_A1 = 0x8057;
public static final int GL_RGBA = 0x1908;
public static final int GL_RGBA4 = 0x8056;
public static final int GL_SCISSOR_TEST = 0xC11;
public static final int GL_SHADING_LANGUAGE_VERSION = 0x8B8C;
public static final int GL_SHORT = 0x1402;
public static final int GL_SRC_ALPHA = 0x302;
public static final int GL_SRC_COLOR = 0x300;
public static final int GL_STATIC_DRAW = 0x88E4;
public static final int GL_STENCIL_BUFFER_BIT = 0x400;
public static final int GL_STENCIL_TEST = 0xB90;
public static final int GL_STREAM_DRAW = 0x88E0;
public static final int GL_TEXTURE = 0x1702;
public static final int GL_TEXTURE0 = 0x84C0;
public static final int GL_TEXTURE1 = 0x84C1;
public static final int GL_TEXTURE2 = 0x84C2;
public static final int GL_TEXTURE3 = 0x84C3;
public static final int GL_TEXTURE4 = 0x84C4;
public static final int GL_TEXTURE5 = 0x84C5;
public static final int GL_TEXTURE6 = 0x84C6;
public static final int GL_TEXTURE7 = 0x84C7;
public static final int GL_TEXTURE8 = 0x84C8;
public static final int GL_TEXTURE9 = 0x84C9;
public static final int GL_TEXTURE10 = 0x84CA;
public static final int GL_TEXTURE11 = 0x84CB;
public static final int GL_TEXTURE12 = 0x84CC;
public static final int GL_TEXTURE13 = 0x84CD;
public static final int GL_TEXTURE14 = 0x84CE;
public static final int GL_TEXTURE15 = 0x84CF;
public static final int GL_TEXTURE_2D = 0xDE1;
public static final int GL_TEXTURE_CUBE_MAP = 0x8513;
public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
public static final int GL_TEXTURE_MAG_FILTER = 0x2800;
public static final int GL_TEXTURE_MAX_LEVEL = 0x813D;
public static final int GL_TEXTURE_MIN_FILTER = 0x2801;
public static final int GL_TEXTURE_WRAP_S = 0x2802;
public static final int GL_TEXTURE_WRAP_T = 0x2803;
public static final int GL_TRIANGLES = 0x4;
public static final int GL_TRIANGLE_FAN = 0x6;
public static final int GL_TRIANGLE_STRIP = 0x5;
public static final int GL_TRUE = 0x1;
public static final int GL_UNPACK_ALIGNMENT = 0xCF5;
public static final int GL_UNSIGNED_BYTE = 0x1401;
public static final int GL_UNSIGNED_INT = 0x1405;
public static final int GL_UNSIGNED_SHORT = 0x1403;
public static final int GL_UNSIGNED_SHORT_5_6_5 = 0x8363;
public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034;
public static final int GL_VERSION = 0x1F02;
public static final int GL_VERTEX_SHADER = 0x8B31;
public static final int GL_ZERO = 0x0;
public void glActiveTexture(int texture);
public void glAttachShader(int program, int shader);
public void glBindBuffer(int target, int buffer);
public void glBindTexture(int target, int texture);
public void glBlendFunc(int sfactor, int dfactor);
public void glBufferData(int target, FloatBuffer data, int usage);
public void glBufferData(int target, DoubleBuffer data, int usage);
public void glBufferData(int target, ShortBuffer data, int usage);
public void glBufferData(int target, ByteBuffer data, int usage);
public void glBufferSubData(int target, long offset, FloatBuffer data);
public void glBufferSubData(int target, long offset, ShortBuffer data);
public void glBufferSubData(int target, long offset, DoubleBuffer data);
public void glBufferSubData(int target, long offset, ByteBuffer data);
public void glClear(int mask);
public void glClearColor(float red, float green, float blue, float alpha);
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha);
public void glCompileShader(int shader);
public void glCompressedTexImage2D(int target, int level, int internalformat, int width, int height, int border, ByteBuffer data);
public void glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, ByteBuffer data);
public int glCreateProgram();
public int glCreateShader(int shaderType);
public void glCullFace(int mode);
public void glDeleteBuffers(IntBuffer buffers);
public void glDeleteProgram(int program);
public void glDeleteShader(int shader);
public void glDeleteTextures(IntBuffer textures);
public void glDepthFunc(int func);
public void glDepthMask(boolean flag);
public void glDepthRange(double nearVal, double farVal);
public void glDetachShader(int program, int shader);
public void glDisable(int cap);
public void glDisableVertexAttribArray(int index);
public void glDrawArrays(int mode, int first, int count);
public void glDrawRangeElements(int mode, int start, int end, int count, int type, long indices); /// GL2+
public void glEnable(int cap);
public void glEnableVertexAttribArray(int index);
public void glGenBuffers(IntBuffer buffers);
public void glGenTextures(IntBuffer textures);
public int glGetAttribLocation(int program, String name);
public void glGetBoolean(int pname, ByteBuffer params);
public int glGetError();
public void glGetInteger(int pname, IntBuffer params);
public void glGetProgram(int program, int pname, IntBuffer params);
public void glGetProgramInfoLog(int program, IntBuffer length, ByteBuffer infoLog);
public void glGetShader(int shader, int pname, IntBuffer params);
public void glGetShaderInfoLog(int shader, IntBuffer length, ByteBuffer infoLog);
public String glGetString(int name);
public int glGetUniformLocation(int program, String name);
public boolean glIsEnabled(int cap);
public void glLineWidth(float width);
public void glLinkProgram(int program);
public void glPixelStorei(int pname, int param);
public void glPolygonOffset(float factor, float units);
public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer data);
public void glScissor(int x, int y, int width, int height);
public void glShaderSource(int shader, String[] string, IntBuffer length);
public void glStencilFuncSeparate(int face, int func, int ref, int mask);
public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass);
public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data);
public void glTexParameterf(int target, int pname, float param);
public void glTexParameteri(int target, int pname, int param);
public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, ByteBuffer data);
public void glUniform1(int location, FloatBuffer value);
public void glUniform1(int location, IntBuffer value);
public void glUniform1f(int location, float v0);
public void glUniform1i(int location, int v0);
public void glUniform2(int location, IntBuffer value);
public void glUniform2(int location, FloatBuffer value);
public void glUniform2f(int location, float v0, float v1);
public void glUniform3(int location, IntBuffer value);
public void glUniform3(int location, FloatBuffer value);
public void glUniform3f(int location, float v0, float v1, float v2);
public void glUniform4(int location, FloatBuffer value);
public void glUniform4(int location, IntBuffer value);
public void glUniform4f(int location, float v0, float v1, float v2, float v3);
public void glUniformMatrix3(int location, boolean transpose, FloatBuffer value);
public void glUniformMatrix4(int location, boolean transpose, FloatBuffer value);
public void glUseProgram(int program);
public void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long pointer);
public void glViewport(int x, int y, int width, int height);
}

@ -0,0 +1,82 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import java.nio.ByteBuffer;
/**
* GL functions only available on vanilla desktop OpenGL 2.
*
* @author Kirill Vainer
*/
public interface GL2 extends GL {
public static final int GL_ALPHA8 = 0x803C;
public static final int GL_ALPHA_TEST = 0xBC0;
public static final int GL_BGR = 0x80E0;
public static final int GL_BGRA = 0x80E1;
public static final int GL_COMPARE_R_TO_TEXTURE = 0x884E;
public static final int GL_DEPTH_COMPONENT24 = 0x81A6;
public static final int GL_DEPTH_COMPONENT32 = 0x81A7;
public static final int GL_DEPTH_TEXTURE_MODE = 0x884B;
public static final int GL_DOUBLEBUFFER = 0xC32;
public static final int GL_DRAW_BUFFER = 0xC01;
public static final int GL_FILL = 0x1B02;
public static final int GL_GENERATE_MIPMAP = 0x8191;
public static final int GL_INTENSITY = 0x8049;
public static final int GL_LINE = 0x1B01;
public static final int GL_LUMINANCE8 = 0x8040;
public static final int GL_LUMINANCE8_ALPHA8 = 0x8045;
public static final int GL_MAX_ELEMENTS_INDICES = 0x80E9;
public static final int GL_MAX_ELEMENTS_VERTICES = 0x80E8;
public static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49;
public static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A;
public static final int GL_READ_BUFFER = 0xC02;
public static final int GL_RGB8 = 0x8051;
public static final int GL_TEXTURE_3D = 0x806F;
public static final int GL_POINT_SPRITE = 0x8861;
public static final int GL_TEXTURE_COMPARE_FUNC = 0x884D;
public static final int GL_TEXTURE_COMPARE_MODE = 0x884C;
public static final int GL_TEXTURE_WRAP_R = 0x8072;
public static final int GL_VERTEX_PROGRAM_POINT_SIZE = 0x8642;
public static final int GL_UNSIGNED_INT_8_8_8_8 = 0x8035;
public void glAlphaFunc(int func, float ref);
public void glPointSize(float size);
public void glPolygonMode(int face, int mode);
public void glDrawBuffer(int mode);
public void glReadBuffer(int mode);
public void glCompressedTexImage3D(int target, int level, int internalformat, int width, int height, int depth, int border, ByteBuffer data);
public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, ByteBuffer data);
public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, int format, int type, ByteBuffer data);
public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, ByteBuffer data);
}

@ -0,0 +1,48 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import java.nio.IntBuffer;
/**
* GL functions only available on vanilla desktop OpenGL 3.0.
*
* @author Kirill Vainer
*/
public interface GL3 extends GL2 {
public static final int GL_DEPTH_STENCIL_ATTACHMENT = 0x821A;
public void glBindFragDataLocation(int param1, int param2, String param3); /// GL3+
public void glBindVertexArray(int param1); /// GL3+
public void glGenVertexArrays(IntBuffer param1); /// GL3+
}

@ -0,0 +1,103 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
/**
* GL functions provided by extensions.
*
* Always must check against a renderer capability prior to using those.
*
* @author Kirill Vainer
*/
public interface GLExt extends GLFbo {
public static final int GL_ETC1_RGB8_OES = 0x8D64;
public static final int GL_COMPRESSED_RGB8_ETC2 = 0x9274;
public static final int GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
public static final int GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
public static final int GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
public static final int GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
public static final int GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D;
public static final int GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E;
public static final int GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
public static final int GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
public static final int GL_DEPTH_COMPONENT32F = 0x8CAC;
public static final int GL_DEPTH24_STENCIL8_EXT = 0x88F0;
public static final int GL_DEPTH_STENCIL_EXT = 0x84F9;
public static final int GL_FRAMEBUFFER_SRGB_CAPABLE_EXT = 0x8DBA;
public static final int GL_FRAMEBUFFER_SRGB_EXT = 0x8DB9;
public static final int GL_HALF_FLOAT_ARB = 0x140B;
public static final int GL_LUMINANCE16F_ARB = 0x881E;
public static final int GL_LUMINANCE32F_ARB = 0x8818;
public static final int GL_LUMINANCE_ALPHA16F_ARB = 0x881F;
public static final int GL_MAX_COLOR_TEXTURE_SAMPLES = 0x910E;
public static final int GL_MAX_DEPTH_TEXTURE_SAMPLES = 0x910F;
public static final int GL_MAX_DRAW_BUFFERS_ARB = 0x8824;
public static final int GL_MAX_SAMPLES_EXT = 0x8D57;
public static final int GL_MULTISAMPLE_ARB = 0x809D;
public static final int GL_R11F_G11F_B10F_EXT = 0x8C3A;
public static final int GL_RGBA8 = 0x8058;
public static final int GL_RGB16F_ARB = 0x881B;
public static final int GL_RGB32F_ARB = 0x8815;
public static final int GL_RGB9_E5_EXT = 0x8C3D;
public static final int GL_RGBA16F_ARB = 0x881A;
public static final int GL_RGBA32F_ARB = 0x8814;
public static final int GL_SAMPLES_ARB = 0x80A9;
public static final int GL_SAMPLE_ALPHA_TO_COVERAGE_ARB = 0x809E;
public static final int GL_SAMPLE_BUFFERS_ARB = 0x80A8;
public static final int GL_SAMPLE_POSITION = 0x8E50;
public static final int GL_SLUMINANCE8_ALPHA8_EXT = 0x8C45;
public static final int GL_SLUMINANCE8_EXT = 0x8C47;
public static final int GL_SRGB8_ALPHA8_EXT = 0x8C43;
public static final int GL_SRGB8_EXT = 0x8C41;
public static final int GL_TEXTURE_2D_ARRAY_EXT = 0x8C1A;
public static final int GL_TEXTURE_2D_MULTISAMPLE = 0x9100;
public static final int GL_TEXTURE_2D_MULTISAMPLE_ARRAY = 0x9102;
public static final int GL_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
public static final int GL_UNSIGNED_INT_10F_11F_11F_REV_EXT = 0x8C3B;
public static final int GL_UNSIGNED_INT_24_8_EXT = 0x84FA;
public static final int GL_UNSIGNED_INT_5_9_9_9_REV_EXT = 0x8C3E;
public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
public void glBufferData(int target, IntBuffer data, int usage);
public void glBufferSubData(int target, long offset, IntBuffer data);
public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount);
public void glDrawBuffers(IntBuffer bufs);
public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount);
public void glGetMultisample(int pname, int index, FloatBuffer val);
public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height);
public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations);
public void glVertexAttribDivisorARB(int index, int divisor);
}

@ -0,0 +1,81 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import java.nio.IntBuffer;
/**
* Framebuffer object functions.
*
* Available by default in OpenGL ES 2, but on desktop GL 2
* an extension is required.
*
* @author Kirill Vainer
*/
public interface GLFbo {
public static final int GL_COLOR_ATTACHMENT0_EXT = 0x8CE0;
public static final int GL_COLOR_ATTACHMENT15_EXT = 0x8CEF;
public static final int GL_DEPTH_ATTACHMENT_EXT = 0x8D00;
public static final int GL_DRAW_FRAMEBUFFER_BINDING_EXT = 0x8CA6;
public static final int GL_DRAW_FRAMEBUFFER_EXT = 0x8CA9;
public static final int GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT = 0x8CD1;
public static final int GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT = 0x8CD0;
public static final int GL_FRAMEBUFFER_COMPLETE_EXT = 0x8CD5;
public static final int GL_FRAMEBUFFER_EXT = 0x8D40;
public static final int GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT = 0x8CD6;
public static final int GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT = 0x8CD9;
public static final int GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT = 0x8CDB;
public static final int GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT = 0x8CDA;
public static final int GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT = 0x8CD7;
public static final int GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT = 0x8D56;
public static final int GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT = 0x8CDC;
public static final int GL_FRAMEBUFFER_UNSUPPORTED_EXT = 0x8CDD;
public static final int GL_MAX_COLOR_ATTACHMENTS_EXT = 0x8CDF;
public static final int GL_MAX_RENDERBUFFER_SIZE_EXT = 0x84E8;
public static final int GL_READ_FRAMEBUFFER_BINDING_EXT = 0x8CAA;
public static final int GL_READ_FRAMEBUFFER_EXT = 0x8CA8;
public static final int GL_RENDERBUFFER_EXT = 0x8D41;
public void glBindFramebufferEXT(int param1, int param2);
public void glBindRenderbufferEXT(int param1, int param2);
public int glCheckFramebufferStatusEXT(int param1);
public void glDeleteFramebuffersEXT(IntBuffer param1);
public void glDeleteRenderbuffersEXT(IntBuffer param1);
public void glFramebufferRenderbufferEXT(int param1, int param2, int param3, int param4);
public void glFramebufferTexture2DEXT(int param1, int param2, int param3, int param4, int param5);
public void glGenFramebuffersEXT(IntBuffer param1);
public void glGenRenderbuffersEXT(IntBuffer param1);
public void glGenerateMipmapEXT(int param1);
public void glRenderbufferStorageEXT(int param1, int param2, int param3, int param4);
}

@ -0,0 +1,71 @@
/*
* Copyright (c) 2009-2014 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.opengl;
/**
* Describes an OpenGL image format.
*
* @author Kirill Vainer
*/
public final class GLImageFormat {
public final int internalFormat;
public final int format;
public final int dataType;
public final boolean compressed;
/**
* Constructor for uncompressed formats.
*
* @param internalFormat OpenGL internal format
* @param format OpenGL format
* @param dataType OpenGL datatype
*/
public GLImageFormat(int internalFormat, int format, int dataType) {
this.internalFormat = internalFormat;
this.format = format;
this.dataType = dataType;
this.compressed = false;
}
/**
* Constructor for compressed formats.
*
* @param compressedFormat OpenGL compressed internal format
*/
public GLImageFormat(int compressedFormat) {
this.internalFormat = compressedFormat;
this.format = -1;
this.dataType = -1;
this.compressed = true;
}
}

@ -0,0 +1,195 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import com.jme3.renderer.Caps;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import java.util.EnumSet;
/**
* Generates a table of supported image formats for a given renderer caps.
*
* @author Kirill Vainer
*/
public final class GLImageFormats {
private GLImageFormats() { }
private static void format(GLImageFormat[][] formatToGL, Image.Format format,
int glInternalFormat,
int glFormat,
int glDataType){
formatToGL[0][format.ordinal()] = new GLImageFormat(glInternalFormat, glFormat, glDataType);
}
private static void formatSrgb(GLImageFormat[][] formatToGL, Image.Format format,
int glInternalFormat,
int glFormat,
int glDataType)
{
formatToGL[1][format.ordinal()] = new GLImageFormat(glInternalFormat, glFormat, glDataType);
}
private static void formatComp(GLImageFormat[][] formatToGL, Image.Format format,
int glCompressedFormat){
formatToGL[0][format.ordinal()] = new GLImageFormat(glCompressedFormat);
}
private static void formatCompSrgb(GLImageFormat[][] formatToGL, Image.Format format,
int glCompressedFormat)
{
formatToGL[1][format.ordinal()] = new GLImageFormat(glCompressedFormat);
}
/**
* Generates a list of supported texture formats.
*
* The first dimension of the array specifies the colorspace,
* currently 0 means linear and 1 means sRGB. The second dimension
* is the ordinal in the {@link Format image format}.
*
* @param caps The capabilities for which to determine supported formats.
* @return An 2D array containing supported texture formats.
*/
public static GLImageFormat[][] getFormatsForCaps(EnumSet<Caps> caps) {
GLImageFormat[][] formatToGL = new GLImageFormat[2][Image.Format.values().length];
if (caps.contains(Caps.OpenGL20)) {
format(formatToGL, Format.Alpha8, GL2.GL_ALPHA8, GL.GL_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8, GL2.GL_LUMINANCE8, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8Alpha8, GL2.GL_LUMINANCE8_ALPHA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGB8, GL2.GL_RGB8, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGBA8, GLExt.GL_RGBA8, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGB565, GL2.GL_RGB8, GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
// Additional desktop-specific formats:
format(formatToGL, Format.BGR8, GL2.GL_RGB8, GL2.GL_BGR, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.ARGB8, GLExt.GL_RGBA8, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8);
format(formatToGL, Format.BGRA8, GLExt.GL_RGBA8, GL2.GL_BGRA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.ABGR8, GLExt.GL_RGBA8, GL.GL_RGBA, GL2.GL_UNSIGNED_INT_8_8_8_8);
// sRGB formats
if (caps.contains(Caps.Srgb)) {
formatSrgb(formatToGL, Format.RGB8, GLExt.GL_SRGB8_EXT, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.RGB565, GLExt.GL_SRGB8_EXT, GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
formatSrgb(formatToGL, Format.RGB5A1, GLExt.GL_SRGB8_ALPHA8_EXT, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1);
formatSrgb(formatToGL, Format.RGBA8, GLExt.GL_SRGB8_ALPHA8_EXT, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.Luminance8, GLExt.GL_SLUMINANCE8_EXT, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.Luminance8Alpha8, GLExt.GL_SLUMINANCE8_ALPHA8_EXT, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.BGR8, GLExt.GL_SRGB8_EXT, GL2.GL_BGR, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.ABGR8, GLExt.GL_SRGB8_ALPHA8_EXT, GL.GL_RGBA, GL2.GL_UNSIGNED_INT_8_8_8_8);
formatSrgb(formatToGL, Format.ARGB8, GLExt.GL_SRGB8_ALPHA8_EXT, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8);
formatSrgb(formatToGL, Format.BGRA8, GLExt.GL_SRGB8_ALPHA8_EXT, GL2.GL_BGRA, GL.GL_UNSIGNED_BYTE);
if (caps.contains(Caps.TextureCompressionS3TC)) {
formatCompSrgb(formatToGL, Format.DXT1, GLExt.GL_COMPRESSED_SRGB_S3TC_DXT1_EXT);
formatCompSrgb(formatToGL, Format.DXT1A, GLExt.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT);
formatCompSrgb(formatToGL, Format.DXT3, GLExt.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT);
formatCompSrgb(formatToGL, Format.DXT5, GLExt.GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT);
}
}
} else if (caps.contains(Caps.Rgba8)) {
// A more limited form of 32-bit RGBA. Only GL_RGBA8 is available.
format(formatToGL, Format.Alpha8, GLExt.GL_RGBA8, GL.GL_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8, GLExt.GL_RGBA8, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8Alpha8, GLExt.GL_RGBA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGB8, GLExt.GL_RGBA8, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGBA8, GLExt.GL_RGBA8, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
} else {
format(formatToGL, Format.Alpha8, GL.GL_RGBA4, GL.GL_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8, GL.GL_RGB565, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8Alpha8, GL.GL_RGBA4, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGB8, GL.GL_RGB565, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGBA8, GL.GL_RGBA4, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
}
if (caps.contains(Caps.OpenGLES20)) {
format(formatToGL, Format.RGB565, GL.GL_RGB565, GL.GL_RGB, GL.GL_UNSIGNED_SHORT_5_6_5);
}
format(formatToGL, Format.RGB5A1, GL.GL_RGB5_A1, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1);
if (caps.contains(Caps.FloatTexture)) {
format(formatToGL, Format.Luminance16F, GLExt.GL_LUMINANCE16F_ARB, GL.GL_LUMINANCE, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.Luminance32F, GLExt.GL_LUMINANCE32F_ARB, GL.GL_LUMINANCE, GL.GL_FLOAT);
format(formatToGL, Format.Luminance16FAlpha16F, GLExt.GL_LUMINANCE_ALPHA16F_ARB, GL.GL_LUMINANCE_ALPHA, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.RGB16F, GLExt.GL_RGB16F_ARB, GL.GL_RGB, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.RGB32F, GLExt.GL_RGB32F_ARB, GL.GL_RGB, GL.GL_FLOAT);
format(formatToGL, Format.RGBA16F, GLExt.GL_RGBA16F_ARB, GL.GL_RGBA, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.RGBA32F, GLExt.GL_RGBA32F_ARB, GL.GL_RGBA, GL.GL_FLOAT);
}
if (caps.contains(Caps.PackedFloatTexture)) {
format(formatToGL, Format.RGB111110F, GLExt.GL_R11F_G11F_B10F_EXT, GL.GL_RGB, GLExt.GL_UNSIGNED_INT_10F_11F_11F_REV_EXT);
if (caps.contains(Caps.FloatTexture)) {
format(formatToGL, Format.RGB16F_to_RGB111110F, GLExt.GL_R11F_G11F_B10F_EXT, GL.GL_RGB, GLExt.GL_HALF_FLOAT_ARB);
}
}
if (caps.contains(Caps.SharedExponentTexture)) {
format(formatToGL, Format.RGB9E5, GLExt.GL_RGB9_E5_EXT, GL.GL_RGB, GLExt.GL_UNSIGNED_INT_5_9_9_9_REV_EXT);
if (caps.contains(Caps.FloatTexture)) {
format(formatToGL, Format.RGB16F_to_RGB9E5, GLExt.GL_RGB9_E5_EXT, GL.GL_RGB, GLExt.GL_HALF_FLOAT_ARB);
}
}
// Need to check if Caps.DepthTexture is supported prior to using for textures
// But for renderbuffers its OK.
format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Depth16, GL.GL_DEPTH_COMPONENT16, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_SHORT);
if (caps.contains(Caps.OpenGL20)) {
format(formatToGL, Format.Depth24, GL2.GL_DEPTH_COMPONENT24, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_INT);
}
if (caps.contains(Caps.FloatDepthBuffer)) {
format(formatToGL, Format.Depth32F, GLExt.GL_DEPTH_COMPONENT32F, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT);
}
if (caps.contains(Caps.PackedDepthStencilBuffer)) {
format(formatToGL, Format.Depth24Stencil8, GLExt.GL_DEPTH24_STENCIL8_EXT, GLExt.GL_DEPTH_STENCIL_EXT, GLExt.GL_UNSIGNED_INT_24_8_EXT);
}
// Compressed formats
if (caps.contains(Caps.TextureCompressionS3TC)) {
formatComp(formatToGL, Format.DXT1, GLExt.GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
formatComp(formatToGL, Format.DXT1A, GLExt.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
formatComp(formatToGL, Format.DXT3, GLExt.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
formatComp(formatToGL, Format.DXT5, GLExt.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
}
if (caps.contains(Caps.TextureCompressionETC2)) {
formatComp(formatToGL, Format.ETC1, GLExt.GL_COMPRESSED_RGB8_ETC2);
} else if (caps.contains(Caps.TextureCompressionETC1)) {
formatComp(formatToGL, Format.ETC1, GLExt.GL_ETC1_RGB8_OES);
}
return formatToGL;
}
}

@ -0,0 +1,229 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import com.jme3.util.IntMap;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;
/**
* Utility class that allows tracing of OpenGL calls generated by the engine.
*
* @author Kirill Vainer
*/
public final class GLTracer implements InvocationHandler {
private final GL gl;
private final Object obj;
private final IntMap<String> constMap;
private static final HashMap<String, IntMap<Void>> nonEnumArgMap = new HashMap<String, IntMap<Void>>();
private static void noEnumArgs(String method, int... argSlots) {
IntMap<Void> argSlotsMap = new IntMap<Void>();
for (int argSlot : argSlots) {
argSlotsMap.put(argSlot, (Void) null);
}
nonEnumArgMap.put(method, argSlotsMap);
}
static {
noEnumArgs("glViewport", 0, 1, 2, 3);
noEnumArgs("glScissor", 0, 1, 2, 3);
noEnumArgs("glClear", 0);
noEnumArgs("glGetInteger", 1);
noEnumArgs("glBindTexture", 1);
noEnumArgs("glPixelStorei", 1);
// noEnumArgs("glTexParameteri", 2);
noEnumArgs("glTexImage2D", 1, 3, 4, 5);
noEnumArgs("glDeleteTextures", 0);
noEnumArgs("glBindBuffer", 1);
noEnumArgs("glEnableVertexAttribArray", 0);
noEnumArgs("glDisableVertexAttribArray", 0);
noEnumArgs("glVertexAttribPointer", 0, 1, 4, 5);
noEnumArgs("glDrawRangeElements", 1, 2, 3, 5);
noEnumArgs("glDrawArrays", 1, 2);
noEnumArgs("glDeleteBuffers", 0);
noEnumArgs("glBindFramebufferEXT", 1);
noEnumArgs("glBindRenderbufferEXT", 1);
noEnumArgs("glRenderbufferStorageEXT", 2, 3);
noEnumArgs("glFramebufferRenderbufferEXT", 3);
noEnumArgs("glFramebufferTexture2DEXT", 3, 4);
noEnumArgs("glCreateProgram", -1);
noEnumArgs("glCreateShader", -1);
noEnumArgs("glShaderSource", 0);
noEnumArgs("glCompileShader", 0);
noEnumArgs("glGetShader", 0);
noEnumArgs("glAttachShader", 0, 1);
noEnumArgs("glLinkProgram", 0);
noEnumArgs("glGetProgram", 0);
noEnumArgs("glUseProgram", 0);
noEnumArgs("glGetUniformLocation", 0, -1);
noEnumArgs("glUniformMatrix3", 0);
noEnumArgs("glUniformMatrix4", 0);
noEnumArgs("glUniform1i", 0, 1);
noEnumArgs("glUniform1f", 0);
noEnumArgs("glUniform4f", 0);
noEnumArgs("glGetAttribLocation", 0, -1);
noEnumArgs("glDetachShader", 0, 1);
noEnumArgs("glDeleteShader", 0);
noEnumArgs("glDeleteProgram", 0);
}
public GLTracer(GL gl, Object obj, IntMap<String> constMap) {
this.gl = gl;
this.obj = obj;
this.constMap = constMap;
}
public static IntMap<String> generateConstantMap(Class<?> ... classes) {
IntMap<String> constMap = new IntMap<String>();
for (Class<?> clazz : classes) {
for (Field field : clazz.getFields()) {
if (field.getType() == int.class) {
try {
int val = field.getInt(null);
String name = field.getName();
constMap.put(val, name);
} catch (IllegalArgumentException ex) {
} catch (IllegalAccessException ex) {
}
}
}
}
return constMap;
}
private String translateInteger(String method, int value, int argIndex) {
IntMap<Void> argSlotMap = nonEnumArgMap.get(method);
if (argSlotMap != null && argSlotMap.containsKey(argIndex)) {
return Integer.toString(value);
}
String enumName = constMap.get(value);
if (enumName != null) {
return enumName;
} else {
return "GL_ENUM_" + Integer.toHexString(value);
//throw new IllegalStateException("Untranslatable enum encountered on " + method +
// " at argument " + argIndex + " with value " + value);
}
}
private String translateString(String value) {
return "\"" + value.replaceAll("\0", "\\\\0") + "\"";
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(obj, args);
String methodName = method.getName();
if (methodName.startsWith("gl")) {
System.out.print(methodName);
System.out.print("(");
if (args != null) {
Class<?>[] paramTypes = method.getParameterTypes();
for (int i = 0; i < args.length; i++) {
if (paramTypes[i] == int.class) {
int val = (Integer)args[i];
System.out.print(translateInteger(methodName, val, i));
} else if (paramTypes[i] == String.class) {
System.out.print(translateString((String)args[i]));
} else if (paramTypes[i] == String[].class) {
String[] arr = (String[]) args[i];
if (arr.length == 1) {
if (arr[0].length() > 150) {
System.out.print("\"" + arr[0].substring(0, 150) + "...\"");
} else {
System.out.print("\"" + arr[0] + "\"");
}
} else {
System.out.print("String[" + arr.length + "]");
}
} else if (args[i] instanceof IntBuffer) {
IntBuffer buf = (IntBuffer) args[i];
if (buf.capacity() == 16) {
int val = buf.get(0);
System.out.print("out=" + translateInteger(methodName, val, i));
} else if (buf.capacity() == 1) {
System.out.print("out=" + buf.get(0));
} else {
System.out.print(args[i]);
}
} else if (args[i] instanceof ByteBuffer) {
ByteBuffer bb = (ByteBuffer)args[i];
if (bb.capacity() == 250) {
if (bb.get(0) != 0) {
System.out.print("out=GL_TRUE");
} else {
System.out.print("out=GL_FALSE");
}
} else {
System.out.print(args[i]);
}
} else {
System.out.print(args[i]);
}
if (i != args.length - 1) {
System.out.print(", ");
}
}
}
System.out.print(")");
if (method.getReturnType() != void.class) {
if (result instanceof String) {
System.out.println(" = " + translateString((String)result));
} else if (method.getReturnType() == int.class) {
int val = (Integer)result;
System.out.println(" = " + translateInteger(methodName, val, -1));
} else if (method.getReturnType() == boolean.class) {
boolean val = (Boolean)result;
if (val) System.out.println(" = GL_TRUE");
else System.out.println(" = GL_FALSE");
} else {
System.out.println(" = ???");
}
} else {
System.out.println();
}
}
return result;
}
}

@ -0,0 +1,364 @@
/*
* Copyright (c) 2009-2014 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.opengl;
import com.jme3.renderer.Caps;
import com.jme3.renderer.RendererException;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ColorSpace;
import java.nio.ByteBuffer;
import java.util.EnumSet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Internal utility class used by {@link GLRenderer} to manage textures.
*
* @author Kirill Vainer
*/
final class TextureUtil {
private static final Logger logger = Logger.getLogger(TextureUtil.class.getName());
private final GL gl;
private final GL2 gl2;
private final GLExt glext;
private GLImageFormat[][] formats;
public TextureUtil(GL gl, GL2 gl2, GLExt glext) {
this.gl = gl;
this.gl2 = gl2;
this.glext = glext;
}
public void initialize(EnumSet<Caps> caps) {
StringBuilder sb = new StringBuilder();
this.formats = GLImageFormats.getFormatsForCaps(caps);
sb.append("Supported texture formats: \n");
for (int i = 0; i < Format.values().length; i++) {
Format format = Format.values()[i];
if (formats[0][i] != null) {
boolean srgb = formats[1][i] != null;
sb.append("\t").append(format.toString());
sb.append(" (Linear");
if (srgb) sb.append("/sRGB");
sb.append(")\n");
}
}
logger.log(Level.INFO, sb.toString());
}
public GLImageFormat getImageFormat(Format fmt, boolean isSrgb) {
if (isSrgb) {
return formats[1][fmt.ordinal()];
} else {
return formats[0][fmt.ordinal()];
}
}
public GLImageFormat getImageFormatWithError(Format fmt, boolean isSrgb) {
GLImageFormat glFmt = getImageFormat(fmt, isSrgb);
if (glFmt == null && isSrgb) {
glFmt = getImageFormat(fmt, false);
logger.log(Level.WARNING, "No sRGB format available for ''{0}''. Failling back to linear.", fmt);
}
if (glFmt == null) {
throw new RendererException("Image format '" + fmt + "' is unsupported by the video hardware.");
}
return glFmt;
}
private void uploadTextureLevel(GLImageFormat format, int target, int level, int slice, int sliceCount, int width, int height, int depth, int samples, ByteBuffer data) {
if (format.compressed && data != null) {
if (target == GL2.GL_TEXTURE_3D) {
// For 3D textures, we upload the entire mipmap level.
gl2.glCompressedTexImage3D(target,
level,
format.internalFormat,
width,
height,
depth,
0,
data);
} else if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT) {
// For texture arrays, only upload 1 slice at a time.
// zoffset specifies slice index, and depth is 1 to indicate
// a single texture in the array.
gl2.glCompressedTexSubImage3D(target,
level,
0,
0,
slice,
width,
height,
1,
format.internalFormat,
data);
} else {
// Cubemaps also use 2D upload.
gl2.glCompressedTexImage2D(target,
level,
format.internalFormat,
width,
height,
0,
data);
}
} else {
// (Non-compressed OR allocating texture storage for FBO)
if (target == GL2.GL_TEXTURE_3D) {
gl2.glTexImage3D(target,
level,
format.internalFormat,
width,
height,
depth,
0,
format.format,
format.dataType,
data);
} else if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT) {
if (slice == -1) {
// Allocate texture storage (data is NULL)
gl2.glTexImage3D(target,
level,
format.internalFormat,
width,
height,
sliceCount, //# of slices
0,
format.format,
format.dataType,
data);
} else {
// For texture arrays, only upload 1 slice at a time.
// zoffset specifies slice index, and depth is 1 to indicate
// a single texture in the array.
gl2.glTexSubImage3D(target,
level, // level
0, // xoffset
0, // yoffset
slice, // zoffset
width, // width
height, // height
1, // depth
format.format,
format.dataType,
data);
}
} else {
// 2D multisampled image.
if (samples > 1) {
glext.glTexImage2DMultisample(target,
samples,
format.internalFormat,
width,
height,
true);
} else {
// Regular 2D image
gl.glTexImage2D(target,
level,
format.internalFormat,
width,
height,
0,
format.format,
format.dataType,
data);
}
}
}
}
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;
int sliceCount = 1;
if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
data = image.getData(index);
sliceCount = image.getData().size();
} else {
data = null;
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
if (data != null) {
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
}
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary 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 (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];
}
}
/**
* Update the texture currently bound to target at with data from the given
* Image at position x and y. The parameter index is used as the zoffset in
* case a 3d texture or texture 2d array is being updated.
*
* @param image Image with the source data (this data will be put into the
* texture)
* @param target the target texture
* @param index the mipmap level to update
* @param x the x position where to put the image in the texture
* @param y the y position where to put the image in the texture
*/
/*
public void uploadSubTexture(
EnumSet<Caps> caps,
Image image,
int target,
int index,
int x,
int y,
boolean linearizeSrgb) {
Image.Format fmt = image.getFormat();
GLImageFormat glFmt = getImageFormatWithError(caps, fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
ByteBuffer data = null;
if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
data = image.getData(index);
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
if (data != null) {
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
}
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary allocation
if (mipSizes == null){
if (data != null) {
mipSizes = new int[]{ data.capacity() };
} else {
mipSizes = new int[]{ width * height * fmt.getBitsPerPixel() / 8 };
}
}
int samples = image.getMultiSamples();
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]);
}
// to remove the cumbersome if/then/else stuff below we'll update the pos right here and use continue after each
// gl*Image call in an attempt to unclutter things a bit
pos += mipSizes[i];
int glFmtInternal = glFmt.internalFormat;
int glFmtFormat = glFmt.format;
int glFmtDataType = glFmt.dataType;
if (glFmt.compressed && data != null){
if (target == GL.GL_TEXTURE_3D){
gl.glCompressedTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtInternal, data);
continue;
}
// all other targets use 2D: array, cubemap, 2d
gl.glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtInternal, data);
continue;
}
if (target == GL.GL_TEXTURE_3D){
gl.glTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtFormat, glFmtDataType, data);
continue;
}
if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT){
// prepare data for 2D array or upload slice
if (index == -1){
gl.glTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtFormat, glFmtDataType, data);
continue;
}
gl.glTexSubImage3D(target, i, x, y, index, width, height, 1, glFmtFormat, glFmtDataType, data);
continue;
}
if (samples > 1){
throw new IllegalStateException("Cannot update multisample textures");
}
gl.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtFormat, glFmtDataType, data);
}
}
*/
}
Loading…
Cancel
Save