RenderbufferStorage() private method

private RenderbufferStorage ( UInt32 target, UInt32 internalformat, Int32 width, Int32 height ) : void
target System.UInt32
internalformat System.UInt32
width System.Int32
height System.Int32
return void
Example #1
0
        public unsafe DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats)
            : base(parent)
        {
            try
            {
                uint depthBit = GL.DEPTH_COMPONENT16, stencilBit = 0;
                switch (depthStencilFormats)
                {
                case DepthStencilFormats.Defualt:
                                                #if iOS || ANDROID || NaCl || RPI
                    depthBit   = GL.DEPTH_COMPONENT16;
                    stencilBit = 0;
                                                #else
                    depthBit   = GL.DEPTH_COMPONENT24;
                    stencilBit = 0;
                                                #endif
                    break;

                case DepthStencilFormats.Depth24Stencil8:
                    depthBit   = GL.DEPTH_COMPONENT24;
                    stencilBit = GL.STENCIL_INDEX8;
                    break;

                case DepthStencilFormats.Depth16:
                    depthBit   = GL.DEPTH_COMPONENT16;
                    stencilBit = 0;
                    break;

                case DepthStencilFormats.Depth24:
                    depthBit   = GL.DEPTH_COMPONENT24;
                    stencilBit = 0;
                    break;

                case DepthStencilFormats.Depth32:
                    depthBit   = GL.DEPTH_COMPONENT32;
                    stencilBit = 0;
                    break;

                default:
                    Debug.ThrowError("DepthStencil", "Unsuported DepthStencilFormat type");
                    break;
                }

                Size  = new Size2(width, height);
                SizeF = Size.ToVector2();

                // create depth
                uint surfaceTEMP = 0;
                GL.GenRenderbuffers(1, &surfaceTEMP);
                if (surfaceTEMP == 0)
                {
                    Debug.ThrowError("DpethStencil", "Failed to create DepthBuffer");
                }
                depthBuffer = surfaceTEMP;

                GL.BindRenderbuffer(GL.RENDERBUFFER, depthBuffer);
                GL.RenderbufferStorage(GL.RENDERBUFFER, depthBit, width, height);

                // create stencil
                if (stencilBit != 0)
                {
                    surfaceTEMP = 0;
                    GL.GenRenderbuffers(1, &surfaceTEMP);
                    if (surfaceTEMP == 0)
                    {
                        Debug.ThrowError("DpethStencil", "Failed to create StencilBuffer");
                    }
                    stencilBuffer = surfaceTEMP;

                    GL.BindRenderbuffer(GL.RENDERBUFFER, stencilBuffer);
                    GL.RenderbufferStorage(GL.RENDERBUFFER, stencilBit, width, height);
                }

                uint   error;
                string errorName;
                if (Video.checkForError(out error, out errorName))
                {
                    Debug.ThrowError("DepthStencil", string.Format("{0} {1}: Failed to create DepthStencil", error, errorName));
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }