-
Notifications
You must be signed in to change notification settings - Fork 14
/
SpoutServer.py
59 lines (39 loc) · 1.7 KB
/
SpoutServer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging
from argparse import ArgumentParser, Namespace
from typing import Optional
import SpoutGL
import bgl
import gpu
from gpu_extras.presets import draw_texture_2d
from ..FrameBufferSharingServer import FrameBufferSharingServer
class SpoutServer(FrameBufferSharingServer):
def __init__(self, name: str = "SpoutServer"):
super().__init__(name)
self.ctx: Optional[SpoutGL.SpoutSender] = None
def setup(self):
# setup spout
self.ctx = SpoutGL.SpoutSender()
self.ctx.setSenderName(self.name)
def draw_texture(self, offscreen: gpu.types.GPUOffScreen, rect_pos: tuple[int, int], width: int, height: int):
draw_texture_2d(offscreen.color_texture, rect_pos, width, height)
def send_texture(self, offscreen: gpu.types.GPUOffScreen, width: int, height: int, is_flipped: bool = False):
texture = offscreen.color_texture
success = self.ctx.sendTexture(texture, bgl.GL_TEXTURE_2D, width, height, is_flipped, 0)
if not success:
logging.warning("Could not send spout texture.")
return
self.ctx.setFrameSync(self.name)
def can_memory_buffer(self):
return True
def create_memory_buffer(self, texture_name: str, size: int):
success = self.ctx.createMemoryBuffer(texture_name, size)
if not success:
logging.warning("Could not create memory buffer.")
return
def write_memory_buffer(self, texture_name: str, buffer):
success = self.ctx.writeMemoryBuffer(texture_name, buffer, len(buffer))
if not success:
logging.warning("Could not write memory buffer.")
return
def release(self):
self.ctx.releaseSender()