From 7c46bcb7078bdc012e24e3f2634d8726d38040d2 Mon Sep 17 00:00:00 2001 From: shr Date: Sun, 17 Sep 2023 21:11:11 +0900 Subject: [PATCH] add docs --- source/funkin/graphics/framebuffer/FrameBuffer.hx | 15 ++++++++++++--- .../graphics/framebuffer/FrameBufferManager.hx | 3 +++ source/funkin/graphics/framebuffer/SpriteCopy.hx | 5 ++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/funkin/graphics/framebuffer/FrameBuffer.hx b/source/funkin/graphics/framebuffer/FrameBuffer.hx index 73567d0ba..0209a4aef 100644 --- a/source/funkin/graphics/framebuffer/FrameBuffer.hx +++ b/source/funkin/graphics/framebuffer/FrameBuffer.hx @@ -8,6 +8,9 @@ import flixel.FlxCamera; import openfl.Lib; import openfl.display3D.textures.TextureBase; +/** + * A single frame buffer. Used by `FrameBufferManager`. + */ class FrameBuffer { /** @@ -37,8 +40,7 @@ class FrameBuffer public function create(width:Int, height:Int, bgColor:FlxColor):Void { dispose(); - final c3d = Lib.current.stage.context3D; - texture = c3d.createTexture(width, height, BGRA, true); + texture = Lib.current.stage.context3D.createTexture(width, height, BGRA, true); bitmap = BitmapData.fromTexture(texture); camera.bgColor = bgColor; } @@ -88,13 +90,15 @@ class FrameBuffer /** * Unlocks the frame buffer and makes the bitmap ready to use. */ - @:access(flixel.FlxCamera) public function unlock():Void { bitmap.fillRect(new Rectangle(0, 0, bitmap.width, bitmap.height), 0); bitmap.draw(camera.flashSprite, new Matrix(1, 0, 0, 1, camera.flashSprite.x, camera.flashSprite.y)); } + /** + * Diposes stuff. Call `create` again if you want to reuse the instance. + */ public function dispose():Void { if (texture != null) @@ -104,8 +108,13 @@ class FrameBuffer bitmap.dispose(); bitmap = null; } + spriteCopies.clear(); } + /** + * Adds a sprite copy to the frame buffer. + * @param spriteCopy the sprite copy + */ public function addSpriteCopy(spriteCopy:SpriteCopy):Void { spriteCopies.push(spriteCopy); diff --git a/source/funkin/graphics/framebuffer/FrameBufferManager.hx b/source/funkin/graphics/framebuffer/FrameBufferManager.hx index f842ef638..6cfadd468 100644 --- a/source/funkin/graphics/framebuffer/FrameBufferManager.hx +++ b/source/funkin/graphics/framebuffer/FrameBufferManager.hx @@ -5,6 +5,9 @@ import openfl.display.BitmapData; import flixel.FlxSprite; import flixel.FlxCamera; +/** + * Manages frame buffers and gives access to each frame buffer. + */ class FrameBufferManager { final camera:FlxCamera; diff --git a/source/funkin/graphics/framebuffer/SpriteCopy.hx b/source/funkin/graphics/framebuffer/SpriteCopy.hx index b1fc82497..b95462ea3 100644 --- a/source/funkin/graphics/framebuffer/SpriteCopy.hx +++ b/source/funkin/graphics/framebuffer/SpriteCopy.hx @@ -1,9 +1,12 @@ package funkin.graphics.framebuffer; -import flixel.util.FlxColor; import flixel.FlxCamera; import flixel.FlxSprite; +import flixel.util.FlxColor; +/** + * A copy of a `FlxSprite` with a specified color. Used to render the sprite to a frame buffer. + */ class SpriteCopy { final sprite:FlxSprite;