Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h	(revision 37613)
@@ -169,7 +169,4 @@
 #endif
 
-    /*@todo add back buffer, depth and fbos and move out of here*/
-    GLvoid *pImage; /*stored front buffer image*/
-
     /** For buffering vertices for selection/feedback */
     /*@{*/
Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h	(revision 37613)
@@ -27,5 +27,5 @@
 #endif
 
-#define SHCROGL_SSM_VERSION 26
+#define SHCROGL_SSM_VERSION 27
 
 #define CR_MAX_WINDOWS 100
Index: /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_buffer.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_buffer.h	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/state/cr_buffer.h	(revision 37613)
@@ -75,4 +75,9 @@
 	GLenum		blendEquation;
 #endif
+
+    GLint       width, height;
+    GLint       storedWidth, storedHeight;
+    GLvoid      *pFrontImg;
+    GLvoid      *pBackImg;
 } CRBufferState;
 
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_buffer.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_buffer.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_buffer.c	(revision 37613)
@@ -16,4 +16,11 @@
     CRBufferBits *bb = &(sb->buffer);
     GLcolorf zero_colorf = {0.0f, 0.0f, 0.0f, 0.0f};
+
+    b->width = 640;
+    b->height = 480;
+    b->storedWidth = 0;
+    b->storedHeight = 0;
+    b->pFrontImg = NULL;
+    b->pBackImg = NULL;
 
     b->depthTest = GL_FALSE;
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_diff.c	(revision 37613)
@@ -8,4 +8,5 @@
 #include "cr_error.h"
 #include "cr_mem.h"
+#include "cr_pixeldata.h"
 
 void crStateDiffContext( CRContext *from, CRContext *to )
@@ -123,7 +124,7 @@
 void crStateApplyFBImage(CRContext *to)
 {
-    if (to->pImage)
+    if (to->buffer.pFrontImg || to->buffer.pBackImg)
     {
-        CRViewportState *pVP = &to->viewport;
+        CRBufferState *pBuf = &to->buffer;
         CRPixelPackState unpack = to->client.unpack;
 
@@ -137,11 +138,67 @@
         diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, 0);
 
-        diff_api.DrawBuffer(GL_FRONT);
-        diff_api.WindowPos2iARB(0, 0);
-        diff_api.DrawPixels(pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, to->pImage);
+        if (to->framebufferobject.drawFB)
+        {
+            diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
+        }
+
+        if (to->bufferobject.unpackBuffer->hwid>0)
+        {
+            diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+        }
+
+        diff_api.Disable(GL_ALPHA_TEST);
+        diff_api.Disable(GL_SCISSOR_TEST);
+        diff_api.Disable(GL_BLEND);
+        diff_api.Disable(GL_COLOR_LOGIC_OP);
+
+        if (pBuf->pFrontImg)
+        {
+            diff_api.DrawBuffer(GL_FRONT);
+            diff_api.WindowPos2iARB(0, 0);
+            diff_api.DrawPixels(pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBuf->pFrontImg);
+            crDebug("Applied %ix%i fb image", pBuf->storedWidth, pBuf->storedHeight);
+            crFree(pBuf->pFrontImg);
+            pBuf->pFrontImg = NULL;
+        }
+
+        if (pBuf->pBackImg)
+        {
+            diff_api.DrawBuffer(GL_BACK);
+            diff_api.WindowPos2iARB(0, 0);
+            diff_api.DrawPixels(pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBuf->pBackImg);
+            crDebug("Applied %ix%i bb image", pBuf->storedWidth, pBuf->storedHeight);
+            crFree(pBuf->pBackImg);
+            pBuf->pBackImg = NULL;
+        }
 
         diff_api.WindowPos3fvARB(to->current.rasterAttrib[VERT_ATTRIB_POS]);
+        if (to->bufferobject.unpackBuffer->hwid>0)
+        {
+            diff_api.BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, to->bufferobject.unpackBuffer->hwid);
+        }
+        if (to->framebufferobject.drawFB)
+        {
+            diff_api.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, to->framebufferobject.drawFB->hwid);
+        }
         diff_api.DrawBuffer(to->framebufferobject.drawFB ? 
                             to->framebufferobject.drawFB->drawbuffer[0] : to->buffer.drawBuffer);
+        if (to->buffer.alphaTest)
+        {
+            diff_api.Enable(GL_ALPHA_TEST);
+        }
+        if (to->viewport.scissorTest)
+        {
+            diff_api.Enable(GL_SCISSOR_TEST);
+        }
+        if (to->buffer.blend)
+        {
+            diff_api.Enable(GL_BLEND);
+        }
+        if (to->buffer.logicOp)
+        {
+            diff_api.Enable(GL_COLOR_LOGIC_OP);
+        }
+
         diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, unpack.skipRows);
         diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, unpack.skipPixels);
@@ -154,9 +211,4 @@
 
         diff_api.Finish();
-
-        crDebug("Applied %ix%i fb image", pVP->viewportW, pVP->viewportH);
-
-        crFree(to->pImage);
-        to->pImage = NULL;
     }
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c	(revision 37613)
@@ -156,6 +156,4 @@
     int node32 = i >> 5;
     int node = i & 0x1f;
-
-    ctx->pImage = NULL;
 
     ctx->id = i;
@@ -276,5 +274,6 @@
     crStateFramebufferObjectDestroy(ctx);
     crStateGLSLDestroy(ctx);
-    if (ctx->pImage) crFree(ctx->pImage);
+    if (ctx->buffer.pFrontImg) crFree(ctx->buffer.pFrontImg);
+    if (ctx->buffer.pBackImg) crFree(ctx->buffer.pBackImg);
     crFree( ctx );
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c	(revision 37613)
@@ -1011,4 +1011,7 @@
     CRASSERT(pContext && pSSM);
 
+    pContext->buffer.storedWidth = pContext->buffer.width;
+    pContext->buffer.storedHeight = pContext->buffer.height;
+
     rc = SSMR3PutMem(pSSM, pContext, sizeof(*pContext));
     AssertRCReturn(rc, rc);
@@ -1283,9 +1286,13 @@
 #endif
 
-    {
-        CRViewportState *pVP = &pContext->viewport;
+    if (pContext->buffer.storedWidth && pContext->buffer.storedHeight)
+    {
+        CRBufferState *pBuf = &pContext->buffer;
         CRPixelPackState packing = pContext->client.pack;
-        GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
-        void *pData = crAlloc(cbData);
+        GLint cbData;
+        void *pData;
+
+        cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pBuf->storedWidth * pBuf->storedHeight;
+        pData = crAlloc(cbData);
 
         if (!pData)
@@ -1303,9 +1310,34 @@
         diff_api.PixelStorei(GL_PACK_LSB_FIRST, 0);
 
+        if (pContext->framebufferobject.readFB)
+        {
+            diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
+        }
+        if (pContext->bufferobject.packBuffer->hwid>0)
+        {
+            diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
+        }
+
         diff_api.ReadBuffer(GL_FRONT);
-        diff_api.ReadPixels(0, 0, pVP->viewportW, pVP->viewportH, GL_RGBA, GL_UNSIGNED_BYTE, pData);
-
+        diff_api.ReadPixels(0, 0, pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pData);
+        rc = SSMR3PutMem(pSSM, pData, cbData);
+        AssertRCReturn(rc, rc);
+
+        diff_api.ReadBuffer(GL_BACK);
+        diff_api.ReadPixels(0, 0, pBuf->storedWidth, pBuf->storedHeight, GL_RGBA, GL_UNSIGNED_BYTE, pData);
+        rc = SSMR3PutMem(pSSM, pData, cbData);
+        AssertRCReturn(rc, rc);
+
+        if (pContext->bufferobject.packBuffer->hwid>0)
+        {
+            diff_api.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pContext->bufferobject.packBuffer->hwid);
+        }
+        if (pContext->framebufferobject.readFB)
+        {
+            diff_api.BindFramebufferEXT(GL_READ_FRAMEBUFFER, pContext->framebufferobject.readFB->hwid);
+        }
         diff_api.ReadBuffer(pContext->framebufferobject.readFB ? 
                             pContext->framebufferobject.readFB->readbuffer : pContext->buffer.readBuffer);
+
         diff_api.PixelStorei(GL_PACK_SKIP_ROWS, packing.skipRows);
         diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, packing.skipPixels);
@@ -1316,7 +1348,4 @@
         diff_api.PixelStorei(GL_PACK_SWAP_BYTES, packing.swapBytes);
         diff_api.PixelStorei(GL_PACK_LSB_FIRST, packing.psLSBFirst);
-
-        rc = SSMR3PutMem(pSSM, pData, cbData);
-        AssertRCReturn(rc, rc);
 
         crFree(pData);
@@ -1989,13 +2018,18 @@
 
 
-    /*Restore front buffer image*/
-    {
-        CRViewportState *pVP = &pContext->viewport;
-        GLint cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pVP->viewportH * pVP->viewportW;
-        void *pData = crAlloc(cbData);
-
+    /*Restore front/back buffer images*/
+    if (pContext->buffer.storedWidth && pContext->buffer.storedHeight)
+    {
+        CRBufferState *pBuf = &pContext->buffer;
+        GLint cbData;
+        void *pData;
+
+        cbData = crPixelSize(GL_RGBA, GL_UNSIGNED_BYTE) * pBuf->storedWidth * pBuf->storedHeight;
+
+        pData = crAlloc(cbData);
         if (!pData)
         {
-            pContext->pImage = NULL;
+            pBuf->pFrontImg = NULL;
+            pBuf->pBackImg = NULL;
             return VERR_NO_MEMORY;
         }
@@ -2004,5 +2038,17 @@
         AssertRCReturn(rc, rc);
 
-        pContext->pImage = pData;
+        pBuf->pFrontImg = pData;
+
+        pData = crAlloc(cbData);
+        if (!pData)
+        {
+            pBuf->pBackImg = NULL;
+            return VERR_NO_MEMORY;
+        }
+
+        rc = SSMR3GetMem(pSSM, pData, cbData);
+        AssertRCReturn(rc, rc);
+
+        pBuf->pBackImg = pData;
     }
 
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texdiff.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texdiff.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texdiff.c	(revision 37613)
@@ -686,22 +686,25 @@
                             diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
                         }
-                        if (tl->compressed) {
-                            diff_api.CompressedTexImage1DARB(GL_TEXTURE_1D, lvl,
-                                                             tl->internalFormat, tl->width,
-                                                             tl->border, tl->bytes, tl->img);
-                        }
-                        else {
-                            /* alignment must be one */
-                            diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                            if (tl->generateMipmap) {
-                                diff_api.TexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP_SGIS, 1);
+                        if (tl->width)
+                        {
+                            if (tl->compressed) {
+                                diff_api.CompressedTexImage1DARB(GL_TEXTURE_1D, lvl,
+                                                                 tl->internalFormat, tl->width,
+                                                                 tl->border, tl->bytes, tl->img);
                             }
-                            diff_api.TexImage1D(GL_TEXTURE_1D, lvl,
-                                                tl->internalFormat,
-                                                tl->width, tl->border,
-                                                tl->format, tl->type, tl->img);
+                            else {
+                                /* alignment must be one */
+                                diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                                if (tl->generateMipmap) {
+                                    diff_api.TexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP_SGIS, 1);
+                                }
+                                diff_api.TexImage1D(GL_TEXTURE_1D, lvl,
+                                                    tl->internalFormat,
+                                                    tl->width, tl->border,
+                                                    tl->format, tl->type, tl->img);
+                            }
                         }
                         if (!alwaysDirty)
@@ -729,20 +732,23 @@
                         }
 
-                        if (tl->compressed) {
-                            diff_api.CompressedTexImage2DARB(GL_TEXTURE_2D, lvl,
-                                     tl->internalFormat, tl->width,
-                                     tl->height, tl->border,
-                                     tl->bytes, tl->img);
-                        }
-                        else {
-                            /* alignment must be one */
-                            diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                            diff_api.TexImage2D(GL_TEXTURE_2D, lvl,
-                                                tl->internalFormat,
-                                                tl->width, tl->height, tl->border,
-                                                tl->format, tl->type, tl->img);
+                        if (tl->width && tl->height)
+                        {
+                            if (tl->compressed) {
+                                diff_api.CompressedTexImage2DARB(GL_TEXTURE_2D, lvl,
+                                         tl->internalFormat, tl->width,
+                                         tl->height, tl->border,
+                                         tl->bytes, tl->img);
+                            }
+                            else {
+                                /* alignment must be one */
+                                diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                                diff_api.TexImage2D(GL_TEXTURE_2D, lvl,
+                                                    tl->internalFormat,
+                                                    tl->width, tl->height, tl->border,
+                                                    tl->format, tl->type, tl->img);
+                            }
                         }
 
@@ -771,22 +777,27 @@
                             diff_api.TexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP_SGIS, 1);
                         }
