void CadScene::unload()
{
  if (m_geometry.empty()) return;

  glFinish();

  if (GLEW_NV_vertex_buffer_unified_memory){
    if (GLEW_NV_bindless_texture){
      glMakeTextureHandleNonResidentNV(m_matricesTexGLADDR);
    }

    glMakeNamedBufferNonResidentNV(m_matricesGL);
    glMakeNamedBufferNonResidentNV(m_materialsGL);
  }

  glDeleteTextures(1,&m_matricesOrigTexGL);
  glDeleteTextures(1,&m_matricesTexGL);
  glDeleteTextures(1,&m_geometryBboxesTexGL);

  glDeleteBuffers(1,&m_matricesOrigGL);
  glDeleteBuffers(1,&m_matricesGL);
  glDeleteBuffers(1,&m_materialsGL);
  glDeleteBuffers(1,&m_objectAssignsGL);
  glDeleteBuffers(1,&m_geometryBboxesGL);
  glDeleteBuffers(1,&m_parentIDsGL);

  
  for (size_t i = 0 ; i < m_geometry.size(); i++)
  {
    if (m_geometry[i].cloneIdx >= 0) continue;
    
    if (GLEW_NV_vertex_buffer_unified_memory){
      glMakeNamedBufferNonResidentNV(m_geometry[i].iboGL);
      glMakeNamedBufferNonResidentNV(m_geometry[i].vboGL);
    }
    glDeleteBuffers(1,&m_geometry[i].iboGL);
    glDeleteBuffers(1,&m_geometry[i].vboGL);
  }

  m_matrices.clear();
  m_geometryBboxes.clear();
  m_geometry.clear();
  m_objectAssigns.clear();
  m_objects.clear();
  m_geometryBboxes.clear();
  m_nodeTree.clear();

  glFinish();
}
 void makeNonResident() const {
     assert(m_nHandle);
     return glMakeTextureHandleNonResidentNV(m_nHandle);
 }
JNIEXPORT void JNICALL Java_org_lwjgl_opengles_NVBindlessTexture_glMakeTextureHandleNonResidentNV(JNIEnv *__env, jclass clazz, jlong handle) {
    glMakeTextureHandleNonResidentNVPROC glMakeTextureHandleNonResidentNV = (glMakeTextureHandleNonResidentNVPROC)tlsGetFunction(590);
    UNUSED_PARAM(clazz)
    glMakeTextureHandleNonResidentNV(handle);
}