/** Initialize EGL for a given configuration spec. */ public void start(SurfaceTexture mSurface) { if (LOG_EGL) { Log.d("EglHelper", "start() tid=" + Thread.currentThread().getId()); } /* * Get an EGL instance */ mEgl = (EGL10) EGLContext.getEGL(); /* * Get to the default display. */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } /* * We can now initialize EGL for that display */ int[] version = new int[2]; if (!mEgl.eglInitialize(mEglDisplay, version)) { throw new RuntimeException("eglInitialize failed"); } mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay); if (mEglConfig == null) { throw new RuntimeException("eglConfig not initialized"); } /* * Create an EGL context. We want to do this as rarely as we can, because an * EGL context is a somewhat heavy object. */ mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig); if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) { mEglContext = null; throwEglException("createContext"); } if (LOG_EGL) { Log.d( "EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId()); } mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface, null); if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) { int error = mEgl.eglGetError(); if (error == EGL10.EGL_BAD_NATIVE_WINDOW) { Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW."); } throw new RuntimeException( "createWindowSurface failed " + GLUtils.getEGLErrorString(error)); } if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { throw new RuntimeException( "eglMakeCurrent failed " + GLUtils.getEGLErrorString(mEgl.eglGetError())); } }
// EGL functions public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) { try { if (SDLActivity.mEGLDisplay == null) { Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(dpy, version); EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; if (!egl.eglChooseConfig(dpy, attribs, configs, 1, num_config) || num_config[0] == 0) { Log.e("SDL", "No EGL config available"); return false; } EGLConfig config = configs[0]; SDLActivity.mEGLDisplay = dpy; SDLActivity.mEGLConfig = config; SDLActivity.mGLMajor = majorVersion; SDLActivity.mGLMinor = minorVersion; } return SDLActivity.createEGLSurface(); } catch (Exception e) { Log.v("SDL", e + ""); for (StackTraceElement s : e.getStackTrace()) { Log.v("SDL", s.toString()); } return false; } }
/** * Initialize EGL for a given configuration spec. * * @param configSpec */ public void start() { /* * Get an EGL instance */ mEgl = (EGL10) EGLContext.getEGL(); /* * Get to the default display. */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); /* * We can now initialize EGL for that display */ int[] version = new int[2]; mEgl.eglInitialize(mEglDisplay, version); mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay); /* * Create an OpenGL ES context. This must be done only once, an * OpenGL context is a somewhat heavy object. */ mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null); mEglSurface = null; }
private boolean initGLES() { EGL10 egl = (EGL10) EGLContext.getEGL(); mEglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { Log.e(TAG, "Fail to get Display"); return false; } int[] version = new int[2]; if (!egl.eglInitialize(mEglDisplay, version)) { Log.e(TAG, "Fail to eglInitialize"); return false; } int[] configSpec = {EGL10.EGL_NONE}; EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!egl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, numConfigs)) { Log.e(TAG, "Fail to Choose Config"); return false; } mEglConfig = configs[0]; mEglContext = egl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null); if (mEglContext == EGL10.EGL_NO_CONTEXT) { Log.e(TAG, "Fail to Create OpenGL Context"); return false; } return true; }
private static void initEGL() { if (sEGL != null) { return; } sEGL = (EGL10) EGLContext.getEGL(); sEGLDisplay = sEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); if (sEGLDisplay == EGL10.EGL_NO_DISPLAY) { Log.w(LOGTAG, "can't get EGL display!"); return; } // while calling eglInitialize here should not be necessary as it was already called // by the EGLPreloadingThread, it really doesn't cost much to call it again here, // and makes this code easier to think about: EGLPreloadingThread is only a // preloading optimization, not something we rely on for anything else. // // Also note that while calling eglInitialize isn't necessary on Android 4.x // (at least Android's HardwareRenderer does it for us already), it is necessary // on Android 2.x. int[] returnedVersion = new int[2]; if (!sEGL.eglInitialize(sEGLDisplay, returnedVersion)) { Log.w(LOGTAG, "eglInitialize failed"); return; } sEGLConfig = chooseConfig(); }
public void initEGL() { mEGL = (EGL10) GLDebugHelper.wrap( EGLContext.getEGL(), GLDebugHelper.CONFIG_CHECK_GL_ERROR | GLDebugHelper.CONFIG_CHECK_THREAD, null); mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] curGLVersion = new int[2]; mEGL.eglInitialize(mGLDisplay, curGLVersion); Log.i("GL", "GL version = " + curGLVersion[0] + "." + curGLVersion[1]); EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1, num_config); mGLConfig = configs[0]; mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv.getHolder(), null); mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig, EGL10.EGL_NO_CONTEXT, null); mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext); mGL = (GL10) GLDebugHelper.wrap( mGLContext.getGL(), GLDebugHelper.CONFIG_CHECK_GL_ERROR | GLDebugHelper.CONFIG_CHECK_THREAD | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null); }
protected boolean checkGL20() { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(display, version); int EGL_OPENGL_ES2_BIT = 4; int[] configAttribs = { EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[10]; int[] num_config = new int[1]; egl.eglChooseConfig(display, configAttribs, configs, 10, num_config); egl.eglTerminate(display); return num_config[0] > 0; }
@Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG, "surfaceCreated"); // Lots of stunningly tedious EGL setup. All we want is a 565 surface. egl = (EGL10) EGLContext.getEGL(); display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; if (!egl.eglInitialize(display, version)) { throw new RuntimeException("eglInitialize failed"); } /* int[] attrib_list = new int[] { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, EGL10.EGL_ALPHA_SIZE, 0, EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_NONE }; egl.eglGetConfigs(display, configs, config_size, num_config) EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[] {1}; egl.eglChooseConfig(display, attrib_list, configs, configs.length, numConfigs); if (0 == numConfigs[0]) { throw new RuntimeException("No matching EGL config"); } config = configs[0]; */ config = getEglConfig565(egl, display); ctxt = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null); }
private boolean createSurface() { EGL10 egl = (EGL10) EGLContext.getEGL(); mEglSurface = egl.eglCreateWindowSurface(mEglDisplay, mEglConfig, getHolder(), null); if (mEglSurface == EGL10.EGL_NO_SURFACE) { return false; } return true; }
private void destroySurfaceForTimeWarp() { if (null != mMainSurface) { Log.v(TAG, "destroying mMainSurface: 0x%x", mMainSurface.hashCode()); final EGL10 egl = (EGL10) EGLContext.getEGL(); final EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); egl.eglDestroySurface(display, mMainSurface); mMainSurface = null; } }
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { EGL10 egl = (EGL10) EGLContext.getEGL(); YabauseRunnable.lockGL(); egl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); YabauseRunnable.initViewport(width, height); YabauseRunnable.unlockGL(); }
/** Some initialization of the OpenGL stuff (that I don't understand...) */ protected void init() { // Much of this code is from GLSurfaceView in the Google API Demos. // I encourage those interested to look there for documentation. egl = (EGL10) EGLContext.getEGL(); dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(dpy, version); int[] configSpec = { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, EGL10.EGL_DEPTH_SIZE, 8, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config); EGLConfig config = configs[0]; eglContext = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null); surface = egl.eglCreateWindowSurface(dpy, config, sHolder, null); egl.eglMakeCurrent(dpy, surface, surface, eglContext); gl = (GL10) eglContext.getGL(); // Load the buffer and stuff gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepthf(1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glEnable(GL10.GL_TEXTURE_2D); // Resize... whatever? gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glViewport(0, 0, width, height); GLU.gluPerspective(gl, 45.0f, ((float) width) / height, 1f, 100f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, 5.5f, 0, 0, 0, 0, 1, 0); gl.glNormal3f(0, 0, 1); }
/** Initialize EGL for a given configuration spec. */ @SuppressWarnings("StatementWithEmptyBody") public void start() { // Log.d("EglHelper" + instanceId, "start()"); if (mEgl == null) { // Log.d("EglHelper" + instanceId, "getting new EGL"); /* * Get an EGL instance */ mEgl = (EGL10) EGLContext.getEGL(); } else { // Log.d("EglHelper" + instanceId, "reusing EGL"); } if (mEglDisplay == null) { // Log.d("EglHelper" + instanceId, "getting new display"); /* * Get to the default display. */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); } else { // Log.d("EglHelper" + instanceId, "reusing display"); } if (mEglConfig == null) { // Log.d("EglHelper" + instanceId, "getting new config"); /* * We can now initialize EGL for that display */ int[] version = new int[2]; mEgl.eglInitialize(mEglDisplay, version); mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay); } else { // Log.d("EglHelper" + instanceId, "reusing config"); } if (mEglContext == null) { // Log.d("EglHelper" + instanceId, "creating new context"); /* * Create an OpenGL ES context. This must be done only once, an OpenGL context is a somewhat heavy object. */ mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig); if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) { throw new RuntimeException("createContext failed"); } } else { // Log.d("EglHelper" + instanceId, "reusing context"); } mEglSurface = null; }
public static boolean createEGLContext() { EGL10 egl = (EGL10) EGLContext.getEGL(); int EGL_CONTEXT_CLIENT_VERSION = 0x3098; int contextAttrs[] = new int[] {EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE}; SDLActivity.mEGLContext = egl.eglCreateContext( SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs); if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) { Log.e("SDL", "Couldn't create context"); return false; } return true; }
public static boolean createEGLSurface() { if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) { EGL10 egl = (EGL10) EGLContext.getEGL(); if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) createEGLContext(); if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) { Log.v("SDL", "Creating new EGL Surface"); SDLActivity.mEGLSurface = egl.eglCreateWindowSurface( SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null); if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) { Log.e("SDL", "Couldn't create surface"); return false; } } else Log.v("SDL", "EGL Surface remains valid"); if (egl.eglGetCurrentContext() != SDLActivity.mEGLContext) { if (!egl.eglMakeCurrent( SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface, SDLActivity.mEGLSurface, SDLActivity.mEGLContext)) { Log.e("SDL", "Old EGL Context doesnt work, trying with a new one"); // TODO: Notify the user via a message that the old context could not be restored, and // that textures need to be manually restored. createEGLContext(); if (!egl.eglMakeCurrent( SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface, SDLActivity.mEGLSurface, SDLActivity.mEGLContext)) { Log.e("SDL", "Failed making EGL Context current"); return false; } } else Log.v("SDL", "EGL Context made current"); } else Log.v("SDL", "EGL Context remains current"); return true; } else { Log.e( "SDL", "Surface creation failed, display = " + SDLActivity.mEGLDisplay + ", config = " + SDLActivity.mEGLConfig); return false; } }
void initializeEgl() { synchronized (sEglLock) { if (sEgl == null && sEglConfig == null) { sEgl = (EGL10) EGLContext.getEGL(); // Get to the default display. sEglDisplay = sEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY); if (sEglDisplay == EGL_NO_DISPLAY) { throw new RuntimeException( "eglGetDisplay failed " + GLUtils.getEGLErrorString(sEgl.eglGetError())); } // We can now initialize EGL for that display int[] version = new int[2]; if (!sEgl.eglInitialize(sEglDisplay, version)) { throw new RuntimeException( "eglInitialize failed " + GLUtils.getEGLErrorString(sEgl.eglGetError())); } checkEglErrorsForced(); sEglConfig = chooseEglConfig(); if (sEglConfig == null) { // We tried to use EGL_SWAP_BEHAVIOR_PRESERVED_BIT, try again without if (sDirtyRegions) { sDirtyRegions = false; sEglConfig = chooseEglConfig(); if (sEglConfig == null) { throw new RuntimeException("eglConfig not initialized"); } } else { throw new RuntimeException("eglConfig not initialized"); } } } } ManagedEGLContext managedContext = sEglContextStorage.get(); mEglContext = managedContext != null ? managedContext.getContext() : null; mEglThread = Thread.currentThread(); if (mEglContext == null) { mEglContext = createContext(sEgl, sEglDisplay, sEglConfig); sEglContextStorage.set(createManagedContext(mEglContext)); } }
public static void deleteGLContext() { if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLContext != EGL10.EGL_NO_CONTEXT) { EGL10 egl = (EGL10) EGLContext.getEGL(); egl.eglMakeCurrent( SDLActivity.mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); egl.eglDestroyContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLContext); SDLActivity.mEGLContext = EGL10.EGL_NO_CONTEXT; if (SDLActivity.mEGLSurface != EGL10.EGL_NO_SURFACE) { egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface); SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE; } } }
// Called when we lose the surface @Override public void surfaceDestroyed(SurfaceHolder holder) { Log.v("SDL", "surfaceDestroyed()"); // Call this *before* setting mIsSurfaceReady to 'false' SDLActivity.handlePause(); SDLActivity.mIsSurfaceReady = false; /* We have to clear the current context and destroy the egl surface here * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d */ EGL10 egl = (EGL10) EGLContext.getEGL(); egl.eglMakeCurrent( SDLActivity.mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface); SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE; }
// EGL buffer flip public static void flipEGL() { try { EGL10 egl = (EGL10) EGLContext.getEGL(); egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null); // drawing here egl.eglWaitGL(); egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface); } catch (Exception e) { Log.v("SDL", "flipEGL(): " + e); for (StackTraceElement s : e.getStackTrace()) { Log.v("SDL", s.toString()); } } }
/** * Initialize EGL for a given configuration spec. * * @param configSpec */ public void start() { /* * Get an EGL instance */ mEgl = (EGL10) EGLContext.getEGL(); /* * Get to the default display. */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } /* * We can now initialize EGL for that display */ int[] version = new int[2]; if (!mEgl.eglInitialize(mEglDisplay, version)) { throw new RuntimeException("eglInitialize failed"); } GlView view = mGLSceneViewWeakRef.get(); if (view == null) { mEglConfig = null; mEglContext = null; } else { mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay); /* * Create an EGL context. We want to do this as rarely as we can, because an * EGL context is a somewhat heavy object. */ mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig); } if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) { mEglContext = null; throwEglException("createContext"); } mEglSurface = null; }
public void initialize(int[] configSpec, Renderer rendererInterface) { renderer = rendererInterface; egl = (EGL10) EGLContext.getEGL(); display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); egl.eglInitialize(display, null); EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; egl.eglChooseConfig(display, configSpec, configs, 1, num_config); config = configs[0]; eglContext = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null); hasSurface = false; surface = null; createSurface(); }
private void endGLES() { EGL10 egl = (EGL10) EGLContext.getEGL(); if (mEglSurface != null) { // レンダリングコンテキストとの結びつけは解除 egl.eglMakeCurrent( mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); egl.eglDestroySurface(mEglDisplay, mEglSurface); mEglSurface = null; } if (mEglContext != null) { egl.eglDestroyContext(mEglDisplay, mEglContext); mEglContext = null; } if (mEglDisplay != null) { egl.eglTerminate(mEglDisplay); mEglDisplay = null; } }
private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException { /* Get an EGL instance. */ final EGL10 egl = (EGL10) EGLContext.getEGL(); /* Get to the default display. */ final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); /* We can now initialize EGL for that display. */ final int[] version = new int[2]; egl.eglInitialize(eglDisplay, version); final ConfigChooser configChooser = new ConfigChooser( false); // TODO Doesn't correlate to possible multisampling request in EngineOptions... try { configChooser.chooseConfig(egl, eglDisplay); } catch (final IllegalArgumentException e) { throw new DeviceNotSupportedException(DeviceNotSupportedCause.EGLCONFIG_NOT_FOUND, e); } }
private void logConfig(EGLConfig config) { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int r = getAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0); int g = getAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0); int b = getAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0); int a = getAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0); int d = getAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0); int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0); int samples = Math.max( getAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0), getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0)); boolean coverageSample = getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0) != 0; Gdx.app.log("AndroidGraphics", "framebuffer: (" + r + ", " + g + ", " + b + ", " + a + ")"); Gdx.app.log("AndroidGraphics", "depthbuffer: (" + d + ")"); Gdx.app.log("AndroidGraphics", "stencilbuffer: (" + s + ")"); Gdx.app.log("AndroidGraphics", "samples: (" + samples + ")"); Gdx.app.log("AndroidGraphics", "coverage sampling: (" + coverageSample + ")"); bufferFormat = new BufferFormat(r, g, b, a, d, s, samples, coverageSample); }
@Override public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) { eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext(); setupGL(gl); logConfig(config); updatePpi(); Mesh.invalidateAllMeshes(app); Texture.invalidateAllTextures(app); ShaderProgram.invalidateAllShaderPrograms(app); FrameBuffer.invalidateAllFrameBuffers(app); Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus()); Gdx.app.log("AndroidGraphics", Texture.getManagedStatus()); Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus()); Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus()); Display display = app.getWindowManager().getDefaultDisplay(); this.width = display.getWidth(); this.height = display.getHeight(); mean = new WindowedMean(5); this.lastFrameTime = System.nanoTime(); gl.glViewport(0, 0, this.width, this.height); isSurfaceCreated = true; }
@Override public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) { eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext(); // jw: added setupGL(gl); logConfig(config); updatePpi(); Mesh.invalidateAllMeshes(app); Texture.invalidateAllTextures(app); ShaderProgram.invalidateAllShaderPrograms(app); FrameBuffer.invalidateAllFrameBuffers(app); if (AndroidLiveWallpaperService .DEBUG) { // to prevent creating too many string buffers in live wallpapers Gdx.app.debug("AndroidGraphics", Mesh.getManagedStatus()); Gdx.app.debug("AndroidGraphics", Texture.getManagedStatus()); Gdx.app.debug("AndroidGraphics", ShaderProgram.getManagedStatus()); Gdx.app.debug("AndroidGraphics", FrameBuffer.getManagedStatus()); } Display display = app.getWindowManager().getDefaultDisplay(); this.width = display.getWidth(); this.height = display.getHeight(); mean = new WindowedMean(5); this.lastFrameTime = System.nanoTime(); gl.glViewport(0, 0, this.width, this.height); // jw: moved to onSurfaceChanged (as in AndroidGraphics class) /*if (created == false) { app.getListener().create(); created = true; synchronized (this) { running = true; } }*/ }
private void logConfig(EGLConfig config) { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int r = getAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0); int g = getAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0); int b = getAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0); int a = getAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0); int d = getAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0); int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0); int samples = Math.max( getAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0), getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0)); boolean coverageSample = getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0) != 0; // print configuration just one time (on some devices gl context is recreated every time when // device is locked / unlocked - every time when screen turns on and off) if (!configLogged) { if (gl != null) { Gdx.app.log("AndroidGraphics", "OGL renderer: " + gl.glGetString(GL10.GL_RENDERER)); Gdx.app.log("AndroidGraphics", "OGL vendor: " + gl.glGetString(GL10.GL_VENDOR)); Gdx.app.log("AndroidGraphics", "OGL version: " + gl.glGetString(GL10.GL_VERSION)); Gdx.app.log("AndroidGraphics", "OGL extensions: " + gl.glGetString(GL10.GL_EXTENSIONS)); configLogged = true; } Gdx.app.log("AndroidGraphics", "framebuffer: (" + r + ", " + g + ", " + b + ", " + a + ")"); Gdx.app.log("AndroidGraphics", "depthbuffer: (" + d + ")"); Gdx.app.log("AndroidGraphics", "stencilbuffer: (" + s + ")"); Gdx.app.log("AndroidGraphics", "samples: (" + samples + ")"); Gdx.app.log("AndroidGraphics", "coverage sampling: (" + coverageSample + ")"); } bufferFormat = new BufferFormat(r, g, b, a, d, s, samples, coverageSample); }
private void doInitGL() { // These are copied from GLSurfaceView mEgl = (EGL10) EGLContext.getEGL(); mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } int[] version = new int[2]; if (!mEgl.eglInitialize(mEglDisplay, version)) { throw new RuntimeException("eglInitialize failed"); } else { Log.v(TAG, "EGL version: " + version[0] + '.' + version[1]); } int[] attribList = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; mEglConfig = chooseConfig(mEgl, mEglDisplay); mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, attribList); if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) { throw new RuntimeException("failed to createContext"); } mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, mMosaicOutputSurfaceTexture, null); if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) { throw new RuntimeException("failed to createWindowSurface"); } if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { throw new RuntimeException("failed to eglMakeCurrent"); } mGl = (GL10) mEglContext.getGL(); mInputSurfaceTexture = new SurfaceTexture(MosaicRenderer.init()); MosaicRenderer.reset(mWidth, mHeight, mIsLandscape); }
public void swapBuffers() { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetCurrentDisplay(); EGLSurface surface = egl.eglGetCurrentSurface(EGL10.EGL_READ); egl.eglSwapBuffers(display, surface); }
public MainView(Context context, Activity inActivity) { super(context); int eglVersion = 1; // See if version 2 is supported? if (false || false) { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(display, version); EGLConfig[] v2_configs = new EGLConfig[1]; int[] num_config = new int[1]; int[] attrs = {EGL10.EGL_RENDERABLE_TYPE, 4 /*EGL_OPENGL_ES2_BIT*/, EGL10.EGL_NONE}; egl.eglChooseConfig(display, attrs, v2_configs, 1, num_config); // Log.v("EGL","v2 configs : " + num_config[0]); if (num_config[0] == 1) { eglVersion = 2; setEGLContextClientVersion(2); } } final int renderType = eglVersion == 1 ? 0x01 : 0x04; setEGLConfigChooser( new EGLConfigChooser() { public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { int depth = 0; int stencil = 0; EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; // Try as specified - aa if (0 > 1) { int[] attrs = { EGL10.EGL_DEPTH_SIZE, depth, EGL10.EGL_STENCIL_SIZE, stencil, EGL10.EGL_SAMPLE_BUFFERS, 1 /* true */, EGL10.EGL_SAMPLES, 0, EGL10.EGL_RENDERABLE_TYPE, renderType, EGL10.EGL_NONE }; egl.eglChooseConfig(display, attrs, configs, 1, num_config); Log.v("EGL", "Match AA=0, depth + stencil : " + num_config[0]); if (num_config[0] == 1) return configs[0]; // Try with just 2 specified - aa if (0 > 2) { int[] attrs_aa2 = { EGL10.EGL_DEPTH_SIZE, depth, EGL10.EGL_STENCIL_SIZE, stencil, EGL10.EGL_SAMPLE_BUFFERS, 1 /* true */, EGL10.EGL_SAMPLES, 2, EGL10.EGL_RENDERABLE_TYPE, renderType, EGL10.EGL_NONE }; egl.eglChooseConfig(display, attrs_aa2, configs, 1, num_config); Log.v("EGL", "Match AA=2, depth + stencil : " + num_config[0]); if (num_config[0] == 1) return configs[0]; } // No normal multisampling config was found. Try to create a // converage multisampling configuration, for the nVidia Tegra2. // See the EGL_NV_coverage_sample documentation. final int EGL_COVERAGE_BUFFERS_NV = 0x30E0; final int EGL_COVERAGE_SAMPLES_NV = 0x30E1; int[] attrs_aanv = { EGL10.EGL_DEPTH_SIZE, depth, EGL10.EGL_STENCIL_SIZE, stencil, EGL_COVERAGE_BUFFERS_NV, 1 /* true */, EGL_COVERAGE_SAMPLES_NV, 2, // always 5 in practice on tegra 2 EGL10.EGL_RENDERABLE_TYPE, renderType, EGL10.EGL_NONE }; egl.eglChooseConfig(display, attrs_aanv, configs, 1, num_config); Log.v("EGL", "Match AANV, depth + stencil : " + num_config[0]); if (num_config[0] == 1) return configs[0]; } // Try just specifying just depth and stencil int[] attrs1 = { EGL10.EGL_DEPTH_SIZE, depth, EGL10.EGL_STENCIL_SIZE, stencil, EGL10.EGL_RENDERABLE_TYPE, renderType, EGL10.EGL_NONE }; egl.eglChooseConfig(display, attrs1, configs, 1, num_config); Log.v("EGL", "Matched depth + stencil : " + num_config[0]); if (num_config[0] == 1) return configs[0]; // Just give me whatever you've got int[] attrs2 = {EGL10.EGL_NONE}; egl.eglChooseConfig(display, attrs2, configs, 1, num_config); if (num_config[0] == 1) return configs[0]; Log.v("EGL", "Matched any : " + num_config[0]); return null; } }); mActivity = inActivity; mRefreshView = this; setFocusable(true); setFocusableInTouchMode(true); setRenderer(new Renderer(this)); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); }