Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.renderer.android.AndroidGL;
import com.jme3.renderer.opengl.GL;
import com.jme3.renderer.opengl.GLES_30;
import com.jme3.renderer.opengl.GLDebugES;
import com.jme3.renderer.opengl.GLExt;
import com.jme3.renderer.opengl.GLFbo;
import com.jme3.renderer.opengl.GLRenderer;
import com.jme3.renderer.opengl.GLTracer;
import com.jme3.renderer.opengl.*;
import com.jme3.system.*;
import com.jme3.util.AndroidBufferAllocator;
import com.jme3.util.BufferAllocatorFactory;
Expand Down Expand Up @@ -209,14 +203,14 @@ public void uncaughtException(Thread thread, Throwable thrown) {
});

timer = new NanoTimer();
Object gl = new AndroidGL();
GL gl = new AndroidGL();
if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugES((GL) gl, (GLExt) gl, (GLFbo) gl);
gl = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GLES_30.class, GLFbo.class, GLExt.class);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
gl = (GL)GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
}
renderer = new GLRenderer((GL)gl, (GLExt)gl, (GLFbo)gl);
renderer = new GLRenderer(gl, (GLExt)gl, (GLFbo)gl);
renderer.initialize();

JmeSystem.setSoftTextDialogInput(this);
Expand Down
93 changes: 91 additions & 2 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebug.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
/*
* Copyright (c) 2009-2020 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.RendererException;

public abstract class GLDebug {
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
* This class uses Reflection to intercept method calls to the Proxy Object ({@link #createProxy(GL, Object, Class[])}
* and extends them with the Error Checking in {@link #checkError()}.<br/>
* This means we don't have to generate a class with overrides for every possible method just to add a
* {@link #checkError()} call.<br/>
* Note that we should not call {@link #checkError()} for {@link GL#glGetError()}, it doesn't make sense.<br />
* Note that this class is general purpose and as such every class instance (every object) can be guarded as long as
* the passed gl instance is valid.<br/>
*
* @author MeFisto94
*/
public class GLDebug implements InvocationHandler {
protected Object obj;
protected GL gl;

protected Method methodGlGetError;

private GLDebug(GL gl, Object obj) throws NoSuchMethodException {
this.gl = gl;
this.obj = obj;
methodGlGetError = GL.class.getMethod("glGetError");
/* The NoSuchMethodException shouldn't be thrown, but since we're in a constructor and cannot fail safe
* otherwise, we throw it. */
}

protected String decodeError(int err) {
String errMsg;
switch (err) {
Expand Down Expand Up @@ -46,4 +101,38 @@ protected void checkError() {
throw new RendererException("An OpenGL error occurred - " + decodeError(err));
}
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(obj, args);

if (method.equals(methodGlGetError)) {
return result;
}

checkError();
return result;
}

/**
* Creates a debug-proxied object, which will call {@link GL#glGetError()} after every method invocation and throw
* a {@link com.jme3.renderer.RendererException} if there was a GL Error.
*
* @param gl The GL Context, required to call {@link GL#glGetError()}
* @param obj The object which methods will be proxied
* @param implementedInterfaces The interfaces/class this object implements
* @return The Proxy object (or null if an error occured)
*/
public static Object createProxy(GL gl, Object obj, Class<?>... implementedInterfaces) {
try {
return Proxy.newProxyInstance(
GLDebug.class.getClassLoader(),
implementedInterfaces,
new GLDebug(gl, obj)
);
} catch (NoSuchMethodException nsme) {
throw new IllegalArgumentException ("Could not initialize the proxy because the glGetError method wasn't " +
"found!", nsme);
}
}
}
147 changes: 0 additions & 147 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugDesktop.java

This file was deleted.

Loading