Ejemplo n.º 1
0
        protected override void InitializeService()
        {
            if (RenderStack.Graphics.Configuration.canUseFramebufferObject)
            {
                framebuffer = FramebufferFactory.Create(size, size);
                framebuffer.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Red,
                    PixelInternalFormat.Rgb8
                    //PixelInternalFormat.R8
                    //PixelInternalFormat.Rgb32f
                    );
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent24,
                    0
                    );
                framebuffer.Begin();
                framebuffer.Check();
                framebuffer.End();
            }

            camera.Projection.ProjectionType  = ProjectionType.Other;
            camera.Projection.NearParameter.X = 0.01f;
        }
Ejemplo n.º 2
0
        public void RenderT(int px, int py, Camera camera)
        {
            this.px = px;
            this.py = py;
            RenderStack.Graphics.Debug.WriteLine("=== curveTool.RenderT();");

            renderer.Requested.Viewport = framebuffer.Viewport;
            renderer.Requested.Camera   = camera; // sceneManager.Camera;
            renderer.Requested.Material = tMaterial;
            renderer.Requested.Program  = renderer.Requested.Material.Program;

            framebuffer.Begin();
            camera.UpdateFrame();
            camera.UpdateViewport(renderer.Requested.Viewport);

            renderer.BeginScissorMouse(px, py);
            renderer.PartialGLStateResetToDefaults();
            renderer.CurrentGroup = sceneManager.RenderGroup;

            GL.Viewport(
                (int)renderer.Requested.Viewport.X,
                (int)renderer.Requested.Viewport.Y,
                (int)renderer.Requested.Viewport.Width,
                (int)renderer.Requested.Viewport.Height
                );
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.ClearStencil(0);
            GL.Clear(
                ClearBufferMask.ColorBufferBit |
                ClearBufferMask.DepthBufferBit |
                ClearBufferMask.StencilBufferBit
                );
            //  \todo use RenderStates
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            renderer.Requested.MeshMode = MeshMode.PolygonFill;
            foreach (var segment in segments)
            {
                var model = segment.TubeModel;
                renderer.Requested.Mesh     = model.Batch.Mesh;
                renderer.Requested.Material = model.Batch.Material;
                renderer.Requested.Program  = model.Batch.Material.Program;
                renderer.SetFrame(model.Frame);
                renderer.RenderCurrent();
            }
            renderer.EndScissorMouse();

            MouseT = ReadMouseColor();
            framebuffer.End();
        }
Ejemplo n.º 3
0
        public void Render(Matrix4 cameraTransform, Group renderGroup)
        {
            renderer.Requested.Viewport = framebuffer.Viewport;

            framebuffer.Begin();
            framebuffer.Check();

            //  \todo Use render state
            GL.Disable(EnableCap.PolygonOffsetFill);

            Vector3 positionInWorld = cameraTransform.TransformPoint(new Vector3(0.0f, 0.0f, 0.0f));

            camera.Frame.Parent = null;
            camera.Frame.LocalToParent.Set(cameraTransform);
            camera.Frame.LocalToWorld.Set(cameraTransform);
            renderer.Requested.Camera = camera;
            //camera.Frame.UpdateHierarchical();

            GL.Viewport(
                (int)renderer.Requested.Viewport.X,
                (int)renderer.Requested.Viewport.Y,
                (int)renderer.Requested.Viewport.Width,
                (int)renderer.Requested.Viewport.Height
                );
            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            /*GL.ClearStencil(0);
             * GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);*/
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            //Renderer.RenderGroupBasic(Renderer.RenderGroup, Renderer.Programs.Hemispherical, MeshMode.PolygonFill);
            renderer.CurrentGroup       = renderGroup;
            renderer.Requested.Program  = null; // \todo fixme renderer.Programs["EqualArea"];
            renderer.Requested.MeshMode = MeshMode.PolygonFill;
            renderer.RenderGroup();

            framebuffer.End();

            Texture.GenerateMipmap();

            //  Area of disk, radius r :  Pi * r * r     =      edge * edge * 0.25 * Pi
            //  Area of texture        :                        edge * edge
            //
            //  Hemispherical disc covers ~0.78 of the texture.
        }
Ejemplo n.º 4
0
 private void CreateFramebuffers()
 {
     framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.ColorAttachment0,
         //PixelFormat.RedInteger,
         RenderbufferStorage.R16f,
         0
         );
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.DepthAttachment,
         //PixelFormat.DepthComponent,
         RenderbufferStorage.DepthComponent32,
         0
         );
     framebuffer.Begin();
     framebuffer.Check();
     framebuffer.End();
 }
