1fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/************************************************************************** 2fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 3fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. 4fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * All Rights Reserved. 5fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 6fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 7fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * copy of this software and associated documentation files (the 8fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * "Software"), to deal in the Software without restriction, including 9fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 10fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 11fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 12fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * the following conditions: 13fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 14fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * The above copyright notice and this permission notice (including the 15fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 16fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * of the Software. 17fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 18fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 26fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell **************************************************************************/ 27fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 28c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/context.h" 29c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/glheader.h" 30c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/enums.h" 31c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/imports.h" 3214b36cd568b7f3ae963430248fcd7ef0b7a165f6Vinson Lee#include "main/mfeatures.h" 33c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/mtypes.h" 342cf44390d1e819f23e1d7ceb3199276c9148c647Chia-I Wu#include "main/dispatch.h" 35c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "glapi/glapi.h" 36fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 37fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_context.h" 38fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 39fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 408d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#if FEATURE_dlist 418d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 42fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 43f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergtypedef void (*attr_func)( struct gl_context *ctx, GLint target, const GLfloat * ); 44fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 45fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 462421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell/* This file makes heavy use of the aliasing of NV vertex attributes 4782152a2a8e1afeb61710318e769b1379be6c02c6keithw * with the legacy attributes, and also with ARB and Material 4882152a2a8e1afeb61710318e769b1379be6c02c6keithw * attributes as currently implemented. 492421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell */ 50f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void VertexAttrib1fvNV(struct gl_context *ctx, GLint target, const GLfloat *v) 51fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 52fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_VertexAttrib1fvNV(ctx->Exec, (target, v)); 53fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 54fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 55f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void VertexAttrib2fvNV(struct gl_context *ctx, GLint target, const GLfloat *v) 56fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 57fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_VertexAttrib2fvNV(ctx->Exec, (target, v)); 58fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 59fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 60f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void VertexAttrib3fvNV(struct gl_context *ctx, GLint target, const GLfloat *v) 61fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 62fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_VertexAttrib3fvNV(ctx->Exec, (target, v)); 63fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 64fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 65f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void VertexAttrib4fvNV(struct gl_context *ctx, GLint target, const GLfloat *v) 66fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 67fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_VertexAttrib4fvNV(ctx->Exec, (target, v)); 68fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 69fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 70fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic attr_func vert_attrfunc[4] = { 71fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VertexAttrib1fvNV, 72fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VertexAttrib2fvNV, 73fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VertexAttrib3fvNV, 74fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VertexAttrib4fvNV 75fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}; 76fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 77fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstruct loopback_attr { 78fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint target; 79fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint sz; 80fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell attr_func func; 81fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}; 82fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 83fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Don't emit ends and begins on wrapped primitives. Don't replay 84fab1f07d6ad01463897ae792f4b33738afb07369Jeff Smith * wrapped vertices. If we get here, it's probably because the 85fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * precalculated wrapping is wrong. 86fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 87f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void loopback_prim( struct gl_context *ctx, 88fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *buffer, 89fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct _mesa_prim *prim, 90fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint wrap_count, 91fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint vertex_size, 92fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct loopback_attr *la, GLuint nr ) 93fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 94fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint start = prim->start; 95fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint end = start + prim->count; 96fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *data; 97fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint j; 98fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint k; 99fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 100fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (0) 101298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("loopback prim %s(%s,%s) verts %d..%d\n", 102298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg _mesa_lookup_prim_by_nr(prim->mode), 103298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg prim->begin ? "begin" : "..", 104298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg prim->end ? "end" : "..", 105298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg start, 106298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg end); 107fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 108fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (prim->begin) { 109fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_Begin(GET_DISPATCH(), ( prim->mode )); 110fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 111fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else { 112fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(start == 0); 113fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell start += wrap_count; 114fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 115fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 116fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell data = buffer + start * vertex_size; 117fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 118fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (j = start ; j < end ; j++) { 119fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *tmp = data + la[0].sz; 120fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 121fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (k = 1 ; k < nr ; k++) { 122fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell la[k].func( ctx, la[k].target, tmp ); 123fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell tmp += la[k].sz; 124fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 125fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 126fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Fire the vertex 127fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 128fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell la[0].func( ctx, VBO_ATTRIB_POS, data ); 129fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell data = tmp; 130fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 131fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 132fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (prim->end) { 133fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_End(GET_DISPATCH(), ()); 134fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 135fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 136fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 137fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Primitives generated by DrawArrays/DrawElements/Rectf may be 138fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * caught here. If there is no primitive in progress, execute them 139fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * normally, otherwise need to track and discard the generated 140fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * primitives. 141fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 142f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void loopback_weak_prim( struct gl_context *ctx, 143fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct _mesa_prim *prim ) 144fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 145fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Use the prim_weak flag to ensure that if this primitive 146fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * wraps, we don't mistake future vertex_lists for part of the 147fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * surrounding primitive. 148fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 149fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * While this flag is set, we are simply disposing of data 150fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * generated by an operation now known to be a noop. 151fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 152fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (prim->begin) 153fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.CurrentExecPrimitive |= VBO_SAVE_PRIM_WEAK; 154fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (prim->end) 155fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.CurrentExecPrimitive &= ~VBO_SAVE_PRIM_WEAK; 156fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 157fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 158fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 159f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_loopback_vertex_list( struct gl_context *ctx, 160fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *buffer, 161fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLubyte *attrsz, 162fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct _mesa_prim *prim, 163fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint prim_count, 164fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint wrap_count, 165fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint vertex_size) 166fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 167fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct loopback_attr la[VBO_ATTRIB_MAX]; 168fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i, nr = 0; 169fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1702421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell /* All Legacy, NV, ARB and Material attributes are routed through 1712421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell * the NV attributes entrypoints: 1722421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell */ 1732421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) { 174fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (attrsz[i]) { 175fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell la[nr].target = i; 176fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell la[nr].sz = attrsz[i]; 177fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell la[nr].func = vert_attrfunc[attrsz[i]-1]; 178fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell nr++; 179fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 180fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 181fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 182fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < prim_count ; i++) { 183fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if ((prim[i].mode & VBO_SAVE_PRIM_WEAK) && 184fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END)) 185fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { 186fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell loopback_weak_prim( ctx, &prim[i] ); 187fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 188fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else 189fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { 190fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell loopback_prim( ctx, buffer, &prim[i], wrap_count, vertex_size, la, nr ); 191fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 192fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 193fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1948d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 1958d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 1968d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#endif /* FEATURE_dlist */ 197