예제 #1
0
        internal void RunIteration(NSTimer timer)
        {
            var curUpdateTime = stopwatch.Elapsed;

            if (prevUpdateTime == TimeSpan.Zero)
            {
                prevUpdateTime = curUpdateTime;
            }
            var t = (curUpdateTime - prevUpdateTime).TotalSeconds;

            updateEventArgs.Time = t;
            OnUpdateFrame(updateEventArgs);
            prevUpdateTime = curUpdateTime;

            gl.BindFramebuffer(All.FramebufferOes, framebuffer);

            var curRenderTime = stopwatch.Elapsed;

            if (prevRenderTime == TimeSpan.Zero)
            {
                prevRenderTime = curRenderTime;
            }
            t = (curRenderTime - prevRenderTime).TotalSeconds;
            renderEventArgs.Time = t;
            OnRenderFrame(renderEventArgs);
            prevRenderTime = curRenderTime;
        }
예제 #2
0
        protected virtual void CreateFrameBuffer()
        {
            AssertValid();
            if (LayerColorFormat == null)
            {
                throw new InvalidOperationException("Set the LayerColorFormat property to an EAGLColorFormat value before calling Run().");
            }

            CAEAGLLayer eaglLayer = (CAEAGLLayer)Layer;

            eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys(
                new NSObject [] { NSNumber.FromBoolean(LayerRetainsBacking), LayerColorFormat },
                new NSObject [] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }
                );
            ConfigureLayer(eaglLayer);

            GraphicsContext = Utilities.CreateGraphicsContext(ContextRenderingApi);
            gl = GLCalls.GetGLCalls(ContextRenderingApi);

            gl.GenFramebuffers(1, ref framebuffer);
            gl.BindFramebuffer(All.FramebufferOes, framebuffer);

            gl.GenRenderbuffers(1, ref renderbuffer);
            gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer);

            if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer))
            {
                throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!");
            }
            gl.FramebufferRenderbuffer(All.FramebufferOes, All.ColorAttachment0Oes, All.RenderbufferOes, renderbuffer);

            Size newSize = new Size(
                (int)Math.Round(eaglLayer.Bounds.Size.Width),
                (int)Math.Round(eaglLayer.Bounds.Size.Height));

            Size = newSize;

            gl.Viewport(0, 0, newSize.Width, newSize.Height);
            gl.Scissor(0, 0, newSize.Width, newSize.Height);

            frameBufferWindow = new WeakReference(Window);
            frameBufferLayer  = new WeakReference(Layer);
        }