diff options
Diffstat (limited to '3rdparty/bgfx/examples')
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.cpp | 6 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.h | 4 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp | 99 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.h | 36 |
4 files changed, 119 insertions, 26 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index b8bf5b97a39..6a80447a34b 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -1488,7 +1488,7 @@ struct Imgui } } - uint8_t tabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, uint8_t _nEnabled, va_list _argList) + uint8_t tabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint32_t _nTabs, uint32_t _nEnabled, va_list _argList) { const char* titles[16]; bool tabEnabled[16]; @@ -3469,7 +3469,7 @@ void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled, Im s_imgui.input(_label, _str, _len, _enabled, _align, _r); } -uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, uint8_t _nEnabled, ...) +uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint32_t _nTabs, uint32_t _nEnabled, ...) { va_list argList; va_start(argList, _nEnabled); @@ -3479,7 +3479,7 @@ uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int return result; } -uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, ...) +uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint32_t _nTabs, ...) { va_list argList; va_start(argList, _nTabs); diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.h b/3rdparty/bgfx/examples/common/imgui/imgui.h index 273f2a817e7..3b0fc54f875 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.h +++ b/3rdparty/bgfx/examples/common/imgui/imgui.h @@ -190,8 +190,8 @@ void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = t /// _nEnabled - Number of specified 'enabled' flags. All other unspecified tabs are considered enabled by default. /// In the above example, there are 2 enabled flags: 'Tab0' is specified as enabled and 'Tab1' is specified as disabled. /// Tab2 is unspecified and therefore is treated as enabled. -uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, uint8_t _nEnabled, ...); -uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, ...); +uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint32_t _nTabs, uint32_t _nEnabled, ...); +uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint32_t _nTabs, ...); uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...); #define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL) diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp index 41095d853bb..05973f26284 100644 --- a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp +++ b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp @@ -548,6 +548,7 @@ namespace static void nvgRenderViewport(void* _userPtr, int width, int height, float devicePixelRatio) { struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr; + gl->state = 0; gl->view[0] = (float)width; gl->view[1] = (float)height; bgfx::setViewRect(gl->m_viewId, 0, 0, width * devicePixelRatio, height * devicePixelRatio); @@ -714,33 +715,24 @@ namespace int allocated = gl->tvb.size/gl->tvb.stride; - if (allocated < gl->nverts) { + if (allocated < gl->nverts) + { gl->nverts = allocated; BX_WARN(true, "Vertex number truncated due to transient vertex buffer overflow"); } - memcpy(gl->tvb.data, gl->verts, gl->nverts * sizeof(struct NVGvertex) ); - gl->state = 0 + if (0 == gl->state) + { + gl->state = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA); + } + + gl->state |= 0 | BGFX_STATE_RGB_WRITE | BGFX_STATE_ALPHA_WRITE ; -// if (alphaBlend == NVG_PREMULTIPLIED_ALPHA) -// { -// gl->state |= BGFX_STATE_BLEND_FUNC_SEPARATE( -// BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA -// , BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_INV_SRC_ALPHA -// ); -// } -// else - { - gl->state |= BGFX_STATE_BLEND_FUNC( - BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA - ); - } - bgfx::setUniform(gl->u_viewSize, gl->view); for (uint32_t ii = 0, num = gl->ncalls; ii < num; ++ii) @@ -1089,7 +1081,26 @@ error: } NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId) { - return nvgCreate(edgeaa, _viewId, NULL); + return nvgCreate(edgeaa, _viewId, NULL); +} + +void nvgDelete(struct NVGcontext* ctx) +{ + nvgDeleteInternal(ctx); +} + +void nvgState(struct NVGcontext* ctx, uint64_t state) +{ + struct NVGparams* params = nvgInternalParams(ctx); + struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; + gl->state = state; +} + +uint8_t nvgViewId(struct NVGcontext* ctx) +{ + struct NVGparams* params = nvgInternalParams(ctx); + struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; + return gl->m_viewId; } void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId) @@ -1099,7 +1110,55 @@ void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId) gl->m_viewId = uint8_t(_viewId); } -void nvgDelete(struct NVGcontext* ctx) +bgfx::TextureHandle nvglImageHandle(NVGcontext* ctx, int image) { - nvgDeleteInternal(ctx); + GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(ctx)->userPtr; + GLNVGtexture* tex = glnvg__findTexture(gl, image); + return tex->id; +} + +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, + int height, int imageFlags) { + NVGLUframebuffer* framebuffer = new NVGLUframebuffer; + framebuffer->ctx = ctx; + framebuffer->image = nvgCreateImageRGBA(ctx, width, height, + imageFlags, NULL); + bgfx::TextureHandle texture = nvglImageHandle(ctx, framebuffer->image); + if (!bgfx::isValid(texture)) { + nvgluDeleteFramebuffer(framebuffer); + return NULL; + } + framebuffer->handle = bgfx::createFrameBuffer(1, &texture, false); + if (!bgfx::isValid(framebuffer->handle)) + { + nvgluDeleteFramebuffer(framebuffer); + return NULL; + } + static uint8_t s_ViewId = 1; // may have a better way to assign new view id + framebuffer->viewId = s_ViewId++; + bgfx::setViewFrameBuffer(framebuffer->viewId, framebuffer->handle); + bgfx::setViewSeq(framebuffer->viewId, true); + return framebuffer; +} + +void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer) { + static NVGcontext* s_prevCtx = NULL; + static uint8_t s_prevViewId; + if (framebuffer != NULL) { + s_prevCtx = framebuffer->ctx; + s_prevViewId = nvgViewId(framebuffer->ctx); + nvgViewId(framebuffer->ctx, framebuffer->viewId); + } else if (s_prevCtx != NULL) { + nvgViewId(s_prevCtx, s_prevViewId); + } +} + +void nvgluDeleteFramebuffer(NVGLUframebuffer* framebuffer) { + if (framebuffer == NULL) + return; + if (framebuffer->image >= 0) + nvgDeleteImage(framebuffer->ctx, framebuffer->image); + if (bgfx::isValid(framebuffer->handle)) + bgfx::destroyFrameBuffer(framebuffer->handle); + delete framebuffer; } diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.h b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.h index d24ee4fa72f..2268e900f99 100644 --- a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.h +++ b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.h @@ -6,13 +6,47 @@ #ifndef NANOVG_BGFX_H_HEADER_GUARD #define NANOVG_BGFX_H_HEADER_GUARD +#include "bgfx/bgfx.h" + namespace bx { struct AllocatorI; } struct NVGcontext; +struct NVGLUframebuffer { + NVGcontext* ctx; + bgfx::FrameBufferHandle handle; + int image; + uint8_t viewId; +}; +typedef struct NVGLUframebuffer NVGLUframebuffer; + NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator); NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId); -void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId); void nvgDelete(struct NVGcontext* ctx); +void nvgState(struct NVGcontext* ctx, uint64_t state); +uint8_t nvgViewId(struct NVGcontext* ctx); +void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId); + +// Helper functions to create bgfx framebuffer to render to. +// Example: +// float scale = 2; +// NVGLUframebuffer* fb = nvgluCreateFramebuffer(ctx, 100 * scale, 100 * scale, 0); +// nvgluBindFramebuffer(fb); +// nvgBeginFrame(ctx, 100, 100, scale); +// // renders anything offscreen +// nvgEndFrame(ctx); +// nvgluBindFramebuffer(NULL); +// +// // Pastes the framebuffer rendering. +// nvgBeginFrame(ctx, 1024, 768, scale); +// NVGpaint paint = nvgImagePattern(ctx, 0, 0, 100, 100, 0, fb->image, 1); +// nvgBeginPath(ctx); +// nvgRect(ctx, 0, 0, 100, 100); +// nvgFillPaint(ctx, paint); +// nvgFill(ctx); +// nvgEndFrame(ctx); +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height, int imageFlags); +void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer); +void nvgluDeleteFramebuffer(NVGLUframebuffer* framebuffer); #endif // NANOVG_BGFX_H_HEADER_GUARD |