Advertisement
piluve

Untitled

May 21st, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1.   void SMaterial::Use(glm::mat4 &m, std::vector<SLight*> &l)
  2.   {
  3.     //Use the material
  4.     glUseProgram(programId);
  5.  
  6.     //Set the defaul uniforms,the material settings could request to dont do so
  7.     if (matSettings->setDefaultAttributes)
  8.     {
  9.       rendMang->SetUniform(programId, "uModel", kMat4, glm::value_ptr(m), modelLocation);
  10.  
  11.       //Set lights
  12.       int cLights = l.size();
  13.       glUniform1i(rendMang->GetUniform(programId,"uCurLights"),cLights);
  14.  
  15.       for (unsigned int i = 0; i < l.size(); i++)
  16.       {
  17.         //Set color
  18.         std::string lColName = "uLights[" + std::to_string(i) + "].lColor";
  19.         rendMang->SetUniform(programId, lColName.c_str(), kFloat3, glm::value_ptr(l[i]->GetLightInfo().lCol),
  20.                              rendMang->GetUniform(programId, lColName.c_str()));
  21.         //For sun light
  22.         if (l[i]->GetLightInfo().lType == kSun)
  23.         {
  24.           //Set light direction
  25.           std::string lDirName = "uLights[" + std::to_string(i) + "].lDir";
  26.           rendMang->SetUniform(programId, lDirName.c_str(), kFloat3, glm::value_ptr(l[i]->GetLightInfo().lDir),
  27.                                rendMang->GetUniform(programId, lDirName.c_str()));
  28.           //Set light matrix
  29.           std::string lMatName = "uLights[" + std::to_string(i) + "].lMatrix";
  30.           rendMang->SetUniform(programId, lMatName.c_str(), kMat4, glm::value_ptr(l[i]->GetLightMatrix()),
  31.                                rendMang->GetUniform(programId, lMatName.c_str()));
  32.  
  33.           //Set light shadow map
  34.           std::string lShadowName = "uLights[" + std::to_string(i) + "].uShadowMaps";
  35.           int lShadowLoc = rendMang->GetUniform(programId,lShadowName.c_str());
  36.           //int lShadowLoc = rendMang->GetUniform(programId,"uShadowMaps");
  37.           int lShadowId  = l[i]->GetShadowMapId();
  38.           rendMang->SetTexture(20+i,k2DTexture,lShadowId,lShadowLoc);
  39.         }
  40.       }
  41.     }
  42.  
  43.     //Set the attributes of the material settings
  44.     matSettings->SetLocations(programId);
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement