1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg * 24848b8605Smrg * Authors: 25848b8605Smrg * Keith Whitwell <keithw@vmware.com> 26848b8605Smrg */ 27848b8605Smrg 28848b8605Smrg#include "main/glheader.h" 29848b8605Smrg#include "main/context.h" 30848b8605Smrg#include "main/macros.h" 31848b8605Smrg#include "math/m_eval.h" 32848b8605Smrg#include "main/dispatch.h" 33848b8605Smrg#include "vbo_exec.h" 34848b8605Smrg 35848b8605Smrg 36848b8605Smrgstatic void clear_active_eval1( struct vbo_exec_context *exec, GLuint attr ) 37848b8605Smrg{ 38b8e80941Smrg assert(attr < ARRAY_SIZE(exec->eval.map1)); 39848b8605Smrg exec->eval.map1[attr].map = NULL; 40848b8605Smrg} 41848b8605Smrg 42848b8605Smrgstatic void clear_active_eval2( struct vbo_exec_context *exec, GLuint attr ) 43848b8605Smrg{ 44b8e80941Smrg assert(attr < ARRAY_SIZE(exec->eval.map2)); 45848b8605Smrg exec->eval.map2[attr].map = NULL; 46848b8605Smrg} 47848b8605Smrg 48848b8605Smrgstatic void set_active_eval1( struct vbo_exec_context *exec, GLuint attr, GLuint dim, 49848b8605Smrg struct gl_1d_map *map ) 50848b8605Smrg{ 51b8e80941Smrg assert(attr < ARRAY_SIZE(exec->eval.map1)); 52848b8605Smrg if (!exec->eval.map1[attr].map) { 53848b8605Smrg exec->eval.map1[attr].map = map; 54848b8605Smrg exec->eval.map1[attr].sz = dim; 55848b8605Smrg } 56848b8605Smrg} 57848b8605Smrg 58848b8605Smrgstatic void set_active_eval2( struct vbo_exec_context *exec, GLuint attr, GLuint dim, 59848b8605Smrg struct gl_2d_map *map ) 60848b8605Smrg{ 61b8e80941Smrg assert(attr < ARRAY_SIZE(exec->eval.map2)); 62848b8605Smrg if (!exec->eval.map2[attr].map) { 63848b8605Smrg exec->eval.map2[attr].map = map; 64848b8605Smrg exec->eval.map2[attr].sz = dim; 65848b8605Smrg } 66848b8605Smrg} 67848b8605Smrg 68848b8605Smrgvoid vbo_exec_eval_update( struct vbo_exec_context *exec ) 69848b8605Smrg{ 70848b8605Smrg struct gl_context *ctx = exec->ctx; 71848b8605Smrg GLuint attr; 72848b8605Smrg 73848b8605Smrg /* Vertex program maps have priority over conventional attribs */ 74848b8605Smrg 75848b8605Smrg for (attr = 0; attr < VBO_ATTRIB_FIRST_MATERIAL; attr++) { 76848b8605Smrg clear_active_eval1( exec, attr ); 77848b8605Smrg clear_active_eval2( exec, attr ); 78848b8605Smrg } 79848b8605Smrg 80848b8605Smrg if (ctx->Eval.Map1Color4) 81848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map1Color4 ); 82848b8605Smrg 83848b8605Smrg if (ctx->Eval.Map2Color4) 84848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map2Color4 ); 85848b8605Smrg 86848b8605Smrg if (ctx->Eval.Map1TextureCoord4) 87848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_TEX0, 4, &ctx->EvalMap.Map1Texture4 ); 88848b8605Smrg else if (ctx->Eval.Map1TextureCoord3) 89848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_TEX0, 3, &ctx->EvalMap.Map1Texture3 ); 90848b8605Smrg else if (ctx->Eval.Map1TextureCoord2) 91848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_TEX0, 2, &ctx->EvalMap.Map1Texture2 ); 92848b8605Smrg else if (ctx->Eval.Map1TextureCoord1) 93848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_TEX0, 1, &ctx->EvalMap.Map1Texture1 ); 94848b8605Smrg 95848b8605Smrg if (ctx->Eval.Map2TextureCoord4) 96848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_TEX0, 4, &ctx->EvalMap.Map2Texture4 ); 97848b8605Smrg else if (ctx->Eval.Map2TextureCoord3) 98848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_TEX0, 3, &ctx->EvalMap.Map2Texture3 ); 99848b8605Smrg else if (ctx->Eval.Map2TextureCoord2) 100848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_TEX0, 2, &ctx->EvalMap.Map2Texture2 ); 101848b8605Smrg else if (ctx->Eval.Map2TextureCoord1) 102848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_TEX0, 1, &ctx->EvalMap.Map2Texture1 ); 103848b8605Smrg 104848b8605Smrg if (ctx->Eval.Map1Normal) 105848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map1Normal ); 106848b8605Smrg 107848b8605Smrg if (ctx->Eval.Map2Normal) 108848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map2Normal ); 109848b8605Smrg 110848b8605Smrg if (ctx->Eval.Map1Vertex4) 111848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_POS, 4, &ctx->EvalMap.Map1Vertex4 ); 112848b8605Smrg else if (ctx->Eval.Map1Vertex3) 113848b8605Smrg set_active_eval1( exec, VBO_ATTRIB_POS, 3, &ctx->EvalMap.Map1Vertex3 ); 114848b8605Smrg 115848b8605Smrg if (ctx->Eval.Map2Vertex4) 116848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_POS, 4, &ctx->EvalMap.Map2Vertex4 ); 117848b8605Smrg else if (ctx->Eval.Map2Vertex3) 118848b8605Smrg set_active_eval2( exec, VBO_ATTRIB_POS, 3, &ctx->EvalMap.Map2Vertex3 ); 119848b8605Smrg 120848b8605Smrg exec->eval.recalculate_maps = GL_FALSE; 121848b8605Smrg} 122848b8605Smrg 123848b8605Smrg 124848b8605Smrg 125848b8605Smrgvoid vbo_exec_do_EvalCoord1f(struct vbo_exec_context *exec, GLfloat u) 126848b8605Smrg{ 127848b8605Smrg GLuint attr; 128848b8605Smrg 129848b8605Smrg for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) { 130848b8605Smrg struct gl_1d_map *map = exec->eval.map1[attr].map; 131848b8605Smrg if (map) { 132848b8605Smrg GLfloat uu = (u - map->u1) * map->du; 133b8e80941Smrg fi_type data[4]; 134848b8605Smrg 135b8e80941Smrg ASSIGN_4V(data, FLOAT_AS_UNION(0), FLOAT_AS_UNION(0), 136b8e80941Smrg FLOAT_AS_UNION(0), FLOAT_AS_UNION(1)); 137848b8605Smrg 138b8e80941Smrg _math_horner_bezier_curve(map->Points, &data[0].f, uu, 139848b8605Smrg exec->eval.map1[attr].sz, 140848b8605Smrg map->Order); 141848b8605Smrg 142848b8605Smrg COPY_SZ_4V( exec->vtx.attrptr[attr], 143848b8605Smrg exec->vtx.attrsz[attr], 144848b8605Smrg data ); 145848b8605Smrg } 146848b8605Smrg } 147848b8605Smrg 148848b8605Smrg /** Vertex -- EvalCoord1f is a noop if this map not enabled: 149848b8605Smrg **/ 150848b8605Smrg if (exec->eval.map1[0].map) { 151848b8605Smrg struct gl_1d_map *map = exec->eval.map1[0].map; 152848b8605Smrg GLfloat uu = (u - map->u1) * map->du; 153848b8605Smrg GLfloat vertex[4]; 154848b8605Smrg 155848b8605Smrg ASSIGN_4V(vertex, 0, 0, 0, 1); 156848b8605Smrg 157848b8605Smrg _math_horner_bezier_curve(map->Points, vertex, uu, 158848b8605Smrg exec->eval.map1[0].sz, 159848b8605Smrg map->Order); 160848b8605Smrg 161848b8605Smrg if (exec->eval.map1[0].sz == 4) 162848b8605Smrg CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); 163848b8605Smrg else 164848b8605Smrg CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); 165848b8605Smrg } 166848b8605Smrg} 167848b8605Smrg 168848b8605Smrg 169848b8605Smrg 170848b8605Smrgvoid vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec, 171848b8605Smrg GLfloat u, GLfloat v ) 172848b8605Smrg{ 173848b8605Smrg GLuint attr; 174848b8605Smrg 175848b8605Smrg for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) { 176848b8605Smrg struct gl_2d_map *map = exec->eval.map2[attr].map; 177848b8605Smrg if (map) { 178848b8605Smrg GLfloat uu = (u - map->u1) * map->du; 179848b8605Smrg GLfloat vv = (v - map->v1) * map->dv; 180b8e80941Smrg fi_type data[4]; 181848b8605Smrg 182b8e80941Smrg ASSIGN_4V(data, FLOAT_AS_UNION(0), FLOAT_AS_UNION(0), 183b8e80941Smrg FLOAT_AS_UNION(0), FLOAT_AS_UNION(1)); 184848b8605Smrg 185848b8605Smrg _math_horner_bezier_surf(map->Points, 186b8e80941Smrg &data[0].f, 187848b8605Smrg uu, vv, 188848b8605Smrg exec->eval.map2[attr].sz, 189848b8605Smrg map->Uorder, map->Vorder); 190848b8605Smrg 191848b8605Smrg COPY_SZ_4V( exec->vtx.attrptr[attr], 192848b8605Smrg exec->vtx.attrsz[attr], 193848b8605Smrg data ); 194848b8605Smrg } 195848b8605Smrg } 196848b8605Smrg 197848b8605Smrg /** Vertex -- EvalCoord2f is a noop if this map not enabled: 198848b8605Smrg **/ 199848b8605Smrg if (exec->eval.map2[0].map) { 200848b8605Smrg struct gl_2d_map *map = exec->eval.map2[0].map; 201848b8605Smrg GLfloat uu = (u - map->u1) * map->du; 202848b8605Smrg GLfloat vv = (v - map->v1) * map->dv; 203848b8605Smrg GLfloat vertex[4]; 204848b8605Smrg 205848b8605Smrg ASSIGN_4V(vertex, 0, 0, 0, 1); 206848b8605Smrg 207848b8605Smrg if (exec->ctx->Eval.AutoNormal) { 208b8e80941Smrg fi_type normal[4]; 209848b8605Smrg GLfloat du[4], dv[4]; 210848b8605Smrg 211848b8605Smrg _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, 212848b8605Smrg exec->eval.map2[0].sz, 213848b8605Smrg map->Uorder, map->Vorder); 214848b8605Smrg 215848b8605Smrg if (exec->eval.map2[0].sz == 4) { 216848b8605Smrg du[0] = du[0]*vertex[3] - du[3]*vertex[0]; 217848b8605Smrg du[1] = du[1]*vertex[3] - du[3]*vertex[1]; 218848b8605Smrg du[2] = du[2]*vertex[3] - du[3]*vertex[2]; 219848b8605Smrg 220848b8605Smrg dv[0] = dv[0]*vertex[3] - dv[3]*vertex[0]; 221848b8605Smrg dv[1] = dv[1]*vertex[3] - dv[3]*vertex[1]; 222848b8605Smrg dv[2] = dv[2]*vertex[3] - dv[3]*vertex[2]; 223848b8605Smrg } 224848b8605Smrg 225848b8605Smrg 226b8e80941Smrg CROSS3(&normal[0].f, du, dv); 227b8e80941Smrg NORMALIZE_3FV(&normal[0].f); 228b8e80941Smrg normal[3] = FLOAT_AS_UNION(1.0); 229848b8605Smrg 230b8e80941Smrg COPY_SZ_4V( exec->vtx.attrptr[VBO_ATTRIB_NORMAL], 231848b8605Smrg exec->vtx.attrsz[VBO_ATTRIB_NORMAL], 232848b8605Smrg normal ); 233848b8605Smrg 234848b8605Smrg } 235848b8605Smrg else { 236848b8605Smrg _math_horner_bezier_surf(map->Points, vertex, uu, vv, 237848b8605Smrg exec->eval.map2[0].sz, 238848b8605Smrg map->Uorder, map->Vorder); 239848b8605Smrg } 240848b8605Smrg 241848b8605Smrg if (exec->vtx.attrsz[0] == 4) 242848b8605Smrg CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); 243848b8605Smrg else 244848b8605Smrg CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); 245848b8605Smrg } 246848b8605Smrg} 247848b8605Smrg 248848b8605Smrg 249