Esempio n. 1
0
        public void Sync()
        {
            if (!HasChanges)
            {
                return;
            }
            HasChanges = false;

            if (RendererTexture == null)
            {
                RendererTexture = new RendererTexture(Bitmap, Label);
            }
            else
            {
                if (BitmapChanged)
                {
                    BitmapChanged = false;
                    RendererTexture.SetData(Bitmap);
                    if (AutoDisposeBitmap)
                    {
                        Log.Verbose("Disposing Bitmap for {ObjectLabel}", RendererTexture.ObjectLabel);
                        Bitmap.Dispose();
                        Bitmap = null;
                    }
                }
            }
        }
Esempio n. 2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         RendererTexture?.Dispose();
     }
     RendererTexture = null;
     base.Dispose(disposing);
 }
Esempio n. 3
0
        public override void Init()
        {
            UsePipeline <ForwardRenderPipeline>();

            _shader = new RendererShader("Shaders/skybox.vert", "Shaders/skybox.frag");
            //txt = Texture.LoadCubeMap("Textures/desert-skybox/#.tga");
            txt = RendererTexture.LoadCubeMap("Textures/water-skybox/#.jpg");

            vao = new VertexArrayObject(VertexLayoutDefinition.CreateDefinitionFromVertexStruct <VertexDataPos>().BindToShader(_shader));
            vao.SetData(BufferData.Create(_vertices));
        }
Esempio n. 4
0
        internal override void DoDeallocation()
        {
            if (!HasDeallocation)
            {
                return;
            }

            if (RendererTexture == null)
            {
                return;
            }

            Log.Verbose("Set InternalTexture.Orphaned");

            RendererTexture.Orphaned = true;
            RendererTexture          = null;

            base.DoDeallocation();
        }
Esempio n. 5
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                //GBuffer.Dispose(
                GPosition.Dispose();
                GNormal.Dispose();
                GMaterial.Dispose();
                GAlbedoSpec.Dispose();

                //_DefLightShader.Dispose();
                //_vertices.dis;

                //vao;
                //vbo
            }

            GPosition   = null;
            GNormal     = null;
            GMaterial   = null;
            GAlbedoSpec = null;

            base.Dispose(disposing);
        }
Esempio n. 6
0
        public override void Init()
        {
            var width  = RenderContext.Current.ScreenPixelSize.X;
            var height = RenderContext.Current.ScreenPixelSize.Y;

            GBuffer             = new FrameBuffer(width, height);
            GBuffer.ObjectLabel = nameof(GBuffer);
            //GBuffer.InitNormal();

            // R11fG11fB10f --> rgba16f
            // Warning: R11fG11fB10f has no sign bit!

            GPosition = new RendererTexture(nameof(GPosition), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb16f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GPosition.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GPosition);
            GBuffer.BindTexture(GPosition, FramebufferAttachment.ColorAttachment0);

            GNormal = new RendererTexture(nameof(GNormal), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb16f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GNormal.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GNormal);
            GBuffer.BindTexture(GNormal, FramebufferAttachment.ColorAttachment1);

            GAlbedoSpec = new RendererTexture(nameof(GAlbedoSpec), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GAlbedoSpec.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GAlbedoSpec);
            GBuffer.BindTexture(GAlbedoSpec, FramebufferAttachment.ColorAttachment2);

            GMaterial = new RendererTexture(nameof(GMaterial), TextureTarget.Texture2D, 0, PixelInternalFormat.R11fG11fB10f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GMaterial.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GMaterial);
            GBuffer.BindTexture(GMaterial, FramebufferAttachment.ColorAttachment3);

            GL.DrawBuffers(4, new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment0,
                DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2,
                DrawBuffersEnum.ColorAttachment3,
            });

            // var rboDepth = new RenderBuffer(gBuffer, RenderbufferStorage.DepthComponent, FramebufferAttachment.DepthAttachment);
            // rboDepth.ObjectLabel = nameof(rboDepth);

            // Attach default Forward Depth Buffer to this Framebuffer, so both share the same depth informations.
            var fwPipe = RenderContext.Current.GetPipeline <ForwardRenderPipeline>();

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, fwPipe.FrameBuffer.RenderBuffer.Handle);

            GBuffer.Check();

            _DefLightShader = new RendererShader("Shaders/deferred-shading.vert", "Shaders/deferred-shading.frag", null, false);
            if (Renderer.Current.UseShadows)
            {
                _DefLightShader.SetDefine("USE_SHADOW");
            }
            _DefLightShader.Compile();
            _DefLightShader.SetInt("gPosition", 0);
            _DefLightShader.SetInt("gNormal", 1);
            _DefLightShader.SetInt("gAlbedoSpec", 2);
            _DefLightShader.SetInt("gMaterial", 3);

            vbo = new VertexBufferObject();
            vbo.Create();
            vbo.Bind();

            var layout = VertexLayoutDefinition.CreateDefinitionFromVertexStruct <VertexDataPos2UV>();

            vao = new VertexArrayObject(layout.BindToShader(_DefLightShader), vbo);
            vao.Create();

            vao.SetData(BufferData.Create(_vertices));
        }