2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_fbo.h"
30 #include "nouveau_util.h"
31 #include "nouveau_class.h"
32 #include "nv04_driver.h"
34 static inline unsigned
35 get_rt_format(gl_format format
)
38 case MESA_FORMAT_XRGB8888
:
40 case MESA_FORMAT_ARGB8888
:
42 case MESA_FORMAT_RGB565
:
50 nv04_emit_framebuffer(GLcontext
*ctx
, int emit
)
52 struct nouveau_channel
*chan
= context_chan(ctx
);
53 struct nouveau_hw_state
*hw
= &to_nouveau_context(ctx
)->hw
;
54 struct nouveau_grobj
*surf3d
= hw
->surf3d
;
55 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, FRAMEBUFFER
);
56 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
57 struct nouveau_surface
*s
;
58 uint32_t rt_format
= NV04_CONTEXT_SURFACES_3D_FORMAT_TYPE_PITCH
;
59 uint32_t rt_pitch
= 0, zeta_pitch
= 0;
60 unsigned bo_flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
;
62 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
)
66 if (fb
->_NumColorDrawBuffers
) {
67 s
= &to_nouveau_renderbuffer(
68 fb
->_ColorDrawBuffers
[0])->surface
;
70 rt_format
|= get_rt_format(s
->format
);
71 zeta_pitch
= rt_pitch
= s
->pitch
;
73 nouveau_bo_markl(bctx
, surf3d
,
74 NV04_CONTEXT_SURFACES_3D_OFFSET_COLOR
,
79 if (fb
->_DepthBuffer
) {
80 s
= &to_nouveau_renderbuffer(
81 fb
->_DepthBuffer
->Wrapped
)->surface
;
83 zeta_pitch
= s
->pitch
;
85 nouveau_bo_markl(bctx
, surf3d
,
86 NV04_CONTEXT_SURFACES_3D_OFFSET_ZETA
,
90 BEGIN_RING(chan
, surf3d
, NV04_CONTEXT_SURFACES_3D_FORMAT
, 1);
91 OUT_RING(chan
, rt_format
);
92 BEGIN_RING(chan
, surf3d
, NV04_CONTEXT_SURFACES_3D_PITCH
, 1);
93 OUT_RING(chan
, zeta_pitch
<< 16 | rt_pitch
);
95 /* Recompute the scissor state. */
96 context_dirty(ctx
, SCISSOR
);
100 nv04_emit_scissor(GLcontext
*ctx
, int emit
)
102 struct nouveau_channel
*chan
= context_chan(ctx
);
103 struct nouveau_hw_state
*hw
= &to_nouveau_context(ctx
)->hw
;
104 struct nouveau_grobj
*surf3d
= hw
->surf3d
;
107 get_scissors(ctx
->DrawBuffer
, &x
, &y
, &w
, &h
);
109 BEGIN_RING(chan
, surf3d
, NV04_CONTEXT_SURFACES_3D_CLIP_HORIZONTAL
, 2);
110 OUT_RING(chan
, w
<< 16 | x
);
111 OUT_RING(chan
, h
<< 16 | y
);
113 /* Messing with surf3d invalidates some engine state. */
114 context_dirty(ctx
, CONTROL
);
115 context_dirty(ctx
, BLEND
);