コード例 #1
0
        public void RenderToContext(IRenderGuiControl renderControl, float timestamp)
        {
            foreach (var viewport in renderControl.Viewports)
            {
                var offScreen = offScreenContainer.Get(this, viewport, viewport.Width, viewport.Height, MsaaCount, OffscreenTtl);
                for (var i = 0; i < viewport.View.Layers.Count; i++)
                {
                    var layer                 = viewport.View.Layers[i];
                    var isFirstLayer          = i == 0;
                    var isLastLayer           = i == viewport.View.Layers.Count - 1;
                    var sceneRendererSettings = GetSceneRendererSettings(isFirstLayer, true, isLastLayer);
                    var sceneRenderer         = sceneRendererPool.Allocate(sceneRendererSettings);
                    sceneRenderer.Execute(layer.VisibleScene, layer.Camera, offScreen, timestamp, sceneRendererSettings);
                    sceneRendererPool.Return(sceneRenderer);
                }
                glContext.Actions.BlitFramebuffer(offScreen.Framebuffer, null,
                                                  0, 0,
                                                  viewport.Width, viewport.Height,
                                                  viewport.Left, renderControl.Height - viewport.Top,
                                                  viewport.Left + viewport.Width, renderControl.Height - (viewport.Top + viewport.Height),
                                                  ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            }

            glContext.Infra.SwapBuffers();

            // todo: to Update
            offScreenCacheDeathNote.Clear();

            infra.MainThreadDisposer.DisposeOfAll();
        }
コード例 #2
0
        public void Draw(IFramebuffer targetFramebuffer, IRenderbuffer depthStencil)
        {
            infra.GlContext.States.DepthStencil.StencilTestEnable.Set(true);
            infra.GlContext.States.Blend.BlendEnable.Set(false);
            infra.GlContext.States.DepthStencil.DepthMask.Set(false);
            infra.GlContext.States.DepthStencil.DepthTestEnable.Set(false);
            infra.GlContext.States.DepthStencil.Back.StencilWriteMask.Set(0xff);
            infra.GlContext.States.DepthStencil.Front.StencilWriteMask.Set(0xff);
            infra.GlContext.States.Rasterizer.CullFaceEnable.Set(false);

            var offScreen = offScreenContainer.Get(this, depthStencil, depthStencil.Width, depthStencil.Height, depthStencil.Samples, OffScreenTtl);

            drawSpotFramebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.Color0, offScreen.ColorBuffer);
            drawSpotFramebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil);
            drawSpotFramebuffer.ClearColor(0, new Color4(0, 0, 0, 0));
            infra.GlContext.Bindings.Framebuffers.Draw.Set(drawSpotFramebuffer);

            infra.GlContext.Bindings.Program.Set(program);
            infra.GlContext.Bindings.VertexArray.Set(vao);

            SetStencilFunc(StencilFunction.Equal);
            infra.GlContext.Actions.Draw.Arrays(BeginMode.TriangleStrip, 0, 4);
            offScreen.Resolve();
            infra.GlContext.Bindings.Framebuffers.Draw.Set(offScreen.Framebuffer);
            SetStencilFunc(StencilFunction.Always);

            bleedDrawer.Draw(offScreen.ResolvedTex, Common.Numericals.Colors.Color4.Orange);
            offScreen.Resolve();
            infra.GlContext.Bindings.Framebuffers.Draw.Set(targetFramebuffer);
            SetStencilFunc(StencilFunction.Notequal);
            quadDrawer.Draw(offScreen.ResolvedTex);
            //quadDrawer.Draw(Common.Numericals.Colors.Color4.Blue);
            SetStencilFunc(StencilFunction.Always);

            infra.GlContext.States.DepthStencil.StencilTestEnable.Set(false);
            infra.GlContext.States.DepthStencil.DepthMask.Set(true);
            infra.GlContext.States.DepthStencil.DepthTestEnable.Set(true);
        }