Fix the state change counter for a draw loop

Review the AI's codeEasy12 minNvidia style

Your task

Your OpenGL renderer stalls for milliseconds every frame. Each object's draw binds its shader and its material (which re-uploads its textures), and objects arrive in any order, so the same state gets bound again and again. You model the cost to show what batching saves.

An assistant wrote state_change_cost(object_shaders, object_materials). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • object_shaders, object_materials: object i is drawn with shader object_shaders[i] and material object_materials[i].
  • Return [cost_in_submission_order, cost_after_batching].

Rules the tests check:

  • If the two lists differ in length, use only as many objects as the shorter one has.
  • The cost of drawing objects in a given order: nothing is bound at the start. For each object, add 1 if its shader differs from the shader currently bound (or none is bound), then add 1 if its material differs from the material currently bound (or none is bound). Each bind replaces what was bound before.
  • The first number is the cost in the order the objects were given.
  • The second is the cost after sorting the objects by shader, then by material, both in ascending order by plain string comparison.

Examples

state_change_cost(object_shaders: list[str], object_materials: list[str]) -> list[int]
Example 1
Inputstate_change_cost(["pbr", "pbr", "pbr"], ["rock", "grass", "rock"])
Output[4, 3]
Example 2
Inputstate_change_cost([], [])
Output[0, 0]
Example 3
Inputstate_change_cost(["pbr"], ["rock"])
Output[2, 2]