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 "nv04_3d.xml.h"
32 #include "nv04_driver.h"
34 static inline unsigned
35 get_rt_format(mesa_format format
)
38 case MESA_FORMAT_B8G8R8X8_UNORM
:
39 return NV04_CONTEXT_SURFACES_3D_FORMAT_COLOR_X8R8G8B8_X8R8G8B8
;
40 case MESA_FORMAT_B8G8R8A8_UNORM
:
41 return NV04_CONTEXT_SURFACES_3D_FORMAT_COLOR_A8R8G8B8
;
42 case MESA_FORMAT_B5G6R5_UNORM
:
43 return NV04_CONTEXT_SURFACES_3D_FORMAT_COLOR_R5G6B5
;
50 nv04_emit_framebuffer(struct gl_context
*ctx
, int emit
)
52 struct nouveau_pushbuf
*push
= context_push(ctx
);
53 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
54 struct nouveau_surface
*s
;
55 uint32_t rt_format
= NV04_CONTEXT_SURFACES_3D_FORMAT_TYPE_PITCH
;
56 uint32_t rt_pitch
= 0, zeta_pitch
= 0;
57 unsigned bo_flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
;
59 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
)
62 PUSH_RESET(push
, BUFCTX_FB
);
65 if (fb
->_ColorDrawBuffers
[0]) {
66 s
= &to_nouveau_renderbuffer(
67 fb
->_ColorDrawBuffers
[0])->surface
;
69 rt_format
|= get_rt_format(s
->format
);
70 zeta_pitch
= rt_pitch
= s
->pitch
;
72 BEGIN_NV04(push
, NV04_SF3D(OFFSET_COLOR
), 1);
73 PUSH_MTHDl(push
, NV04_SF3D(OFFSET_COLOR
), BUFCTX_FB
,
78 if (fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
) {
79 s
= &to_nouveau_renderbuffer(
80 fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
)->surface
;
82 zeta_pitch
= s
->pitch
;
84 BEGIN_NV04(push
, NV04_SF3D(OFFSET_ZETA
), 1);
85 PUSH_MTHDl(push
, NV04_SF3D(OFFSET_ZETA
), BUFCTX_FB
,
89 BEGIN_NV04(push
, NV04_SF3D(FORMAT
), 1);
90 PUSH_DATA (push
, rt_format
);
91 BEGIN_NV04(push
, NV04_SF3D(PITCH
), 1);
92 PUSH_DATA (push
, zeta_pitch
<< 16 | rt_pitch
);
94 /* Recompute the scissor state. */
95 context_dirty(ctx
, SCISSOR
);
99 nv04_emit_scissor(struct gl_context
*ctx
, int emit
)
101 struct nouveau_pushbuf
*push
= context_push(ctx
);
104 get_scissors(ctx
->DrawBuffer
, &x
, &y
, &w
, &h
);
106 BEGIN_NV04(push
, NV04_SF3D(CLIP_HORIZONTAL
), 2);
107 PUSH_DATA (push
, w
<< 16 | x
);
108 PUSH_DATA (push
, h
<< 16 | y
);