Skip to content

Commit 2623c68

Browse files
committed
Add sendFbo and example
1 parent 9b77204 commit 2623c68

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

examples/texture/sender.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from OpenGL.GLU import *
66
from random import Random
77
import time
8+
import argparse
89

910
TARGET_FPS = 30
1011

@@ -54,6 +55,11 @@ def Cube():
5455
glEnd()
5556

5657

58+
parser = argparse.ArgumentParser()
59+
parser.add_argument('--use-send-fbo', dest='useSendFbo',
60+
action='store_true')
61+
args = parser.parse_args()
62+
5763
pygame.init()
5864
pygame.display.set_caption('Texture Sender Example')
5965
pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT),
@@ -70,8 +76,8 @@ def Cube():
7076
SEND_WIDTH, SEND_HEIGHT, 0)
7177

7278
# Create framebuffer and attach texture
73-
fbo = glGenFramebuffers(1)
74-
glBindFramebuffer(GL_FRAMEBUFFER, fbo)
79+
fboID = glGenFramebuffers(1)
80+
glBindFramebuffer(GL_FRAMEBUFFER, fboID)
7581
glFramebufferTexture2D(
7682
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sendTextureID, 0)
7783

@@ -99,11 +105,16 @@ def Cube():
99105

100106
# Copy on-screen framebuffer to our fbo
101107
glBlitNamedFramebuffer(
102-
0, fbo, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, 0, SEND_WIDTH, SEND_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST)
108+
0, fboID, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, 0, SEND_WIDTH, SEND_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST)
103109

104110
# Send the texture
105-
result = sender.sendTexture(
106-
sendTextureID, GL_TEXTURE_2D, SEND_WIDTH, SEND_HEIGHT, True, 0)
111+
if args.useSendFbo:
112+
glBindFramebuffer(GL_FRAMEBUFFER, fboID)
113+
result = sender.sendFbo(fboID, SEND_WIDTH, SEND_HEIGHT, True)
114+
glBindFramebuffer(GL_FRAMEBUFFER, 0)
115+
else:
116+
result = sender.sendTexture(
117+
sendTextureID, GL_TEXTURE_2D, SEND_WIDTH, SEND_HEIGHT, True, 0)
107118

108119
# Indicate that a frame is ready to read
109120
sender.setFrameSync(SENDER_NAME)

src/PySpoutGL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ PYBIND11_MODULE(_spoutgl, m) {
9797
.def("setSenderName", &SpoutSender::SetSenderName)
9898
.def("releaseSender", &SpoutSender::ReleaseSender)
9999
.def("sendTexture", &SpoutSender::SendTexture)
100+
.def("sendFbo", &SpoutSender::SendFbo)
100101
.def("sendImage", [](SpoutSender& sender, const py::buffer pixelBuffer, int height, int width, GLenum glFormat, bool invert, GLuint hostFbo) {
101102
py::buffer_info bufferInfo = pixelBuffer.request();
102103
if (bufferInfo.size * bufferInfo.itemsize < width * height * getBytesPerPixel(glFormat)) {

0 commit comments

Comments
 (0)