-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Work in progress] [macOS] Syphon output #63
Changes from all commits
c5e5041
fc9cfb7
e835e4c
e3b6c35
3a2fef2
001909a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ add_executable(projectMSDL WIN32 | |
RenderLoop.h | ||
SDLRenderingWindow.h | ||
SDLRenderingWindow.cpp | ||
TextureSharing.h | ||
TextureSharing.mm | ||
) | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
|
@@ -46,12 +48,20 @@ target_compile_definitions(projectMSDL | |
PROJECTMSDL_VERSION="${PROJECT_VERSION}" | ||
) | ||
|
||
if(APPLE) | ||
include(fetch_syphon.cmake) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ObjC++") | ||
find_library(SYPHON Syphon ${PROJECT_SOURCE_DIR}) | ||
target_link_libraries(projectMSDL PRIVATE ${SYPHON}) | ||
endif() | ||
|
||
target_link_libraries(projectMSDL | ||
PRIVATE | ||
libprojectM::playlist | ||
Poco::Util | ||
SDL2::SDL2$<$<STREQUAL:${SDL2_LINKAGE},static>:-static> | ||
SDL2::SDL2main | ||
glad | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is glad required for all platforms, even macOS, when not building Syphon support? I'd suggest making All the Syphon-specific code, libraries etc. dependent on a specific Also, use |
||
) | ||
|
||
if(MSVC) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,10 @@ void ProjectMSDLApplication::defineOptions(Poco::Util::OptionSet& options) | |
false, "<number>", true) | ||
.binding("projectM.beatSensitivity", _commandLineOverrides)); | ||
|
||
options.addOption(Option("textureSharingEnabled", "", "Syphon texture sharing enabled.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - only provide the command-line option in builds which actually have Syphon support built-in. for any other build, it would confuse users. |
||
false, "<0/1>", true) | ||
.binding("projectM.textureSharingEnabled", _commandLineOverrides)); | ||
|
||
} | ||
|
||
int ProjectMSDLApplication::main(POCO_UNUSED const std::vector<std::string>& args) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <SDL2/SDL.h> | ||
|
||
#include <Poco/Logger.h> | ||
|
||
#include <glad/glad.h> | ||
|
||
#include <Syphon/Syphon.h> | ||
/** | ||
* @brief Class to help with texture sharing to other apps via Syphon/Spout. | ||
*/ | ||
class TextureSharing | ||
{ | ||
public: | ||
/** | ||
* @brief Performs initialization of texture sharing. | ||
*/ | ||
void initialize(int width, int height); | ||
|
||
/** | ||
* @brief Publishes current texture. | ||
*/ | ||
void publish(); | ||
|
||
protected: | ||
void createFramebuffer(int width, int height); | ||
|
||
Poco::Logger& _logger{Poco::Logger::get("TextureSharing")}; //!< The class logger. | ||
|
||
GLuint _shareFramebuffer, _shareTexture; | ||
int _width, _height; | ||
|
||
SyphonOpenGLServer* _syphonServer = NULL; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "TextureSharing.h" | ||
|
||
#include <Poco/Util/Application.h> | ||
|
||
void TextureSharing::createFramebuffer(int width, int height) | ||
{ | ||
glGenFramebuffers(1, &_shareFramebuffer); | ||
glBindFramebuffer(GL_FRAMEBUFFER, _shareFramebuffer); | ||
|
||
glGenTextures(1, &_shareTexture); | ||
glBindTexture(GL_TEXTURE_2D, _shareTexture); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
|
||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _shareTexture, 0); | ||
|
||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | ||
{ | ||
poco_error_f1(_logger, "Failed to initialize texture sharing framebuffer: %s", std::string(SDL_GetError())); | ||
return; | ||
} | ||
|
||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
} | ||
|
||
void TextureSharing::initialize(int width, int height) | ||
{ | ||
// Syphon setup | ||
CGLContextObj cgl_ctx = CGLGetCurrentContext(); | ||
_syphonServer = [[SyphonOpenGLServer alloc] initWithName:nil context:cgl_ctx options:nil]; | ||
|
||
_width = width; | ||
_height = height; | ||
|
||
createFramebuffer(_width, _height); | ||
} | ||
|
||
void TextureSharing::publish() | ||
{ | ||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | ||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _shareFramebuffer); | ||
|
||
glBlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height, GL_COLOR_BUFFER_BIT, GL_LINEAR); | ||
|
||
[_syphonServer publishFrameTexture:_shareTexture textureTarget:GL_TEXTURE_2D imageRegion:NSMakeRect(0, 0, _width, _height) textureDimensions:NSMakeSize(_width, _height) flipped:NO]; | ||
|
||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# Download Syphon framework | ||
file(DOWNLOAD | ||
https://github.com/Syphon/Syphon-Framework/releases/download/5/Syphon.SDK.5.zip | ||
Syphon.zip | ||
EXPECTED_HASH SHA256=8a8993da2d39f84b7fbd9ad0071a8f300e947635a52c6c5a521c88df5ccb882f | ||
TLS_VERIFY true | ||
) | ||
|
||
file(ARCHIVE_EXTRACT | ||
INPUT Syphon.zip | ||
DESTINATION . | ||
PATTERNS "Syphon SDK 5/Syphon.framework/" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
project(Glad) | ||
|
||
add_library(glad include/glad/glad.h src/glad.c) | ||
target_include_directories(glad PUBLIC include/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check that this still compiles on Windows and Linux, as those OSes don't have Obj-C++ support?
Because on my Linux machine, I get an error configuring the project: