示例#1
0
        /// <summary>
        /// Gets called from OpenTK whenever it is time for an update
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void Update(object sender, FrameEventArgs e)
        {
            FrameCounter++;

            MemoryTracer.NextStage("Update Frame: " + FrameCounter);

            MemoryTracer.AddSubStage("Scene Update");
            CurrentScene?.Update((float)e.Time);
            MemoryTracer.NextStage("World Update");
            CurrentScene?.Update((float)e.Time);

            MemoryTracer.NextStage("Physics Update");
            PhysicsEngine.Update((float)e.Time);

            if (_changeScene)
            {
                MemoryTracer.NextStage("Scene Intialization");
                _changeScene = false;


                MemoryTracer.AddSubStage("Removing Old Scene");

                CurrentScene?._Destroy();

                CurrentScene?.DestroyScene(); //Call on destroy on the scene itself.

                MemoryTracer.NextStage("Removing World");

                CurrentScene?.RemoveDestroyedObjects();


                MemoryTracer.NextStage("Create New Scene");

                CurrentScene = (AbstractScene)Activator.CreateInstance(_nextScene);

                MemoryTracer.NextStage("Initialize New Scene");

                CurrentScene._initializeScene();

                MemoryTracer.ReturnFromSubStage();
            }


            //Cleanup
            MemoryTracer.NextStage("Clean up Destroyed Objects");
            CurrentScene?.RemoveDestroyedObjects();
            MemoryTracer.ReturnFromSubStage(); //Returning to root.
            //ResourceManager.ProcessDeleteQueue();
        }
示例#2
0
        /// <summary>
        /// Gets called by opentk when it is time for a render update
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void OnRender(object o, EventArgs e)
        {
            RenderFrameCounter++;

            MemoryTracer.NextStage("Render Frame: " + RenderFrameCounter);

            MemoryTracer.AddSubStage("Rendering Render Targets");

            Renderer.RenderAllTargets(CurrentScene);

            MemoryTracer.NextStage("Swapping Window Buffers");

            Window.SwapBuffers();

            MemoryTracer.ReturnFromSubStage();
        }
示例#3
0
        /// <summary>
        /// merges the targets and draws the results on the back buffer of the OpenGL Window
        /// </summary>
        /// <param name="targets"></param>
        public void MergeAndDisplayTargets(List <RenderTarget> targets)
        {
            if (isDisposed)
            {
                throw new Byt3Exception("Use of Disposed RenderMergeStage");
            }

            if (!_init)
            {
                Init();
            }


            MemoryTracer.AddSubStage("Merge Framebuffers");

            GL.Enable(EnableCap.Blend);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            foreach (RenderTarget renderTarget in targets)
            {
                MemoryTracer.NextStage("Merge Framebuffer: " + renderTarget.PassMask);
                RenderTarget dst = GetTarget();
                RenderTarget src = GetSource();

                if (dst.IsDisposed || src.IsDisposed)
                {
                    throw new Byt3Exception("Use of Disposed RenderMergeStage");
                }

                _mergeTypes[renderTarget.MergeType].Use();

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, dst.FrameBuffer);

                GL.ClearColor(dst.ClearColor);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


                GL.ActiveTexture(TextureUnit.Texture0);
                GL.Uniform1(_mergeTypes[renderTarget.MergeType].GetUniformLocation("destinationTexture"), 0);
                GL.BindTexture(TextureTarget.Texture2D, src.RenderedTexture);

                GL.ActiveTexture(TextureUnit.Texture1);
                GL.Uniform1(_mergeTypes[renderTarget.MergeType].GetUniformLocation("otherTexture"), 1);
                GL.BindTexture(TextureTarget.Texture2D, renderTarget.RenderedTexture);

                GL.BindVertexArray(_screenVao);
                GL.DrawArrays(PrimitiveType.Triangles, 0, 6);


                Ping();
            }

            MemoryTracer.ReturnFromSubStage();

            MemoryTracer.NextStage("Rendering To Screen");
            GL.Disable(EnableCap.Blend);

            Ping();
            DefaultFilepaths.DefaultScreenShader.Use();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            GL.ClearColor(Color.FromArgb(168, 143, 50, 255));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Uniform1(DefaultFilepaths.DefaultScreenShader.GetUniformLocation("sourceTexture"), 0);
            GL.BindTexture(TextureTarget.Texture2D, GetTarget().RenderedTexture);


            GL.BindVertexArray(_screenVao);

            GL.DrawArrays(PrimitiveType.Triangles, 0, 6);

            GL.BindVertexArray(0);
            GL.ActiveTexture(TextureUnit.Texture0);


            //Clear the ping pong buffers after rendering them to the screen
            //For whatever reason GL.Clear is not acting on the active framebuffer
            GL.ClearTexImage(_screenTarget1.RenderedTexture, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
            GL.ClearTexImage(_screenTarget0.RenderedTexture, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);


            GL.Enable(EnableCap.DepthTest);
        }