void EnsureDepthBufferAttachment(GlInterface gl)
        {
            var size = GetPixelSize();

            if (size == _depthBufferSize && _depthBuffer != 0)
            {
                return;
            }

            gl.GetIntegerv(GL_RENDERBUFFER_BINDING, out var oldRenderBuffer);
            if (_depthBuffer != 0)
            {
                gl.DeleteRenderbuffers(1, new[] { _depthBuffer });
            }

            var oneArr = new int[1];

            gl.GenRenderbuffers(1, oneArr);
            _depthBuffer = oneArr[0];
            gl.BindRenderbuffer(GL_RENDERBUFFER, _depthBuffer);
            gl.RenderbufferStorage(GL_RENDERBUFFER,
                                   GlVersion.Type == GlProfileType.OpenGLES ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT,
                                   size.Width, size.Height);
            gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthBuffer);
            gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderBuffer);
        }