Comments (2)
Due to how Apple's IOSurface/OpenGL intergration works, calls to glGetTexImage()
won't work - if you need access to the pixel data, draw the texture to an FBO and then download from the FBO's colour attachment (ideally into a PBO so you can defer the download).
Obviously drawing to the window via this method is a terrible idea (just draw the original texture directly) - but presumably this is just an example and you plan to do further processing via OpenCV.
from syphon-framework.
Ah, I see. Thanks for the feedback. For future reference, rendering to a frame buffer did address the issue. This was the client callback block that solved my issue based on your suggestion. Indeed the goal is to process the frame, rendering with OpenCV is just a sanity check.
SyphonOpenGLImage *frame = [client newFrameImage];
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, frame.textureName, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
std::cout << "frame buffer error " << status << std::endl;
}
glBindTexture(GL_TEXTURE_RECTANGLE, frame.textureName);
int width, height;
glGetTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &height);
uint8_t* pixelBuffer = new uint8_t[width * height * 4];
std::memset(pixelBuffer, 0, width * height * 4);
glViewport(0, 0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_RECTANGLE);
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_RECTANGLE, frame.textureName);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
glTexCoord2f(width, 0.0f); glVertex2f(1.0f, -1.0f);
glTexCoord2f(width, height); glVertex2f(1.0f, 1.0f);
glTexCoord2f(0.0f, height); glVertex2f(-1.0f, 1.0f);
glEnd();
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer);
glBindTexture(GL_TEXTURE_RECTANGLE, 0);
glDeleteFramebuffers(1, &fbo);
torch::Tensor tensor = torch::from_blob(pixelBuffer, {height, width, 4}, torch::kUInt8).flip(0).slice(2, 0, 3, 1).contiguous();
cv::imshow(serverName, tensor2mat(tensor));
char c = (char) cv::waitKey(10);
delete[] pixelBuffer;
[frame release];
from syphon-framework.
Related Issues (20)
- Documentation or simple send&receive example in swift ? HOT 8
- Crashes in Clients when Servers exit without using stop HOT 6
- CFRunLoop required (?) HOT 1
- IOSurface Syphon HOT 3
- UnrealEngine 5.1 HOT 1
- Adobe Character Animator just took off Syphon!!! Please make all efforts to be on Character Animator again! HOT 12
- Syphon for Blender issue HOT 7
- Frame Meta Data HOT 1
- Use ARC HOT 1
- Per-API framework builds HOT 1
- Use a single SyphonServerRendererMetal per MTLDevice
- Possibly allow the host to avoid server Metal pipeline state if they will always blit
- Metal drawFrame: API
- Remove support for custom class names
- Update Xcode project to use the built-in DocC for documentation
- hasNewFrame not working properly HOT 1
- Static library export HOT 8
- Available documentation without building ? HOT 3
- SyphonServerDirectory sharedDirectory servers is always empty HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syphon-framework.