Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 35821)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 35822)
@@ -191,4 +191,5 @@
     unsigned char                   numbumpenvmatconsts;
     char                            num_int_consts;
+    const struct wined3d_context    *context;
 };
 
@@ -223,4 +224,5 @@
     char                            need_color_unclamp;
     UINT                            pos_fixup;
+    const struct wined3d_context    *context;
 };
 
@@ -4066,5 +4068,6 @@
 
 /* GL locking is done by the caller */
-static struct arb_ps_compiled_shader *find_arb_pshader(IWineD3DPixelShaderImpl *shader, const struct arb_ps_compile_args *args)
+static struct arb_ps_compiled_shader *find_arb_pshader(IWineD3DPixelShaderImpl *shader, 
+    const struct arb_ps_compile_args *args, const struct wined3d_context *context)
 {
     UINT i;
@@ -4104,5 +4107,6 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if(memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
+        if(shader_data->gl_shaders[i].context==context
+           && memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
             return &shader_data->gl_shaders[i];
         }
@@ -4129,4 +4133,5 @@
     }
 
+    shader_data->gl_shaders[shader_data->num_gl_shaders].context = context;
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
@@ -4161,5 +4166,6 @@
 }
 
-static struct arb_vs_compiled_shader *find_arb_vshader(IWineD3DVertexShaderImpl *shader, const struct arb_vs_compile_args *args)
+static struct arb_vs_compiled_shader *find_arb_vshader(IWineD3DVertexShaderImpl *shader, 
+    const struct arb_vs_compile_args *args, const struct wined3d_context *context)
 {
     UINT i;
@@ -4183,6 +4189,7 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if (vs_args_equal(&shader_data->gl_shaders[i].args, args,
-                use_map, gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]))
+        if (shader_data->gl_shaders[i].context==context
+            && vs_args_equal(&shader_data->gl_shaders[i].args, args,
+                             use_map, gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]))
         {
             return &shader_data->gl_shaders[i];
@@ -4211,4 +4218,5 @@
     }
 
+    shader_data->gl_shaders[shader_data->num_gl_shaders].context = context;
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
@@ -4378,5 +4386,5 @@
         TRACE("Using pixel shader %p\n", This->stateBlock->pixelShader);
         find_arb_ps_compile_args(ps, This->stateBlock, &compile_args);
-        compiled = find_arb_pshader(ps, &compile_args);
+        compiled = find_arb_pshader(ps, &compile_args, context);
         priv->current_fprogram_id = compiled->prgId;
         priv->compiled_fprog = compiled;
@@ -4434,5 +4442,5 @@
         TRACE("Using vertex shader %p\n", This->stateBlock->vertexShader);
         find_arb_vs_compile_args(vs, This->stateBlock, &compile_args);
-        compiled = find_arb_vshader(vs, &compile_args);
+        compiled = find_arb_vshader(vs, &compile_args, context);
         priv->current_vprogram_id = compiled->prgId;
         priv->compiled_vprog = compiled;
@@ -4530,6 +4538,14 @@
             for (i = 0; i < shader_data->num_gl_shaders; ++i)
             {
-                GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
-                checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+                if (shader_data->gl_shaders[i].context==context_get_current())
+                {
+                    GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
+                    checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+                }
+                else
+                {
+                    WARN("Attempting to delete fprog %u created in ctx %p from ctx %p\n", 
+                         shader_data->gl_shaders[i].prgId, shader_data->gl_shaders[i].context, context_get_current());
+                }
             }
             LEAVE_GL();
@@ -4556,6 +4572,14 @@
             for (i = 0; i < shader_data->num_gl_shaders; ++i)
             {
-                GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
-                checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+                if (shader_data->gl_shaders[i].context==context_get_current())
+                {
+                    GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId));
+                    checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader_data->gl_shaders[i].prgId))");
+                }
+                else
+                {
+                    WARN("Attempting to delete vprog %u created in ctx %p from ctx %p\n", 
+                         shader_data->gl_shaders[i].prgId, shader_data->gl_shaders[i].context, context_get_current());
+                }
             }
             LEAVE_GL();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 35821)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 35822)
@@ -126,4 +126,5 @@
     struct ps_compile_args      ps_args;
     UINT                        constant_version;
+    const struct wined3d_context *context;
 #ifdef VBOX_WITH_WDDM
     UINT                        inp2Fixup_info;
@@ -145,8 +146,9 @@
 
 typedef struct {
-    IWineD3DVertexShader        *vshader;
-    IWineD3DPixelShader         *pshader;
-    struct ps_compile_args      ps_args;
-    struct vs_compile_args      vs_args;
+    IWineD3DVertexShader         *vshader;
+    IWineD3DPixelShader          *pshader;
+    struct ps_compile_args       ps_args;
+    struct vs_compile_args       vs_args;
+    const struct wined3d_context *context;
 } glsl_program_key_t;
 
@@ -162,4 +164,5 @@
     struct ps_np2fixup_info         np2fixup;
     GLhandleARB                     prgId;
+    const struct wined3d_context    *context;
 };
 
@@ -174,4 +177,5 @@
     struct vs_compile_args          args;
     GLhandleARB                     prgId;
+    const struct wined3d_context    *context;
 };
 
@@ -3667,4 +3671,5 @@
     key.vs_args = entry->vs_args;
     key.ps_args = entry->ps_args;
+    key.context = entry->context;
 
     if (wine_rb_put(&priv->program_lookup, &key, &entry->program_lookup_entry) == -1)
