void vrend_renderer_resource_destroy(struct vrend_resource *res)
{
   if (has_bit(res->storage_bits, VREND_STORAGE_GL_TEXTURE)) {
      glDeleteTextures(1, &res->id);
   } else if (has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER)) {
      glDeleteBuffers(1, &res->id);
      if (res->tbo_tex_id)
         glDeleteTextures(1, &res->tbo_tex_id);
   } else if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) {
      free(res->ptr);
   }

   if (res->rbo_id) {
      glDeleteRenderbuffers(1, &res->rbo_id);
   }

   if (has_bit(res->storage_bits, VREND_STORAGE_GL_MEMOBJ)) {
      glDeleteMemoryObjectsEXT(1, &res->memobj);
   }

#if HAVE_EPOXY_EGL_H
   if (res->egl_image) {
      virgl_egl_image_destroy(egl, res->egl_image);
      for (unsigned i = 0; i < ARRAY_SIZE(res->aux_plane_egl_image); i++) {
         if (res->aux_plane_egl_image[i]) {
            virgl_egl_image_destroy(egl, res->aux_plane_egl_image[i]);
         }
      }
   }
#endif
#ifdef ENABLE_MINIGBM_ALLOCATION
   if (res->gbm_bo)
      gbm_bo_destroy(res->gbm_bo);
#endif

   free(res);
}
void vrend_renderer_resource_destroy(struct vrend_resource *res)
{
   if (has_bit(res->storage_bits, VREND_STORAGE_GL_TEXTURE)) {
      glDeleteTextures(1, &res->id);
   } else if (has_bit(res->storage_bits, VREND_STORAGE_GL_BUFFER)) {
      glDeleteBuffers(1, &res->id);
      if (res->tbo_tex_id)
         glDeleteTextures(1, &res->tbo_tex_id);
   } else if (has_bit(res->storage_bits, VREND_STORAGE_HOST_SYSTEM_MEMORY)) {
      free(res->ptr);
   }

   if (res->rbo_id) {
      glDeleteRenderbuffers(1, &res->rbo_id);
   }

   if (has_bit(res->storage_bits, VREND_STORAGE_GL_MEMOBJ)) {
      glDeleteMemoryObjectsEXT(1, &res->memobj);
   }

#if HAVE_EPOXY_EGL_H
   if (res->egl_image) {
      virgl_egl_image_destroy(egl, res->egl_image);
      for (unsigned i = 0; i < ARRAY_SIZE(res->aux_plane_egl_image); i++) {
         if (res->aux_plane_egl_image[i]) {
            virgl_egl_image_destroy(egl, res->aux_plane_egl_image[i]);
         }
      }
   }
#endif
#ifdef ENABLE_MINIGBM_ALLOCATION
   if (res->gbm_bo)
      gbm_bo_destroy(res->gbm_bo);
#endif

   free(res);
}