bool FrameBuffer::post(HandleType p_colorbuffer, bool needLock) { if (needLock) m_lock.lock(); bool ret = false; ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); if (c != m_colorbuffers.end()) { m_lastPostedColorBuffer = p_colorbuffer; if (!m_subWin) { // no subwindow created for the FB output // cannot post the colorbuffer if (needLock) m_lock.unlock(); return ret; } // bind the subwindow eglSurface if (!bindSubwin_locked()) { ERR("FrameBuffer::post eglMakeCurrent failed\n"); if (needLock) m_lock.unlock(); return false; } // // render the color buffer to the window // s_gl.glPushMatrix(); s_gl.glRotatef(m_zRot, 0.0f, 0.0f, 1.0f); if (m_zRot != 0.0f) { s_gl.glClear(GL_COLOR_BUFFER_BIT); } ret = (*c).second.cb->post(); s_gl.glPopMatrix(); if (ret) { // // output FPS statistics // if (m_fpsStats) { long long currTime = GetCurrentTimeMS(); m_statsNumFrames++; if (currTime - m_statsStartTime >= 1000) { float dt = (float)(currTime - m_statsStartTime) / 1000.0f; printf("FPS: %5.3f\n", (float)m_statsNumFrames / dt); m_statsStartTime = currTime; m_statsNumFrames = 0; } } s_egl.eglSwapBuffers(m_eglDisplay, m_eglSurface); } // restore previous binding unbind_locked(); // // Send framebuffer (without FPS overlay) to callback // if (m_onPost) { (*c).second.cb->readback(m_fbImage); m_onPost(m_onPostContext, m_width, m_height, -1, GL_RGBA, GL_UNSIGNED_BYTE, m_fbImage); } } if (needLock) m_lock.unlock(); return ret; }
bool FrameBuffer::post(HandleType p_colorbuffer, bool needLock) { if (needLock) { m_lock.lock(); } bool ret = false; ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); if (c == m_colorbuffers.end()) { goto EXIT; } m_lastPostedColorBuffer = p_colorbuffer; if (m_subWin) { // bind the subwindow eglSurface if (!bindSubwin_locked()) { ERR("FrameBuffer::post(): eglMakeCurrent failed\n"); goto EXIT; } // // render the color buffer to the window // if (m_zRot != 0.0f) { s_gles2.glClear(GL_COLOR_BUFFER_BIT); } ret = (*c).second.cb->post(m_zRot); if (ret) { s_egl.eglSwapBuffers(m_eglDisplay, m_eglSurface); } // restore previous binding unbind_locked(); } else { // If there is no sub-window, don't display anything, the client will // rely on m_onPost to get the pixels instead. ret = true; } // // output FPS statistics // if (m_fpsStats) { long long currTime = GetCurrentTimeMS(); m_statsNumFrames++; if (currTime - m_statsStartTime >= 1000) { float dt = (float)(currTime - m_statsStartTime) / 1000.0f; printf("FPS: %5.3f\n", (float)m_statsNumFrames / dt); m_statsStartTime = currTime; m_statsNumFrames = 0; } } // // Send framebuffer (without FPS overlay) to callback // if (m_onPost) { (*c).second.cb->readback(m_fbImage); m_onPost(m_onPostContext, m_width, m_height, -1, GL_RGBA, GL_UNSIGNED_BYTE, m_fbImage); } EXIT: if (needLock) { m_lock.unlock(); } return ret; }