diff --git a/examples/common/nanovg/nanovg_bgfx.cpp b/examples/common/nanovg/nanovg_bgfx.cpp index 81f6b0948..7e5ccc435 100644 --- a/examples/common/nanovg/nanovg_bgfx.cpp +++ b/examples/common/nanovg/nanovg_bgfx.cpp @@ -1229,6 +1229,61 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32 return framebuffer; } +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int32_t imageFlags, bgfx::ViewId viewId) +{ + NVGLUframebuffer* framebuffer = nvgluCreateFramebuffer(ctx, imageFlags); + + if (framebuffer != NULL) + { + nvgluSetViewFramebuffer(viewId, framebuffer); + } + + return framebuffer; +} + +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags) +{ + BX_UNUSED(_imageFlags); + bgfx::TextureHandle textures[] = + { + bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT), + bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY) + }; + bgfx::FrameBufferHandle fbh = bgfx::createFrameBuffer( + BX_COUNTOF(textures) + , textures + , true + ); + + if (!bgfx::isValid(fbh) ) + { + return NULL; + } + + struct NVGparams* params = nvgInternalParams(_ctx); + struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; + struct GLNVGtexture* tex = glnvg__allocTexture(gl); + + if (NULL == tex) + { + bgfx::destroy(fbh); + return NULL; + } + + tex->width = 0; + tex->height = 0; + tex->type = NVG_TEXTURE_RGBA; + tex->flags = _imageFlags | NVG_IMAGE_PREMULTIPLIED; + tex->id = bgfx::getTexture(fbh); + + NVGLUframebuffer* framebuffer = BX_NEW(gl->allocator, NVGLUframebuffer); + framebuffer->ctx = _ctx; + framebuffer->image = tex->id.idx; + framebuffer->handle = fbh; + + return framebuffer; +} + void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer) { static NVGcontext* s_prevCtx = NULL; diff --git a/examples/common/nanovg/nanovg_bgfx.h b/examples/common/nanovg/nanovg_bgfx.h index 38f111ded..690c8310e 100644 --- a/examples/common/nanovg/nanovg_bgfx.h +++ b/examples/common/nanovg/nanovg_bgfx.h @@ -61,6 +61,12 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32 /// NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags); +/// +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags, bgfx::ViewId _viewId); + +/// +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _imageFlags); + /// void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer);