2 * Copyright (C) 2009-2010 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_class.h"
30 #include "nv10_driver.h"
32 #define NUM_VERTEX_ATTRS 8
35 nv10_emit_material(GLcontext
*ctx
, struct nouveau_array_state
*a
,
38 /* Vertex attribute format. */
39 static struct nouveau_attr_info nv10_vertex_attrs
[VERT_ATTRIB_MAX
] = {
42 .imm_method
= NV10TCL_VERTEX_POS_4F_X
,
45 [VERT_ATTRIB_COLOR0
] = {
47 .imm_method
= NV10TCL_VERTEX_COL_4F_R
,
50 [VERT_ATTRIB_COLOR1
] = {
52 .imm_method
= NV10TCL_VERTEX_COL2_3F_R
,
55 [VERT_ATTRIB_TEX0
] = {
57 .imm_method
= NV10TCL_VERTEX_TX0_4F_S
,
60 [VERT_ATTRIB_TEX1
] = {
62 .imm_method
= NV10TCL_VERTEX_TX1_4F_S
,
65 [VERT_ATTRIB_NORMAL
] = {
67 .imm_method
= NV10TCL_VERTEX_NOR_3F_X
,
72 .imm_method
= NV10TCL_VERTEX_FOG_1F
,
75 [VERT_ATTRIB_GENERIC0
] = {
76 .emit
= nv10_emit_material
,
78 [VERT_ATTRIB_GENERIC2
] = {
79 .emit
= nv10_emit_material
,
81 [VERT_ATTRIB_GENERIC4
] = {
82 .emit
= nv10_emit_material
,
84 [VERT_ATTRIB_GENERIC6
] = {
85 .emit
= nv10_emit_material
,
87 [VERT_ATTRIB_GENERIC8
] = {
88 .emit
= nv10_emit_material
,
93 get_hw_format(int type
)
97 return NV10TCL_VTXFMT_TYPE_FLOAT
;
99 case GL_UNSIGNED_SHORT
:
100 return NV10TCL_VTXFMT_TYPE_SHORT
;
101 case GL_UNSIGNED_BYTE
:
102 return NV10TCL_VTXFMT_TYPE_BYTE_RGBA
;
109 nv10_render_set_format(GLcontext
*ctx
)
111 struct nouveau_render_state
*render
= to_render_state(ctx
);
112 struct nouveau_channel
*chan
= context_chan(ctx
);
113 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
116 for (i
= 0; i
< NUM_VERTEX_ATTRS
; i
++) {
117 int attr
= render
->map
[i
];
120 struct nouveau_array_state
*a
= &render
->attrs
[attr
];
122 hw_format
= a
->stride
<< 8 |
124 get_hw_format(a
->type
);
126 if (attr
== VERT_ATTRIB_POS
&& a
->fields
== 4)
127 hw_format
|= NV10TCL_VTXFMT_POS_HOMOGENEOUS
;
129 /* Unused attribute. */
130 hw_format
= NV10TCL_VTXFMT_TYPE_FLOAT
;
133 BEGIN_RING(chan
, celsius
, NV10TCL_VTXFMT(i
), 1);
134 OUT_RING(chan
, hw_format
);
139 nv10_render_bind_vertices(GLcontext
*ctx
)
141 struct nouveau_render_state
*render
= to_render_state(ctx
);
142 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, VERTEX
);
143 struct nouveau_channel
*chan
= context_chan(ctx
);
144 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
147 for (i
= 0; i
< NUM_VERTEX_ATTRS
; i
++) {
148 int attr
= render
->map
[i
];
151 struct nouveau_array_state
*a
= &render
->attrs
[attr
];
153 nouveau_bo_markl(bctx
, celsius
,
154 NV10TCL_VTXBUF_ADDRESS(i
),
156 NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
160 BEGIN_RING(chan
, celsius
, NV10TCL_VERTEX_ARRAY_VALIDATE
, 1);
164 /* Vertex array rendering defs. */
165 #define RENDER_LOCALS(ctx) \
166 struct nouveau_grobj *celsius = context_eng3d(ctx)
168 #define BATCH_BEGIN(prim) \
169 BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1); \
170 OUT_RING(chan, prim);
171 #define BATCH_END() \
172 BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1); \
175 #define MAX_PACKET 0x400
177 #define MAX_OUT_L 0x100
178 #define BATCH_PACKET_L(n) \
179 BEGIN_RING_NI(chan, celsius, NV10TCL_VERTEX_BUFFER_DRAW_ARRAYS, n);
180 #define BATCH_OUT_L(i, n) \
181 OUT_RING(chan, ((n) - 1) << 24 | (i));
183 #define MAX_OUT_I16 0x2
184 #define BATCH_PACKET_I16(n) \
185 BEGIN_RING_NI(chan, celsius, NV10TCL_VB_ELEMENT_U16, n);
186 #define BATCH_OUT_I16(i0, i1) \
187 OUT_RING(chan, (i1) << 16 | (i0));
189 #define MAX_OUT_I32 0x1
190 #define BATCH_PACKET_I32(n) \
191 BEGIN_RING_NI(chan, celsius, NV10TCL_VB_ELEMENT_U32, n);
192 #define BATCH_OUT_I32(i) \
195 #define IMM_PACKET(m, n) \
196 BEGIN_RING(chan, celsius, m, n);
200 #define TAG(x) nv10_##x
201 #include "nouveau_render_t.c"