{"action":"created","issue":{"url":"https://api.github.com/repos/bkaradzic/bgfx/issues/802","repository_url":"https://api.github.com/repos/bkaradzic/bgfx","labels_url":"https://api.github.com/repos/bkaradzic/bgfx/issues/802/labels{/name}","comments_url":"https://api.github.com/repos/bkaradzic/bgfx/issues/802/comments","events_url":"https://api.github.com/repos/bkaradzic/bgfx/issues/802/events","html_url":"https://github.com/bkaradzic/bgfx/issues/802","id":157764358,"number":802,"title":"RTT and readPixel sync","user":{"login":"hcomere","id":15142649,"avatar_url":"https://avatars.githubusercontent.com/u/15142649?v=3","gravatar_id":"","url":"https://api.github.com/users/hcomere","html_url":"https://github.com/hcomere","followers_url":"https://api.github.com/users/hcomere/followers","following_url":"https://api.github.com/users/hcomere/following{/other_user}","gists_url":"https://api.github.com/users/hcomere/gists{/gist_id}","starred_url":"https://api.github.com/users/hcomere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hcomere/subscriptions","organizations_url":"https://api.github.com/users/hcomere/orgs","repos_url":"https://api.github.com/users/hcomere/repos","events_url":"https://api.github.com/users/hcomere/events{/privacy}","received_events_url":"https://api.github.com/users/hcomere/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-05-31T20:36:25Z","updated_at":"2016-06-04T15:50:41Z","closed_at":null,"body":"Hi,\r\n\r\nI am trying to perform a render in a texture and then reading back texture pixels. The RTT part seems OK but i suspect a synchronization issue.\r\nI probably do anything wrong but i do not find anything clear about it in doc or examples.\r\n\r\nI first create a texture :\r\n\r\n```\r\nm_textureHandle =\tbgfx::createTexture2D(a_width, a_height, a_mipmapCount, format, flags, NULL);\r\n```\r\n\r\n1) What flags are needed for RTT and ReadPixel ? I see flags like BGFX_TEXTURE_RT and BGFX_TEXTURE_READ_BACK but i did not find their documentation.\r\n\r\nThen i create a FBO : \r\n\r\n```\r\nbgfx::TextureHandle textureHandles[1];\r\ntextureHandles[0].idx = m_textureHandle;\r\n\r\nm_FBOHandle = bgfx::createFrameBuffer(1, textureHandles, false);\r\n```\r\n\r\n2) Does this allocation on the stack of textureHandles array work or do i need to allocate it on the heap ?\r\n\r\nThen i render anything in my FBO\r\n\r\n```\r\nbgfx::setViewFrameBuffer(m_viewUId, m_FBOHandle);\r\n// some other view config and submits on m_viewUId\r\nbgfx::frame();\r\n```\r\n\r\nAnd finally, i read back texture pixels.\r\n\r\n```\r\n// Allocation of std::uint8_t * pixelBuffer with good size\r\nbgfx::readTexture(m_textureHandle, pixelBuffer);\r\n// Stuff to write on disk .png image \r\n```\r\n\r\nI obtain images on disk partially filled, or a crash.\r\n\r\n3) Does the readTexture() call is executed after the end of the render and is it blocking ?\r\n\r\nA hint would be welcome :)\r\nThanks,\r\n\r\nHarold"},"comment":{"url":"https://api.github.com/repos/bkaradzic/bgfx/issues/comments/223762775","html_url":"https://github.com/bkaradzic/bgfx/issues/802#issuecomment-223762775","issue_url":"https://api.github.com/repos/bkaradzic/bgfx/issues/802","id":223762775,"user":{"login":"bkaradzic","id":814772,"avatar_url":"https://avatars.githubusercontent.com/u/814772?v=3","gravatar_id":"","url":"https://api.github.com/users/bkaradzic","html_url":"https://github.com/bkaradzic","followers_url":"https://api.github.com/users/bkaradzic/followers","following_url":"https://api.github.com/users/bkaradzic/following{/other_user}","gists_url":"https://api.github.com/users/bkaradzic/gists{/gist_id}","starred_url":"https://api.github.com/users/bkaradzic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bkaradzic/subscriptions","organizations_url":"https://api.github.com/users/bkaradzic/orgs","repos_url":"https://api.github.com/users/bkaradzic/repos","events_url":"https://api.github.com/users/bkaradzic/events{/privacy}","received_events_url":"https://api.github.com/users/bkaradzic/received_events","type":"User","site_admin":false},"created_at":"2016-06-04T15:50:41Z","updated_at":"2016-06-04T15:50:41Z","body":"Frame number is intended for this use: https://bkaradzic.github.io/bgfx/bgfx.html#_CPPv2N4bgfx5frameEb\r\n\r\nIt's equivalent of callback you're talking about. You can implement callback when current frame reaches texture read frame + 2."}}
{"actor":{"display_login":"bkaradzic"}}