Ejemplo n.º 5
0
        public void CreateWindowSizeResources()
        {
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources()");
            @default = FramebufferFactory.Create(window);

            if (Configuration.gammaCorrect)
            {
                bool sRgbEnable = GL.IsEnabled(EnableCap.FramebufferSrgb);

                linear = FramebufferFactory.Create(window.Width, window.Height);

                int samples = 4;

                linear.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    RenderbufferStorage.Rgb32f,
                    samples
                    );
                linear.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    samples
                    );
                linear.Begin();
                linear.Check();
                linear.End();

                multisampleResolve = FramebufferFactory.Create(window.Width, window.Height);
                multisampleResolve.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    PixelInternalFormat.Rgb32f
                    );
                multisampleResolve.Begin();
                multisampleResolve.Check();
                multisampleResolve.End();
            }
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources() done");
        }
Ejemplo n.º 6
0
        public void Render(StereoMode mode)
        {
#if true
            float[]      offset           = { -1.0f, 1.0f };
            float        stereoSeparation = sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0];
            IFramebuffer framebuffer      = views[0];
            for (int viewIndex = 0; viewIndex < 2; ++viewIndex)
            {
                framebuffer = views[viewIndex];

                renderer.Requested.Camera   = sceneManager.Camera;
                renderer.Requested.Viewport = framebuffer.Viewport;
                framebuffer.Begin();
                //framebufferManager.Default.Begin();

                sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0] = offset[viewIndex] * stereoSeparation;
                mainSceneRenderer.Render(viewIndex);
                framebuffer.End();
            }
            sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0] = stereoSeparation;
#endif

#if true
            Debug.WriteLine("=== Render Stereo Combine");

            renderer.Requested.Viewport = highLevelRenderer.WindowViewport;
            renderer.Requested.Camera   = sceneManager.Camera;
            renderer.RenderCurrentClear();

            highLevelRenderer.Use2DCamera();

            renderer.Requested.Mesh     = quadRenderer.Mesh;
            renderer.Requested.Material = stereoMerge;
            renderer.Requested.Program  = (mode != null && mode.Program != null) ? mode.Program : blend;
            renderer.Requested.MeshMode = MeshMode.PolygonFill;
            renderer.SetFrame(renderer.DefaultFrame);
            renderer.SetTexture("t_left", views[0][FramebufferAttachment.ColorAttachment0]);
            renderer.SetTexture("t_right", views[1][FramebufferAttachment.ColorAttachment0]);
            renderer.RenderCurrent();
#endif
        }
Ejemplo n.º 7
0
        private void ClearShadow(int lightIndex)
        {
            if (
                (RenderStack.Graphics.Configuration.canUseTextureArrays == false) &&
                (lightIndex > 0)
                )
            {
                return;
            }

            IFramebuffer framebuffer = shadow;

            renderer.Requested.Viewport = framebuffer.Viewport;

            var shadowAttachment = example.Renderer.Configuration.hardwareShadowPCF
                ? FramebufferAttachment.DepthAttachment
                : FramebufferAttachment.ColorAttachment0;

            framebuffer.Begin();
            if (
                (RenderStack.Graphics.Configuration.canUseTextureArrays) &&
                (RenderStack.Graphics.Configuration.glslVersion >= 330)
                )
            {
                framebuffer.AttachTextureLayer(shadowAttachment, 0, lightIndex);
            }

            GL.Viewport(
                renderer.Requested.Viewport.X,
                renderer.Requested.Viewport.Y,
                renderer.Requested.Viewport.Width,
                renderer.Requested.Viewport.Height
                );

            renderer.PartialGLStateResetToDefaults();

            GL.Disable(EnableCap.ScissorTest);
            GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
Ejemplo n.º 8
0
        private void CreateFramebuffers()
        {
            if (useFramebuffer == false)
            {
                return;
            }

            framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
            if (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.RedInteger,
                    RenderbufferStorage.R32ui,
                    0
                    );
            }
            else
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.Rgb,
                    RenderbufferStorage.Rgb8,
                    0
                    );
            }
            framebuffer.AttachRenderBuffer(
                FramebufferAttachment.DepthAttachment,
                //PixelFormat.DepthComponent,
                RenderbufferStorage.DepthComponent32,
                0
                );
            framebuffer.Begin();
            framebuffer.Check();
            framebuffer.End();
        }
