urtree.blogg.se

Mac for rendering video
Mac for rendering video








mac for rendering video
  1. MAC FOR RENDERING VIDEO UPDATE
  2. MAC FOR RENDERING VIDEO CODE

GlEnableVertexAttribArray(m_attributeTexCoord)

mac for rendering video

GlVertexAttribPointer(m_attributePos, 4, GL_FLOAT, GL_FALSE, 0, 0) GlEnableVertexAttribArray(m_attributePos) GlUseProgram(m_yuv2rgbShader->GetProgram()) GlBindTexture(GL_TEXTURE_RECTANGLE_ARB, texID_V)

mac for rendering video

GlBindTexture(GL_TEXTURE_RECTANGLE_ARB, texID_U) GlBindTexture(GL_TEXTURE_RECTANGLE_ARB, texID_Y) GlScalef( (GLfloat)m_surfaceWidth, (GLfloat)m_surfaceHeight, 1.0f ) GlViewport(0,0,m_surfaceWidth,m_surfaceHeight) GlPushAttrib(GL_VIEWPORT_BIT) // need to set viewport all the time? GlBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer) īefore doing that rendering to the screen of the current frame (as the usual framerate is about 24 fps for videos, this frame might be rendered a few times before the next videoframe gets rendered - that's why I use this approach) I call the video decoder class to check if a new frame is available (ie it is responsible for syncing to the timeline and updating the backbuffer with a new frame), if a frame is available, then I am rendering to the backbuffer texture from inside the videodecoder class (this happens on the same thread as the main rendering thread): glBindFramebuffer(GL_FRAMEBUFFER, backbufferFBOHandle)

mac for rendering video

GlBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer) GlEnableClientState( GL_TEXTURE_COORD_ARRAY ) GlPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ) GlTe圎nvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) GlBindTexture(GL_TEXTURE_RECTANGLE_ARB, frontTexHandle) In the main rendering loop it then checks which one is the front buffer, and then renders this front buffer to the screen using texture unit 0: glActiveTexture(GL_TEXTURE0) That main rendering thread has two framebuffers, and associated to them via glFramebufferTexture2D two textures, in order to implement some kind of double buffering. The main rendering thread meanwhile (after ensuring correct state, etc) then accesses this queue (that queue class has its access internally protected by a mutex) and renders the top frame. Once the minimum queue size is reached, the main application is notified that it can start to render the video. Once this is done I put the textures that I used are marked as being used and a VideoFrame class is filled with their info (ie the texture number, and which area in the buffer they occupy etc) and put into a queue to be rendered. (As a side question: I am not sure if for each of the textures I should use a different texture unit? ) GlTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, Memcpy( planeInfo->m_buffer, srcData, planeInfo->m_planeSize ) GlPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE) GlTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE) GlBindTexture(GL_TEXTURE_RECTANGLE_ARB, planeInfo->m_texHandle)

MAC FOR RENDERING VIDEO UPDATE

When I receive a newly decoded video frame I find a set of free YUV surfaces and update the three components each with this code: glActiveTexture(m_textureUnits) I created a pool of those YUV textures (depending on the size of the video it typically ranges between 3 and 8 surfaces (times three as it is Y, U and V components) - each of the textures mapped into its own area of the above m_mappedMem. Instead of uploading BGRA textures (which weigh in at about 8MB per frame for 1920x1080) I upload three individual textures for Y, U and V (each being GL_LUMINANCE, GL_UNSIGNED_BYTE, and the Y texture of original size, and the U and V at half the dimensions), thereby reducing the size being uploaded to about 3 MB, which already showed some improvement.

MAC FOR RENDERING VIDEO CODE

In order to improve that I implemented a different kind of pool class which has its own GL context (NSOpenGLContext as I am on Mac), which shares the resources with the main context.įurthermore I changed the code so that it uses glTextureRangeAPPLE( GL_TEXTURE_RECTANGLE_ARB, m_mappedMemSize, m_mappedMem ) Īnd glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE) įor the textures that I use, in order to improve the performance of uploading to VRAM. The thread that decodes the video originally just wrote the resulting frames as BGRA into a RAM buffer, which got uploaded to VRAM by glTexSubImage2D which worked fine enough for normal videos, but -as expected- got slow for HD (esp 1920x1080). I have a video player application, and use multiple threads in order to keep the user interaction still smooth.










Mac for rendering video