private void Initialize() { if (designMode) { return; } renderLoopWorker = null; renderOnceWorker = null; backingOption = GlesBackingOption.Detroyed; multisampling = GlesMultisampling.None; depthFormat = GlesDepthFormat.None; stencilFormat = GlesStencilFormat.None; contentsScale = 1; propertiesChanged = No; renderbufferWidth = 0; renderbufferHeight = 0; Context = null; DrawInBackground = false; SizeChanged += OnSizeChanged; CompositionScaleChanged += OnCompositionChanged; }
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); } }