t_draw.c revision 9827dc8bea422b940f1efcfbd1c0d76f8bbca844
1c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
2c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/*
3c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Mesa 3-D graphics library
4c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Version:  6.5
5c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *
6c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
7c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *
8c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
9c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * copy of this software and associated documentation files (the "Software"),
10c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * to deal in the Software without restriction, including without limitation
11c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
13c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Software is furnished to do so, subject to the following conditions:
14c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *
15c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * The above copyright notice and this permission notice shall be included
16c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * in all copies or substantial portions of the Software.
17c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *
18c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *
25c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * Authors:
26c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell *    Keith Whitwell <keith@tungstengraphics.com>
27c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */
28c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
29c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "glheader.h"
30c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "context.h"
31c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "imports.h"
32c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "state.h"
33c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "mtypes.h"
34c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell#include "macros.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
44c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic GLfloat *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;
50c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   return (GLfloat *)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,
97c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			       GLuint start,
98c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			       GLuint end,
99c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			       const struct gl_client_array *input,
100c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			       const char *ptr )
101c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{
102c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
103c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   struct vertex_buffer *VB = &tnl->vb;
104c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   const GLuint count = end - start;
105c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   GLuint stride = input->StrideB;
106c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
107c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   ptr += start * stride;
108c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
109c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   if (input->Type != GL_FLOAT) {
110c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      const GLuint sz = input->Size;
111c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      GLfloat *fptr = get_space(ctx, count * sz * sizeof(GLfloat));
112c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
113c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      switch (input->Type) {
114c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_BYTE:
115c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLbyte, BYTE_TO_FLOAT);
116c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
117c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_UNSIGNED_BYTE:
118c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLubyte, UBYTE_TO_FLOAT);
119c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
120c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_SHORT:
121c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLshort, SHORT_TO_FLOAT);
122c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
123c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_UNSIGNED_SHORT:
124c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLushort, USHORT_TO_FLOAT);
125c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
126c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_INT:
127c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLint, INT_TO_FLOAT);
128c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
129c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_UNSIGNED_INT:
130c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLuint, UINT_TO_FLOAT);
131c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
132c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      case GL_DOUBLE:
133c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 CONVERT(GLdouble, (GLfloat));
134c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
135c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      default:
136c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 assert(0);
137c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 break;
138c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      }
139c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
140c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      ptr = (const char *)fptr;
141c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      stride = sz * sizeof(GLfloat);
142c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
143c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
144c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib] = &tnl->tmp_inputs[attrib];
145c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->data = (GLfloat (*)[4])ptr;
146c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->start = (GLfloat *)ptr;
147c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->count = count;
148c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->stride = stride;
149c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->size = input->Size;
150c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
151c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   /* This should die, but so should the whole GLvector4f concept:
152c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
153c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->flags = (((1<<input->Size)-1) |
154c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				   VEC_NOT_WRITEABLE |
155c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				   (stride == 4*sizeof(GLfloat) ? 0 : VEC_BAD_STRIDE));
156c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
157c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->AttribPtr[attrib]->storage = NULL;
158c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell}
159c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
1609827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell#define CLIPVERTS  ((6 + MAX_CLIP_PLANES) * 2)
1619827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell
1629827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell
1639827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwellstatic GLboolean *_tnl_import_edgeflag( GLcontext *ctx,
1649827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell					const GLvector4f *input,
1659827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell					GLuint count)
1669827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell{
1679827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   const GLubyte *ptr = (const GLubyte *)input->data;
1689827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   const GLuint stride = input->stride;
1699827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   GLboolean *space = (GLboolean *)get_space(ctx, count + CLIPVERTS);
1709827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   GLboolean *bptr = space;
1719827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   GLuint i;
1729827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell
1739827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   for (i = 0; i < count; i++) {
1749827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell      *bptr++ = ((GLfloat *)ptr)[0] == 1.0;
1759827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell      ptr += stride;
1769827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   }
1779827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell
1789827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   return space;
1799827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell}
1809827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell
181c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
182c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void bind_inputs( GLcontext *ctx,
183c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			 const struct gl_client_array *inputs[],
184c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			 GLint start, GLint end,
185c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			 struct gl_buffer_object **bo,
186c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			 GLuint *nr_bo )
187c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{
188c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
189c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   struct vertex_buffer *VB = &tnl->vb;
190c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   GLuint i;
191c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
192c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   /* Map all the VBOs
193c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
194c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
195c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      const void *ptr;
196c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
197c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      if (inputs[i]->BufferObj->Name) {
198c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 if (!inputs[i]->BufferObj->Pointer) {
199c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	    bo[*nr_bo] = inputs[i]->BufferObj;
200c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	    *nr_bo++;
201c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	    ctx->Driver.MapBuffer(ctx,
202c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				  GL_ARRAY_BUFFER,
203c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				  GL_READ_ONLY_ARB,
204c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				  inputs[i]->BufferObj);
205c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
206c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	    assert(inputs[i]->BufferObj->Pointer);
207c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 }
208c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
209c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 ptr = ADD_POINTERS(inputs[i]->BufferObj->Pointer,
210c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			    inputs[i]->Ptr);
211c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      }
212c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      else
213c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell	 ptr = inputs[i]->Ptr;
214c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
215c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      /* Just make sure the array is floating point, otherwise convert to
216c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       * temporary storage.  Rebase arrays so that 'start' becomes
217c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       * element zero.
218c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       *
219c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       * XXX: remove the GLvector4f type at some stage and just use
220c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       * client arrays.
221c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       */
222c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      _tnl_import_array(ctx, i, start, end, inputs[i], ptr);
223c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
224c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
225c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   /* Legacy pointers -- remove one day.
226c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
227c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->ObjPtr = VB->AttribPtr[_TNL_ATTRIB_POS];
228c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->NormalPtr = VB->AttribPtr[_TNL_ATTRIB_NORMAL];
229c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->ColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR0];
230c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->ColorPtr[1] = NULL;
231c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->IndexPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR_INDEX];
232c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->IndexPtr[1] = NULL;
233c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->SecondaryColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR1];
234c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->SecondaryColorPtr[1] = NULL;
235c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->FogCoordPtr = VB->AttribPtr[_TNL_ATTRIB_FOG];
236c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
237c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
238c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      VB->TexCoordPtr[i] = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i];
239c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
240c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
2419827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell   /* Clipping and drawing code still requires this to be a packed
2429827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell    * array of ubytes which can be written into.  TODO: Fix and
2439827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell    * remove.
244c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
245c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   if (ctx->Polygon.FrontMode != GL_FILL ||
246c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell       ctx->Polygon.BackMode != GL_FILL)
247c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   {
2489827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell      VB->EdgeFlag = _tnl_import_edgeflag( ctx,
2499827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell					   VB->AttribPtr[_TNL_ATTRIB_EDGEFLAG],
2509827dc8bea422b940f1efcfbd1c0d76f8bbca844Keith Whitwell					   VB->Count );
251c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
252c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
253c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell}
254c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
255c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
256c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* Translate indices to GLuints and store in VB->Elts.
257c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */
258c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void bind_indicies( GLcontext *ctx,
259c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			   const struct _mesa_index_buffer *ib,
260c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			   struct gl_buffer_object **bo,
261c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			   GLuint *nr_bo)
262c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{
263c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
264c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   struct vertex_buffer *VB = &tnl->vb;
265c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
266c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   if (!ib)
267c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      return;
268c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
269c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   if (ib->obj->Name && !ib->obj->Pointer) {
270c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      bo[*nr_bo] = ib->obj;
271c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      *nr_bo++;
272c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      ctx->Driver.MapBuffer(ctx,
273c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			    GL_ELEMENT_ARRAY_BUFFER,
274c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			    GL_READ_ONLY_ARB,
275c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			    ib->obj);
276c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
277c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      assert(ib->obj->Pointer);
278c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
279c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
280c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->Elts = (GLuint *)ADD_POINTERS(ib->obj->Pointer,
281c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell				     ib->ptr);
282c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
283c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->Elts += ib->rebase;
284c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
285c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   switch (ib->type) {
286c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   case GL_UNSIGNED_INT:
287c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      return;
288c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   case GL_UNSIGNED_SHORT:
289c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      break;
290c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   case GL_UNSIGNED_BYTE:
291c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      break;
292c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
293c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell}
294c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
295c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellstatic void unmap_vbos( GLcontext *ctx,
296c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			struct gl_buffer_object **bo,
297c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			GLuint nr_bo )
298c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{
299c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   GLuint i;
300c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   for (i = 0; i < nr_bo; i++) {
301c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell      ctx->Driver.UnmapBuffer(ctx,
302c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			      0, /* target -- I don't see why this would be needed */
303c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell			      bo[i]);
304c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   }
305c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell}
306c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
307c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
308c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
309c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell/* This is the main entrypoint into the slimmed-down software tnl
310c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * module.  In a regular swtnl driver, this can be plugged straight
311c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell * into the vbo->Driver.DrawPrims() callback.
312c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell */
313c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwellvoid _tnl_draw_prims( GLcontext *ctx,
314c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      const struct gl_client_array *arrays[],
315c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      const struct _mesa_prim *prim,
316c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      GLuint nr_prims,
317c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      const struct _mesa_index_buffer *ib,
318c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      GLuint min_index,
319c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell		      GLuint max_index)
320c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell{
321c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
322c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   struct vertex_buffer *VB = &tnl->vb;
323c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
324c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   /* May need to map a vertex buffer object for every attribute plus
325c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    * one for the index buffer.
326c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
327c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1];
328c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   GLuint nr_bo = 0;
329c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
330c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   /* Binding inputs may imply mapping some vertex buffer objects.
331c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    * They will need to be unmapped below.
332c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell    */
333c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   bind_inputs(ctx, arrays, min_index, max_index, bo, &nr_bo);
334c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   bind_indicies(ctx, ib, bo, &nr_bo);
335c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
336c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->Primitive = prim;
337c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->PrimitiveCount = nr_prims;
338c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   VB->Count = max_index - min_index;
339c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
340c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);
341c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
342c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   unmap_vbos(ctx, bo, nr_bo);
343c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell   free_space(ctx);
344c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell}
345c22f8a7787bd5260135a20a0c2ae8b743228497bKeith Whitwell
346