diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index 2bad36fe7..fdd80e7c1 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -14,9 +14,6 @@ #include #include -#define IMGUI_VIEWID 30 -#define NANOVG_VIEWID 31 - static bool s_flipV = false; static float s_texelHalf = 0.0f; @@ -447,9 +444,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiCreate(data); free(data); - NVGcontext* nvg = nvgCreate(512, 512, 1, NANOVG_VIEWID); - bgfx::setViewSeq(NANOVG_VIEWID, true); - // Uniforms. s_uniforms.init(); @@ -563,13 +557,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) , 0 , width , height - , IMGUI_VIEWID ); - nvgBeginFrame(nvg, int32_t(width), int32_t(height), 1.0f, NVG_STRAIGHT_ALPHA); - static int32_t rightScrollArea = 0; - imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea, nvg); + imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea); imguiLabel("Shade:"); imguiSeparator(); @@ -596,7 +587,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiEndScrollArea(); static int32_t leftScrollArea = 0; - imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea, nvg); + imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea); imguiLabel("Material properties:"); imguiSeparator(); @@ -670,7 +661,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiEndScrollArea(); - nvgEndFrame(nvg); imguiEndFrame(); s_uniforms.m_glossiness = settings.m_glossiness; @@ -723,7 +713,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setViewRect(0, 0, 0, width, height); bgfx::setViewRect(1, 0, 0, width, height); - bgfx::setViewRect(NANOVG_VIEWID, 0, 0, width, height); // View 0. bgfx::setTexture(4, u_texCube, lightProbes[currentLightProbe].m_tex); @@ -778,7 +767,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) s_uniforms.destroy(); - nvgDelete(nvg); imguiDestroy(); // Shutdown bgfx. diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index ed9b97b24..99a334b38 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -169,6 +169,8 @@ struct Imgui bool create(const void* _data) { + m_nvg = nvgCreate(512, 512, 1, m_view); + for (int32_t ii = 0; ii < NUM_CIRCLE_VERTS; ++ii) { float a = (float)ii / (float)NUM_CIRCLE_VERTS * (float)(M_PI * 2.0); @@ -239,6 +241,7 @@ struct Imgui bgfx::destroyTexture(m_fontTexture); bgfx::destroyProgram(m_colorProgram); bgfx::destroyProgram(m_textureProgram); + nvgDelete(m_nvg); } bool anyActive() const @@ -350,6 +353,8 @@ struct Imgui void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view) { + nvgBeginFrame(m_nvg, _width, _height, 1.0f, NVG_STRAIGHT_ALPHA); + m_view = _view; bgfx::setViewSeq(_view, true); bgfx::setViewRect(_view, 0, 0, _width, _height); @@ -378,9 +383,10 @@ struct Imgui void endFrame() { clearInput(); + nvgEndFrame(m_nvg); } - bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, NVGcontext* _nvg) + bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll) { m_areaId++; m_widgetId = 0; @@ -419,16 +425,12 @@ struct Imgui , imguiRGBA(255, 255, 255, 128) ); - if (NULL != _nvg) - { - m_nvg = _nvg; - nvgScissor(m_nvg - , float(_x + SCROLL_AREA_PADDING) - , float(_y + SCROLL_AREA_PADDING) - , float(_width - SCROLL_AREA_PADDING * 4) - , float(_height - AREA_HEADER - SCROLL_AREA_PADDING) - ); - } + nvgScissor(m_nvg + , float(_x + SCROLL_AREA_PADDING) + , float(_y + SCROLL_AREA_PADDING) + , float(_width - SCROLL_AREA_PADDING * 4) + , float(_height - AREA_HEADER - SCROLL_AREA_PADDING) + ); m_scissor = bgfx::setScissor(uint16_t(_x + SCROLL_AREA_PADDING) , uint16_t(_y + SCROLL_AREA_PADDING) @@ -443,11 +445,7 @@ struct Imgui { // Disable scissoring. m_scissor = UINT16_MAX; - if (NULL != m_nvg) - { - nvgResetScissor(m_nvg); - m_nvg = NULL; - } + nvgResetScissor(m_nvg); // Draw scroll bar int32_t xx = m_scrollRight + SCROLL_AREA_PADDING / 2; @@ -1881,9 +1879,9 @@ void imguiEndFrame() s_imgui.endFrame(); } -bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, NVGcontext* _nvg) +bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll) { - return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _nvg); + return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll); } void imguiEndScrollArea() diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 502f71e70..391e3d1cb 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -57,7 +57,7 @@ void imguiDestroy(); void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31); void imguiEndFrame(); -bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, struct NVGcontext* _nvg = NULL); +bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll); void imguiEndScrollArea(); void imguiIndent();