st_atom_framebuffer.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Keith Whitwell <keith@tungstengraphics.com>
00031   *   Brian Paul
00032   */
00033  
00034 #include "st_context.h"
00035 #include "st_atom.h"
00036 #include "st_cb_fbo.h"
00037 #include "st_texture.h"
00038 #include "pipe/p_context.h"
00039 #include "pipe/p_inlines.h"
00040 #include "cso_cache/cso_context.h"
00041 
00042 
00043 
00049 static void
00050 update_renderbuffer_surface(struct st_context *st,
00051                             struct st_renderbuffer *strb)
00052 {
00053    struct pipe_screen *screen = st->pipe->screen;
00054    struct pipe_texture *texture = strb->rtt->pt;
00055    int rtt_width = strb->Base.Width;
00056    int rtt_height = strb->Base.Height;
00057 
00058    if (!strb->surface ||
00059        strb->surface->texture != texture ||
00060        strb->surface->width != rtt_width ||
00061        strb->surface->height != rtt_height) {
00062       GLuint level;
00063       /* find matching mipmap level size */
00064       for (level = 0; level <= texture->last_level; level++) {
00065          if (texture->width[level] == rtt_width &&
00066              texture->height[level] == rtt_height) {
00067 
00068             pipe_surface_reference(&strb->surface, NULL);
00069 
00070             strb->surface = screen->get_tex_surface(screen,
00071                                               texture,
00072                                               strb->rtt_face,
00073                                               level,
00074                                               strb->rtt_slice,
00075                                               PIPE_BUFFER_USAGE_GPU_READ |
00076                                               PIPE_BUFFER_USAGE_GPU_WRITE);
00077 #if 0
00078             printf("-- alloc new surface %d x %d into tex %p\n",
00079                    strb->surface->width, strb->surface->height,
00080                    texture);
00081 #endif
00082             break;
00083          }
00084       }
00085    }
00086 }
00087 
00088 
00092 static void
00093 update_framebuffer_state( struct st_context *st )
00094 {
00095    struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
00096    struct gl_framebuffer *fb = st->ctx->DrawBuffer;
00097    struct st_renderbuffer *strb;
00098    GLuint i, j;
00099 
00100    memset(framebuffer, 0, sizeof(*framebuffer));
00101 
00102    framebuffer->width = fb->Width;
00103    framebuffer->height = fb->Height;
00104 
00105    /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/
00106 
00107    /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
00108     * to determine which surfaces to draw to
00109     */
00110    framebuffer->num_cbufs = 0;
00111    for (j = 0; j < MAX_DRAW_BUFFERS; j++) {
00112       for (i = 0; i < fb->_NumColorDrawBuffers[j]; i++) {
00113          strb = st_renderbuffer(fb->_ColorDrawBuffers[j][i]);
00114 
00115          /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/
00116          if (strb->rtt) {
00117             /* rendering to a GL texture, may have to update surface */
00118             update_renderbuffer_surface(st, strb);
00119          }
00120 
00121          if (strb->surface) {
00122             framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface;
00123             framebuffer->num_cbufs++;
00124          }
00125       }
00126    }
00127 
00128    strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
00129    if (strb) {
00130       strb = st_renderbuffer(strb->Base.Wrapped);
00131       if (strb->rtt) {
00132          /* rendering to a GL texture, may have to update surface */
00133          update_renderbuffer_surface(st, strb);
00134       }
00135 
00136       framebuffer->zsbuf = strb->surface;
00137    }
00138    else {
00139       strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
00140       if (strb) {
00141          strb = st_renderbuffer(strb->Base.Wrapped);
00142          assert(strb->surface);
00143          framebuffer->zsbuf = strb->surface;
00144       }
00145    }
00146 
00147    cso_set_framebuffer(st->cso_context, framebuffer);
00148 
00149    if (fb->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_LEFT) {
00150       if (st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) {
00151          /* XXX copy back buf to front? */
00152       }
00153       /* we're assuming we'll really draw to the front buffer */
00154       st->frontbuffer_status = FRONT_STATUS_DIRTY;
00155    }
00156 }
00157 
00158 
00159 const struct st_tracked_state st_update_framebuffer = {
00160    "st_update_framebuffer",                             /* name */
00161    {                                                    /* dirty */
00162       _NEW_BUFFERS,                                     /* mesa */
00163       ST_NEW_FRAMEBUFFER,                               /* st */
00164    },
00165    update_framebuffer_state                             /* update */
00166 };
00167 

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4