void IGraphicsBackend.BeginRendering(IDrawDevice device, RenderOptions options, RenderStats stats) { DebugCheckOpenGLErrors(); // ToDo: AA is disabled for now //this.CheckContextCaps(); this.currentDevice = device; this.renderOptions = options; this.renderStats = stats; // Prepare the target surface for rendering NativeRenderTarget.Bind(options.Target as NativeRenderTarget); // Determine the available size on the active rendering surface //Point2 availableSize; //if (NativeRenderTarget.BoundRT != null) { // availableSize = new Point2(NativeRenderTarget.BoundRT.Width, NativeRenderTarget.BoundRT.Height); //} else { // availableSize = this.externalBackbufferSize; //} Rect openGLViewport = options.Viewport; // Setup viewport and scissor rects GL.Viewport((int)openGLViewport.X, (int)openGLViewport.Y, (int)MathF.Ceiling(openGLViewport.W), (int)MathF.Ceiling(openGLViewport.H)); GL.Scissor((int)openGLViewport.X, (int)openGLViewport.Y, (int)MathF.Ceiling(openGLViewport.W), (int)MathF.Ceiling(openGLViewport.H)); // Clear buffers if (options.ClearFlags != ClearFlag.None) { uint glClearMask = 0; ColorRgba clearColor = options.ClearColor; if ((options.ClearFlags & ClearFlag.Color) != ClearFlag.None) { glClearMask |= WebGLRenderingContextBase.COLOR_BUFFER_BIT; } if ((options.ClearFlags & ClearFlag.Depth) != ClearFlag.None) { glClearMask |= WebGLRenderingContextBase.DEPTH_BUFFER_BIT; } GL.ClearColor(clearColor.R / 255.0f, clearColor.G / 255.0f, clearColor.B / 255.0f, clearColor.A / 255.0f); GL.ClearDepth(options.ClearDepth); GL.Clear(glClearMask); } // Configure Rendering params GL.Enable(WebGLRenderingContextBase.SCISSOR_TEST); GL.Enable(WebGLRenderingContextBase.DEPTH_TEST); if (options.DepthTest) { GL.DepthFunc(WebGLRenderingContextBase.LEQUAL); } else { GL.DepthFunc(WebGLRenderingContextBase.ALWAYS); } Matrix4 view = options.ViewMatrix; Matrix4 projection = options.ProjectionMatrix; if (NativeRenderTarget.BoundRT != null) { Matrix4 flipOutput = Matrix4.CreateScale(1.0f, -1.0f, 1.0f); projection = projection * flipOutput; } // Convert matrices to float arrays GetArrayMatrix(ref view, viewData); GetArrayMatrix(ref projection, projectionData); // All EBOs can be used again lastUsedEBO = 0; }