summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/sis/sis_vb.c
blob: acff4601e9637259ed6a920a692273546f28baeb (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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/* $XFree86$ */
/**************************************************************************

Copyright 2003 Eric Anholt
All Rights Reserved.

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
on the rights to use, copy, modify, merge, publish, distribute, sub
license, 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 (including the next
paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL
ERIC ANHOLT 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.

**************************************************************************/

/*
 * Authors:
 *    Eric Anholt <anholt@FreeBSD.org>
 */

#include "glheader.h"
#include "mtypes.h"
#include "imports.h"
#include "macros.h"
#include "colormac.h"

#include "swrast_setup/swrast_setup.h"
#include "tnl/t_context.h"

#include "sis_context.h"
#include "sis_vb.h"
#include "sis_tris.h"
#include "sis_state.h"


#define SIS_TEX1_BIT       0x1
#define SIS_TEX0_BIT       0x2
#define SIS_RGBA_BIT       0x4
#define SIS_SPEC_BIT       0x8
#define SIS_FOG_BIT	   0x10
#define SIS_XYZW_BIT       0x20
#define SIS_PTEX_BIT       0x40
#define SIS_MAX_SETUP      0x80

static struct {
   void                (*emit)( GLcontext *, GLuint, GLuint, void *, GLuint );
   interp_func		interp;
   copy_pv_func	        copy_pv;
   GLboolean           (*check_tex_sizes)( GLcontext *ctx );
   GLuint               vertex_size;
   GLuint               vertex_format;
} setup_tab[SIS_MAX_SETUP];

#define TEX0_VERTEX_FORMAT	1
#define TEX1_VERTEX_FORMAT	2

#define TINY_VERTEX_FORMAT	0
#define NOTEX_VERTEX_FORMAT	0
#define PROJ_TEX1_VERTEX_FORMAT 0
#define TEX2_VERTEX_FORMAT      0
#define TEX3_VERTEX_FORMAT      0
#define PROJ_TEX3_VERTEX_FORMAT 0

#define DO_XYZW (IND & SIS_XYZW_BIT)
#define DO_RGBA (IND & SIS_RGBA_BIT)
#define DO_SPEC (IND & SIS_SPEC_BIT)
#define DO_FOG  (IND & SIS_FOG_BIT)
#define DO_TEX0 (IND & SIS_TEX0_BIT)
#define DO_TEX1 (IND & SIS_TEX1_BIT)
#define DO_TEX2 0
#define DO_TEX3 0
#define DO_PTEX (IND & SIS_PTEX_BIT)

#define VERTEX sisVertex
#define VERTEX_COLOR sis_color_t
#define LOCALVARS sisContextPtr smesa = SIS_CONTEXT(ctx);
#define GET_VIEWPORT_MAT() smesa->hw_viewport
#define GET_TEXSOURCE(n)  n
#define GET_VERTEX_FORMAT() smesa->vertex_format
#define GET_VERTEX_STORE() smesa->verts
#define GET_VERTEX_SIZE() smesa->vertex_size * sizeof(GLuint)

#define HAVE_HW_VIEWPORT    0
#define HAVE_HW_DIVIDE      0
#define HAVE_RGBA_COLOR     0
#define HAVE_TINY_VERTICES  0
#define HAVE_NOTEX_VERTICES 0
#define HAVE_TEX0_VERTICES  1
#define HAVE_TEX1_VERTICES  1
#define HAVE_TEX2_VERTICES  0
#define HAVE_TEX3_VERTICES  0
#define HAVE_PTEX_VERTICES  0

#define UNVIEWPORT_VARS  GLfloat h = SIS_CONTEXT(ctx)->driDrawable->h
#define UNVIEWPORT_X(x)  x - SUBPIXEL_X
#define UNVIEWPORT_Y(y)  - y + h + SUBPIXEL_Y
#define UNVIEWPORT_Z(z)  z / smesa->depth_scale

#define PTEX_FALLBACK() FALLBACK(smesa, SIS_FALLBACK_TEXTURE, 1)

#define INTERP_VERTEX setup_tab[smesa->SetupIndex].interp
#define COPY_PV_VERTEX setup_tab[smesa->SetupIndex].copy_pv

/***********************************************************************
 *         Generate  pv-copying and translation functions              *
 ***********************************************************************/

#define TAG(x) sis_##x
#include "tnl_dd/t_dd_vb.c"

/***********************************************************************
 *             Generate vertex emit and interp functions               *
 ***********************************************************************/


#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT)
#define TAG(x) x##_wg
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT)
#define TAG(x) x##_wgs
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_wgt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_wgt0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_PTEX_BIT)
#define TAG(x) x##_wgpt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_wgst0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\
             SIS_TEX1_BIT)
#define TAG(x) x##_wgst0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\
             SIS_PTEX_BIT)
#define TAG(x) x##_wgspt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT)
#define TAG(x) x##_wgf
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT)
#define TAG(x) x##_wgfs
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_wgft0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|\
             SIS_TEX1_BIT)
#define TAG(x) x##_wgft0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|\
             SIS_PTEX_BIT)
#define TAG(x) x##_wgfpt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\
             SIS_TEX0_BIT)
#define TAG(x) x##_wgfst0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\
             SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_wgfst0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_XYZW_BIT|SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|\
             SIS_TEX0_BIT|SIS_PTEX_BIT)
#define TAG(x) x##_wgfspt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_TEX0_BIT)
#define TAG(x) x##_t0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_t0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_FOG_BIT)
#define TAG(x) x##_f
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_FOG_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_ft0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_FOG_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_ft0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT)
#define TAG(x) x##_g
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT)
#define TAG(x) x##_gs
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_gt0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_gt0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_gst0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_gst0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT)
#define TAG(x) x##_gf
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT)
#define TAG(x) x##_gfs
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_gft0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_TEX0_BIT|SIS_TEX1_BIT)
#define TAG(x) x##_gft0t1
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT)
#define TAG(x) x##_gfst0
#include "tnl_dd/t_dd_vbtmp.h"

#define IND (SIS_RGBA_BIT|SIS_FOG_BIT|SIS_SPEC_BIT|SIS_TEX0_BIT|\
             SIS_TEX1_BIT)
#define TAG(x) x##_gfst0t1
#include "tnl_dd/t_dd_vbtmp.h"


static void init_setup_tab( void )
{
   init_wg();
   init_wgs();
   init_wgt0();
   init_wgt0t1();
   init_wgpt0();
   init_wgst0();
   init_wgst0t1();
   init_wgspt0();
   init_wgf();
   init_wgfs();
   init_wgft0();
   init_wgft0t1();
   init_wgfpt0();
   init_wgfst0();
   init_wgfst0t1();
   init_wgfspt0();
   init_t0();
   init_t0t1();
   init_f();
   init_ft0();
   init_ft0t1();
   init_g();
   init_gs();
   init_gt0();
   init_gt0t1();
   init_gst0();
   init_gst0t1();
   init_gf();
   init_gfs();
   init_gft0();
   init_gft0t1();
   init_gfst0();
   init_gfst0t1();
}



void sisPrintSetupFlags(char *msg, GLuint flags )
{
   fprintf(stderr, "%s(%x): %s%s%s%s%s%s\n",
	   msg,
	   (int)flags,
	   (flags & SIS_XYZW_BIT)     ? " xyzw," : "",
	   (flags & SIS_RGBA_BIT)     ? " rgba," : "",
	   (flags & SIS_SPEC_BIT)     ? " spec," : "",
	   (flags & SIS_FOG_BIT)      ? " fog," : "",
	   (flags & SIS_TEX0_BIT)     ? " tex-0," : "",
	   (flags & SIS_TEX1_BIT)     ? " tex-1," : "");
}



