| 245 | } |
| 246 | |
| 247 | void SetProgramConstantValues(dmGraphics::HContext graphics_context, dmGraphics::HProgram program, uint32_t total_constants_count, dmHashTable64<dmGraphics::HUniformLocation>& name_hash_to_location, dmArray<RenderConstant>& constants, dmArray<Sampler>& samplers) |
| 248 | { |
| 249 | const uint32_t buffer_size = 128; |
| 250 | char buffer[buffer_size]; |
| 251 | |
| 252 | uint32_t default_values_capacity = 0; |
| 253 | dmVMath::Vector4* default_values = 0; |
| 254 | uint32_t sampler_index = 0; |
| 255 | |
| 256 | for (uint32_t i = 0; i < total_constants_count; ++i) |
| 257 | { |
| 258 | dmGraphics::Uniform uniform_desc; |
| 259 | dmGraphics::GetUniform(program, i, &uniform_desc); |
| 260 | |
| 261 | #if 0 |
| 262 | dmLogInfo("Uniform[%d]: name=%s, type=%s, num_values=%d, location=%lld", |
| 263 | i, uniform_desc.m_Name, dmGraphics::GetGraphicsTypeLiteral(uniform_desc.m_Type), |
| 264 | uniform_desc.m_Count, uniform_desc.m_Location); |
| 265 | #endif |
| 266 | |
| 267 | // DEF-2971-hotfix |
| 268 | // Previously this check was an assert. In Emscripten 1.38.3 they made changes |
| 269 | // to how uniforms are collected and reported back from WebGL. Simply speaking |
| 270 | // in previous Emscripten versions you would get "valid" locations for uniforms |
| 271 | // that wasn't used, but after the upgrade these unused uniforms will return -1 |
| 272 | // as location instead. The fix here is to avoid asserting on such values, but |
| 273 | // not saving them in the m_Constants and m_NameHashToLocation structs. |
| 274 | if (uniform_desc.m_Location == dmGraphics::INVALID_UNIFORM_LOCATION || !IsUniformTypeSupported(uniform_desc.m_Type)) |
| 275 | { |
| 276 | continue; |
| 277 | } |
| 278 | |
| 279 | name_hash_to_location.Put(uniform_desc.m_NameHash, uniform_desc.m_Location); |
| 280 | |
| 281 | uint32_t num_values = uniform_desc.m_Count; |
| 282 | |
| 283 | if (uniform_desc.m_Type == dmGraphics::TYPE_FLOAT_VEC4 || uniform_desc.m_Type == dmGraphics::TYPE_FLOAT_MAT4) |
| 284 | { |
| 285 | HConstant render_constant = dmRender::NewConstant(uniform_desc.m_NameHash); |
| 286 | |
| 287 | dmRender::SetConstantLocation(render_constant, uniform_desc.m_Location); |
| 288 | |
| 289 | // We are about to add a duplicate. Make sure to reuse the data |
| 290 | HConstant prev_constant = FindConstant(constants, uniform_desc.m_NameHash); |
| 291 | if (prev_constant != 0) |
| 292 | { |
| 293 | uint32_t prev_num_values; |
| 294 | dmVMath::Vector4* prev_values = GetConstantValues(prev_constant, &prev_num_values); |
| 295 | |
| 296 | dmRender::SetConstantValuesRef(render_constant, prev_values, prev_num_values); |
| 297 | dmRender::SetConstantType(render_constant, GetConstantType(prev_constant)); |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | if (uniform_desc.m_Type == dmGraphics::TYPE_FLOAT_MAT4) |
| 302 | { |
| 303 | num_values *= 4; |
| 304 | dmRender::SetConstantType(render_constant, dmRenderDDF::MaterialDesc::CONSTANT_TYPE_USER_MATRIX4); |
no test coverage detected