Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
28f509d
Update GLImageFormats.java
joliver82 May 17, 2018
71fcaa9
Merge remote-tracking branch 'upstream/master'
joliver82 May 23, 2018
4f8a2cc
Merge pull request #3 from jMonkeyEngine/master
joliver82 Nov 14, 2018
05db003
Merge pull request #4 from jMonkeyEngine/master
joliver82 Jun 1, 2019
18b431f
Modified JmeBatchRenderBackend to clear the inner buffer of the image…
Nov 19, 2019
38e330b
Merge pull request #5 from jMonkeyEngine/master
joliver82 Nov 20, 2019
f9282c1
First impl of testcasefor multiple atlases issue. Still missing to ad…
joliver82 Dec 19, 2019
9d8cbfa
Merge pull request #7 from jMonkeyEngine/master
joliver82 Mar 9, 2020
2a6ca82
Merge branch 'nifty-batch-fix' into master
joliver82 Mar 9, 2020
0569a0a
Merge remote-tracking branch 'upstream/master'
Jan 25, 2021
8a90e91
Manual merge pending stuff from jme3 base
Jan 25, 2021
1092b80
Manual merge
Jan 25, 2021
066ba48
Merge pull request #9 from jMonkeyEngine/master
joliver82 Feb 15, 2021
70a63d1
Implemented new methods in IosGL wrapper for GLES30
Feb 16, 2021
ce68960
Fixed some imports and typos
Feb 16, 2021
732016e
Added comment
Feb 16, 2021
077e854
Fixed compilation if using java >= 1.9. The bytecode was generated wi…
Feb 19, 2021
44c9430
Added glTexParameterf and fixed black screen rendering on iOS when us…
Feb 22, 2021
f59ddf3
Added constant GL_FRAMEBUFFER_BINDING
Feb 22, 2021
d92c48c
More gl functions implemented
Feb 22, 2021
ad5dcc1
Removed useless comments
Feb 24, 2021
2a7c2d9
Fixed release option to match current gradle version defined in gradlew
Feb 24, 2021
b076c56
Fixed formatting to match jME standards
Feb 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ version = jmeFullVersion
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

if(JavaVersion.current() >= JavaVersion.VERSION_1_9) {
compileJava {
options.compilerArgs.addAll(['--release', '8'])
//Replace previous with "options.release = 8" if updated to gradle 6.6 or newer
}
}

gradle.projectsEvaluated {
tasks.withType(JavaCompile) { // compile-time options:
options.compilerArgs << '-Xlint:unchecked'
Expand Down
3 changes: 2 additions & 1 deletion jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}
17 changes: 14 additions & 3 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public final class GLRenderer implements Renderer {
private final EnumMap<Limits, Integer> limits = new EnumMap<Limits, Integer>(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;
Expand Down Expand Up @@ -630,6 +631,16 @@ public void initialize() {
gl2.glEnable(GL2.GL_POINT_SPRITE);
}
}

IntBuffer tmp = BufferUtils.createIntBuffer(16);
gl.glGetInteger(GL.GL_FRAMEBUFFER_BINDING, 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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions jme3-ios/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
106 changes: 80 additions & 26 deletions jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,13 +46,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() {
Expand Down Expand Up @@ -129,7 +133,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
Expand Down Expand Up @@ -314,7 +318,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
Expand All @@ -333,7 +337,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
Expand All @@ -343,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
Expand Down Expand Up @@ -374,12 +376,14 @@ 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");
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");
JmeIosGLES.glGetQueryiv(query, pname, temp_array);
return temp_array[0];
}

@Override
Expand All @@ -406,11 +410,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);
}
}

Expand Down Expand Up @@ -454,25 +458,22 @@ 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
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
public void glTexParameterf(int target, int pname, float param) {
// TODO: fix me!!!
// JmeIosGLES.glTexParameterf(target, pname, param);
JmeIosGLES.glTexParameterf(target, pname, param);
}

@Override
Expand Down Expand Up @@ -583,7 +584,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
Expand All @@ -598,17 +599,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
Expand All @@ -628,7 +629,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
Expand Down Expand Up @@ -717,6 +718,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.glFramebufferTextureLayer(target, attachment, texture, level, layer);
}

// New methods from GL2 interface which are supported in GLES30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supported or unsupported? given that they are stubs atm

Copy link
Contributor Author

@joliver82 joliver82 Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is not too clear... Methods below are those defined in GL2 which we need to implement because gles30 supports some of them like GL{Read|Write}Buffer and also 3D textures. The reason to create the stubs is that glAlphaFunc, glPointSize and glPolygonMode have no gles equivalent but are defined in GL2 interface.

@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) {
((Buffer)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);
}


}
36 changes: 33 additions & 3 deletions jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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;

/**
* The <code>iOS GLES interface</code> iOS alternative to Android's GLES20 class
* The <code>iOS GLES interface</code> iOS alternative to Android's GLES20 and GLES30 classes
*
* @author Kostyantyn Hushchyn
* @author Kostyantyn Hushchyn, Jesus Oliver
*/
public class JmeIosGLES {
private static final Logger logger = Logger.getLogger(JmeIosGLES.class.getName());
Expand Down Expand Up @@ -184,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);
Expand All @@ -193,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);
Expand All @@ -204,8 +207,11 @@ 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);
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);
Expand All @@ -232,7 +238,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;
Expand Down Expand Up @@ -271,4 +301,4 @@ public static String gluErrorString(int error) {
}
*/

}
}