| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "tr_local.h" |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
void RB_CheckOverflow( int verts, int indexes ) { |
| 49 |
if (tess.numVertexes + verts < SHADER_MAX_VERTEXES |
| 50 |
&& tess.numIndexes + indexes < SHADER_MAX_INDEXES) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
RB_EndSurface(); |
| 55 |
|
| 56 |
if ( verts >= SHADER_MAX_VERTEXES ) { |
| 57 |
ri.Error(ERR_DROP, "RB_CheckOverflow: verts > MAX (%d > %d)", verts, SHADER_MAX_VERTEXES ); |
| 58 |
} |
| 59 |
if ( indexes >= SHADER_MAX_INDEXES ) { |
| 60 |
ri.Error(ERR_DROP, "RB_CheckOverflow: indices > MAX (%d > %d)", indexes, SHADER_MAX_INDEXES ); |
| 61 |
} |
| 62 |
|
| 63 |
RB_BeginSurface(tess.shader, tess.fogNum, tess.cubemapIndex ); |
| 64 |
} |
| 65 |
|
| 66 |
void RB_CheckVao(vao_t *vao) |
| 67 |
{ |
| 68 |
if (vao != glState.currentVao) |
| 69 |
{ |
| 70 |
RB_EndSurface(); |
| 71 |
RB_BeginSurface(tess.shader, tess.fogNum, tess.cubemapIndex); |
| 72 |
|
| 73 |
R_BindVao(vao); |
| 74 |
} |
| 75 |
|
| 76 |
if (vao != tess.vao) |
| 77 |
tess.useInternalVao = qfalse; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, float color[4], float s1, float t1, float s2, float t2 ) { |
| 87 |
vec3_t normal; |
| 88 |
int16_t iNormal[4]; |
| 89 |
uint16_t iColor[4]; |
| 90 |
int ndx; |
| 91 |
|
| 92 |
RB_CheckVao(tess.vao); |
| 93 |
|
| 94 |
RB_CHECKOVERFLOW( 4, 6 ); |
| 95 |
|
| 96 |
ndx = tess.numVertexes; |
| 97 |
|
| 98 |
|
| 99 |
tess.indexes[ tess.numIndexes ] = ndx; |
| 100 |
tess.indexes[ tess.numIndexes + 1 ] = ndx + 1; |
| 101 |
tess.indexes[ tess.numIndexes + 2 ] = ndx + 3; |
| 102 |
|
| 103 |
tess.indexes[ tess.numIndexes + 3 ] = ndx + 3; |
| 104 |
tess.indexes[ tess.numIndexes + 4 ] = ndx + 1; |
| 105 |
tess.indexes[ tess.numIndexes + 5 ] = ndx + 2; |
| 106 |
|
| 107 |
tess.xyz[ndx][0] = origin[0] + left[0] + up[0]; |
| 108 |
tess.xyz[ndx][1] = origin[1] + left[1] + up[1]; |
| 109 |
tess.xyz[ndx][2] = origin[2] + left[2] + up[2]; |
| 110 |
|
| 111 |
tess.xyz[ndx+1][0] = origin[0] - left[0] + up[0]; |
| 112 |
tess.xyz[ndx+1][1] = origin[1] - left[1] + up[1]; |
| 113 |
tess.xyz[ndx+1][2] = origin[2] - left[2] + up[2]; |
| 114 |
|
| 115 |
tess.xyz[ndx+2][0] = origin[0] - left[0] - up[0]; |
| 116 |
tess.xyz[ndx+2][1] = origin[1] - left[1] - up[1]; |
| 117 |
tess.xyz[ndx+2][2] = origin[2] - left[2] - up[2]; |
| 118 |
|
| 119 |
tess.xyz[ndx+3][0] = origin[0] + left[0] - up[0]; |
| 120 |
tess.xyz[ndx+3][1] = origin[1] + left[1] - up[1]; |
| 121 |
tess.xyz[ndx+3][2] = origin[2] + left[2] - up[2]; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
VectorSubtract( vec3_origin, backEnd.viewParms.or.axis[0], normal ); |
| 126 |
|
| 127 |
R_VaoPackNormal(iNormal, normal); |
| 128 |
|
| 129 |
VectorCopy4(iNormal, tess.normal[ndx]); |
| 130 |
VectorCopy4(iNormal, tess.normal[ndx + 1]); |
| 131 |
VectorCopy4(iNormal, tess.normal[ndx + 2]); |
| 132 |
VectorCopy4(iNormal, tess.normal[ndx + 3]); |
| 133 |
|
| 134 |
|
| 135 |
VectorSet2(tess.texCoords[ndx], s1, t1); |
| 136 |
VectorSet2(tess.lightCoords[ndx], s1, t1); |
| 137 |
|
| 138 |
VectorSet2(tess.texCoords[ndx+1], s2, t1); |
| 139 |
VectorSet2(tess.lightCoords[ndx+1], s2, t1); |
| 140 |
|
| 141 |
VectorSet2(tess.texCoords[ndx+2], s2, t2); |
| 142 |
VectorSet2(tess.lightCoords[ndx+2], s2, t2); |
| 143 |
|
| 144 |
VectorSet2(tess.texCoords[ndx+3], s1, t2); |
| 145 |
VectorSet2(tess.lightCoords[ndx+3], s1, t2); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
R_VaoPackColor(iColor, color); |
| 151 |
|
| 152 |
VectorCopy4(iColor, tess.color[ndx]); |
| 153 |
VectorCopy4(iColor, tess.color[ndx + 1]); |
| 154 |
VectorCopy4(iColor, tess.color[ndx + 2]); |
| 155 |
VectorCopy4(iColor, tess.color[ndx + 3]); |
| 156 |
|
| 157 |
tess.numVertexes += 4; |
| 158 |
tess.numIndexes += 6; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, float color[4] ) { |
| 167 |
RB_AddQuadStampExt( origin, left, up, color, 0, 0, 1, 1 ); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4]) |
| 179 |
{ |
| 180 |
GLimp_LogComment("--- RB_InstantQuad2 ---\n"); |
| 181 |
|
| 182 |
tess.numVertexes = 0; |
| 183 |
tess.numIndexes = 0; |
| 184 |
tess.firstIndex = 0; |
| 185 |
|
| 186 |
VectorCopy4(quadVerts[0], tess.xyz[tess.numVertexes]); |
| 187 |
VectorCopy2(texCoords[0], tess.texCoords[tess.numVertexes]); |
| 188 |
tess.numVertexes++; |
| 189 |
|
| 190 |
VectorCopy4(quadVerts[1], tess.xyz[tess.numVertexes]); |
| 191 |
VectorCopy2(texCoords[1], tess.texCoords[tess.numVertexes]); |
| 192 |
tess.numVertexes++; |
| 193 |
|
| 194 |
VectorCopy4(quadVerts[2], tess.xyz[tess.numVertexes]); |
| 195 |
VectorCopy2(texCoords[2], tess.texCoords[tess.numVertexes]); |
| 196 |
tess.numVertexes++; |
| 197 |
|
| 198 |
VectorCopy4(quadVerts[3], tess.xyz[tess.numVertexes]); |
| 199 |
VectorCopy2(texCoords[3], tess.texCoords[tess.numVertexes]); |
| 200 |
tess.numVertexes++; |
| 201 |
|
| 202 |
tess.indexes[tess.numIndexes++] = 0; |
| 203 |
tess.indexes[tess.numIndexes++] = 1; |
| 204 |
tess.indexes[tess.numIndexes++] = 2; |
| 205 |
tess.indexes[tess.numIndexes++] = 0; |
| 206 |
tess.indexes[tess.numIndexes++] = 2; |
| 207 |
tess.indexes[tess.numIndexes++] = 3; |
| 208 |
|
| 209 |
RB_UpdateTessVao(ATTR_POSITION | ATTR_TEXCOORD); |
| 210 |
|
| 211 |
R_DrawElements(tess.numIndexes, tess.firstIndex); |
| 212 |
|
| 213 |
tess.numIndexes = 0; |
| 214 |
tess.numVertexes = 0; |
| 215 |
tess.firstIndex = 0; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
void RB_InstantQuad(vec4_t quadVerts[4]) |
| 220 |
{ |
| 221 |
vec2_t texCoords[4]; |
| 222 |
|
| 223 |
VectorSet2(texCoords[0], 0.0f, 0.0f); |
| 224 |
VectorSet2(texCoords[1], 1.0f, 0.0f); |
| 225 |
VectorSet2(texCoords[2], 1.0f, 1.0f); |
| 226 |
VectorSet2(texCoords[3], 0.0f, 1.0f); |
| 227 |
|
| 228 |
GLSL_BindProgram(&tr.textureColorShader); |
| 229 |
|
| 230 |
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); |
| 231 |
GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite); |
| 232 |
|
| 233 |
RB_InstantQuad2(quadVerts, texCoords); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
static void RB_SurfaceSprite( void ) { |
| 243 |
vec3_t left, up; |
| 244 |
float radius; |
| 245 |
float colors[4]; |
| 246 |
trRefEntity_t *ent = backEnd.currentEntity; |
| 247 |
|
| 248 |
|
| 249 |
radius = ent->e.radius; |
| 250 |
if ( ent->e.rotation == 0 ) { |
| 251 |
VectorScale( backEnd.viewParms.or.axis[1], radius, left ); |
| 252 |
VectorScale( backEnd.viewParms.or.axis[2], radius, up ); |
| 253 |
} else { |
| 254 |
float s, c; |
| 255 |
float ang; |
| 256 |
|
| 257 |
ang = M_PI * ent->e.rotation / 180; |
| 258 |
s = sin( ang ); |
| 259 |
c = cos( ang ); |
| 260 |
|
| 261 |
VectorScale( backEnd.viewParms.or.axis[1], c * radius, left ); |
| 262 |
VectorMA( left, -s * radius, backEnd.viewParms.or.axis[2], left ); |
| 263 |
|
| 264 |
VectorScale( backEnd.viewParms.or.axis[2], c * radius, up ); |
| 265 |
VectorMA( up, s * radius, backEnd.viewParms.or.axis[1], up ); |
| 266 |
} |
| 267 |
if ( backEnd.viewParms.isMirror ) { |
| 268 |
VectorSubtract( vec3_origin, left, left ); |
| 269 |
} |
| 270 |
|
| 271 |
VectorScale4(ent->e.shaderRGBA, 1.0f / 255.0f, colors); |
| 272 |
|
| 273 |
RB_AddQuadStamp( ent->e.origin, left, up, colors ); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
static void RB_SurfacePolychain( srfPoly_t *p ) { |
| 283 |
int i; |
| 284 |
int numv; |
| 285 |
|
| 286 |
RB_CheckVao(tess.vao); |
| 287 |
|
| 288 |
RB_CHECKOVERFLOW( p->numVerts, 3*(p->numVerts - 2) ); |
| 289 |
|
| 290 |
|
| 291 |
numv = tess.numVertexes; |
| 292 |
for ( i = 0; i < p->numVerts; i++ ) { |
| 293 |
VectorCopy( p->verts[i].xyz, tess.xyz[numv] ); |
| 294 |
tess.texCoords[numv][0] = p->verts[i].st[0]; |
| 295 |
tess.texCoords[numv][1] = p->verts[i].st[1]; |
| 296 |
tess.color[numv][0] = (int)p->verts[i].modulate[0] * 257; |
| 297 |
tess.color[numv][1] = (int)p->verts[i].modulate[1] * 257; |
| 298 |
tess.color[numv][2] = (int)p->verts[i].modulate[2] * 257; |
| 299 |
tess.color[numv][3] = (int)p->verts[i].modulate[3] * 257; |
| 300 |
|
| 301 |
numv++; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
for ( i = 0; i < p->numVerts-2; i++ ) { |
| 306 |
tess.indexes[tess.numIndexes + 0] = tess.numVertexes; |
| 307 |
tess.indexes[tess.numIndexes + 1] = tess.numVertexes + i + 1; |
| 308 |
tess.indexes[tess.numIndexes + 2] = tess.numVertexes + i + 2; |
| 309 |
tess.numIndexes += 3; |
| 310 |
} |
| 311 |
|
| 312 |
tess.numVertexes = numv; |
| 313 |
} |
| 314 |
|
| 315 |
static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIndexes, glIndex_t *indexes, int dlightBits, int pshadowBits) |
| 316 |
{ |
| 317 |
int i; |
| 318 |
glIndex_t *inIndex; |
| 319 |
srfVert_t *dv; |
| 320 |
float *xyz, *texCoords, *lightCoords; |
| 321 |
int16_t *lightdir; |
| 322 |
int16_t *normal; |
| 323 |
int16_t *tangent; |
| 324 |
glIndex_t *outIndex; |
| 325 |
uint16_t *color; |
| 326 |
|
| 327 |
RB_CheckVao(tess.vao); |
| 328 |
|
| 329 |
RB_CHECKOVERFLOW( numVerts, numIndexes ); |
| 330 |
|
| 331 |
inIndex = indexes; |
| 332 |
outIndex = &tess.indexes[ tess.numIndexes ]; |
| 333 |
for ( i = 0 ; i < numIndexes ; i++ ) { |
| 334 |
*outIndex++ = tess.numVertexes + *inIndex++; |
| 335 |
} |
| 336 |
tess.numIndexes += numIndexes; |
| 337 |
|
| 338 |
if ( tess.shader->vertexAttribs & ATTR_POSITION ) |
| 339 |
{ |
| 340 |
dv = verts; |
| 341 |
xyz = tess.xyz[ tess.numVertexes ]; |
| 342 |
for ( i = 0 ; i < numVerts ; i++, dv++, xyz+=4 ) |
| 343 |
VectorCopy(dv->xyz, xyz); |
| 344 |
} |
| 345 |
|
| 346 |
if ( tess.shader->vertexAttribs & ATTR_NORMAL ) |
| 347 |
{ |
| 348 |
dv = verts; |
| 349 |
normal = tess.normal[ tess.numVertexes ]; |
| 350 |
for ( i = 0 ; i < numVerts ; i++, dv++, normal+=4 ) |
| 351 |
VectorCopy4(dv->normal, normal); |
| 352 |
} |
| 353 |
|
| 354 |
if ( tess.shader->vertexAttribs & ATTR_TANGENT ) |
| 355 |
{ |
| 356 |
dv = verts; |
| 357 |
tangent = tess.tangent[ tess.numVertexes ]; |
| 358 |
for ( i = 0 ; i < numVerts ; i++, dv++, tangent+=4 ) |
| 359 |
VectorCopy4(dv->tangent, tangent); |
| 360 |
} |
| 361 |
|
| 362 |
if ( tess.shader->vertexAttribs & ATTR_TEXCOORD ) |
| 363 |
{ |
| 364 |
dv = verts; |
| 365 |
texCoords = tess.texCoords[tess.numVertexes]; |
| 366 |
for ( i = 0 ; i < numVerts ; i++, dv++, texCoords+=2 ) |
| 367 |
VectorCopy2(dv->st, texCoords); |
| 368 |
} |
| 369 |
|
| 370 |
if ( tess.shader->vertexAttribs & ATTR_LIGHTCOORD ) |
| 371 |
{ |
| 372 |
dv = verts; |
| 373 |
lightCoords = tess.lightCoords[ tess.numVertexes ]; |
| 374 |
for ( i = 0 ; i < numVerts ; i++, dv++, lightCoords+=2 ) |
| 375 |
VectorCopy2(dv->lightmap, lightCoords); |
| 376 |
} |
| 377 |
|
| 378 |
if ( tess.shader->vertexAttribs & ATTR_COLOR ) |
| 379 |
{ |
| 380 |
dv = verts; |
| 381 |
color = tess.color[ tess.numVertexes ]; |
| 382 |
for ( i = 0 ; i < numVerts ; i++, dv++, color+=4 ) |
| 383 |
VectorCopy4(dv->color, color); |
| 384 |
} |
| 385 |
|
| 386 |
if ( tess.shader->vertexAttribs & ATTR_LIGHTDIRECTION ) |
| 387 |
{ |
| 388 |
dv = verts; |
| 389 |
lightdir = tess.lightdir[ tess.numVertexes ]; |
| 390 |
for ( i = 0 ; i < numVerts ; i++, dv++, lightdir+=4 ) |
| 391 |
VectorCopy4(dv->lightdir, lightdir); |
| 392 |
} |
| 393 |
|
| 394 |
#if 0 |
| 395 |
for ( i = 0 ; i < numVerts ; i++ ) { |
| 396 |
tess.vertexDlightBits[ tess.numVertexes + i ] = dlightBits; |
| 397 |
} |
| 398 |
#endif |
| 399 |
|
| 400 |
tess.dlightBits |= dlightBits; |
| 401 |
tess.pshadowBits |= pshadowBits; |
| 402 |
|
| 403 |
tess.numVertexes += numVerts; |
| 404 |
} |
| 405 |
|
| 406 |
static qboolean RB_SurfaceVaoCached(int numVerts, srfVert_t *verts, int numIndexes, glIndex_t *indexes, int dlightBits, int pshadowBits) |
| 407 |
{ |
| 408 |
qboolean recycleVertexBuffer = qfalse; |
| 409 |
qboolean recycleIndexBuffer = qfalse; |
| 410 |
qboolean endSurface = qfalse; |
| 411 |
|
| 412 |
if (!r_vaoCache->integer) |
| 413 |
return qfalse; |
| 414 |
|
| 415 |
if (!(!ShaderRequiresCPUDeforms(tess.shader) && !tess.shader->isSky && !tess.shader->isPortal)) |
| 416 |
return qfalse; |
| 417 |
|
| 418 |
if (!numIndexes || !numVerts) |
| 419 |
return qfalse; |
| 420 |
|
| 421 |
VaoCache_BindVao(); |
| 422 |
|
| 423 |
tess.dlightBits |= dlightBits; |
| 424 |
tess.pshadowBits |= pshadowBits; |
| 425 |
|
| 426 |
VaoCache_CheckAdd(&endSurface, &recycleVertexBuffer, &recycleIndexBuffer, numVerts, numIndexes); |
| 427 |
|
| 428 |
if (endSurface) |
| 429 |
{ |
| 430 |
RB_EndSurface(); |
| 431 |
RB_BeginSurface(tess.shader, tess.fogNum, tess.cubemapIndex); |
| 432 |
} |
| 433 |
|
| 434 |
if (recycleVertexBuffer) |
| 435 |
VaoCache_RecycleVertexBuffer(); |
| 436 |
|
| 437 |
if (recycleIndexBuffer) |
| 438 |
VaoCache_RecycleIndexBuffer(); |
| 439 |
|
| 440 |
if (!tess.numVertexes) |
| 441 |
VaoCache_InitQueue(); |
| 442 |
|
| 443 |
VaoCache_AddSurface(verts, numVerts, indexes, numIndexes); |
| 444 |
|
| 445 |
tess.numIndexes += numIndexes; |
| 446 |
tess.numVertexes += numVerts; |
| 447 |
tess.useInternalVao = qfalse; |
| 448 |
tess.useCacheVao = qtrue; |
| 449 |
|
| 450 |
return qtrue; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
static void RB_SurfaceTriangles( srfBspSurface_t *srf ) { |
| 460 |
if (RB_SurfaceVaoCached(srf->numVerts, srf->verts, srf->numIndexes, |
| 461 |
srf->indexes, srf->dlightBits, srf->pshadowBits)) |
| 462 |
{ |
| 463 |
return; |
| 464 |
} |
| 465 |
|
| 466 |
RB_SurfaceVertsAndIndexes(srf->numVerts, srf->verts, srf->numIndexes, |
| 467 |
srf->indexes, srf->dlightBits, srf->pshadowBits); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
static void RB_SurfaceBeam( void ) |
| 478 |
{ |
| 479 |
#define NUM_BEAM_SEGS 6 |
| 480 |
refEntity_t *e; |
| 481 |
shaderProgram_t *sp = &tr.textureColorShader; |
| 482 |
int i; |
| 483 |
vec3_t perpvec; |
| 484 |
vec3_t direction, normalized_direction; |
| 485 |
vec3_t start_points[NUM_BEAM_SEGS], end_points[NUM_BEAM_SEGS]; |
| 486 |
vec3_t oldorigin, origin; |
| 487 |
|
| 488 |
e = &backEnd.currentEntity->e; |
| 489 |
|
| 490 |
oldorigin[0] = e->oldorigin[0]; |
| 491 |
oldorigin[1] = e->oldorigin[1]; |
| 492 |
oldorigin[2] = e->oldorigin[2]; |
| 493 |
|
| 494 |
origin[0] = e->origin[0]; |
| 495 |
origin[1] = e->origin[1]; |
| 496 |
origin[2] = e->origin[2]; |
| 497 |
|
| 498 |
normalized_direction[0] = direction[0] = oldorigin[0] - origin[0]; |
| 499 |
normalized_direction[1] = direction[1] = oldorigin[1] - origin[1]; |
| 500 |
normalized_direction[2] = direction[2] = oldorigin[2] - origin[2]; |
| 501 |
|
| 502 |
if ( VectorNormalize( normalized_direction ) == 0 ) |
| 503 |
return; |
| 504 |
|
| 505 |
PerpendicularVector( perpvec, normalized_direction ); |
| 506 |
|
| 507 |
VectorScale( perpvec, 4, perpvec ); |
| 508 |
|
| 509 |
for ( i = 0; i < NUM_BEAM_SEGS ; i++ ) |
| 510 |
{ |
| 511 |
RotatePointAroundVector( start_points[i], normalized_direction, perpvec, (360.0/NUM_BEAM_SEGS)*i ); |
| 512 |
|
| 513 |
VectorAdd( start_points[i], direction, end_points[i] ); |
| 514 |
} |
| 515 |
|
| 516 |
GL_BindToTMU( tr.whiteImage, TB_COLORMAP ); |
| 517 |
|
| 518 |
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE ); |
| 519 |
|
| 520 |
|
| 521 |
tess.numVertexes = 0; |
| 522 |
tess.numIndexes = 0; |
| 523 |
tess.firstIndex = 0; |
| 524 |
|
| 525 |
for ( i = 0; i <= NUM_BEAM_SEGS; i++ ) { |
| 526 |
VectorCopy(start_points[ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); |
| 527 |
VectorCopy(end_points [ i % NUM_BEAM_SEGS ], tess.xyz[tess.numVertexes++]); |
| 528 |
} |
| 529 |
|
| 530 |
for ( i = 0; i < NUM_BEAM_SEGS; i++ ) { |
| 531 |
tess.indexes[tess.numIndexes++] = i * 2; |
| 532 |
tess.indexes[tess.numIndexes++] = (i + 1) * 2; |
| 533 |
tess.indexes[tess.numIndexes++] = 1 + i * 2; |
| 534 |
|
| 535 |
tess.indexes[tess.numIndexes++] = 1 + i * 2; |
| 536 |
tess.indexes[tess.numIndexes++] = (i + 1) * 2; |
| 537 |
tess.indexes[tess.numIndexes++] = 1 + (i + 1) * 2; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
RB_UpdateTessVao(ATTR_POSITION); |
| 542 |
|
| 543 |
GLSL_BindProgram(sp); |
| 544 |
|
| 545 |
GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); |
| 546 |
|
| 547 |
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, colorRed); |
| 548 |
|
| 549 |
GLSL_SetUniformInt(sp, UNIFORM_ALPHATEST, 0); |
| 550 |
|
| 551 |
R_DrawElements(tess.numIndexes, tess.firstIndex); |
| 552 |
|
| 553 |
tess.numIndexes = 0; |
| 554 |
tess.numVertexes = 0; |
| 555 |
tess.firstIndex = 0; |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
static void DoRailCore( const vec3_t start, const vec3_t end, const vec3_t up, float len, float spanWidth ) |
| 561 |
{ |
| 562 |
float spanWidth2; |
| 563 |
int vbase; |
| 564 |
float t = len / 256.0f; |
| 565 |
|
| 566 |
RB_CheckVao(tess.vao); |
| 567 |
|
| 568 |
RB_CHECKOVERFLOW( 4, 6 ); |
| 569 |
|
| 570 |
vbase = tess.numVertexes; |
| 571 |
|
| 572 |
spanWidth2 = -spanWidth; |
| 573 |
|
| 574 |
|
| 575 |
VectorMA( start, spanWidth, up, tess.xyz[tess.numVertexes] ); |
| 576 |
tess.texCoords[tess.numVertexes][0] = 0; |
| 577 |
tess.texCoords[tess.numVertexes][1] = 0; |
| 578 |
tess.color[tess.numVertexes][0] = backEnd.currentEntity->e.shaderRGBA[0] * 0.25f * 257.0f; |
| 579 |
tess.color[tess.numVertexes][1] = backEnd.currentEntity->e.shaderRGBA[1] * 0.25f * 257.0f; |
| 580 |
tess.color[tess.numVertexes][2] = backEnd.currentEntity->e.shaderRGBA[2] * 0.25f * 257.0f; |
| 581 |
tess.numVertexes++; |
| 582 |
|
| 583 |
VectorMA( start, spanWidth2, up, tess.xyz[tess.numVertexes] ); |
| 584 |
tess.texCoords[tess.numVertexes][0] = 0; |
| 585 |
tess.texCoords[tess.numVertexes][1] = 1; |
| 586 |
tess.color[tess.numVertexes][0] = backEnd.currentEntity->e.shaderRGBA[0] * 257; |
| 587 |
tess.color[tess.numVertexes][1] = backEnd.currentEntity->e.shaderRGBA[1] * 257; |
| 588 |
tess.color[tess.numVertexes][2] = backEnd.currentEntity->e.shaderRGBA[2] * 257; |
| 589 |
tess.numVertexes++; |
| 590 |
|
| 591 |
VectorMA( end, spanWidth, up, tess.xyz[tess.numVertexes] ); |
| 592 |
|
| 593 |
tess.texCoords[tess.numVertexes][0] = t; |
| 594 |
tess.texCoords[tess.numVertexes][1] = 0; |
| 595 |
tess.color[tess.numVertexes][0] = backEnd.currentEntity->e.shaderRGBA[0] * 257; |
| 596 |
tess.color[tess.numVertexes][1] = backEnd.currentEntity->e.shaderRGBA[1] * 257; |
| 597 |
tess.color[tess.numVertexes][2] = backEnd.currentEntity->e.shaderRGBA[2] * 257; |
| 598 |
tess.numVertexes++; |
| 599 |
|
| 600 |
VectorMA( end, spanWidth2, up, tess.xyz[tess.numVertexes] ); |
| 601 |
tess.texCoords[tess.numVertexes][0] = t; |
| 602 |
tess.texCoords[tess.numVertexes][1] = 1; |
| 603 |
tess.color[tess.numVertexes][0] = backEnd.currentEntity->e.shaderRGBA[0] * 257; |
| 604 |
tess.color[tess.numVertexes][1] = backEnd.currentEntity->e.shaderRGBA[1] * 257; |
| 605 |
tess.color[tess.numVertexes][2] = backEnd.currentEntity->e.shaderRGBA[2] * 257; |
| 606 |
tess.numVertexes++; |
| 607 |
|
| 608 |
tess.indexes[tess.numIndexes++] = vbase; |
| 609 |
tess.indexes[tess.numIndexes++] = vbase + 1; |
| 610 |
tess.indexes[tess.numIndexes++] = vbase + 2; |
| 611 |
|
| 612 |
tess.indexes[tess.numIndexes++] = vbase + 2; |
| 613 |
tess.indexes[tess.numIndexes++] = vbase + 1; |
| 614 |
tess.indexes[tess.numIndexes++] = vbase + 3; |
| 615 |
} |
| 616 |
|
| 617 |
static void DoRailDiscs( int numSegs, const vec3_t start, const vec3_t dir, const vec3_t right, const vec3_t up ) |
| 618 |
{ |
| 619 |
int i; |
| 620 |
vec3_t pos[4]; |
| 621 |
vec3_t v; |
| 622 |
int spanWidth = r_railWidth->integer; |
| 623 |
float c, s; |
| 624 |
float scale; |
| 625 |
|
| 626 |
if ( numSegs > 1 ) |
| 627 |
numSegs--; |
| 628 |
if ( !numSegs ) |
| 629 |
return; |
| 630 |
|
| 631 |
scale = 0.25; |
| 632 |
|
| 633 |
for ( i = 0; i < 4; i++ ) |
| 634 |
{ |
| 635 |
c = cos( DEG2RAD( 45 + i * 90 ) ); |
| 636 |
s = sin( DEG2RAD( 45 + i * 90 ) ); |
| 637 |
v[0] = ( right[0] * c + up[0] * s ) * scale * spanWidth; |
| 638 |
v[1] = ( right[1] * c + up[1] * s ) * scale * spanWidth; |
| 639 |
v[2] = ( right[2] * c + up[2] * s ) * scale * spanWidth; |
| 640 |
VectorAdd( start, v, pos[i] ); |
| 641 |
|
| 642 |
if ( numSegs > 1 ) |
| 643 |
{ |
| 644 |
|
| 645 |
VectorAdd( pos[i], dir, pos[i] ); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
RB_CheckVao(tess.vao); |
| 650 |
|
| 651 |
for ( i = 0; i < numSegs; i++ ) |
| 652 |
{ |
| 653 |
int j; |
| 654 |
|
| 655 |
RB_CHECKOVERFLOW( 4, 6 ); |
| 656 |
|
| 657 |
for ( j = 0; j < 4; j++ ) |
| 658 |
{ |
| 659 |
VectorCopy( pos[j], tess.xyz[tess.numVertexes] ); |
| 660 |
tess.texCoords[tess.numVertexes][0] = (j < 2); |
| 661 |
tess.texCoords[tess.numVertexes][1] = (j && j != 3); |
| 662 |
tess.color[tess.numVertexes][0] = backEnd.currentEntity->e.shaderRGBA[0] * 257; |
| 663 |
tess.color[tess.numVertexes][1] = backEnd.currentEntity->e.shaderRGBA[1] * 257; |
| 664 |
tess.color[tess.numVertexes][2] = backEnd.currentEntity->e.shaderRGBA[2] * 257; |
| 665 |
tess.numVertexes++; |
| 666 |
|
| 667 |
VectorAdd( pos[j], dir, pos[j] ); |
| 668 |
} |
| 669 |
|
| 670 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 0; |
| 671 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 1; |
| 672 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 3; |
| 673 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 3; |
| 674 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 1; |
| 675 |
tess.indexes[tess.numIndexes++] = tess.numVertexes - 4 + 2; |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
static void RB_SurfaceRailRings( void ) { |
| 683 |
refEntity_t *e; |
| 684 |
int numSegs; |
| 685 |
int len; |
| 686 |
vec3_t vec; |
| 687 |
vec3_t right, up; |
| 688 |
vec3_t start, end; |
| 689 |
|
| 690 |
e = &backEnd.currentEntity->e; |
| 691 |
|
| 692 |
VectorCopy( e->oldorigin, start ); |
| 693 |
VectorCopy( e->origin, end ); |
| 694 |
|
| 695 |
|
| 696 |
VectorSubtract( end, start, vec ); |
| 697 |
len = VectorNormalize( vec ); |
| 698 |
MakeNormalVectors( vec, right, up ); |
| 699 |
numSegs = ( len ) / r_railSegmentLength->value; |
| 700 |
if ( numSegs <= 0 ) { |
| 701 |
numSegs = 1; |
| 702 |
} |
| 703 |
|
| 704 |
VectorScale( vec, r_railSegmentLength->value, vec ); |
| 705 |
|
| 706 |
DoRailDiscs( numSegs, start, vec, right, up ); |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
static void RB_SurfaceRailCore( void ) { |
| 713 |
refEntity_t *e; |
| 714 |
int len; |
| 715 |
vec3_t right; |
| 716 |
vec3_t vec; |
| 717 |
vec3_t start, end; |
| 718 |
vec3_t v1, v2; |
| 719 |
|
| 720 |
e = &backEnd.currentEntity->e; |
| 721 |
|
| 722 |
VectorCopy( e->oldorigin, start ); |
| 723 |
VectorCopy( e->origin, end ); |
| 724 |
|
| 725 |
VectorSubtract( end, start, vec ); |
| 726 |
len = VectorNormalize( vec ); |
| 727 |
|
| 728 |
|
| 729 |
VectorSubtract( start, backEnd.viewParms.or.origin, v1 ); |
| 730 |
VectorNormalize( v1 ); |
| 731 |
VectorSubtract( end, backEnd.viewParms.or.origin, v2 ); |
| 732 |
VectorNormalize( v2 ); |
| 733 |
CrossProduct( v1, v2, right ); |
| 734 |
VectorNormalize( right ); |
| 735 |
|
| 736 |
DoRailCore( start, end, right, len, r_railCoreWidth->integer ); |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
static void RB_SurfaceLightningBolt( void ) { |
| 743 |
refEntity_t *e; |
| 744 |
int len; |
| 745 |
vec3_t right; |
| 746 |
vec3_t vec; |
| 747 |
vec3_t start, end; |
| 748 |
vec3_t v1, v2; |
| 749 |
int i; |
| 750 |
|
| 751 |
e = &backEnd.currentEntity->e; |
| 752 |
|
| 753 |
VectorCopy( e->oldorigin, end ); |
| 754 |
VectorCopy( e->origin, start ); |
| 755 |
|
| 756 |
|
| 757 |
VectorSubtract( end, start, vec ); |
| 758 |
len = VectorNormalize( vec ); |
| 759 |
|
| 760 |
|
| 761 |
VectorSubtract( start, backEnd.viewParms.or.origin, v1 ); |
| 762 |
VectorNormalize( v1 ); |
| 763 |
VectorSubtract( end, backEnd.viewParms.or.origin, v2 ); |
| 764 |
VectorNormalize( v2 ); |
| 765 |
CrossProduct( v1, v2, right ); |
| 766 |
VectorNormalize( right ); |
| 767 |
|
| 768 |
for ( i = 0 ; i < 4 ; i++ ) { |
| 769 |
vec3_t temp; |
| 770 |
|
| 771 |
DoRailCore( start, end, right, len, 8 ); |
| 772 |
RotatePointAroundVector( temp, vec, right, 45 ); |
| 773 |
VectorCopy( temp, right ); |
| 774 |
} |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
static void LerpMeshVertexes(mdvSurface_t *surf, float backlerp) |
| 779 |
{ |
| 780 |
float *outXyz; |
| 781 |
int16_t *outNormal, *outTangent; |
| 782 |
mdvVertex_t *newVerts; |
| 783 |
int vertNum; |
| 784 |
|
| 785 |
newVerts = surf->verts + backEnd.currentEntity->e.frame * surf->numVerts; |
| 786 |
|
| 787 |
outXyz = tess.xyz[tess.numVertexes]; |
| 788 |
outNormal = tess.normal[tess.numVertexes]; |
| 789 |
outTangent = tess.tangent[tess.numVertexes]; |
| 790 |
|
| 791 |
if (backlerp == 0) |
| 792 |
{ |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
for (vertNum=0 ; vertNum < surf->numVerts ; vertNum++) |
| 798 |
{ |
| 799 |
VectorCopy(newVerts->xyz, outXyz); |
| 800 |
VectorCopy4(newVerts->normal, outNormal); |
| 801 |
VectorCopy4(newVerts->tangent, outTangent); |
| 802 |
|
| 803 |
newVerts++; |
| 804 |
outXyz += 4; |
| 805 |
outNormal += 4; |
| 806 |
outTangent += 4; |
| 807 |
} |
| 808 |
} |
| 809 |
else |
| 810 |
{ |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
mdvVertex_t *oldVerts; |
| 816 |
|
| 817 |
oldVerts = surf->verts + backEnd.currentEntity->e.oldframe * surf->numVerts; |
| 818 |
|
| 819 |
for (vertNum=0 ; vertNum < surf->numVerts ; vertNum++) |
| 820 |
{ |
| 821 |
VectorLerp(newVerts->xyz, oldVerts->xyz, backlerp, outXyz); |
| 822 |
|
| 823 |
outNormal[0] = (int16_t)(newVerts->normal[0] * (1.0f - backlerp) + oldVerts->normal[0] * backlerp); |
| 824 |
outNormal[1] = (int16_t)(newVerts->normal[1] * (1.0f - backlerp) + oldVerts->normal[1] * backlerp); |
| 825 |
outNormal[2] = (int16_t)(newVerts->normal[2] * (1.0f - backlerp) + oldVerts->normal[2] * backlerp); |
| 826 |
outNormal[3] = 0; |
| 827 |
|
| 828 |
outTangent[0] = (int16_t)(newVerts->tangent[0] * (1.0f - backlerp) + oldVerts->tangent[0] * backlerp); |
| 829 |
outTangent[1] = (int16_t)(newVerts->tangent[1] * (1.0f - backlerp) + oldVerts->tangent[1] * backlerp); |
| 830 |
outTangent[2] = (int16_t)(newVerts->tangent[2] * (1.0f - backlerp) + oldVerts->tangent[2] * backlerp); |
| 831 |
outTangent[3] = newVerts->tangent[3]; |
| 832 |
|
| 833 |
newVerts++; |
| 834 |
oldVerts++; |
| 835 |
outXyz += 4; |
| 836 |
outNormal += 4; |
| 837 |
outTangent += 4; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
static void RB_SurfaceMesh(mdvSurface_t *surface) { |
| 850 |
int j; |
| 851 |
float backlerp; |
| 852 |
mdvSt_t *texCoords; |
| 853 |
int Bob, Doug; |
| 854 |
int numVerts; |
| 855 |
|
| 856 |
if ( backEnd.currentEntity->e.oldframe == backEnd.currentEntity->e.frame ) { |
| 857 |
backlerp = 0; |
| 858 |
} else { |
| 859 |
backlerp = backEnd.currentEntity->e.backlerp; |
| 860 |
} |
| 861 |
|
| 862 |
RB_CheckVao(tess.vao); |
| 863 |
|
| 864 |
RB_CHECKOVERFLOW( surface->numVerts, surface->numIndexes ); |
| 865 |
|
| 866 |
LerpMeshVertexes (surface, backlerp); |
| 867 |
|
| 868 |
Bob = tess.numIndexes; |
| 869 |
Doug = tess.numVertexes; |
| 870 |
for (j = 0 ; j < surface->numIndexes ; j++) { |
| 871 |
tess.indexes[Bob + j] = Doug + surface->indexes[j]; |
| 872 |
} |
| 873 |
tess.numIndexes += surface->numIndexes; |
| 874 |
|
| 875 |
texCoords = surface->st; |
| 876 |
|
| 877 |
numVerts = surface->numVerts; |
| 878 |
for ( j = 0; j < numVerts; j++ ) { |
| 879 |
tess.texCoords[Doug + j][0] = texCoords[j].st[0]; |
| 880 |
tess.texCoords[Doug + j][1] = texCoords[j].st[1]; |
| 881 |
|
| 882 |
} |
| 883 |
|
| 884 |
tess.numVertexes += surface->numVerts; |
| 885 |
|
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
static void RB_SurfaceFace( srfBspSurface_t *srf ) { |
| 895 |
if (RB_SurfaceVaoCached(srf->numVerts, srf->verts, srf->numIndexes, |
| 896 |
srf->indexes, srf->dlightBits, srf->pshadowBits)) |
| 897 |
{ |
| 898 |
return; |
| 899 |
} |
| 900 |
|
| 901 |
RB_SurfaceVertsAndIndexes(srf->numVerts, srf->verts, srf->numIndexes, |
| 902 |
srf->indexes, srf->dlightBits, srf->pshadowBits); |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
static float LodErrorForVolume( vec3_t local, float radius ) { |
| 907 |
vec3_t world; |
| 908 |
float d; |
| 909 |
|
| 910 |
|
| 911 |
if ( r_lodCurveError->value < 0 ) { |
| 912 |
return 0; |
| 913 |
} |
| 914 |
|
| 915 |
world[0] = local[0] * backEnd.or.axis[0][0] + local[1] * backEnd.or.axis[1][0] + |
| 916 |
local[2] * backEnd.or.axis[2][0] + backEnd.or.origin[0]; |
| 917 |
world[1] = local[0] * backEnd.or.axis[0][1] + local[1] * backEnd.or.axis[1][1] + |
| 918 |
local[2] * backEnd.or.axis[2][1] + backEnd.or.origin[1]; |
| 919 |
world[2] = local[0] * backEnd.or.axis[0][2] + local[1] * backEnd.or.axis[1][2] + |
| 920 |
local[2] * backEnd.or.axis[2][2] + backEnd.or.origin[2]; |
| 921 |
|
| 922 |
VectorSubtract( world, backEnd.viewParms.or.origin, world ); |
| 923 |
d = DotProduct( world, backEnd.viewParms.or.axis[0] ); |
| 924 |
|
| 925 |
if ( d < 0 ) { |
| 926 |
d = -d; |
| 927 |
} |
| 928 |
d -= radius; |
| 929 |
if ( d < 1 ) { |
| 930 |
d = 1; |
| 931 |
} |
| 932 |
|
| 933 |
return r_lodCurveError->value / d; |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
static void RB_SurfaceGrid( srfBspSurface_t *srf ) { |
| 944 |
int i, j; |
| 945 |
float *xyz; |
| 946 |
float *texCoords, *lightCoords; |
| 947 |
int16_t *normal; |
| 948 |
int16_t *tangent; |
| 949 |
uint16_t *color; |
| 950 |
int16_t *lightdir; |
| 951 |
srfVert_t *dv; |
| 952 |
int rows, irows, vrows; |
| 953 |
int used; |
| 954 |
int widthTable[MAX_GRID_SIZE]; |
| 955 |
int heightTable[MAX_GRID_SIZE]; |
| 956 |
float lodError; |
| 957 |
int lodWidth, lodHeight; |
| 958 |
int numVertexes; |
| 959 |
int dlightBits; |
| 960 |
int pshadowBits; |
| 961 |
|
| 962 |
|
| 963 |
if (RB_SurfaceVaoCached(srf->numVerts, srf->verts, srf->numIndexes, |
| 964 |
srf->indexes, srf->dlightBits, srf->pshadowBits)) |
| 965 |
{ |
| 966 |
return; |
| 967 |
} |
| 968 |
|
| 969 |
RB_CheckVao(tess.vao); |
| 970 |
|
| 971 |
dlightBits = srf->dlightBits; |
| 972 |
tess.dlightBits |= dlightBits; |
| 973 |
|
| 974 |
pshadowBits = srf->pshadowBits; |
| 975 |
tess.pshadowBits |= pshadowBits; |
| 976 |
|
| 977 |
|
| 978 |
lodError = LodErrorForVolume( srf->lodOrigin, srf->lodRadius ); |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
widthTable[0] = 0; |
| 983 |
lodWidth = 1; |
| 984 |
for ( i = 1 ; i < srf->width-1 ; i++ ) { |
| 985 |
if ( srf->widthLodError[i] <= lodError ) { |
| 986 |
widthTable[lodWidth] = i; |
| 987 |
lodWidth++; |
| 988 |
} |
| 989 |
} |
| 990 |
widthTable[lodWidth] = srf->width-1; |
| 991 |
lodWidth++; |
| 992 |
|
| 993 |
heightTable[0] = 0; |
| 994 |
lodHeight = 1; |
| 995 |
for ( i = 1 ; i < srf->height-1 ; i++ ) { |
| 996 |
if ( srf->heightLodError[i] <= lodError ) { |
| 997 |
heightTable[lodHeight] = i; |
| 998 |
lodHeight++; |
| 999 |
} |
| 1000 |
} |
| 1001 |
heightTable[lodHeight] = srf->height-1; |
| 1002 |
lodHeight++; |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
used = 0; |
| 1009 |
while ( used < lodHeight - 1 ) { |
| 1010 |
|
| 1011 |
do { |
| 1012 |
vrows = ( SHADER_MAX_VERTEXES - tess.numVertexes ) / lodWidth; |
| 1013 |
irows = ( SHADER_MAX_INDEXES - tess.numIndexes ) / ( lodWidth * 6 ); |
| 1014 |
|
| 1015 |
|
| 1016 |
if ( vrows < 2 || irows < 1 ) { |
| 1017 |
RB_EndSurface(); |
| 1018 |
RB_BeginSurface(tess.shader, tess.fogNum, tess.cubemapIndex ); |
| 1019 |
} else { |
| 1020 |
break; |
| 1021 |
} |
| 1022 |
} while ( 1 ); |
| 1023 |
|
| 1024 |
rows = irows; |
| 1025 |
if ( vrows < irows + 1 ) { |
| 1026 |
rows = vrows - 1; |
| 1027 |
} |
| 1028 |
if ( used + rows > lodHeight ) { |
| 1029 |
rows = lodHeight - used; |
| 1030 |
} |
| 1031 |
|
| 1032 |
numVertexes = tess.numVertexes; |
| 1033 |
|
| 1034 |
xyz = tess.xyz[numVertexes]; |
| 1035 |
normal = tess.normal[numVertexes]; |
| 1036 |
tangent = tess.tangent[numVertexes]; |
| 1037 |
texCoords = tess.texCoords[numVertexes]; |
| 1038 |
lightCoords = tess.lightCoords[numVertexes]; |
| 1039 |
color = tess.color[numVertexes]; |
| 1040 |
lightdir = tess.lightdir[numVertexes]; |
| 1041 |
|
| 1042 |
|
| 1043 |
for ( i = 0 ; i < rows ; i++ ) { |
| 1044 |
for ( j = 0 ; j < lodWidth ; j++ ) { |
| 1045 |
dv = srf->verts + heightTable[ used + i ] * srf->width |
| 1046 |
+ widthTable[ j ]; |
| 1047 |
|
| 1048 |
if ( tess.shader->vertexAttribs & ATTR_POSITION ) |
| 1049 |
{ |
| 1050 |
VectorCopy(dv->xyz, xyz); |
| 1051 |
xyz += 4; |
| 1052 |
} |
| 1053 |
|
| 1054 |
if ( tess.shader->vertexAttribs & ATTR_NORMAL ) |
| 1055 |
{ |
| 1056 |
VectorCopy4(dv->normal, normal); |
| 1057 |
normal += 4; |
| 1058 |
} |
| 1059 |
|
| 1060 |
if ( tess.shader->vertexAttribs & ATTR_TANGENT ) |
| 1061 |
{ |
| 1062 |
VectorCopy4(dv->tangent, tangent); |
| 1063 |
tangent += 4; |
| 1064 |
} |
| 1065 |
|
| 1066 |
if ( tess.shader->vertexAttribs & ATTR_TEXCOORD ) |
| 1067 |
{ |
| 1068 |
VectorCopy2(dv->st, texCoords); |
| 1069 |
texCoords += 2; |
| 1070 |
} |
| 1071 |
|
| 1072 |
if ( tess.shader->vertexAttribs & ATTR_LIGHTCOORD ) |
| 1073 |
{ |
| 1074 |
VectorCopy2(dv->lightmap, lightCoords); |
| 1075 |
lightCoords += 2; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if ( tess.shader->vertexAttribs & ATTR_COLOR ) |
| 1079 |
{ |
| 1080 |
VectorCopy4(dv->color, color); |
| 1081 |
color += 4; |
| 1082 |
} |
| 1083 |
|
| 1084 |
if ( tess.shader->vertexAttribs & ATTR_LIGHTDIRECTION ) |
| 1085 |
{ |
| 1086 |
VectorCopy4(dv->lightdir, lightdir); |
| 1087 |
lightdir += 4; |
| 1088 |
} |
| 1089 |
|
| 1090 |
|
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
{ |
| 1097 |
int numIndexes; |
| 1098 |
int w, h; |
| 1099 |
|
| 1100 |
h = rows - 1; |
| 1101 |
w = lodWidth - 1; |
| 1102 |
numIndexes = tess.numIndexes; |
| 1103 |
for (i = 0 ; i < h ; i++) { |
| 1104 |
for (j = 0 ; j < w ; j++) { |
| 1105 |
int v1, v2, v3, v4; |
| 1106 |
|
| 1107 |
|
| 1108 |
v1 = numVertexes + i*lodWidth + j + 1; |
| 1109 |
v2 = v1 - 1; |
| 1110 |
v3 = v2 + lodWidth; |
| 1111 |
v4 = v3 + 1; |
| 1112 |
|
| 1113 |
tess.indexes[numIndexes] = v2; |
| 1114 |
tess.indexes[numIndexes+1] = v3; |
| 1115 |
tess.indexes[numIndexes+2] = v1; |
| 1116 |
|
| 1117 |
tess.indexes[numIndexes+3] = v1; |
| 1118 |
tess.indexes[numIndexes+4] = v3; |
| 1119 |
tess.indexes[numIndexes+5] = v4; |
| 1120 |
numIndexes += 6; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
tess.numIndexes = numIndexes; |
| 1125 |
} |
| 1126 |
|
| 1127 |
tess.numVertexes += rows * lodWidth; |
| 1128 |
|
| 1129 |
used += rows - 1; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
static void RB_SurfaceAxis( void ) { |
| 1150 |
|
| 1151 |
#if 0 |
| 1152 |
GL_BindToTMU( tr.whiteImage, TB_COLORMAP ); |
| 1153 |
GL_State( GLS_DEFAULT ); |
| 1154 |
qglLineWidth( 3 ); |
| 1155 |
qglBegin( GL_LINES ); |
| 1156 |
qglColor3f( 1,0,0 ); |
| 1157 |
qglVertex3f( 0,0,0 ); |
| 1158 |
qglVertex3f( 16,0,0 ); |
| 1159 |
qglColor3f( 0,1,0 ); |
| 1160 |
qglVertex3f( 0,0,0 ); |
| 1161 |
qglVertex3f( 0,16,0 ); |
| 1162 |
qglColor3f( 0,0,1 ); |
| 1163 |
qglVertex3f( 0,0,0 ); |
| 1164 |
qglVertex3f( 0,0,16 ); |
| 1165 |
qglEnd(); |
| 1166 |
qglLineWidth( 1 ); |
| 1167 |
#endif |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
static void RB_SurfaceEntity( surfaceType_t *surfType ) { |
| 1180 |
switch( backEnd.currentEntity->e.reType ) { |
| 1181 |
case RT_SPRITE: |
| 1182 |
RB_SurfaceSprite(); |
| 1183 |
break; |
| 1184 |
case RT_BEAM: |
| 1185 |
RB_SurfaceBeam(); |
| 1186 |
break; |
| 1187 |
case RT_RAIL_CORE: |
| 1188 |
RB_SurfaceRailCore(); |
| 1189 |
break; |
| 1190 |
case RT_RAIL_RINGS: |
| 1191 |
RB_SurfaceRailRings(); |
| 1192 |
break; |
| 1193 |
case RT_LIGHTNING: |
| 1194 |
RB_SurfaceLightningBolt(); |
| 1195 |
break; |
| 1196 |
default: |
| 1197 |
RB_SurfaceAxis(); |
| 1198 |
break; |
| 1199 |
} |
| 1200 |
} |
| 1201 |
|
| 1202 |
static void RB_SurfaceBad( surfaceType_t *surfType ) { |
| 1203 |
ri.Printf( PRINT_ALL, "Bad surface tesselated.\n" ); |
| 1204 |
} |
| 1205 |
|
| 1206 |
static void RB_SurfaceFlare(srfFlare_t *surf) |
| 1207 |
{ |
| 1208 |
if (r_flares->integer) |
| 1209 |
RB_AddFlare(surf, tess.fogNum, surf->origin, surf->color, surf->normal); |
| 1210 |
} |
| 1211 |
|
| 1212 |
void RB_SurfaceVaoMdvMesh(srfVaoMdvMesh_t * surface) |
| 1213 |
{ |
| 1214 |
|
| 1215 |
|
| 1216 |
refEntity_t *refEnt; |
| 1217 |
|
| 1218 |
GLimp_LogComment("--- RB_SurfaceVaoMdvMesh ---\n"); |
| 1219 |
|
| 1220 |
if (ShaderRequiresCPUDeforms(tess.shader)) |
| 1221 |
{ |
| 1222 |
RB_SurfaceMesh(surface->mdvSurface); |
| 1223 |
return; |
| 1224 |
} |
| 1225 |
|
| 1226 |
if(!surface->vao) |
| 1227 |
return; |
| 1228 |
|
| 1229 |
|
| 1230 |
RB_EndSurface(); |
| 1231 |
RB_BeginSurface(tess.shader, tess.fogNum, tess.cubemapIndex); |
| 1232 |
|
| 1233 |
R_BindVao(surface->vao); |
| 1234 |
|
| 1235 |
tess.useInternalVao = qfalse; |
| 1236 |
|
| 1237 |
tess.numIndexes = surface->numIndexes; |
| 1238 |
tess.numVertexes = surface->numVerts; |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
refEnt = &backEnd.currentEntity->e; |
| 1244 |
|
| 1245 |
glState.vertexAttribsInterpolation = (refEnt->oldframe == refEnt->frame) ? 0.0f : refEnt->backlerp; |
| 1246 |
|
| 1247 |
if (surface->mdvModel->numFrames > 1) |
| 1248 |
{ |
| 1249 |
int frameOffset, attribIndex; |
| 1250 |
vaoAttrib_t *vAtb; |
| 1251 |
|
| 1252 |
glState.vertexAnimation = qtrue; |
| 1253 |
|
| 1254 |
if (glRefConfig.vertexArrayObject) |
| 1255 |
{ |
| 1256 |
qglBindBuffer(GL_ARRAY_BUFFER, surface->vao->vertexesVBO); |
| 1257 |
} |
| 1258 |
|
| 1259 |
frameOffset = refEnt->frame * surface->vao->frameSize; |
| 1260 |
|
| 1261 |
attribIndex = ATTR_INDEX_POSITION; |
| 1262 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1263 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1264 |
|
| 1265 |
attribIndex = ATTR_INDEX_NORMAL; |
| 1266 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1267 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1268 |
|
| 1269 |
attribIndex = ATTR_INDEX_TANGENT; |
| 1270 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1271 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1272 |
|
| 1273 |
frameOffset = refEnt->oldframe * surface->vao->frameSize; |
| 1274 |
|
| 1275 |
attribIndex = ATTR_INDEX_POSITION2; |
| 1276 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1277 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1278 |
|
| 1279 |
attribIndex = ATTR_INDEX_NORMAL2; |
| 1280 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1281 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1282 |
|
| 1283 |
attribIndex = ATTR_INDEX_TANGENT2; |
| 1284 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1285 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset + frameOffset)); |
| 1286 |
|
| 1287 |
|
| 1288 |
if (!glRefConfig.vertexArrayObject) |
| 1289 |
{ |
| 1290 |
attribIndex = ATTR_INDEX_TEXCOORD; |
| 1291 |
vAtb = &surface->vao->attribs[attribIndex]; |
| 1292 |
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset)); |
| 1293 |
} |
| 1294 |
} |
| 1295 |
|
| 1296 |
RB_EndSurface(); |
| 1297 |
|
| 1298 |
|
| 1299 |
glState.vertexAnimation = qfalse; |
| 1300 |
} |
| 1301 |
|
| 1302 |
static void RB_SurfaceSkip( void *surf ) { |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])( void *) = { |
| 1307 |
(void(*)(void*))RB_SurfaceBad, |
| 1308 |
(void(*)(void*))RB_SurfaceSkip, |
| 1309 |
(void(*)(void*))RB_SurfaceFace, |
| 1310 |
(void(*)(void*))RB_SurfaceGrid, |
| 1311 |
(void(*)(void*))RB_SurfaceTriangles, |
| 1312 |
(void(*)(void*))RB_SurfacePolychain, |
| 1313 |
(void(*)(void*))RB_SurfaceMesh, |
| 1314 |
(void(*)(void*))RB_MDRSurfaceAnim, |
| 1315 |
(void(*)(void*))RB_IQMSurfaceAnim, |
| 1316 |
(void(*)(void*))RB_SurfaceFlare, |
| 1317 |
(void(*)(void*))RB_SurfaceEntity, |
| 1318 |
(void(*)(void*))RB_SurfaceVaoMdvMesh, |
| 1319 |
(void(*)(void*))RB_IQMSurfaceAnimVao, |
| 1320 |
}; |