Exemplo n.º 1
0
        /// <inheritdoc/>
        protected override void OnLoadingContent()
        {
            var window = Ultraviolet.GetPlatform().Windows.GetPrimary();

            if (!headless)
            {
                // HACK: AMD drivers produce weird rasterization artifacts when rendering
                // to a NPOT render buffer??? So we have to fix it with this stupid hack???
                var width  = MathUtil.FindNextPowerOfTwo(window.DrawableSize.Width);
                var height = MathUtil.FindNextPowerOfTwo(window.DrawableSize.Height);

                rtargetColorBuffer        = Texture2D.CreateRenderBuffer(RenderBufferFormat.Color, width, height);
                rtargetDepthStencilBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Depth24Stencil8, width, height);
                rtarget = RenderTarget2D.Create(width, height);
                rtarget.Attach(rtargetColorBuffer);
                rtarget.Attach(rtargetDepthStencilBuffer);
            }

            if (loader != null)
            {
                content = ContentManager.Create("Content");
                loader(content);
            }

            base.OnLoadingContent();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomCompositor"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="window">The window with which this compositor is associated.</param>
        public CustomCompositor(UltravioletContext uv, IUltravioletWindow window)
            : base(uv, window)
        {
            rtScene = RenderTarget2D.Create(BufferWidth, BufferHeight);

            rtSceneColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight);
            rtScene.Attach(rtSceneColor);

            rtSceneDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight);
            rtScene.Attach(rtSceneDepthStencil);

            rtInterface = RenderTarget2D.Create(BufferWidth, BufferHeight);

            rtInterfaceColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight);
            rtInterface.Attach(rtInterfaceColor);

            rtInterfaceDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight);
            rtInterface.Attach(rtInterfaceDepthStencil);

            rtComposition = RenderTarget2D.Create(BufferWidth, BufferHeight, RenderTargetUsage.PreserveContents);

            rtCompositionColor = RenderBuffer2D.Create(RenderBufferFormat.Color, BufferWidth, BufferHeight);
            rtComposition.Attach(rtCompositionColor);

            rtCompositionDepthStencil = RenderBuffer2D.Create(RenderBufferFormat.Depth24Stencil8, BufferWidth, BufferHeight);
            rtComposition.Attach(rtCompositionDepthStencil);

            spriteBatch = SpriteBatch.Create();
        }
Exemplo n.º 3
0
        protected override void OnLoadingContent()
        {
            this.content = ContentManager.Create("Content");
            LoadContentManifests();

            this.spriteBatch = SpriteBatch.Create();

            // A render target is composed of one or more render buffers. Each render buffer represents a particular
            // output channel from a pixel shader, such as color or depth.
            this.rbufferColor = Texture2D.CreateRenderBuffer(RenderBufferFormat.Color, 256, 256);
            this.rbufferDepth = Texture2D.CreateRenderBuffer(RenderBufferFormat.Depth16, 256, 256);
            this.rtarget      = RenderTarget2D.Create(256, 256);

            // Render buffers must be explicitly attached to a render target before they can be used.
            this.rtarget.Attach(this.rbufferColor);
            this.rtarget.Attach(this.rbufferDepth);

            base.OnLoadingContent();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutOfBandRenderTarget"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        internal OutOfBandRenderTarget(UltravioletContext uv)
            : base(uv)
        {
            renderTarget = RenderTarget2D.Create(1, 1);

            colorBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Color, 1, 1, RenderBufferOptions.SrgbColor);
            renderTarget.Attach(colorBuffer);

            if (uv.GetGraphics().Capabilities.SupportsDepthStencilTextures)
            {
                depthBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Depth24Stencil8, 1, 1, RenderBufferOptions.WillNotBeSampled);
                renderTarget.Attach(depthBuffer);
            }
            else
            {
                depthBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Depth16, 1, 1, RenderBufferOptions.WillNotBeSampled);
                renderTarget.Attach(depthBuffer);

                stencilBuffer = Texture2D.CreateRenderBuffer(RenderBufferFormat.Stencil8, 1, 1, RenderBufferOptions.WillNotBeSampled);
                renderTarget.Attach(stencilBuffer);
            }
        }