diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 3b6d34bca..3f1619ca0 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -444,28 +444,28 @@ class ExampleHDR : public entry::AppI // Downscale luminance 0. setOffsets4x4Lum(u_offset, 128, 128); - bgfx::setTexture(0, s_texColor, m_lum[0]); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_lum[0]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(64.0f, 64.0f, m_caps->originBottomLeft); bgfx::submit(3, m_lumAvgProgram); // Downscale luminance 1. setOffsets4x4Lum(u_offset, 64, 64); - bgfx::setTexture(0, s_texColor, m_lum[1]); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_lum[1]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(16.0f, 16.0f, m_caps->originBottomLeft); bgfx::submit(4, m_lumAvgProgram); // Downscale luminance 2. setOffsets4x4Lum(u_offset, 16, 16); - bgfx::setTexture(0, s_texColor, m_lum[2]); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_lum[2]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(4.0f, 4.0f, m_caps->originBottomLeft); bgfx::submit(5, m_lumAvgProgram); // Downscale luminance 3. setOffsets4x4Lum(u_offset, 4, 4); - bgfx::setTexture(0, s_texColor, m_lum[3]); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_lum[3]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(1.0f, 1.0f, m_caps->originBottomLeft); bgfx::submit(6, m_lumAvgProgram); @@ -476,28 +476,28 @@ class ExampleHDR : public entry::AppI // m_bright pass m_threshold is tonemap[3]. setOffsets4x4Lum(u_offset, m_width/2, m_height/2); bgfx::setTexture(0, s_texColor, m_fbtextures[0]); - bgfx::setTexture(1, s_texLum, m_lum[4]); + bgfx::setTexture(1, s_texLum, bgfx::getTexture(m_lum[4]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad( (float)m_width/2.0f, (float)m_height/2.0f, m_caps->originBottomLeft); bgfx::submit(7, m_brightProgram); // m_blur m_bright pass vertically. - bgfx::setTexture(0, s_texColor, m_bright); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_bright) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad( (float)m_width/8.0f, (float)m_height/8.0f, m_caps->originBottomLeft); bgfx::submit(8, m_blurProgram); // m_blur m_bright pass horizontally, do tonemaping and combine. bgfx::setTexture(0, s_texColor, m_fbtextures[0]); - bgfx::setTexture(1, s_texLum, m_lum[4]); - bgfx::setTexture(2, s_texBlur, m_blur); + bgfx::setTexture(1, s_texLum, bgfx::getTexture(m_lum[4]) ); + bgfx::setTexture(2, s_texBlur, bgfx::getTexture(m_blur) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad( (float)m_width, (float)m_height, m_caps->originBottomLeft); bgfx::submit(9, m_tonemapProgram); if (bgfx::isValid(m_rb) ) { - bgfx::blit(9, m_rb, 0, 0, m_lum[4]); + bgfx::blit(9, m_rb, 0, 0, bgfx::getTexture(m_lum[4]) ); bgfx::readTexture(m_rb, &m_lumBgra8); } diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index 588061212..83e01eb79 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -1176,7 +1176,7 @@ struct Model { bgfx::setTexture(0, s_texColor, m_texture); } - bgfx::setTexture(1, s_texStencil, s_stencilFb); + bgfx::setTexture(1, s_texStencil, bgfx::getTexture(s_stencilFb) ); // Apply render state ::setRenderState(_renderState); diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 47855786f..9071f0081 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1013,7 +1013,7 @@ struct Mesh { for (uint8_t ii = 0; ii < ShadowMapRenderTargets::Count; ++ii) { - bgfx::setTexture(4 + ii, s_shadowMap[ii], s_rtShadowMap[ii]); + bgfx::setTexture(4 + ii, s_shadowMap[ii], bgfx::getTexture(s_rtShadowMap[ii]) ); } } @@ -2816,12 +2816,12 @@ int _main_(int _argc, char** _argv) if (bVsmOrEsm && currentSmSettings->m_doBlur) { - bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[0]); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtShadowMap[0]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_VBLUR_0_ID, s_programs.m_vBlur[depthType]); - bgfx::setTexture(4, s_shadowMap[0], s_rtBlur); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtBlur) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_HBLUR_0_ID, s_programs.m_hBlur[depthType]); @@ -2832,12 +2832,12 @@ int _main_(int _argc, char** _argv) { const uint8_t viewId = RENDERVIEW_VBLUR_0_ID + jj; - bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[ii]); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtShadowMap[ii]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(viewId, s_programs.m_vBlur[depthType]); - bgfx::setTexture(4, s_shadowMap[0], s_rtBlur); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtBlur) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(viewId+1, s_programs.m_hBlur[depthType]); @@ -3072,7 +3072,7 @@ int _main_(int _argc, char** _argv) // Draw depth rect. if (settings.m_drawDepthBuffer) { - bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[0]); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtShadowMap[0]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_DRAWDEPTH_0_ID, s_programs.m_drawDepth[depthType]); @@ -3081,7 +3081,7 @@ int _main_(int _argc, char** _argv) { for (uint8_t ii = 1; ii < settings.m_numSplits; ++ii) { - bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[ii]); + bgfx::setTexture(4, s_shadowMap[0], bgfx::getTexture(s_rtShadowMap[ii]) ); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_DRAWDEPTH_0_ID+ii, s_programs.m_drawDepth[depthType]); diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 871ba7af6..cd13449f5 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -686,8 +686,8 @@ class ExampleDeferred : public entry::AppI bgfx::setUniform(u_mtx, invMvp); const uint16_t scissorHeight = uint16_t(y1-y0); bgfx::setScissor(uint16_t(x0), m_height-scissorHeight-uint16_t(y0), uint16_t(x1-x0), scissorHeight); - bgfx::setTexture(0, s_normal, m_gbuffer, 1); - bgfx::setTexture(1, s_depth, m_gbuffer, 2); + bgfx::setTexture(0, s_normal, bgfx::getTexture(m_gbuffer, 1) ); + bgfx::setTexture(1, s_depth, bgfx::getTexture(m_gbuffer, 2) ); bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE @@ -699,8 +699,8 @@ class ExampleDeferred : public entry::AppI } // Combine color and light buffers. - bgfx::setTexture(0, s_albedo, m_gbuffer, 0); - bgfx::setTexture(1, s_light, m_lightBuffer, 0); + bgfx::setTexture(0, s_albedo, bgfx::getTexture(m_gbuffer, 0) ); + bgfx::setTexture(1, s_light, bgfx::getTexture(m_lightBuffer, 0) ); bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index 004b8c5ea..ed9866e38 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -136,7 +136,7 @@ void VectorDisplay::endFrame() bx::mtxOrtho(proj, 0.0f, (float)m_screenWidth, (float)m_screenHeight, 0.0f, 0.0f, 1000.0f); bgfx::setViewRect(m_view, 0, 0, m_screenWidth, m_screenHeight); - bgfx::setViewFrameBuffer(m_view, m_sceneFrameBuffer); //render all geometry to this framebuffer + bgfx::setViewFrameBuffer(m_view, m_sceneFrameBuffer); bgfx::setViewTransform(m_view, NULL, proj); // advance step @@ -155,7 +155,7 @@ void VectorDisplay::endFrame() int stepi = m_numberDecaySteps - loopvar - 1; int i = (m_currentDrawStep + m_numberDecaySteps - stepi) % m_numberDecaySteps; - if (m_vertexBuffersSize[i] != 0) //only draw if something is in the buffer + if (m_vertexBuffersSize[i] != 0) { float alpha; if (stepi == 0) @@ -200,14 +200,14 @@ void VectorDisplay::endFrame() if (m_brightness > 0) { - bgfx::setTexture(0, s_texColor, m_sceneFrameBuffer); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_sceneFrameBuffer) ); int npasses = (int)(m_brightness * 4); for (int pass = 0; pass < npasses; pass++) { // render the glow1 texture to the glow0 buffer with horizontal blur - bgfx::setViewFrameBuffer(viewCounter, m_glow0FrameBuffer); //first glow pass + bgfx::setViewFrameBuffer(viewCounter, m_glow0FrameBuffer); bgfx::setViewRect(viewCounter, 0, 0, m_glowWidth, m_glowHeight); bgfx::setState(0 | BGFX_STATE_RGB_WRITE @@ -224,9 +224,9 @@ void VectorDisplay::endFrame() viewCounter++; - bgfx::setViewFrameBuffer(viewCounter, m_glow1FrameBuffer); //second glow pass + bgfx::setViewFrameBuffer(viewCounter, m_glow1FrameBuffer); bgfx::setViewRect(viewCounter, 0, 0, m_glowWidth, m_glowHeight); - bgfx::setTexture(0, s_texColor, m_glow0FrameBuffer); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_glow0FrameBuffer) ); bgfx::setViewTransform(viewCounter, NULL, proj); screenSpaceQuad(m_glowWidth, m_glowHeight); @@ -248,7 +248,7 @@ void VectorDisplay::endFrame() viewCounter++; //set for next iteration - bgfx::setTexture(0, s_texColor, m_glow1FrameBuffer); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_glow1FrameBuffer) ); } } @@ -257,7 +257,7 @@ void VectorDisplay::endFrame() //now do last pass, combination of blur and normal buffer to screen bgfx::setViewTransform(viewCounter, NULL, proj); bgfx::setViewRect(viewCounter, 0, 0, m_screenWidth, m_screenHeight); - bgfx::setTexture(0, s_texColor, m_sceneFrameBuffer); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_sceneFrameBuffer) ); bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE @@ -277,7 +277,7 @@ void VectorDisplay::endFrame() // blend in the glow bgfx::setViewTransform(viewCounter, NULL, proj); bgfx::setViewRect(viewCounter, 0, 0, m_screenWidth, m_screenHeight); - bgfx::setTexture(0, s_texColor, m_glow1FrameBuffer); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_glow1FrameBuffer) ); bgfx::setState(0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE diff --git a/examples/31-rsm/reflectiveshadowmap.cpp b/examples/31-rsm/reflectiveshadowmap.cpp index c3a2e9382..07856d13d 100644 --- a/examples/31-rsm/reflectiveshadowmap.cpp +++ b/examples/31-rsm/reflectiveshadowmap.cpp @@ -515,12 +515,12 @@ public: for (uint32_t j = 0; j < MAX_SPHERE; j++) { // These are used in the fragment shader - bgfx::setTexture(0, s_normal, m_gbuffer, GBUFFER_RT_NORMAL); // Normal for lighting calculations - bgfx::setTexture(1, s_depth, m_gbuffer, GBUFFER_RT_DEPTH); // Depth to reconstruct world position + bgfx::setTexture(0, s_normal, bgfx::getTexture(m_gbuffer, GBUFFER_RT_NORMAL) ); // Normal for lighting calculations + bgfx::setTexture(1, s_depth, bgfx::getTexture(m_gbuffer, GBUFFER_RT_DEPTH) ); // Depth to reconstruct world position // Thse are used in the vert shader - bgfx::setTexture(2, s_shadowMap, m_shadowBuffer, SHADOW_RT_DEPTH); // Used to place sphere - bgfx::setTexture(3, s_rsm, m_shadowBuffer, SHADOW_RT_RSM); // Used to scale/color sphere + bgfx::setTexture(2, s_shadowMap, bgfx::getTexture(m_shadowBuffer, SHADOW_RT_DEPTH) ); // Used to place sphere + bgfx::setTexture(3, s_rsm, bgfx::getTexture(m_shadowBuffer, SHADOW_RT_RSM) ); // Used to scale/color sphere bgfx::setUniform(u_invMvp, invMvp); bgfx::setUniform(u_invMvpShadow, invMvpShadow); @@ -551,11 +551,13 @@ public: // Draw combine pass // Texture inputs for combine pass - bgfx::setTexture(0, s_normal, m_gbuffer, GBUFFER_RT_NORMAL); - bgfx::setTexture(1, s_color, m_gbuffer, GBUFFER_RT_COLOR); - bgfx::setTexture(2, s_light, m_lightBuffer, 0); - bgfx::setTexture(3, s_depth, m_gbuffer, GBUFFER_RT_DEPTH); - bgfx::setTexture(4, s_shadowMap, m_shadowBuffer, SHADOW_RT_DEPTH, BGFX_TEXTURE_COMPARE_LEQUAL); + bgfx::setTexture(0, s_normal, bgfx::getTexture(m_gbuffer, GBUFFER_RT_NORMAL) ); + bgfx::setTexture(1, s_color, bgfx::getTexture(m_gbuffer, GBUFFER_RT_COLOR) ); + bgfx::setTexture(2, s_light, bgfx::getTexture(m_lightBuffer, 0) ); + bgfx::setTexture(3, s_depth, bgfx::getTexture(m_gbuffer, GBUFFER_RT_DEPTH) ); + bgfx::setTexture(4, s_shadowMap, bgfx::getTexture(m_shadowBuffer, SHADOW_RT_DEPTH) + , BGFX_TEXTURE_COMPARE_LEQUAL + ); // Uniforms for combine pass diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 2ba1417f6..f59c87e8c 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -1838,20 +1838,6 @@ namespace bgfx /// uint32_t readTexture(TextureHandle _handle, void* _data, uint8_t _mip = 0); - /// Read back texture content. - /// - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _data Destination buffer. - /// - /// @returns Frame number when the result will be available. See: `bgfx::frame`. - /// - /// @attention Texture must be created with `BGFX_TEXTURE_READ_BACK` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_READ_BACK`. - /// @attention C99 equivalent is `bgfx_read_frame_buffer`. - /// - uint32_t readTexture(FrameBufferHandle _handle, uint8_t _attachment, void* _data); - /// Destroy texture. /// /// @param[in] _handle Texture handle. @@ -1961,6 +1947,16 @@ namespace bgfx , TextureFormat::Enum _depthFormat = TextureFormat::UnknownDepth ); + /// Obtain texture handle of frame buffer attachment. + /// + /// @param[in] _handle Frame buffer handle. + /// @param[in] _attachment Frame buffer attachment index. + /// + /// @returns Returns invalid texture handle if attachment index is not + /// correct, or frame buffer is created with native window handle. + /// + TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment = 0); + /// Destroy frame buffer. /// /// @attention C99 equivalent is `bgfx_destroy_frame_buffer`. @@ -2525,29 +2521,6 @@ namespace bgfx , uint32_t _flags = UINT32_MAX ); - /// Set texture stage for draw primitive. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _flags Texture sampling mode. Default value UINT32_MAX uses - /// texture sampling settings from the texture. - /// - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap - /// mode. - /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic - /// sampling. - /// - /// @attention C99 equivalent is `bgfx_set_texture_from_frame_buffer`. - /// - void setTexture( - uint8_t _stage - , UniformHandle _sampler - , FrameBufferHandle _handle - , uint8_t _attachment = 0 - , uint32_t _flags = UINT32_MAX - ); - /// Submit an empty primitive for rendering. Uniforms and draw state /// will be applied but no geometry will be submitted. /// @@ -2691,26 +2664,6 @@ namespace bgfx , TextureFormat::Enum _format = TextureFormat::Count ); - /// Set compute image from frame buffer texture. - /// - /// @param[in] _stage Texture unit. - /// @param[in] _sampler Program sampler. - /// @param[in] _handle Frame buffer handle. - /// @param[in] _attachment Frame buffer attachment index. - /// @param[in] _access Texture access. See `Access::Enum`. - /// @param[in] _format Texture format. See: `TextureFormat::Enum`. - /// - /// @attention C99 equivalent is `bgfx_set_image_from_frame_buffer`. - /// - void setImage( - uint8_t _stage - , UniformHandle _sampler - , FrameBufferHandle _handle - , uint8_t _attachment - , Access::Enum _access - , TextureFormat::Enum _format = TextureFormat::Count - ); - /// Dispatch compute. /// /// @param[in] _id View id. @@ -2791,36 +2744,6 @@ namespace bgfx , uint16_t _height = UINT16_MAX ); - /// Blit texture 2D region between 2D frame buffer and 2D texture. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _src Source frame buffer handle. - /// @param[in] _attachment Source frame buffer attachment index. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint16_t _dstX - , uint16_t _dstY - , FrameBufferHandle _src - , uint8_t _attachment = 0 - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - ); - /// Blit texture region between two textures. /// /// @param[in] _id View id. @@ -2864,51 +2787,6 @@ namespace bgfx , uint16_t _depth = UINT16_MAX ); - /// Blit texture region between frame buffer and texture. - /// - /// @param[in] _id View id. - /// @param[in] _dst Destination texture handle. - /// @param[in] _dstMip Destination texture mip level. - /// @param[in] _dstX Destination texture X position. - /// @param[in] _dstY Destination texture Y position. - /// @param[in] _dstZ If texture is 2D this argument should be 0. If destination texture is cube - /// this argument represent destination texture cube face. For 3D texture this argument - /// represent destination texture Z position. - /// @param[in] _src Source frame buffer handle. - /// @param[in] _attachment Source frame buffer attachment index. - /// @param[in] _srcMip Source texture mip level. - /// @param[in] _srcX Source texture X position. - /// @param[in] _srcY Source texture Y position. - /// @param[in] _srcZ If texture is 2D this argument should be 0. If source texture is cube - /// this argument represent source texture cube face. For 3D texture this argument - /// represent source texture Z position. - /// @param[in] _width Width of region. - /// @param[in] _height Height of region. - /// @param[in] _depth If texture is 3D this argument represent depth of region, otherwise is - /// unused. - /// - /// @attention Destination texture must be create with `BGFX_TEXTURE_BLIT_DST` flag. - /// @attention Availability depends on: `BGFX_CAPS_TEXTURE_BLIT`. - /// @attention C99 equivalent is `bgfx_blit`. - /// - void blit( - uint8_t _id - , TextureHandle _dst - , uint8_t _dstMip - , uint16_t _dstX - , uint16_t _dstY - , uint16_t _dstZ - , FrameBufferHandle _src - , uint8_t _attachment = 0 - , uint8_t _srcMip = 0 - , uint16_t _srcX = 0 - , uint16_t _srcY = 0 - , uint16_t _srcZ = 0 - , uint16_t _width = UINT16_MAX - , uint16_t _height = UINT16_MAX - , uint16_t _depth = UINT16_MAX - ); - /// Request screen shot. /// /// @param[in] _filePath Will be passed to `bgfx::CallbackI::screenShot` callback. diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index f42fd25c6..894e5b614 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(29) +#define BGFX_API_VERSION UINT32_C(30) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index fdf7f52d2..ef92c8e32 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -736,6 +736,9 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(u /**/ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat); +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment); + /**/ BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle); diff --git a/include/bgfx/c99/bgfxplatform.h b/include/bgfx/c99/bgfxplatform.h index 56b4d8ab7..df26b7662 100644 --- a/include/bgfx/c99/bgfxplatform.h +++ b/include/bgfx/c99/bgfxplatform.h @@ -139,12 +139,12 @@ typedef struct bgfx_interface_vtbl void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem); void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); uint32_t (*read_texture)(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip); - uint32_t (*read_frame_buffer)(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, void* _data); void (*destroy_texture)(bgfx_texture_handle_t _handle); bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags); bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags); bgfx_frame_buffer_handle_t (*create_frame_buffer_from_attachment)(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTextures); bgfx_frame_buffer_handle_t (*create_frame_buffer_from_nwh)(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat); + bgfx_texture_handle_t (*get_texture)(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment); void (*destroy_frame_buffer)(bgfx_frame_buffer_handle_t _handle); bgfx_uniform_handle_t (*create_uniform)(const char* _name, bgfx_uniform_type_t _type, uint16_t _num); void (*get_uniform_info)(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info); @@ -183,13 +183,11 @@ typedef struct bgfx_interface_vtbl void (*set_instance_data_from_vertex_buffer)(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); void (*set_instance_data_from_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); - void (*set_texture_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags); uint32_t (*touch)(uint8_t _id); uint32_t (*submit)(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState); uint32_t (*submit_occlusion_query)(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth, bool _preserveState); uint32_t (*submit_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState); void (*set_image)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); - void (*set_image_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format); void (*set_compute_index_buffer)(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); void (*set_compute_vertex_buffer)(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); void (*set_compute_dynamic_index_buffer)(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index c8312198b..fe91122dc 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -3229,14 +3229,6 @@ error: return s_ctx->readTexture(_handle, _data, _mip); } - uint32_t readTexture(FrameBufferHandle _handle, uint8_t _attachment, void* _data) - { - BGFX_CHECK_MAIN_THREAD(); - BX_CHECK(NULL != _data, "_data can't be NULL"); - BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_READ_BACK, "Texture read-back is not supported!"); - return s_ctx->readTexture(_handle, _attachment, _data); - } - FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags) { _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; @@ -3283,6 +3275,12 @@ error: return s_ctx->createFrameBuffer(_nwh, _width, _height, _depthFormat); } + TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->getTexture(_handle, _attachment); + } + void destroyFrameBuffer(FrameBufferHandle _handle) { BGFX_CHECK_MAIN_THREAD(); @@ -3605,14 +3603,6 @@ error: s_ctx->setTexture(_stage, _sampler, _handle, _flags); } - void setTexture(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, uint32_t _flags) - { - BGFX_CHECK_MAIN_THREAD(); - BX_CHECK(_stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, "Invalid stage %d (max %d).", _stage, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS); - BX_CHECK(_attachment < g_caps.limits.maxFBAttachments, "Frame buffer attachment index %d is invalid.", _attachment); - s_ctx->setTexture(_stage, _sampler, _handle, _attachment, _flags); - } - uint32_t touch(uint8_t _id) { ProgramHandle handle = BGFX_INVALID_HANDLE; @@ -3684,14 +3674,6 @@ error: s_ctx->setImage(_stage, _sampler, _handle, _mip, _access, _format); } - void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format) - { - BGFX_CHECK_MAIN_THREAD(); - BX_CHECK(_stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, "Invalid stage %d (max %d).", _stage, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS); - BX_CHECK(_attachment < g_caps.limits.maxFBAttachments, "Frame buffer attachment index %d is invalid.", _attachment); - s_ctx->setImage(_stage, _sampler, _handle, _attachment, _access, _format); - } - uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) { BGFX_CHECK_MAIN_THREAD(); @@ -3715,11 +3697,6 @@ error: blit(_id, _dst, 0, _dstX, _dstY, 0, _src, 0, _srcX, _srcY, 0, _width, _height, 0); } - void blit(uint8_t _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, FrameBufferHandle _src, uint8_t _attachment, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) - { - blit(_id, _dst, 0, _dstX, _dstY, 0, _src, _attachment, 0, _srcX, _srcY, 0, _width, _height, 0); - } - void blit(uint8_t _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) { BGFX_CHECK_MAIN_THREAD(); @@ -3727,14 +3704,6 @@ error: s_ctx->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } - void blit(uint8_t _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, FrameBufferHandle _src, uint8_t _attachment, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) - { - BGFX_CHECK_MAIN_THREAD(); - BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_BLIT, "Texture blit is not supported!"); - BX_CHECK(_attachment < g_caps.limits.maxFBAttachments, "Frame buffer attachment index %d is invalid.", _attachment); - s_ctx->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _attachment, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); - } - void saveScreenShot(const char* _filePath) { BGFX_CHECK_MAIN_THREAD(); @@ -4310,12 +4279,6 @@ BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data return bgfx::readTexture(handle.cpp, _data, _mip); } -BGFX_C_API uint32_t bgfx_read_frame_buffer(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, void* _data) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - return bgfx::readTexture(handle.cpp, _attachment, _data); -} - BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; @@ -4357,6 +4320,14 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _n return handle.c; } +BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } textureHandle; + textureHandle.cpp = bgfx::getTexture(handle.cpp, _attachment); + return textureHandle.c; +} + BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; @@ -4578,13 +4549,6 @@ BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _flags); } -BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _attachment, _flags); -} - BGFX_C_API uint32_t bgfx_touch(uint8_t _id) { return bgfx::touch(_id); @@ -4617,13 +4581,6 @@ BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, b bgfx::setImage(_stage, sampler.cpp, handle.cpp, _mip, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ); } -BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::setImage(_stage, sampler.cpp, handle.cpp, _attachment, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ); -} - BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) { union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; @@ -4679,13 +4636,6 @@ BGFX_C_API void bgfx_blit(uint8_t _id, bgfx_texture_handle_t _dst, uint8_t _dstM bgfx::blit(_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } -BGFX_C_API void bgfx_blit_frame_buffer(uint8_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_frame_buffer_handle_t _src, uint8_t _attachment, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } dst = { _dst }; - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } src = { _src }; - bgfx::blit(_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _attachment, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); -} - BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) { bgfx::saveScreenShot(_filePath); @@ -4797,12 +4747,12 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(update_texture_3d) \ BGFX_IMPORT_FUNC(update_texture_cube) \ BGFX_IMPORT_FUNC(read_texture) \ - BGFX_IMPORT_FUNC(read_frame_buffer) \ BGFX_IMPORT_FUNC(destroy_texture) \ BGFX_IMPORT_FUNC(create_frame_buffer) \ BGFX_IMPORT_FUNC(create_frame_buffer_scaled) \ BGFX_IMPORT_FUNC(create_frame_buffer_from_attachment) \ BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh) \ + BGFX_IMPORT_FUNC(get_texture) \ BGFX_IMPORT_FUNC(destroy_frame_buffer) \ BGFX_IMPORT_FUNC(create_uniform) \ BGFX_IMPORT_FUNC(get_uniform_info) \ @@ -4841,13 +4791,11 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(set_instance_data_from_vertex_buffer) \ BGFX_IMPORT_FUNC(set_instance_data_from_dynamic_vertex_buffer) \ BGFX_IMPORT_FUNC(set_texture) \ - BGFX_IMPORT_FUNC(set_texture_from_frame_buffer) \ BGFX_IMPORT_FUNC(touch) \ BGFX_IMPORT_FUNC(submit) \ BGFX_IMPORT_FUNC(submit_occlusion_query) \ BGFX_IMPORT_FUNC(submit_indirect) \ BGFX_IMPORT_FUNC(set_image) \ - BGFX_IMPORT_FUNC(set_image_from_frame_buffer) \ BGFX_IMPORT_FUNC(set_compute_index_buffer) \ BGFX_IMPORT_FUNC(set_compute_vertex_buffer) \ BGFX_IMPORT_FUNC(set_compute_dynamic_index_buffer) \ diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 070f921c5..b28519752 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -3256,17 +3256,6 @@ namespace bgfx return m_frames + 2; } - BGFX_API_FUNC(uint32_t readTexture(FrameBufferHandle _handle, uint8_t _attachment, void* _data) ) - { - const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); - - TextureHandle textureHandle = ref.un.m_th[_attachment]; - BGFX_CHECK_HANDLE("readTexture", m_textureHandle, textureHandle); - - return readTexture(textureHandle, _data,0); - } - void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) { const TextureRef& textureRef = m_textureRef[_handle.idx]; @@ -3442,6 +3431,21 @@ namespace bgfx return handle; } + BGFX_API_FUNC(TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) ) + { + BGFX_CHECK_HANDLE("getTexture", m_frameBufferHandle, _handle); + + const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; + if (!ref.m_window) + { + uint32_t attachment = bx::uint32_min(_attachment, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); + return ref.un.m_th[attachment]; + } + + TextureHandle invalid = BGFX_INVALID_HANDLE; + return invalid; + } + BGFX_API_FUNC(void destroyFrameBuffer(FrameBufferHandle _handle) ) { BGFX_CHECK_HANDLE("destroyFrameBuffer", m_frameBufferHandle, _handle); @@ -3878,21 +3882,6 @@ namespace bgfx m_submit->setTexture(_stage, _sampler, _handle, _flags); } - BGFX_API_FUNC(void setTexture(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, uint32_t _flags) ) - { - BGFX_CHECK_HANDLE_INVALID_OK("setTexture/FrameBufferHandle", m_frameBufferHandle, _handle); - TextureHandle textureHandle = BGFX_INVALID_HANDLE; - if (isValid(_handle) ) - { - const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); - textureHandle = ref.un.m_th[_attachment]; - BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment); - } - - m_submit->setTexture(_stage, _sampler, textureHandle, _flags); - } - BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth, bool _preserveState) ) { BGFX_CHECK_HANDLE_INVALID_OK("submit", m_programHandle, _program); @@ -3970,20 +3959,6 @@ namespace bgfx m_submit->setImage(_stage, _sampler, _handle, _mip, _access, _format); } - BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format) ) - { - TextureHandle textureHandle = BGFX_INVALID_HANDLE; - if (isValid(_handle) ) - { - const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); - textureHandle = ref.un.m_th[_attachment]; - BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment); - } - - setImage(_stage, _sampler, textureHandle, 0, _access, _format); - } - BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) ) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) @@ -4024,15 +3999,6 @@ namespace bgfx m_submit->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } - BGFX_API_FUNC(void blit(uint8_t _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, FrameBufferHandle _src, uint8_t _attachment, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) ) - { - const FrameBufferRef& ref = m_frameBufferRef[_src.idx]; - BX_CHECK(!ref.m_window, "Can't sample window frame buffer."); - TextureHandle textureHandle = ref.un.m_th[_attachment]; - BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment); - blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, textureHandle, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); - } - BGFX_API_FUNC(uint32_t frame(bool _capture = false) ); void dumpViewStats();