@@ -891,12 +891,46 @@ class Framebuffer {
891891
892892 /**
893893 * Creates a new
894- * <a href="#/p5.Camera">p5.Camera</a> object to use with the framebuffer and sets it as the current (active) camera .
894+ * <a href="#/p5.Camera">p5.Camera</a> object to use with the framebuffer.
895895 *
896896 * The new camera is initialized with a default position `(0, 0, 800)` and a
897897 * default perspective projection. Its properties can be controlled with
898898 * <a href="#/p5.Camera">p5.Camera</a> methods such as `myCamera.lookAt(0, 0, 0)`.
899899 *
900+ * Framebuffer cameras should be created between calls to
901+ * <a href="#/p5.Framebuffer/begin">myBuffer.begin()</a> and
902+ * <a href="#/p5.Framebuffer/end">myBuffer.end()</a> like so:
903+ *
904+ * ```js
905+ * let myCamera;
906+ *
907+ * myBuffer.begin();
908+ *
909+ * // Create the camera for the framebuffer.
910+ * myCamera = myBuffer.createCamera();
911+ *
912+ * myBuffer.end();
913+ * ```
914+ *
915+ * Calling <a href="#/p5/setCamera">setCamera()</a> updates the
916+ * framebuffer's projection using the camera.
917+ * <a href="#/p5/resetMatrix">resetMatrix()</a> must also be called for the
918+ * view to change properly:
919+ *
920+ * ```js
921+ * myBuffer.begin();
922+ *
923+ * // Set the camera for the framebuffer.
924+ * setCamera(myCamera);
925+ *
926+ * // Reset all transformations.
927+ * resetMatrix();
928+ *
929+ * // Draw stuff...
930+ *
931+ * myBuffer.end();
932+ * ```
933+ *
900934 * @method createCamera
901935 * @returns {p5.Camera } new camera.
902936 *
@@ -916,6 +950,9 @@ class Framebuffer {
916950 * // Create a p5.Framebuffer object.
917951 * myBuffer = createFramebuffer();
918952 *
953+ * // Create the cameras between begin() and end().
954+ * myBuffer.begin();
955+ *
919956 * // Create the first camera.
920957 * // Keep its default settings.
921958 * cam1 = myBuffer.createCamera();
@@ -927,17 +964,31 @@ class Framebuffer {
927964 * cam2.setPosition(400, -400, 800);
928965 * cam2.lookAt(0, 0, 0);
929966 *
930- * // Set the current camera to cam1.
931- * setCamera(cam1);
967+ * myBuffer.end();
932968 *
933- * describe('A white cube on a gray background. The camera toggles between frontal and aerial views when the user double-clicks.');
969+ * describe(
970+ * 'A white cube on a gray background. The camera toggles between frontal and aerial views when the user double-clicks.'
971+ * );
934972 * }
935973 *
936974 * function draw() {
937975 * // Draw to the p5.Framebuffer object.
938976 * myBuffer.begin();
939977 * background(200);
978+ *
979+ * // Set the camera.
980+ * if (usingCam1 === true) {
981+ * setCamera(cam1);
982+ * } else {
983+ * setCamera(cam2);
984+ * }
985+ *
986+ * // Reset all transformations.
987+ * resetMatrix();
988+ *
989+ * // Draw the box.
940990 * box();
991+ *
941992 * myBuffer.end();
942993 *
943994 * // Display the p5.Framebuffer object.
@@ -947,10 +998,8 @@ class Framebuffer {
947998 * // Toggle the current camera when the user double-clicks.
948999 * function doubleClicked() {
9491000 * if (usingCam1 === true) {
950- * setCamera(cam2);
9511001 * usingCam1 = false;
9521002 * } else {
953- * setCamera(cam1);
9541003 * usingCam1 = true;
9551004 * }
9561005 * }
@@ -980,7 +1029,24 @@ class Framebuffer {
9801029 }
9811030
9821031 /**
983- * Removes the framebuffer from the web page.
1032+ * Deletes the framebuffer from GPU memory.
1033+ *
1034+ * Calling `myBuffer.remove()` frees the GPU memory used by the framebuffer.
1035+ * The framebuffer also uses a bit of memory on the CPU which can be freed
1036+ * like so:
1037+ *
1038+ * ```js
1039+ * // Delete the framebuffer from GPU memory.
1040+ * myBuffer.remove();
1041+ *
1042+ * // Delete the framebuffer from CPU memory.
1043+ * myBuffer = undefined;
1044+ * ```
1045+ *
1046+ * Note: All variables that reference the framebuffer must be assigned
1047+ * the value `undefined` to delete the framebuffer from CPU memory. If any
1048+ * variable still refers to the framebuffer, then it won't be garbage
1049+ * collected.
9841050 *
9851051 * @method remove
9861052 *
@@ -1023,7 +1089,11 @@ class Framebuffer {
10231089 * // Remove the p5.Framebuffer object when the
10241090 * // the user double-clicks.
10251091 * function doubleClicked() {
1092+ * // Delete the framebuffer from GPU memory.
10261093 * myBuffer.remove();
1094+ *
1095+ * // Delete the framebuffer from CPU memory.
1096+ * myBuffer = undefined;
10271097 * }
10281098 * </code>
10291099 * </div>
0 commit comments