Advertisement
microwerx

getting active uniforms

Dec 30th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.95 KB | None | 0 0
  1.     void __ShaderProgramLocations::GetMaterialProgramLocations(SimpleProgram &program)
  2.     {
  3.         locations.clear();
  4.         locations["Ka"] = Ka = program.GetUniformLocation("Ka");
  5.         locations["Kd"] = Kd = program.GetUniformLocation("Kd");
  6.         locations["Ks"] = Ks = program.GetUniformLocation("Ks");
  7.         locations["Ke"] = Ke = program.GetUniformLocation("Ke");
  8.         locations["Tr"] = Tr = program.GetUniformLocation("Tr");
  9.         locations["Tf"] = Tf = program.GetUniformLocation("Tf");
  10.         locations["Ns"] = Ns = program.GetUniformLocation("Ns");
  11.         locations["Ni"] = Ni = program.GetUniformLocation("Ni");
  12.  
  13.         locations["PBk"] = PBk = program.GetUniformLocation("PBk");
  14.         locations["PBm"] = PBm = program.GetUniformLocation("PBm");
  15.         locations["PBKdm"] = PBKdm = program.GetUniformLocation("PBKdm");
  16.         locations["PBKsm"] = PBKsm = program.GetUniformLocation("PBKsm");
  17.         locations["PBior"] = PBior = program.GetUniformLocation("PBior");
  18.         locations["PBGGXgamma"] = PBGGXgamma = program.GetUniformLocation("PBGGXgamma");
  19.         locations["PBmap"] = PBmap = program.GetUniformLocation("PBmap");
  20.         ///
  21.         locations["map_Ka"] = map_Ka = program.GetUniformLocation("map_Ka");
  22.         locations["map_Kd"] = map_Kd = program.GetUniformLocation("map_Kd");
  23.         locations["map_Ks"] = map_Ks = program.GetUniformLocation("map_Ks");
  24.         locations["map_Ke"] = map_Ke = program.GetUniformLocation("map_Ke");
  25.         locations["map_Tr"] = map_Tr = program.GetUniformLocation("map_Tr");
  26.         locations["map_Tf"] = map_Tf = program.GetUniformLocation("map_Tf");
  27.         locations["map_Ni"] = map_Ni = program.GetUniformLocation("map_Ni");
  28.         locations["map_Ns"] = map_Ns = program.GetUniformLocation("map_Ns");
  29.         locations["map_bump"] = map_bump = program.GetUniformLocation("map_bump");
  30.         locations["map_normal"] = map_normal = program.GetUniformLocation("map_normal");
  31.         locations["map_Ka_mix"] = map_Ka_mix = program.GetUniformLocation("map_Ka_mix");
  32.         locations["map_Kd_mix"] = map_Kd_mix = program.GetUniformLocation("map_Kd_mix");
  33.         locations["map_Ks_mix"] = map_Ks_mix = program.GetUniformLocation("map_Ks_mix");
  34.         locations["map_Ke_mix"] = map_Ke_mix = program.GetUniformLocation("map_Ke_mix");
  35.         locations["map_Tf_mix"] = map_Tf_mix = program.GetUniformLocation("map_Tf_mix");
  36.         locations["map_Tr_mix"] = map_Tr_mix = program.GetUniformLocation("map_Tr_mix");
  37.         locations["map_Ni_mix"] = map_Ni_mix = program.GetUniformLocation("map_Ni_mix");
  38.         locations["map_Ns_mix"] = map_Ns_mix = program.GetUniformLocation("map_Ns_mix");
  39.         locations["map_bump_mix"] = map_bump_mix = program.GetUniformLocation("map_bump_mix");
  40.         locations["map_normal_mix"] = map_normal_mix = program.GetUniformLocation("map_normal_mix");
  41.  
  42.         locations["Spheres"] = sphere_array = program.GetUniformLocation("Spheres[0]");
  43.         locations["SpheresCount"] = sphere_count = program.GetUniformLocation("SpheresCount");
  44.         locations["SpheresKe"] = sphere_Ke = program.GetUniformLocation("SpheresKe[0]");
  45.  
  46.         for (int i = 0; i < 16; i++)
  47.         {
  48.             char name[64];
  49.             sprintf_s(name, "SphlLights[%d].Enabled", i);  locations[name] = sphl_lights_enabled[i] = program.GetUniformLocation(name);
  50.             sprintf_s(name, "SphlLights[%d].E0", i);       locations[name] = sphl_lights_E0[i] = program.GetUniformLocation(name);
  51.             sprintf_s(name, "SphlLights[%d].Position", i); locations[name] = sphl_lights_position[i] = program.GetUniformLocation(name);
  52.             sprintf_s(name, "SphlLights[%d].LightProbeCubeMap", i); locations[name] = sphl_lights_lightProbeCubeMap[i] = program.GetUniformLocation(name);
  53.             sprintf_s(name, "SphlLights[%d].EnvironmentCubeMap", i); locations[name] = sphl_lights_environmentCubeMap[i] = program.GetUniformLocation(name);
  54.             sprintf_s(name, "SphlLights[%d].DepthShadowCubeMap", i); locations[name] = sphl_lights_depthShadowCubeMap[i] = program.GetUniformLocation(name);
  55.             sprintf_s(name, "SphlLights[%d].DepthShadowZFar", i); locations[name] = sphl_lights_depthShadowZFar[i] = program.GetUniformLocation(name);
  56.             for (int j = 0; j < 9; j++)
  57.             {
  58.                 sphl_lights_sph[i][j] = -1;
  59.                 sprintf_s(name, "SphlLights[%d].sph[%d]", i, j); locations[name] = sphl_lights_sph[i][j] = program.GetUniformLocation(name);
  60.             }
  61.         }
  62.  
  63.         locations["ToneMapScale"] = toneMapScale = program.GetUniformLocation("ToneMapScale");
  64.         locations["ToneMapExposure"] = toneMapExposure = program.GetUniformLocation("ToneMapExposure");
  65.         locations["ToneMapGamma"] = toneMapGamma = program.GetUniformLocation("ToneMapGamma");
  66.         locations["SunDirTo"] = sunDirTo = program.GetUniformLocation("SunDirTo");
  67.         locations["SunColor"] = sunColor = program.GetUniformLocation("SunColor");
  68.         locations["SunSize"] = sunSize = program.GetUniformLocation("SunSize");
  69.         locations["SunShadowMap"] = sunShadowMap = program.GetUniformLocation("SunShadowMap");
  70.         locations["SunColorMap"] = sunColorMap = program.GetUniformLocation("SunColorMap");
  71.         locations["SunShadowMatrix"] = sunShadowMatrix = program.GetUniformLocation("SunShadowMatrix");
  72.         locations["SunE0"] = sunE0 = program.GetUniformLocation("SunE0");
  73.         locations["GroundE0"] = groundE0 = program.GetUniformLocation("GroundE0");
  74.    
  75.         locations["EnviroCubeMap"] = enviroCubeMap = program.GetUniformLocation("EnviroCubeMap");
  76.         locations["EnviroCubeMapAmount"] = enviroCubeMapAmount = program.GetUniformLocation("EnviroCubeMapAmount");
  77.  
  78.         locations["PBSkyCubeMap"] = pbskyCubeMap = program.GetUniformLocation("PBSkyCubeMap");
  79.  
  80.         locations["ShaderDebugChoice"] = shaderDebugChoice = program.GetUniformLocation("ShaderDebugChoice");
  81.         locations["ShaderDebugLight"] = shaderDebugLight = program.GetUniformLocation("ShaderDebugLight");
  82.         locations["ShaderDebugSphl"] = shaderDebugSphl = program.GetUniformLocation("ShaderDebugSphl");
  83.  
  84.         // Do the new way by finding out what uniforms the program actually has, or is looking for...
  85.         newLocationList.Clear();
  86.  
  87.         for (auto uniform : program.activeUniforms)
  88.         {
  89.             // uniform.first is the name of the uniform...
  90.             // uniform.second has the details...
  91.    
  92.             newLocationList[uniform.first] = MakeSharedIntProperty(uniform.second.index);
  93.         }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement