protected void setGLBackgroundTransparent(boolean transparent) { if (transparent) { mSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); mSurfaceView.setZOrderOnTop(true); } else { mSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888); mSurfaceView.setZOrderOnTop(false); } }
@Override public void onSetScript() { mSurfaceView = new GLSurfaceView(mActivity); mSurfaceView.setPreserveEGLContextOnPause(true); mSurfaceView.setEGLContextClientVersion(3); mSurfaceView.setEGLContextFactory(mContextFactory); mSurfaceView.setEGLConfigChooser(mConfigChooser); mSurfaceView.setEGLWindowSurfaceFactory(mWindowSurfaceFactory); mSurfaceView.setRenderer(mRenderer); mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mActivity.setContentView(mSurfaceView); final DisplayMetrics metrics = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); final VrAppSettings appSettings = mActivity.getAppSettings(); final int screenWidthPixels = Math.max(metrics.widthPixels, metrics.heightPixels); final int screenHeightPixels = Math.min(metrics.widthPixels, metrics.heightPixels); final int frameBufferWidth = appSettings.getFramebufferPixelsWide(); final int frameBufferHeight = appSettings.getFramebufferPixelsHigh(); final SurfaceHolder holder = mSurfaceView.getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT); if ((-1 != frameBufferHeight) && (-1 != frameBufferWidth)) { if ((screenWidthPixels != frameBufferWidth) && (screenHeightPixels != frameBufferHeight)) { Log.v(TAG, "--- window configuration ---"); Log.v(TAG, "--- width: %d", frameBufferWidth); Log.v(TAG, "--- height: %d", frameBufferHeight); // a different resolution of the native window requested holder.setFixedSize((int) frameBufferWidth, (int) frameBufferHeight); Log.v(TAG, "----------------------------"); } } }
private void init(Context context, AttributeSet attrs) { mGLSurfaceView = new GPUImageGLSurfaceView(context, attrs); mGLSurfaceView.setZOrderOnTop(true); mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT); addView(mGLSurfaceView); mGPUImage = new GPUImage(getContext()); mGPUImage.setGLSurfaceView(mGLSurfaceView); }
/** * Sets the GLSurfaceView which will display the preview. * * @param view the GLSurfaceView */ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView = view; // 设置OpenGl版本号为2 mGlSurfaceView.setEGLContextClientVersion(2); // 设置颜色缓存为RGBA,位数都为8,深度缓存位数为16,蒙版缓存位数为0 mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mGlSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888); mGlSurfaceView.setRenderer(mRenderer); // 脏模式,需要重绘时手动调用requestRender() mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGlSurfaceView.requestRender(); }
public void resetSurfaceView() { removeViewInLayout(surfaceView); surfaceView = null; surfaceView = new GLSurfaceView(getContext()); // surfaceView.setBackgroundColor(Color.WHITE); surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); surfaceView.setZOrderOnTop(true); surfaceView.setRenderer(renderer); surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); addViewInLayout( surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT), false); }
// -------------------------------------------------------------------------------------------------------------------- // Internals private void setupSurfaceView(Context context) { surfaceView = new GLSurfaceView(getContext()); cards = new FlipCards(this, flipOrientation == VERTICAL); renderer = new FlipRenderer(this, cards); surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); surfaceView.setZOrderOnTop(true); surfaceView.setRenderer(renderer); surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); addViewInLayout( surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT), false); }
@Override public void onSurfaceChanged(final GL10 gl, final int width, final int height) { Log.i(TAG, "onSurfaceChanged; %d x %d", width, height); if (null != mMainSurface) { Log.v(TAG, "short-circuiting onSurfaceChanged"); return; } final EGL10 egl = (EGL10) EGLContext.getEGL(); final EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); final EGLContext context = egl.eglGetCurrentContext(); int numAttribs = 0; final int[] configAttribs = new int[16]; Arrays.fill(configAttribs, EGL10.EGL_NONE); Log.v(TAG, "--- window surface configuration ---"); final VrAppSettings appSettings = mActivity.getAppSettings(); if (appSettings.useSrgbFramebuffer) { final int EGL_GL_COLORSPACE_KHR = 0x309D; final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089; configAttribs[numAttribs++] = EGL_GL_COLORSPACE_KHR; configAttribs[numAttribs++] = EGL_GL_COLORSPACE_SRGB_KHR; } Log.v(TAG, "--- srgb framebuffer: %b", appSettings.useSrgbFramebuffer); if (appSettings.useProtectedFramebuffer) { final int EGL_PROTECTED_CONTENT_EXT = 0x32c0; configAttribs[numAttribs++] = EGL_PROTECTED_CONTENT_EXT; configAttribs[numAttribs++] = EGL14.EGL_TRUE; } Log.v(TAG, "--- protected framebuffer: %b", appSettings.useProtectedFramebuffer); configAttribs[numAttribs++] = EGL10.EGL_NONE; Log.v(TAG, "------------------------------------"); // this is the display surface timewarp will hijack mMainSurface = egl.eglCreateWindowSurface(display, mConfig, mSurfaceView.getHolder(), configAttribs); Log.v(TAG, "mMainSurface: 0x%x", mMainSurface.hashCode()); if (mMainSurface == EGL10.EGL_NO_SURFACE) { throw new IllegalStateException( "eglCreateWindowSurface() failed: 0x" + Integer.toHexString(egl.eglGetError())); } if (!egl.eglMakeCurrent(display, mMainSurface, mMainSurface, context)) { throw new IllegalStateException( "eglMakeCurrent() failed: 0x " + Integer.toHexString(egl.eglGetError())); } nativeOnSurfaceChanged(mPtr); // necessary to explicitly make the pbuffer current for the rendering thread; // TimeWarp took over the window surface if (!egl.eglMakeCurrent(display, mPixelBuffer, mPixelBuffer, context)) { throw new IllegalStateException( "Failed to make context current ; egl error 0x" + Integer.toHexString(egl.eglGetError())); } startChoreographerThreadIfNotStarted(); mViewManager.onSurfaceChanged(width, height); }