summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/i965/brw_pipe_fb.c
blob: a90b7c73f69eed44bb3190b719230eb807f72cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "util/u_math.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "util/u_inlines.h"

#include "brw_context.h"

/**
 * called from intelDrawBuffer()
 */
static void brw_set_framebuffer_state( struct pipe_context *pipe, 
				       const struct pipe_framebuffer_state *fb )
{
   struct brw_context *brw = brw_context(pipe);
   unsigned i;

   /* Dimensions:
    */
   if (brw->curr.fb.width != fb->width ||
       brw->curr.fb.height != fb->height) {
      brw->curr.fb.width = fb->width;
      brw->curr.fb.height = fb->height;
      brw->state.dirty.mesa |= PIPE_NEW_FRAMEBUFFER_DIMENSIONS;
   }
   
   /* Z/Stencil
    */
   if (brw->curr.fb.zsbuf != fb->zsbuf) {
      pipe_surface_reference(&brw->curr.fb.zsbuf, fb->zsbuf);
      brw->state.dirty.mesa |= PIPE_NEW_DEPTH_BUFFER;
   }

   /* Color buffers:
    */
   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
      if (brw->curr.fb.cbufs[i] != fb->cbufs[i]) {
	 brw->state.dirty.mesa |= PIPE_NEW_COLOR_BUFFERS;
	 pipe_surface_reference(&brw->curr.fb.cbufs[i], fb->cbufs[i]);
      }
   }
   
   if (brw->curr.fb.nr_cbufs != fb->nr_cbufs) {
      brw->curr.fb.nr_cbufs = MIN2(BRW_MAX_DRAW_BUFFERS, fb->nr_cbufs);
      brw->state.dirty.mesa |= PIPE_NEW_NR_CBUFS;
   }
}


static void brw_set_viewport_state( struct pipe_context *pipe,
				    const struct pipe_viewport_state *viewport )
{
   struct brw_context *brw = brw_context(pipe);

   brw->curr.viewport = *viewport;
   brw->curr.ccv.min_depth = viewport->scale[2] * -1.0 + viewport->translate[2];
   brw->curr.ccv.max_depth = viewport->scale[2] *  1.0 + viewport->translate[2];

   if (0)
      debug_printf("%s depth range %f .. %f\n",
                   __FUNCTION__,
                   brw->curr.ccv.min_depth,
                   brw->curr.ccv.max_depth);

   brw->state.dirty.mesa |= PIPE_NEW_VIEWPORT;
}


void brw_pipe_framebuffer_init( struct brw_context *brw )
{
   brw->base.set_framebuffer_state = brw_set_framebuffer_state;
   brw->base.set_viewport_state = brw_set_viewport_state;
}

void brw_pipe_framebuffer_cleanup( struct brw_context *brw )
{
   struct pipe_framebuffer_state *fb = &brw->curr.fb;
   int i;

   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
      pipe_surface_reference(&fb->cbufs[i], NULL);
   }

   pipe_surface_reference(&fb->zsbuf, NULL);
}