MCPcopy Create free account
hub / github.com/dfranx/ShaderDebugger / translateArraySubscript

Method translateArraySubscript

src/GLSLCompiler.cpp:372–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370 }
371
372 void GLSLCompiler::translateArraySubscript(glsl::astArraySubscript *expression) {
373 // first push index
374 translateExpression(expression->index);
375
376 m_indexDepth++;
377
378 bool isArray = true;
379 if (expression->operand->type == glsl::astExpression::kVariableIdentifier) {
380 glsl::astVariableIdentifier* varInfo = (glsl::astVariableIdentifier*)expression->operand;
381
382 for (const auto& loc : m_locals[m_currentFunction])
383 if (loc == varInfo->variable->name)
384 isArray = false; // TODO: after local arrays have been implemented, rewrite this part
385
386 if (isArray) {
387 for (const auto& glob : m_globals)
388 if (glob.Name == varInfo->variable->name) {
389 isArray = glob.IsArray;
390 break;
391 }
392 }
393
394 // TODO: m_indexDetph-arraySize when using an array of matrices, example: mat4 m[4]; m[0][0][0];
395 if (m_writeIndexDepth || m_isSet) {
396 if (!isArray) // which means it must be an object
397 m_gen.Function.PushStack((char)m_indexDepth);//objects require index count
398 }
399 }
400
401 // then array
402 bool temp_isSet = m_isSet, temp_writeIndexDepth = m_writeIndexDepth;
403 m_isSet = false;
404 m_writeIndexDepth = temp_isSet;
405 translateExpression(expression->operand);
406 m_writeIndexDepth = false;
407 m_isSet = temp_isSet;
408
409 if (expression->operand->type == glsl::astExpression::kVariableIdentifier) {
410 if (m_isSet || (temp_writeIndexDepth && !isArray))
411 m_gen.Function.SetArrayElement();
412 else
413 m_gen.Function.GetArrayElement();
414
415 m_indexDepth = 0;
416
417
418 if (m_isSet || (temp_writeIndexDepth && !isArray)) {
419 temp_isSet = m_isSet;
420 if (!m_isSet)
421 m_isSet = true;
422 translateExpression(expression->operand);
423 m_isSet = temp_isSet;
424 }
425 }
426 else if (!m_isSet)
427 m_gen.Function.GetArrayElement();
428 }
429

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected