Vuo  2.3.2
VuoSyphonSender.m
Go to the documentation of this file.
1 
10 #import "VuoSyphonSender.h"
11 #include "VuoImageRenderer.h"
12 #include <OpenGL/OpenGL.h>
13 #include <OpenGL/CGLMacro.h>
14 #include "VuoGlContext.h"
15 #include "module.h"
16 #include "node.h"
17 
18 #ifdef VUO_COMPILER
20  "title" : "VuoSyphonSender",
21  "dependencies" : [
22  "AppKit.framework",
23  "VuoGlContext"
24  ]
25  });
26 #endif
27 
28 @implementation VuoSyphonSender
29 
30 @synthesize syphonServer;
31 
37 - (void) initServerWithName:(NSString*)name
38 {
39  VUOLOG_PROFILE_BEGIN(mainQueue);
40  dispatch_sync(dispatch_get_main_queue(), ^{
41  VUOLOG_PROFILE_END(mainQueue);
42  VuoGlContext_perform(^(CGLContextObj cgl_ctx){
43  syphonServer = [[SyphonServer alloc] initWithName:name context:cgl_ctx options:nil];
44  });
45  });
46 }
47 
51 - (void) publishFrame:(VuoImage)image
52 {
53  if ([syphonServer hasClients] && image)
54  {
55  if (image->pixelsWide < 1 || image->pixelsHigh < 1)
56  return;
57 
58  VuoGlContext_perform(^(CGLContextObj cgl_ctx){
59  VuoShader_resetContext(cgl_ctx);
60 
61  // Syphon draws its triangles backwards, so we have to temporarily turn off backface culling.
62  glDisable(GL_CULL_FACE);
63 
64  [syphonServer publishFrameTexture:image->glTextureName
65  textureTarget:GL_TEXTURE_2D
66  imageRegion:NSMakeRect(0, 0, image->pixelsWide, image->pixelsHigh)
67  textureDimensions:NSMakeSize(image->pixelsWide, image->pixelsHigh)
68  flipped:NO];
69 
70  glEnable(GL_CULL_FACE);
71  });
72  }
73 }
74 
78 - (void) setName:(NSString*)newName
79 {
80  VUOLOG_PROFILE_BEGIN(mainQueue);
81  dispatch_sync(dispatch_get_main_queue(), ^{
82  VUOLOG_PROFILE_END(mainQueue);
83  syphonServer.name = newName;
84  });
85 }
86 
90 - (void) stop
91 {
92  VUOLOG_PROFILE_BEGIN(mainQueue);
93  dispatch_sync(dispatch_get_main_queue(), ^{
94  VUOLOG_PROFILE_END(mainQueue);
95  [syphonServer stop];
96  [syphonServer release];
97  });
98 }
99 
100 @end