Repository: ManimCommunity/manim
File: manim/renderer/opengl_renderer.py (Python)

Code before:
                shader.set_uniform(
                    "u_projection_matrix",
                    self.scene.camera.projection_matrix,
                )
            except KeyError:
                pass

            # Set depth test.
            if shader_wrapper.depth_test:
                self.context.enable(moderngl.DEPTH_TEST)
            else:
                self.context.disable(moderngl.DEPTH_TEST)

            # Render.
            mesh = Mesh(
                shader,
                shader_wrapper.vert_data,
                indices=shader_wrapper.vert_indices,
                use_depth_test=shader_wrapper.depth_test,
                primitive=mobject.render_primitive,
            )
            mesh.set_uniforms(self)
            mesh.render()

    def get_texture_id(self, path):
        if str(path) not in self.path_to_texture_id:
            if type(path) == str:
                # A way to increase tid's sequentially
                tid = len(self.path_to_texture_id)
                im = Image.open(path)
                texture = self.context.texture(
                    size=im.size,
                    components=len(im.getbands()),
                    data=im.tobytes(),
                )
                texture.use(location=tid)
            elif type(path) == np.ndarray:
                tid = len(self.path_to_texture_id)
                texture = self.context.texture(
                    size=path.shape[1::-1],
                    components=path.shape[2],
                    data=path.astype("uint8"),
                )
                texture.use(location=tid)
            self.path_to_texture_id[str(path)] = tid
        return self.path_to_texture_id[str(path)]

    def update_skipping_status(self):
        """
        This method is used internally to check if the current
        animation needs to be skipped or not. It also checks if

Review comment (suggestion):
is `path` a `Path` object? In which case I would recommend using `os.fspath`. If it's not using the `repr` function instead of `str` function is better.

Code after:
                )
                shader.set_uniform(
                    "u_projection_matrix",
                    self.scene.camera.projection_matrix,
                )
            except KeyError:
                pass

            # Set depth test.
            if shader_wrapper.depth_test:
                self.context.enable(moderngl.DEPTH_TEST)
            else:
                self.context.disable(moderngl.DEPTH_TEST)

            # Render.
            mesh = Mesh(
                shader,
                shader_wrapper.vert_data,
                indices=shader_wrapper.vert_indices,
                use_depth_test=shader_wrapper.depth_test,
                primitive=mobject.render_primitive,
            )
            mesh.set_uniforms(self)
            mesh.render()

    def get_texture_id(self, path):
        if repr(path) not in self.path_to_texture_id:
            tid = len(self.path_to_texture_id)
            texture = self.context.texture(
                size=path.size,
                components=len(path.getbands()),
                data=path.tobytes(),
            )
            texture.repeat_x = False
            texture.repeat_y = False
            texture.filter = (moderngl.NEAREST, moderngl.NEAREST)
            texture.swizzle = "RRR1" if path.mode == "L" else "RGBA"
            texture.use(location=tid)
            self.path_to_texture_id[repr(path)] = tid

        return self.path_to_texture_id[repr(path)]

    def update_skipping_status(self):
        """
        This method is used internally to check if the current
        animation needs to be skipped or not. It also checks if
        the number of animations that were played correspond to
        the number of animations that need to be played, and
        raises an EndSceneEarlyException if they don't correspond.
        """
        # there is always at least one section -> no out of bounds here