Ejemplo n.º 9
0
        public void SetLightCount(int n)
        {
            if (n == currentLightCount)
            {
                return;
            }

            currentLightCount = n;

            // \todo if n < currentLightCount ?

            if (RenderStack.Graphics.Configuration.useGl1 == true)
            {
                return;
            }

            if (shadow != null)
            {
                shadow.Dispose();
            }
            shadow = FramebufferFactory.Create(Configuration.shadowResolution, Configuration.shadowResolution);

            if (example.Renderer.Configuration.hardwareShadowPCF)
            {
                shadowAttachment = FramebufferAttachment.DepthAttachment;
                var texture = shadow.AttachTextureArray(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    PixelInternalFormat.DepthComponent,
                    n
                    );
            }
            else
            {
                shadowAttachment = FramebufferAttachment.ColorAttachment0;
                if (
                    (RenderStack.Graphics.Configuration.canUseTextureArrays) &&
                    (RenderStack.Graphics.Configuration.glslVersion >= 330)
                    )
                {
                    shadow.AttachTextureArray(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f,
                        n
                        );
                }
                else
                {
                    shadow.AttachTexture(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f
                        );
                }
                shadow.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    0
                    );
            }
            shadow.Begin();
            shadow.Check();
            shadow.End();

            var noShadow = materialManager.Textures["NoShadow"] = new TextureGL(
                1, 1, PixelFormat.Red, PixelInternalFormat.R16f, n
                );

            System.Single[] whiteData = new System.Single[n];
            for (int i = 0; i < n; ++i)
            {
                whiteData[i] = 1.0f;
            }
            noShadow.Upload(whiteData, 0);
        }
Ejemplo n.º 10
0
        public void Render(int px, int py)
        {
            this.px = px;
            this.py = py;

            RenderStack.Graphics.Debug.WriteLine("=== RenderId");

            bool         first  = true;
            Camera       camera = sceneManager.Camera;
            List <Group> groups = sceneManager.IdGroups;

            if (useFramebuffer && framebuffer != null)
            {
                renderer.Requested.Viewport = framebuffer.Viewport;
                framebuffer.Begin();
            }

            //SetMultisample(false);
            //renderer.BeginScissorMouse(px, py);
            RenderIdBegin();

            renderer.Requested.Camera   = camera;
            renderer.Requested.MeshMode = MeshMode.PolygonFill;
            foreach (var group in groups)
            {
                if (group.Visible == false)
                {
                    continue;
                }

                renderer.CurrentGroup = group;

                if (first)
                {
                    //  First group can skip special processing
                    renderer.Requested.Material = idMaterial;
                    renderer.Requested.Program  = renderer.Requested.Material.Program;
                    first = false;
                }
                else
                {
                    //  Following groups ignore depth from previous groups
                    //  This is done by rendering first all objects in the
                    //  group with depth range (1, 1) and then rendering
                    //  objects in the group normally with depth range (0, 1)
                    renderer.Requested.Material = resetDepth;
                    renderer.Requested.Program  = renderer.Requested.Material.Program;

                    if (
                        RenderStack.Graphics.Configuration.canUseInstancing
                        /* && RenderStack.Graphics.Configuration.canUseBaseVertex */
                        )
                    {
                        //  Instanced code path
                        foreach (var kvp in group.AllInstances.Collection)
                        {
                            var tuple   = kvp.Key;
                            var models2 = kvp.Value;
                            renderer.Requested.Mesh = tuple.Item1;
                            renderer.RenderInstancedPrepare();

                            int i = 0;
                            foreach (var model in models2)
                            {
                                renderer.Models.Floats("model_to_world_matrix").SetI(
                                    i, model.Frame.LocalToWorld.Matrix
                                    );
                                i++;
                                if (i > 49)
                                {
                                    renderer.Models.Sync();
                                    renderer.RenderCurrent(i);
                                    i = 0;
                                }
                            }
                            if (i > 0)
                            {
                                renderer.Models.Sync();

                                if (i > 1)
                                {
                                    renderer.RenderCurrent(i);
                                }
                                else
                                {
                                    renderer.RenderCurrent();
                                }
                            }
                        }
                    }
                    else
                    {
                        //  Non-instanced code path
                        foreach (var model in group.Models)
                        {
                            renderer.Requested.Mesh = model.Batch.Mesh;
                            renderer.SetFrame(model.Frame);
                            renderer.RenderCurrent();
                        }
                    }
                }

                RenderGroupId(group);
            }
            if (RuntimeConfiguration.disableReadPixels == false)
            {
                ReadId();
                ReadDepth();
                FetchDepth();
            }

            if (useFramebuffer && framebuffer != null)
            {
                framebuffer.End();
            }

            //renderer.EndScissorMouse();
            //SetMultisample(true);
        }