void SMFRenderStateGLSL::Enable(const CSMFGroundDrawer* smfGroundDrawer, const DrawPass::e&) { if (useLuaShaders) { // use raw, GLSLProgramObject::Enable also calls RecompileIfNeeded glUseProgram(glslShaders[GLSL_SHADER_CURRENT]->GetObjID()); // diffuse textures are always bound (SMFGroundDrawer::SetupBigSquare) glActiveTexture(GL_TEXTURE0); return; } const CSMFReadMap* smfMap = smfGroundDrawer->GetReadMap(); const GL::LightHandler* cLightHandler = smfGroundDrawer->GetLightHandler(); GL::LightHandler* mLightHandler = const_cast<GL::LightHandler*>(cLightHandler); // XXX glslShaders[GLSL_SHADER_CURRENT]->SetFlag("HAVE_SHADOWS", shadowHandler->ShadowsLoaded()); glslShaders[GLSL_SHADER_CURRENT]->SetFlag("HAVE_INFOTEX", infoTextureHandler->IsEnabled()); glslShaders[GLSL_SHADER_CURRENT]->Enable(); glslShaders[GLSL_SHADER_CURRENT]->SetUniform("mapHeights", readMap->GetCurrMinHeight(), readMap->GetCurrMaxHeight()); glslShaders[GLSL_SHADER_CURRENT]->SetUniform3v("cameraPos", &camera->GetPos()[0]); glslShaders[GLSL_SHADER_CURRENT]->SetUniformMatrix4x4("shadowMat", false, shadowHandler->GetShadowMatrixRaw()); glslShaders[GLSL_SHADER_CURRENT]->SetUniform4v("shadowParams", &(shadowHandler->GetShadowParams().x)); glslShaders[GLSL_SHADER_CURRENT]->SetUniform("infoTexIntensityMul", float(infoTextureHandler->GetMode() == "metal") + 1.0f); // already on the MV stack at this point glLoadIdentity(); mLightHandler->Update(glslShaders[GLSL_SHADER_CURRENT]); glMultMatrixf(camera->GetViewMatrix()); if (shadowHandler->ShadowsLoaded()) shadowHandler->SetupShadowTexSampler(GL_TEXTURE4); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, smfMap->GetDetailTexture()); glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, smfMap->GetNormalsTexture()); glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, smfMap->GetSpecularTexture()); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatDetailTexture()); glActiveTexture(GL_TEXTURE8); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatDistrTexture()); glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapHandler->GetSkyReflectionTextureID()); glActiveTexture(GL_TEXTURE10); glBindTexture(GL_TEXTURE_2D, smfMap->GetSkyReflectModTexture()); glActiveTexture(GL_TEXTURE11); glBindTexture(GL_TEXTURE_2D, smfMap->GetBlendNormalsTexture()); glActiveTexture(GL_TEXTURE12); glBindTexture(GL_TEXTURE_2D, smfMap->GetLightEmissionTexture()); glActiveTexture(GL_TEXTURE13); glBindTexture(GL_TEXTURE_2D, smfMap->GetParallaxHeightTexture()); glActiveTexture(GL_TEXTURE14); glBindTexture(GL_TEXTURE_2D, infoTextureHandler->GetCurrentInfoTexture()); for (int i = 0; i < CSMFReadMap::NUM_SPLAT_DETAIL_NORMALS; i++) { if (smfMap->GetSplatNormalTexture(i) != 0) { glActiveTexture(GL_TEXTURE15 + i); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatNormalTexture(i)); } } glActiveTexture(GL_TEXTURE0); }
void SMFRenderStateGLSL::Enable(const CSMFGroundDrawer* smfGroundDrawer, const DrawPass::e& drawPass) { if (useLuaShaders) { // use raw, GLSLProgramObject::Enable also calls RecompileIfNeeded glUseProgram(glslShaders[GLSL_SHADER_CURRENT]->GetObjID()); // diffuse textures are always bound (SMFGroundDrawer::SetupBigSquare) glActiveTexture(GL_TEXTURE0); return; } Shader::IProgramObject* shader = glslShaders[GLSL_SHADER_CURRENT]; const CSMFReadMap* smfMap = smfGroundDrawer->GetReadMap(); const GL::LightHandler* cLightHandler = smfGroundDrawer->GetLightHandler(); GL::LightHandler* mLightHandler = const_cast<GL::LightHandler*>(cLightHandler); // XXX const float3 cameraPos = camera->GetPos(); const float3 fogParams = {sky->fogStart, sky->fogEnd, globalRendering->viewRange}; const float2 mapParams = {readMap->GetCurrMinHeight(), readMap->GetCurrMaxHeight()}; shader->SetFlag("HAVE_SHADOWS", shadowHandler->ShadowsLoaded()); shader->SetFlag("HAVE_INFOTEX", infoTextureHandler->IsEnabled()); shader->Enable(); shader->SetUniform2v<const char*, float>("mapHeights", &mapParams.x); shader->SetUniform3v<const char*, float>("cameraPos", &cameraPos.x); shader->SetUniformMatrix4x4<const char*, float>("viewMat", false, camera->GetViewMatrix()); shader->SetUniformMatrix4x4<const char*, float>("viewMatInv", false, camera->GetViewMatrixInverse()); shader->SetUniformMatrix4x4<const char*, float>("viewProjMat", false, camera->GetViewProjectionMatrix()); shader->SetUniformMatrix4x4<const char*, float>("shadowMat", false, shadowHandler->GetShadowViewMatrix()); shader->SetUniform4v<const char*, float>("shadowParams", shadowHandler->GetShadowParams()); shader->SetUniform3v<const char*, float>("fogParams", &fogParams.x); shader->SetUniform<const char*, float>("infoTexIntensityMul", float(infoTextureHandler->InMetalMode()) + 1.0f); if (cLightHandler->NumConfigLights() > 0) { mLightHandler->Update(); shader->SetUniform4v<const char*, float>("fwdDynLights", cLightHandler->NumUniformVecs(), cLightHandler->GetRawLightDataPtr()); } switch (drawPass) { case DrawPass::WaterReflection: { shader->SetUniform4v<const char*, float>("clipPlane", IWater::MapReflClipPlane()); } break; case DrawPass::WaterRefraction: { shader->SetUniform4v<const char*, float>("clipPlane", IWater::MapRefrClipPlane()); } break; default: {} break; } if (shadowHandler->ShadowsLoaded()) shadowHandler->SetupShadowTexSampler(GL_TEXTURE4); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, smfMap->GetDetailTexture()); glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, smfMap->GetNormalsTexture()); glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, smfMap->GetSpecularTexture()); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatDetailTexture()); glActiveTexture(GL_TEXTURE8); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatDistrTexture()); glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapHandler->GetSkyReflectionTextureID()); glActiveTexture(GL_TEXTURE10); glBindTexture(GL_TEXTURE_2D, smfMap->GetSkyReflectModTexture()); glActiveTexture(GL_TEXTURE11); glBindTexture(GL_TEXTURE_2D, smfMap->GetBlendNormalsTexture()); glActiveTexture(GL_TEXTURE12); glBindTexture(GL_TEXTURE_2D, smfMap->GetLightEmissionTexture()); glActiveTexture(GL_TEXTURE13); glBindTexture(GL_TEXTURE_2D, smfMap->GetParallaxHeightTexture()); glActiveTexture(GL_TEXTURE14); glBindTexture(GL_TEXTURE_2D, infoTextureHandler->GetCurrentInfoTexture()); for (int i = 0; i < CSMFReadMap::NUM_SPLAT_DETAIL_NORMALS; i++) { if (smfMap->GetSplatNormalTexture(i) != 0) { glActiveTexture(GL_TEXTURE15 + i); glBindTexture(GL_TEXTURE_2D, smfMap->GetSplatNormalTexture(i)); } } glActiveTexture(GL_TEXTURE0); }