-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat+refactor!!: add Spout broadcasting support.
i am not 100% satisfied with this, but for now it can work. you can now toggle the spout broadcasting option, and the stage will be broadcasted both from the editor and from the proper stage viewer. this preserves transparency and allows for using the output of vtubetiny in many applications, without having to resort to window capture and chroma keying. this is only a x64 windows thing, so on other platforms enabling spout will just do nothing. i don't like the fact that i had to add a fullscreen blitting thing to the rendering context abstraction, but we need to draw the stage to the screen when we're in the stage viewer. maybe i'll revisit it later.
- Loading branch information
1 parent
eca4bbc
commit a1d20a7
Showing
9 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Raylib_cs; | ||
using Spout.NET; | ||
|
||
namespace VTTiny.Rendering | ||
{ | ||
#if ARCH_WINDOWS | ||
/// <summary> | ||
/// A framebuffer context that also sends the render texture after drawing to Spout. | ||
/// </summary> | ||
internal class SpoutFramebufferRenderingContext : FramebufferRenderingContext | ||
{ | ||
/// <summary> | ||
/// The sender name for Spout. | ||
/// </summary> | ||
private const string SPOUT_SENDER_NAME = "VTubeTiny"; | ||
|
||
/// <summary> | ||
/// The Texture2D constant for OpenGL. | ||
/// </summary> | ||
private const uint GL_TEXTURE_2D = 3553u; | ||
|
||
/// <summary> | ||
/// The Spout sender. | ||
/// </summary> | ||
private SpoutSender _sender; | ||
|
||
/// <summary> | ||
/// Constructs a new spout framebuffer rendering context and sets up the spout sender. | ||
/// </summary> | ||
public SpoutFramebufferRenderingContext() | ||
: base() | ||
{ | ||
_sender = new SpoutSender(); | ||
_sender.CreateSender(SPOUT_SENDER_NAME, (uint)_renderTexture.texture.width, (uint)_renderTexture.texture.height, 0); | ||
} | ||
|
||
public override void Begin(Color _) | ||
{ | ||
Raylib.BeginTextureMode(_renderTexture); | ||
|
||
// We clear the stage with a blank color for transparency. | ||
Raylib.ClearBackground(Color.BLANK); | ||
} | ||
|
||
public override void End() | ||
{ | ||
base.End(); | ||
|
||
// Send the data straight to Spout. | ||
_sender.SendTexture(_renderTexture.texture.id, GL_TEXTURE_2D, (uint)_renderTexture.texture.width, (uint)_renderTexture.texture.height, true, 0); | ||
} | ||
|
||
public override void Resize(Vector2Int dimensions) | ||
{ | ||
base.Resize(dimensions); | ||
|
||
// Resize the sender as well. | ||
_sender.UpdateSender(SPOUT_SENDER_NAME, (uint)dimensions.X, (uint)dimensions.Y); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
|
||
if (disposing && | ||
_sender != null) | ||
{ | ||
_sender.ReleaseSender(0); | ||
_sender.Dispose(); | ||
|
||
_sender = null; | ||
} | ||
} | ||
} | ||
#else | ||
/// <summary> | ||
/// Mock framebuffer context for non-Windows platforms. (Spout is not supported on non-windows architectures) | ||
/// </summary> | ||
|
||
internal class SpoutFramebufferRenderingContext : FramebufferRenderingContext | ||
{ | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters