Skip to content

Conversation

@arnaud-ma
Copy link
Contributor

Overview: What does this pull request change?

Motivation and Explanation: Why and how do your changes improve the library?

For #3375

Links to added or changed documentation pages

Further Information and Comments

The typing revealed a bug in the get_texture_id method: it is passed a path (string), but throughout the function it is treated as if it were a PIL Image. No test triggers this call, and I did not find anything that could trigger it. To trigger it, there must be a mobject that has a shader in mobject.get_shader_wrapper_list() with a non-empty shader.texture.texture_paths. To fix this, the create_texture method open the path into a PIL Image.

Also, there are some uses of typing.cast. This is because of the implicit contracts "using OpenGLRenderer => the camera is an OpenGLCamera" and "using OpenGLRenderer => all mobjects are OpenGLMobject or OpenGLVMobject”. I think the proper way to deal with this would be to introduce generics in the Scene class, such as Scene[CameraType, MobjectType], and define protocol classes to bound these types. For example, for the camera:

class Camera(typing.Protocol): 
    minimal methods/attributes needed for a camera ...

_CameraType = typing.TypeVar("_CameraType", bound=Camera)

class Scene(typing.Generic[_CameraType]: 
     def __init__(self, ..., camera_class: type[_CameraType]):
         ...

but the cast seems quite reasonable compared to this complexity.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@arnaud-ma
Copy link
Contributor Author

CI tests failing only on mac due to font-related things seems really weird lol. I don't think this is related to this PR at all

behackl and others added 6 commits January 25, 2026 16:53
The Window import was moved to module-level in a recent type annotation
commit, but this causes opengl_renderer_window.py to be imported at
load time, triggering pyglet which fails on headless systems (RTD) when
it tries to create a shadow window. Moving the import into TYPE_CHECKING
preserves type hints for mypy while avoiding runtime display dependency.
- Cast np.linalg.inv() result to correct type
- Convert quaternion list to ndarray before passing to rotation_matrix_transpose_from_quaternion
- Cast get_center return value
- Fix return type for pixel_coords_to_space_coords (ensure float dtype)
- Add type: ignore for moderngl.create_context backend arg (incorrect stubs)
- Add type: ignore for blend_func assignment (incorrect stubs)
- Import MatrixMN and Point3D at runtime (needed for typing.cast)
- Cast np.linalg.inv() result to correct MatrixMN type
- Convert quaternion list to ndarray before passing to rotation_matrix_transpose_from_quaternion
- Cast get_center and pixel_coords_to_space_coords return values to Point3D
- Ensure float dtype in np.array literals for type consistency
The Window class is imported inside TYPE_CHECKING for type hints, but
needs to be imported at runtime when actually creating a window. This
import is deferred to avoid triggering pyglet display initialization
on headless systems (RTD build).
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your hard work with this contribution! There was an issue with mypy when running it locally that I've added a minor fix to improve, and there was a problem with the Window import where I've restored the previous behavior to avoid having the library import fail on headless systems.

Otherwise, the documentation and typehint improvements here seem fine to me (and are much appreciated)!

One thing to note, however: in case you'd like to continue improving the OpenGL rendering pipeline, have a look at what we are doing on the experimental branch -- basically a future-proof rewrite of a good chunk of the rendering system to make it less entwined and easier to maintain in the future.

Again, very much appreciate your work here!

@behackl behackl merged commit bbdcda1 into ManimCommunity:main Jan 25, 2026
15 checks passed
@arnaud-ma arnaud-ma deleted the typing-opengl-renderer branch January 25, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants