Skip to content

Created initial abstract renderers #2455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from

Conversation

k4pran
Copy link
Collaborator

@k4pran k4pran commented Jan 9, 2022

Overview: What does this pull request change?

The purpose of this PR is an initial refactor of the renderer and scene. The main goals were to remove circular dependencies between scene, renderer and scene_file_writer, and to make scene agnostic to the type of renderer used. There is still a lot more refactoring and improvements to still do beyond this, but those first few goals already created quite a large PR so anything else now related to these I think should be outside the scope of this PR.

  • Created initial abstract Renderer class
  • Made scene agnostic to the type of renderer
  • Untangled circular dependencies between scene, renderer and scene_file_writer

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

The goals of this PR are

  1. To make scene agnostic to the renderers. Currently scene needs to know if the renderer is opengl or cairo. This PR allows scene to treat both renderers (and any future renderers) the same.

  2. To untangle the dependencies between scene <-> renderer and renderer <-> scene_file_writer. This avoids circular dependencies that adds complexity, makes the flow more difficult to follow and improves the decoupling of components. The scene now has access to a renderer and a scene_file_writer. The renderer does not need to be aware of the scene or the file_writer. The few cases where the renderer uses a file_writer it is passed as a parameter from the scene.

  3. To create an initial abstract renderer that can be applied to cairo and opengl. This is not meant to be what the final abstract renderer will look like, it was simply to extract what the common methods currently are. Finding the final abstract renderers will involve making improvements to the renderers themselves and this is outside the scope of this PR.

Things that are outside the scope of this PR:

  • To make any improvements to the logic or functionality of the renderers, scene etc.
  • To try and find a final abstract renderer for the long-term. This will likely materialize after we merge the Mobjects and OpenGLMObjects to a united mobject. So you can think of the current Renderer class as a placeholder for now

In doing this a lot has moved about, such as renderer-specific logic to the renderers, and common logic to the scene, but the goal was to try and not change any behaviour.

Links to added or changed documentation pages

Further Information and Comments

This likely will not be merged to the main branch but will be targetting a new branch as part of the refactor.

It is a bit behind main, I will rebase to main once we are ready to start merging these kind of changes, but I thought I would open a draft for people to begin looking at it.

Most of the tests are passing. There are a four graphical unit tests not passing, I am not sure if this is due to an error in this PR, but I didn't think that it was. They are failing because the last frame in this PR is showing the scene, however in the stored test data the last frame is an empty scene. An example of one of the tests that fail is

@frames_comparison(last_frame=False)
def test_ZIndex(scene):
    circle = Circle().set_fill(RED, opacity=1)
    square = Square(side_length=1.7).set_fill(BLUE, opacity=1)
    triangle = Triangle().set_fill(GREEN, opacity=1)
    square.z_index = 0
    triangle.z_index = 1
    circle.z_index = 2

    scene.play(FadeIn(VGroup(circle, square, triangle)))
    scene.play(ApplyMethod(circle.shift, UP))
    scene.play(ApplyMethod(triangle.shift, 2 * UP))

I don't see from this scene why the last frame should be an empty scene?

The below tests fail:

FAILED tests/test_graphical_units/test_opengl.py::test_Circle - AssertionError:
FAILED tests/test_graphical_units/test_geometry.py::test_ZIndex - AssertionError:
FAILED tests/test_graphical_units/test_indication.py::test_FocusOn - AssertionError:
FAILED tests/test_graphical_units/test_indication.py::test_Flash - AssertionError:
FAILED tests/test_graphical_units/test_indication.py::test_ShowPassingFlash - AssertionError:

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

@behackl behackl added this to the v0.16.0 milestone Feb 27, 2022
@MrDiver
Copy link
Collaborator

MrDiver commented Jun 18, 2022

I put this on the list of relevant PRs on the Architecture discussion

@MrDiver MrDiver closed this Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.

3 participants