Open julee opened 8 months ago
Right. I guess that is driver dependent. More data needs to be added to the key.
Potential key values
id()
of the object glo
This is a semi-hot path, so it should ideally be as light as possible.
It could also add some unique identifier in the Program.extra
dict. That might be the best solution
It could also add some unique identifier in the
Program.extra
dict. That might be the best solution
Program.extra is for user use, it seems inappropriate to use it here. Your suggestion of using "The id() of the object" may be a better idea.
Python's id()
can have the same problem as using program.glo
. I've had problems with this in the past.
Python's
id()
can have the same problem as usingprogram.glo
. I've had problems with this in the past.
Yes, I forgot it. Perhaps we can use weakref to track whether the program object still exists, if it exists and the id is the same, we can confirm that the program matches.
The use of Program.extra that you mentioned might be the simplest method, but from an interface design perspective, extra should be for the user to use, and the user could overwrite it with a new object at any time.
Similarly, adding an additional identifier member in Program might also be a way. Perhaps this is the most intuitive way. But this requires modifications in moderngl.
WeakValueDictionary is definitely the only solution here as far as I can see.
The VAO instance method uses the program id as a key to cache VertexArray internally.
However, if the original Program is released, and a new Program is created, the opengl id of the new Program may be the same as the original program.
But the vertex attributes of the new Program have a different layout. At this time, calling the VAO instance method to get the VertexArray from the cache will be wrong!
This is a potential error behavior, difficult to be discovered.
A better way might be to remember the layout of the vertices, see if they are consistent, and then decide whether to reuse the VertexArray in the cache.
Source code with potential issues: