summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/glide/fxvbtmp.h
blob: 8d7649c6bb0f23637128d276f19b6b0b8873e000 (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

/*
 * Mesa 3-D graphics library
 * Version:  3.3
 *
 * Copyright (C) 1999-2000  Brian Paul   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
 * 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
 * BRIAN PAUL 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.
 *
 * Author:
 *   Keith Whitwell <keith@precisioninsight.com>
 */


static void
NAME(GLcontext * ctx, GLuint start, GLuint end)
{
   fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
   fxVertex *verts = fxMesa->verts;
   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
   GLuint tmu0_source = fxMesa->tmu_source[0];
   GLuint tmu1_source = fxMesa->tmu_source[1];
   GLfloat(*tmu0_data)[4];
   GLfloat(*tmu1_data)[4];
   GLubyte(*color)[4];
   GLfloat(*proj)[4] = VB->ProjectedClipPtr->data;
   fxVertex *v = &verts[start];
   GLfloat sscale0 = fxMesa->s0scale;
   GLfloat tscale0 = fxMesa->t0scale;
   GLfloat sscale1 = fxMesa->s1scale;
   GLfloat tscale1 = fxMesa->t1scale;
   GLubyte *clipmask = VB->ClipMask;
   GLuint i;
   const GLfloat *const s = ctx->Viewport._WindowMap.m;

   if (IND & SETUP_TMU0)
      tmu0_data = VB->TexCoordPtr[tmu0_source]->data;

   if (IND & SETUP_TMU1)
      tmu1_data = VB->TexCoordPtr[tmu1_source]->data;

   if (IND & SETUP_RGBA)
      color = VB->ColorPtr[0]->data;

   if (VB->ClipOrMask) {
      for (i = start; i < end; i++, v++) {
	 if (!clipmask[i]) {
	    if (IND & SETUP_XYZW) {
	       v->v.x = s[0] * proj[i][0] + s[12];
	       v->v.y = s[5] * proj[i][1] + s[13];
	       v->v.ooz = s[10] * proj[i][2] + s[14];
	       v->v.oow = proj[i][3];

	       if (IND & SETUP_SNAP) {
#if defined(USE_IEEE)
		  const float snapper = (3L << 18);
		  v->v.x += snapper;
		  v->v.x -= snapper;
		  v->v.y += snapper;
		  v->v.y -= snapper;
#else
		  v->v.x = ((int) (v->v.x * 16.0f)) * (1.0f / 16.0f);
		  v->v.y = ((int) (v->v.y * 16.0f)) * (1.0f / 16.0f);
#endif
	       }
	    }
	    if (IND & SETUP_RGBA) {
	       UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.r, color[i][0]);
	       UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.g, color[i][1]);
	       UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.b, color[i][2]);
	       UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.a, color[i][3]);
	    }
	    if (IND & SETUP_TMU0) {
	       v->v.tmuvtx[0].sow = sscale0 * tmu0_data[i][0] * v->v.oow;
	       v->v.tmuvtx[0].tow = tscale0 * tmu0_data[i][1] * v->v.oow;
	    }
	    if (IND & SETUP_TMU1) {
	       v->v.tmuvtx[1].sow = sscale1 * tmu1_data[i][0] * v->v.oow;
	       v->v.tmuvtx[1].tow = tscale1 * tmu1_data[i][1] * v->v.oow;
	    }
	 }
      }
   }
   else {
      for (i = start; i < end; i++, v++) {
	 if (IND & SETUP_XYZW) {
	    v->v.x = s[0] * proj[i][0] + s[12];
	    v->v.y = s[5] * proj[i][1] + s[13];
	    v->v.ooz = s[10] * proj[i][2] + s[14];
	    v->v.oow = proj[i][3];

	    if (IND & SETUP_SNAP) {
#if defined(USE_IEEE)
	       const float snapper = (3L << 18);
	       v->v.x += snapper;
	       v->v.x -= snapper;
	       v->v.y += snapper;
	       v->v.y -= snapper;
#else
	       v->v.x = ((int) (v->v.x * 16.0f)) * (1.0f / 16.0f);
	       v->v.y = ((int) (v->v.y * 16.0f)) * (1.0f / 16.0f);
#endif
	    }
	 }
	 if (IND & SETUP_RGBA) {
	    UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.r, color[i][0]);
	    UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.g, color[i][1]);
	    UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.b, color[i][2]);
	    UBYTE_COLOR_TO_FLOAT_255_COLOR2(v->v.a, color[i][3]);
	 }
	 if (IND & SETUP_TMU0) {
	    v->v.tmuvtx[0].sow = sscale0 * tmu0_data[i][0] * v->v.oow;
	    v->v.tmuvtx[0].tow = tscale0 * tmu0_data[i][1] * v->v.oow;
	 }
	 if (IND & SETUP_TMU1) {
	    v->v.tmuvtx[1].sow = sscale1 * tmu1_data[i][0] * v->v.oow;
	    v->v.tmuvtx[1].tow = tscale1 * tmu1_data[i][1] * v->v.oow;
	 }
      }
   }

   if ((IND & SETUP_XYZW) &&
       ctx->ProjectionMatrix.m[15] != 0.0F && ctx->Fog.Enabled) {
      fx_fake_fog_w(ctx, v, VB, start, end);
   }

   /* Check for and enable projective texturing in each texture unit.
    */
   if (IND & (SETUP_TMU0 | SETUP_TMU1)) {
      GLuint tmu0_sz = 2;
      GLuint tmu1_sz = 2;
      GLuint hs = fxMesa->stw_hint_state & ~(GR_STWHINT_W_DIFF_TMU0 |
					     GR_STWHINT_W_DIFF_TMU1);

      if (VB->TexCoordPtr[tmu0_source])
	 tmu0_sz = VB->TexCoordPtr[tmu0_source]->size;

      if (VB->TexCoordPtr[tmu1_source])
	 tmu1_sz = VB->TexCoordPtr[tmu1_source]->size;

      if (tmu0_sz == 4) {
	 project_texcoords(v, VB, 0, tmu0_source, start, end);
	 if (tmu1_sz == 4)
	    project_texcoords(v, VB, 1, tmu1_source, start, end);
	 else
	    copy_w(v, VB, 1, start, end);
	 hs |= (GR_STWHINT_W_DIFF_TMU0 | GR_STWHINT_W_DIFF_TMU1);
      }
      else if (tmu1_sz == 4) {
	 project_texcoords(v, VB, 1, tmu1_source, start, end);
	 hs |= GR_STWHINT_W_DIFF_TMU1;
      }

      if (hs != fxMesa->stw_hint_state) {
	 fxMesa->stw_hint_state = hs;
	 FX_grHints(GR_HINT_STWHINT, hs);
      }
   }
}




#undef IND
#undef NAME
#undef INPUTS