Fixed GFX errors on newer Tegra devices, due to improper choosing GL config in Java code
This commit is contained in:
@@ -657,14 +657,14 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
private static class ComponentSizeChooser extends BaseConfigChooser {
|
private static class ComponentSizeChooser extends BaseConfigChooser {
|
||||||
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
|
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
|
||||||
int alphaSize, int depthSize, int stencilSize, boolean isGles2) {
|
int alphaSize, int depthSize, int stencilSize, boolean isGles2) {
|
||||||
super(new int[] {
|
super(new int[] { /*
|
||||||
EGL10.EGL_RED_SIZE, redSize,
|
EGL10.EGL_RED_SIZE, redSize,
|
||||||
EGL10.EGL_GREEN_SIZE, greenSize,
|
EGL10.EGL_GREEN_SIZE, greenSize,
|
||||||
EGL10.EGL_BLUE_SIZE, blueSize,
|
EGL10.EGL_BLUE_SIZE, blueSize,
|
||||||
EGL10.EGL_ALPHA_SIZE, alphaSize,
|
EGL10.EGL_ALPHA_SIZE, alphaSize,
|
||||||
EGL10.EGL_DEPTH_SIZE, depthSize,
|
EGL10.EGL_DEPTH_SIZE, depthSize,
|
||||||
EGL10.EGL_STENCIL_SIZE, stencilSize,
|
EGL10.EGL_STENCIL_SIZE, stencilSize,
|
||||||
EGL10.EGL_RENDERABLE_TYPE, isGles2 ? EGL_OPENGL_ES2_BIT : 0,
|
EGL10.EGL_RENDERABLE_TYPE, isGles2 ? EGL_OPENGL_ES2_BIT : 0, */
|
||||||
EGL10.EGL_NONE});
|
EGL10.EGL_NONE});
|
||||||
mValue = new int[1];
|
mValue = new int[1];
|
||||||
mRedSize = redSize;
|
mRedSize = redSize;
|
||||||
@@ -673,7 +673,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
mAlphaSize = alphaSize;
|
mAlphaSize = alphaSize;
|
||||||
mDepthSize = depthSize;
|
mDepthSize = depthSize;
|
||||||
mStencilSize = stencilSize;
|
mStencilSize = stencilSize;
|
||||||
this.isGles2 = isGles2;
|
mIsGles2 = isGles2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -682,7 +682,11 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
EGLConfig closestConfig = null;
|
EGLConfig closestConfig = null;
|
||||||
int closestDistance = 1000;
|
int closestDistance = 1000;
|
||||||
String cfglog = "";
|
String cfglog = "";
|
||||||
|
int idx = 0;
|
||||||
|
int selectidx = -1;
|
||||||
for(EGLConfig config : configs) {
|
for(EGLConfig config : configs) {
|
||||||
|
if ( config == null )
|
||||||
|
continue;
|
||||||
int r = findConfigAttrib(egl, display, config,
|
int r = findConfigAttrib(egl, display, config,
|
||||||
EGL10.EGL_RED_SIZE, 0);
|
EGL10.EGL_RED_SIZE, 0);
|
||||||
int g = findConfigAttrib(egl, display, config,
|
int g = findConfigAttrib(egl, display, config,
|
||||||
@@ -695,37 +699,53 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
EGL10.EGL_DEPTH_SIZE, 0);
|
EGL10.EGL_DEPTH_SIZE, 0);
|
||||||
int s = findConfigAttrib(egl, display, config,
|
int s = findConfigAttrib(egl, display, config,
|
||||||
EGL10.EGL_STENCIL_SIZE, 0);
|
EGL10.EGL_STENCIL_SIZE, 0);
|
||||||
boolean gles2 = (findConfigAttrib(egl, display, config,
|
int rendertype = findConfigAttrib(egl, display, config,
|
||||||
EGL10.EGL_RENDERABLE_TYPE, 0) & EGL_OPENGL_ES2_BIT) != 0;
|
EGL10.EGL_RENDERABLE_TYPE, 0);
|
||||||
|
int desiredtype = mIsGles2 ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_ES_BIT;
|
||||||
int distance = Math.abs(r - mRedSize)
|
int distance = Math.abs(r - mRedSize)
|
||||||
+ Math.abs(g - mGreenSize)
|
+ Math.abs(g - mGreenSize)
|
||||||
+ Math.abs(b - mBlueSize) + Math.abs(a - mAlphaSize)
|
+ Math.abs(b - mBlueSize) + Math.abs(a - mAlphaSize)
|
||||||
+ Math.abs( ((d > 0) == (mDepthSize > 0)) ? 0 : 16 )
|
+ Math.abs( ((d > 0) == (mDepthSize > 0)) ? 0 : 10 )
|
||||||
+ Math.abs( ((s > 0) == (mStencilSize > 0)) ? 0 : 16 )
|
+ Math.abs( ((s > 0) == (mStencilSize > 0)) ? 0 : 10 )
|
||||||
+ (gles2 == isGles2 ? 0 : 16);
|
+ ( ((rendertype & desiredtype) != 0 ) ? 0 : 16 )
|
||||||
|
+ ( (rendertype == desiredtype) ? 0 : 1 ); // Small penalty for mixed GLES + GLES2 + OPENVG etc modes
|
||||||
|
String cfgcur = "R" + r + "G" + g + "B" + b + "A" + a + " depth " + d + " stencil " + s +
|
||||||
|
" renderable type " + findConfigAttrib(egl, display, config, EGL10.EGL_RENDERABLE_TYPE, 0) + "(";
|
||||||
|
if((rendertype & EGL_OPENGL_ES_BIT) != 0)
|
||||||
|
cfgcur += " GLES";
|
||||||
|
if((rendertype & EGL_OPENGL_ES2_BIT) != 0)
|
||||||
|
cfgcur += " GLES2";
|
||||||
|
if((rendertype & EGL_OPENGL_BIT) != 0)
|
||||||
|
cfgcur += " OPENGL";
|
||||||
|
if((rendertype & EGL_OPENVG_BIT) != 0)
|
||||||
|
cfgcur += " OPENVG";
|
||||||
|
cfgcur += " )";
|
||||||
|
Log.v("SDL", "GL config " + idx + ": " + cfgcur);
|
||||||
if (distance < closestDistance) {
|
if (distance < closestDistance) {
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
closestConfig = config;
|
closestConfig = config;
|
||||||
cfglog = "R" + r + "G" + g + "B" + b + "A" + a + " depth " + d + " stencil " + s + " GLES2 " + gles2 +
|
cfglog = new String(cfgcur);
|
||||||
" renderable type " + findConfigAttrib(egl, display, config, EGL10.EGL_RENDERABLE_TYPE, 0);
|
selectidx = idx;
|
||||||
}
|
}
|
||||||
|
idx += 1;
|
||||||
}
|
}
|
||||||
Log.v("SDL", "GLSurfaceView_SDL::EGLConfigChooser::chooseConfig(): selected " + cfglog );
|
Log.v("SDL", "GLSurfaceView_SDL::EGLConfigChooser::chooseConfig(): selected " + selectidx + ": " + cfglog );
|
||||||
return closestConfig;
|
return closestConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
|
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
|
||||||
EGLConfig config, int attribute, int defaultValue) {
|
EGLConfig config, int attribute, int defaultValue) {
|
||||||
|
mValue[0] = -1;
|
||||||
if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
|
if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
|
||||||
return mValue[0];
|
return mValue[0];
|
||||||
}
|
}
|
||||||
|
Log.w("SDL", "GLSurfaceView_SDL::EGLConfigChooser::findConfigAttrib(): attribute doesn't exist: " + attribute);
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGles2Required()
|
public boolean isGles2Required()
|
||||||
{
|
{
|
||||||
return isGles2;
|
return mIsGles2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] mValue;
|
private int[] mValue;
|
||||||
@@ -736,9 +756,12 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
protected int mAlphaSize;
|
protected int mAlphaSize;
|
||||||
protected int mDepthSize;
|
protected int mDepthSize;
|
||||||
protected int mStencilSize;
|
protected int mStencilSize;
|
||||||
public boolean isGles2 = false;
|
protected boolean mIsGles2 = false;
|
||||||
|
|
||||||
|
public static final int EGL_OPENGL_ES_BIT = 1;
|
||||||
|
public static final int EGL_OPENVG_BIT = 2;
|
||||||
public static final int EGL_OPENGL_ES2_BIT = 4;
|
public static final int EGL_OPENGL_ES2_BIT = 4;
|
||||||
|
public static final int EGL_OPENGL_BIT = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -817,6 +840,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
int[] version = new int[2];
|
int[] version = new int[2];
|
||||||
mEgl.eglInitialize(mEglDisplay, version);
|
mEgl.eglInitialize(mEglDisplay, version);
|
||||||
mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
|
mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
|
||||||
|
if( mEglConfig == null )
|
||||||
|
Log.e("SDL", "GLSurfaceView_SDL::EglHelper::start(): mEglConfig is NULL");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create an OpenGL ES context. This must be done only once, an
|
* Create an OpenGL ES context. This must be done only once, an
|
||||||
@@ -825,11 +850,12 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call
|
|||||||
final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
|
final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
|
||||||
final int[] gles2_attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
|
final int[] gles2_attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
|
||||||
|
|
||||||
Log.v("SDL", "GLSurfaceView_SDL::EglHelper::start(): Gles2 " + mEGLConfigChooser.isGles2Required());
|
|
||||||
|
|
||||||
mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
|
mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
|
||||||
EGL10.EGL_NO_CONTEXT, mEGLConfigChooser.isGles2Required() ? gles2_attrib_list : null );
|
EGL10.EGL_NO_CONTEXT, mEGLConfigChooser.isGles2Required() ? gles2_attrib_list : null );
|
||||||
|
|
||||||
|
if( mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT )
|
||||||
|
Log.e("SDL", "GLSurfaceView_SDL::EglHelper::start(): mEglContext is EGL_NO_CONTEXT, error: " + mEgl.eglGetError());
|
||||||
|
|
||||||
mEglSurface = null;
|
mEglSurface = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user