예제 #1
0
        public void OnEndScene(Context glImmediateContext, CBackBuffer backBuffer)
        {
            var boundProgram = glPipeline.Program;
            var boundVertexArray = glPipeline.VertexArray;
            var boundTexture = glPipeline.Textures[0];
            var boundSampler = glPipeline.Samplers[0];
            var boundFramebuffer = glPipeline.Framebuffer;

            var boundViewportCount = glPipeline.Viewports.EnabledViewportCount;
            if (tempViewports == null || tempViewports.Length < boundViewportCount)
                tempViewports = new Viewport[boundViewportCount];
            for (int i = 0; i < boundViewportCount; i++)
            {
                var glViewport = glPipeline.Viewports[i];
                tempViewports[i] = new Viewport
                {
                    Left = glViewport.X,
                    Top = glViewport.Y,
                    Width =  glViewport.Width,
                    Height = glViewport.Height,
                    MinDepth = glViewport.Near,
                    MaxDepth = glViewport.Far
                };
            }

            var boundCullFaceEnable = glPipeline.Rasterizer.CullFaceEnable;
            var boundPolyginModeFront = glPipeline.Rasterizer.PolygonModeFront;
            var boundPolygonModeBack = glPipeline.Rasterizer.PolygonModeBack;
            var boundScissorEnable = glPipeline.Rasterizer.ScissorEnable;
            var boundMultisampleEnable = glPipeline.Rasterizer.MultisampleEnable;
            var boundLineSmoothEnable = glPipeline.Rasterizer.LineSmoothEnable;

            var boundDepthTestEnable = glPipeline.DepthStencil.DepthTestEnable;
            var boundDepthMask = glPipeline.DepthStencil.DepthMask;
            var boundStencilTestEnable = glPipeline.DepthStencil.StencilTestEnable;

            var boundBlendEnable = glPipeline.Blend.BlendEnable;
            var boundAlphaToCoverageEnable = glPipeline.Blend.AlphaToCoverageEnable;
            var boundSampleMask = glPipeline.Blend.SampleMask;

            glPipeline.Program = program;
            glPipeline.VertexArray = vertexArray;

            if (backBuffer.Sampling != Sampling.NoMultisampling)
            {
                sourceFramebuffer.AttachTextureImage(glContext, FramebufferAttachmentPoint.Color0, (Texture2DMultisample)backBuffer.GLTexture);
                destinationFramebuffer.AttachTextureImage(glContext, FramebufferAttachmentPoint.Color0, backBuffer.GLResolveTexture, 0);
               glContext.BlitFramebuffer(
                   sourceFramebuffer, 0, 0, backBuffer.Width, backBuffer.Height,
                   destinationFramebuffer, 0, 0, backBuffer.Width, backBuffer.Height,
                   ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
                glPipeline.Textures[0] = backBuffer.GLResolveTexture;
            }
            else
            {
                glPipeline.Textures[0] = backBuffer.GLTexture;
            }

            glPipeline.Samplers[0] = sampler;
            glPipeline.Framebuffer = null;
            glPipeline.Viewports.EnabledViewportCount = 1;
            glPipeline.Viewports[0].Set(backBuffer.Width, backBuffer.Height);

            glPipeline.Rasterizer.CullFaceEnable = false;
            glPipeline.Rasterizer.PolygonModeFront = PolygonMode.Fill;
            glPipeline.Rasterizer.PolygonModeBack = PolygonMode.Fill;
            glPipeline.Rasterizer.ScissorEnable = false;
            glPipeline.Rasterizer.MultisampleEnable = false;
            glPipeline.Rasterizer.LineSmoothEnable = false;

            glPipeline.DepthStencil.DepthTestEnable = false;
            glPipeline.DepthStencil.DepthMask = false;
            glPipeline.DepthStencil.StencilTestEnable = false;

            glPipeline.Blend.BlendEnable = false;
            glPipeline.Blend.AlphaToCoverageEnable = false;
            glPipeline.Blend.SampleMask = 0xffffffff;

            glImmediateContext.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);

            glPipeline.Program = boundProgram;
            glPipeline.VertexArray = boundVertexArray;
            glPipeline.Textures[0] = boundTexture;
            glPipeline.Samplers[0] = boundSampler;
            glPipeline.Framebuffer = boundFramebuffer;

            for (int i = 0; i < boundViewportCount; i++)
            {
                glPipeline.Viewports[i].Set(
                    tempViewports[i].Left, tempViewports[i].Top,
                    tempViewports[i].Width, tempViewports[i].Height,
                    tempViewports[i].MinDepth, tempViewports[i].MaxDepth);
            }
            glPipeline.Viewports.EnabledViewportCount = boundViewportCount;

            glPipeline.Rasterizer.CullFaceEnable = boundCullFaceEnable;
            glPipeline.Rasterizer.PolygonModeFront = boundPolyginModeFront;
            glPipeline.Rasterizer.PolygonModeBack = boundPolygonModeBack;
            glPipeline.Rasterizer.ScissorEnable = boundScissorEnable;
            glPipeline.Rasterizer.MultisampleEnable = boundMultisampleEnable;
            glPipeline.Rasterizer.LineSmoothEnable = boundLineSmoothEnable;

            glPipeline.DepthStencil.DepthTestEnable = boundDepthTestEnable;
            glPipeline.DepthStencil.DepthMask = boundDepthMask;
            glPipeline.DepthStencil.StencilTestEnable = boundStencilTestEnable;

            glPipeline.Blend.BlendEnable = boundBlendEnable;
            glPipeline.Blend.AlphaToCoverageEnable = boundAlphaToCoverageEnable;
            glPipeline.Blend.SampleMask = boundSampleMask;
        }
예제 #2
0
파일: Viewport.cs 프로젝트: Zulkir/Beholder
 public static bool Equals(Viewport v1, Viewport v2)
 {
     return
         v1.Left == v2.Left &&
         v1.Top == v2.Top &&
         v1.Width == v2.Width &&
         v1.Height == v2.Height &&
         v1.MinDepth == v2.MinDepth &&
         v1.MaxDepth == v2.MaxDepth;
 }
예제 #3
0
 public static SharpDX.Viewport Viewport(Viewport bViewport)
 {
     return new SharpDX.Viewport
     {
         X = (int)System.Math.Round(bViewport.Left),
         Y = (int)System.Math.Round(bViewport.Top),
         Width = (int)System.Math.Round(bViewport.Width),
         Height = (int)System.Math.Round(bViewport.Height),
         MinDepth = (int)System.Math.Round(bViewport.MinDepth),
         MaxDepth = (int)System.Math.Round(bViewport.MaxDepth)
     };
 }