You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Add off-screen GL context
This commit is contained in:
@@ -407,6 +407,18 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
||||
}
|
||||
}
|
||||
|
||||
public boolean createOffscreenGL() {
|
||||
return mView.createOffscreenGL();
|
||||
}
|
||||
|
||||
public void destroyOffscreenGL() {
|
||||
mView.destroyOffscreenGL();
|
||||
}
|
||||
|
||||
public void setOffscreenGLCurrent(boolean p_current) {
|
||||
mView.setOffscreenGLCurrent(p_current);
|
||||
}
|
||||
|
||||
public void setKeepScreenOn(final boolean p_enabled) {
|
||||
runOnUiThread(() -> {
|
||||
if (p_enabled) {
|
||||
|
||||
@@ -72,10 +72,9 @@ public class GodotLib {
|
||||
|
||||
/**
|
||||
* Invoked on the GL thread when the underlying Android surface is created or recreated.
|
||||
* @param p_32_bits
|
||||
* @see android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)
|
||||
*/
|
||||
public static native void newcontext(boolean p_32_bits);
|
||||
public static native void newcontext();
|
||||
|
||||
/**
|
||||
* Forward {@link Activity#onBackPressed()} event from the main thread to the GL thread.
|
||||
|
||||
@@ -76,7 +76,7 @@ class GodotRenderer implements GLSurfaceView.Renderer {
|
||||
}
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
GodotLib.newcontext(GLUtils.use_32);
|
||||
GodotLib.newcontext();
|
||||
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
||||
plugin.onGLSurfaceCreated(gl, config);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ import android.view.GestureDetector;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
|
||||
/**
|
||||
* A simple GLSurfaceView sub-class that demonstrate how to perform
|
||||
* OpenGL ES 2.0 rendering into a GL Surface. Note the following important
|
||||
@@ -75,6 +79,10 @@ public class GodotView extends GLSurfaceView {
|
||||
private final GestureDetector detector;
|
||||
private final GodotRenderer godotRenderer;
|
||||
|
||||
private EGLConfigChooser eglConfigChooser;
|
||||
private EGLContextFactory eglContextFactory;
|
||||
private EGLContext eglSecondaryContext;
|
||||
|
||||
public GodotView(Context context, Godot godot, XRMode xrMode, boolean p_use_gl3,
|
||||
boolean p_use_32_bits, boolean p_use_debug_opengl, boolean p_translucent) {
|
||||
super(context);
|
||||
@@ -123,10 +131,10 @@ public class GodotView extends GLSurfaceView {
|
||||
switch (xrMode) {
|
||||
case OVR:
|
||||
// Replace the default egl config chooser.
|
||||
setEGLConfigChooser(new OvrConfigChooser());
|
||||
eglConfigChooser = new OvrConfigChooser();
|
||||
|
||||
// Replace the default context factory.
|
||||
setEGLContextFactory(new OvrContextFactory());
|
||||
eglContextFactory = new OvrContextFactory();
|
||||
|
||||
// Replace the default window surface factory.
|
||||
setEGLWindowSurfaceFactory(new OvrWindowSurfaceFactory());
|
||||
@@ -147,7 +155,7 @@ public class GodotView extends GLSurfaceView {
|
||||
/* Setup the context factory for 2.0 rendering.
|
||||
* See ContextFactory class definition below
|
||||
*/
|
||||
setEGLContextFactory(new RegularContextFactory());
|
||||
eglContextFactory = new RegularContextFactory();
|
||||
|
||||
/* We need to choose an EGLConfig that matches the format of
|
||||
* our surface exactly. This is going to be done in our
|
||||
@@ -156,24 +164,49 @@ public class GodotView extends GLSurfaceView {
|
||||
*/
|
||||
|
||||
if (GLUtils.use_32) {
|
||||
setEGLConfigChooser(translucent
|
||||
? new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,
|
||||
new RegularConfigChooser(8, 8, 8, 8, 16, stencil))
|
||||
: new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,
|
||||
new RegularConfigChooser(5, 6, 5, 0, 16, stencil)));
|
||||
eglConfigChooser = translucent
|
||||
? new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,
|
||||
new RegularConfigChooser(8, 8, 8, 8, 16, stencil))
|
||||
: new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,
|
||||
new RegularConfigChooser(5, 6, 5, 0, 16, stencil));
|
||||
|
||||
} else {
|
||||
setEGLConfigChooser(translucent
|
||||
? new RegularConfigChooser(8, 8, 8, 8, 16, stencil)
|
||||
: new RegularConfigChooser(5, 6, 5, 0, 16, stencil));
|
||||
eglConfigChooser = translucent
|
||||
? new RegularConfigChooser(8, 8, 8, 8, 16, stencil)
|
||||
: new RegularConfigChooser(5, 6, 5, 0, 16, stencil);
|
||||
}
|
||||
break;
|
||||
}
|
||||
setEGLConfigChooser(eglConfigChooser);
|
||||
setEGLContextFactory(eglContextFactory);
|
||||
|
||||
/* Set the renderer responsible for frame rendering */
|
||||
setRenderer(godotRenderer);
|
||||
}
|
||||
|
||||
public boolean createOffscreenGL() {
|
||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||
EGLConfig eglConfig = eglConfigChooser.chooseConfig(egl, egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY));
|
||||
eglSecondaryContext = eglContextFactory.createContext(egl, egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY), eglConfig);
|
||||
if (eglSecondaryContext == EGL10.EGL_NO_CONTEXT) {
|
||||
eglSecondaryContext = null;
|
||||
}
|
||||
return eglSecondaryContext != null;
|
||||
}
|
||||
|
||||
public void setOffscreenGLCurrent(boolean p_current) {
|
||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||
egl.eglMakeCurrent(egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY), EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, p_current ? eglSecondaryContext : EGL10.EGL_NO_CONTEXT);
|
||||
}
|
||||
|
||||
public void destroyOffscreenGL() {
|
||||
if (eglSecondaryContext != null) {
|
||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||
eglContextFactory.destroyContext(egl, egl.eglGetCurrentDisplay(), eglSecondaryContext);
|
||||
eglSecondaryContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
godot.onBackPressed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user