| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003 Tungsten Graphics, inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 9 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 10 | * the Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 22 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Keith Whitwell <keithw@tungstengraphics.com> |
| 26 | */ |
| 27 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 28 | #include "glheader.h" |
| 29 | #include "context.h" |
| 30 | #include "colormac.h" |
| 31 | |
| 32 | #include "t_context.h" |
| 33 | #include "t_vertex.h" |
| 34 | |
| 35 | |
| 36 | /* Build and manage clipspace/ndc/window vertices. |
| 37 | * |
| 38 | * Another new mechanism designed and crying out for codegen. Before |
| 39 | * that, it would be very interesting to investigate the merger of |
| 40 | * these vertices and those built in t_vtx_*. |
| 41 | */ |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | |
| Keith Whitwell | 203dca4 | 2004-01-06 20:13:41 +0000 | [diff] [blame] | 45 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 46 | #define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 47 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 48 | static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 49 | const GLfloat *in ) |
| 50 | { |
| 51 | GLfloat *out = (GLfloat *)v; |
| 52 | const GLfloat * const vp = a->vp; |
| 53 | |
| 54 | out[0] = vp[0] * in[0] + vp[12]; |
| 55 | out[1] = vp[5] * in[1] + vp[13]; |
| 56 | out[2] = vp[10] * in[2] + vp[14]; |
| 57 | out[3] = in[3]; |
| 58 | } |
| 59 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 60 | static void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 61 | const GLfloat *in ) |
| 62 | { |
| 63 | GLfloat *out = (GLfloat *)v; |
| 64 | const GLfloat * const vp = a->vp; |
| 65 | |
| 66 | out[0] = vp[0] * in[0] + vp[12]; |
| 67 | out[1] = vp[5] * in[1] + vp[13]; |
| 68 | out[2] = vp[10] * in[2] + vp[14]; |
| 69 | out[3] = 1; |
| 70 | } |
| 71 | |
| 72 | static void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 73 | const GLfloat *in ) |
| 74 | { |
| 75 | GLfloat *out = (GLfloat *)v; |
| 76 | const GLfloat * const vp = a->vp; |
| 77 | |
| 78 | out[0] = vp[0] * in[0] + vp[12]; |
| 79 | out[1] = vp[5] * in[1] + vp[13]; |
| 80 | out[2] = vp[14]; |
| 81 | out[3] = 1; |
| 82 | } |
| 83 | |
| 84 | static void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 85 | const GLfloat *in ) |
| 86 | { |
| 87 | GLfloat *out = (GLfloat *)v; |
| 88 | const GLfloat * const vp = a->vp; |
| 89 | |
| 90 | out[0] = vp[0] * in[0] + vp[12]; |
| 91 | out[1] = vp[13]; |
| 92 | out[2] = vp[14]; |
| 93 | out[3] = 1; |
| 94 | } |
| 95 | |
| 96 | static void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 97 | const GLfloat *in ) |
| 98 | { |
| 99 | GLfloat *out = (GLfloat *)v; |
| 100 | const GLfloat * const vp = a->vp; |
| 101 | |
| 102 | out[0] = vp[0] * in[0] + vp[12]; |
| 103 | out[1] = vp[5] * in[1] + vp[13]; |
| 104 | out[2] = vp[10] * in[2] + vp[14]; |
| 105 | } |
| 106 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 107 | static void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 108 | const GLfloat *in ) |
| 109 | { |
| 110 | GLfloat *out = (GLfloat *)v; |
| 111 | const GLfloat * const vp = a->vp; |
| 112 | |
| 113 | out[0] = vp[0] * in[0] + vp[12]; |
| 114 | out[1] = vp[5] * in[1] + vp[13]; |
| 115 | out[2] = vp[10] * in[2] + vp[14]; |
| 116 | } |
| 117 | |
| 118 | static void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 119 | const GLfloat *in ) |
| 120 | { |
| 121 | GLfloat *out = (GLfloat *)v; |
| 122 | const GLfloat * const vp = a->vp; |
| 123 | |
| 124 | out[0] = vp[0] * in[0] + vp[12]; |
| 125 | out[1] = vp[13]; |
| 126 | out[2] = vp[14]; |
| 127 | } |
| 128 | |
| 129 | static void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 130 | const GLfloat *in ) |
| 131 | { |
| 132 | GLfloat *out = (GLfloat *)v; |
| 133 | const GLfloat * const vp = a->vp; |
| 134 | |
| 135 | out[0] = vp[0] * in[0] + vp[12]; |
| 136 | out[1] = vp[5] * in[1] + vp[13]; |
| 137 | } |
| 138 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 139 | static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 140 | const GLfloat *in ) |
| 141 | { |
| 142 | GLfloat *out = (GLfloat *)v; |
| 143 | const GLfloat * const vp = a->vp; |
| 144 | |
| 145 | out[0] = vp[0] * in[0] + vp[12]; |
| 146 | out[1] = vp[13]; |
| 147 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 148 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 149 | |
| 150 | static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 151 | { |
| 152 | GLfloat *out = (GLfloat *)(v); |
| 153 | |
| 154 | out[0] = in[0]; |
| 155 | out[1] = in[1]; |
| 156 | out[2] = in[2]; |
| 157 | out[3] = in[3]; |
| 158 | } |
| 159 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 160 | static void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 161 | { |
| 162 | GLfloat *out = (GLfloat *)(v); |
| 163 | |
| 164 | out[0] = in[0]; |
| 165 | out[1] = in[1]; |
| 166 | out[2] = in[2]; |
| 167 | out[3] = 1; |
| 168 | } |
| 169 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 170 | static void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 171 | { |
| 172 | GLfloat *out = (GLfloat *)(v); |
| 173 | |
| 174 | out[0] = in[0]; |
| 175 | out[1] = in[1]; |
| 176 | out[2] = 0; |
| 177 | out[3] = 1; |
| 178 | } |
| 179 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 180 | static void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 181 | { |
| 182 | GLfloat *out = (GLfloat *)(v); |
| 183 | |
| 184 | out[0] = in[0]; |
| 185 | out[1] = 0; |
| 186 | out[2] = 0; |
| 187 | out[3] = 1; |
| 188 | } |
| 189 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 190 | static void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 191 | { |
| 192 | GLfloat *out = (GLfloat *)(v); |
| 193 | |
| 194 | out[0] = in[0]; |
| 195 | out[1] = in[1]; |
| 196 | out[2] = in[3]; |
| 197 | } |
| 198 | |
| 199 | static void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 200 | { |
| 201 | abort(); |
| 202 | } |
| 203 | |
| 204 | static void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 205 | { |
| 206 | GLfloat *out = (GLfloat *)(v); |
| 207 | |
| 208 | out[0] = in[0]; |
| 209 | out[1] = in[1]; |
| 210 | out[2] = in[2]; |
| 211 | } |
| 212 | |
| 213 | static void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 214 | { |
| 215 | GLfloat *out = (GLfloat *)(v); |
| 216 | |
| 217 | out[0] = in[0]; |
| 218 | out[1] = in[1]; |
| 219 | out[2] = 0; |
| 220 | } |
| 221 | |
| 222 | static void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 223 | { |
| 224 | GLfloat *out = (GLfloat *)(v); |
| 225 | |
| 226 | out[0] = in[0]; |
| 227 | out[1] = 0; |
| 228 | out[2] = 0; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | static void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 233 | { |
| 234 | GLfloat *out = (GLfloat *)(v); |
| 235 | |
| 236 | out[0] = in[0]; |
| 237 | out[1] = in[1]; |
| 238 | } |
| 239 | |
| 240 | static void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 241 | { |
| 242 | GLfloat *out = (GLfloat *)(v); |
| 243 | |
| 244 | out[0] = in[0]; |
| 245 | out[1] = 0; |
| 246 | } |
| 247 | |
| 248 | static void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) |
| 249 | { |
| 250 | GLfloat *out = (GLfloat *)(v); |
| 251 | |
| 252 | out[0] = in[0]; |
| 253 | } |
| 254 | |
| 255 | static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 256 | const GLfloat *in ) |
| 257 | { |
| 258 | GLchan *c = (GLchan *)v; |
| 259 | UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); |
| 260 | UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]); |
| 261 | UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]); |
| 262 | UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]); |
| 263 | } |
| 264 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 265 | static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 266 | const GLfloat *in ) |
| 267 | { |
| 268 | GLchan *c = (GLchan *)v; |
| 269 | UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); |
| 270 | UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]); |
| 271 | UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]); |
| 272 | c[3] = CHAN_MAX; |
| 273 | } |
| 274 | |
| 275 | static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 276 | const GLfloat *in ) |
| 277 | { |
| 278 | GLchan *c = (GLchan *)v; |
| 279 | UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); |
| 280 | UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]); |
| 281 | c[2] = 0; |
| 282 | c[3] = CHAN_MAX; |
| 283 | } |
| 284 | |
| 285 | static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 286 | const GLfloat *in ) |
| 287 | { |
| 288 | GLchan *c = (GLchan *)v; |
| 289 | UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); |
| 290 | c[1] = 0; |
| 291 | c[2] = 0; |
| 292 | c[3] = CHAN_MAX; |
| 293 | } |
| 294 | |
| 295 | static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 296 | const GLfloat *in ) |
| 297 | { |
| 298 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 299 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 300 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]); |
| 301 | UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]); |
| 302 | } |
| 303 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 304 | static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 305 | const GLfloat *in ) |
| 306 | { |
| 307 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 308 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 309 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]); |
| 310 | v[3] = 0xff; |
| 311 | } |
| 312 | |
| 313 | static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 314 | const GLfloat *in ) |
| 315 | { |
| 316 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 317 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 318 | v[2] = 0; |
| 319 | v[3] = 0xff; |
| 320 | } |
| 321 | |
| 322 | static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 323 | const GLfloat *in ) |
| 324 | { |
| 325 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 326 | v[1] = 0; |
| 327 | v[2] = 0; |
| 328 | v[3] = 0xff; |
| 329 | } |
| 330 | |
| 331 | static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 332 | const GLfloat *in ) |
| 333 | { |
| 334 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 335 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 336 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]); |
| 337 | UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]); |
| 338 | } |
| 339 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 340 | static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 341 | const GLfloat *in ) |
| 342 | { |
| 343 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 344 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 345 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]); |
| 346 | v[3] = 0xff; |
| 347 | } |
| 348 | |
| 349 | static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 350 | const GLfloat *in ) |
| 351 | { |
| 352 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 353 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 354 | v[0] = 0; |
| 355 | v[3] = 0xff; |
| 356 | } |
| 357 | |
| 358 | static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 359 | const GLfloat *in ) |
| 360 | { |
| 361 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 362 | v[1] = 0; |
| 363 | v[0] = 0; |
| 364 | v[3] = 0xff; |
| 365 | } |
| 366 | |
| 367 | static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 368 | const GLfloat *in ) |
| 369 | { |
| 370 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 371 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 372 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]); |
| 373 | } |
| 374 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 375 | static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 376 | const GLfloat *in ) |
| 377 | { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 378 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 379 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 380 | v[2] = 0; |
| 381 | } |
| 382 | |
| 383 | static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 384 | const GLfloat *in ) |
| 385 | { |
| 386 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 387 | v[1] = 0; |
| 388 | v[2] = 0; |
| 389 | } |
| 390 | |
| 391 | static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 392 | const GLfloat *in ) |
| 393 | { |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 394 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 395 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 396 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]); |
| 397 | } |
| 398 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 399 | static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 400 | const GLfloat *in ) |
| 401 | { |
| 402 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 403 | UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); |
| 404 | v[0] = 0; |
| 405 | } |
| 406 | |
| 407 | static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| 408 | const GLfloat *in ) |
| 409 | { |
| 410 | UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); |
| 411 | v[1] = 0; |
| Keith Whitwell | ef167c6 | 2004-01-26 21:34:28 +0000 | [diff] [blame^] | 412 | v[0] = 0; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
| 416 | static void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 417 | const GLfloat *in ) |
| 418 | { |
| 419 | UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | /*********************************************************************** |
| 424 | * Functions to perform the reverse operations to the above, for |
| 425 | * swrast translation and clip-interpolation. |
| 426 | * |
| 427 | * Currently always extracts a full 4 floats. |
| 428 | */ |
| 429 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 430 | static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 431 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 432 | { |
| 433 | const GLfloat *in = (const GLfloat *)v; |
| 434 | const GLfloat * const vp = a->vp; |
| 435 | |
| Keith Whitwell | ef167c6 | 2004-01-26 21:34:28 +0000 | [diff] [blame^] | 436 | /* Although included for completeness, the position coordinate is |
| 437 | * usually handled differently during clipping. |
| 438 | */ |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 439 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 440 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 441 | out[2] = (in[2] - vp[14]) / vp[10]; |
| 442 | out[3] = in[3]; |
| 443 | } |
| 444 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 445 | static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 446 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 447 | { |
| 448 | const GLfloat *in = (const GLfloat *)v; |
| 449 | const GLfloat * const vp = a->vp; |
| 450 | |
| 451 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 452 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 453 | out[2] = (in[2] - vp[14]) / vp[10]; |
| 454 | out[3] = 1; |
| 455 | } |
| 456 | |
| 457 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 458 | static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 459 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 460 | { |
| 461 | const GLfloat *in = (const GLfloat *)v; |
| 462 | const GLfloat * const vp = a->vp; |
| 463 | |
| 464 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 465 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 466 | out[2] = 0; |
| 467 | out[3] = 1; |
| 468 | } |
| 469 | |
| 470 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 471 | static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 472 | { |
| 473 | const GLfloat *in = (const GLfloat *)v; |
| 474 | |
| 475 | out[0] = in[0]; |
| 476 | out[1] = in[1]; |
| 477 | out[2] = in[2]; |
| 478 | out[3] = in[3]; |
| 479 | } |
| 480 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 481 | static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 482 | { |
| 483 | const GLfloat *in = (const GLfloat *)v; |
| 484 | |
| 485 | out[0] = in[0]; |
| 486 | out[1] = in[1]; |
| 487 | out[2] = in[3]; |
| 488 | out[3] = 1; |
| 489 | } |
| 490 | |
| 491 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 492 | static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 493 | { |
| 494 | const GLfloat *in = (const GLfloat *)v; |
| 495 | |
| 496 | out[0] = in[0]; |
| 497 | out[1] = in[1]; |
| 498 | out[2] = in[2]; |
| 499 | out[3] = 1; |
| 500 | } |
| 501 | |
| 502 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 503 | static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 504 | { |
| 505 | const GLfloat *in = (const GLfloat *)v; |
| 506 | |
| 507 | out[0] = in[0]; |
| 508 | out[1] = in[1]; |
| 509 | out[2] = 0; |
| 510 | out[3] = 1; |
| 511 | } |
| 512 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 513 | static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 514 | { |
| 515 | const GLfloat *in = (const GLfloat *)v; |
| 516 | |
| 517 | out[0] = in[0]; |
| 518 | out[1] = 0; |
| 519 | out[2] = 0; |
| 520 | out[3] = 1; |
| 521 | } |
| 522 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 523 | static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 524 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 525 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 526 | GLchan *c = (GLchan *)v; |
| 527 | |
| 528 | out[0] = CHAN_TO_FLOAT(c[0]); |
| 529 | out[1] = CHAN_TO_FLOAT(c[1]); |
| 530 | out[2] = CHAN_TO_FLOAT(c[2]); |
| 531 | out[3] = CHAN_TO_FLOAT(c[3]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 534 | static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 535 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 536 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 537 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| 538 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 539 | out[2] = UBYTE_TO_FLOAT(v[2]); |
| 540 | out[3] = UBYTE_TO_FLOAT(v[3]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 543 | static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 544 | const GLubyte *v ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 545 | { |
| 546 | out[2] = UBYTE_TO_FLOAT(v[0]); |
| 547 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 548 | out[0] = UBYTE_TO_FLOAT(v[2]); |
| 549 | out[3] = UBYTE_TO_FLOAT(v[3]); |
| 550 | } |
| 551 | |
| 552 | static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 553 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 554 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 555 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| 556 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 557 | out[2] = UBYTE_TO_FLOAT(v[2]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 558 | out[3] = 1; |
| 559 | } |
| 560 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 561 | static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 562 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 563 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 564 | out[2] = UBYTE_TO_FLOAT(v[0]); |
| 565 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 566 | out[0] = UBYTE_TO_FLOAT(v[2]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 567 | out[3] = 1; |
| 568 | } |
| 569 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 570 | static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 571 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 572 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 573 | out[1] = 0; |
| 574 | out[2] = 0; |
| 575 | out[3] = 1; |
| 576 | } |
| 577 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 578 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 579 | struct { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 580 | const char *name; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 581 | extract_func extract; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 582 | insert_func insert[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 583 | GLuint attrsize; |
| 584 | } format_info[EMIT_MAX] = { |
| 585 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 586 | { "1f", |
| 587 | extract_1f, |
| 588 | { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 589 | sizeof(GLfloat) }, |
| 590 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 591 | { "2f", |
| 592 | extract_2f, |
| 593 | { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 594 | 2 * sizeof(GLfloat) }, |
| 595 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 596 | { "3f", |
| 597 | extract_3f, |
| 598 | { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 599 | 3 * sizeof(GLfloat) }, |
| 600 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 601 | { "4f", |
| 602 | extract_4f, |
| 603 | { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 604 | 4 * sizeof(GLfloat) }, |
| 605 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 606 | { "2f_viewport", |
| 607 | extract_2f_viewport, |
| 608 | { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2, |
| 609 | insert_2f_viewport_2 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 610 | 2 * sizeof(GLfloat) }, |
| 611 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 612 | { "3f_viewport", |
| 613 | extract_3f_viewport, |
| 614 | { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3, |
| 615 | insert_3f_viewport_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 616 | 3 * sizeof(GLfloat) }, |
| 617 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 618 | { "4f_viewport", |
| 619 | extract_4f_viewport, |
| 620 | { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3, |
| 621 | insert_4f_viewport_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 622 | 4 * sizeof(GLfloat) }, |
| 623 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 624 | { "3f_xyw", |
| 625 | extract_3f_xyw, |
| 626 | { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err, |
| 627 | insert_3f_xyw_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 628 | 3 * sizeof(GLfloat) }, |
| 629 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 630 | { "1ub_1f", |
| 631 | extract_1ub_1f, |
| 632 | { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 633 | sizeof(GLubyte) }, |
| 634 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 635 | { "3ub_3f_rgb", |
| 636 | extract_3ub_3f_rgb, |
| 637 | { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3, |
| 638 | insert_3ub_3f_rgb_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 639 | 3 * sizeof(GLubyte) }, |
| 640 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 641 | { "3ub_3f_bgr", |
| 642 | extract_3ub_3f_bgr, |
| 643 | { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3, |
| 644 | insert_3ub_3f_bgr_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 645 | 3 * sizeof(GLubyte) }, |
| 646 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 647 | { "4ub_4f_rgba", |
| 648 | extract_4ub_4f_rgba, |
| 649 | { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3, |
| 650 | insert_4ub_4f_rgba_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 651 | 4 * sizeof(GLubyte) }, |
| 652 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 653 | { "4ub_4f_bgra", |
| 654 | extract_4ub_4f_bgra, |
| 655 | { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3, |
| 656 | insert_4ub_4f_bgra_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 657 | 4 * sizeof(GLubyte) }, |
| 658 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 659 | { "4chan_4f_rgba", |
| 660 | extract_4chan_4f_rgba, |
| 661 | { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3, |
| 662 | insert_4chan_4f_rgba_4 }, |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 663 | 4 * sizeof(GLchan) }, |
| 664 | |
| 665 | { "pad", |
| 666 | 0, |
| 667 | { 0, 0, 0, 0 }, |
| 668 | 0 } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 669 | |
| 670 | }; |
| 671 | |
| 672 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 673 | /*********************************************************************** |
| 674 | * Generic (non-codegen) functions for whole vertices or groups of |
| 675 | * vertices |
| 676 | */ |
| 677 | |
| 678 | static void generic_emit( GLcontext *ctx, |
| 679 | GLuint start, GLuint end, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 680 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 681 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 682 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 683 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 684 | struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 685 | GLubyte *v = (GLubyte *)dest; |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 686 | GLuint i, j; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 687 | GLuint count = vtx->attr_count; |
| 688 | GLuint stride; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 689 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 690 | for (j = 0; j < count; j++) { |
| 691 | GLvector4f *vptr = VB->AttribPtr[a[j].attrib]; |
| 692 | a[j].inputstride = vptr->stride; |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 693 | a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 694 | a[j].emit = a[j].insert[vptr->size - 1]; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 697 | end -= start; |
| 698 | stride = vtx->vertex_size; |
| 699 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 700 | for (i = 0 ; i < end ; i++, v += stride) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 701 | for (j = 0; j < count; j++) { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 702 | GLfloat *in = (GLfloat *)a[j].inputptr; |
| 703 | a[j].inputptr += a[j].inputstride; |
| 704 | a[j].emit( &a[j], v + a[j].vertoffset, in ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | static void generic_interp( GLcontext *ctx, |
| 711 | GLfloat t, |
| 712 | GLuint edst, GLuint eout, GLuint ein, |
| 713 | GLboolean force_boundary ) |
| 714 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 715 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 716 | struct vertex_buffer *VB = &tnl->vb; |
| 717 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 718 | GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size; |
| 719 | GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size; |
| 720 | GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 721 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 722 | int attr_count = vtx->attr_count; |
| 723 | int j; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 724 | |
| 725 | if (tnl->NeedNdcCoords) { |
| 726 | const GLfloat *dstclip = VB->ClipPtr->data[edst]; |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 727 | if (dstclip[3] != 0.0) { |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 728 | const GLfloat w = 1.0f / dstclip[3]; |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 729 | GLfloat pos[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 730 | |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 731 | pos[0] = dstclip[0] * w; |
| 732 | pos[1] = dstclip[1] * w; |
| 733 | pos[2] = dstclip[2] * w; |
| 734 | pos[3] = w; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 735 | |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 736 | a[0].insert[4-1]( &a[0], vdst, pos ); |
| 737 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 738 | } |
| 739 | else { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 740 | a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
| 744 | for (j = 1; j < attr_count; j++) { |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 745 | GLfloat fin[4], fout[4], fdst[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 746 | |
| 747 | a[j].extract( &a[j], fin, vin + a[j].vertoffset ); |
| 748 | a[j].extract( &a[j], fout, vout + a[j].vertoffset ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 749 | |
| 750 | INTERP_F( t, fdst[3], fout[3], fin[3] ); |
| 751 | INTERP_F( t, fdst[2], fout[2], fin[2] ); |
| 752 | INTERP_F( t, fdst[1], fout[1], fin[1] ); |
| 753 | INTERP_F( t, fdst[0], fout[0], fin[0] ); |
| 754 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 755 | a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | |
| 760 | /* Extract color attributes from one vertex and insert them into |
| 761 | * another. (Shortcircuit extract/insert with memcpy). |
| 762 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 763 | static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 764 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 765 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 766 | GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size; |
| 767 | GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 768 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 769 | int attr_count = vtx->attr_count; |
| 770 | int j; |
| 771 | |
| 772 | for (j = 0; j < attr_count; j++) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 773 | if (a[j].attrib == VERT_ATTRIB_COLOR0 || |
| 774 | a[j].attrib == VERT_ATTRIB_COLOR1) { |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 775 | |
| Brian Paul | 3663c0f | 2004-01-15 00:29:51 +0000 | [diff] [blame] | 776 | _mesa_memcpy( vdst + a[j].vertoffset, |
| 777 | vsrc + a[j].vertoffset, |
| 778 | a[j].vertattrsize ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 779 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 783 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 784 | /* Helper functions for hardware which doesn't put back colors and/or |
| 785 | * edgeflags into vertices. |
| 786 | */ |
| 787 | static void generic_interp_extras( GLcontext *ctx, |
| 788 | GLfloat t, |
| 789 | GLuint dst, GLuint out, GLuint in, |
| 790 | GLboolean force_boundary ) |
| 791 | { |
| 792 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 793 | |
| 794 | if (VB->ColorPtr[1]) { |
| 795 | assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat)); |
| 796 | |
| 797 | INTERP_4F( t, |
| 798 | VB->ColorPtr[1]->data[dst], |
| 799 | VB->ColorPtr[1]->data[out], |
| 800 | VB->ColorPtr[1]->data[in] ); |
| 801 | |
| 802 | if (VB->SecondaryColorPtr[1]) { |
| 803 | INTERP_3F( t, |
| 804 | VB->SecondaryColorPtr[1]->data[dst], |
| 805 | VB->SecondaryColorPtr[1]->data[out], |
| 806 | VB->SecondaryColorPtr[1]->data[in] ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 807 | } |
| 808 | } |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 809 | else if (VB->IndexPtr[1]) { |
| 810 | VB->IndexPtr[1]->data[dst][0] = LINTERP( t, |
| 811 | VB->IndexPtr[1]->data[out][0], |
| 812 | VB->IndexPtr[1]->data[in][0] ); |
| 813 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 814 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 815 | if (VB->EdgeFlag) { |
| 816 | VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary; |
| 817 | } |
| 818 | |
| 819 | generic_interp(ctx, t, dst, out, in, force_boundary); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 822 | static void generic_copy_pv_extras( GLcontext *ctx, |
| 823 | GLuint dst, GLuint src ) |
| 824 | { |
| 825 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 826 | |
| 827 | if (VB->ColorPtr[1]) { |
| 828 | COPY_4FV( VB->ColorPtr[1]->data[dst], |
| 829 | VB->ColorPtr[1]->data[src] ); |
| 830 | |
| 831 | if (VB->SecondaryColorPtr[1]) { |
| 832 | COPY_4FV( VB->SecondaryColorPtr[1]->data[dst], |
| 833 | VB->SecondaryColorPtr[1]->data[src] ); |
| 834 | } |
| 835 | } |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 836 | else if (VB->IndexPtr[1]) { |
| 837 | VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0]; |
| 838 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 839 | |
| Keith Whitwell | ef167c6 | 2004-01-26 21:34:28 +0000 | [diff] [blame^] | 840 | generic_copy_pv(ctx, dst, src); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 841 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | /*********************************************************************** |
| 849 | * Build codegen functions or return generic ones: |
| 850 | */ |
| 851 | |
| 852 | |
| 853 | static void choose_emit_func( GLcontext *ctx, |
| 854 | GLuint start, GLuint end, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 855 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 856 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 857 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 858 | vtx->emit = generic_emit; |
| 859 | vtx->emit( ctx, start, end, dest ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | |
| 863 | static void choose_interp_func( GLcontext *ctx, |
| 864 | GLfloat t, |
| 865 | GLuint edst, GLuint eout, GLuint ein, |
| 866 | GLboolean force_boundary ) |
| 867 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 868 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 869 | |
| 870 | if (vtx->need_extras && |
| 871 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| 872 | vtx->interp = generic_interp_extras; |
| 873 | } else { |
| 874 | vtx->interp = generic_interp; |
| 875 | } |
| 876 | |
| 877 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 881 | static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 882 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 883 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 884 | |
| 885 | if (vtx->need_extras && |
| 886 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| 887 | vtx->copy_pv = generic_copy_pv_extras; |
| 888 | } else { |
| 889 | vtx->copy_pv = generic_copy_pv; |
| 890 | } |
| 891 | |
| 892 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
| 896 | /*********************************************************************** |
| 897 | * Public entrypoints, mostly dispatch to the above: |
| 898 | */ |
| 899 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 900 | |
| 901 | /* Interpolate between two vertices to produce a third: |
| 902 | */ |
| 903 | void _tnl_interp( GLcontext *ctx, |
| 904 | GLfloat t, |
| 905 | GLuint edst, GLuint eout, GLuint ein, |
| 906 | GLboolean force_boundary ) |
| 907 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 908 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 909 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /* Copy colors from one vertex to another: |
| 913 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 914 | void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 915 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 916 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 917 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | |
| 921 | /* Extract a named attribute from a hardware vertex. Will have to |
| 922 | * reverse any viewport transformation, swizzling or other conversions |
| 923 | * which may have been applied: |
| 924 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 925 | void _tnl_get_attr( GLcontext *ctx, const void *vin, |
| 926 | GLenum attr, GLfloat *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 927 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 928 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 929 | const struct tnl_clipspace_attr *a = vtx->attr; |
| 930 | int attr_count = vtx->attr_count; |
| 931 | int j; |
| 932 | |
| 933 | for (j = 0; j < attr_count; j++) { |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 934 | if (a[j].attrib == (int)attr) { |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 935 | a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | /* Else return the value from ctx->Current |
| 941 | */ |
| Brian Paul | 3663c0f | 2004-01-15 00:29:51 +0000 | [diff] [blame] | 942 | _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat)); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | void *_tnl_get_vertex( GLcontext *ctx, GLuint nr ) |
| 946 | { |
| 947 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 948 | |
| 949 | return vtx->vertex_buf + nr * vtx->vertex_size; |
| 950 | } |
| 951 | |
| 952 | void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state ) |
| 953 | { |
| 954 | if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) { |
| 955 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 956 | vtx->new_inputs = ~0; |
| 957 | vtx->interp = choose_interp_func; |
| 958 | vtx->copy_pv = choose_copy_pv_func; |
| 959 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 963 | GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 964 | GLuint nr, const GLfloat *vp, |
| 965 | GLuint unpacked_size ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 966 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 967 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 968 | int offset = 0; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 969 | GLuint i, j; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 970 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 971 | assert(nr < _TNL_ATTRIB_MAX); |
| 972 | assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 973 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 974 | vtx->emit = choose_emit_func; |
| 975 | vtx->interp = choose_interp_func; |
| 976 | vtx->copy_pv = choose_copy_pv_func; |
| 977 | vtx->new_inputs = ~0; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 978 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 979 | for (j = 0, i = 0; i < nr; i++) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 980 | GLuint format = map[i].format; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 981 | if (format == EMIT_PAD) { |
| 982 | offset += map[i].offset; |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 983 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 984 | /* fprintf(stderr, "%d: pad %d, offset now %d\n", i, */ |
| 985 | /* map[i].offset, offset); */ |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 986 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 987 | } |
| 988 | else { |
| 989 | vtx->attr[j].attrib = map[i].attrib; |
| 990 | vtx->attr[j].vp = vp; |
| 991 | vtx->attr[j].insert = format_info[format].insert; |
| 992 | vtx->attr[j].extract = format_info[format].extract; |
| 993 | vtx->attr[j].vertattrsize = format_info[format].attrsize; |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 994 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 995 | if (unpacked_size) |
| 996 | vtx->attr[j].vertoffset = map[i].offset; |
| 997 | else |
| 998 | vtx->attr[j].vertoffset = offset; |
| 999 | |
| 1000 | /* fprintf(stderr, "%d: %s offset %d\n", i, */ |
| 1001 | /* format_info[format].name, vtx->attr[j].vertoffset); */ |
| 1002 | |
| 1003 | offset += format_info[format].attrsize; |
| 1004 | j++; |
| 1005 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1006 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1007 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 1008 | vtx->attr_count = j; |
| 1009 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1010 | if (unpacked_size) |
| 1011 | vtx->vertex_size = unpacked_size; |
| 1012 | else |
| 1013 | vtx->vertex_size = offset; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1014 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1015 | assert(vtx->vertex_size <= vtx->max_vertex_size); |
| 1016 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1017 | return vtx->vertex_size; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1022 | void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1023 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1024 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1025 | vtx->new_inputs |= newinputs; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1029 | |
| 1030 | void _tnl_build_vertices( GLcontext *ctx, |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 1031 | GLuint start, |
| 1032 | GLuint end, |
| 1033 | GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1034 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1035 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1036 | GLuint stride = vtx->vertex_size; |
| 1037 | GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1038 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1039 | newinputs |= vtx->new_inputs; |
| 1040 | vtx->new_inputs = 0; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1041 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1042 | if (newinputs) |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 1043 | vtx->emit( ctx, start, end, v ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1046 | |
| 1047 | void *_tnl_emit_vertices_to_buffer( GLcontext *ctx, |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 1048 | GLuint start, |
| 1049 | GLuint end, |
| 1050 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1051 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1052 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 1053 | vtx->emit( ctx, start, end, dest ); |
| 1054 | return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1057 | |
| 1058 | void _tnl_init_vertices( GLcontext *ctx, |
| 1059 | GLuint vb_size, |
| 1060 | GLuint max_vertex_size ) |
| 1061 | { |
| 1062 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1063 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1064 | _tnl_install_attrs( ctx, 0, 0, 0, 0 ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1065 | |
| 1066 | vtx->need_extras = GL_TRUE; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1067 | if (max_vertex_size > vtx->max_vertex_size) { |
| 1068 | _tnl_free_vertices( ctx ); |
| 1069 | vtx->max_vertex_size = max_vertex_size; |
| Brian Paul | cb7c689 | 2004-01-26 16:16:16 +0000 | [diff] [blame] | 1070 | vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 ); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1071 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | |
| 1075 | void _tnl_free_vertices( GLcontext *ctx ) |
| 1076 | { |
| 1077 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1078 | if (vtx->vertex_buf) { |
| 1079 | ALIGN_FREE(vtx->vertex_buf); |
| 1080 | vtx->vertex_buf = 0; |
| 1081 | } |
| 1082 | } |