1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-09-12 05:07:06 +00:00
This commit is contained in:
shr 2023-09-17 21:11:11 +09:00 committed by Cameron Taylor
parent ace89a44a5
commit 7c46bcb707
3 changed files with 19 additions and 4 deletions

View file

@ -8,6 +8,9 @@ import flixel.FlxCamera;
import openfl.Lib; import openfl.Lib;
import openfl.display3D.textures.TextureBase; import openfl.display3D.textures.TextureBase;
/**
* A single frame buffer. Used by `FrameBufferManager`.
*/
class FrameBuffer class FrameBuffer
{ {
/** /**
@ -37,8 +40,7 @@ class FrameBuffer
public function create(width:Int, height:Int, bgColor:FlxColor):Void public function create(width:Int, height:Int, bgColor:FlxColor):Void
{ {
dispose(); dispose();
final c3d = Lib.current.stage.context3D; texture = Lib.current.stage.context3D.createTexture(width, height, BGRA, true);
texture = c3d.createTexture(width, height, BGRA, true);
bitmap = BitmapData.fromTexture(texture); bitmap = BitmapData.fromTexture(texture);
camera.bgColor = bgColor; camera.bgColor = bgColor;
} }
@ -88,13 +90,15 @@ class FrameBuffer
/** /**
* Unlocks the frame buffer and makes the bitmap ready to use. * Unlocks the frame buffer and makes the bitmap ready to use.
*/ */
@:access(flixel.FlxCamera)
public function unlock():Void public function unlock():Void
{ {
bitmap.fillRect(new Rectangle(0, 0, bitmap.width, bitmap.height), 0); 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)); 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 public function dispose():Void
{ {
if (texture != null) if (texture != null)
@ -104,8 +108,13 @@ class FrameBuffer
bitmap.dispose(); bitmap.dispose();
bitmap = null; bitmap = null;
} }
spriteCopies.clear();
} }
/**
* Adds a sprite copy to the frame buffer.
* @param spriteCopy the sprite copy
*/
public function addSpriteCopy(spriteCopy:SpriteCopy):Void public function addSpriteCopy(spriteCopy:SpriteCopy):Void
{ {
spriteCopies.push(spriteCopy); spriteCopies.push(spriteCopy);

View file

@ -5,6 +5,9 @@ import openfl.display.BitmapData;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.FlxCamera; import flixel.FlxCamera;
/**
* Manages frame buffers and gives access to each frame buffer.
*/
class FrameBufferManager class FrameBufferManager
{ {
final camera:FlxCamera; final camera:FlxCamera;

View file

@ -1,9 +1,12 @@
package funkin.graphics.framebuffer; package funkin.graphics.framebuffer;
import flixel.util.FlxColor;
import flixel.FlxCamera; import flixel.FlxCamera;
import flixel.FlxSprite; 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 class SpriteCopy
{ {
final sprite:FlxSprite; final sprite:FlxSprite;