Esempio n. 1
0
        public virtual void Draw()
        {
            gl.Enable(WebGLRenderingContextBase.DEPTH_TEST);

            gl.Viewport(0, 0, canvasWidth, canvasHeight);

            gl.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W);
            gl.Clear(WebGLRenderingContextBase.COLOR_BUFFER_BIT);
        }
Esempio n. 2
0
        public virtual void Draw()
        {
            gl.Enable(WebGLRenderingContextBase.DEPTH_TEST);
            gl.Viewport(0, 0, canvasWidth, canvasHeight);
            gl.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W);
            gl.Clear(WebGLRenderingContextBase.COLOR_BUFFER_BIT);

            gl.UniformMatrix4fv(pMatrixUniform, false, projectionMatrix.ToArray());
            gl.UniformMatrix4fv(vMatrixUniform, false, viewMatrix.ToArray());
            gl.UniformMatrix4fv(wMatrixUniform, false, worldMatrix.ToArray());
            gl.DrawElements(WebGLRenderingContextBase.TRIANGLES, indices.Length, WebGLRenderingContextBase.UNSIGNED_SHORT, 0);
        }
Esempio n. 3
0
        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;
        }