| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.1 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
* |
| 24 |
* Authors: |
| 25 |
* Keith Whitwell <[email protected]> |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "glheader.h" |
| 29 |
#include "api_eval.h" |
| 30 |
#include "context.h" |
| 31 |
#include "macros.h" |
| 32 |
#include "math/m_eval.h" |
| 33 |
#include "t_vtx_api.h" |
| 34 |
#include "dispatch.h" |
| 35 |
|
| 36 |
|
| 37 |
static void clear_active_eval1( TNLcontext *tnl, GLuint attr ) |
| 38 |
{ |
| 39 |
tnl->vtx.eval.map1[attr].map = NULL; |
| 40 |
} |
| 41 |
|
| 42 |
static void clear_active_eval2( TNLcontext *tnl, GLuint attr ) |
| 43 |
{ |
| 44 |
tnl->vtx.eval.map2[attr].map = NULL; |
| 45 |
} |
| 46 |
|
| 47 |
static void set_active_eval1( TNLcontext *tnl, GLuint attr, GLuint dim, |
| 48 |
struct gl_1d_map *map ) |
| 49 |
{ |
| 50 |
if (!tnl->vtx.eval.map1[attr].map) { |
| 51 |
tnl->vtx.eval.map1[attr].map = map; |
| 52 |
tnl->vtx.eval.map1[attr].sz = dim; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
static void set_active_eval2( TNLcontext *tnl, GLuint attr, GLuint dim, |
| 57 |
struct gl_2d_map *map ) |
| 58 |
{ |
| 59 |
if (!tnl->vtx.eval.map2[attr].map) { |
| 60 |
tnl->vtx.eval.map2[attr].map = map; |
| 61 |
tnl->vtx.eval.map2[attr].sz = dim; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
void _tnl_update_eval( GLcontext *ctx ) |
| 66 |
{ |
| 67 |
TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 68 |
GLuint attr; |
| 69 |
|
| 70 |
/* Vertex program maps have priority over conventional attribs */ |
| 71 |
|
| 72 |
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { |
| 73 |
clear_active_eval1( tnl, attr ); |
| 74 |
clear_active_eval2( tnl, attr ); |
| 75 |
} |
| 76 |
|
| 77 |
if (ctx->VertexProgram._Enabled) { |
| 78 |
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { |
| 79 |
if (ctx->Eval.Map1Attrib[attr]) |
| 80 |
set_active_eval1( tnl, attr, 4, &ctx->EvalMap.Map1Attrib[attr] ); |
| 81 |
|
| 82 |
if (ctx->Eval.Map2Attrib[attr]) |
| 83 |
set_active_eval2( tnl, attr, 4, &ctx->EvalMap.Map2Attrib[attr] ); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
if (ctx->Eval.Map1Color4) |
| 88 |
set_active_eval1( tnl, VERT_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map1Color4 ); |
| 89 |
|
| 90 |
if (ctx->Eval.Map2Color4) |
| 91 |
set_active_eval2( tnl, VERT_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map2Color4 ); |
| 92 |
|
| 93 |
if (ctx->Eval.Map1TextureCoord4) |
| 94 |
set_active_eval1( tnl, VERT_ATTRIB_TEX0, 4, &ctx->EvalMap.Map1Texture4 ); |
| 95 |
else if (ctx->Eval.Map1TextureCoord3) |
| 96 |
set_active_eval1( tnl, VERT_ATTRIB_TEX0, 3, &ctx->EvalMap.Map1Texture3 ); |
| 97 |
else if (ctx->Eval.Map1TextureCoord2) |
| 98 |
set_active_eval1( tnl, VERT_ATTRIB_TEX0, 2, &ctx->EvalMap.Map1Texture2 ); |
| 99 |
else if (ctx->Eval.Map1TextureCoord1) |
| 100 |
set_active_eval1( tnl, VERT_ATTRIB_TEX0, 1, &ctx->EvalMap.Map1Texture1 ); |
| 101 |
|
| 102 |
if (ctx->Eval.Map2TextureCoord4) |
| 103 |
set_active_eval2( tnl, VERT_ATTRIB_TEX0, 4, &ctx->EvalMap.Map2Texture4 ); |
| 104 |
else if (ctx->Eval.Map2TextureCoord3) |
| 105 |
set_active_eval2( tnl, VERT_ATTRIB_TEX0, 3, &ctx->EvalMap.Map2Texture3 ); |
| 106 |
else if (ctx->Eval.Map2TextureCoord2) |
| 107 |
set_active_eval2( tnl, VERT_ATTRIB_TEX0, 2, &ctx->EvalMap.Map2Texture2 ); |
| 108 |
else if (ctx->Eval.Map2TextureCoord1) |
| 109 |
set_active_eval2( tnl, VERT_ATTRIB_TEX0, 1, &ctx->EvalMap.Map2Texture1 ); |
| 110 |
|
| 111 |
if (ctx->Eval.Map1Normal) |
| 112 |
set_active_eval1( tnl, VERT_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map1Normal ); |
| 113 |
|
| 114 |
if (ctx->Eval.Map2Normal) |
| 115 |
set_active_eval2( tnl, VERT_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map2Normal ); |
| 116 |
|
| 117 |
if (ctx->Eval.Map1Vertex4) |
| 118 |
set_active_eval1( tnl, VERT_ATTRIB_POS, 4, &ctx->EvalMap.Map1Vertex4 ); |
| 119 |
else if (ctx->Eval.Map1Vertex3) |
| 120 |
set_active_eval1( tnl, VERT_ATTRIB_POS, 3, &ctx->EvalMap.Map1Vertex3 ); |
| 121 |
|
| 122 |
if (ctx->Eval.Map2Vertex4) |
| 123 |
set_active_eval2( tnl, VERT_ATTRIB_POS, 4, &ctx->EvalMap.Map2Vertex4 ); |
| 124 |
else if (ctx->Eval.Map2Vertex3) |
| 125 |
set_active_eval2( tnl, VERT_ATTRIB_POS, 3, &ctx->EvalMap.Map2Vertex3 ); |
| 126 |
|
| 127 |
tnl->vtx.eval.new_state = 0; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
void _tnl_do_EvalCoord1f(GLcontext* ctx, GLfloat u) |
| 133 |
{ |
| 134 |
TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 135 |
GLuint attr; |
| 136 |
|
| 137 |
for (attr = 1; attr <= _TNL_ATTRIB_INDEX; attr++) { |
| 138 |
struct gl_1d_map *map = tnl->vtx.eval.map1[attr].map; |
| 139 |
if (map) { |
| 140 |
GLfloat uu = (u - map->u1) * map->du; |
| 141 |
GLfloat data[4]; |
| 142 |
|
| 143 |
ASSIGN_4V(data, 0, 0, 0, 1); |
| 144 |
|
| 145 |
_math_horner_bezier_curve(map->Points, data, uu, |
| 146 |
tnl->vtx.eval.map1[attr].sz, |
| 147 |
map->Order); |
| 148 |
|
| 149 |
COPY_SZ_4V( tnl->vtx.attrptr[attr], |
| 150 |
tnl->vtx.attrsz[attr], |
| 151 |
data ); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
/** Vertex -- EvalCoord1f is a noop if this map not enabled: |
| 156 |
**/ |
| 157 |
if (tnl->vtx.eval.map1[0].map) { |
| 158 |
struct gl_1d_map *map = tnl->vtx.eval.map1[0].map; |
| 159 |
GLfloat uu = (u - map->u1) * map->du; |
| 160 |
GLfloat vertex[4]; |
| 161 |
|
| 162 |
ASSIGN_4V(vertex, 0, 0, 0, 1); |
| 163 |
|
| 164 |
_math_horner_bezier_curve(map->Points, vertex, uu, |
| 165 |
tnl->vtx.eval.map1[0].sz, |
| 166 |
map->Order); |
| 167 |
|
| 168 |
if (tnl->vtx.eval.map1[0].sz == 4) |
| 169 |
CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); |
| 170 |
else |
| 171 |
CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
void _tnl_do_EvalCoord2f( GLcontext* ctx, GLfloat u, GLfloat v ) |
| 178 |
{ |
| 179 |
TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 180 |
GLuint attr; |
| 181 |
|
| 182 |
for (attr = 1; attr <= _TNL_ATTRIB_INDEX; attr++) { |
| 183 |
struct gl_2d_map *map = tnl->vtx.eval.map2[attr].map; |
| 184 |
if (map) { |
| 185 |
GLfloat uu = (u - map->u1) * map->du; |
| 186 |
GLfloat vv = (v - map->v1) * map->dv; |
| 187 |
GLfloat data[4]; |
| 188 |
|
| 189 |
ASSIGN_4V(data, 0, 0, 0, 1); |
| 190 |
|
| 191 |
_math_horner_bezier_surf(map->Points, |
| 192 |
data, |
| 193 |
uu, vv, |
| 194 |
tnl->vtx.eval.map2[attr].sz, |
| 195 |
map->Uorder, map->Vorder); |
| 196 |
|
| 197 |
COPY_SZ_4V( tnl->vtx.attrptr[attr], |
| 198 |
tnl->vtx.attrsz[attr], |
| 199 |
data ); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
/** Vertex -- EvalCoord2f is a noop if this map not enabled: |
| 204 |
**/ |
| 205 |
if (tnl->vtx.eval.map2[0].map) { |
| 206 |
struct gl_2d_map *map = tnl->vtx.eval.map2[0].map; |
| 207 |
GLfloat uu = (u - map->u1) * map->du; |
| 208 |
GLfloat vv = (v - map->v1) * map->dv; |
| 209 |
GLfloat vertex[4]; |
| 210 |
|
| 211 |
ASSIGN_4V(vertex, 0, 0, 0, 1); |
| 212 |
|
| 213 |
if (ctx->Eval.AutoNormal) { |
| 214 |
GLfloat normal[4]; |
| 215 |
GLfloat du[4], dv[4]; |
| 216 |
|
| 217 |
_math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, |
| 218 |
tnl->vtx.eval.map2[0].sz, |
| 219 |
map->Uorder, map->Vorder); |
| 220 |
|
| 221 |
if (tnl->vtx.eval.map2[0].sz == 4) { |
| 222 |
du[0] = du[0]*vertex[3] - du[3]*vertex[0]; |
| 223 |
du[1] = du[1]*vertex[3] - du[3]*vertex[1]; |
| 224 |
du[2] = du[2]*vertex[3] - du[3]*vertex[2]; |
| 225 |
|
| 226 |
dv[0] = dv[0]*vertex[3] - dv[3]*vertex[0]; |
| 227 |
dv[1] = dv[1]*vertex[3] - dv[3]*vertex[1]; |
| 228 |
dv[2] = dv[2]*vertex[3] - dv[3]*vertex[2]; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
CROSS3(normal, du, dv); |
| 233 |
NORMALIZE_3FV(normal); |
| 234 |
normal[3] = 1.0; |
| 235 |
|
| 236 |
COPY_SZ_4V( tnl->vtx.attrptr[_TNL_ATTRIB_NORMAL], |
| 237 |
tnl->vtx.attrsz[_TNL_ATTRIB_NORMAL], |
| 238 |
normal ); |
| 239 |
|
| 240 |
} |
| 241 |
else { |
| 242 |
_math_horner_bezier_surf(map->Points, vertex, uu, vv, |
| 243 |
tnl->vtx.eval.map2[0].sz, |
| 244 |
map->Uorder, map->Vorder); |
| 245 |
} |
| 246 |
|
| 247 |
if (tnl->vtx.attrsz[0] == 4) |
| 248 |
CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); |
| 249 |
else |
| 250 |
CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
|