Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)attachBufferToTexture:(uint8_t*)buffer inContext:(CGLContextObj)context{
- CGLSetCurrentContext(context);
- if (buffer != nil) {
- if (_usePBO == YES) {
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, _pbo[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, movieWidth * movieHeight * [_pixelType byteCount], 0, GL_STREAM_DRAW_ARB);
- GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if (ptr) {
- GLubyte * data = (GLubyte *)buffer;
- memcpy(ptr, data, movieWidth * movieHeight * [_pixelType byteCount]);
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
- }
- glBindTexture(GL_TEXTURE_2D, _surfaceTexture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // copy pixels from PBO to texture object && Use offset instead of pointer see the (zero) !!!!!!
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, movieWidth, movieHeight, [_pixelType format], [_pixelType type], 0);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
- glDisable(GL_TEXTURE_RECTANGLE_ARB);
- } else {
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _surfaceTexture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- GLubyte * data = (GLubyte *)buffer;
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, [_pixelType internalFormat], movieWidth, movieHeight, 0, [_pixelType format], [_pixelType type], data);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
- glDisable(GL_TEXTURE_RECTANGLE_ARB);
- }
- }
- }
Add Comment
Please, Sign In to add comment