@@ -3676,5 +3681,5 @@
 static struct glsl_shader_prog_link *get_glsl_program_entry(struct shader_glsl_priv *priv,
         IWineD3DVertexShader *vshader, IWineD3DPixelShader *pshader, struct vs_compile_args *vs_args,
-        struct ps_compile_args *ps_args) {
+        struct ps_compile_args *ps_args, const struct wined3d_context *context) {
     struct wine_rb_entry *entry;
     glsl_program_key_t key;
@@ -3684,4 +3689,5 @@
     key.vs_args = *vs_args;
     key.ps_args = *ps_args;
+    key.context = context;
 
     entry = wine_rb_get(&priv->program_lookup, &key);
@@ -3699,9 +3705,18 @@
     key.vs_args = entry->vs_args;
     key.ps_args = entry->ps_args;
+    key.context = entry->context;
     wine_rb_remove(&priv->program_lookup, &key);
 
-    TRACE("deleting program %u\n", entry->programId);
-    GL_EXTCALL(glDeleteObjectARB(entry->programId));
-    checkGLcall("glDeleteObjectARB");
+    if (context_get_current() == entry->context)
+    {
+        TRACE("deleting program %u\n", entry->programId);
+        GL_EXTCALL(glDeleteObjectARB(entry->programId));
+        checkGLcall("glDeleteObjectARB");
+    }
+    else
+    {
+        WARN("Attempting to delete program %u created in ctx %p from ctx %p\n", entry->programId, entry->context, context_get_current());
+    }
+    
     if (entry->vshader) list_remove(&entry->vshader_entry);
     if (entry->pshader) list_remove(&entry->pshader_entry);
@@ -4252,5 +4267,6 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if(memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
+        if(shader_data->gl_shaders[i].context==context
+           && memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
             if(args->np2_fixup) {
 #ifdef VBOX_WITH_WDDM
@@ -4284,4 +4300,5 @@
     }
 
+    shader_data->gl_shaders[shader_data->num_gl_shaders].context = context;
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
@@ -4338,5 +4355,6 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if(vs_args_equal(&shader_data->gl_shaders[i].args, args, use_map)) {
+        if(shader_data->gl_shaders[i].context==context
+           && vs_args_equal(&shader_data->gl_shaders[i].args, args, use_map)) {
             return shader_data->gl_shaders[i].prgId;
         }
@@ -4364,4 +4382,5 @@
     }
 
+    shader_data->gl_shaders[shader_data->num_gl_shaders].context = context;
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
@@ -4401,5 +4420,5 @@
     if (pshader) find_ps_compile_args((IWineD3DPixelShaderImpl *)pshader, device->stateBlock, &ps_compile_args);
 
-    entry = get_glsl_program_entry(priv, vshader, pshader, &vs_compile_args, &ps_compile_args);
+    entry = get_glsl_program_entry(priv, vshader, pshader, &vs_compile_args, &ps_compile_args, context);
     if (entry) {
         priv->glsl_program = entry;
@@ -4413,4 +4432,5 @@
     /* Create the entry */
     entry = HeapAlloc(GetProcessHeap(), 0, sizeof(struct glsl_shader_prog_link));
+    entry->context = context;
     entry->programId = programId;
     entry->vshader = vshader;
@@ -4812,7 +4832,15 @@
         ENTER_GL();
         for(i = 0; i < shader_data->num_gl_shaders; i++) {
-            TRACE("deleting pshader %u\n", shader_data->gl_shaders[i].prgId);
-            GL_EXTCALL(glDeleteObjectARB(shader_data->gl_shaders[i].prgId));
-            checkGLcall("glDeleteObjectARB");
+            if (shader_data->gl_shaders[i].context==context_get_current())
+            {
+                TRACE("deleting pshader %u\n", shader_data->gl_shaders[i].prgId);
+                GL_EXTCALL(glDeleteObjectARB(shader_data->gl_shaders[i].prgId));
+                checkGLcall("glDeleteObjectARB");
+            }
+            else
+            {
+                WARN("Attempting to delete pshader %u created in ctx %p from ctx %p\n", 
+                     shader_data->gl_shaders[i].prgId, shader_data->gl_shaders[i].context, context_get_current());
+            }
         }
         LEAVE_GL();
@@ -4826,7 +4854,15 @@
         ENTER_GL();
         for(i = 0; i < shader_data->num_gl_shaders; i++) {
-            TRACE("deleting vshader %u\n", shader_data->gl_shaders[i].prgId);
-            GL_EXTCALL(glDeleteObjectARB(shader_data->gl_shaders[i].prgId));
-            checkGLcall("glDeleteObjectARB");
+            if (shader_data->gl_shaders[i].context==context_get_current())
+            {
+                TRACE("deleting vshader %u\n", shader_data->gl_shaders[i].prgId);
+                GL_EXTCALL(glDeleteObjectARB(shader_data->gl_shaders[i].prgId));
+                checkGLcall("glDeleteObjectARB");
+            }
+            else
+            {
+                WARN("Attempting to delete vshader %u created in ctx %p from ctx %p\n", 
+                     shader_data->gl_shaders[i].prgId, shader_data->gl_shaders[i].context, context_get_current());
+            }
         }
         LEAVE_GL();
@@ -4846,4 +4882,7 @@
             const struct glsl_shader_prog_link, program_lookup_entry);
     int cmp;
+
+    if (k->context > prog->context) return 1;
+    else if (k->context < prog->context) return -1;
 
     if (k->vshader > prog->vshader) return 1;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 35821)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 35822)
@@ -709,4 +709,6 @@
 };
 
+struct wined3d_context;
+
 /* Stateblock dependent parameters which have to be hardcoded
  * into the shader code
@@ -736,6 +738,4 @@
     WORD                        swizzle_map;   /* MAX_ATTRIBS, 16 */
 };
-
-struct wined3d_context;
 
 typedef struct {
