openage icon indicating copy to clipboard operation
openage copied to clipboard

Optionally check if all uniform values have been set

Open heinezen opened this issue 1 year ago • 4 comments

Required Skills: C++ (understanding OpenGL terminology is helpful too)

Difficulty: Easy

Whenever we want to change something in the shader for an object, we use a UniformInput object to store the values. When the object is rendered, the data from the uniform input is passed to the GPU, e.g. via OpenGL. The definitions of the uniform data rypes are stored in the ShaderProgram class.

During rendering, the GPU does not strictly require that all uniform values have to be set for rendering to happen. However, when a uniform value is not set, e.g. when someone forgets to set pass it to the uniform input, this often leads to rendering errors, or worse: nothing being rendered at all. This is often infuriating to debug as it not always clear from the start whether the value was just forgotten or another error produces the rendering problems. To mitigate these issues, we should add a way to check if all uniform values for a uniform input have been set.

To try out the renderer and see how setting uniform values work, check out renderer demo 4 by running the following command:

./run test -d renderer.tests.renderer_demo 4

Tasks:

  • [ ] Implement an is_complete(..) method for GlUniformInput that checks if all uniform values have been set. You can accomplish this easily by iterating through the update_offs vector and testing if the used flag has been set.
  • [ ] Add is_complete(..) checks to the renderer demos in https://github.com/SFTtech/openage/tree/master/libopenage/renderer/demo

Further Reading

heinezen avatar Aug 25 '24 05:08 heinezen

Hey, I think I'll try this issue out.

AdamYChe avatar Sep 22 '24 00:09 AdamYChe

@AdamYChe Nice! If you have any problems, contact us in our chatroom

heinezen avatar Sep 22 '24 01:09 heinezen

Hey ! can i try this issue too ?

yukirine avatar Oct 17 '24 08:10 yukirine

@yukirine Yes, you can!

heinezen avatar Oct 18 '24 03:10 heinezen

Hi, I’d love to contribute to this! I was wondering if it would be appropriate to call the is_complete(..) function within GlShaderProgram::update_uniforms(...)? This way, the uniforms can be verified in each iteration of the loop before rendering. Would this approach make sense?

ZzzhHe avatar Nov 26 '24 15:11 ZzzhHe

@ZzzhHe We would probably want to avoid this (even in debug mode) because the render loop should be as fast as possible and adding sanity checks could slow it down substantially. I think the best place to call the function is in the code of the several demos that we have, see https://github.com/SFTtech/openage/tree/master/libopenage/renderer/demo

heinezen avatar Nov 26 '24 17:11 heinezen

@heinezen Thanks! I get it. Working on it.

ZzzhHe avatar Nov 26 '24 18:11 ZzzhHe

I’ve implemented an is_complete() function in GlUniformInput, but using it requires dynamic_pointer_cast since new_uniform_input() returns a UniformInput instead of GlUniformInput. Would it make sense to add is_complete() as a virtual method in UniformInput? This would allow calling is_complete() directly on UniformInput. Or, is there another approach you’d recommend?

ZzzhHe avatar Nov 26 '24 20:11 ZzzhHe

@ZzzhHe Yes, that would make sense!

heinezen avatar Nov 27 '24 12:11 heinezen