示例#1
0
        /// <summary>
        /// Convert a <see cref="SurfaceFormat"/> to an OpenTK.Graphics.ColorFormat.
        /// This is used for setting up the backbuffer format of the OpenGL context.
        /// </summary>
        /// <returns>An OpenTK.Graphics.ColorFormat instance.</returns>
        /// <param name="format">The <see cref="SurfaceFormat"/> to convert.</param>
        internal static ColorFormat GetColorFormat(this RSurfaceFormat format)
        {
            switch (format)
            {
            case RSurfaceFormat.Alpha8:
                return(new ColorFormat(0, 0, 0, 8));

            case RSurfaceFormat.Bgr565:
                return(new ColorFormat(5, 6, 5, 0));

            case RSurfaceFormat.Bgra4444:
                return(new ColorFormat(4, 4, 4, 4));

            case RSurfaceFormat.Bgra5551:
                return(new ColorFormat(5, 5, 5, 1));

            case RSurfaceFormat.Bgr32:
                return(new ColorFormat(8, 8, 8, 0));

            case RSurfaceFormat.Bgra32:
            case RSurfaceFormat.Color:
                return(new ColorFormat(8, 8, 8, 8));

            case RSurfaceFormat.Rgba1010102:
                return(new ColorFormat(10, 10, 10, 2));

            default:
                // Floating point backbuffers formats could be implemented
                // but they are not typically used on the backbuffer. In
                // those cases it is better to create a render target instead.
                throw new NotSupportedException();
            }
        }
示例#2
0
        private void Build(int width, int height, bool mipMap,
                           RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount, bool shared)
        {
            var depth   = 0;
            var stencil = 0;


            BackBuffer = new RTexture2D();
            BackBuffer.Create(width, height, RPixelFormat.Rgba, preferredFormat);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, BackBuffer.Id, 0);



            if (preferredDepthFormat != RDepthFormat.None)
            {
                DepthBuffer = new RTexture2D();

                if (preferredDepthFormat == RDepthFormat.Depth24Stencil8 || preferredDepthFormat == RDepthFormat.Depth32Stencil8)
                {
                    DepthBuffer.CreateDepth(width, height, RPixelFormat.DepthStencil, preferredDepthFormat);
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, TextureTarget.Texture2D, DepthBuffer.Id, 0);
                }
                else
                {
                    DepthBuffer.CreateDepth(width, height, RPixelFormat.DepthComponent, preferredDepthFormat);
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, DepthBuffer.Id, 0);
                }
                REngine.CheckGLError();
            }
            if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("Error creating frame buffer: framebuffer is not complete");
            }
        }
示例#3
0
 public IEnumerable <RDisplayMode> this[RSurfaceFormat format]
 {
     get
     {
         List <RDisplayMode> list = new List <RDisplayMode>();
         foreach (RDisplayMode mode in this.modes)
         {
             //if (mode.Format == format)
             //{
             list.Add(mode);
             //}
         }
         return(list);
     }
 }
示例#4
0
        public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount, bool shared)
        {
            Width              = width;
            Height             = height;
            DepthStencilFormat = preferredDepthFormat;
            SurfaceFormat      = preferredFormat;
            MultiSampleCount   = preferredMultiSampleCount;
            var id = 0;

            GL.GenFramebuffers(1, out id);
            REngine.CheckGLError();
            Id = id;
            Bind();
            Build(width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, shared);
            Unbind();
        }
示例#5
0
        static RenderbufferStorage GetStorageForFormat(RSurfaceFormat surfaceFormat)
        {
            switch (surfaceFormat)
            {
            case RSurfaceFormat.Alpha8:
                return(RenderbufferStorage.Alpha8);

            case RSurfaceFormat.Color:
                return(RenderbufferStorage.Rgba8);

            case RSurfaceFormat.HalfVector4:
            case RSurfaceFormat.HdrBlendable:
                return(RenderbufferStorage.Rgba16f);

            default:
                return(RenderbufferStorage.Rgba8);
            }
        }
示例#6
0
        PixelType GetPixelTypeForSurface(RSurfaceFormat surface)
        {
            switch (surface)
            {
            case RSurfaceFormat.HalfVector2:
            case RSurfaceFormat.HalfVector4:
            case RSurfaceFormat.HalfSingle:
            case RSurfaceFormat.HdrBlendable:
                return(PixelType.HalfFloat);

            case RSurfaceFormat.Single:
            case RSurfaceFormat.Vector2:
            case RSurfaceFormat.Vector4:
                return(PixelType.Float);

            case RSurfaceFormat.Rgba64:
                return(PixelType.UnsignedInt);

            default:
                return(PixelType.UnsignedByte);
            }
        }
示例#7
0
 public void Create(int width, int height, RPixelFormat format, RSurfaceFormat surfaceFormat, bool multisample = false)
 {
     GL.GenTextures(1, out Id);
     if (multisample)
     {
         textureTarget = TextureTarget.Texture2DMultisample;
         GL.BindTexture(TextureTarget.Texture2DMultisample, Id);
         GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.Rgba, width, height, true);
         REngine.CheckGLError();
         CreateProperties(TextureTarget.Texture2DMultisample, true);
         REngine.CheckGLError();
     }
     else
     {
         textureTarget = TextureTarget.Texture2D;
         GL.BindTexture(TextureTarget.Texture2D, Id);
         GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, (PixelFormat)format, GetPixelTypeForSurface(surfaceFormat), IntPtr.Zero);
         REngine.CheckGLError();
         CreateProperties(TextureTarget.Texture2D, false);
         REngine.CheckGLError();
     }
 }
示例#8
0
 public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat)
     : this(width, height, mipMap, preferredFormat, preferredDepthFormat, 0)
 {
 }
示例#9
0
 public RFrameBuffer(int width, int height, bool mipMap, RSurfaceFormat preferredFormat, RDepthFormat preferredDepthFormat, int preferredMultiSampleCount)
     : this(width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, false)
 {
 }