summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/i810/i810tris.c
blob: 1c81b9549b86deab9d01bb1bf905e061948359e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * GLX Hardware Device Driver for Intel i810
 * Copyright (C) 1999 Keith Whitwell
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *
 */

#include <stdio.h>
#include <math.h>

#include "vb.h"
#include "pipeline.h"

#include "mm.h"
#include "i810lib.h"
#include "i810tris.h"
#include "i810vb.h"
#include "i810log.h"
#include "xsmesaP.h"


static void i810_null_quad( GLcontext *ctx, GLuint v0,
			    GLuint v1, GLuint v2, GLuint v3, GLuint pv )
{
}     

static void i810_null_triangle( GLcontext *ctx, GLuint v0,
				GLuint v1, GLuint v2, GLuint pv )
{
}     

static void i810_null_line( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ) 
{
}

static void i810_null_points( GLcontext *ctx, GLuint first, GLuint last ) 
{
}


#define I810_COLOR(to, from) {			\
  (to)[0] = (from)[2];				\
  (to)[1] = (from)[1];				\
  (to)[2] = (from)[0];				\
  (to)[3] = (from)[3];				\
}



static triangle_func tri_tab[0x20];   
static quad_func     quad_tab[0x20];  
static line_func     line_tab[0x20];  
static points_func   points_tab[0x20];

void i810PrintRenderState( const char *msg, GLuint state )
{
   fprintf(stderr, "%s: (%x) %s%s%s%s%s%s\n",
	   msg, state,
	   (state & I810_FLAT_BIT)       ? "flat, "       : "",
	   (state & I810_OFFSET_BIT)     ? "offset, "     : "",
	   (state & I810_TWOSIDE_BIT)    ? "twoside, "    : "",
	   (state & I810_ANTIALIAS_BIT)  ? "antialias, "  : "",
	   (state & I810_NODRAW_BIT)     ? "no-draw, "    : "",
	   (state & I810_FALLBACK_BIT)   ? "fallback"     : "");
}

#define IND (0)
#define TAG(x) x
#include "i810tritmp.h"

#define IND (I810_FLAT_BIT)
#define TAG(x) x##_flat
#include "i810tritmp.h"

#define IND (I810_OFFSET_BIT)
#define TAG(x) x##_offset
#include "i810tritmp.h"

#define IND (I810_OFFSET_BIT|I810_FLAT_BIT)
#define TAG(x) x##_offset_flat
#include "i810tritmp.h"

#define IND (I810_TWOSIDE_BIT)
#define TAG(x) x##_twoside
#include "i810tritmp.h"

#define IND (I810_TWOSIDE_BIT|I810_FLAT_BIT)
#define TAG(x) x##_twoside_flat
#include "i810tritmp.h"

#define IND (I810_TWOSIDE_BIT|I810_OFFSET_BIT)
#define TAG(x) x##_twoside_offset
#include "i810tritmp.h"

#define IND (I810_TWOSIDE_BIT|I810_OFFSET_BIT|I810_FLAT_BIT)
#define TAG(x) x##_twoside_offset_flat
#include "i810tritmp.h"

void i810DDTrifuncInit()
{
   int i;
   init();
   init_flat();
   init_offset();
   init_offset_flat();
   init_twoside();
   init_twoside_flat();
   init_twoside_offset();
   init_twoside_offset_flat();

   /* Hmmm...
    */
   for (i = 0 ; i < 0x20 ; i++) {
      if (i & ~I810_FLAT_BIT) {
	 points_tab[i] = points_tab[i&I810_FLAT_BIT];
	 line_tab[i] = line_tab[i&I810_FLAT_BIT];
      }
   }

   for (i = 0 ; i < 0x20 ; i++) 
      if ((i & (I810_NODRAW_BIT|I810_FALLBACK_BIT)) == I810_NODRAW_BIT ||
	  i810glx.nullprims) 
      {
	 quad_tab[i] = i810_null_quad; 
	 tri_tab[i] = i810_null_triangle; 
	 line_tab[i] = i810_null_line;
	 points_tab[i] = i810_null_points;
      }

   if (i810glx.noFallback) {
      for (i = 0 ; i < 0x10 ; i++) {
	 points_tab[i|I810_FALLBACK_BIT] = points_tab[i];
	 line_tab[i|I810_FALLBACK_BIT] = line_tab[i];
	 tri_tab[i|I810_FALLBACK_BIT] = tri_tab[i];
	 quad_tab[i|I810_FALLBACK_BIT] = quad_tab[i];
      }
   }

}


/* Everything is done via single triangle instructiopns at the moment;
 * this can change fairly easily.
 */
#if I810_USE_BATCH

