Esempio n. 1
0
        void DoUpdate()
        {
            // set context and bind buffers
            EAGLContext.SetCurrentContext(_glContext);
            ThreadContext.Current.GLContext = _glContext.Handle;
            _alContext.MakeCurrent();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _cb);

            // do user time-step
            var time = _link.Timestamp;

            _frame.Time      = time;
            _frame.DeltaTime = _lastTime < 0.0 ? 0f : (float)(time - _lastTime);
            _lastTime        = time;

            if (_loadFrame > 0)
            {
                _frame.DeltaTime = Interval / 60f;
                _loadFrame--;
            }

            if (this.Update != null)
            {
                Update(this, _frame);
            }
            if (this.Render != null)
            {
                Render(this, _frame);
            }

            // present output
            _glContext.PresentRenderBuffer((uint)RenderbufferTarget.Renderbuffer);
        }
Esempio n. 2
0
        public void PresentRenderBufferTest()
        {
            TestRuntime.AssertXcodeVersion(8, 0);

            var obj = new EAGLContext(EAGLRenderingAPI.OpenGLES2);

            Asserts.AreEqual(true, obj.PresentRenderBuffer((int)RenderbufferTarget.Renderbuffer, 0), "PresentRenderBuffer");
            if (TestRuntime.CheckXcodeVersion(8, 3))
            {
                Asserts.AreEqual(true, obj.PresentRenderBuffer((int)RenderbufferTarget.Renderbuffer, 0, EAGLContext.PresentationMode.AtTime), "PresentRenderBufferAtTime");
                Asserts.AreEqual(true, obj.PresentRenderBuffer((int)RenderbufferTarget.Renderbuffer, 0, EAGLContext.PresentationMode.AfterMinimumDuration), "PresentRenderBufferAfterMinimumDuration");
            }
        }
Esempio n. 3
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // create the surface
            if (renderTarget.Width == 0 || renderTarget.Height == 0)
            {
                renderTarget = SKGLDrawable.CreateRenderTarget();
            }
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw on the surface
                DrawInSurface(surface, renderTarget);
                SKDelegate?.DrawInSurface(surface, renderTarget);

                surface.Canvas.Flush();
            }

            // flush the SkiaSharp context to the GL context
            context.Flush();

            // present the GL buffers
            glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
            EAGLContext.SetCurrentContext(null);
        }
Esempio n. 4
0
 public override void SwapBuffers()
 {
     if (!EAGLContext.PresentRenderBuffer((uint)OpenTK.Graphics.ES11.All.RenderbufferOes))
     {
         throw new InvalidOperationException ("EAGLContext.PresentRenderbuffer failed.");
     }
 }
Esempio n. 5
0
 public override void SwapBuffers()
 {
     if (!EAGLContext.PresentRenderBuffer((uint)All.Renderbuffer))
     {
         throw new InvalidOperationException("EAGLContext.PresentRenderbuffer failed.");
     }
 }
Esempio n. 6
0
        void drawView()
        {
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);

            Controller.Draw();

            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer);
            context.PresentRenderBuffer((uint)RenderbufferTarget.Renderbuffer);
        }
Esempio n. 7
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // manage the drawing surface
            if (renderTarget == null || surface == null)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer);
                Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil);
                Gles.glGetIntegerv(Gles.GL_SAMPLES, out var samples);
                var maxSamples = context.GetMaxSurfaceSampleCount(colorType);
                if (samples > maxSamples)
                {
                    samples = maxSamples;
                }
                Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_WIDTH, out var bufferWidth);
                Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_HEIGHT, out var bufferHeight);
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget(bufferWidth, bufferHeight, samples, stencil, glInfo);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp context to the GL context
            surface.Canvas.Flush();
            context.Flush();

            // present the GL buffers
            glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
            EAGLContext.SetCurrentContext(null);
        }
Esempio n. 8
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // manage the drawing surface
            if (renderTarget == null || surface == null)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                renderTarget = SKGLDrawable.CreateRenderTarget(0, 0);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp context to the GL context
            surface.Canvas.Flush();
            context.Flush();

            // present the GL buffers
            glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
            EAGLContext.SetCurrentContext(null);
        }
        private void RenderWithSquareVerticies(float[,] squareVerticies, float[,] textureVerticies)
        {
            // Use Shader Program
            GL.UseProgram(glProgram);

            // Update attribute values
            GL.VertexAttribPointer(ATTRIB_VERTEX, 2, VertexAttribPointerType.Float, false, 0, squareVerticies);
            GL.EnableVertexAttribArray(ATTRIB_VERTEX);

            GL.VertexAttribPointer(ATTRIB_TEXCOORD, 2, VertexAttribPointerType.Float, false, 0, textureVerticies);
            GL.EnableVertexAttribArray(ATTRIB_TEXCOORD);

            // Validate program before drawing. (For Debugging purposes)
#if DEBUG
            GL.ValidateProgram(glProgram);
#endif
            GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);

            // Present
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, colorBuffer);
            context.PresentRenderBuffer((uint)All.Renderbuffer);
        }
