Index: trunk/src/VBox/GuestHost/OpenGL/include/cr_bits.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/cr_bits.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/cr_bits.h	(revision 41057)
@@ -65,4 +65,48 @@
 }
 
+static INLINE int CHECKBIT( const unsigned int *b, const unsigned int bit )
+{
+    unsigned int node32 = bit >> 5;
+    unsigned int node = bit & 0x1f;
+
+    return !!(b[node32] & (1 < node));
+}
+
+static INLINE void CLEARBIT( unsigned int *b, const unsigned int bit )
+{
+    unsigned int node32 = bit >> 5;
+    unsigned int node = bit & 0x1f;
+
+    b[node32] &=  ~(1 << node);
+}
+
+static INLINE void SETBIT( unsigned int *b, const unsigned int bit )
+{
+    unsigned int node32 = bit >> 5;
+    unsigned int node = bit & 0x1f;
+
+    b[node32] |=  (1 << node);
+}
+
+static INLINE int HASBITS( const unsigned int *b )
+{
+    int j;
+
+    for (j=0;j<CR_MAX_BITARRAY;j++)
+        if (b[j])
+            return 1;
+
+    return 0;
+}
+
+static INLINE void CLEARBITS( unsigned int *b )
+{
+    int j;
+
+    for (j=0;j<CR_MAX_BITARRAY;j++)
+        b[j] = 0;
+}
+
+
 #ifdef __cplusplus
 }
Index: trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 41057)
@@ -116,4 +116,8 @@
 } CRSharedState;
 
+#define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) (CLEARBITS((_pObj)->ctxUsage))
+#define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) (SETBIT((_pObj)->ctxUsage, (_pCtx)->id))
+#define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (CLEARBIT((_pObj)->ctxUsage, (_pCtx)->id))
+#define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (HASBITS((_pObj)->ctxUsage))
 
 /**
@@ -231,5 +235,5 @@
 typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
 DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM);
-DECLEXPORT(void)    crStateFreeShared(CRSharedState *s);
+DECLEXPORT(void)    crStateFreeShared(CRContext *pContext, CRSharedState *s);
 #endif
 
Index: trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h	(revision 41057)
@@ -31,5 +31,5 @@
 #endif
 
-#define SHCROGL_SSM_VERSION 28
+#define SHCROGL_SSM_VERSION 29
 
 #define CR_MAX_WINDOWS 100
Index: trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h	(revision 41057)
@@ -42,4 +42,8 @@
 	CRbitvalue dirty[CR_MAX_BITARRAY];  /* dirty data or state */
 	GLintptrARB dirtyStart, dirtyLength; /* dirty region */
+#ifndef IN_GUEST
+    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
+    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
+#endif
 } CRBufferObject;
 
Index: trunk/src/VBox/GuestHost/OpenGL/include/state/cr_framebuffer.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/state/cr_framebuffer.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/state/cr_framebuffer.h	(revision 41057)
@@ -49,4 +49,7 @@
 #ifdef IN_GUEST
     GLenum                  status;
+#else
+    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
+    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
 #endif
 } CRFramebufferObject;
@@ -57,4 +60,8 @@
     GLenum   internalformat;
     GLuint   redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits;
+#ifndef IN_GUEST
+    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
+    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
+#endif
 } CRRenderbufferObject;
 
Index: trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h	(revision 40691)
+++ trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h	(revision 41057)
@@ -97,4 +97,8 @@
     CRbitvalue             imageBit[CR_MAX_BITARRAY];
     CRbitvalue             paramsBit[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
+#ifndef IN_GUEST
+    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
+    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
+#endif
 } CRTextureObj;
 