void sisCheckTexSizes( GLcontext *ctx )
{
   sisContextPtr smesa = SIS_CONTEXT( ctx );

   if (!setup_tab[smesa->SetupIndex].check_tex_sizes(ctx)) {
      TNLcontext *tnl = TNL_CONTEXT(ctx);

      /* Invalidate stored verts
       */
      smesa->SetupNewInputs = ~0;
      smesa->SetupIndex |= SIS_PTEX_BIT;

      if (!smesa->Fallback &&
	  !(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
	 tnl->Driver.Render.Interp = setup_tab[smesa->SetupIndex].interp;
	 tnl->Driver.Render.CopyPV = setup_tab[smesa->SetupIndex].copy_pv;
      }
   }
}

void sisBuildVertices( GLcontext *ctx,
		       GLuint start,
		       GLuint count,
		       GLuint newinputs )
{
   sisContextPtr smesa = SIS_CONTEXT( ctx );
   GLuint stride = smesa->vertex_size * sizeof(int);
   GLubyte *v = ((GLubyte *)smesa->verts + (start * stride));

   newinputs |= smesa->SetupNewInputs;
   smesa->SetupNewInputs = 0;

   if (!newinputs)
      return;

   if (newinputs & VERT_BIT_POS) {
      setup_tab[smesa->SetupIndex].emit( ctx, start, count, v, stride );
   } else {
      GLuint ind = 0;

      if (newinputs & VERT_BIT_COLOR0)
	 ind |= SIS_RGBA_BIT;

      if (newinputs & VERT_BIT_COLOR1)
	 ind |= SIS_SPEC_BIT;

      if (newinputs & VERT_BIT_TEX0)
	 ind |= SIS_TEX0_BIT;

      if (newinputs & VERT_BIT_TEX1)
	 ind |= SIS_TEX1_BIT;

      if (newinputs & VERT_BIT_FOG)
	 ind |= SIS_FOG_BIT;

      if (smesa->SetupIndex & SIS_PTEX_BIT)
	 ind = ~0;

      ind &= smesa->SetupIndex;

      if (ind) {
	 setup_tab[ind].emit( ctx, start, count, v, stride );
      }
   }
}

void sisChooseVertexState( GLcontext *ctx )
{
  TNLcontext *tnl = TNL_CONTEXT(ctx);
  sisContextPtr smesa = SIS_CONTEXT( ctx );
  GLuint ind = SIS_XYZW_BIT | SIS_RGBA_BIT;

  if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
    ind |= SIS_SPEC_BIT;

  if (ctx->Fog.Enabled)
    ind |= SIS_FOG_BIT;

  if (ctx->Texture._EnabledUnits) {
    ind |= SIS_TEX0_BIT;
    if (ctx->Texture.Unit[0]._ReallyEnabled &&
        ctx->Texture.Unit[1]._ReallyEnabled)
    ind |= SIS_TEX1_BIT;
  }

  smesa->SetupIndex = ind;

  if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_TRI_UNFILLED)) {
    tnl->Driver.Render.Interp = sis_interp_extras;
    tnl->Driver.Render.CopyPV = sis_copy_pv_extras;
  } else {
    tnl->Driver.Render.Interp = setup_tab[ind].interp;
    tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
  }

  if (setup_tab[ind].vertex_format != smesa->vertex_format) {
    smesa->vertex_format = setup_tab[ind].vertex_format;
    smesa->vertex_size = setup_tab[ind].vertex_size;
  }
}


void sisInitVB( GLcontext *ctx )
{
  sisContextPtr smesa = SIS_CONTEXT( ctx );
  GLuint size = TNL_CONTEXT(ctx)->vb.Size;
  static int firsttime = 1;

  smesa->verts = (GLubyte *)ALIGN_MALLOC(size * 4 * 16, 32);

  if (firsttime) {
    init_setup_tab();
    firsttime = 0;
  }
}

void sisFreeVB( GLcontext *ctx )
{
  sisContextPtr smesa = SIS_CONTEXT( ctx );
  if (smesa->verts) {
    ALIGN_FREE(smesa->verts);
    smesa->verts = NULL;
  }
}