| 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 "context.h" |
| 30 |
#include "macros.h" |
| 31 |
#include "imports.h" |
| 32 |
#include "state.h" |
| 33 |
#include "mtypes.h" |
| 34 |
|
| 35 |
#include "array_cache/acache.h" |
| 36 |
#include "math/m_translate.h" |
| 37 |
|
| 38 |
#include "t_array_import.h" |
| 39 |
#include "t_context.h" |
| 40 |
|
| 41 |
|
| 42 |
static void _tnl_import_vertex( GLcontext *ctx, |
| 43 |
GLboolean writeable, |
| 44 |
GLboolean stride ) |
| 45 |
{ |
| 46 |
struct gl_client_array *tmp; |
| 47 |
GLboolean is_writeable = 0; |
| 48 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 49 |
const GLubyte *data; |
| 50 |
|
| 51 |
tmp = _ac_import_vertex(ctx, |
| 52 |
GL_FLOAT, |
| 53 |
stride ? 4*sizeof(GLfloat) : 0, |
| 54 |
0, |
| 55 |
writeable, |
| 56 |
&is_writeable); |
| 57 |
|
| 58 |
data = tmp->Ptr; |
| 59 |
inputs->Obj.data = (GLfloat (*)[4]) data; |
| 60 |
inputs->Obj.start = (GLfloat *) data; |
| 61 |
inputs->Obj.stride = tmp->StrideB; |
| 62 |
inputs->Obj.size = tmp->Size; |
| 63 |
} |
| 64 |
|
| 65 |
static void _tnl_import_normal( GLcontext *ctx, |
| 66 |
GLboolean writeable, |
| 67 |
GLboolean stride ) |
| 68 |
{ |
| 69 |
struct gl_client_array *tmp; |
| 70 |
GLboolean is_writeable = 0; |
| 71 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 72 |
const GLubyte *data; |
| 73 |
|
| 74 |
tmp = _ac_import_normal(ctx, GL_FLOAT, |
| 75 |
stride ? 3*sizeof(GLfloat) : 0, writeable, |
| 76 |
&is_writeable); |
| 77 |
|
| 78 |
data = tmp->Ptr; |
| 79 |
inputs->Normal.data = (GLfloat (*)[4]) data; |
| 80 |
inputs->Normal.start = (GLfloat *) data; |
| 81 |
inputs->Normal.stride = tmp->StrideB; |
| 82 |
inputs->Normal.size = 3; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
static void _tnl_import_color( GLcontext *ctx, |
| 87 |
GLboolean writeable, |
| 88 |
GLboolean stride ) |
| 89 |
{ |
| 90 |
struct gl_client_array *tmp; |
| 91 |
GLboolean is_writeable = 0; |
| 92 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 93 |
const GLubyte *data; |
| 94 |
|
| 95 |
tmp = _ac_import_color(ctx, |
| 96 |
GL_FLOAT, |
| 97 |
stride ? 4*sizeof(GLfloat) : 0, |
| 98 |
4, |
| 99 |
writeable, |
| 100 |
&is_writeable); |
| 101 |
|
| 102 |
data = tmp->Ptr; |
| 103 |
inputs->Color.data = (GLfloat (*)[4]) data; |
| 104 |
inputs->Color.start = (GLfloat *) data; |
| 105 |
inputs->Color.stride = tmp->StrideB; |
| 106 |
inputs->Color.size = tmp->Size; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
static void _tnl_import_secondarycolor( GLcontext *ctx, |
| 111 |
GLboolean writeable, |
| 112 |
GLboolean stride ) |
| 113 |
{ |
| 114 |
struct gl_client_array *tmp; |
| 115 |
GLboolean is_writeable = 0; |
| 116 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 117 |
const GLubyte *data; |
| 118 |
|
| 119 |
tmp = _ac_import_secondarycolor(ctx, |
| 120 |
GL_FLOAT, |
| 121 |
stride ? 4*sizeof(GLfloat) : 0, |
| 122 |
4, |
| 123 |
writeable, |
| 124 |
&is_writeable); |
| 125 |
|
| 126 |
data = tmp->Ptr; |
| 127 |
inputs->SecondaryColor.data = (GLfloat (*)[4]) data; |
| 128 |
inputs->SecondaryColor.start = (GLfloat *) data; |
| 129 |
inputs->SecondaryColor.stride = tmp->StrideB; |
| 130 |
inputs->SecondaryColor.size = tmp->Size; |
| 131 |
} |
| 132 |
|
| 133 |
static void _tnl_import_fogcoord( GLcontext *ctx, |
| 134 |
GLboolean writeable, |
| 135 |
GLboolean stride ) |
| 136 |
{ |
| 137 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 138 |
struct gl_client_array *tmp; |
| 139 |
GLboolean is_writeable = 0; |
| 140 |
const GLubyte *data; |
| 141 |
|
| 142 |
tmp = _ac_import_fogcoord(ctx, GL_FLOAT, |
| 143 |
stride ? sizeof(GLfloat) : 0, writeable, |
| 144 |
&is_writeable); |
| 145 |
|
| 146 |
data = tmp->Ptr; |
| 147 |
inputs->FogCoord.data = (GLfloat (*)[4]) data; |
| 148 |
inputs->FogCoord.start = (GLfloat *) data; |
| 149 |
inputs->FogCoord.stride = tmp->StrideB; |
| 150 |
} |
| 151 |
|
| 152 |
static void _tnl_import_index( GLcontext *ctx, |
| 153 |
GLboolean writeable, |
| 154 |
GLboolean stride ) |
| 155 |
{ |
| 156 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 157 |
struct gl_client_array *tmp; |
| 158 |
GLboolean is_writeable = 0; |
| 159 |
const GLubyte *data; |
| 160 |
|
| 161 |
tmp = _ac_import_index(ctx, GL_FLOAT, |
| 162 |
stride ? sizeof(GLfloat) : 0, writeable, |
| 163 |
&is_writeable); |
| 164 |
|
| 165 |
data = tmp->Ptr; |
| 166 |
inputs->Index.data = (GLfloat (*)[4]) data; |
| 167 |
inputs->Index.start = (GLfloat *) data; |
| 168 |
inputs->Index.stride = tmp->StrideB; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
static void _tnl_import_texcoord( GLcontext *ctx, |
| 173 |
GLuint unit, |
| 174 |
GLboolean writeable, |
| 175 |
GLboolean stride ) |
| 176 |
{ |
| 177 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 178 |
struct gl_client_array *tmp; |
| 179 |
GLboolean is_writeable = 0; |
| 180 |
const GLubyte *data; |
| 181 |
|
| 182 |
tmp = _ac_import_texcoord(ctx, unit, GL_FLOAT, |
| 183 |
stride ? 4 * sizeof(GLfloat) : 0, |
| 184 |
0, |
| 185 |
writeable, |
| 186 |
&is_writeable); |
| 187 |
|
| 188 |
data = tmp->Ptr; |
| 189 |
inputs->TexCoord[unit].data = (GLfloat (*)[4]) data; |
| 190 |
inputs->TexCoord[unit].start = (GLfloat *) data; |
| 191 |
inputs->TexCoord[unit].stride = tmp->StrideB; |
| 192 |
inputs->TexCoord[unit].size = tmp->Size; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
static void _tnl_import_edgeflag( GLcontext *ctx, |
| 197 |
GLboolean writeable, |
| 198 |
GLboolean stride ) |
| 199 |
{ |
| 200 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 201 |
struct gl_client_array *tmp; |
| 202 |
GLboolean is_writeable = 0; |
| 203 |
const GLubyte *data; |
| 204 |
(void) writeable; (void) stride; |
| 205 |
|
| 206 |
tmp = _ac_import_edgeflag(ctx, GL_UNSIGNED_BYTE, |
| 207 |
sizeof(GLubyte), |
| 208 |
0, |
| 209 |
&is_writeable); |
| 210 |
|
| 211 |
data = tmp->Ptr; |
| 212 |
inputs->EdgeFlag = (GLubyte *) data; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
static void _tnl_import_attrib( GLcontext *ctx, |
| 218 |
GLuint index, |
| 219 |
GLboolean writeable, |
| 220 |
GLboolean stride ) |
| 221 |
{ |
| 222 |
struct tnl_vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; |
| 223 |
struct gl_client_array *tmp; |
| 224 |
GLboolean is_writeable = 0; |
| 225 |
const GLubyte *data; |
| 226 |
|
| 227 |
tmp = _ac_import_attrib(ctx, index, GL_FLOAT, |
| 228 |
stride ? 4 * sizeof(GLfloat) : 0, |
| 229 |
4, /* want GLfloat[4] */ |
| 230 |
writeable, |
| 231 |
&is_writeable); |
| 232 |
|
| 233 |
data = tmp->Ptr; |
| 234 |
inputs->Attribs[index].data = (GLfloat (*)[4]) data; |
| 235 |
inputs->Attribs[index].start = (GLfloat *) data; |
| 236 |
inputs->Attribs[index].stride = tmp->StrideB; |
| 237 |
inputs->Attribs[index].size = tmp->Size; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
static void _tnl_constant_attrib( TNLcontext *tnl, |
| 242 |
struct tnl_vertex_arrays *tmp, |
| 243 |
GLuint i ) |
| 244 |
{ |
| 245 |
tmp->Attribs[i].count = 1; |
| 246 |
tmp->Attribs[i].data = (GLfloat (*)[4]) tnl->vtx.current[i]; |
| 247 |
tmp->Attribs[i].start = tnl->vtx.current[i]; |
| 248 |
tmp->Attribs[i].size = 4; |
| 249 |
tmp->Attribs[i].stride = 0; |
| 250 |
tnl->vb.AttribPtr[i] = &tmp->Attribs[i]; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLint end) |
| 256 |
{ |
| 257 |
TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 258 |
struct vertex_buffer *VB = &tnl->vb; |
| 259 |
struct tnl_vertex_arrays *tmp = &tnl->array_inputs; |
| 260 |
GLuint i, index; |
| 261 |
|
| 262 |
VB->Count = end - start; |
| 263 |
VB->Elts = NULL; |
| 264 |
|
| 265 |
_ac_import_range( ctx, start, end ); |
| 266 |
|
| 267 |
/* When vertex program mode is enabled, the generic vertex program |
| 268 |
* attribute arrays have priority over the conventional attributes. |
| 269 |
* Try to use them now. |
| 270 |
*/ |
| 271 |
for (index = 0; index < VERT_ATTRIB_MAX; index++) { |
| 272 |
/* When vertex program mode is enabled, the generic vertex attribute |
| 273 |
* arrays have priority over the conventional vertex arrays. |
| 274 |
*/ |
| 275 |
if (ctx->VertexProgram._Enabled |
| 276 |
&& ctx->Array.VertexAttrib[index].Enabled) { |
| 277 |
/* Use generic attribute array */ |
| 278 |
_tnl_import_attrib( ctx, index, GL_FALSE, GL_TRUE ); |
| 279 |
VB->AttribPtr[index] = &tmp->Attribs[index]; |
| 280 |
} |
| 281 |
/* use conventional arrays... */ |
| 282 |
else if (index == VERT_ATTRIB_POS) { |
| 283 |
_tnl_import_vertex( ctx, 0, 0 ); |
| 284 |
tmp->Obj.count = VB->Count; |
| 285 |
VB->AttribPtr[_TNL_ATTRIB_POS] = &tmp->Obj; |
| 286 |
} |
| 287 |
else if (index == VERT_ATTRIB_NORMAL) { |
| 288 |
_tnl_import_normal( ctx, 0, 0 ); |
| 289 |
tmp->Normal.count = VB->Count; |
| 290 |
VB->AttribPtr[_TNL_ATTRIB_NORMAL] = &tmp->Normal; |
| 291 |
} |
| 292 |
else if (index == VERT_ATTRIB_COLOR0) { |
| 293 |
_tnl_import_color( ctx, 0, 0 ); |
| 294 |
tmp->Color.count = VB->Count; |
| 295 |
VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &tmp->Color; |
| 296 |
} |
| 297 |
else if (index == VERT_ATTRIB_COLOR1) { |
| 298 |
_tnl_import_secondarycolor( ctx, 0, 0 ); |
| 299 |
tmp->SecondaryColor.count = VB->Count; |
| 300 |
VB->AttribPtr[_TNL_ATTRIB_COLOR1] = &tmp->SecondaryColor; |
| 301 |
} |
| 302 |
else if (index == VERT_ATTRIB_FOG) { |
| 303 |
_tnl_import_fogcoord( ctx, 0, 0 ); |
| 304 |
tmp->FogCoord.count = VB->Count; |
| 305 |
VB->AttribPtr[_TNL_ATTRIB_FOG] = &tmp->FogCoord; |
| 306 |
} |
| 307 |
else if (index >= VERT_ATTRIB_TEX0 && index <= VERT_ATTRIB_TEX7) { |
| 308 |
i = index - VERT_ATTRIB_TEX0; |
| 309 |
_tnl_import_texcoord( ctx, i, GL_FALSE, GL_FALSE ); |
| 310 |
tmp->TexCoord[i].count = VB->Count; |
| 311 |
VB->AttribPtr[_TNL_ATTRIB_TEX0 + i] = &tmp->TexCoord[i]; |
| 312 |
} |
| 313 |
else { |
| 314 |
_tnl_constant_attrib(tnl, tmp, index); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
/* odd-ball vertex attributes */ |
| 319 |
{ |
| 320 |
_tnl_import_index( ctx, 0, 0 ); |
| 321 |
tmp->Index.count = VB->Count; |
| 322 |
VB->AttribPtr[_TNL_ATTRIB_INDEX] = &tmp->Index; |
| 323 |
} |
| 324 |
|
| 325 |
{ |
| 326 |
_tnl_import_edgeflag( ctx, GL_TRUE, sizeof(GLboolean) ); |
| 327 |
VB->EdgeFlag = (GLboolean *) tmp->EdgeFlag; |
| 328 |
} |
| 329 |
|
| 330 |
/* These are constant & could be precalculated: |
| 331 |
*/ |
| 332 |
for (i = _TNL_ATTRIB_MAT_FRONT_AMBIENT; i < _TNL_ATTRIB_INDEX; i++) { |
| 333 |
_tnl_constant_attrib(tnl, tmp, i); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
/* Legacy pointers -- remove one day. |
| 338 |
*/ |
| 339 |
VB->ObjPtr = VB->AttribPtr[_TNL_ATTRIB_POS]; |
| 340 |
VB->NormalPtr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]; |
| 341 |
VB->ColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR0]; |
| 342 |
VB->ColorPtr[1] = NULL; |
| 343 |
VB->IndexPtr[0] = VB->AttribPtr[_TNL_ATTRIB_INDEX]; |
| 344 |
VB->IndexPtr[1] = NULL; |
| 345 |
VB->SecondaryColorPtr[0] = VB->AttribPtr[_TNL_ATTRIB_COLOR1]; |
| 346 |
VB->SecondaryColorPtr[1] = NULL; |
| 347 |
VB->FogCoordPtr = VB->AttribPtr[_TNL_ATTRIB_FOG]; |
| 348 |
|
| 349 |
for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { |
| 350 |
VB->TexCoordPtr[i] = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]; |
| 351 |
} |
| 352 |
} |