Fix problem with initial viewport/scissor size.
authorBrian <brian.paul@tungstengraphics.com>
Wed, 19 Dec 2007 20:45:00 +0000 (13:45 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 19 Dec 2007 20:45:00 +0000 (13:45 -0700)
If an app never called glViewport, the viewport size was always 0 by 0 pixels.
Now pass initial size to st_create_framebuffer() and initialize the viewport
and scissor bounds in st_make_current().
This could also be fixed by ensuring the gl_framebuffers passed to
_mesa_make_current() were initialized to the right size.  But that involves
allocating the renderbuffers/pipe_surfaces earlier and that runs into some
other issues ATM.
Also remove obsolete createRenderbuffers param to st_create_framebuffer().

src/mesa/drivers/dri/intel_winsys/intel_screen.c
src/mesa/pipe/xlib/xm_api.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_framebuffer.c
src/mesa/state_tracker/st_public.h

index bce6c5699a1cd36301608fe7c4c09de62a517c7b..9e31c013a9569af292d340194506099127f98c94 100644 (file)
@@ -297,10 +297,12 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
       else
          stencilFormat = PIPE_FORMAT_NONE;
 
-      intelfb->stfb = st_create_framebuffer(visual, GL_TRUE,
+      intelfb->stfb = st_create_framebuffer(visual,
                                             colorFormat,
                                             depthFormat,
                                             stencilFormat,
+                                            driDrawPriv->w,
+                                            driDrawPriv->h,
                                             (void*) intelfb);
       if (!intelfb->stfb) {
          free(intelfb);
index 186a712b52c3b612937875de66d01267946275ea..ebf4c21eaf604ae45a9a77314e70abb9c580c8c1 100644 (file)
@@ -207,7 +207,7 @@ static GLboolean window_exists( XMesaDisplay *dpy, Window win )
 }
 
 static Status
-get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height )
+get_drawable_size( XMesaDisplay *dpy, Drawable d, uint *width, uint *height )
 {
    Window root;
    Status stat;
@@ -323,6 +323,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
    XMesaBuffer b;
    GLframebuffer *fb;
    enum pipe_format colorFormat, depthFormat, stencilFormat;
+   uint width, height;
 
    ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER);
 
@@ -359,11 +360,14 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
    }
 
 
+   get_drawable_size(vis->display, d, &width, &height);
+
    /*
     * Create framebuffer, but we'll plug in our own renderbuffers below.
     */
-   b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE,
+   b->stfb = st_create_framebuffer(&vis->mesa_visual,
                                    colorFormat, depthFormat, stencilFormat,
+                                   width, height,
                                    (void *) b);
    fb = &b->stfb->Base;
 
index 524e06fb00af6e78081870a7f9f0d6a3a0a59e8b..1d26da474e0ffcd695b7778797a6e2e23f818dda 100644 (file)
@@ -28,6 +28,8 @@
 #include "main/imports.h"
 #include "main/context.h"
 #include "main/extensions.h"
+#include "main/matrix.h"
+#include "main/buffers.h"
 #include "vbo/vbo.h"
 #include "shader/shader_api.h"
 #include "st_public.h"
@@ -163,7 +165,19 @@ void st_make_current(struct st_context *st,
                      struct st_framebuffer *read)
 {
    if (st) {
+      GLboolean firstTime = st->ctx->FirstTimeCurrent;
       _mesa_make_current(st->ctx, &draw->Base, &read->Base);
+      /* Need to initialize viewport here since draw->Base->Width/Height
+       * will still be zero at this point.
+       * This could be improved, but would require rather extensive work
+       * elsewhere (allocate rb surface storage sooner)
+       */
+      if (firstTime) {
+         GLuint w = draw->InitWidth, h = draw->InitHeight;
+         _mesa_set_viewport(st->ctx, 0, 0, w, h);
+         _mesa_set_scissor(st->ctx, 0, 0, w, h);
+
+      }
    }
    else {
       _mesa_make_current(NULL, NULL, NULL);
index c3919d474cfad627d669e9fc9fd723fd9f2fbd85..0f40f3ceee95afdb75bc54a064e27f25c6709cba 100644 (file)
@@ -191,6 +191,7 @@ struct st_framebuffer
 {
    GLframebuffer Base;
    void *Private;
+   GLuint InitWidth, InitHeight;
 };
 
 
index b81a894ef18fffb7e7adebfac302920cf8f750db..5e0943f75cc47494eef596c0f67a3f8b439f7ba9 100644 (file)
 
 struct st_framebuffer *
 st_create_framebuffer( const __GLcontextModes *visual,
-                       boolean createRenderbuffers, /* XXX remove? */
                        enum pipe_format colorFormat,
                        enum pipe_format depthFormat,
                        enum pipe_format stencilFormat,
+                       uint width, uint height,
                        void *private)
 {
    struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer);
    if (stfb) {
       _mesa_initialize_framebuffer(&stfb->Base, visual);
 
-      if (createRenderbuffers) {
-         {
-            /* fake frontbuffer */
-            /* XXX allocation should only happen in the unusual case
-               it's actually needed */
-            struct gl_renderbuffer *rb
-               = st_new_renderbuffer_fb(colorFormat);
-            _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb);
-         }
+      {
+         /* fake frontbuffer */
+         /* XXX allocation should only happen in the unusual case
+            it's actually needed */
+         struct gl_renderbuffer *rb
+            = st_new_renderbuffer_fb(colorFormat);
+         _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb);
+      }
 
-         if (visual->doubleBufferMode) {
-            struct gl_renderbuffer *rb
-               = st_new_renderbuffer_fb(colorFormat);
-            _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb);
-         }
+      if (visual->doubleBufferMode) {
+         struct gl_renderbuffer *rb
+            = st_new_renderbuffer_fb(colorFormat);
+         _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb);
+      }
+
+      if (visual->depthBits == 24 && visual->stencilBits == 8) {
+         /* combined depth/stencil buffer */
+         struct gl_renderbuffer *depthStencilRb
+            = st_new_renderbuffer_fb(depthFormat);
+         /* note: bind RB to two attachment points */
+         _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb);
+         _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb);
+      }
+      else {
+         /* separate depth and/or stencil */
 
-         if (visual->depthBits == 24 && visual->stencilBits == 8) {
-            /* combined depth/stencil buffer */
-            struct gl_renderbuffer *depthStencilRb
+         if (visual->depthBits == 32) {
+            /* 32-bit depth buffer */
+            struct gl_renderbuffer *depthRb
                = st_new_renderbuffer_fb(depthFormat);
-            /* note: bind RB to two attachment points */
-            _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb);
-            _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb);
+            _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
          }
-         else {
-            /* separate depth and/or stencil */
-
-            if (visual->depthBits == 32) {
-               /* 32-bit depth buffer */
-               struct gl_renderbuffer *depthRb
-                  = st_new_renderbuffer_fb(depthFormat);
-               _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
-            }
-            else if (visual->depthBits == 24) {
-               /* 24-bit depth buffer, ignore stencil bits */
-               struct gl_renderbuffer *depthRb
-                  = st_new_renderbuffer_fb(depthFormat);
-               _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
-            }
-            else if (visual->depthBits > 0) {
-               /* 16-bit depth buffer */
-               struct gl_renderbuffer *depthRb
-                  = st_new_renderbuffer_fb(depthFormat);
-               _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
-            }
-
-            if (visual->stencilBits > 0) {
-               /* 8-bit stencil */
-               struct gl_renderbuffer *stencilRb
-                  = st_new_renderbuffer_fb(stencilFormat);
-               _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb);
-            }
+         else if (visual->depthBits == 24) {
+            /* 24-bit depth buffer, ignore stencil bits */
+            struct gl_renderbuffer *depthRb
+               = st_new_renderbuffer_fb(depthFormat);
+            _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
+         }
+         else if (visual->depthBits > 0) {
+            /* 16-bit depth buffer */
+            struct gl_renderbuffer *depthRb
+               = st_new_renderbuffer_fb(depthFormat);
+            _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
          }
 
-         if (visual->accumRedBits > 0) {
-            /* 16-bit/channel accum */
-            struct gl_renderbuffer *accumRb
-               = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM);
-            _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
+         if (visual->stencilBits > 0) {
+            /* 8-bit stencil */
+            struct gl_renderbuffer *stencilRb
+               = st_new_renderbuffer_fb(stencilFormat);
+            _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb);
          }
       }
 
-      stfb->Base.Initialized = GL_TRUE;
+      if (visual->accumRedBits > 0) {
+         /* 16-bit/channel accum */
+         struct gl_renderbuffer *accumRb
+            = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM);
+         _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
+      }
 
+      stfb->Base.Initialized = GL_TRUE;
+      stfb->InitWidth = width;
+      stfb->InitHeight = height;
       stfb->Private = private;
    }
    return stfb;
index 558b20f1e870224dd5a2d9c4ecedfe9ec85d0ca5..ed5ef1f1590fef69380c3eef9fb802508dd04151 100644 (file)
@@ -55,10 +55,10 @@ void st_copy_context_state(struct st_context *dst, struct st_context *src,
                            uint mask);
 
 struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual,
-                                              boolean createRenderbuffers,
                                               enum pipe_format colorFormat,
                                               enum pipe_format depthFormat,
                                               enum pipe_format stencilFormat,
+                                              uint width, uint height,
                                               void *privateData);
 
 void st_resize_framebuffer( struct st_framebuffer *stfb,