For example, would the following be legal and produce valid deterministic results:
var A = createGraphics(...);
var B = createGraphics(...);
… // other stuff
void draw() {
A.beginDraw();
... // draw shapes and sprites to A, normal rendering operations, etc.
A.endDraw();
... // advance various intra-frame logic
A.beginDraw();
... // render the contents of other PGraphics instances (not B) to A
A.endDraw();
...
B.beginDraw();
B.image(A...); // render the contents of A to B
B.endDraw();
...
image(B...) // render the contents of B to the main window
}
Expectation
I would expect (or perhaps “hope” is more appropriate here) that this would result in my screen containing an image of B which itself contains an image of A which itself contains images of other PGraphics objects not listed here overtop of various shapes and sprites that were “initially” rendered to A before the images. The status of this closed github issue (I’m too new to the forums to include every link so the issue route is: processing/processing4/issues/641) led me to believe that this might be the case but it is still not totally clear to me.
Context
I know that the ideal solution would be to batch everything within a single begin/end draw sequence, however, this requires significant refactoring of my “controlled access resource” system I’ve implemented to provide canvases for rendering throughout the application life span (basically, calling “get(id)” to retrieve a canvas automatically calls “open()” on the controlled access resource wrapping the PGraphics object which, in turn, calls beginDraw() and then, when put inside of a try-with-resources block, “close()” is called automatically which, in turn, calls endDraw()) so I’d like to know if it is an explicit requirement before committing to the refactor. These “extra” begin/end draw sequences would be quite infrequent so I do not anticipate much performance impact if they are allowed.
Code
- Logic which initially batches all “normal” rendering operations together (shapes and sprites per canvas, etc.)
- Logic which may potentially result in additional begin/end draw sequence that takes place after the “regular” render phase has completed (right now the phases are: render() where shapes and sprites are drawn followed by update() where simulation logic is updated and PGraphics are rendered to other PGraphics)
Note
- This project is using Processing 4.3 as a locally-managed Java library on JDK 26
- My current logic appears to render the results I expect when there are only 2 PGraphics objects of concern (the main window context and 1 offscreen context which gets scaled and rendered to the window context at the window’s full dimensions) but since my “controlled access resource” wrapper differentiates between the main window PGraphics and child PGraphics objects it is not an accurate representation of the issue I’m asking about (the main PGraphics wrapper essentially overrides the default open/close behavior with no-op implementations since all of this happens within the main PApplet::draw and, thus, we don’t need to signal begin/end of the draw in that case).