GLuint *i810AllocPrimitiveVerts( int dwords ) 
{
   GLuint orig_dwords = dwords;

   dwords+=2;
   dwords&=~1;

   while (1) {
      if (i810glx.dma_buffer->space < dwords * 4) 
      {
	 if (I810_DEBUG & DEBUG_VERBOSE_RING)
	    fprintf(stderr, "i810AllocPrimitiveVerts: dma buffer overflow\n");
	 i810DmaOverflow( dwords );
      }
      else
      {
	 GLuint start = i810glx.dma_buffer->head;
	 i810glx.dma_buffer->head += dwords * 4;
	 i810glx.dma_buffer->space -= dwords * 4;

	 if ((orig_dwords & 1) == 0) {
	    *(GLuint *)(i810glx.dma_buffer->virtual_start + start ) = 0;
	    start += 4;
	 }

	 *(GLuint *)(i810glx.dma_buffer->virtual_start + start ) = 
	    GFX_OP_PRIMITIVE | PR_TRIANGLES | (orig_dwords-1);

	 return (GLuint *)(i810glx.dma_buffer->virtual_start + start + 4);
      }
   }
}

#else
GLuint *i810AllocPrimitiveVerts( int dwords ) 
{
   GLuint orig_dwords = dwords;
   
   dwords+=2;
   dwords&=~1;

   while (1)
   {
      BEGIN_LP_RING( dwords );

      if (outring + dwords * 4 != ((outring + dwords * 4) & ringmask)) 
      {
	 int i;

	 if (I810_DEBUG & DEBUG_VERBOSE_RING)
	    fprintf(stderr, "\n\nwrap case in i810AllocPrimitiveVerts\n\n");

	 for (i = 0 ; i < dwords ; i++)
	    OUT_RING( 0 );
	 ADVANCE_LP_RING();
      }
      else 
      {
	 I810LpRing.tail = outring + dwords * 4;

	 if ((orig_dwords & 1) == 0)
	    OUT_RING(0);

	 OUT_RING( GFX_OP_PRIMITIVE | PR_TRIANGLES | (orig_dwords-1) );
	 return (GLuint *)(virt + outring);
      }
   }
}
#endif



void i810DDChooseRenderState( GLcontext *ctx )
{
   i810ContextPtr imesa = I810_CONTEXT( ctx );
   GLuint flags = ctx->TriangleCaps;

   ctx->IndirectTriangles &= ~DD_SW_RASTERIZE;

   if (flags) {
      GLuint ind = 0;
      GLuint shared = 0;
      GLuint setup = imesa->setupindex;
      GLuint fallback = I810_FALLBACK_BIT; 

      if (i810glx.noFallback) fallback = 0; 

      if ((flags & DD_FLATSHADE) && (setup & I810_RGBA_BIT)) shared |= I810_FLAT_BIT;
      if (flags & DD_MULTIDRAW)                    shared |= fallback;
      if (flags & DD_SELECT)                       shared |= I810_FALLBACK_BIT;
      if (flags & DD_FEEDBACK)                     shared |= I810_FALLBACK_BIT;

      ind = shared;
      if (flags & DD_POINT_SMOOTH)                 ind |= I810_ANTIALIAS_BIT;
      if (flags & DD_POINT_ATTEN)                  ind |= fallback;

      imesa->renderindex = ind;
      imesa->PointsFunc = points_tab[ind]; 
      if (ind & I810_FALLBACK_BIT)  
	 ctx->IndirectTriangles |= DD_POINT_SW_RASTERIZE;

      ind = shared;
      if (flags & DD_LINE_SMOOTH)                   ind |= I810_ANTIALIAS_BIT;
      if (flags & DD_LINE_STIPPLE)                  ind |= fallback;

      imesa->renderindex |= ind;
      imesa->LineFunc = line_tab[ind];
      if (ind & I810_FALLBACK_BIT) 
	 ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE;

      ind = shared;
      if (flags & DD_TRI_SMOOTH)                    ind |= I810_ANTIALIAS_BIT;
      if (flags & DD_TRI_OFFSET)                    ind |= I810_OFFSET_BIT;
      if (flags & DD_TRI_LIGHT_TWOSIDE)             ind |= I810_TWOSIDE_BIT;
      if (flags & (DD_TRI_UNFILLED|DD_TRI_STIPPLE)) ind |= fallback;	

      imesa->renderindex |= ind;
      imesa->TriangleFunc = tri_tab[ind];
      imesa->QuadFunc = quad_tab[ind];
      if (ind & I810_FALLBACK_BIT)
	 ctx->IndirectTriangles |= (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE);
   } 
   else if (imesa->renderindex)
   {
      imesa->renderindex  = 0;
      imesa->PointsFunc   = points_tab[0]; 
      imesa->LineFunc     = line_tab[0];
      imesa->TriangleFunc = tri_tab[0];
      imesa->QuadFunc     = quad_tab[0];
   }

   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      gl_print_tri_caps("tricaps", ctx->TriangleCaps);
      i810PrintRenderState("i810: Render state", imesa->renderindex);
   }
}