t_draw.c revision 92d7ed8a20d4a018ce5324e6537ae7b478b9e5bf
1c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* 2c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Mesa 3-D graphics library 3f8ee72d98f2d23e034e90870ff6a760659a462a5Brian * Version: 7.1 4c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 5f8ee72d98f2d23e034e90870ff6a760659a462a5Brian * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 6c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 7c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 8c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * copy of this software and associated documentation files (the "Software"), 9c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * to deal in the Software without restriction, including without limitation 10c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 12c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Software is furnished to do so, subject to the following conditions: 13c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 14c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * The above copyright notice and this permission notice shall be included 15c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * in all copies or substantial portions of the Software. 16c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 17c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 24c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Authors: 25c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Keith Whitwell <keith@tungstengraphics.com> 26c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 27c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 28bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/glheader.h" 29bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/context.h" 30bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/imports.h" 31bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/state.h" 32bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/mtypes.h" 33bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/macros.h" 34bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/enums.h" 35c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 36c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "t_context.h" 37c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "t_pipeline.h" 38c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "t_vp_build.h" 39c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "t_vertex.h" 40c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "tnl.h" 41c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 42c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 43c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 44188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwellstatic GLubyte *get_space(GLcontext *ctx, GLuint bytes) 45c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 46c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 47c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLubyte *space = _mesa_malloc(bytes); 48c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 49c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell tnl->block[tnl->nr_blocks++] = space; 50188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell return space; 51c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 52c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 53c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 54c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void free_space(GLcontext *ctx) 55c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 56c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 57c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint i; 58c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < tnl->nr_blocks; i++) 59c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell _mesa_free(tnl->block[i]); 60c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell tnl->nr_blocks = 0; 61c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 62c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 63c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 649827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell/* Convert the incoming array to GLfloats. Understands the 659827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell * array->Normalized flag and selects the correct conversion method. 669827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell */ 679827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell#define CONVERT( TYPE, MACRO ) do { \ 689827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLuint i, j; \ 699827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell if (input->Normalized) { \ 709827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (i = 0; i < count; i++) { \ 719827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const TYPE *in = (TYPE *)ptr; \ 729827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (j = 0; j < sz; j++) { \ 739827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell *fptr++ = MACRO(*in); \ 749827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell in++; \ 759827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } \ 769827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell ptr += input->StrideB; \ 779827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } \ 789827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } else { \ 799827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (i = 0; i < count; i++) { \ 809827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const TYPE *in = (TYPE *)ptr; \ 819827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (j = 0; j < sz; j++) { \ 829827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell *fptr++ = (GLfloat)(*in); \ 839827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell in++; \ 849827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } \ 859827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell ptr += input->StrideB; \ 869827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } \ 879827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } \ 889827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell} while (0) 899827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 909827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 910791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul/** 920791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul * Convert array of BGRA/GLubyte[4] values to RGBA/float[4] 930791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul * \param ptr input/ubyte array 940791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul * \param fptr output/float array 950791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul */ 960791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paulstatic void 970791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paulconvert_bgra_to_float(const struct gl_client_array *input, 980791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul const GLubyte *ptr, GLfloat *fptr, 990791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul GLuint count ) 1000791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul{ 1010791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul GLuint i; 1020791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul assert(input->Normalized); 1030791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul assert(input->Size == 4); 1040791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul for (i = 0; i < count; i++) { 1050791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul const GLubyte *in = (GLubyte *) ptr; /* in is in BGRA order */ 1060791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul *fptr++ = UBYTE_TO_FLOAT(in[2]); /* red */ 1070791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul *fptr++ = UBYTE_TO_FLOAT(in[1]); /* green */ 1080791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul *fptr++ = UBYTE_TO_FLOAT(in[0]); /* blue */ 1090791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul *fptr++ = UBYTE_TO_FLOAT(in[3]); /* alpha */ 1100791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul ptr += input->StrideB; 1110791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul } 1120791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul} 1130791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul 1149827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 115c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* Adjust pointer to point at first requested element, convert to 116c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * floating point, populate VB->AttribPtr[]. 117c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 118c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void _tnl_import_array( GLcontext *ctx, 119c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint attrib, 120893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLuint count, 121c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *input, 122188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell const GLubyte *ptr ) 123c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 124c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 125c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 126c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint stride = input->StrideB; 127c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 128c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (input->Type != GL_FLOAT) { 129c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const GLuint sz = input->Size; 130188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLubyte *buf = get_space(ctx, count * sz * sizeof(GLfloat)); 1317e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell GLfloat *fptr = (GLfloat *)buf; 132c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 133c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell switch (input->Type) { 134c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_BYTE: 135c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLbyte, BYTE_TO_FLOAT); 136c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 137c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_BYTE: 1380791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul if (input->Format == GL_BGRA) { 1390791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul /* See GL_EXT_vertex_array_bgra */ 1400791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul convert_bgra_to_float(input, ptr, fptr, count); 1410791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul } 1420791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul else { 1430791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul CONVERT(GLubyte, UBYTE_TO_FLOAT); 1440791fdff6fe87cf9a29ddf4a716f1881c367c7deBrian Paul } 145c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 146c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_SHORT: 147c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLshort, SHORT_TO_FLOAT); 148c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 149c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_SHORT: 150c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLushort, USHORT_TO_FLOAT); 151c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 152c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_INT: 153c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLint, INT_TO_FLOAT); 154c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 155c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_INT: 156c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLuint, UINT_TO_FLOAT); 157c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 158c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_DOUBLE: 159c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLdouble, (GLfloat)); 160c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 161c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell default: 162c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(0); 163c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 164c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 165c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 1667e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell ptr = buf; 167c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell stride = sz * sizeof(GLfloat); 168c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 169c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 170c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib] = &tnl->tmp_inputs[attrib]; 171c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->data = (GLfloat (*)[4])ptr; 172c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->start = (GLfloat *)ptr; 173c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->count = count; 174c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->stride = stride; 175c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->size = input->Size; 176c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 177c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* This should die, but so should the whole GLvector4f concept: 178c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 179c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->flags = (((1<<input->Size)-1) | 180c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VEC_NOT_WRITEABLE | 181c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell (stride == 4*sizeof(GLfloat) ? 0 : VEC_BAD_STRIDE)); 182c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 183c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->storage = NULL; 184c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 185c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 1869827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell#define CLIPVERTS ((6 + MAX_CLIP_PLANES) * 2) 1879827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1889827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1899827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwellstatic GLboolean *_tnl_import_edgeflag( GLcontext *ctx, 1909827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLvector4f *input, 1919827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLuint count) 1929827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell{ 1939827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLubyte *ptr = (const GLubyte *)input->data; 1949827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLuint stride = input->stride; 1959827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS); 1969827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLboolean *bptr = space; 1979827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLuint i; 1989827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1999827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (i = 0; i < count; i++) { 2009827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell *bptr++ = ((GLfloat *)ptr)[0] == 1.0; 2019827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell ptr += stride; 2029827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } 2039827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 2049827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell return space; 2059827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell} 2069827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 207c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 208c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void bind_inputs( GLcontext *ctx, 209c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *inputs[], 210893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLint count, 211c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct gl_buffer_object **bo, 212c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint *nr_bo ) 213c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 214c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 215c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 216c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint i; 217c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 218c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Map all the VBOs 219c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 220c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < VERT_ATTRIB_MAX; i++) { 221c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const void *ptr; 222c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 223c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (inputs[i]->BufferObj->Name) { 224c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (!inputs[i]->BufferObj->Pointer) { 225c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[*nr_bo] = inputs[i]->BufferObj; 2267e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell (*nr_bo)++; 227c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.MapBuffer(ctx, 228c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_ARRAY_BUFFER, 229c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_READ_ONLY_ARB, 230c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell inputs[i]->BufferObj); 231c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 232c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(inputs[i]->BufferObj->Pointer); 233c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 234c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 235c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ptr = ADD_POINTERS(inputs[i]->BufferObj->Pointer, 236c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell inputs[i]->Ptr); 237c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 238c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell else 239c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ptr = inputs[i]->Ptr; 240c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 241c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Just make sure the array is floating point, otherwise convert to 242893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * temporary storage. 243c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 244c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * XXX: remove the GLvector4f type at some stage and just use 245c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * client arrays. 246c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 247893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell _tnl_import_array(ctx, i, count, inputs[i], ptr); 248c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 249c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 2505464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* We process only the vertices between min & max index: 2515464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 252893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Count = count; 2535464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 2545464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 255c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Legacy pointers -- remove one day. 256c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 257c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ObjPtr = VB->AttribPtr[_TNL_ATTRIB_POS]; 258c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->NormalPtr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]; 259c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR0]; 260c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ColorPtr[1] = NULL; 261c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->IndexPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR_INDEX]; 262c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->IndexPtr[1] = NULL; 263c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->SecondaryColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR1]; 264c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->SecondaryColorPtr[1] = NULL; 265c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->FogCoordPtr = VB->AttribPtr[_TNL_ATTRIB_FOG]; 266c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 267c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { 268c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->TexCoordPtr[i] = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]; 269c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 270c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 2719827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell /* Clipping and drawing code still requires this to be a packed 2729827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell * array of ubytes which can be written into. TODO: Fix and 2739827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell * remove. 274c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 275c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (ctx->Polygon.FrontMode != GL_FILL || 276c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Polygon.BackMode != GL_FILL) 277c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell { 2789827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->EdgeFlag = _tnl_import_edgeflag( ctx, 2799827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->AttribPtr[_TNL_ATTRIB_EDGEFLAG], 2809827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->Count ); 281c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 282d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian else { 283d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian /* the data previously pointed to by EdgeFlag may have been freed */ 284d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian VB->EdgeFlag = NULL; 285d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian } 286c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 287c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 288c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 289c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* Translate indices to GLuints and store in VB->Elts. 290c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 2915464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwellstatic void bind_indices( GLcontext *ctx, 2925464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell const struct _mesa_index_buffer *ib, 2935464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct gl_buffer_object **bo, 2945464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell GLuint *nr_bo) 295c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 296c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 297c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 298188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLuint i; 299188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell void *ptr; 300c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 301893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (!ib) { 302893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Elts = NULL; 303c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell return; 304893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell } 305c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 306c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (ib->obj->Name && !ib->obj->Pointer) { 307c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[*nr_bo] = ib->obj; 3087e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell (*nr_bo)++; 309c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.MapBuffer(ctx, 310c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_ELEMENT_ARRAY_BUFFER, 311c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_READ_ONLY_ARB, 312c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ib->obj); 313c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 314c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(ib->obj->Pointer); 315c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 316c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 317188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); 318c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 31992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { 320188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell VB->Elts = (GLuint *) ptr; 321188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 322188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell else { 323188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); 324188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell VB->Elts = elts; 325188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell 32692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (ib->type == GL_UNSIGNED_INT) { 32792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLuint *in = (GLuint *)ptr; 32892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt for (i = 0; i < ib->count; i++) 32992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; 33092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt } 33192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt else if (ib->type == GL_UNSIGNED_SHORT) { 332893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLushort *in = (GLushort *)ptr; 333188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell for (i = 0; i < ib->count; i++) 33492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; 335188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 336893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell else { 337893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLubyte *in = (GLubyte *)ptr; 338188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell for (i = 0; i < ib->count; i++) 33992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; 340188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 341c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 342c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 343c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 3445464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwellstatic void bind_prims( GLcontext *ctx, 3455464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell const struct _mesa_prim *prim, 346893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLuint nr_prims ) 3475464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell{ 3485464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 3495464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct vertex_buffer *VB = &tnl->vb; 3505464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 351893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Primitive = prim; 3525464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell VB->PrimitiveCount = nr_prims; 3535464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell} 3545464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 355c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void unmap_vbos( GLcontext *ctx, 356c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct gl_buffer_object **bo, 357c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint nr_bo ) 358c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 359c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint i; 360c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < nr_bo; i++) { 361c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.UnmapBuffer(ctx, 362c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 0, /* target -- I don't see why this would be needed */ 363c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[i]); 364c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 365c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 366c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 367c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 3682708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholtvoid _tnl_vbo_draw_prims(GLcontext *ctx, 3692708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt const struct gl_client_array *arrays[], 3702708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt const struct _mesa_prim *prim, 3712708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt GLuint nr_prims, 3722708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt const struct _mesa_index_buffer *ib, 3732708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt GLboolean index_bounds_valid, 3742708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt GLuint min_index, 3752708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt GLuint max_index) 3762708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt{ 3772708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt if (!index_bounds_valid) 3782708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt vbo_get_minmax_index(ctx, prim, ib, &min_index, &max_index); 3792708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt 3802708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt _tnl_draw_prims(ctx, arrays, prim, nr_prims, ib, min_index, max_index); 3812708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt} 382c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 383c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* This is the main entrypoint into the slimmed-down software tnl 384c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * module. In a regular swtnl driver, this can be plugged straight 385c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * into the vbo->Driver.DrawPrims() callback. 386c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 387c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellvoid _tnl_draw_prims( GLcontext *ctx, 388c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *arrays[], 389c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct _mesa_prim *prim, 390c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint nr_prims, 391c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct _mesa_index_buffer *ib, 392c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint min_index, 393c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint max_index) 394c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 395c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 396893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLuint TEST_SPLIT = 0; 397893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES; 39892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint max_basevertex = prim->basevertex; 39992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint i; 40092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 40192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt for (i = 1; i < nr_prims; i++) 40292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt max_basevertex = MAX2(max_basevertex, prim[i].basevertex); 4035464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 404893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (0) 40582152a2a8e1afeb61710318e769b1379be6c02c6keithw { 40682152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index); 40782152a2a8e1afeb61710318e769b1379be6c02c6keithw for (i = 0; i < nr_prims; i++) 40882152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_printf("prim %d: %s start %d count %d\n", i, 40982152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_lookup_enum_by_nr(prim[i].mode), 41082152a2a8e1afeb61710318e769b1379be6c02c6keithw prim[i].start, 41182152a2a8e1afeb61710318e769b1379be6c02c6keithw prim[i].count); 41282152a2a8e1afeb61710318e769b1379be6c02c6keithw } 4135464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 414893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (min_index) { 415893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell /* We always translate away calls with min_index != 0. 416893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell */ 417893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell vbo_rebase_prims( ctx, arrays, prim, nr_prims, ib, 418893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell min_index, max_index, 4192708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt _tnl_vbo_draw_prims ); 420893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell return; 421893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell } 42292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt else if (max_index + max_basevertex > max) { 423893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell /* The software TNL pipeline has a fixed amount of storage for 424893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * vertices and it is necessary to split incoming drawing commands 425893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * if they exceed that limit. 426893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell */ 4275464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct split_limits limits; 428893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell limits.max_verts = max; 4295464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell limits.max_vb_size = ~0; 4305464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell limits.max_indices = ~0; 4315464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 4325464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* This will split the buffers one way or another and 4335464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell * recursively call back into this function. 4345464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 4355464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell vbo_split_prims( ctx, arrays, prim, nr_prims, ib, 43692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 0, max_index + prim->basevertex, 4372708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt _tnl_vbo_draw_prims, 4385464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell &limits ); 4395464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell } 4405464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell else { 4415464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* May need to map a vertex buffer object for every attribute plus 4425464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell * one for the index buffer. 4435464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 4445464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1]; 4455464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell GLuint nr_bo = 0; 446c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 44792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt for (i = 0; i < nr_prims;) { 44892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint this_nr_prims; 44992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 45092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt /* Our SW TNL pipeline doesn't handle basevertex yet, so bind_indices 45192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt * will rebase the elements to the basevertex, and we'll only 45292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt * emit strings of prims with the same basevertex in one draw call. 45392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt */ 45492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt for (this_nr_prims = 1; i + this_nr_prims < nr_prims; 45592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt this_nr_prims++) { 45692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (prim[i].basevertex != prim[i + this_nr_prims].basevertex) 45792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt break; 45892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt } 45992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 46092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt /* Binding inputs may imply mapping some vertex buffer objects. 46192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt * They will need to be unmapped below. 46292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt */ 46392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt bind_prims(ctx, &prim[i], this_nr_prims); 46492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1, 46592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt bo, &nr_bo); 46692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt bind_indices(ctx, ib, bo, &nr_bo); 467c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 46892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); 469c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 47092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt unmap_vbos(ctx, bo, nr_bo); 47192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt free_space(ctx); 47292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 47392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt i += this_nr_prims; 47492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt } 4755464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell } 476c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 477c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 478