Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / i810 / i810render.c
1 /*
2  * Intel i810 DRI driver for Mesa 3.5
3  *
4  * Copyright (C) 1999-2000  Keith Whitwell   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL KEITH WHITWELL BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Author:
25  *    Keith Whitwell <keith@tungstengraphics.com>
26  */
27
28
29 /*
30  * Render unclipped vertex buffers by emitting vertices directly to
31  * dma buffers.  Use strip/fan hardware acceleration where possible.
32  *
33  */
34 #include "main/glheader.h"
35 #include "main/context.h"
36 #include "main/macros.h"
37 #include "main/imports.h"
38 #include "main/mtypes.h"
39
40 #include "math/m_xform.h"
41
42 #include "tnl/t_context.h"
43
44 #include "i810screen.h"
45 #include "i810_dri.h"
46
47 #include "i810context.h"
48 #include "i810tris.h"
49 #include "i810vb.h"
50 #include "i810ioctl.h"
51
52 /*
53  * Render unclipped vertex buffers by emitting vertices directly to
54  * dma buffers.  Use strip/fan hardware primitives where possible.
55  * Try to simulate missing primitives with indexed vertices.
56  */
57 #define HAVE_POINTS      0
58 #define HAVE_LINES       1
59 #define HAVE_LINE_STRIPS 1
60 #define HAVE_TRIANGLES   1
61 #define HAVE_TRI_STRIPS  1
62 #define HAVE_TRI_STRIP_1 0      /* has it, template can't use it yet */
63 #define HAVE_TRI_FANS    1
64 #define HAVE_POLYGONS    1
65 #define HAVE_QUADS       0
66 #define HAVE_QUAD_STRIPS 0
67
68 #define HAVE_ELTS        0
69
70
71 static GLuint hw_prim[GL_POLYGON+1] = {
72    0,
73    PR_LINES,
74    0,
75    PR_LINESTRIP,
76    PR_TRIANGLES,
77    PR_TRISTRIP_0,
78    PR_TRIFAN,
79    0,
80    0,
81    PR_POLYGON
82 };
83
84 static const GLenum reduced_prim[GL_POLYGON+1] = {
85    GL_POINTS,
86    GL_LINES,
87    GL_LINES,
88    GL_LINES,
89    GL_TRIANGLES,
90    GL_TRIANGLES,
91    GL_TRIANGLES,
92    GL_TRIANGLES,
93    GL_TRIANGLES,
94    GL_TRIANGLES
95 };
96
97
98
99
100 #define LOCAL_VARS i810ContextPtr imesa = I810_CONTEXT(ctx)
101 #define INIT( prim ) do {                                               \
102    I810_STATECHANGE(imesa, 0);                                          \
103    i810RasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] );       \
104 } while (0)
105 #define GET_CURRENT_VB_MAX_VERTS() \
106   (((int)imesa->vertex_high - (int)imesa->vertex_low) / (imesa->vertex_size*4))
107 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
108   (I810_DMA_BUF_SZ-4) / (imesa->vertex_size * 4)
109
110 #define ALLOC_VERTS( nr ) \
111   i810AllocDmaLow( imesa, (nr) * imesa->vertex_size * 4)
112 #define EMIT_VERTS( ctx, j, nr, buf ) \
113   i810_emit_contiguous_verts(ctx, j, (j)+(nr), buf)
114
115 #define FLUSH()  I810_FIREVERTICES( imesa )
116
117
118 #define TAG(x) i810_##x
119 #include "tnl_dd/t_dd_dmatmp.h"
120
121
122 /**********************************************************************/
123 /*                          Render pipeline stage                     */
124 /**********************************************************************/
125
126
127 static GLboolean i810_run_render( struct gl_context *ctx,
128                                   struct tnl_pipeline_stage *stage )
129 {
130    i810ContextPtr imesa = I810_CONTEXT(ctx);
131    TNLcontext *tnl = TNL_CONTEXT(ctx);
132    struct vertex_buffer *VB = &tnl->vb;
133    GLuint i;
134
135    /* Don't handle clipping or indexed vertices.
136     */
137    if (imesa->RenderIndex != 0 || 
138        !i810_validate_render( ctx, VB )) {
139       return GL_TRUE;
140    }
141
142    imesa->SetupNewInputs = VERT_BIT_POS;
143
144    tnl->Driver.Render.Start( ctx );
145
146    for (i = 0 ; i < VB->PrimitiveCount ; i++)
147    {
148       GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
149       GLuint start = VB->Primitive[i].start;
150       GLuint length = VB->Primitive[i].count;
151
152       if (!length)
153          continue;
154
155       i810_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
156                                                     prim );
157    }
158
159    tnl->Driver.Render.Finish( ctx );
160
161    return GL_FALSE;             /* finished the pipe */
162 }
163
164
165
166 const struct tnl_pipeline_stage _i810_render_stage =
167 {
168    "i810 render",
169    NULL,
170    NULL,
171    NULL,
172    NULL,
173    i810_run_render              /* run */
174 };