コード例 #1
0
        private RenderTarget CreateRenderTarget(Vector2i size, RenderTargetColorFormat colorFormat,
                                                TextureSampleParameters?sampleParameters = null, string name = null)
        {
            // Generate color attachment texture.
            var texture = new OGLHandle(GL.GenTexture());

            GL.BindTexture(TextureTarget.Texture2D, texture.Handle);

            _applySampleParameters(sampleParameters);

            var internalFormat = colorFormat switch
            {
                RenderTargetColorFormat.Rgba8 => PixelInternalFormat.Rgba8,
                RenderTargetColorFormat.Rgba16F => PixelInternalFormat.Rgba16f,
                RenderTargetColorFormat.Rgba8Srgb => PixelInternalFormat.Srgb8Alpha8,
                RenderTargetColorFormat.R11FG11FB10F => PixelInternalFormat.R11fG11fB10f,
                _ => throw new ArgumentOutOfRangeException(nameof(colorFormat), colorFormat, null)
            };

            var(width, height) = size;
            GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, width, height, 0, PixelFormat.Red,
                          PixelType.Byte, IntPtr.Zero);

            // Generate FBO.
            var fbo = new OGLHandle(GL.GenFramebuffer());

            // Cache currently bound framebuffers
            // so if somebody creates a framebuffer while drawing it won't ruin everything.
            var boundDrawBuffer = GL.GetInteger(GetPName.DrawFramebufferBinding);
            var boundReadBuffer = GL.GetInteger(GetPName.ReadFramebufferBinding);

            // Bind color attachment to FBO.
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo.Handle);

            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, texture.Handle,
                                  0);

            // This should always pass but OpenGL makes it easy to check for once so let's.
            var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            DebugTools.Assert(status == FramebufferErrorCode.FramebufferComplete,
                              $"new framebuffer has bad status {status}");

            // Re-bind previous framebuffers.
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, boundDrawBuffer);
            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, boundReadBuffer);

            var textureObject = _genTexture(texture, size, name);
            var handle        = AllocRid();
            var renderTarget  = new RenderTarget(size, textureObject, fbo, this, handle);

            _renderTargets.Add(handle, renderTarget);
            return(renderTarget);
        }
コード例 #2
0
 public IRenderTarget CreateRenderTarget(Vector2i size, RenderTargetColorFormat colorFormat,
                                         TextureSampleParameters?sampleParameters = null, string name = null)
 {
     return(new DummyRenderTarget(size, new DummyTexture(size)));
 }
コード例 #3
0
 IRenderTarget IClyde.CreateRenderTarget(Vector2i size, RenderTargetColorFormat colorFormat,
                                         TextureSampleParameters?sampleParameters, string name)
 {
     return(CreateRenderTarget(size, colorFormat, sampleParameters, name));
 }
コード例 #4
0
 public RenderTargetFormatParameters(RenderTargetColorFormat colorFormat, bool hasDepthStencil = false)
 {
     ColorFormat     = colorFormat;
     HasDepthStencil = hasDepthStencil;
 }