From 28f509d9f48d165bb38e956eb8a8805c405115c4 Mon Sep 17 00:00:00 2001 From: joliver82 <39382046+joliver82@users.noreply.github.com> Date: Thu, 17 May 2018 23:07:23 +0200 Subject: [PATCH 01/15] Update GLImageFormats.java --- .../src/main/java/com/jme3/renderer/opengl/GLImageFormats.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java index 21070227b1..fb46b0805e 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java @@ -220,7 +220,7 @@ public static GLImageFormat[][] getFormatsForCaps(EnumSet caps) { // NOTE: OpenGL ES 2.0 does not support DEPTH_COMPONENT as internal format -- fallback to 16-bit depth. if (caps.contains(Caps.OpenGLES20)) { - format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT16, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE); + format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT16, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_SHORT); } else { format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE); } From 18b431f64739d9b049323659aa8e7986a56fbf77 Mon Sep 17 00:00:00 2001 From: joliver82 Date: Tue, 19 Nov 2019 19:45:02 +0100 Subject: [PATCH 02/15] Modified JmeBatchRenderBackend to clear the inner buffer of the image in the atlases instead of setting a predefined byte buffer on disposal that made all atlases in the backend use the same buffer and generated rendering issues. --- .../jme3/niftygui/JmeBatchRenderBackend.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java index a8947fdea6..845ef594a7 100644 --- a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java +++ b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java @@ -89,7 +89,6 @@ public class JmeBatchRenderBackend implements BatchRenderBackend { private int textureAtlasId = 1; private Batch currentBatch; private Matrix4f tempMat = new Matrix4f(); - private ByteBuffer initialData; // this is only used for debugging purpose and will make the removed textures filled with a color // please note: the old way to init this via a system property has been @@ -184,15 +183,6 @@ public void disableMouseCursor() { public int createTextureAtlas(final int width, final int height) { try { int atlasId = addTexture(createAtlasTextureInternal(width, height)); - - // we just initialize a second buffer here that will replace the texture atlas image - initialData = BufferUtils.createByteBuffer(width*height*4); - for (int i=0; i Date: Thu, 19 Dec 2019 02:59:33 +0100 Subject: [PATCH 03/15] First impl of testcasefor multiple atlases issue. Still missing to add more images to the screens so it really uses more atlases --- .../TestNiftyBatchMultipleAtlases.java | 107 ++++++++++++++++++ .../Nifty/NiftyBatchMultipleAtlases.xml | 58 ++++++++++ 2 files changed, 165 insertions(+) create mode 100644 jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java create mode 100644 jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml diff --git a/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java b/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java new file mode 100644 index 0000000000..6de8c4b235 --- /dev/null +++ b/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2009-2019 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 jme3test.niftygui; + +import com.jme3.app.SimpleApplication; +import com.jme3.niftygui.NiftyJmeDisplay; +import de.lessvoid.nifty.Nifty; +import de.lessvoid.nifty.render.batch.BatchRenderConfiguration; +import de.lessvoid.nifty.screen.Screen; +import de.lessvoid.nifty.screen.ScreenController; + +public class TestNiftyBatchMultipleAtlases extends SimpleApplication implements ScreenController { + + private Nifty nifty; + + public static void main(String[] args){ + TestNiftyBatchMultipleAtlases app = new TestNiftyBatchMultipleAtlases(); + app.setPauseOnLostFocus(false); + app.start(); + } + + @Override + public void simpleInitApp() { + + BatchRenderConfiguration batchConfig = new BatchRenderConfiguration(); + batchConfig.atlasWidth = 256; + batchConfig.atlasHeight = 256; + batchConfig.atlasPadding = 2; + batchConfig.atlasTolerance = 0.5f; + batchConfig.fillRemovedImagesInAtlas = false; + batchConfig.disposeImagesBetweenScreens = true; + batchConfig.initialAtlasCount = 3; + + NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay( + assetManager, + inputManager, + audioRenderer, + guiViewPort, + batchConfig); + nifty = niftyDisplay.getNifty(); + nifty.loadControlFile("nifty-default-controls.xml"); + nifty.loadStyleFile("nifty-default-styles.xml"); + nifty.fromXml("Interface/Nifty/NiftyBatchMultipleAtlases.xml", "screen1", this); + + // attach the nifty display to the gui view port as a processor + guiViewPort.addProcessor(niftyDisplay); + + // disable the fly cam + flyCam.setEnabled(false); + flyCam.setDragToRotate(true); + inputManager.setCursorVisible(true); + } + + @Override + public void bind(Nifty nifty, Screen screen) { + System.out.println("bind(" + screen.getScreenId() + ")"); + } + + @Override + public void onStartScreen() { + System.out.println("onStartScreen"); + } + + @Override + public void onEndScreen() { + System.out.println("onEndScreen"); + } + + public void quit(){ + nifty.gotoScreen("end"); + } + + public void gotoScreen(String screen) { + nifty.gotoScreen(screen); + } + +} diff --git a/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml b/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml new file mode 100644 index 0000000000..e32550d8d7 --- /dev/null +++ b/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8a90e91ea86764c8913104c8389a61b014596ce8 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Mon, 25 Jan 2021 19:23:39 +0100 Subject: [PATCH 04/15] Manual merge pending stuff from jme3 base --- .../com/jme3/niftygui/JmeBatchRenderBackend.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java index 49165df640..429a21c896 100644 --- a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java +++ b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java @@ -209,17 +209,8 @@ public int createTextureAtlas(final int width, final int height) { @Override public void clearTextureAtlas(final int atlasId) { - com.jme3.texture.Image atlasImage=getTextureAtlas(atlasId).getImage(); - ByteBuffer atlasBuffer=atlasImage.getData(0); - atlasBuffer.rewind(); - for (int i=0; i Date: Mon, 25 Jan 2021 19:24:39 +0100 Subject: [PATCH 05/15] Manual merge --- .../TestNiftyBatchMultipleAtlases.java | 107 ------------------ .../Nifty/NiftyBatchMultipleAtlases.xml | 58 ---------- 2 files changed, 165 deletions(-) delete mode 100644 jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java delete mode 100644 jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml diff --git a/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java b/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java deleted file mode 100644 index 6de8c4b235..0000000000 --- a/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyBatchMultipleAtlases.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2009-2019 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 jme3test.niftygui; - -import com.jme3.app.SimpleApplication; -import com.jme3.niftygui.NiftyJmeDisplay; -import de.lessvoid.nifty.Nifty; -import de.lessvoid.nifty.render.batch.BatchRenderConfiguration; -import de.lessvoid.nifty.screen.Screen; -import de.lessvoid.nifty.screen.ScreenController; - -public class TestNiftyBatchMultipleAtlases extends SimpleApplication implements ScreenController { - - private Nifty nifty; - - public static void main(String[] args){ - TestNiftyBatchMultipleAtlases app = new TestNiftyBatchMultipleAtlases(); - app.setPauseOnLostFocus(false); - app.start(); - } - - @Override - public void simpleInitApp() { - - BatchRenderConfiguration batchConfig = new BatchRenderConfiguration(); - batchConfig.atlasWidth = 256; - batchConfig.atlasHeight = 256; - batchConfig.atlasPadding = 2; - batchConfig.atlasTolerance = 0.5f; - batchConfig.fillRemovedImagesInAtlas = false; - batchConfig.disposeImagesBetweenScreens = true; - batchConfig.initialAtlasCount = 3; - - NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay( - assetManager, - inputManager, - audioRenderer, - guiViewPort, - batchConfig); - nifty = niftyDisplay.getNifty(); - nifty.loadControlFile("nifty-default-controls.xml"); - nifty.loadStyleFile("nifty-default-styles.xml"); - nifty.fromXml("Interface/Nifty/NiftyBatchMultipleAtlases.xml", "screen1", this); - - // attach the nifty display to the gui view port as a processor - guiViewPort.addProcessor(niftyDisplay); - - // disable the fly cam - flyCam.setEnabled(false); - flyCam.setDragToRotate(true); - inputManager.setCursorVisible(true); - } - - @Override - public void bind(Nifty nifty, Screen screen) { - System.out.println("bind(" + screen.getScreenId() + ")"); - } - - @Override - public void onStartScreen() { - System.out.println("onStartScreen"); - } - - @Override - public void onEndScreen() { - System.out.println("onEndScreen"); - } - - public void quit(){ - nifty.gotoScreen("end"); - } - - public void gotoScreen(String screen) { - nifty.gotoScreen(screen); - } - -} diff --git a/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml b/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml deleted file mode 100644 index e32550d8d7..0000000000 --- a/jme3-examples/src/main/resources/Interface/Nifty/NiftyBatchMultipleAtlases.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 70a63d198761f9da22fd942638e235177614f74e Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Tue, 16 Feb 2021 03:58:11 +0100 Subject: [PATCH 06/15] Implemented new methods in IosGL wrapper for GLES30 Created native methods in JmeIosGLES --- .../java/com/jme3/renderer/ios/IosGL.java | 103 +++++++++++++++--- .../com/jme3/renderer/ios/JmeIosGLES.java | 29 ++++- 2 files changed, 115 insertions(+), 17 deletions(-) diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index 39f20a41a0..b1cfaf979f 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -43,13 +43,14 @@ import java.nio.ShortBuffer; /** - * Implements OpenGL ES 2.0 for iOS. + * Implements OpenGL ES 2.0 and 3.0 for iOS. * - * @author Kirill Vainer + * @author Kirill Vainer, Jesus Oliver */ -public class IosGL implements GL, GLExt, GLFbo { +public class IosGL implements GL, GL2, GLES_30, GLExt, GLFbo { private final int[] temp_array = new int[16]; + private final IntBuffer tmpBuff = BufferUtils.createIntBuffer(1); @Override public void resetStats() { @@ -129,7 +130,7 @@ public void glAttachShader(int program, int shader) { @Override public void glBeginQuery(int target, int query) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glBeginQuery(target, query); } @Override @@ -314,7 +315,7 @@ public void glEnableVertexAttribArray(int index) { @Override public void glEndQuery(int target) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glEndQuery(target); } @Override @@ -333,7 +334,7 @@ public void glGenTextures(IntBuffer textures) { @Override public void glGenQueries(int num, IntBuffer buff) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGenQueries(num, buff); } @Override @@ -374,12 +375,31 @@ public String glGetProgramInfoLog(int program, int maxLength) { @Override public long glGetQueryObjectui64(int query, int pname) { - throw new UnsupportedOperationException("Today is not a good day for this"); + //Sample from Android + /* + IntBuffer buff = IntBuffer.allocate(1); + //FIXME This is wrong IMO should be glGetQueryObjectui64v with a LongBuffer but it seems the API doesn't provide it. + JmeIosGLES.glGetQueryObjectuiv(query, pname, buff); + return buff.get(0); + */ + + //Sample from glGetInteger + mods + JmeIosGLES.glGetQueryObjectuiv(query, pname, temp_array); + return temp_array[0]; } @Override public int glGetQueryObjectiv(int query, int pname) { - throw new UnsupportedOperationException("Today is not a good day for this"); + //Sample from Android + /* + IntBuffer buff = IntBuffer.allocate(1); + JmeIosGLES.glGetQueryiv(query, pname, buff); + return buff.get(0); + */ + + //Sample from glGetInteger + mods + JmeIosGLES.glGetQueryiv(query, pname, temp_array); + return temp_array[0]; } @Override @@ -466,7 +486,7 @@ public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { @Override public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data) { - JmeIosGLES.glTexImage2D(target, level, format, width, height, 0, format, type, data); + JmeIosGLES.glTexImage2D(target, level, internalFormat, width, height, 0, format, type, data); } @Override @@ -583,7 +603,7 @@ public void glViewport(int x, int y, int width, int height) { @Override public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { - throw new UnsupportedOperationException("FBO blit not available on iOS"); + JmeIosGLES.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter) } @Override @@ -598,17 +618,17 @@ public void glBufferSubData(int target, long offset, IntBuffer data) { @Override public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glDrawArraysInstanced(mode, first, count, primcount); } @Override public void glDrawBuffers(IntBuffer bufs) { - throw new UnsupportedOperationException("MRT not available on iOS"); + JmeIosGLES.glDrawBuffers(getLimitBytes(bufs), bufs); } @Override public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glDrawElementsInstanced(mode, indices_count, type, indices_buffer_offset, primcount); } @Override @@ -628,7 +648,7 @@ public void glTexImage2DMultisample(int target, int samples, int internalformat, @Override public void glVertexAttribDivisorARB(int index, int divisor) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glVertexAttribDivisor(index, divisor); } @Override @@ -717,6 +737,59 @@ public Object glFenceSync(int condition, int flags) { @Override public void glFramebufferTextureLayerEXT(int target, int attachment, int texture, int level, int layer) { - throw new UnsupportedOperationException("OpenGL ES 2 does not support texture arrays"); + JmeIosGLES.glFramebufferTextureLayerEXT(target, attachment, texture, level, layer); + } + + // New methods from GL2 interface which are supported in GLES30 + @Override + public void glAlphaFunc(int func, float ref) { + } + + @Override + public void glPointSize(float size) { + } + + @Override + public void glPolygonMode(int face, int mode) { + } + + // Wrapper to DrawBuffers as there's no DrawBuffer method in GLES + @Override + public void glDrawBuffer(int mode) { + tmpBuff.clear(); + tmpBuff.put(0, mode); + tmpBuff.rewind(); + glDrawBuffers(tmpBuff); + } + + @Override + public void glReadBuffer(int mode) { + JmeIosGLES.glReadBuffer(mode); + } + + @Override + public void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, + int border, ByteBuffer data) { + JmeIosGLES.glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, getLimitBytes(data), data); + } + + @Override + public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, + int height, int depth, int format, ByteBuffer data) { + JmeIosGLES.glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, getLimitBytes(data), data); } + + @Override + public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, + int format, int type, ByteBuffer data) { + JmeIosGLES.glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data); + } + + @Override + 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) { + JmeIosGLES.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data); + } + + } diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java index 2a2eee5b5a..7ce3f74669 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java @@ -3,6 +3,7 @@ import com.jme3.renderer.RendererException; import java.nio.Buffer; +import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.logging.Logger; @@ -10,7 +11,7 @@ /** * The iOS GLES interface iOS alternative to Android's GLES20 class * - * @author Kostyantyn Hushchyn + * @author Kostyantyn Hushchyn, Jesus Oliver */ public class JmeIosGLES { private static final Logger logger = Logger.getLogger(JmeIosGLES.class.getName()); @@ -232,7 +233,31 @@ public class JmeIosGLES { public static native void glVertexAttribPointer2(int indx, int size, int type, boolean normalized, int stride, int offset); public static native void glViewport(int x, int y, int width, int height); + // New methods for GLES3 + public static native void glBeginQuery(int target, int query); + public static native void glEndQuery(int target); + public static native void glGenQueries(int num, IntBuffer buff); + public static native void glGetQueryObjectuiv(int query, int pname, int[] params); + public static native void glGetQueryiv(int query, int pname, int[] params); + public static native void glBlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter); + public static native void glDrawArraysInstanced(int mode, int first, int count, int primcount); + public static native void glDrawBuffers(int size, IntBuffer data); //TODO: use buffer or intbuffer? + public static native void glDrawElementsInstanced(int mode, int indices_count, int type, long indices_buffer_offset, int primcount); + public static native void glVertexAttribDivisor(int index, int divisor); + public static native void glFramebufferTextureLayer(int target, int attachment, int texture, int level, int layer); + + // New methods from GL2 interface which are supported in GLES30 + public static native void glReadBuffer(int mode); + public static native void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, + int border, int size, ByteBuffer data); + public static native void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, + int height, int depth, int format, int size, ByteBuffer data); + public static native void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, + int format, int type, ByteBuffer data); + public static native void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, + int depth, int format, int type, ByteBuffer data); + public static void checkGLError() { if (!ENABLE_ERROR_CHECKING) { return; @@ -271,4 +296,4 @@ public static String gluErrorString(int error) { } */ -} \ No newline at end of file +} From ce68960e12df876ceba8d5886ad71e099bcd31d7 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Tue, 16 Feb 2021 04:02:13 +0100 Subject: [PATCH 07/15] Fixed some imports and typos --- jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index b1cfaf979f..e2d8df9e05 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -33,8 +33,11 @@ import com.jme3.renderer.RendererException; import com.jme3.renderer.opengl.GL; +import com.jme3.renderer.opengl.GL2; +import com.jme3.renderer.opengl.GLES_30; import com.jme3.renderer.opengl.GLExt; import com.jme3.renderer.opengl.GLFbo; +import com.jme3.util.BufferUtils; import java.nio.Buffer; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; @@ -603,7 +606,7 @@ public void glViewport(int x, int y, int width, int height) { @Override public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { - JmeIosGLES.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter) + JmeIosGLES.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); } @Override @@ -737,7 +740,7 @@ public Object glFenceSync(int condition, int flags) { @Override public void glFramebufferTextureLayerEXT(int target, int attachment, int texture, int level, int layer) { - JmeIosGLES.glFramebufferTextureLayerEXT(target, attachment, texture, level, layer); + JmeIosGLES.glFramebufferTextureLayer(target, attachment, texture, level, layer); } // New methods from GL2 interface which are supported in GLES30 From 732016e69a4608b61374cbd105bdc4d323cd9ad7 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Tue, 16 Feb 2021 04:04:16 +0100 Subject: [PATCH 08/15] Added comment --- jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java index 7ce3f74669..3c39f1bf5f 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java @@ -9,7 +9,7 @@ import java.util.logging.Logger; /** - * The iOS GLES interface iOS alternative to Android's GLES20 class + * The iOS GLES interface iOS alternative to Android's GLES20 and GLES30 classes * * @author Kostyantyn Hushchyn, Jesus Oliver */ From 077e854d5ec29ccfe3bd64443155a8db02554990 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Fri, 19 Feb 2021 03:09:19 +0100 Subject: [PATCH 09/15] Fixed compilation if using java >= 1.9. The bytecode was generated with v52 but when executing it failed to find methods of nio.*Buffer because of an implementation change after java 1.9 --- common.gradle | 6 ++++++ jme3-ios/build.gradle | 3 +++ jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common.gradle b/common.gradle index 2b59420c08..0076d93a97 100644 --- a/common.gradle +++ b/common.gradle @@ -12,6 +12,12 @@ version = jmeFullVersion sourceCompatibility = '1.8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +if(JavaVersion.current() >= JavaVersion.VERSION_1_9) { + compileJava { + options.release = 8 + } +} + gradle.projectsEvaluated { tasks.withType(JavaCompile) { // compile-time options: options.compilerArgs << '-Xlint:unchecked' diff --git a/jme3-ios/build.gradle b/jme3-ios/build.gradle index bc93216107..8eb91e0bc5 100644 --- a/jme3-ios/build.gradle +++ b/jme3-ios/build.gradle @@ -2,6 +2,9 @@ if (!hasProperty('mainClass')) { ext.mainClass = '' } +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + dependencies { compile project(':jme3-core') compile project(':jme3-plugins') diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index e2d8df9e05..050d43a1da 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -759,7 +759,7 @@ public void glPolygonMode(int face, int mode) { // Wrapper to DrawBuffers as there's no DrawBuffer method in GLES @Override public void glDrawBuffer(int mode) { - tmpBuff.clear(); + ((Buffer)tmpBuff).clear(); tmpBuff.put(0, mode); tmpBuff.rewind(); glDrawBuffers(tmpBuff); From 44c94307d0f8da763c9a617fc96d0900135722d1 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Mon, 22 Feb 2021 14:07:54 +0100 Subject: [PATCH 10/15] Added glTexParameterf and fixed black screen rendering on iOS when using any additional framebuffer (scene processors and filters) --- .../com/jme3/renderer/opengl/GLRenderer.java | 17 ++++++++++++++--- .../main/java/com/jme3/renderer/ios/IosGL.java | 3 +-- .../java/com/jme3/renderer/ios/JmeIosGLES.java | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index fed5800a9d..3afe7c0f07 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -91,6 +91,7 @@ public final class GLRenderer implements Renderer { private final EnumMap limits = new EnumMap(Limits.class); private FrameBuffer mainFbOverride = null; + private int defaultFBO = 0; private final Statistics statistics = new Statistics(); private int vpX, vpY, vpW, vpH; private int clipX, clipY, clipW, clipH; @@ -630,6 +631,16 @@ public void initialize() { gl2.glEnable(GL2.GL_POINT_SPRITE); } } + + IntBuffer tmp=BufferUtils.createIntBuffer(16); + gl.glGetInteger(36006, tmp); + tmp.rewind(); + int fbOnLoad=tmp.get(); + if(fbOnLoad>0) + { + // Overriding default FB to fbOnLoad. Mostly iOS fix for scene processors and filters + defaultFBO=fbOnLoad; + } } @Override @@ -1856,10 +1867,10 @@ public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) { private void bindFrameBuffer(FrameBuffer fb) { if (fb == null) { - if (context.boundFBO != 0) { - glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, 0); + if (context.boundFBO != defaultFBO) { + glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, defaultFBO); statistics.onFrameBufferUse(null, true); - context.boundFBO = 0; + context.boundFBO = defaultFBO; context.boundFB = null; } } else { diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index 050d43a1da..b998fdd09d 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -494,8 +494,7 @@ public void glTexImage2D(int target, int level, int internalFormat, int width, i @Override public void glTexParameterf(int target, int pname, float param) { - // TODO: fix me!!! - // JmeIosGLES.glTexParameterf(target, pname, param); + JmeIosGLES.glTexParameterf(target, pname, param); } @Override diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java index 3c39f1bf5f..7a0428124d 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java @@ -207,6 +207,7 @@ public class JmeIosGLES { public static native void glShaderSource(int shader, String string); public static native void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels); public static native void glTexParameteri(int target, int pname, int param); + public static native void glTexParameterf(int target, int pname, float param); public static native void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels); public static native void glUniform1f(int location, float x); public static native void glUniform1fv(int location, int count, FloatBuffer v); From f59ddf30da2bc348e6dd24d2c7f8da3a2af36aec Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Mon, 22 Feb 2021 14:25:22 +0100 Subject: [PATCH 11/15] Added constant GL_FRAMEBUFFER_BINDING --- jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java | 3 ++- .../src/main/java/com/jme3/renderer/opengl/GLRenderer.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java index 9f7c5ac309..3202af5628 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java @@ -195,6 +195,7 @@ public interface GL { public static final int GL_VERTEX_SHADER = 0x8B31; public static final int GL_ZERO = 0x0; public static final int GL_UNPACK_ROW_LENGTH = 0x0CF2; + public static final int GL_FRAMEBUFFER_BINDING = 0x8CA6; public void resetStats(); @@ -1300,4 +1301,4 @@ public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int * @param height the viewport height. */ public void glViewport(int x, int y, int width, int height); -} \ No newline at end of file +} diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 3afe7c0f07..8b34ed5961 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -633,7 +633,7 @@ public void initialize() { } IntBuffer tmp=BufferUtils.createIntBuffer(16); - gl.glGetInteger(36006, tmp); + gl.glGetInteger(GL.GL_FRAMEBUFFER_BINDING, tmp); tmp.rewind(); int fbOnLoad=tmp.get(); if(fbOnLoad>0) From d92c48cd3c05310a8cf7dd16306774d17194abbd Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Mon, 22 Feb 2021 15:01:48 +0100 Subject: [PATCH 12/15] More gl functions implemented --- .../src/main/java/com/jme3/renderer/ios/IosGL.java | 14 +++++--------- .../java/com/jme3/renderer/ios/JmeIosGLES.java | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index b998fdd09d..139991d3d4 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -347,9 +347,7 @@ public int glGetAttribLocation(int program, String name) { @Override public void glGetBoolean(int pname, ByteBuffer params) { - // TODO: fix me!!! - // JmeIosGLES.glGetBoolean(pname, params); - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGetBoolean(pname, params); } @Override @@ -429,11 +427,11 @@ public int glGetUniformLocation(int program, String name) { @Override public boolean glIsEnabled(int cap) { - // TODO: fix me!!! + // kept this always returning true for compatibility if (cap == GLExt.GL_MULTISAMPLE_ARB) { return true; } else { - throw new UnsupportedOperationException(); + return JmeIosGLES.glIsEnabled(cap); } } @@ -477,14 +475,12 @@ public void glShaderSource(int shader, String[] string, IntBuffer length) { @Override public void glStencilFuncSeparate(int face, int func, int ref, int mask) { - // TODO: fix me!!! - // JmeIosGLES.glStencilFuncSeparate(face, func, ref, mask); + JmeIosGLES.glStencilFuncSeparate(face, func, ref, mask); } @Override public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - // TODO: fix me!!! - // JmeIosGLES.glStencilOpSeparate(face, sfail, dpfail, dppass); + JmeIosGLES.glStencilOpSeparate(face, sfail, dpfail, dppass); } @Override diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java index 7a0428124d..347babbbd4 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java @@ -185,6 +185,7 @@ public class JmeIosGLES { public static native void glGenTextures(int n, int[] textures, int offset); public static native void glGenerateMipmap(int target); public static native int glGetAttribLocation(int program, String name); + public static native void glGetBoolean(int pname, ByteBuffer params); public static native int glGetError(); public static native void glGetFramebufferAttachmentParameteriv(int target, int attachment, int pname, int[] params, int offset); public static native void glGetIntegerv (int pname, int[] params, int offset); @@ -194,6 +195,7 @@ public class JmeIosGLES { public static native void glGetShaderiv(int shader, int pname, int[] params, int offset); public static native String glGetString(int name); public static native int glGetUniformLocation(int program, String name); + public static native boolean glIsEnabled(int cap); public static native boolean glIsFramebuffer(int framebuffer); public static native boolean glIsRenderbuffer(int renderbuffer); public static native void glLineWidth(float width); @@ -205,6 +207,8 @@ public class JmeIosGLES { public static native void glRenderbufferStorage(int target, int internalformat, int width, int height); public static native void glScissor(int x, int y, int width, int height); public static native void glShaderSource(int shader, String string); + public static native void glStencilFuncSeparate(int face, int func, int ref, int mask); + public static native void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass); public static native void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels); public static native void glTexParameteri(int target, int pname, int param); public static native void glTexParameterf(int target, int pname, float param); From ad5dcc1650fac2d1952929f4fadcba0d372f953d Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Wed, 24 Feb 2021 04:20:26 +0100 Subject: [PATCH 13/15] Removed useless comments --- .../main/java/com/jme3/renderer/ios/IosGL.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index 139991d3d4..5de9d77500 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -376,29 +376,12 @@ public String glGetProgramInfoLog(int program, int maxLength) { @Override public long glGetQueryObjectui64(int query, int pname) { - //Sample from Android - /* - IntBuffer buff = IntBuffer.allocate(1); - //FIXME This is wrong IMO should be glGetQueryObjectui64v with a LongBuffer but it seems the API doesn't provide it. - JmeIosGLES.glGetQueryObjectuiv(query, pname, buff); - return buff.get(0); - */ - - //Sample from glGetInteger + mods JmeIosGLES.glGetQueryObjectuiv(query, pname, temp_array); return temp_array[0]; } @Override public int glGetQueryObjectiv(int query, int pname) { - //Sample from Android - /* - IntBuffer buff = IntBuffer.allocate(1); - JmeIosGLES.glGetQueryiv(query, pname, buff); - return buff.get(0); - */ - - //Sample from glGetInteger + mods JmeIosGLES.glGetQueryiv(query, pname, temp_array); return temp_array[0]; } From 2a7c2d9aebc1d969f41b742d8b812f6ade02ad1a Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Wed, 24 Feb 2021 04:59:56 +0100 Subject: [PATCH 14/15] Fixed release option to match current gradle version defined in gradlew --- common.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common.gradle b/common.gradle index 0076d93a97..ace48aa122 100644 --- a/common.gradle +++ b/common.gradle @@ -14,7 +14,8 @@ sourceCompatibility = '1.8' if(JavaVersion.current() >= JavaVersion.VERSION_1_9) { compileJava { - options.release = 8 + options.compilerArgs.addAll(['--release', '8']) + //Replace previous with "options.release = 8" if updated to gradle 6.6 or newer } } From b076c569192134368ed7a6bff39324d3b41f97e5 Mon Sep 17 00:00:00 2001 From: Jesus Oliver Date: Fri, 26 Feb 2021 12:16:17 +0100 Subject: [PATCH 15/15] Fixed formatting to match jME standards --- .../main/java/com/jme3/renderer/opengl/GLRenderer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 8b34ed5961..95b2ce7f1d 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -632,14 +632,14 @@ public void initialize() { } } - IntBuffer tmp=BufferUtils.createIntBuffer(16); + IntBuffer tmp = BufferUtils.createIntBuffer(16); gl.glGetInteger(GL.GL_FRAMEBUFFER_BINDING, tmp); tmp.rewind(); - int fbOnLoad=tmp.get(); - if(fbOnLoad>0) + int fbOnLoad = tmp.get(); + if(fbOnLoad > 0) { // Overriding default FB to fbOnLoad. Mostly iOS fix for scene processors and filters - defaultFBO=fbOnLoad; + defaultFBO = fbOnLoad; } }