| 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; |
| 412 | v[0]= 0; |
| 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 | |
| 436 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 437 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 438 | out[2] = (in[2] - vp[14]) / vp[10]; |
| 439 | out[3] = in[3]; |
| 440 | } |
| 441 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 442 | 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] | 443 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 444 | { |
| 445 | const GLfloat *in = (const GLfloat *)v; |
| 446 | const GLfloat * const vp = a->vp; |
| 447 | |
| 448 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 449 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 450 | out[2] = (in[2] - vp[14]) / vp[10]; |
| 451 | out[3] = 1; |
| 452 | } |
| 453 | |
| 454 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 455 | 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] | 456 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 457 | { |
| 458 | const GLfloat *in = (const GLfloat *)v; |
| 459 | const GLfloat * const vp = a->vp; |
| 460 | |
| 461 | out[0] = (in[0] - vp[12]) / vp[0]; |
| 462 | out[1] = (in[1] - vp[13]) / vp[5]; |
| 463 | out[2] = 0; |
| 464 | out[3] = 1; |
| 465 | } |
| 466 | |
| 467 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 468 | 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] | 469 | { |
| 470 | const GLfloat *in = (const GLfloat *)v; |
| 471 | |
| 472 | out[0] = in[0]; |
| 473 | out[1] = in[1]; |
| 474 | out[2] = in[2]; |
| 475 | out[3] = in[3]; |
| 476 | } |
| 477 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 478 | 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] | 479 | { |
| 480 | const GLfloat *in = (const GLfloat *)v; |
| 481 | |
| 482 | out[0] = in[0]; |
| 483 | out[1] = in[1]; |
| 484 | out[2] = in[3]; |
| 485 | out[3] = 1; |
| 486 | } |
| 487 | |
| 488 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 489 | 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] | 490 | { |
| 491 | const GLfloat *in = (const GLfloat *)v; |
| 492 | |
| 493 | out[0] = in[0]; |
| 494 | out[1] = in[1]; |
| 495 | out[2] = in[2]; |
| 496 | out[3] = 1; |
| 497 | } |
| 498 | |
| 499 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 500 | 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] | 501 | { |
| 502 | const GLfloat *in = (const GLfloat *)v; |
| 503 | |
| 504 | out[0] = in[0]; |
| 505 | out[1] = in[1]; |
| 506 | out[2] = 0; |
| 507 | out[3] = 1; |
| 508 | } |
| 509 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 510 | 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] | 511 | { |
| 512 | const GLfloat *in = (const GLfloat *)v; |
| 513 | |
| 514 | out[0] = in[0]; |
| 515 | out[1] = 0; |
| 516 | out[2] = 0; |
| 517 | out[3] = 1; |
| 518 | } |
| 519 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 520 | 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] | 521 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 522 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 523 | GLchan *c = (GLchan *)v; |
| 524 | |
| 525 | out[0] = CHAN_TO_FLOAT(c[0]); |
| 526 | out[1] = CHAN_TO_FLOAT(c[1]); |
| 527 | out[2] = CHAN_TO_FLOAT(c[2]); |
| 528 | out[3] = CHAN_TO_FLOAT(c[3]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 531 | 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] | 532 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 533 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 534 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| 535 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 536 | out[2] = UBYTE_TO_FLOAT(v[2]); |
| 537 | out[3] = UBYTE_TO_FLOAT(v[3]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 540 | 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] | 541 | const GLubyte *v ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 542 | { |
| 543 | out[2] = UBYTE_TO_FLOAT(v[0]); |
| 544 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 545 | out[0] = UBYTE_TO_FLOAT(v[2]); |
| 546 | out[3] = UBYTE_TO_FLOAT(v[3]); |
| 547 | } |
| 548 | |
| 549 | 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] | 550 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 551 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 552 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| 553 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 554 | out[2] = UBYTE_TO_FLOAT(v[2]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 555 | out[3] = 1; |
| 556 | } |
| 557 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 558 | 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] | 559 | const GLubyte *v ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 560 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 561 | out[2] = UBYTE_TO_FLOAT(v[0]); |
| 562 | out[1] = UBYTE_TO_FLOAT(v[1]); |
| 563 | out[0] = UBYTE_TO_FLOAT(v[2]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 564 | out[3] = 1; |
| 565 | } |
| 566 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 567 | 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] | 568 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 569 | out[0] = UBYTE_TO_FLOAT(v[0]); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 570 | out[1] = 0; |
| 571 | out[2] = 0; |
| 572 | out[3] = 1; |
| 573 | } |
| 574 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 575 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 576 | struct { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 577 | const char *name; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 578 | extract_func extract; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 579 | insert_func insert[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 580 | GLuint attrsize; |
| 581 | } format_info[EMIT_MAX] = { |
| 582 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 583 | { "1f", |
| 584 | extract_1f, |
| 585 | { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 586 | sizeof(GLfloat) }, |
| 587 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 588 | { "2f", |
| 589 | extract_2f, |
| 590 | { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 591 | 2 * sizeof(GLfloat) }, |
| 592 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 593 | { "3f", |
| 594 | extract_3f, |
| 595 | { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 596 | 3 * sizeof(GLfloat) }, |
| 597 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 598 | { "4f", |
| 599 | extract_4f, |
| 600 | { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 601 | 4 * sizeof(GLfloat) }, |
| 602 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 603 | { "2f_viewport", |
| 604 | extract_2f_viewport, |
| 605 | { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2, |
| 606 | insert_2f_viewport_2 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 607 | 2 * sizeof(GLfloat) }, |
| 608 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 609 | { "3f_viewport", |
| 610 | extract_3f_viewport, |
| 611 | { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3, |
| 612 | insert_3f_viewport_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 613 | 3 * sizeof(GLfloat) }, |
| 614 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 615 | { "4f_viewport", |
| 616 | extract_4f_viewport, |
| 617 | { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3, |
| 618 | insert_4f_viewport_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 619 | 4 * sizeof(GLfloat) }, |
| 620 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 621 | { "3f_xyw", |
| 622 | extract_3f_xyw, |
| 623 | { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err, |
| 624 | insert_3f_xyw_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 625 | 3 * sizeof(GLfloat) }, |
| 626 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 627 | { "1ub_1f", |
| 628 | extract_1ub_1f, |
| 629 | { 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] | 630 | sizeof(GLubyte) }, |
| 631 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 632 | { "3ub_3f_rgb", |
| 633 | extract_3ub_3f_rgb, |
| 634 | { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3, |
| 635 | insert_3ub_3f_rgb_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 636 | 3 * sizeof(GLubyte) }, |
| 637 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 638 | { "3ub_3f_bgr", |
| 639 | extract_3ub_3f_bgr, |
| 640 | { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3, |
| 641 | insert_3ub_3f_bgr_3 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 642 | 3 * sizeof(GLubyte) }, |
| 643 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 644 | { "4ub_4f_rgba", |
| 645 | extract_4ub_4f_rgba, |
| 646 | { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3, |
| 647 | insert_4ub_4f_rgba_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 648 | 4 * sizeof(GLubyte) }, |
| 649 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 650 | { "4ub_4f_bgra", |
| 651 | extract_4ub_4f_bgra, |
| 652 | { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3, |
| 653 | insert_4ub_4f_bgra_4 }, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 654 | 4 * sizeof(GLubyte) }, |
| 655 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 656 | { "4chan_4f_rgba", |
| 657 | extract_4chan_4f_rgba, |
| 658 | { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3, |
| 659 | insert_4chan_4f_rgba_4 }, |
| 660 | 4 * sizeof(GLchan) } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 661 | |
| 662 | }; |
| 663 | |
| 664 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 665 | /*********************************************************************** |
| 666 | * Generic (non-codegen) functions for whole vertices or groups of |
| 667 | * vertices |
| 668 | */ |
| 669 | |
| 670 | static void generic_emit( GLcontext *ctx, |
| 671 | GLuint start, GLuint end, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 672 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 673 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 674 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 675 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 676 | struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 677 | GLubyte *v = (GLubyte *)dest; |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 678 | GLuint i, j; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 679 | GLuint count = vtx->attr_count; |
| 680 | GLuint stride; |
| 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 | for (j = 0; j < count; j++) { |
| 683 | GLvector4f *vptr = VB->AttribPtr[a[j].attrib]; |
| 684 | a[j].inputstride = vptr->stride; |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 685 | a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 686 | a[j].emit = a[j].insert[vptr->size - 1]; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 689 | end -= start; |
| 690 | stride = vtx->vertex_size; |
| 691 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 692 | for (i = 0 ; i < end ; i++, v += stride) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 693 | for (j = 0; j < count; j++) { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 694 | GLfloat *in = (GLfloat *)a[j].inputptr; |
| 695 | a[j].inputptr += a[j].inputstride; |
| 696 | a[j].emit( &a[j], v + a[j].vertoffset, in ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | |
| 702 | static void generic_interp( GLcontext *ctx, |
| 703 | GLfloat t, |
| 704 | GLuint edst, GLuint eout, GLuint ein, |
| 705 | GLboolean force_boundary ) |
| 706 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 707 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 708 | struct vertex_buffer *VB = &tnl->vb; |
| 709 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 710 | GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size; |
| 711 | GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size; |
| 712 | GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 713 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 714 | int attr_count = vtx->attr_count; |
| 715 | int j; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 716 | |
| 717 | if (tnl->NeedNdcCoords) { |
| 718 | const GLfloat *dstclip = VB->ClipPtr->data[edst]; |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 719 | if (dstclip[3] != 0.0) { |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 720 | const GLfloat w = 1.0f / dstclip[3]; |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 721 | GLfloat pos[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 722 | |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 723 | pos[0] = dstclip[0] * w; |
| 724 | pos[1] = dstclip[1] * w; |
| 725 | pos[2] = dstclip[2] * w; |
| 726 | pos[3] = w; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 727 | |
| Keith Whitwell | fb2a95b | 2004-01-08 13:55:24 +0000 | [diff] [blame] | 728 | a[0].insert[4-1]( &a[0], vdst, pos ); |
| 729 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 730 | } |
| 731 | else { |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 732 | a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | |
| 736 | for (j = 1; j < attr_count; j++) { |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 737 | GLfloat fin[4], fout[4], fdst[4]; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 738 | |
| 739 | a[j].extract( &a[j], fin, vin + a[j].vertoffset ); |
| 740 | a[j].extract( &a[j], fout, vout + a[j].vertoffset ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 741 | |
| 742 | INTERP_F( t, fdst[3], fout[3], fin[3] ); |
| 743 | INTERP_F( t, fdst[2], fout[2], fin[2] ); |
| 744 | INTERP_F( t, fdst[1], fout[1], fin[1] ); |
| 745 | INTERP_F( t, fdst[0], fout[0], fin[0] ); |
| 746 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 747 | a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | /* Extract color attributes from one vertex and insert them into |
| 753 | * another. (Shortcircuit extract/insert with memcpy). |
| 754 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 755 | static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 756 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 757 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 758 | GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size; |
| 759 | GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 760 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 761 | int attr_count = vtx->attr_count; |
| 762 | int j; |
| 763 | |
| 764 | for (j = 0; j < attr_count; j++) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 765 | if (a[j].attrib == VERT_ATTRIB_COLOR0 || |
| 766 | a[j].attrib == VERT_ATTRIB_COLOR1) { |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 767 | |
| Brian Paul | 3663c0f | 2004-01-15 00:29:51 +0000 | [diff] [blame^] | 768 | _mesa_memcpy( vdst + a[j].vertoffset, |
| 769 | vsrc + a[j].vertoffset, |
| 770 | a[j].vertattrsize ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 771 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 775 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 776 | /* Helper functions for hardware which doesn't put back colors and/or |
| 777 | * edgeflags into vertices. |
| 778 | */ |
| 779 | static void generic_interp_extras( GLcontext *ctx, |
| 780 | GLfloat t, |
| 781 | GLuint dst, GLuint out, GLuint in, |
| 782 | GLboolean force_boundary ) |
| 783 | { |
| 784 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 785 | |
| 786 | if (VB->ColorPtr[1]) { |
| 787 | assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat)); |
| 788 | |
| 789 | INTERP_4F( t, |
| 790 | VB->ColorPtr[1]->data[dst], |
| 791 | VB->ColorPtr[1]->data[out], |
| 792 | VB->ColorPtr[1]->data[in] ); |
| 793 | |
| 794 | if (VB->SecondaryColorPtr[1]) { |
| 795 | INTERP_3F( t, |
| 796 | VB->SecondaryColorPtr[1]->data[dst], |
| 797 | VB->SecondaryColorPtr[1]->data[out], |
| 798 | VB->SecondaryColorPtr[1]->data[in] ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 801 | else if (VB->IndexPtr[1]) { |
| 802 | VB->IndexPtr[1]->data[dst][0] = LINTERP( t, |
| 803 | VB->IndexPtr[1]->data[out][0], |
| 804 | VB->IndexPtr[1]->data[in][0] ); |
| 805 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 806 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 807 | if (VB->EdgeFlag) { |
| 808 | VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary; |
| 809 | } |
| 810 | |
| 811 | generic_interp(ctx, t, dst, out, in, force_boundary); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 814 | static void generic_copy_pv_extras( GLcontext *ctx, |
| 815 | GLuint dst, GLuint src ) |
| 816 | { |
| 817 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 818 | |
| 819 | if (VB->ColorPtr[1]) { |
| 820 | COPY_4FV( VB->ColorPtr[1]->data[dst], |
| 821 | VB->ColorPtr[1]->data[src] ); |
| 822 | |
| 823 | if (VB->SecondaryColorPtr[1]) { |
| 824 | COPY_4FV( VB->SecondaryColorPtr[1]->data[dst], |
| 825 | VB->SecondaryColorPtr[1]->data[src] ); |
| 826 | } |
| 827 | } |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 828 | else if (VB->IndexPtr[1]) { |
| 829 | VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0]; |
| 830 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 831 | |
| 832 | _tnl_copy_pv(ctx, dst, src); |
| 833 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | /*********************************************************************** |
| 841 | * Build codegen functions or return generic ones: |
| 842 | */ |
| 843 | |
| 844 | |
| 845 | static void choose_emit_func( GLcontext *ctx, |
| 846 | GLuint start, GLuint end, |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 847 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 848 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 849 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 850 | vtx->emit = generic_emit; |
| 851 | vtx->emit( ctx, start, end, dest ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | |
| 855 | static void choose_interp_func( GLcontext *ctx, |
| 856 | GLfloat t, |
| 857 | GLuint edst, GLuint eout, GLuint ein, |
| 858 | GLboolean force_boundary ) |
| 859 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 860 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 861 | |
| 862 | if (vtx->need_extras && |
| 863 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| 864 | vtx->interp = generic_interp_extras; |
| 865 | } else { |
| 866 | vtx->interp = generic_interp; |
| 867 | } |
| 868 | |
| 869 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 873 | static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 874 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 875 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 876 | |
| 877 | if (vtx->need_extras && |
| 878 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| 879 | vtx->copy_pv = generic_copy_pv_extras; |
| 880 | } else { |
| 881 | vtx->copy_pv = generic_copy_pv; |
| 882 | } |
| 883 | |
| 884 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | |
| 888 | /*********************************************************************** |
| 889 | * Public entrypoints, mostly dispatch to the above: |
| 890 | */ |
| 891 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 892 | |
| 893 | /* Interpolate between two vertices to produce a third: |
| 894 | */ |
| 895 | void _tnl_interp( GLcontext *ctx, |
| 896 | GLfloat t, |
| 897 | GLuint edst, GLuint eout, GLuint ein, |
| 898 | GLboolean force_boundary ) |
| 899 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 900 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 901 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /* Copy colors from one vertex to another: |
| 905 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 906 | void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 907 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 908 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 909 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | |
| 913 | /* Extract a named attribute from a hardware vertex. Will have to |
| 914 | * reverse any viewport transformation, swizzling or other conversions |
| 915 | * which may have been applied: |
| 916 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 917 | void _tnl_get_attr( GLcontext *ctx, const void *vin, |
| 918 | GLenum attr, GLfloat *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 919 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 920 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 921 | const struct tnl_clipspace_attr *a = vtx->attr; |
| 922 | int attr_count = vtx->attr_count; |
| 923 | int j; |
| 924 | |
| 925 | for (j = 0; j < attr_count; j++) { |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 926 | if (a[j].attrib == (int)attr) { |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 927 | a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 928 | return; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /* Else return the value from ctx->Current |
| 933 | */ |
| Brian Paul | 3663c0f | 2004-01-15 00:29:51 +0000 | [diff] [blame^] | 934 | _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat)); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void *_tnl_get_vertex( GLcontext *ctx, GLuint nr ) |
| 938 | { |
| 939 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 940 | |
| 941 | return vtx->vertex_buf + nr * vtx->vertex_size; |
| 942 | } |
| 943 | |
| 944 | void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state ) |
| 945 | { |
| 946 | if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) { |
| 947 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 948 | vtx->new_inputs = ~0; |
| 949 | vtx->interp = choose_interp_func; |
| 950 | vtx->copy_pv = choose_copy_pv_func; |
| 951 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 955 | GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 956 | GLuint nr, const GLfloat *vp, |
| 957 | GLuint unpacked_size ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 958 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 959 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 960 | int offset = 0; |
| Karl Schultz | c6c4cd8 | 2004-01-13 01:11:09 +0000 | [diff] [blame] | 961 | GLuint i; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 962 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 963 | assert(nr < _TNL_ATTRIB_MAX); |
| 964 | assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 965 | |
| 966 | vtx->attr_count = nr; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 967 | vtx->emit = choose_emit_func; |
| 968 | vtx->interp = choose_interp_func; |
| 969 | vtx->copy_pv = choose_copy_pv_func; |
| 970 | vtx->new_inputs = ~0; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 971 | |
| 972 | for (i = 0; i < nr; i++) { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 973 | GLuint format = map[i].format; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 974 | vtx->attr[i].attrib = map[i].attrib; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 975 | vtx->attr[i].vp = vp; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 976 | vtx->attr[i].insert = format_info[format].insert; |
| 977 | vtx->attr[i].extract = format_info[format].extract; |
| 978 | vtx->attr[i].vertattrsize = format_info[format].attrsize; |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 979 | |
| 980 | if (unpacked_size) |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 981 | vtx->attr[i].vertoffset = map[i].offset; |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 982 | else |
| 983 | vtx->attr[i].vertoffset = offset; |
| 984 | |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 985 | /* fprintf(stderr, "%d: %s offset %d\n", i, */ |
| 986 | /* format_info[format].name, vtx->attr[i].vertoffset); */ |
| 987 | |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 988 | offset += format_info[format].attrsize; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 989 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 990 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 991 | if (unpacked_size) |
| 992 | vtx->vertex_size = unpacked_size; |
| 993 | else |
| 994 | vtx->vertex_size = offset; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 995 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 996 | assert(vtx->vertex_size <= vtx->max_vertex_size); |
| 997 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 998 | return vtx->vertex_size; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | |
| 1002 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1003 | void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1004 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1005 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1006 | vtx->new_inputs |= newinputs; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1010 | |
| 1011 | void _tnl_build_vertices( GLcontext *ctx, |
| 1012 | GLuint start, |
| 1013 | GLuint count, |
| 1014 | GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1015 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1016 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1017 | GLuint stride = vtx->vertex_size; |
| 1018 | GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1019 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1020 | newinputs |= vtx->new_inputs; |
| 1021 | vtx->new_inputs = 0; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1022 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1023 | if (newinputs) |
| 1024 | vtx->emit( ctx, start, count, v ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1027 | |
| 1028 | void *_tnl_emit_vertices_to_buffer( GLcontext *ctx, |
| 1029 | GLuint start, |
| 1030 | GLuint count, |
| 1031 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1032 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1033 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1034 | vtx->emit( ctx, start, count, dest ); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1035 | return (void *)((GLubyte *)dest + vtx->vertex_size * (count - start)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1038 | |
| 1039 | void _tnl_init_vertices( GLcontext *ctx, |
| 1040 | GLuint vb_size, |
| 1041 | GLuint max_vertex_size ) |
| 1042 | { |
| 1043 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1044 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1045 | _tnl_install_attrs( ctx, 0, 0, 0, 0 ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1046 | |
| 1047 | vtx->need_extras = GL_TRUE; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 1048 | if (max_vertex_size > vtx->max_vertex_size) { |
| 1049 | _tnl_free_vertices( ctx ); |
| 1050 | vtx->max_vertex_size = max_vertex_size; |
| 1051 | vtx->vertex_buf = (GLubyte *)ALIGN_MALLOC(vb_size * max_vertex_size, 32 ); |
| 1052 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | void _tnl_free_vertices( GLcontext *ctx ) |
| 1057 | { |
| 1058 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 1059 | if (vtx->vertex_buf) { |
| 1060 | ALIGN_FREE(vtx->vertex_buf); |
| 1061 | vtx->vertex_buf = 0; |
| 1062 | } |
| 1063 | } |