Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="RenderBuffer2D"/> class.
        /// </summary>
        /// <param name="format">A <see cref="RenderBufferFormat"/> value specifying the render buffer's data format.</param>
        /// <param name="width">The render buffer's width in pixels.</param>
        /// <param name="height">The render buffer's height in pixels.</param>
        /// <param name="options">The render buffer's configuration options.</param>
        /// <returns>The instance of <see cref="RenderBuffer2D"/> that was created.</returns>
        public static RenderBuffer2D Create(RenderBufferFormat format, Int32 width, Int32 height, RenderBufferOptions options)
        {
            Contract.EnsureRange(width > 0, "width");
            Contract.EnsureRange(height > 0, "height");

            var uv = UltravioletContext.DemandCurrent();
            return uv.GetFactoryMethod<RenderBuffer2DFactory>()(uv, format, width, height, options);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the OpenGLRenderBuffer2D class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="format">The render buffer's format.</param>
        /// <param name="width">The render buffer's width in pixels.</param>
        /// <param name="height">The render buffer's height in pixels.</param>
        /// <param name="options">The render buffer's configuration options.</param>
        public OpenGLRenderBuffer2D(UltravioletContext uv, RenderBufferFormat format, Int32 width, Int32 height, RenderBufferOptions options)
            : base(uv)
        {
            Contract.EnsureRange(width > 0, nameof(width));
            Contract.EnsureRange(height > 0, nameof(height));

            var isSrgb   = (options & RenderBufferOptions.SrgbColor) == RenderBufferOptions.SrgbColor;
            var isLinear = (options & RenderBufferOptions.LinearColor) == RenderBufferOptions.LinearColor;

            if (isSrgb && isLinear)
            {
                throw new ArgumentException(UltravioletStrings.BuffersCannotHaveMultipleEncodings);
            }

            if ((isSrgb || isLinear) && format != RenderBufferFormat.Color)
            {
                throw new ArgumentException(UltravioletStrings.EncodingSpecifiedForNonColorBuffer);
            }

            var caps        = uv.GetGraphics().Capabilities;
            var srgbEncoded = (isLinear ? false : (isSrgb ? true : uv.Properties.SrgbDefaultForRenderBuffer2D)) && caps.SrgbEncodingEnabled;

            this.format           = format;
            this.width            = width;
            this.height           = height;
            this.immutable        = (options & RenderBufferOptions.ImmutableStorage) == RenderBufferOptions.ImmutableStorage;
            this.willNotBeSampled = (options & RenderBufferOptions.WillNotBeSampled) == RenderBufferOptions.WillNotBeSampled;

            if (willNotBeSampled)
            {
                using (var state = OpenGLState.ScopedCreateRenderbuffer(out renderbuffer))
                {
                    AllocateRenderbufferStorage(width, height);
                }
            }
            else
            {
                switch (format)
                {
                case RenderBufferFormat.Color:
                {
                    var texformat         = OpenGLTextureUtil.GetFormatFromBytesPerPixel(4);
                    var texinternalformat = OpenGLTextureUtil.GetInternalFormatFromBytesPerPixel(4, srgbEncoded);
                    this.texture     = new OpenGLTexture2D(uv, texinternalformat, width, height, texformat, gl.GL_UNSIGNED_BYTE, IntPtr.Zero, immutable, true);
                    this.SrgbEncoded = this.texture.SrgbEncoded;
                }
                break;

                case RenderBufferFormat.Depth24Stencil8:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH24_STENCIL8, width, height, gl.GL_DEPTH_STENCIL, gl.GL_UNSIGNED_INT_24_8, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Depth32:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH_COMPONENT32, width, height, gl.GL_DEPTH_COMPONENT, gl.GL_UNSIGNED_INT, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Depth16:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH_COMPONENT16, width, height, gl.GL_DEPTH_COMPONENT, gl.GL_UNSIGNED_SHORT, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Stencil8:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_STENCIL_INDEX8, width, height, gl.GL_STENCIL, gl.GL_UNSIGNED_INT, IntPtr.Zero, immutable, true);
                    break;

                default:
                    throw new NotSupportedException(nameof(format));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the OpenGLRenderBuffer2D class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="format">The render buffer's format.</param>
        /// <param name="width">The render buffer's width in pixels.</param>
        /// <param name="height">The render buffer's height in pixels.</param>
        /// <param name="options">The render buffer's configuration options.</param>
        public OpenGLRenderBuffer2D(UltravioletContext uv, RenderBufferFormat format, Int32 width, Int32 height, RenderBufferOptions options)
            : base(uv)
        {
            Contract.EnsureRange(width > 0, nameof(width));
            Contract.EnsureRange(height > 0, nameof(height));

            this.format           = format;
            this.width            = width;
            this.height           = height;
            this.immutable        = (options & RenderBufferOptions.ImmutableStorage) == RenderBufferOptions.ImmutableStorage;
            this.willNotBeSampled = (options & RenderBufferOptions.WillNotBeSampled) == RenderBufferOptions.WillNotBeSampled;

            if (willNotBeSampled)
            {
                OpenGLState.CreateRenderbuffer(out renderbuffer);
                AllocateRenderbufferStorage(width, height);
            }
            else
            {
                switch (format)
                {
                case RenderBufferFormat.Color:
                    this.texture = new OpenGLTexture2D(uv, gl.IsGLES2 ? gl.GL_RGBA : gl.GL_RGBA8, width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Depth24Stencil8:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH24_STENCIL8, width, height, gl.GL_DEPTH_STENCIL, gl.GL_UNSIGNED_INT_24_8, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Depth32:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH_COMPONENT32, width, height, gl.GL_DEPTH_COMPONENT, gl.GL_UNSIGNED_INT, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Depth16:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_DEPTH_COMPONENT16, width, height, gl.GL_DEPTH_COMPONENT, gl.GL_UNSIGNED_SHORT, IntPtr.Zero, immutable, true);
                    break;

                case RenderBufferFormat.Stencil8:
                    this.texture = new OpenGLTexture2D(uv, gl.GL_STENCIL_INDEX8, width, height, gl.GL_STENCIL, gl.GL_UNSIGNED_INT, IntPtr.Zero, immutable, true);
                    break;

                default:
                    throw new NotSupportedException(nameof(format));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of the <see cref="RenderBuffer2D"/> class.
        /// </summary>
        /// <param name="format">A <see cref="RenderBufferFormat"/> value specifying the render buffer's data format.</param>
        /// <param name="width">The render buffer's width in pixels.</param>
        /// <param name="height">The render buffer's height in pixels.</param>
        /// <param name="options">The render buffer's configuration options.</param>
        /// <returns>The instance of <see cref="RenderBuffer2D"/> that was created.</returns>
        public static RenderBuffer2D CreateRenderBuffer(RenderBufferFormat format, Int32 width, Int32 height, RenderBufferOptions options = RenderBufferOptions.Default)
        {
            Contract.EnsureRange(width > 0, nameof(width));
            Contract.EnsureRange(height > 0, nameof(height));

            var uv = UltravioletContext.DemandCurrent();

            return(uv.GetFactoryMethod <RenderBuffer2DFactory>()(uv, format, width, height, options));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of the <see cref="RenderBuffer2D"/> that represents a color buffer.
 /// </summary>
 /// <param name="width">The render buffer's width in pixels.</param>
 /// <param name="height">The render buffer's height in pixels.</param>
 /// <param name="options">The render buffer's configuration options.</param>
 /// <returns>The instance of <see cref="RenderBuffer2D"/> that was created.</returns>
 public static RenderBuffer2D CreateRenderBuffer(Int32 width, Int32 height, RenderBufferOptions options = RenderBufferOptions.Default)
 {
     return(CreateRenderBuffer(RenderBufferFormat.Color, width, height, options));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of the <see cref="RenderBuffer2D"/> that represents a color buffer.
 /// </summary>
 /// <param name="width">The render buffer's width in pixels.</param>
 /// <param name="height">The render buffer's height in pixels.</param>
 /// <param name="options">The render buffer's configuration options.</param>
 /// <returns>The instance of <see cref="RenderBuffer2D"/> that was created.</returns>
 public static RenderBuffer2D Create(Int32 width, Int32 height, RenderBufferOptions options)
 {
     return Create(RenderBufferFormat.Color, width, height, options);
 }