Skip to content

Minimal Viable OpenGLView#4279

Draft
corranwebster wants to merge 24 commits intobeeware:mainfrom
corranwebster:opengl-minimal-widget
Draft

Minimal Viable OpenGLView#4279
corranwebster wants to merge 24 commits intobeeware:mainfrom
corranwebster:opengl-minimal-widget

Conversation

@corranwebster
Copy link
Copy Markdown
Contributor

@corranwebster corranwebster commented Mar 28, 2026

This implements a minimal OpenGLView widget for Android, Cocoa, Gtk, iOS and Qt. This widget merely sets up an OpenGL context, and calls back to user code to do the rendering with whatever OpenGL API is appropriate.

Includes documentation and an example.

NOTE: To test in an existing installation you will need to run pip install -e "./cocoa" --no-deps (or ./qt, etc) to pick up the new entrypoint for the OpenGL widget.

Things to be resolved:

  • Android tests are not calling out to renderer (works locally, fails in CI)
  • Android example renderer is not drawing triangles
  • Tests are expected to fail on Windows because the widget is not implemented.
  • More graceful failures/warnings when can't get requested API level (my ARM Linux VMs have trouble with anything above OpenGL 2.1...)

Nice to haves (mostly in examples, possibly for later PRs):

  • Mouse/touch positions.
  • Better iOS support for OpenGL.
  • Show Qt GL bindings in example.
  • Actual 3D rendering (Teapots!) in example.
  • Shadertoy!

Ref #51
Fixes #4273

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

This implements a minimal OpenGLView widget for many backends.
This widget merely sets up an OpenGL context, and calls back to
user code to do the rendering with whatever OpenGL API is
appropriate.

Includes basic documentation and an example.
@corranwebster corranwebster mentioned this pull request Mar 28, 2026
11 tasks
Comment on lines +72 to +74
fitting_size = self.native.fittingSize()
self.interface.intrinsic.height = at_least(fitting_size.height)
self.interface.intrinsic.width = at_least(fitting_size.width)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here this value is 0 on cocoa. Same may be occuring on other backends -- it'd be wise to take the maximum of the native fitting size and self.interface._MIN_WIDTH and self.interface._MIN_HEIGHT (defined in core base.py).

I understand that you did not ask for a review, but since this is not in your TODO list, I'd like to bring this to attn.

Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm... I stole borrowed that from the Canvas widget. I figured that I want the same logic for the size of the widget.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In which case it may be appropriate to not enforce a minimum size. I apologize for not researching those precedents in advance.

You may resolve this comment now. I brought this up because I got a "singular matrix" eror when I resized toga-chart to 0 size...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There shouldn't be a minimum size, per-se, but having it at least be positive might be a good idea. In any case it's a wider issue than just this.

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.

Add an OpenGL API-Agnostic OpenGL Widget

2 participants