00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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
00106
00107
00108
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
00116 if (strb->rtt) {
00117
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
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
00152 }
00153
00154 st->frontbuffer_status = FRONT_STATUS_DIRTY;
00155 }
00156 }
00157
00158
00159 const struct st_tracked_state st_update_framebuffer = {
00160 "st_update_framebuffer",
00161 {
00162 _NEW_BUFFERS,
00163 ST_NEW_FRAMEBUFFER,
00164 },
00165 update_framebuffer_state
00166 };
00167