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_util.h"
30 #include "nv04_3d.xml.h"
31 #include "nv04_driver.h"
34 #include "tnl/t_pipeline.h"
35 #include "tnl/t_vertex.h"
37 #define NUM_VERTEX_ATTRS 6
40 swtnl_update_viewport(struct gl_context *ctx)
42 float *viewport = to_nv04_context(ctx)->viewport;
43 struct gl_framebuffer *fb = ctx->DrawBuffer;
45 get_viewport_scale(ctx, viewport);
46 get_viewport_translate(ctx, &viewport[MAT_TX]);
48 /* It wants normalized Z coordinates. */
49 viewport[MAT_SZ] /= fb->_DepthMaxF;
50 viewport[MAT_TZ] /= fb->_DepthMaxF;
54 swtnl_emit_attr(struct gl_context *ctx, struct tnl_attr_map *m, int attr, int emit)
56 TNLcontext *tnl = TNL_CONTEXT(ctx);
58 if (tnl->render_inputs_bitset & BITFIELD64_BIT(attr))
59 *m = (struct tnl_attr_map) {
64 *m = (struct tnl_attr_map) {
66 .offset = _tnl_format_info[emit].attrsize,
71 swtnl_choose_attrs(struct gl_context *ctx)
73 TNLcontext *tnl = TNL_CONTEXT(ctx);
74 struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
75 struct nv04_context *nctx = to_nv04_context(ctx);
76 static struct tnl_attr_map map[NUM_VERTEX_ATTRS];
79 tnl->vb.AttribPtr[VERT_ATTRIB_POS] = tnl->vb.NdcPtr;
81 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT);
82 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA);
83 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR);
84 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_FOG, EMIT_1UB_1F);
85 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX0, EMIT_2F);
86 if (nv04_mtex_engine(fahrenheit))
87 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX1, EMIT_2F);
89 swtnl_update_viewport(ctx);
91 _tnl_install_attrs(ctx, map, n, nctx->viewport, 0);
94 /* TnL renderer entry points */
97 swtnl_start(struct gl_context *ctx)
99 swtnl_choose_attrs(ctx);
103 swtnl_finish(struct gl_context *ctx)
105 FIRE_RING(context_chan(ctx));
109 swtnl_primitive(struct gl_context *ctx, GLenum mode)
114 swtnl_reset_stipple(struct gl_context *ctx)
118 /* Primitive rendering */
120 #define BEGIN_PRIMITIVE(n) \
121 struct nouveau_channel *chan = context_chan(ctx); \
122 struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); \
123 int vertex_len = TNL_CONTEXT(ctx)->clipspace.vertex_size / 4; \
125 if (nv04_mtex_engine(fahrenheit)) \
126 BEGIN_RING(chan, fahrenheit, \
127 NV04_MULTITEX_TRIANGLE_TLMTVERTEX_SX(0), \
130 BEGIN_RING(chan, fahrenheit, \
131 NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0), \
134 #define OUT_VERTEX(i) \
135 OUT_RINGp(chan, _tnl_get_vertex(ctx, i), vertex_len);
137 #define END_PRIMITIVE(draw) \
138 if (nv04_mtex_engine(fahrenheit)) { \
139 BEGIN_RING(chan, fahrenheit, \
140 NV04_MULTITEX_TRIANGLE_DRAWPRIMITIVE(0), 1); \
141 OUT_RING(chan, draw); \
143 BEGIN_RING(chan, fahrenheit, \
144 NV04_TEXTURED_TRIANGLE_DRAWPRIMITIVE(0), 1); \
145 OUT_RING(chan, draw); \
149 swtnl_points(struct gl_context *ctx, GLuint first, GLuint last)
154 swtnl_line(struct gl_context *ctx, GLuint v1, GLuint v2)
159 swtnl_triangle(struct gl_context *ctx, GLuint v1, GLuint v2, GLuint v3)
165 END_PRIMITIVE(0x102);
169 swtnl_quad(struct gl_context *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4)
176 END_PRIMITIVE(0x213103);
179 /* TnL initialization. */
181 nv04_render_init(struct gl_context *ctx)
183 TNLcontext *tnl = TNL_CONTEXT(ctx);
185 tnl->Driver.RunPipeline = _tnl_run_pipeline;
186 tnl->Driver.Render.Interp = _tnl_interp;
187 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
188 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
189 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
190 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
192 tnl->Driver.Render.Start = swtnl_start;
193 tnl->Driver.Render.Finish = swtnl_finish;
194 tnl->Driver.Render.PrimitiveNotify = swtnl_primitive;
195 tnl->Driver.Render.ResetLineStipple = swtnl_reset_stipple;
197 tnl->Driver.Render.Points = swtnl_points;
198 tnl->Driver.Render.Line = swtnl_line;
199 tnl->Driver.Render.Triangle = swtnl_triangle;
200 tnl->Driver.Render.Quad = swtnl_quad;
202 _tnl_need_projected_coords(ctx, GL_TRUE);
203 _tnl_init_vertices(ctx, tnl->vb.Size,
204 NUM_VERTEX_ATTRS * 4 * sizeof(GLfloat));
205 _tnl_allow_pixel_fog(ctx, GL_FALSE);
210 nv04_render_destroy(struct gl_context *ctx)