Esempio n. 10
0
 public void Present()
 {
     Bind();
     var success = _context.PresentRenderBuffer(GlConsts.GL_RENDERBUFFER);
 }
Esempio n. 11
0
        public void DisplayPixelBuffer(CVPixelBuffer pixelBuffer)
        {
            DrawTextInCorner(pixelBuffer);
            CVReturn error;

            if (pixelBuffer != null)
            {
                int frameWidth  = (int)pixelBuffer.Width;
                int frameHeight = (int)pixelBuffer.Height;

                if (videoTextureCache == null)
                {
                    Console.WriteLine("No video texture cache");
                    return;
                }

                CleanUpTextures();
                CVAttachmentMode attachmentMode;
                var colorAttachments = pixelBuffer.GetAttachment <NSString> (CVImageBuffer.YCbCrMatrixKey, out attachmentMode);

                if (colorAttachments == CVImageBuffer.YCbCrMatrix_ITU_R_601_4)
                {
                    preferredConversion = colorConversion601;
                }
                else
                {
                    preferredConversion = colorConversion709;
                }

                GL.ActiveTexture(TextureUnit.Texture0);
                lumaTexture = videoTextureCache.TextureFromImage(pixelBuffer, true, All.RedExt, frameWidth, frameHeight,
                                                                 All.RedExt, DataType.UnsignedByte, 0, out error);

                if (lumaTexture == null)
                {
                    Console.WriteLine("Error at CVOpenGLESTextureCach.TextureFromImage");
                }

                GL.BindTexture(lumaTexture.Target, lumaTexture.Name);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);

                GL.ActiveTexture(TextureUnit.Texture1);
                chromaTexture = videoTextureCache.TextureFromImage(pixelBuffer, true, All.RgExt, frameWidth / 2, frameHeight / 2,
                                                                   All.RgExt, DataType.UnsignedByte, 1, out error);

                if (chromaTexture == null)
                {
                    Console.WriteLine("Error at CVOpenGLESTextureCach.TextureFromImage");
                }

                GL.BindTexture(chromaTexture.Target, chromaTexture.Name);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferHandle);
                GL.Viewport(0, 0, backingWidth, backingHeight);
            }

            GL.ClearColor(0f, 0f, 0f, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.UseProgram(Program);
            GL.Uniform1(uniforms [(int)UniformIndex.RotationAngle], 0f);
            GL.UniformMatrix3(uniforms [(int)UniformIndex.ColorConversionMatrix], 1, false, preferredConversion);

            CGRect vertexSamplingRect = AVUtilities.WithAspectRatio(Bounds, PresentationRect);

            var normalizedSamplingSize = new CGSize(0f, 0f);
            var cropScaleAmount        = new CGSize(vertexSamplingRect.Width / Bounds.Width, vertexSamplingRect.Height / Bounds.Height);

            if (cropScaleAmount.Width > cropScaleAmount.Height)
            {
                normalizedSamplingSize.Width  = 1f;
                normalizedSamplingSize.Height = cropScaleAmount.Height / cropScaleAmount.Width;
            }
            else
            {
                normalizedSamplingSize.Width  = 1f;
                normalizedSamplingSize.Height = cropScaleAmount.Width / cropScaleAmount.Height;
            }

            float[] quadVertexData =
            {
                -1f * (float)normalizedSamplingSize.Width, -1f * (float)normalizedSamplingSize.Height,
                (float)normalizedSamplingSize.Width,       -1f * (float)normalizedSamplingSize.Height,
                -1f * (float)normalizedSamplingSize.Width, (float)normalizedSamplingSize.Height,
                (float)normalizedSamplingSize.Width,       (float)normalizedSamplingSize.Height,
            };

            GL.VertexAttribPointer((int)AttributeIndex.Vertex, 2, VertexAttribPointerType.Float, false, 0, quadVertexData);
            GL.EnableVertexAttribArray((int)AttributeIndex.Vertex);

            var textureSamplingRect = new CGRect(0, 0, 1, 1);

            float[] quadTextureData =
            {
                (float)textureSamplingRect.GetMinX(), (float)textureSamplingRect.GetMaxY(),
                (float)textureSamplingRect.GetMaxX(), (float)textureSamplingRect.GetMaxY(),
                (float)textureSamplingRect.GetMinX(), (float)textureSamplingRect.GetMinY(),
                (float)textureSamplingRect.GetMaxX(), (float)textureSamplingRect.GetMinY()
            };

            GL.VertexAttribPointer((int)AttributeIndex.TextureCoordinates, 2, VertexAttribPointerType.Float, false, 0, quadTextureData);
            GL.EnableVertexAttribArray((int)AttributeIndex.TextureCoordinates);

            GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, colorBufferHandle);
            context.PresentRenderBuffer((int)RenderbufferTarget.Renderbuffer);
        }