| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 1 | /* $Id: varray.c,v 1.24 2000/10/18 15:02:59 brianp Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 5 | * Version: 3.5 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
| Brian Paul | 4463a24 | 2000-01-13 00:25:22 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #ifdef PC_HEADER |
| 28 | #include "all.h" |
| 29 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 30 | #include "glheader.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 31 | #include "context.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 32 | #include "cva.h" |
| 33 | #include "enable.h" |
| 34 | #include "enums.h" |
| 35 | #include "dlist.h" |
| 36 | #include "light.h" |
| 37 | #include "macros.h" |
| 38 | #include "mmath.h" |
| 39 | #include "pipeline.h" |
| Brian Paul | ea39f04 | 2000-02-02 19:17:57 +0000 | [diff] [blame] | 40 | #include "state.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 41 | #include "texstate.h" |
| 42 | #include "translate.h" |
| 43 | #include "types.h" |
| 44 | #include "varray.h" |
| 45 | #include "vb.h" |
| 46 | #include "vbfill.h" |
| 47 | #include "vbrender.h" |
| 48 | #include "vbindirect.h" |
| 49 | #include "vbxform.h" |
| 50 | #include "xform.h" |
| Keith Whitwell | 485f040 | 1999-10-08 09:27:09 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 53 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 54 | |
| 55 | void |
| 56 | _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 57 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 58 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 59 | |
| 60 | if (size<2 || size>4) { |
| 61 | gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(size)" ); |
| 62 | return; |
| 63 | } |
| 64 | if (stride<0) { |
| 65 | gl_error( ctx, GL_INVALID_VALUE, "glVertexPointer(stride)" ); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API)) |
| 70 | fprintf(stderr, "glVertexPointer( sz %d type %s stride %d )\n", size, |
| 71 | gl_lookup_enum_by_nr( type ), |
| 72 | stride); |
| 73 | |
| 74 | ctx->Array.Vertex.StrideB = stride; |
| 75 | if (!stride) { |
| 76 | switch (type) { |
| 77 | case GL_SHORT: |
| 78 | ctx->Array.Vertex.StrideB = size*sizeof(GLshort); |
| 79 | break; |
| 80 | case GL_INT: |
| 81 | ctx->Array.Vertex.StrideB = size*sizeof(GLint); |
| 82 | break; |
| 83 | case GL_FLOAT: |
| 84 | ctx->Array.Vertex.StrideB = size*sizeof(GLfloat); |
| 85 | break; |
| 86 | case GL_DOUBLE: |
| 87 | ctx->Array.Vertex.StrideB = size*sizeof(GLdouble); |
| 88 | break; |
| 89 | default: |
| 90 | gl_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" ); |
| 91 | return; |
| 92 | } |
| 93 | } |
| 94 | ctx->Array.Vertex.Size = size; |
| 95 | ctx->Array.Vertex.Type = type; |
| 96 | ctx->Array.Vertex.Stride = stride; |
| 97 | ctx->Array.Vertex.Ptr = (void *) ptr; |
| 98 | ctx->Array.VertexFunc = gl_trans_4f_tab[size][TYPE_IDX(type)]; |
| 99 | ctx->Array.VertexEltFunc = gl_trans_elt_4f_tab[size][TYPE_IDX(type)]; |
| 100 | ctx->Array.NewArrayState |= VERT_OBJ_ANY; |
| 101 | ctx->NewState |= NEW_CLIENT_STATE; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 107 | void |
| 108 | _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 110 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 111 | |
| 112 | if (stride<0) { |
| 113 | gl_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" ); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API)) |
| 118 | fprintf(stderr, "glNormalPointer( type %s stride %d )\n", |
| 119 | gl_lookup_enum_by_nr( type ), |
| 120 | stride); |
| 121 | |
| 122 | ctx->Array.Normal.StrideB = stride; |
| 123 | if (!stride) { |
| 124 | switch (type) { |
| 125 | case GL_BYTE: |
| 126 | ctx->Array.Normal.StrideB = 3*sizeof(GLbyte); |
| 127 | break; |
| 128 | case GL_SHORT: |
| 129 | ctx->Array.Normal.StrideB = 3*sizeof(GLshort); |
| 130 | break; |
| 131 | case GL_INT: |
| 132 | ctx->Array.Normal.StrideB = 3*sizeof(GLint); |
| 133 | break; |
| 134 | case GL_FLOAT: |
| 135 | ctx->Array.Normal.StrideB = 3*sizeof(GLfloat); |
| 136 | break; |
| 137 | case GL_DOUBLE: |
| 138 | ctx->Array.Normal.StrideB = 3*sizeof(GLdouble); |
| 139 | break; |
| 140 | default: |
| 141 | gl_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" ); |
| 142 | return; |
| 143 | } |
| 144 | } |
| 145 | ctx->Array.Normal.Type = type; |
| 146 | ctx->Array.Normal.Stride = stride; |
| 147 | ctx->Array.Normal.Ptr = (void *) ptr; |
| 148 | ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(type)]; |
| 149 | ctx->Array.NormalEltFunc = gl_trans_elt_3f_tab[TYPE_IDX(type)]; |
| 150 | ctx->Array.NewArrayState |= VERT_NORM; |
| 151 | ctx->NewState |= NEW_CLIENT_STATE; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 156 | void |
| 157 | _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 158 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 159 | GET_CURRENT_CONTEXT(ctx); |
| 160 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 161 | if (size<3 || size>4) { |
| 162 | gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" ); |
| 163 | return; |
| 164 | } |
| 165 | if (stride<0) { |
| 166 | gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" ); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API)) |
| 171 | fprintf(stderr, "glColorPointer( sz %d type %s stride %d )\n", size, |
| 172 | gl_lookup_enum_by_nr( type ), |
| 173 | stride); |
| 174 | |
| 175 | ctx->Array.Color.StrideB = stride; |
| 176 | if (!stride) { |
| 177 | switch (type) { |
| 178 | case GL_BYTE: |
| 179 | ctx->Array.Color.StrideB = size*sizeof(GLbyte); |
| 180 | break; |
| 181 | case GL_UNSIGNED_BYTE: |
| 182 | ctx->Array.Color.StrideB = size*sizeof(GLubyte); |
| 183 | break; |
| 184 | case GL_SHORT: |
| 185 | ctx->Array.Color.StrideB = size*sizeof(GLshort); |
| 186 | break; |
| 187 | case GL_UNSIGNED_SHORT: |
| 188 | ctx->Array.Color.StrideB = size*sizeof(GLushort); |
| 189 | break; |
| 190 | case GL_INT: |
| 191 | ctx->Array.Color.StrideB = size*sizeof(GLint); |
| 192 | break; |
| 193 | case GL_UNSIGNED_INT: |
| 194 | ctx->Array.Color.StrideB = size*sizeof(GLuint); |
| 195 | break; |
| 196 | case GL_FLOAT: |
| 197 | ctx->Array.Color.StrideB = size*sizeof(GLfloat); |
| 198 | break; |
| 199 | case GL_DOUBLE: |
| 200 | ctx->Array.Color.StrideB = size*sizeof(GLdouble); |
| 201 | break; |
| 202 | default: |
| 203 | gl_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" ); |
| 204 | return; |
| 205 | } |
| 206 | } |
| 207 | ctx->Array.Color.Size = size; |
| 208 | ctx->Array.Color.Type = type; |
| 209 | ctx->Array.Color.Stride = stride; |
| 210 | ctx->Array.Color.Ptr = (void *) ptr; |
| 211 | ctx->Array.ColorFunc = gl_trans_4ub_tab[size][TYPE_IDX(type)]; |
| 212 | ctx->Array.ColorEltFunc = gl_trans_elt_4ub_tab[size][TYPE_IDX(type)]; |
| 213 | ctx->Array.NewArrayState |= VERT_RGBA; |
| 214 | ctx->NewState |= NEW_CLIENT_STATE; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 219 | void |
| 220 | _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 221 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 222 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 223 | |
| 224 | if (stride<0) { |
| 225 | gl_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" ); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | ctx->Array.Index.StrideB = stride; |
| 230 | if (!stride) { |
| 231 | switch (type) { |
| 232 | case GL_UNSIGNED_BYTE: |
| 233 | ctx->Array.Index.StrideB = sizeof(GLubyte); |
| 234 | break; |
| 235 | case GL_SHORT: |
| 236 | ctx->Array.Index.StrideB = sizeof(GLshort); |
| 237 | break; |
| 238 | case GL_INT: |
| 239 | ctx->Array.Index.StrideB = sizeof(GLint); |
| 240 | break; |
| 241 | case GL_FLOAT: |
| 242 | ctx->Array.Index.StrideB = sizeof(GLfloat); |
| 243 | break; |
| 244 | case GL_DOUBLE: |
| 245 | ctx->Array.Index.StrideB = sizeof(GLdouble); |
| 246 | break; |
| 247 | default: |
| 248 | gl_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" ); |
| 249 | return; |
| 250 | } |
| 251 | } |
| 252 | ctx->Array.Index.Type = type; |
| 253 | ctx->Array.Index.Stride = stride; |
| 254 | ctx->Array.Index.Ptr = (void *) ptr; |
| 255 | ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(type)]; |
| 256 | ctx->Array.IndexEltFunc = gl_trans_elt_1ui_tab[TYPE_IDX(type)]; |
| 257 | ctx->Array.NewArrayState |= VERT_INDEX; |
| 258 | ctx->NewState |= NEW_CLIENT_STATE; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 263 | void |
| 264 | _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 265 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 266 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 267 | GLuint texUnit; |
| 268 | |
| Brian Paul | 45224fa | 1999-09-07 22:31:30 +0000 | [diff] [blame] | 269 | texUnit = ctx->Array.ActiveTexture; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 270 | |
| 271 | if (size<1 || size>4) { |
| 272 | gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" ); |
| 273 | return; |
| 274 | } |
| 275 | if (stride<0) { |
| 276 | gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" ); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API)) |
| 281 | fprintf(stderr, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n", |
| 282 | texUnit, |
| 283 | size, |
| 284 | gl_lookup_enum_by_nr( type ), |
| 285 | stride); |
| 286 | |
| 287 | ctx->Array.TexCoord[texUnit].StrideB = stride; |
| 288 | if (!stride) { |
| 289 | switch (type) { |
| 290 | case GL_SHORT: |
| 291 | ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLshort); |
| 292 | break; |
| 293 | case GL_INT: |
| 294 | ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLint); |
| 295 | break; |
| 296 | case GL_FLOAT: |
| 297 | ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLfloat); |
| 298 | break; |
| 299 | case GL_DOUBLE: |
| 300 | ctx->Array.TexCoord[texUnit].StrideB = size*sizeof(GLdouble); |
| 301 | break; |
| 302 | default: |
| 303 | gl_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" ); |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | ctx->Array.TexCoord[texUnit].Size = size; |
| 308 | ctx->Array.TexCoord[texUnit].Type = type; |
| 309 | ctx->Array.TexCoord[texUnit].Stride = stride; |
| 310 | ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr; |
| 311 | |
| 312 | ctx->Array.TexCoordFunc[texUnit] = gl_trans_4f_tab[size][TYPE_IDX(type)]; |
| 313 | ctx->Array.TexCoordEltFunc[texUnit] = gl_trans_elt_4f_tab[size][TYPE_IDX(type)]; |
| 314 | ctx->Array.NewArrayState |= PIPE_TEX(texUnit); |
| 315 | ctx->NewState |= NEW_CLIENT_STATE; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 321 | void |
| 322 | _mesa_EdgeFlagPointer(GLsizei stride, const void *vptr) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 323 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 324 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 325 | const GLboolean *ptr = (GLboolean *)vptr; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 326 | |
| 327 | if (stride<0) { |
| 328 | gl_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" ); |
| 329 | return; |
| 330 | } |
| 331 | ctx->Array.EdgeFlag.Stride = stride; |
| 332 | ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean); |
| 333 | ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr; |
| 334 | if (stride != sizeof(GLboolean)) { |
| 335 | ctx->Array.EdgeFlagFunc = gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)]; |
| 336 | } else { |
| 337 | ctx->Array.EdgeFlagFunc = 0; |
| 338 | } |
| 339 | ctx->Array.EdgeFlagEltFunc = gl_trans_elt_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)]; |
| 340 | ctx->Array.NewArrayState |= VERT_EDGE; |
| 341 | ctx->NewState |= NEW_CLIENT_STATE; |
| 342 | } |
| 343 | |
| 344 | |
| Brian Paul | 4463a24 | 2000-01-13 00:25:22 +0000 | [diff] [blame] | 345 | #if 0 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 346 | /* Called only from gl_DrawElements |
| 347 | */ |
| Brian Paul | 4463a24 | 2000-01-13 00:25:22 +0000 | [diff] [blame] | 348 | static void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 349 | { |
| 350 | switch (type) { |
| 351 | case GL_UNSIGNED_BYTE: |
| 352 | ctx->CVA.Elt.StrideB = sizeof(GLubyte); |
| 353 | break; |
| 354 | case GL_UNSIGNED_SHORT: |
| 355 | ctx->CVA.Elt.StrideB = sizeof(GLushort); |
| 356 | break; |
| 357 | case GL_UNSIGNED_INT: |
| 358 | ctx->CVA.Elt.StrideB = sizeof(GLuint); |
| 359 | break; |
| 360 | default: |
| 361 | gl_error( ctx, GL_INVALID_ENUM, "glEltPointer(type)" ); |
| 362 | return; |
| 363 | } |
| 364 | ctx->CVA.Elt.Type = type; |
| 365 | ctx->CVA.Elt.Stride = 0; |
| 366 | ctx->CVA.Elt.Ptr = (void *) ptr; |
| 367 | ctx->CVA.EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)]; |
| 368 | ctx->Array.NewArrayState |= VERT_ELT; /* ??? */ |
| 369 | } |
| Brian Paul | 4463a24 | 2000-01-13 00:25:22 +0000 | [diff] [blame] | 370 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 371 | |
| 372 | |
| Brian Paul | 1f0e213 | 2000-06-12 15:30:51 +0000 | [diff] [blame] | 373 | |
| 374 | void |
| 375 | _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 376 | GLsizei count, const GLvoid *ptr) |
| 377 | { |
| 378 | (void) count; |
| 379 | _mesa_VertexPointer(size, type, stride, ptr); |
| 380 | } |
| 381 | |
| 382 | |
| 383 | void |
| 384 | _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 385 | const GLvoid *ptr) |
| 386 | { |
| 387 | (void) count; |
| 388 | _mesa_NormalPointer(type, stride, ptr); |
| 389 | } |
| 390 | |
| 391 | |
| 392 | void |
| 393 | _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, |
| 394 | const GLvoid *ptr) |
| 395 | { |
| 396 | (void) count; |
| 397 | _mesa_ColorPointer(size, type, stride, ptr); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | void |
| 402 | _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, |
| 403 | const GLvoid *ptr) |
| 404 | { |
| 405 | (void) count; |
| 406 | _mesa_IndexPointer(type, stride, ptr); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | void |
| 411 | _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, |
| 412 | GLsizei count, const GLvoid *ptr) |
| 413 | { |
| 414 | (void) count; |
| 415 | _mesa_TexCoordPointer(size, type, stride, ptr); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | void |
| 420 | _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) |
| 421 | { |
| 422 | (void) count; |
| 423 | _mesa_EdgeFlagPointer(stride, ptr); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 430 | /* KW: Batch function to exec all the array elements in the input |
| 431 | * buffer prior to transform. Done only the first time a vertex |
| 432 | * buffer is executed or compiled. |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 433 | * |
| 434 | * KW: Have to do this after each glEnd if cva isn't active. (also |
| 435 | * have to do it after each full buffer) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 436 | */ |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 437 | void gl_exec_array_elements( GLcontext *ctx, struct immediate *IM, |
| 438 | GLuint start, |
| 439 | GLuint count) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 440 | { |
| 441 | GLuint *flags = IM->Flag; |
| 442 | GLuint *elts = IM->Elt; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 443 | GLuint translate = ctx->Array.Flags; |
| 444 | GLuint i; |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 445 | |
| 446 | if (MESA_VERBOSE&VERBOSE_IMMEDIATE) |
| 447 | fprintf(stderr, "exec_array_elements %d .. %d\n", start, count); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 448 | |
| 449 | if (translate & VERT_OBJ_ANY) |
| 450 | (ctx->Array.VertexEltFunc)( IM->Obj, |
| 451 | &ctx->Array.Vertex, |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 452 | flags, elts, (VERT_ELT|VERT_OBJ_ANY), |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 453 | start, count); |
| 454 | |
| 455 | if (translate & VERT_NORM) |
| 456 | (ctx->Array.NormalEltFunc)( IM->Normal, |
| 457 | &ctx->Array.Normal, |
| 458 | flags, elts, (VERT_ELT|VERT_NORM), |
| 459 | start, count); |
| 460 | |
| 461 | if (translate & VERT_EDGE) |
| 462 | (ctx->Array.EdgeFlagEltFunc)( IM->EdgeFlag, |
| 463 | &ctx->Array.EdgeFlag, |
| 464 | flags, elts, (VERT_ELT|VERT_EDGE), |
| 465 | start, count); |
| 466 | |
| 467 | if (translate & VERT_RGBA) |
| 468 | (ctx->Array.ColorEltFunc)( IM->Color, |
| 469 | &ctx->Array.Color, |
| 470 | flags, elts, (VERT_ELT|VERT_RGBA), |
| 471 | start, count); |
| 472 | |
| 473 | if (translate & VERT_INDEX) |
| 474 | (ctx->Array.IndexEltFunc)( IM->Index, |
| 475 | &ctx->Array.Index, |
| 476 | flags, elts, (VERT_ELT|VERT_INDEX), |
| 477 | start, count); |
| 478 | |
| 479 | if (translate & VERT_TEX0_ANY) |
| 480 | (ctx->Array.TexCoordEltFunc[0])( IM->TexCoord[0], |
| 481 | &ctx->Array.TexCoord[0], |
| 482 | flags, elts, (VERT_ELT|VERT_TEX0_ANY), |
| 483 | start, count); |
| 484 | |
| 485 | if (translate & VERT_TEX1_ANY) |
| 486 | (ctx->Array.TexCoordEltFunc[1])( IM->TexCoord[1], |
| 487 | &ctx->Array.TexCoord[1], |
| 488 | flags, elts, (VERT_ELT|VERT_TEX1_ANY), |
| 489 | start, count); |
| 490 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 491 | #if MAX_TEXTURE_UNITS > 2 |
| 492 | if (translate & VERT_TEX2_ANY) |
| 493 | (ctx->Array.TexCoordEltFunc[1])( IM->TexCoord[2], |
| 494 | &ctx->Array.TexCoord[2], |
| 495 | flags, elts, (VERT_ELT|VERT_TEX2_ANY), |
| 496 | start, count); |
| 497 | #endif |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 498 | |
| 499 | for (i = start ; i < count ; i++) |
| Keith Whitwell | 6adfc6b | 1999-11-09 17:26:15 +0000 | [diff] [blame] | 500 | if (flags[i] & VERT_ELT) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 501 | flags[i] |= translate; |
| Keith Whitwell | 6adfc6b | 1999-11-09 17:26:15 +0000 | [diff] [blame] | 502 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
| 506 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 507 | /* Enough funny business going on in here it might be quicker to use a |
| 508 | * function pointer. |
| 509 | */ |
| 510 | #define ARRAY_ELT( IM, i ) \ |
| 511 | { \ |
| 512 | GLuint count = IM->Count; \ |
| 513 | IM->Elt[count] = i; \ |
| 514 | IM->Flag[count] = ((IM->Flag[count] & IM->ArrayAndFlags) | \ |
| 515 | VERT_ELT); \ |
| 516 | IM->FlushElt |= IM->ArrayEltFlush; \ |
| 517 | IM->Count = count += IM->ArrayIncr; \ |
| 518 | if (count == VB_MAX) \ |
| Brian Paul | 038573a | 2000-09-11 18:49:06 +0000 | [diff] [blame] | 519 | _mesa_maybe_transform_vb( IM ); \ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
| 523 | void |
| 524 | _mesa_ArrayElement( GLint i ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 525 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 526 | GET_IMMEDIATE; |
| 527 | ARRAY_ELT( IM, i ); |
| 528 | } |
| 529 | |
| 530 | |
| Brian Paul | 4463a24 | 2000-01-13 00:25:22 +0000 | [diff] [blame] | 531 | static void |
| 532 | gl_ArrayElement( GLcontext *CC, GLint i ) |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 533 | { |
| 534 | struct immediate *im = CC->input; |
| 535 | ARRAY_ELT( im, i ); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | |
| 540 | void |
| 541 | _mesa_DrawArrays(GLenum mode, GLint start, GLsizei count) |
| 542 | { |
| 543 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 544 | struct vertex_buffer *VB = ctx->VB; |
| 545 | GLint i; |
| 546 | |
| 547 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawArrays"); |
| 548 | |
| 549 | if (count<0) { |
| 550 | gl_error( ctx, GL_INVALID_VALUE, "glDrawArrays(count)" ); |
| 551 | return; |
| 552 | } |
| 553 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 554 | if (!ctx->CompileFlag && ctx->Array.Vertex.Enabled) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 555 | GLint remaining = count; |
| 556 | GLint i; |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 557 | struct gl_client_array *Normal; |
| 558 | struct gl_client_array *Color; |
| 559 | struct gl_client_array *Index; |
| 560 | struct gl_client_array *TexCoord[MAX_TEXTURE_UNITS]; |
| 561 | struct gl_client_array *EdgeFlag; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 562 | struct immediate *IM = VB->IM; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 563 | struct gl_pipeline *elt = &ctx->CVA.elt; |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 564 | GLboolean relock; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 565 | GLuint fallback, required; |
| 566 | |
| 567 | if (ctx->NewState) |
| 568 | gl_update_state( ctx ); |
| 569 | |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 570 | /* Just turn off cva on this path. Could be useful for multipass |
| 571 | * rendering to keep it turned on. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 572 | */ |
| 573 | relock = ctx->CompileCVAFlag; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 574 | |
| Keith Whitwell | 784657c | 1999-11-19 00:03:27 +0000 | [diff] [blame] | 575 | if (relock) { |
| 576 | ctx->CompileCVAFlag = 0; |
| 577 | elt->pipeline_valid = 0; |
| 578 | } |
| 579 | |
| 580 | if (!elt->pipeline_valid) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 581 | gl_build_immediate_pipeline( ctx ); |
| 582 | |
| 583 | required = elt->inputs; |
| 584 | fallback = (elt->inputs & ~ctx->Array.Summary); |
| 585 | |
| Keith Whitwell | 784657c | 1999-11-19 00:03:27 +0000 | [diff] [blame] | 586 | /* The translate function doesn't do anything about size. It |
| 587 | * just ensures that type and stride come out right. |
| 588 | */ |
| 589 | IM->v.Obj.size = ctx->Array.Vertex.Size; |
| 590 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 591 | if (required & VERT_RGBA) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 592 | Color = &ctx->Array.Color; |
| 593 | if (fallback & VERT_RGBA) { |
| 594 | Color = &ctx->Fallback.Color; |
| 595 | ctx->Array.ColorFunc = |
| 596 | gl_trans_4ub_tab[4][TYPE_IDX(GL_UNSIGNED_BYTE)]; |
| 597 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 600 | if (required & VERT_INDEX) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 601 | Index = &ctx->Array.Index; |
| 602 | if (fallback & VERT_INDEX) { |
| 603 | Index = &ctx->Fallback.Index; |
| 604 | ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(GL_UNSIGNED_INT)]; |
| 605 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 608 | for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 609 | GLuint flag = VERT_TEX_ANY(i); |
| 610 | |
| 611 | if (required & flag) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 612 | TexCoord[i] = &ctx->Array.TexCoord[i]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 613 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 614 | if (fallback & flag) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 615 | TexCoord[i] = &ctx->Fallback.TexCoord[i]; |
| 616 | TexCoord[i]->Size = gl_texcoord_size( ctx->Current.Flag, i ); |
| 617 | |
| 618 | ctx->Array.TexCoordFunc[i] = |
| 619 | gl_trans_4f_tab[TexCoord[i]->Size][TYPE_IDX(GL_FLOAT)]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 620 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 624 | if (ctx->Array.Flags != ctx->Array.Flag[0]) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 625 | for (i = 0 ; i < VB_MAX ; i++) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 626 | ctx->Array.Flag[i] = ctx->Array.Flags; |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 627 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 628 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 629 | if (required & VERT_NORM) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 630 | Normal = &ctx->Array.Normal; |
| 631 | if (fallback & VERT_NORM) { |
| 632 | Normal = &ctx->Fallback.Normal; |
| 633 | ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(GL_FLOAT)]; |
| 634 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 637 | if ( required & VERT_EDGE ) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 638 | if (mode == GL_TRIANGLES || |
| 639 | mode == GL_QUADS || |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 640 | mode == GL_POLYGON) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 641 | EdgeFlag = &ctx->Array.EdgeFlag; |
| 642 | if (fallback & VERT_EDGE) { |
| 643 | EdgeFlag = &ctx->Fallback.EdgeFlag; |
| 644 | ctx->Array.EdgeFlagFunc = |
| 645 | gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)]; |
| 646 | } |
| 647 | } |
| 648 | else |
| 649 | required &= ~VERT_EDGE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | VB->Primitive = IM->Primitive; |
| 653 | VB->NextPrimitive = IM->NextPrimitive; |
| 654 | VB->MaterialMask = IM->MaterialMask; |
| 655 | VB->Material = IM->Material; |
| 656 | VB->BoundsPtr = 0; |
| 657 | |
| 658 | while (remaining > 0) { |
| 659 | GLint vbspace = VB_MAX - VB_START; |
| 660 | GLuint count, n; |
| 661 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 662 | if (vbspace >= remaining) { |
| 663 | n = remaining; |
| 664 | VB->LastPrimitive = VB_START + n; |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 665 | } |
| 666 | else { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 667 | n = vbspace; |
| 668 | VB->LastPrimitive = VB_START; |
| 669 | } |
| 670 | |
| 671 | VB->CullMode = 0; |
| 672 | |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 673 | ctx->Array.VertexFunc( IM->Obj + VB_START, |
| 674 | &ctx->Array.Vertex, start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 675 | |
| 676 | if (required & VERT_NORM) { |
| 677 | ctx->Array.NormalFunc( IM->Normal + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 678 | Normal, start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | if (required & VERT_EDGE) { |
| 682 | ctx->Array.EdgeFlagFunc( IM->EdgeFlag + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 683 | EdgeFlag, start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | if (required & VERT_RGBA) { |
| 687 | ctx->Array.ColorFunc( IM->Color + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 688 | Color, start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | if (required & VERT_INDEX) { |
| 692 | ctx->Array.IndexFunc( IM->Index + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 693 | Index, start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | if (required & VERT_TEX0_ANY) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 697 | IM->v.TexCoord[0].size = TexCoord[0]->Size; |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 698 | ctx->Array.TexCoordFunc[0]( IM->TexCoord[0] + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 699 | TexCoord[0], start, n ); |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | if (required & VERT_TEX1_ANY) { |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 703 | IM->v.TexCoord[1].size = TexCoord[1]->Size; |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 704 | ctx->Array.TexCoordFunc[1]( IM->TexCoord[1] + VB_START, |
| Keith Whitwell | 6a9f16e | 1999-11-09 17:00:25 +0000 | [diff] [blame] | 705 | TexCoord[1], start, n ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 706 | } |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 707 | #if MAX_TEXTURE_UNITS > 2 |
| 708 | if (required & VERT_TEX2_ANY) { |
| 709 | IM->v.TexCoord[2].size = TexCoord[2]->Size; |
| 710 | ctx->Array.TexCoordFunc[2]( IM->TexCoord[2] + VB_START, |
| 711 | TexCoord[2], start, n ); |
| 712 | } |
| 713 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 714 | |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 715 | VB->ObjPtr = &IM->v.Obj; |
| 716 | VB->NormalPtr = &IM->v.Normal; |
| 717 | VB->ColorPtr = &IM->v.Color; |
| 718 | VB->Color[0] = VB->Color[1] = VB->ColorPtr; |
| 719 | VB->IndexPtr = &IM->v.Index; |
| 720 | VB->EdgeFlagPtr = &IM->v.EdgeFlag; |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 721 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| 722 | VB->TexCoordPtr[i] = &IM->v.TexCoord[i]; |
| 723 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 724 | |
| 725 | VB->Flag = ctx->Array.Flag; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 726 | VB->OrFlag = ctx->Array.Flags; |
| 727 | |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 728 | VB->Start = IM->Start = VB_START; |
| 729 | count = VB->Count = IM->Count = VB_START + n; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 730 | |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 731 | #define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 732 | |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 733 | RESET_VEC(IM->v.Obj, (GLfloat *), VB_START, count); |
| 734 | RESET_VEC(IM->v.Normal, (GLfloat *), VB_START, count); |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 735 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| 736 | RESET_VEC(IM->v.TexCoord[i], (GLfloat *), VB_START, count); |
| 737 | } |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 738 | RESET_VEC(IM->v.Index, &, VB_START, count); |
| 739 | RESET_VEC(IM->v.Elt, &, VB_START, count); |
| 740 | RESET_VEC(IM->v.EdgeFlag, &, VB_START, count); |
| 741 | RESET_VEC(IM->v.Color, (GLubyte *), VB_START, count); |
| 742 | RESET_VEC(VB->Clip, (GLfloat *), VB_START, count); |
| 743 | RESET_VEC(VB->Eye, (GLfloat *), VB_START, count); |
| 744 | RESET_VEC(VB->Win, (GLfloat *), VB_START, count); |
| 745 | RESET_VEC(VB->BColor, (GLubyte *), VB_START, count); |
| 746 | RESET_VEC(VB->BIndex, &, VB_START, count); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 747 | |
| 748 | VB->NextPrimitive[VB->CopyStart] = VB->Count; |
| 749 | VB->Primitive[VB->CopyStart] = mode; |
| Keith Whitwell | e828bc8 | 2000-02-25 03:55:39 +0000 | [diff] [blame] | 750 | ctx->Array.Flag[count] |= VERT_END_VB; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 751 | |
| 752 | /* Transform and render. |
| 753 | */ |
| 754 | gl_run_pipeline( VB ); |
| 755 | gl_reset_vb( VB ); |
| 756 | |
| 757 | ctx->Array.Flag[count] = ctx->Array.Flags; |
| 758 | ctx->Array.Flag[VB_START] = ctx->Array.Flags; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 759 | |
| 760 | start += n; |
| 761 | remaining -= n; |
| 762 | } |
| 763 | |
| Keith Whitwell | 784657c | 1999-11-19 00:03:27 +0000 | [diff] [blame] | 764 | gl_reset_input( ctx ); |
| 765 | |
| 766 | if (relock) { |
| 767 | ctx->CompileCVAFlag = relock; |
| 768 | elt->pipeline_valid = 0; |
| 769 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 770 | } |
| 771 | else if (ctx->Array.Vertex.Enabled) |
| 772 | { |
| 773 | /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These |
| 774 | * could be handled by the above code, but it gets a little |
| Keith Whitwell | 20f6c10 | 1999-11-09 10:12:34 +0000 | [diff] [blame] | 775 | * complex. The generated list is still of good quality |
| 776 | * this way. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 777 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 778 | gl_Begin( ctx, mode ); |
| 779 | for (i=0;i<count;i++) { |
| 780 | gl_ArrayElement( ctx, start+i ); |
| 781 | } |
| 782 | gl_End( ctx ); |
| 783 | } |
| 784 | else |
| 785 | { |
| 786 | /* The degenerate case where vertices are not enabled - only |
| 787 | * need to process the very final array element, as all of the |
| 788 | * preceding ones would be overwritten anyway. |
| 789 | */ |
| 790 | gl_Begin( ctx, mode ); |
| 791 | gl_ArrayElement( ctx, start+count ); |
| 792 | gl_End( ctx ); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | |
| 797 | |
| 798 | /* KW: Exactly fakes the effects of calling glArrayElement multiple times. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 799 | */ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 800 | #if 1 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 801 | #define DRAW_ELT(FUNC, TYPE) \ |
| 802 | static void FUNC( GLcontext *ctx, GLenum mode, \ |
| 803 | TYPE *indices, GLuint count ) \ |
| 804 | { \ |
| 805 | GLuint i,j; \ |
| 806 | \ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 807 | gl_Begin( ctx, mode ); \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 808 | \ |
| 809 | for (j = 0 ; j < count ; ) { \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 810 | struct immediate *IM = ctx->input; \ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 811 | GLuint start = IM->Start; \ |
| 812 | GLuint nr = MIN2( VB_MAX, count - j + start ); \ |
| 813 | GLuint sf = IM->Flag[start]; \ |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 814 | IM->FlushElt |= IM->ArrayEltFlush; \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 815 | \ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 816 | for (i = start ; i < nr ; i++) { \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 817 | IM->Elt[i] = (GLuint) *indices++; \ |
| Keith Whitwell | 2be79c1 | 1999-08-26 14:50:49 +0000 | [diff] [blame] | 818 | IM->Flag[i] = VERT_ELT; \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 819 | } \ |
| 820 | \ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 821 | if (j == 0) IM->Flag[start] |= sf; \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 822 | \ |
| 823 | IM->Count = nr; \ |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 824 | j += nr - start; \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 825 | \ |
| Brian Paul | 038573a | 2000-09-11 18:49:06 +0000 | [diff] [blame] | 826 | if (j == count) \ |
| 827 | gl_End( ctx ); \ |
| 828 | _mesa_maybe_transform_vb( IM ); \ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 829 | } \ |
| 830 | } |
| Keith Whitwell | 30990a6 | 1999-11-04 19:42:28 +0000 | [diff] [blame] | 831 | #else |
| 832 | #define DRAW_ELT(FUNC, TYPE) \ |
| 833 | static void FUNC( GLcontext *ctx, GLenum mode, \ |
| 834 | TYPE *indices, GLuint count ) \ |
| 835 | { \ |
| 836 | int i; \ |
| 837 | glBegin(mode); \ |
| 838 | for (i = 0 ; i < count ; i++) \ |
| 839 | glArrayElement( indices[i] ); \ |
| 840 | glEnd(); \ |
| 841 | } |
| 842 | #endif |
| 843 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 844 | |
| 845 | DRAW_ELT( draw_elt_ubyte, GLubyte ) |
| 846 | DRAW_ELT( draw_elt_ushort, GLushort ) |
| 847 | DRAW_ELT( draw_elt_uint, GLuint ) |
| 848 | |
| 849 | |
| 850 | static GLuint natural_stride[0x10] = |
| 851 | { |
| 852 | sizeof(GLbyte), /* 0 */ |
| 853 | sizeof(GLubyte), /* 1 */ |
| 854 | sizeof(GLshort), /* 2 */ |
| 855 | sizeof(GLushort), /* 3 */ |
| 856 | sizeof(GLint), /* 4 */ |
| 857 | sizeof(GLuint), /* 5 */ |
| 858 | sizeof(GLfloat), /* 6 */ |
| 859 | 2 * sizeof(GLbyte), /* 7 */ |
| 860 | 3 * sizeof(GLbyte), /* 8 */ |
| 861 | 4 * sizeof(GLbyte), /* 9 */ |
| 862 | sizeof(GLdouble), /* a */ |
| 863 | 0, /* b */ |
| 864 | 0, /* c */ |
| 865 | 0, /* d */ |
| 866 | 0, /* e */ |
| 867 | 0 /* f */ |
| 868 | }; |
| 869 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 870 | |
| 871 | void |
| 872 | _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 873 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 874 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 875 | struct gl_cva *cva; |
| 876 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 877 | cva = &ctx->CVA; |
| 878 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawElements"); |
| 879 | |
| Keith Whitwell | d471473 | 1999-10-19 18:37:02 +0000 | [diff] [blame] | 880 | if (count <= 0) { |
| 881 | if (count < 0) |
| 882 | gl_error( ctx, GL_INVALID_VALUE, "glDrawElements(count)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 883 | return; |
| 884 | } |
| 885 | |
| Keith Whitwell | e828bc8 | 2000-02-25 03:55:39 +0000 | [diff] [blame] | 886 | if (mode < 0 || mode > GL_POLYGON) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 887 | gl_error( ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" ); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | if (type != GL_UNSIGNED_INT && type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT) |
| 892 | { |
| 893 | gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | if (ctx->NewState) |
| 898 | gl_update_state(ctx); |
| 899 | |
| 900 | if (ctx->CompileCVAFlag) |
| 901 | { |
| 902 | #if defined(MESA_CVA_PROF) |
| 903 | force_init_prof(); |
| 904 | #endif |
| 905 | |
| 906 | /* Treat VERT_ELT like a special client array. |
| 907 | */ |
| 908 | ctx->Array.NewArrayState |= VERT_ELT; |
| 909 | ctx->Array.Summary |= VERT_ELT; |
| 910 | ctx->Array.Flags |= VERT_ELT; |
| 911 | |
| 912 | cva->elt_mode = mode; |
| 913 | cva->elt_count = count; |
| 914 | cva->Elt.Type = type; |
| 915 | cva->Elt.Ptr = (void *) indices; |
| 916 | cva->Elt.StrideB = natural_stride[TYPE_IDX(type)]; |
| 917 | cva->EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)]; |
| 918 | |
| 919 | if (!cva->pre.pipeline_valid) |
| 920 | gl_build_precalc_pipeline( ctx ); |
| 921 | else if (MESA_VERBOSE & VERBOSE_PIPELINE) |
| 922 | fprintf(stderr, ": dont rebuild\n"); |
| 923 | |
| 924 | gl_cva_force_precalc( ctx ); |
| 925 | |
| 926 | /* Did we 'precalculate' the render op? |
| 927 | */ |
| 928 | if (ctx->CVA.pre.ops & PIPE_OP_RENDER) { |
| 929 | ctx->Array.NewArrayState |= VERT_ELT; |
| 930 | ctx->Array.Summary &= ~VERT_ELT; |
| 931 | ctx->Array.Flags &= ~VERT_ELT; |
| 932 | return; |
| 933 | } |
| 934 | |
| 935 | if ( (MESA_VERBOSE&VERBOSE_VARRAY) ) |
| 936 | printf("using immediate\n"); |
| 937 | } |
| 938 | |
| 939 | |
| 940 | /* Otherwise, have to use the immediate path to render. |
| 941 | */ |
| 942 | switch (type) { |
| 943 | case GL_UNSIGNED_BYTE: |
| 944 | { |
| 945 | GLubyte *ub_indices = (GLubyte *) indices; |
| 946 | if (ctx->Array.Summary & VERT_OBJ_ANY) { |
| 947 | draw_elt_ubyte( ctx, mode, ub_indices, count ); |
| 948 | } else { |
| 949 | gl_ArrayElement( ctx, (GLuint) ub_indices[count-1] ); |
| 950 | } |
| 951 | } |
| 952 | break; |
| 953 | case GL_UNSIGNED_SHORT: |
| 954 | { |
| 955 | GLushort *us_indices = (GLushort *) indices; |
| 956 | if (ctx->Array.Summary & VERT_OBJ_ANY) { |
| 957 | draw_elt_ushort( ctx, mode, us_indices, count ); |
| 958 | } else { |
| 959 | gl_ArrayElement( ctx, (GLuint) us_indices[count-1] ); |
| 960 | } |
| 961 | } |
| 962 | break; |
| 963 | case GL_UNSIGNED_INT: |
| 964 | { |
| 965 | GLuint *ui_indices = (GLuint *) indices; |
| 966 | if (ctx->Array.Summary & VERT_OBJ_ANY) { |
| 967 | draw_elt_uint( ctx, mode, ui_indices, count ); |
| 968 | } else { |
| 969 | gl_ArrayElement( ctx, ui_indices[count-1] ); |
| 970 | } |
| 971 | } |
| 972 | break; |
| 973 | default: |
| 974 | gl_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); |
| 975 | break; |
| 976 | } |
| 977 | |
| 978 | if (ctx->CompileCVAFlag) { |
| 979 | ctx->Array.NewArrayState |= VERT_ELT; |
| 980 | ctx->Array.Summary &= ~VERT_ELT; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | |
| 985 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 986 | void |
| 987 | _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 988 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 989 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 990 | GLboolean tflag, cflag, nflag; /* enable/disable flags */ |
| 991 | GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ |
| 992 | |
| 993 | GLenum ctype; /* color type */ |
| 994 | GLint coffset, noffset, voffset;/* color, normal, vertex offsets */ |
| 995 | GLint defstride; /* default stride */ |
| 996 | GLint c, f; |
| 997 | GLint coordUnitSave; |
| 998 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 999 | f = sizeof(GLfloat); |
| 1000 | c = f * ((4*sizeof(GLubyte) + (f-1)) / f); |
| 1001 | |
| 1002 | if (stride<0) { |
| 1003 | gl_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" ); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | switch (format) { |
| 1008 | case GL_V2F: |
| 1009 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1010 | tcomps = 0; ccomps = 0; vcomps = 2; |
| 1011 | voffset = 0; |
| 1012 | defstride = 2*f; |
| 1013 | break; |
| 1014 | case GL_V3F: |
| 1015 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1016 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 1017 | voffset = 0; |
| 1018 | defstride = 3*f; |
| 1019 | break; |
| 1020 | case GL_C4UB_V2F: |
| 1021 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1022 | tcomps = 0; ccomps = 4; vcomps = 2; |
| 1023 | ctype = GL_UNSIGNED_BYTE; |
| 1024 | coffset = 0; |
| 1025 | voffset = c; |
| 1026 | defstride = c + 2*f; |
| 1027 | break; |
| 1028 | case GL_C4UB_V3F: |
| 1029 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1030 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 1031 | ctype = GL_UNSIGNED_BYTE; |
| 1032 | coffset = 0; |
| 1033 | voffset = c; |
| 1034 | defstride = c + 3*f; |
| 1035 | break; |
| 1036 | case GL_C3F_V3F: |
| 1037 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1038 | tcomps = 0; ccomps = 3; vcomps = 3; |
| 1039 | ctype = GL_FLOAT; |
| 1040 | coffset = 0; |
| 1041 | voffset = 3*f; |
| 1042 | defstride = 6*f; |
| 1043 | break; |
| 1044 | case GL_N3F_V3F: |
| 1045 | tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 1046 | tcomps = 0; ccomps = 0; vcomps = 3; |
| 1047 | noffset = 0; |
| 1048 | voffset = 3*f; |
| 1049 | defstride = 6*f; |
| 1050 | break; |
| 1051 | case GL_C4F_N3F_V3F: |
| 1052 | tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1053 | tcomps = 0; ccomps = 4; vcomps = 3; |
| 1054 | ctype = GL_FLOAT; |
| 1055 | coffset = 0; |
| 1056 | noffset = 4*f; |
| 1057 | voffset = 7*f; |
| 1058 | defstride = 10*f; |
| 1059 | break; |
| 1060 | case GL_T2F_V3F: |
| 1061 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1062 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 1063 | voffset = 2*f; |
| 1064 | defstride = 5*f; |
| 1065 | break; |
| 1066 | case GL_T4F_V4F: |
| 1067 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; |
| 1068 | tcomps = 4; ccomps = 0; vcomps = 4; |
| 1069 | voffset = 4*f; |
| 1070 | defstride = 8*f; |
| 1071 | break; |
| 1072 | case GL_T2F_C4UB_V3F: |
| 1073 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1074 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 1075 | ctype = GL_UNSIGNED_BYTE; |
| 1076 | coffset = 2*f; |
| 1077 | voffset = c+2*f; |
| 1078 | defstride = c+5*f; |
| 1079 | break; |
| 1080 | case GL_T2F_C3F_V3F: |
| 1081 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; |
| 1082 | tcomps = 2; ccomps = 3; vcomps = 3; |
| 1083 | ctype = GL_FLOAT; |
| 1084 | coffset = 2*f; |
| 1085 | voffset = 5*f; |
| 1086 | defstride = 8*f; |
| 1087 | break; |
| 1088 | case GL_T2F_N3F_V3F: |
| 1089 | tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE; |
| 1090 | tcomps = 2; ccomps = 0; vcomps = 3; |
| 1091 | noffset = 2*f; |
| 1092 | voffset = 5*f; |
| 1093 | defstride = 8*f; |
| 1094 | break; |
| 1095 | case GL_T2F_C4F_N3F_V3F: |
| 1096 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1097 | tcomps = 2; ccomps = 4; vcomps = 3; |
| 1098 | ctype = GL_FLOAT; |
| 1099 | coffset = 2*f; |
| 1100 | noffset = 6*f; |
| 1101 | voffset = 9*f; |
| 1102 | defstride = 12*f; |
| 1103 | break; |
| 1104 | case GL_T4F_C4F_N3F_V4F: |
| 1105 | tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; |
| 1106 | tcomps = 4; ccomps = 4; vcomps = 4; |
| 1107 | ctype = GL_FLOAT; |
| 1108 | coffset = 4*f; |
| 1109 | noffset = 8*f; |
| 1110 | voffset = 11*f; |
| 1111 | defstride = 15*f; |
| 1112 | break; |
| 1113 | default: |
| 1114 | gl_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" ); |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | if (stride==0) { |
| 1119 | stride = defstride; |
| 1120 | } |
| 1121 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1122 | _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY ); |
| 1123 | _mesa_DisableClientState( GL_INDEX_ARRAY ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1124 | |
| 1125 | /* Texcoords */ |
| Brian Paul | 45224fa | 1999-09-07 22:31:30 +0000 | [diff] [blame] | 1126 | coordUnitSave = ctx->Array.ActiveTexture; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1127 | if (tflag) { |
| 1128 | GLint i; |
| 1129 | GLint factor = ctx->Array.TexCoordInterleaveFactor; |
| 1130 | for (i = 0; i < factor; i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1131 | _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); |
| 1132 | _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 1133 | glTexCoordPointer( tcomps, GL_FLOAT, stride, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1134 | (GLubyte *) pointer + i * coffset ); |
| 1135 | } |
| 1136 | for (i = factor; i < ctx->Const.MaxTextureUnits; i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1137 | _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); |
| 1138 | _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | else { |
| 1142 | GLint i; |
| 1143 | for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1144 | _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); |
| 1145 | _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | /* Restore texture coordinate unit index */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1149 | _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1150 | |
| 1151 | |
| 1152 | /* Color */ |
| 1153 | if (cflag) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1154 | _mesa_EnableClientState( GL_COLOR_ARRAY ); |
| 1155 | glColorPointer( ccomps, ctype, stride, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1156 | (GLubyte*) pointer + coffset ); |
| 1157 | } |
| 1158 | else { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1159 | _mesa_DisableClientState( GL_COLOR_ARRAY ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | /* Normals */ |
| 1164 | if (nflag) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1165 | _mesa_EnableClientState( GL_NORMAL_ARRAY ); |
| 1166 | glNormalPointer( GL_FLOAT, stride, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1167 | (GLubyte*) pointer + noffset ); |
| 1168 | } |
| 1169 | else { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1170 | _mesa_DisableClientState( GL_NORMAL_ARRAY ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1173 | _mesa_EnableClientState( GL_VERTEX_ARRAY ); |
| 1174 | glVertexPointer( vcomps, GL_FLOAT, stride, |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1175 | (GLubyte *) pointer + voffset ); |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1180 | void |
| 1181 | _mesa_DrawRangeElements(GLenum mode, GLuint start, |
| 1182 | GLuint end, GLsizei count, |
| 1183 | GLenum type, const GLvoid *indices) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1184 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1185 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1186 | |
| 1187 | if (end < start) { |
| 1188 | gl_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements( end < start )"); |
| 1189 | return; |
| 1190 | } |
| 1191 | |
| Brian Paul | df37c6b | 2000-02-05 02:05:14 +0000 | [diff] [blame] | 1192 | #if 0 |
| 1193 | /* |
| 1194 | * XXX something in locked arrays is broken! If start = 0, |
| 1195 | * end = 1 and count = 2 we'll take the LockArrays path and |
| 1196 | * get incorrect results. See Scott McMillan's bug of 3 Jan 2000. |
| 1197 | * For now, don't use locked arrays. |
| 1198 | */ |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1199 | if (!ctx->Array.LockCount && 2*count > (GLint) 3*(end-start)) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1200 | glLockArraysEXT( start, end ); |
| 1201 | glDrawElements( mode, count, type, indices ); |
| 1202 | glUnlockArraysEXT(); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1203 | } else { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1204 | glDrawElements( mode, count, type, indices ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1205 | } |
| Brian Paul | df37c6b | 2000-02-05 02:05:14 +0000 | [diff] [blame] | 1206 | #else |
| 1207 | glDrawElements( mode, count, type, indices ); |
| 1208 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | void gl_update_client_state( GLcontext *ctx ) |
| 1214 | { |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 1215 | static const GLuint sz_flags[5] = { |
| 1216 | 0, |
| 1217 | 0, |
| 1218 | VERT_OBJ_2, |
| 1219 | VERT_OBJ_23, |
| 1220 | VERT_OBJ_234 |
| 1221 | }; |
| 1222 | static const GLuint tc_flags[5] = { |
| 1223 | 0, |
| 1224 | VERT_TEX0_1, |
| 1225 | VERT_TEX0_12, |
| 1226 | VERT_TEX0_123, |
| 1227 | VERT_TEX0_1234 |
| 1228 | }; |
| 1229 | GLint i; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1230 | |
| 1231 | ctx->Array.Flags = 0; |
| 1232 | ctx->Array.Summary = 0; |
| 1233 | ctx->input->ArrayIncr = 0; |
| 1234 | |
| 1235 | if (ctx->Array.Normal.Enabled) ctx->Array.Flags |= VERT_NORM; |
| 1236 | if (ctx->Array.Color.Enabled) ctx->Array.Flags |= VERT_RGBA; |
| 1237 | if (ctx->Array.Index.Enabled) ctx->Array.Flags |= VERT_INDEX; |
| 1238 | if (ctx->Array.EdgeFlag.Enabled) ctx->Array.Flags |= VERT_EDGE; |
| 1239 | if (ctx->Array.Vertex.Enabled) { |
| 1240 | ctx->Array.Flags |= sz_flags[ctx->Array.Vertex.Size]; |
| 1241 | ctx->input->ArrayIncr = 1; |
| 1242 | } |
| Brian Paul | ce938b3 | 2000-10-18 15:02:59 +0000 | [diff] [blame^] | 1243 | for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { |
| 1244 | if (ctx->Array.TexCoord[i].Enabled) { |
| 1245 | ctx->Array.Flags |= (tc_flags[ctx->Array.TexCoord[i].Size] << (i * NR_TEXSIZE_BITS)); |
| 1246 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /* Not really important any more: |
| 1250 | */ |
| 1251 | ctx->Array.Summary = ctx->Array.Flags & VERT_DATA; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1252 | ctx->input->ArrayAndFlags = ~ctx->Array.Flags; |
| 1253 | ctx->input->ArrayEltFlush = !(ctx->CompileCVAFlag); |
| 1254 | } |
| 1255 | |