示例#1
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();
        }
        /// <inheritdoc/>
        public override void Attach(RenderBuffer2D buffer)
        {
            Contract.Require(buffer, nameof(buffer));
            Contract.Ensure <ArgumentException>(
                buffer.Width == width &&
                buffer.Height == height, OpenGLStrings.RenderBufferIsWrongSize);
            Contract.EnsureNotDisposed(this, Disposed);

            Ultraviolet.ValidateResource(buffer);

            var oglBuffer = (OpenGLRenderBuffer2D)buffer;

            Ultraviolet.QueueWorkItem(state =>
            {
                using (OpenGLState.ScopedBindFramebuffer(framebuffer))
                {
                    AttachRenderBuffer(oglBuffer);

                    framebufferStatus = gl.CheckNamedFramebufferStatus(framebuffer, gl.GL_FRAMEBUFFER);
                    gl.ThrowIfError();
                }
            }).Wait();

            oglBuffer.MarkAttached();

            buffers.Add(oglBuffer);
        }
示例#3
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.ClientSize.Width);
                var height = MathUtil.FindNextPowerOfTwo(window.ClientSize.Height);

                rtargetColorBuffer        = RenderBuffer2D.Create(RenderBufferFormat.Color, width, height);
                rtargetDepthStencilBuffer = RenderBuffer2D.Create(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();
        }
示例#4
0
        /// <inheritdoc/>
        protected override void OnLoadingContent()
        {
            this.content = ContentManager.Create("Content");
            LoadContentManifests(this.content);
            LoadLocalizationDatabases(this.content);

            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 = RenderBuffer2D.Create(RenderBufferFormat.Color, 256, 256);
            this.rbufferDepth = RenderBuffer2D.Create(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();
        }
示例#5
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 = RenderBuffer2D.Create(RenderBufferFormat.Color, 1, 1, RenderBufferOptions.None);
            renderTarget.Attach(colorBuffer);

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

                stencilBuffer = RenderBuffer2D.Create(RenderBufferFormat.Stencil8, 1, 1, RenderBufferOptions.WillNotBeSampled);
                renderTarget.Attach(stencilBuffer);
            }
        }