t_draw.c revision bbd287103dad776d8a45c87c4e51fbc26d9b80d5
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 919827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 92c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* Adjust pointer to point at first requested element, convert to 93c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * floating point, populate VB->AttribPtr[]. 94c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 95c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void _tnl_import_array( GLcontext *ctx, 96c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint attrib, 97893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLuint count, 98c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *input, 99188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell const GLubyte *ptr ) 100c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 101c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 102c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 103c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint stride = input->StrideB; 104c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 105c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (input->Type != GL_FLOAT) { 106c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const GLuint sz = input->Size; 107188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLubyte *buf = get_space(ctx, count * sz * sizeof(GLfloat)); 1087e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell GLfloat *fptr = (GLfloat *)buf; 109c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 110c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell switch (input->Type) { 111c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_BYTE: 112c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLbyte, BYTE_TO_FLOAT); 113c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 114c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_BYTE: 115c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLubyte, UBYTE_TO_FLOAT); 116c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 117c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_SHORT: 118c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLshort, SHORT_TO_FLOAT); 119c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 120c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_SHORT: 121c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLushort, USHORT_TO_FLOAT); 122c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 123c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_INT: 124c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLint, INT_TO_FLOAT); 125c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 126c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_UNSIGNED_INT: 127c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLuint, UINT_TO_FLOAT); 128c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 129c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell case GL_DOUBLE: 130c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell CONVERT(GLdouble, (GLfloat)); 131c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 132c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell default: 133c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(0); 134c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell break; 135c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 136c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 1377e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell ptr = buf; 138c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell stride = sz * sizeof(GLfloat); 139c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 140c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 141c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib] = &tnl->tmp_inputs[attrib]; 142c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->data = (GLfloat (*)[4])ptr; 143c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->start = (GLfloat *)ptr; 144c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->count = count; 145c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->stride = stride; 146c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->size = input->Size; 147c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 148c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* This should die, but so should the whole GLvector4f concept: 149c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 150c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->flags = (((1<<input->Size)-1) | 151c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VEC_NOT_WRITEABLE | 152c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell (stride == 4*sizeof(GLfloat) ? 0 : VEC_BAD_STRIDE)); 153c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 154c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->AttribPtr[attrib]->storage = NULL; 155c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 156c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 1579827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell#define CLIPVERTS ((6 + MAX_CLIP_PLANES) * 2) 1589827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1599827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1609827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwellstatic GLboolean *_tnl_import_edgeflag( GLcontext *ctx, 1619827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLvector4f *input, 1629827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLuint count) 1639827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell{ 1649827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLubyte *ptr = (const GLubyte *)input->data; 1659827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell const GLuint stride = input->stride; 1669827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS); 1679827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLboolean *bptr = space; 1689827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell GLuint i; 1699827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1709827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell for (i = 0; i < count; i++) { 1719827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell *bptr++ = ((GLfloat *)ptr)[0] == 1.0; 1729827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell ptr += stride; 1739827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell } 1749827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 1759827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell return space; 1769827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell} 1779827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell 178c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 179c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void bind_inputs( GLcontext *ctx, 180c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *inputs[], 181893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLint count, 182c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct gl_buffer_object **bo, 183c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint *nr_bo ) 184c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 185c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 186c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 187c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint i; 188c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 189c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Map all the VBOs 190c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 191c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < VERT_ATTRIB_MAX; i++) { 192c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const void *ptr; 193c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 194c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (inputs[i]->BufferObj->Name) { 195c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (!inputs[i]->BufferObj->Pointer) { 196c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[*nr_bo] = inputs[i]->BufferObj; 1977e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell (*nr_bo)++; 198c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.MapBuffer(ctx, 199c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_ARRAY_BUFFER, 200c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_READ_ONLY_ARB, 201c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell inputs[i]->BufferObj); 202c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 203c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(inputs[i]->BufferObj->Pointer); 204c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 205c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 206c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ptr = ADD_POINTERS(inputs[i]->BufferObj->Pointer, 207c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell inputs[i]->Ptr); 208c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 209c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell else 210c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ptr = inputs[i]->Ptr; 211c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 212c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Just make sure the array is floating point, otherwise convert to 213893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * temporary storage. 214c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * 215c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * XXX: remove the GLvector4f type at some stage and just use 216c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * client arrays. 217c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 218893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell _tnl_import_array(ctx, i, count, inputs[i], ptr); 219c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 220c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 2215464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* We process only the vertices between min & max index: 2225464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 223893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Count = count; 2245464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 2255464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 226c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell /* Legacy pointers -- remove one day. 227c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 228c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ObjPtr = VB->AttribPtr[_TNL_ATTRIB_POS]; 229c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->NormalPtr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]; 230c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR0]; 231c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->ColorPtr[1] = NULL; 232c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->IndexPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR_INDEX]; 233c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->IndexPtr[1] = NULL; 234c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->SecondaryColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR1]; 235c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->SecondaryColorPtr[1] = NULL; 236c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->FogCoordPtr = VB->AttribPtr[_TNL_ATTRIB_FOG]; 237c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 238c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { 239c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell VB->TexCoordPtr[i] = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]; 240c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 241c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 2429827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell /* Clipping and drawing code still requires this to be a packed 2439827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell * array of ubytes which can be written into. TODO: Fix and 2449827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell * remove. 245c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 246c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (ctx->Polygon.FrontMode != GL_FILL || 247c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Polygon.BackMode != GL_FILL) 248c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell { 2499827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->EdgeFlag = _tnl_import_edgeflag( ctx, 2509827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->AttribPtr[_TNL_ATTRIB_EDGEFLAG], 2519827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell VB->Count ); 252c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 253d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian else { 254d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian /* the data previously pointed to by EdgeFlag may have been freed */ 255d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian VB->EdgeFlag = NULL; 256d2d86a3f0b38716196ea2b3ffa4cbbd0420de1b3Brian } 257c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 258c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 259c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 260c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* Translate indices to GLuints and store in VB->Elts. 261c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 2625464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwellstatic void bind_indices( GLcontext *ctx, 2635464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell const struct _mesa_index_buffer *ib, 2645464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct gl_buffer_object **bo, 2655464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell GLuint *nr_bo) 266c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 267c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 268c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 269188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLuint i; 270188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell void *ptr; 271c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 272893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (!ib) { 273893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Elts = NULL; 274c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell return; 275893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell } 276c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 277c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell if (ib->obj->Name && !ib->obj->Pointer) { 278c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[*nr_bo] = ib->obj; 2797e9c3684ef45e0df8426317f28c883d16f27c031Keith Whitwell (*nr_bo)++; 280c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.MapBuffer(ctx, 281c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_ELEMENT_ARRAY_BUFFER, 282c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GL_READ_ONLY_ARB, 283c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ib->obj); 284c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 285c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell assert(ib->obj->Pointer); 286c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 287c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 288188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); 289c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 290893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (ib->type == GL_UNSIGNED_INT) { 291188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell VB->Elts = (GLuint *) ptr; 292188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 293188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell else { 294188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); 295188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell VB->Elts = elts; 296188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell 297893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (ib->type == GL_UNSIGNED_SHORT) { 298893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLushort *in = (GLushort *)ptr; 299188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell for (i = 0; i < ib->count; i++) 300893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell *elts++ = (GLuint)(*in++); 301188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 302893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell else { 303893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLubyte *in = (GLubyte *)ptr; 304188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell for (i = 0; i < ib->count; i++) 305893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell *elts++ = (GLuint)(*in++); 306188a4db49c4c22429bfa7ae87d4b1a0c35bf0285Keith Whitwell } 307c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 308c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 309c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 3105464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwellstatic void bind_prims( GLcontext *ctx, 3115464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell const struct _mesa_prim *prim, 312893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell GLuint nr_prims ) 3135464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell{ 3145464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 3155464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct vertex_buffer *VB = &tnl->vb; 3165464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 317893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell VB->Primitive = prim; 3185464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell VB->PrimitiveCount = nr_prims; 3195464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell} 3205464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 321c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void unmap_vbos( GLcontext *ctx, 322c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell struct gl_buffer_object **bo, 323c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint nr_bo ) 324c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 325c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint i; 326c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell for (i = 0; i < nr_bo; i++) { 327c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell ctx->Driver.UnmapBuffer(ctx, 328c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 0, /* target -- I don't see why this would be needed */ 329c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell bo[i]); 330c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell } 331c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 332c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 333c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 334c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 335c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* This is the main entrypoint into the slimmed-down software tnl 336c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * module. In a regular swtnl driver, this can be plugged straight 337c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * into the vbo->Driver.DrawPrims() callback. 338c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */ 339c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellvoid _tnl_draw_prims( GLcontext *ctx, 340c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct gl_client_array *arrays[], 341c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct _mesa_prim *prim, 342c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint nr_prims, 343c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell const struct _mesa_index_buffer *ib, 344c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint min_index, 345c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell GLuint max_index) 346c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{ 347c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 348893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLuint TEST_SPLIT = 0; 349893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES; 3505464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 351893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (0) 35282152a2a8e1afeb61710318e769b1379be6c02c6keithw { 35382152a2a8e1afeb61710318e769b1379be6c02c6keithw GLuint i; 35482152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index); 35582152a2a8e1afeb61710318e769b1379be6c02c6keithw for (i = 0; i < nr_prims; i++) 35682152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_printf("prim %d: %s start %d count %d\n", i, 35782152a2a8e1afeb61710318e769b1379be6c02c6keithw _mesa_lookup_enum_by_nr(prim[i].mode), 35882152a2a8e1afeb61710318e769b1379be6c02c6keithw prim[i].start, 35982152a2a8e1afeb61710318e769b1379be6c02c6keithw prim[i].count); 36082152a2a8e1afeb61710318e769b1379be6c02c6keithw } 3615464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 362893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell if (min_index) { 363893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell /* We always translate away calls with min_index != 0. 364893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell */ 365893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell vbo_rebase_prims( ctx, arrays, prim, nr_prims, ib, 366893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell min_index, max_index, 367893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell _tnl_draw_prims ); 368893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell return; 369893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell } 370f8ee72d98f2d23e034e90870ff6a760659a462a5Brian else if (max_index > max) { 371893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell /* The software TNL pipeline has a fixed amount of storage for 372893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * vertices and it is necessary to split incoming drawing commands 373893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell * if they exceed that limit. 374893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell */ 3755464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct split_limits limits; 376893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell limits.max_verts = max; 3775464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell limits.max_vb_size = ~0; 3785464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell limits.max_indices = ~0; 3795464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell 3805464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* This will split the buffers one way or another and 3815464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell * recursively call back into this function. 3825464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 3835464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell vbo_split_prims( ctx, arrays, prim, nr_prims, ib, 384893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell 0, max_index, 3855464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell _tnl_draw_prims, 3865464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell &limits ); 3875464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell } 3885464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell else { 3895464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* May need to map a vertex buffer object for every attribute plus 3905464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell * one for the index buffer. 3915464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 3925464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1]; 3935464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell GLuint nr_bo = 0; 394c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 3955464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell /* Binding inputs may imply mapping some vertex buffer objects. 3965464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell * They will need to be unmapped below. 3975464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell */ 398893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell bind_inputs(ctx, arrays, max_index+1, bo, &nr_bo); 399893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell bind_indices(ctx, ib, bo, &nr_bo); 400893526b8a823fe1b88f2b46376155afb91c84016Keith Whitwell bind_prims(ctx, prim, nr_prims ); 401c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 4025464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); 403c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 4045464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell unmap_vbos(ctx, bo, nr_bo); 4055464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell free_space(ctx); 4065464cd0a60f474753abc6af047fd21b0e29b8ac4Keith Whitwell } 407c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell} 408c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell 409