public bool SwapBuffers(GlesRenderTarget renderTarget, int width, int height) { int curFB; Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out curFB); Gles.glBindFramebuffer(Gles.GL_DRAW_FRAMEBUFFER_ANGLE, 0); Gles.glBindFramebuffer(Gles.GL_READ_FRAMEBUFFER_ANGLE, (uint)curFB); Gles.glBlitFramebufferANGLE(0, 0, width, height, 0, 0, width, height, Gles.GL_COLOR_BUFFER_BIT, Gles.GL_NEAREST); Gles.glBindFramebuffer(Gles.GL_DRAW_FRAMEBUFFER_ANGLE, (uint)curFB); Gles.glBindFramebuffer(Gles.GL_READ_FRAMEBUFFER_ANGLE, (uint)curFB); return(Egl.eglSwapBuffers(eglDisplay, eglSurface) == Egl.EGL_TRUE); }
public void SetSurface( SwapChainPanel swapChainPanel, int rbWidth, int rbHeight, GlesBackingOption backingOption = GlesBackingOption.Detroyed, GlesMultisampling multisampling = GlesMultisampling.None, GlesRenderTarget renderTarget = GlesRenderTarget.Renderbuffer) { if (eglSurface != Egl.EGL_NO_SURFACE) { DestroySurface(eglSurface); eglSurface = Egl.EGL_NO_SURFACE; } if (swapChainPanel != null) { CreateSurface(swapChainPanel, rbWidth, rbHeight, backingOption, multisampling, renderTarget); } }
private void CreateSurface(SwapChainPanel panel, int rbWidth, int rbHeight, GlesBackingOption backingOption, GlesMultisampling multisampling, GlesRenderTarget renderTarget) { if (panel == null) { throw new ArgumentNullException(nameof(panel), "SwapChainPanel parameter is invalid"); } if (rbWidth == 0 || rbHeight == 0) { rbWidth = 320; rbHeight = 480; } // Create a temporary surface so that we can make the context current int[] surfaceAttributes = { Egl.EGL_WIDTH, rbWidth, Egl.EGL_HEIGHT, rbHeight, Egl.EGL_FIXED_SIZE_ANGLE, Egl.EGL_TRUE, // Egl.EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as Egl.EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above). // If you have compilation issues with it then please update your Visual Studio templates. Egl.EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, Egl.EGL_TRUE, Egl.EGL_NONE }; eglSurface = Egl.eglCreateWindowSurface(eglDisplay, eglConfig, panel, surfaceAttributes); if (eglSurface == Egl.EGL_NO_SURFACE) { throw new Exception("Failed to create EGL surface"); } // Set up swap behavior. int swapBehavior = backingOption == GlesBackingOption.Retained ? Egl.EGL_BUFFER_PRESERVED : Egl.EGL_BUFFER_DESTROYED; if (Egl.eglSurfaceAttrib(eglDisplay, eglSurface, Egl.EGL_SWAP_BEHAVIOR, swapBehavior) == Egl.EGL_FALSE) { Debug.WriteLine("Unable to set up backbuffer swap behavior, app may experience graphical glitches!"); } if (multisampling == GlesMultisampling.FourTimes) { Gles.glRenderbufferStorageMultisampleANGLE((uint)renderTarget, 4, Gles.GL_BGRA8_EXT, rbWidth, rbHeight); } else { Gles.glRenderbufferStorage((uint)renderTarget, Gles.GL_BGRA8_EXT, rbWidth, rbHeight); } if (CurrentContext == this) { Egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); } }