-                        if (tl->compressed) {
-                            diff_api.CompressedTexImage3DARB(GL_TEXTURE_3D, lvl,
-                                                             tl->internalFormat, tl->width,
-                                                             tl->height, tl->depth,
-                                                             tl->border, tl->bytes, tl->img);
-                        }
-                        else {
-                            /* alignment must be one */
-                            diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                            diff_api.TexImage3D(GL_TEXTURE_3D, lvl,
-                                                tl->internalFormat,
-                                                tl->width, tl->height, tl->depth,
-                                                tl->border, tl->format,
-                                                tl->type, tl->img);
-                        }
+
+                        if (tl->width && tl->height)
+                        {
+                            if (tl->compressed) {
+                                diff_api.CompressedTexImage3DARB(GL_TEXTURE_3D, lvl,
+                                                                 tl->internalFormat, tl->width,
+                                                                 tl->height, tl->depth,
+                                                                 tl->border, tl->bytes, tl->img);
+                            }
+                            else {
+                                /* alignment must be one */
+                                diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                                diff_api.TexImage3D(GL_TEXTURE_3D, lvl,
+                                                    tl->internalFormat,
+                                                    tl->width, tl->height, tl->depth,
+                                                    tl->border, tl->format,
+                                                    tl->type, tl->img);
+                            }
+                        }
+
                         if (!alwaysDirty)
                         {
@@ -812,21 +823,25 @@
                     if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
                     {
-                        if (tl->compressed) {
-                            diff_api.CompressedTexImage2DARB(GL_TEXTURE_RECTANGLE_NV, lvl,
-                                                             tl->internalFormat, tl->width,
-                                                             tl->height, tl->border,
-                                                             tl->bytes, tl->img);
-                        }
-                        else {
-                            /* alignment must be one */
-                            diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                            diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                            diff_api.TexImage2D(GL_TEXTURE_RECTANGLE_NV, lvl,
-                                                tl->internalFormat,
-                                                tl->width, tl->height, tl->border,
-                                                tl->format, tl->type, tl->img);
-                        }
+                        if (tl->width && tl->height)
+                        {
+                            if (tl->compressed) {
+                                diff_api.CompressedTexImage2DARB(GL_TEXTURE_RECTANGLE_NV, lvl,
+                                                                 tl->internalFormat, tl->width,
+                                                                 tl->height, tl->border,
+                                                                 tl->bytes, tl->img);
+                            }
+                            else {
+                                /* alignment must be one */
+                                diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                                diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                                diff_api.TexImage2D(GL_TEXTURE_RECTANGLE_NV, lvl,
+                                                    tl->internalFormat,
+                                                    tl->width, tl->height, tl->border,
+                                                    tl->format, tl->type, tl->img);
+                            }
+                        }
+
                         if (!alwaysDirty)
                         {
@@ -858,21 +873,26 @@
                                                        GL_GENERATE_MIPMAP_SGIS, 1);
                             }
-                            if (tl->compressed) {
-                                diff_api.CompressedTexImage2DARB(target,
-                                                                 lvl, tl->internalFormat,
-                                                                 tl->width, tl->height,
-                                                                 tl->border, tl->bytes, tl->img);
+
+                            if (tl->width && tl->height)
+                            {
+                                if (tl->compressed) {
+                                    diff_api.CompressedTexImage2DARB(target,
+                                                                     lvl, tl->internalFormat,
+                                                                     tl->width, tl->height,
+                                                                     tl->border, tl->bytes, tl->img);
+                                }
+                                else {
+                                    /* alignment must be one */
+                                    diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+                                    diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+                                    diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+                                    diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+                                    diff_api.TexImage2D(target, lvl,
+                                                        tl->internalFormat,
+                                                        tl->width, tl->height, tl->border,
+                                                        tl->format, tl->type, tl->img);
+                                }
                             }
-                            else {
-                                /* alignment must be one */
-                                diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-                                diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
-                                diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                                diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
-                                diff_api.TexImage2D(target, lvl,
-                                                    tl->internalFormat,
-                                                    tl->width, tl->height, tl->border,
-                                                    tl->format, tl->type, tl->img);
-                            }
+
                             if (!alwaysDirty)
                             {
Index: /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c	(revision 37612)
+++ /trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c	(revision 37613)
@@ -56,14 +56,14 @@
     /* compute max levels from max sizes */
     for (i=0, a=limits->maxTextureSize; a; i++, a=a>>1);
-    t->maxLevel = i;
+    t->maxLevel = i-1;
     for (i=0, a=limits->max3DTextureSize; a; i++, a=a>>1);
-    t->max3DLevel = i;
+    t->max3DLevel = i-1;
 #ifdef CR_ARB_texture_cube_map
     for (i=0, a=limits->maxCubeMapTextureSize; a; i++, a=a>>1);
-    t->maxCubeMapLevel = i;
+    t->maxCubeMapLevel = i-1;
 #endif
 #ifdef CR_NV_texture_rectangle
     for (i=0, a=limits->maxRectTextureSize; a; i++, a=a>>1);
-    t->maxRectLevel = i;
+    t->maxRectLevel = i-1;
 #endif
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_context.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_context.c	(revision 37612)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_context.c	(revision 37613)
@@ -318,4 +318,15 @@
         }
     }
-}
-
+
+    if (!mural->bUseFBO)
+    {
+        ctx->buffer.width = mural->width;
+        ctx->buffer.height = mural->height;
+    }
+    else
+    {
+        ctx->buffer.width = 0;
+        ctx->buffer.height = 0;
+    }
+}
+
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c	(revision 37612)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c	(revision 37613)
@@ -1206,9 +1206,9 @@
             cr_server.curClient = cr_server.clients[i];
             if (cr_server.curClient->currentCtx
-                && cr_server.curClient->currentCtx->pImage
+                && (cr_server.curClient->currentCtx->buffer.pFrontImg || cr_server.curClient->currentCtx->buffer.pBackImg)
                 && cr_server.curClient->currentMural
                 && cr_server.curClient->currentMural->screenId == sIndex
-                && cr_server.curClient->currentCtx->viewport.viewportH == h
-                && cr_server.curClient->currentCtx->viewport.viewportW == w)
+                && cr_server.curClient->currentCtx->buffer.storedHeight == h
+                && cr_server.curClient->currentCtx->buffer.storedWidth == w)
             {
                 int clientWindow = cr_server.curClient->currentWindow;
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c	(revision 37612)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c	(revision 37613)
@@ -230,4 +230,7 @@
             cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, mural->idFBO);
         }
+
+        crStateGetCurrent()->buffer.width = 0;
+        crStateGetCurrent()->buffer.height = 0;
     }
     else
@@ -246,4 +249,7 @@
             }
         }
+
+        crStateGetCurrent()->buffer.width = mural->width;
+        crStateGetCurrent()->buffer.height = mural->height;
     }
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c	(revision 37612)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c	(revision 37613)
@@ -103,4 +103,7 @@
 
         crServerSetupOutputRedirect(mural);
+
+        crStateGetCurrent()->buffer.width = mural->width;
+        crStateGetCurrent()->buffer.height = mural->height;
     }
 
@@ -252,4 +255,7 @@
     mural->height = height;
 
+    crStateGetCurrent()->buffer.width = mural->width;
+    crStateGetCurrent()->buffer.height = mural->height;
+
     crServerCheckMuralGeometry(mural);
 
