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); } }
private View createGLSurfaceView( Activity activity, boolean useGL2, final ResolutionStrategy resolutionStrategy) { EGLConfigChooser configChooser = getEglConfigChooser(); if (useGL2 && checkGL20()) { // GLSurfaceView20 view = new GLSurfaceView20(activity, resolutionStrategy); GLSurfaceView20 view = new GLSurfaceView20(activity, true, 16, 0, resolutionStrategy); Log.v("launcher", "create gl"); // view.setZOrderOnTop(true); if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); // view.pauseEglHelper = config.pauseEglHelper; view.setRenderer(this); return view; } else { config.useGL20 = false; configChooser = getEglConfigChooser(); int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK); if (sdkVersion >= 11) { GLSurfaceView view = new GLSurfaceView(activity) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(measures.width, measures.height); } }; if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); // view.pauseEglHelper = config.pauseEglHelper; view.setRenderer(this); return view; } else { GLSurfaceViewCupcake view = new GLSurfaceViewCupcake(activity, resolutionStrategy); if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); view.setRenderer(this); return view; } } }
@Override public void onCreate(Bundle savedInstanceState) { Logger.log("onCreate"); if (master != null) { copy(master); } super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); mGLView = new GLSurfaceView(getApplication()); mGLView.setEGLConfigChooser( new GLSurfaceView.EGLConfigChooser() { public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { // Ensure that we get a 16bit framebuffer. Otherwise, we'll fall // back to Pixelflinger on some device (read: Samsung I7500) int[] attributes = new int[] {EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE}; EGLConfig[] configs = new EGLConfig[1]; int[] result = new int[1]; egl.eglChooseConfig(display, attributes, configs, 1, result); return configs[0]; } }); mGLView.setLayoutParams( new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT)); mGLView.setRenderer(new BRenderer()); this.setContentView(mGLView); wakeLock = getWakeLock(this, TAG); }
@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 initGLSurfaceView() { if (glView != null) { glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); glView.setRenderer(renderer); glView.setOnTouchListener(this); } }
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); }
protected void createMultisampleConfig() { final int EGL_COVERAGE_BUFFERS_NV = 0x30E0; final int EGL_COVERAGE_SAMPLES_NV = 0x30E1; mSurfaceView.setEGLConfigChooser( new GLSurfaceView.EGLConfigChooser() { public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { int[] configSpec = new int[] { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_RENDERABLE_TYPE, 4, EGL10.EGL_SAMPLE_BUFFERS, 1, EGL10.EGL_SAMPLES, 2, EGL10.EGL_NONE }; int[] result = new int[1]; if (!egl.eglChooseConfig(display, configSpec, null, 0, result)) { RajLog.e("Multisampling configuration 1 failed."); } if (result[0] <= 0) { // no multisampling, check for coverage multisampling configSpec = new int[] { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_RENDERABLE_TYPE, 4, EGL_COVERAGE_BUFFERS_NV, 1, EGL_COVERAGE_SAMPLES_NV, 2, EGL10.EGL_NONE }; if (!egl.eglChooseConfig(display, configSpec, null, 0, result)) { RajLog.e( "Multisampling configuration 2 failed. Multisampling is not possible on your device."); } if (result[0] <= 0) { configSpec = new int[] { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_RENDERABLE_TYPE, 4, EGL10.EGL_NONE }; if (!egl.eglChooseConfig(display, configSpec, null, 0, result)) { RajLog.e( "Multisampling configuration 3 failed. Multisampling is not possible on your device."); } if (result[0] <= 0) { throw new RuntimeException("Couldn't create OpenGL config."); } } else { mUsesCoverageAa = true; } } EGLConfig[] configs = new EGLConfig[result[0]]; if (!egl.eglChooseConfig(display, configSpec, configs, result[0], result)) { throw new RuntimeException("Couldn't create OpenGL config."); } int index = -1; int[] value = new int[1]; for (int i = 0; i < configs.length; ++i) { egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RED_SIZE, value); if (value[0] == 5) { index = i; break; } } EGLConfig config = configs.length > 0 ? configs[index] : null; if (config == null) { throw new RuntimeException("No config chosen"); } return config; } }); }
// Grabbed from original AndroidGraphics class, with modifications: // + overrided getHolder in created GLSurfaceView instances // + Activity changed to Context (as it should be in AndroidGraphics I think;p) private View createGLSurfaceView( Context context, boolean useGL2, final ResolutionStrategy resolutionStrategy) { EGLConfigChooser configChooser = getEglConfigChooser(); if (useGL2 && checkGL20()) { GLSurfaceView20 view = new GLSurfaceView20(context, resolutionStrategy) { // -> specific for live wallpapers @Override public SurfaceHolder getHolder() { return getSurfaceHolder(); } public void onDestroy() { onDetachedFromWindow(); // calls GLSurfaceView.mGLThread.requestExitAndWait(); } // <- specific for live wallpapers }; if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); view.setRenderer(this); return view; } else { config.useGL20 = false; configChooser = getEglConfigChooser(); int sdkVersion = android.os.Build.VERSION.SDK_INT; if (sdkVersion >= 11) { GLSurfaceView view = new GLSurfaceView(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(measures.width, measures.height); } // -> specific for live wallpapers @Override public SurfaceHolder getHolder() { return getSurfaceHolder(); } public void onDestroy() { onDetachedFromWindow(); // calls GLSurfaceView.mGLThread.requestExitAndWait(); } // <- specific for live wallpapers }; if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); view.setRenderer(this); return view; } else { if (config.useGLSurfaceViewAPI18) { GLSurfaceViewAPI18 view = new GLSurfaceViewAPI18(context, resolutionStrategy) { // -> specific for live wallpapers @Override public SurfaceHolder getHolder() { return getSurfaceHolder(); } // <- specific for live wallpapers }; if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); view.setRenderer(this); return view; } else { GLSurfaceViewCupcake view = new GLSurfaceViewCupcake(context, resolutionStrategy) { // -> specific for live wallpapers @Override public SurfaceHolder getHolder() { return getSurfaceHolder(); } // <- specific for live wallpapers }; if (configChooser != null) view.setEGLConfigChooser(configChooser); else view.setEGLConfigChooser( config.r, config.g, config.b, config.a, config.depth, config.stencil); view.setRenderer(this); return view; } } } }