diff --git a/include/bgfx.h b/include/bgfx.h index 182cd81d..b96b4493 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -835,10 +835,12 @@ namespace bgfx /// /// @param _vsh Vertex shader. /// @param _fsh Fragment shader. + /// @param _destroyShaders If true, shaders will be destroyed when + /// program is destroyed. /// @returns Program handle if vertex shader output and fragment shader /// input are matching, otherwise returns invalid program handle. /// - ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh); + ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh, bool _destroyShaders = false); /// Destroy program. void destroyProgram(ProgramHandle _handle); @@ -974,8 +976,8 @@ namespace bgfx /// /// @param _num Number of texture attachments. /// @param _handles Texture attachments. - /// @param _destroyTextures Destroy textures when frame buffer is - /// destroyed. + /// @param _destroyTextures If true, textures will be destroyed when + /// frame buffer is destroyed. /// FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index d421afad..95a99873 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1856,10 +1856,18 @@ namespace bgfx s_ctx->destroyFragmentShader(_handle); } - ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh) + ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh, bool _destroyShaders) { BGFX_CHECK_MAIN_THREAD(); - return s_ctx->createProgram(_vsh, _fsh); + ProgramHandle handle = s_ctx->createProgram(_vsh, _fsh); + + if (_destroyShaders) + { + destroyVertexShader(_vsh); + destroyFragmentShader(_fsh); + } + + return handle; } void destroyProgram(ProgramHandle _handle)