#include <rendcontext.h>
Inheritance diagram for GLSL_RenderContext:


Public Member Functions | |
| GLSL_RenderContext (const LightingState &ls, const Mesh::Material *) | |
| GLSL_RenderContext (const LightingState &ls) | |
| virtual void | makeCurrent (const Mesh::Material &) |
| virtual void | setVertexArrays (const Mesh::VertexDescription &desc, void *vertexData) |
Private Attributes | |
| const LightingState & | lightingState |
|
|
Definition at line 356 of file rendcontext.cpp. 00356 : 00357 lightingState(ls) 00358 { 00359 }
|
|
||||||||||||
|
Definition at line 362 of file rendcontext.cpp. 00363 : 00364 lightingState(ls) 00365 { 00366 }
|
|
|
Implements RenderContext. Definition at line 371 of file rendcontext.cpp. References CelestiaGLProgram::ambientColor, Texture::bind(), ResourceManager< T >::find(), ShaderManager::getShader(), GetShaderManager(), GetTextureManager(), glColor(), glx::glUseProgramObjectARB, Texture::hasAlpha(), InvalidResource, ShaderProperties::lightModel, min, ShaderProperties::nLights, CelestiaGLProgram::ringRadius, CelestiaGLProgram::ringWidth, setEclipseShadowShaderConstants(), setLightParameters_GLSL(), ShaderProperties::setShadowCountForLight(), ShaderProperties::shadowCounts, CelestiaGLProgram::shininess, ShaderProperties::texUsage, and CelestiaGLProgram::use(). 00372 {
00373 #if 0
00374 ShaderProperties shadprop;
00375
00376 Texture* textures[4] = { NULL, NULL, NULL, NULL };
00377 unsigned int nTextures = 0;
00378
00379 shadprop.nLights = min(ls.nLights, MaxShaderLights);
00380
00381 // Set up the textures used by this object
00382 Texture* baseTex = NULL;
00383 Texture* bumpTex = NULL;
00384 Texture* specTex = NULL;
00385 Texture* emissiveTex = NULL;
00386
00387 if (m.maps[Mesh::DiffuseMap] != InvalidResource)
00388 {
00389 baseTex = GetTextureManager()->find(m.maps[Mesh::DiffuseMap]);
00390 if (baseTex != NULL)
00391 {
00392 shadprop.texUsage = ShaderProperties::DiffuseTexture;
00393 textures[nTextures++] = baseTex;
00394 }
00395 }
00396
00397 if (m.maps[Mesh::NormalMap] != InvalidResource)
00398 {
00399 bumpTex = GetTextureManger()->find(m.maps[Mesh::NormalMap]);
00400 if (bumpTex != NULL)
00401 {
00402 shadprop.texUsage |= ShaderProperties::NormalTexture;
00403 textures[nTextures++] = bumpTex;
00404 }
00405 }
00406
00407 if (m.specular != Color::Black)
00408 {
00409 shadprop.lightModel = ShaderProperties::SpecularModel;
00410 specTex = GetTextureManager()->find(m.maps[Mesh::SpecularMap]);
00411 if (specTex == NULL)
00412 {
00413 shadprop.texUsage |= ShaderProperties::SpecularInDiffuseAlpha;
00414 }
00415 else
00416 {
00417 shadprop.texUsage |= ShaderProperties::SpecularTexture;
00418 textures[nTextures++] = specTex;
00419 }
00420 }
00421
00422 if (m.maps[Mesh::EmissiveMap] != InvalidResource)
00423 {
00424 emissiveTex = GetTextureManager()->find(m.maps[Mesh::EmissiveMap]);
00425 if (emissiveTex != NULL)
00426 {
00427 shadprop.texUsage |= ShaderProperties::NightTexture;
00428 textures[nTextures++] = emissiveTex;
00429 }
00430 }
00431
00432 #if 0
00433 // Set the shadow information.
00434 // Track the total number of shadows; if there are too many, we'll have
00435 // to fall back to multipass.
00436 unsigned int totalShadows = 0;
00437 for (unsigned int li = 0; li < ls.nLights; li++)
00438 {
00439 if (ls.shadows[li] && !ls.shadows[li]->empty())
00440 {
00441 unsigned int nShadows = (unsigned int) min((size_t) MaxShaderShadows, ls.shadows[li]->size());
00442 shadprop.setShadowCountForLight(li, nShadows);
00443 totalShadows += nShadows;
00444 }
00445 }
00446 #endif
00447
00448 // Get a shader for the current rendering configuration
00449 CelestiaGLProgram* prog = GetShaderManager().getShader(shadprop);
00450 if (prog == NULL)
00451 return;
00452
00453 prog->use();
00454
00455 setLightParameters_GLSL(*prog, shadprop, ls,
00456 ri.color, ri.specularColor);
00457
00458 prog->shininess = m.specularPower;
00459 prog->ambientColor = Vec3f(ri.ambientColor.red(), ri.ambientColor.green(),
00460 ri.ambientColor.blue());
00461
00462 if (shadprop.texUsage & ShaderProperties::RingShadowTexture)
00463 {
00464 float ringWidth = rings->outerRadius - rings->innerRadius;
00465 prog->ringRadius = rings->innerRadius / radius;
00466 prog->ringWidth = 1.0f / (ringWidth / radius);
00467 }
00468
00469 if (shadprop.shadowCounts != 0)
00470 setEclipseShadowShaderConstants(ls, radius, planetMat, *prog);
00471
00472 glColor(ri.color);
00473
00474 unsigned int attributes = LODSphereMesh::Normals;
00475 if (ri.bumpTex != NULL)
00476 attributes |= LODSphereMesh::Tangents;
00477 lodSphere->render(context,
00478 attributes,
00479 frustum, ri.pixWidth,
00480 textures[0], textures[1], textures[2], textures[3]);
00481
00482 glx::glUseProgramObjectARB(0);
00483
00484 #if 0
00485 Texture* t = NULL;
00486 if (m.maps[Mesh::DiffuseMap] != InvalidResource)
00487 t = GetTextureManager()->find(m.maps[Mesh::DiffuseMap]);
00488
00489 if (t == NULL)
00490 {
00491 glDisable(GL_TEXTURE_2D);
00492 }
00493 else
00494 {
00495 glEnable(GL_TEXTURE_2D);
00496 t->bind();
00497 }
00498
00499 glColor4f(m.diffuse.red(),
00500 m.diffuse.green(),
00501 m.diffuse.blue(),
00502 m.opacity);
00503
00504 bool blendOnNow = false;
00505 if (m.opacity != 1.0f || (t != NULL && t->hasAlpha()))
00506 blendOnNow = true;
00507
00508 if (blendOnNow != blendOn)
00509 {
00510 blendOn = blendOnNow;
00511 if (blendOn)
00512 {
00513 glEnable(GL_BLEND);
00514 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00515 glDepthMask(GL_FALSE);
00516 }
00517 else
00518 {
00519 glDisable(GL_BLEND);
00520 glDepthMask(GL_TRUE);
00521 }
00522 }
00523
00524 if (m.specular == Color::Black)
00525 {
00526 float matSpecular[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
00527 float zero = 0.0f;
00528 glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
00529 glMaterialfv(GL_FRONT, GL_SHININESS, &zero);
00530 specularOn = false;
00531 }
00532 else
00533 {
00534 float matSpecular[4] = { m.specular.red(),
00535 m.specular.green(),
00536 m.specular.blue(),
00537 0.0f };
00538 glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
00539 glMaterialfv(GL_FRONT, GL_SHININESS, &m.specularPower);
00540 specularOn = true;
00541 }
00542
00543 {
00544 float matEmissive[4] = { m.emissive.red(),
00545 m.emissive.green(),
00546 m.emissive.blue(),
00547 0.0f };
00548 glMaterialfv(GL_FRONT, GL_EMISSION, matEmissive);
00549 }
00550 #endif
00551 #endif
00552 }
|
|
||||||||||||
|
Implements RenderContext. Definition at line 556 of file rendcontext.cpp. 00558 {
00559 }
|
|
|
Definition at line 139 of file rendcontext.h. |
1.4.1