From 30b6d07e292ba7803210db823968fd55e2f73937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 12 Jun 2017 22:43:07 -0700 Subject: [PATCH] Cleanup. --- examples/03-raymarch/raymarch.cpp | 3 +- examples/08-update/update.cpp | 3 +- examples/09-hdr/hdr.cpp | 5 +- examples/10-font/font.cpp | 190 +++++++++++--------- examples/11-fontsdf/fontsdf.cpp | 131 +++++++------- examples/16-shadowmaps/shadowmaps.cpp | 53 +++++- examples/17-drawstress/drawstress.cpp | 7 +- examples/18-ibl/ibl.cpp | 9 +- examples/19-oit/oit.cpp | 4 +- examples/21-deferred/deferred.cpp | 8 +- examples/23-vectordisplay/vectordisplay.cpp | 16 +- examples/31-rsm/reflectiveshadowmap.cpp | 10 +- examples/common/imgui/imgui.cpp | 9 +- examples/common/imgui/ocornut_imgui.cpp | 3 +- src/renderer_gl.cpp | 2 +- tools/texturev/texturev.cpp | 7 +- 16 files changed, 277 insertions(+), 183 deletions(-) diff --git a/examples/03-raymarch/raymarch.cpp b/examples/03-raymarch/raymarch.cpp index 80eb2da31..1f1e88d65 100644 --- a/examples/03-raymarch/raymarch.cpp +++ b/examples/03-raymarch/raymarch.cpp @@ -194,8 +194,9 @@ class ExampleRaymarch : public entry::AppI // Set view and projection matrix for view 1. bgfx::setViewTransform(0, view, proj); + const bgfx::Caps* caps = bgfx::getCaps(); float ortho[16]; - bx::mtxOrtho(ortho, 0.0f, 1280.0f, 720.0f, 0.0f, 0.0f, 100.0f); + bx::mtxOrtho(ortho, 0.0f, 1280.0f, 720.0f, 0.0f, 0.0f, 100.0f, 0.0, caps->homogeneousDepth); // Set view and projection matrix for view 0. bgfx::setViewTransform(1, NULL, ortho); diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 5095b854d..271b2649d 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -492,7 +492,8 @@ public: // Set view and projection matrix for view 1. const float aspectRatio = float(m_height)/float(m_width); const float size = 11.0f; - bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f); + const bgfx::Caps* caps = bgfx::getCaps(); + bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(1, NULL, proj); float mtx[16]; diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 995043a42..b46ac1941 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -404,8 +404,9 @@ class ExampleHDR : public entry::AppI bgfx::FrameBufferHandle invalid = BGFX_INVALID_HANDLE; bgfx::setViewFrameBuffer(hdrHBlurTonemap, invalid); + const bgfx::Caps* caps = bgfx::getCaps(); float proj[16]; - bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth); uint8_t order[] = { @@ -442,7 +443,7 @@ class ExampleHDR : public entry::AppI float view[16]; bx::mtxLookAt(view, temp, at); - bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); + bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, caps->homogeneousDepth); // Set view and projection matrix for view hdrMesh. bgfx::setViewTransform(hdrMesh, view, proj); diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index 949b34e15..4ae8942f9 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -35,7 +35,7 @@ TrueTypeHandle loadTtf(FontManager* _fm, const char* _filePath) return invalid; } -const char* fontFilePath[7] = +static const char* s_fontFilePath[] = { "font/droidsans.ttf", "font/chp-fire.ttf", @@ -51,18 +51,18 @@ class ExampleFont : public entry::AppI void init(int _argc, char** _argv) BX_OVERRIDE { Args args(_argc, _argv); - + m_width = 1280; m_height = 720; m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - + bgfx::init(args.m_type, args.m_pciId); bgfx::reset(m_width, m_height, m_reset); - + // Enable debug text. bgfx::setDebug(m_debug); - + // Set view 0 clear state. bgfx::setViewClear(0 , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH @@ -70,114 +70,114 @@ class ExampleFont : public entry::AppI , 1.0f , 0 ); - + // Init the text rendering system. m_fontManager = new FontManager(512); m_textBufferManager = new TextBufferManager(m_fontManager); - + // Load some TTF files. for (uint32_t ii = 0; ii < numFonts; ++ii) { // Instantiate a usable font. - m_fontFiles[ii] = loadTtf(m_fontManager, fontFilePath[ii]); + m_fontFiles[ii] = loadTtf(m_fontManager, s_fontFilePath[ii]); m_fonts[ii] = m_fontManager->createFontByPixelSize(m_fontFiles[ii], 0, 32); - + // Preload glyphs and blit them to atlas. m_fontManager->preloadGlyph(m_fonts[ii], L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n"); - + // You can unload the truetype files at this stage, but in that // case, the set of glyph's will be limited to the set of preloaded // glyph. m_fontManager->destroyTtf(m_fontFiles[ii]); } - + m_fontAwesomeTtf = loadTtf(m_fontManager, "font/fontawesome-webfont.ttf"); m_fontKenneyTtf = loadTtf(m_fontManager, "font/kenney-icon-font.ttf"); - + // This font doesn't have any preloaded glyph's but the truetype file // is loaded so glyph will be generated as needed. m_fontAwesome72 = m_fontManager->createFontByPixelSize(m_fontAwesomeTtf, 0, 72); m_fontKenney64 = m_fontManager->createFontByPixelSize(m_fontKenneyTtf, 0, 64); - + m_visitorTtf = loadTtf(m_fontManager, "font/visitor1.ttf"); - + // This font doesn't have any preloaded glyph's but the truetype file // is loaded so glyph will be generated as needed. m_visitor10 = m_fontManager->createFontByPixelSize(m_visitorTtf, 0, 10); - + //create a static text buffer compatible with alpha font //a static text buffer content cannot be modified after its first submit. m_staticText = m_textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, BufferType::Static); - + // The pen position represent the top left of the box of the first line // of text. m_textBufferManager->setPenPosition(m_staticText, 24.0f, 100.0f); - + for (uint32_t ii = 0; ii < numFonts; ++ii) { // Add some text to the buffer. // The position of the pen is adjusted when there is an endline. m_textBufferManager->appendText(m_staticText, m_fonts[ii], L"The quick brown fox jumps over the lazy dog\n"); } - + // Now write some styled text. - + // Setup style colors. m_textBufferManager->setBackgroundColor(m_staticText, 0x551111ff); m_textBufferManager->setUnderlineColor(m_staticText, 0xff2222ff); m_textBufferManager->setOverlineColor(m_staticText, 0x2222ffff); m_textBufferManager->setStrikeThroughColor(m_staticText, 0x22ff22ff); - + // Background. m_textBufferManager->setStyle(m_staticText, STYLE_BACKGROUND); m_textBufferManager->appendText(m_staticText, m_fonts[0], L"The quick "); - + // Strike-through. m_textBufferManager->setStyle(m_staticText, STYLE_STRIKE_THROUGH); m_textBufferManager->appendText(m_staticText, m_fonts[0], L"brown fox "); - + // Overline. m_textBufferManager->setStyle(m_staticText, STYLE_OVERLINE); m_textBufferManager->appendText(m_staticText, m_fonts[0], L"jumps over "); - + // Underline. m_textBufferManager->setStyle(m_staticText, STYLE_UNDERLINE); m_textBufferManager->appendText(m_staticText, m_fonts[0], L"the lazy "); - + // Background + strike-through. m_textBufferManager->setStyle(m_staticText, STYLE_BACKGROUND | STYLE_STRIKE_THROUGH); m_textBufferManager->appendText(m_staticText, m_fonts[0], L"dog\n"); - + m_textBufferManager->setStyle(m_staticText, STYLE_NORMAL); m_textBufferManager->appendText(m_staticText, m_fontAwesome72, - " " ICON_FA_POWER_OFF - " " ICON_FA_TWITTER_SQUARE - " " ICON_FA_CERTIFICATE - " " ICON_FA_FLOPPY_O - " " ICON_FA_GITHUB - " " ICON_FA_GITHUB_ALT - "\n" - ); + " " ICON_FA_POWER_OFF + " " ICON_FA_TWITTER_SQUARE + " " ICON_FA_CERTIFICATE + " " ICON_FA_FLOPPY_O + " " ICON_FA_GITHUB + " " ICON_FA_GITHUB_ALT + "\n" + ); m_textBufferManager->appendText(m_staticText, m_fontKenney64, - " " ICON_KI_COMPUTER - " " ICON_KI_JOYSTICK - " " ICON_KI_EXLAMATION - " " ICON_KI_STAR - " " ICON_KI_BUTTON_START - " " ICON_KI_DOWNLOAD - "\n" - ); - + " " ICON_KI_COMPUTER + " " ICON_KI_JOYSTICK + " " ICON_KI_EXLAMATION + " " ICON_KI_STAR + " " ICON_KI_BUTTON_START + " " ICON_KI_DOWNLOAD + "\n" + ); + // Create a transient buffer for real-time data. m_transientText = m_textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, BufferType::Transient); } - + virtual int shutdown() BX_OVERRIDE { m_fontManager->destroyTtf(m_fontKenneyTtf); m_fontManager->destroyTtf(m_fontAwesomeTtf); m_fontManager->destroyTtf(m_visitorTtf); - + // Destroy the fonts. m_fontManager->destroyFont(m_fontKenney64); m_fontManager->destroyFont(m_fontAwesome72); @@ -186,127 +186,157 @@ class ExampleFont : public entry::AppI { m_fontManager->destroyFont(m_fonts[ii]); } - + m_textBufferManager->destroyTextBuffer(m_staticText); m_textBufferManager->destroyTextBuffer(m_transientText); - + delete m_textBufferManager; delete m_fontManager; - + // Shutdown bgfx. bgfx::shutdown(); - + return 0; } - + bool update() BX_OVERRIDE { - if (!entry::processEvents(m_width, m_height, m_debug, m_reset) ) { // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. bgfx::touch(0); - + int64_t now = bx::getHPCounter(); static int64_t last = now; const int64_t frameTime = now - last; last = now; const double freq = double(bx::getHPFrequency() ); const double toMs = 1000.0 / freq; - + // Use debug font to print information about this example. bgfx::dbgTextClear(); bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/10-font"); bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Use the font system to display text and styled text."); bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); - + // Use transient text to display debug information. wchar_t fpsText[64]; bx::swnprintf(fpsText, BX_COUNTOF(fpsText), L"Frame: % 7.3f[ms]", double(frameTime) * toMs); - + m_textBufferManager->clearTextBuffer(m_transientText); m_textBufferManager->setPenPosition(m_transientText, m_width - 150.0f, 10.0f); m_textBufferManager->appendText(m_transientText, m_visitor10, L"Transient\n"); m_textBufferManager->appendText(m_transientText, m_visitor10, L"text buffer\n"); m_textBufferManager->appendText(m_transientText, m_visitor10, fpsText); - + float at[3] = { 0, 0, 0.0f }; float eye[3] = { 0, 0, -1.0f }; - + float view[16]; bx::mtxLookAt(view, eye, at); - + const float centering = 0.5f; - + // Setup a top-left ortho matrix for screen space drawing. - const bgfx::HMD* hmd = bgfx::getHMD(); - if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) + const bgfx::HMD* hmd = bgfx::getHMD(); + const bgfx::Caps* caps = bgfx::getCaps(); + if (NULL != hmd + && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) { float proj[16]; - bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); - + bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, caps->homogeneousDepth); + static float time = 0.0f; time += 0.05f; - + const float dist = 10.0f; const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]); const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]); - + float ortho[2][16]; const float offsetx = m_width/2.0f; - bx::mtxOrtho(ortho[0], centering, offsetx + centering, m_height + centering, centering, -1.0f, 1.0f, offset0); - bx::mtxOrtho(ortho[1], centering, offsetx + centering, m_height + centering, centering, -1.0f, 1.0f, offset1); + bx::mtxOrtho( + ortho[0] + , centering + , offsetx + centering + , m_height + centering + , centering + , -1.0f + , 1.0f + , offset0 + , caps->homogeneousDepth + ); + bx::mtxOrtho( + ortho[1] + , centering + , offsetx + centering + , m_height + centering + , centering + , -1.0f + , 1.0f + , offset1 + , caps->homogeneousDepth + ); bgfx::setViewTransform(0, view, ortho[0], BGFX_VIEW_STEREO, ortho[1]); bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); } else { float ortho[16]; - bx::mtxOrtho(ortho, centering, m_width + centering, m_height + centering, centering, -1.0f, 1.0f, bgfx::getCaps()->homogeneousDepth); + bx::mtxOrtho( + ortho + , centering + , m_width + centering + , m_height + centering + , centering + , 0.0f + , 100.0f + , 0.0f + , caps->homogeneousDepth + ); bgfx::setViewTransform(0, view, ortho); bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) ); } - + // Submit the debug text. m_textBufferManager->submitTextBuffer(m_transientText, 0); - + // Submit the static text. m_textBufferManager->submitTextBuffer(m_staticText, 0); - + // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); - + return true; } - + return false; } - + uint32_t m_width; uint32_t m_height; uint32_t m_debug; uint32_t m_reset; - + FontManager* m_fontManager; TextBufferManager* m_textBufferManager; - + FontHandle m_visitor10; TrueTypeHandle m_fontAwesomeTtf; TrueTypeHandle m_fontKenneyTtf; FontHandle m_fontAwesome72; FontHandle m_fontKenney64; TrueTypeHandle m_visitorTtf; - + TextBufferHandle m_transientText; TextBufferHandle m_staticText; - - static const uint32_t numFonts = BX_COUNTOF(fontFilePath); - + + static const uint32_t numFonts = BX_COUNTOF(s_fontFilePath); + TrueTypeHandle m_fontFiles[numFonts]; FontHandle m_fonts[numFonts]; - }; ENTRY_IMPLEMENT_MAIN(ExampleFont); diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index 19af9de69..e22d0e13e 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -36,18 +36,18 @@ class ExampleFontSDF : public entry::AppI void init(int _argc, char** _argv) BX_OVERRIDE { Args args(_argc, _argv); - + m_width = 1280; m_height = 720; m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - + bgfx::init(args.m_type, args.m_pciId); bgfx::reset(m_width, m_height, m_reset); - + // Enable debug text. bgfx::setDebug(m_debug); - + // Set view 0 clear state. bgfx::setViewClear(0 , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH @@ -55,71 +55,71 @@ class ExampleFontSDF : public entry::AppI , 1.0f , 0 ); - + // Imgui. imguiCreate(); - + m_bigText = (char*)load("text/sherlock_holmes_a_scandal_in_bohemia_arthur_conan_doyle.txt"); - + // Init the text rendering system. m_fontManager = new FontManager(512); m_textBufferManager = new TextBufferManager(m_fontManager); - + m_font = loadTtf(m_fontManager, "font/special_elite.ttf"); - + // Create a distance field font. m_fontSdf = m_fontManager->createFontByPixelSize(m_font, 0, 48, FONT_TYPE_DISTANCE); - + // Create a scaled down version of the same font (without adding anything to the atlas). m_fontScaled = m_fontManager->createScaledFontToPixelSize(m_fontSdf, 14); - + m_metrics = TextLineMetrics(m_fontManager->getFontInfo(m_fontScaled) ); m_lineCount = m_metrics.getLineCount(m_bigText); - + m_visibleLineCount = 20.0f; - + m_textBegin = 0; m_textEnd = 0; m_metrics.getSubText(m_bigText, 0, (uint32_t)m_visibleLineCount, m_textBegin, m_textEnd); - + m_scrollableBuffer = m_textBufferManager->createTextBuffer(FONT_TYPE_DISTANCE, BufferType::Transient); m_textBufferManager->setTextColor(m_scrollableBuffer, 0xFFFFFFFF); - + m_textBufferManager->appendText(m_scrollableBuffer, m_fontScaled, m_textBegin, m_textEnd); - + m_scrollArea = 0; m_textScroll = 0.0f; m_textRotation = 0.0f; m_textScale = 1.0f; m_textSize = 14.0f; } - + virtual int shutdown() BX_OVERRIDE { - + imguiDestroy(); - + BX_FREE(entry::getAllocator(), m_bigText); - + m_fontManager->destroyTtf(m_font); // Destroy the fonts. m_fontManager->destroyFont(m_fontSdf); m_fontManager->destroyFont(m_fontScaled); - + m_textBufferManager->destroyTextBuffer(m_scrollableBuffer); - + delete m_textBufferManager; delete m_fontManager; - + // Shutdown bgfx. bgfx::shutdown(); - + return 0; } bool update() BX_OVERRIDE { - + if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) { imguiBeginFrame(m_mouseState.m_mx @@ -131,10 +131,10 @@ class ExampleFontSDF : public entry::AppI , uint16_t(m_width) , uint16_t(m_height) ); - + const int32_t guiPanelWidth = 250; const int32_t guiPanelHeight = 200; - + imguiBeginScrollArea("Text Area" , m_width - guiPanelWidth - 10 , 10 @@ -143,7 +143,7 @@ class ExampleFontSDF : public entry::AppI , &m_scrollArea ); imguiSeparatorLine(); - + bool recomputeVisibleText = false; recomputeVisibleText |= imguiSlider("Number of lines", m_visibleLineCount, 1.0f, 177.0f , 1.0f); if (imguiSlider("Font size", m_textSize, 6.0f, 64.0f , 1.0f) ) @@ -153,116 +153,117 @@ class ExampleFontSDF : public entry::AppI m_metrics = TextLineMetrics(m_fontManager->getFontInfo(m_fontScaled) ); recomputeVisibleText = true; } - + recomputeVisibleText |= imguiSlider("Scroll", m_textScroll, 0.0f, (m_lineCount-m_visibleLineCount) , 1.0f); imguiSlider("Rotate", m_textRotation, 0.0f, bx::kPi*2.0f , 0.1f); recomputeVisibleText |= imguiSlider("Scale", m_textScale, 0.1f, 10.0f , 0.1f); - + if (recomputeVisibleText) { m_textBufferManager->clearTextBuffer(m_scrollableBuffer); m_metrics.getSubText(m_bigText,(uint32_t)m_textScroll, (uint32_t)(m_textScroll+m_visibleLineCount), m_textBegin, m_textEnd); m_textBufferManager->appendText(m_scrollableBuffer, m_fontScaled, m_textBegin, m_textEnd); } - + imguiEndScrollArea(); - + imguiEndFrame(); - + // Set view 0 default viewport. bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) ); - + // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. bgfx::touch(0); - + int64_t now = bx::getHPCounter(); static int64_t last = now; const int64_t frameTime = now - last; last = now; const double freq = double(bx::getHPFrequency() ); const double toMs = 1000.0 / freq; - + // Use debug font to print32_t information about this example. bgfx::dbgTextClear(); bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/11-fontsdf"); bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Use a single distance field font to render text of various size."); bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime) * toMs); - + float at[3] = { 0, 0, 0.0f }; float eye[3] = {0, 0, -1.0f }; - + float view[16]; bx::mtxLookAt(view, eye, at); - + const float centering = 0.5f; - + // Setup a top-left ortho matrix for screen space drawing. - const bgfx::HMD* hmd = bgfx::getHMD(); + const bgfx::HMD* hmd = bgfx::getHMD(); + const bgfx::Caps* caps = bgfx::getCaps(); if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) { float proj[16]; - bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); - + bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, caps->homogeneousDepth); + static float time = 0.0f; time += 0.05f; - + const float dist = 10.0f; const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]); const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]); - + float ortho[2][16]; const float viewOffset = m_width/4.0f; const float viewWidth = m_width/2.0f; - bx::mtxOrtho(ortho[0], centering + viewOffset, centering + viewOffset + viewWidth, m_height + centering, centering, -1.0f, 1.0f, offset0); - bx::mtxOrtho(ortho[1], centering + viewOffset, centering + viewOffset + viewWidth, m_height + centering, centering, -1.0f, 1.0f, offset1); + bx::mtxOrtho(ortho[0], centering + viewOffset, centering + viewOffset + viewWidth, m_height + centering, centering, -1.0f, 1.0f, offset0, caps->homogeneousDepth); + bx::mtxOrtho(ortho[1], centering + viewOffset, centering + viewOffset + viewWidth, m_height + centering, centering, -1.0f, 1.0f, offset1, caps->homogeneousDepth); bgfx::setViewTransform(0, view, ortho[0], BGFX_VIEW_STEREO, ortho[1]); bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); } else { float ortho[16]; - bx::mtxOrtho(ortho, centering, m_width + centering, m_height + centering, centering, -1.0f, 1.0f); + bx::mtxOrtho(ortho, centering, m_width + centering, m_height + centering, centering, -1.0f, 1.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(0, view, ortho); bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) ); } - + //very crude approximation :( float textAreaWidth = 0.5f * 66.0f * m_fontManager->getFontInfo(m_fontScaled).maxAdvanceWidth; - + float textRotMat[16]; float textCenterMat[16]; float textScaleMat[16]; float screenCenterMat[16]; - + bx::mtxRotateZ(textRotMat, m_textRotation); bx::mtxTranslate(textCenterMat, -(textAreaWidth * 0.5f), (-m_visibleLineCount)*m_metrics.getLineHeight()*0.5f, 0); bx::mtxScale(textScaleMat, m_textScale, m_textScale, 1.0f); bx::mtxTranslate(screenCenterMat, ( (m_width) * 0.5f), ( (m_height) * 0.5f), 0); - + //first translate to text center, then scale, then rotate float tmpMat[16]; bx::mtxMul(tmpMat, textCenterMat, textRotMat); - + float tmpMat2[16]; bx::mtxMul(tmpMat2, tmpMat, textScaleMat); - + float tmpMat3[16]; bx::mtxMul(tmpMat3, tmpMat2, screenCenterMat); - + // Set model matrix for rendering. bgfx::setTransform(tmpMat3); - + // Draw your text. m_textBufferManager->submitTextBuffer(m_scrollableBuffer, 0); - + // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); - + return true; } - + return false; } @@ -271,25 +272,25 @@ class ExampleFontSDF : public entry::AppI uint32_t m_height; uint32_t m_debug; uint32_t m_reset; - + char* m_bigText; - + // Init the text rendering system. FontManager* m_fontManager; TextBufferManager* m_textBufferManager; - + TrueTypeHandle m_font; FontHandle m_fontSdf; FontHandle m_fontScaled; - + TextBufferHandle m_scrollableBuffer; - + TextLineMetrics m_metrics = TextLineMetrics(FontInfo()); uint32_t m_lineCount; float m_visibleLineCount; const char* m_textBegin; const char* m_textEnd; - + int32_t m_scrollArea; float m_textScroll; float m_textRotation; diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 92c508450..525893705 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1926,6 +1926,8 @@ int _main_(int _argc, char** _argv) cameraSetPosition(initialPos); cameraSetVerticalAngle(-0.45f); + const bgfx::Caps* caps = bgfx::getCaps(); + // Set view and projection matrices. const float camFovy = 60.0f; const float camAspect = float(int32_t(viewState.m_width) ) / float(int32_t(viewState.m_height) ); @@ -1933,7 +1935,7 @@ int _main_(int _argc, char** _argv) const float camFar = 2000.0f; const float projHeight = 1.0f/bx::ftan(bx::toRad(camFovy)*0.5f); const float projWidth = projHeight * camAspect; - bx::mtxProj(viewState.m_proj, camFovy, camAspect, camNear, camFar, bgfx::getCaps()->homogeneousDepth); + bx::mtxProj(viewState.m_proj, camFovy, camAspect, camNear, camFar, caps->homogeneousDepth); cameraGetViewMtx(viewState.m_view); float timeAccumulatorLight = 0.0f; @@ -2235,13 +2237,31 @@ int _main_(int _argc, char** _argv) float screenProj[16]; float screenView[16]; bx::mtxIdentity(screenView); - bx::mtxOrtho(screenProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); - if (LightType::SpotLight == settings.m_lightType) + bx::mtxOrtho( + screenProj + , 0.0f + , 1.0f + , 1.0f + , 0.0f + , 0.0f + , 100.0f + , 0.0f + , caps->homogeneousDepth + ); + + if (LightType::SpotLight == settings.m_lightType) { const float fovy = settings.m_coverageSpotL; const float aspect = 1.0f; - bx::mtxProj(lightProj[ProjType::Horizontal], fovy, aspect, currentSmSettings->m_near, currentSmSettings->m_far); + bx::mtxProj( + lightProj[ProjType::Horizontal] + , fovy + , aspect + , currentSmSettings->m_near + , currentSmSettings->m_far + , false + ); //For linear depth, prevent depth division by variable w-component in shaders and divide here by far plane if (DepthImpl::Linear == settings.m_depthImpl) @@ -2271,11 +2291,13 @@ int _main_(int _argc, char** _argv) const float fovy = 125.26438968f + 9.85f + settings.m_fovYAdjust; const float aspect = bx::ftan(bx::toRad(fovx*0.5f) )/bx::ftan(bx::toRad(fovy*0.5f) ); - bx::mtxProj(lightProj[ProjType::Vertical] + bx::mtxProj( + lightProj[ProjType::Vertical] , fovx , aspect , currentSmSettings->m_near , currentSmSettings->m_far + , false ); //For linear depth, prevent depth division by variable w-component in shaders and divide here by far plane @@ -2295,7 +2317,14 @@ int _main_(int _argc, char** _argv) const float fovy = 125.26438968f + 3.0f + settings.m_fovYAdjust; const float aspect = bx::ftan(bx::toRad(fovx*0.5f) )/bx::ftan(bx::toRad(fovy*0.5f) ); - bx::mtxProj(lightProj[ProjType::Horizontal], fovy, aspect, currentSmSettings->m_near, currentSmSettings->m_far); + bx::mtxProj( + lightProj[ProjType::Horizontal] + , fovy + , aspect + , currentSmSettings->m_near + , currentSmSettings->m_far + , caps->homogeneousDepth + ); //For linear depth, prevent depth division by variable w component in shaders and divide here by far plane if (DepthImpl::Linear == settings.m_depthImpl) @@ -2357,7 +2386,17 @@ int _main_(int _argc, char** _argv) } float mtxProj[16]; - bx::mtxOrtho(mtxProj, 1.0f, -1.0f, 1.0f, -1.0f, -currentSmSettings->m_far, currentSmSettings->m_far); + bx::mtxOrtho( + mtxProj + , 1.0f + , -1.0f + , 1.0f + , -1.0f + , -currentSmSettings->m_far + , currentSmSettings->m_far + , 0.0f + , caps->homogeneousDepth + ); const uint8_t numCorners = 8; float frustumCorners[maxNumSplits][numCorners][3]; diff --git a/examples/17-drawstress/drawstress.cpp b/examples/17-drawstress/drawstress.cpp index c632c2363..bbfdc2ff3 100644 --- a/examples/17-drawstress/drawstress.cpp +++ b/examples/17-drawstress/drawstress.cpp @@ -241,9 +241,12 @@ class ExampleDrawStress : public entry::AppI float eye[3] = { 0.0f, 0.0f, -35.0f }; float view[16]; - float proj[16]; bx::mtxLookAt(view, eye, at); - bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f); + + + const bgfx::Caps* caps = bgfx::getCaps(); + float proj[16]; + bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, caps->homogeneousDepth); // Set view and projection matrix for view 0. bgfx::setViewTransform(0, view, proj); diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index 70d0b4591..27f2b7221 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -721,14 +721,17 @@ int _main_(int _argc, char** _argv) // View Transform 0. float view[16]; - float proj[16]; bx::mtxIdentity(view); - bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + + const bgfx::Caps* caps = bgfx::getCaps(); + + float proj[16]; + bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0, caps->homogeneousDepth); bgfx::setViewTransform(0, view, proj); // View Transform 1. camera.mtxLookAt(view); - bx::mtxProj(proj, 45.0f, float(width)/float(height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); + bx::mtxProj(proj, 45.0f, float(width)/float(height), 0.1f, 100.0f, caps->homogeneousDepth); bgfx::setViewTransform(1, view, proj); // View rect. diff --git a/examples/19-oit/oit.cpp b/examples/19-oit/oit.cpp index 12832cc20..a73cfa609 100644 --- a/examples/19-oit/oit.cpp +++ b/examples/19-oit/oit.cpp @@ -366,7 +366,9 @@ class ExampleOIT : public entry::AppI // Set view and projection matrix for view 1. bx::mtxIdentity(view); - bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + + const bgfx::Caps* caps = bgfx::getCaps(); + bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(1, view, proj); for (uint32_t depth = 0; depth < 3; ++depth) diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 26751e252..efb0bc989 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -474,16 +474,18 @@ class ExampleDeferred : public entry::AppI bx::mtxMul(vp, view, proj); bx::mtxInverse(invMvp, vp); - bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + const bgfx::Caps* caps = bgfx::getCaps(); + + bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(RENDER_PASS_LIGHT_ID, NULL, proj); bgfx::setViewTransform(RENDER_PASS_COMBINE_ID, NULL, proj); const float aspectRatio = float(m_height)/float(m_width); const float size = 10.0f; - bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f); + bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(RENDER_PASS_DEBUG_GBUFFER_ID, NULL, proj); - bx::mtxOrtho(proj, 0.0f, (float)m_width, 0.0f, (float)m_height, 0.0f, 1000.0f); + bx::mtxOrtho(proj, 0.0f, (float)m_width, 0.0f, (float)m_height, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(RENDER_PASS_DEBUG_LIGHTS_ID, NULL, proj); } diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index 9b1450cf3..4db6c8a14 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -132,8 +132,20 @@ void VectorDisplay::beginFrame() void VectorDisplay::endFrame() { + const bgfx::Caps* caps = bgfx::getCaps(); + float proj[16]; - bx::mtxOrtho(proj, 0.0f, (float)m_screenWidth, (float)m_screenHeight, 0.0f, 0.0f, 1000.0f); + bx::mtxOrtho( + proj + , 0.0f + , (float)m_screenWidth + , (float)m_screenHeight + , 0.0f + , 0.0f + , 1000.0f + , 0.0f + , caps->homogeneousDepth + ); bgfx::setViewRect(m_view, 0, 0, m_screenWidth, m_screenHeight); bgfx::setViewFrameBuffer(m_view, m_sceneFrameBuffer); @@ -192,7 +204,7 @@ void VectorDisplay::endFrame() uint8_t viewCounter = m_view + 1; - bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth); float glow_iter_mult = 1.05f + ( (m_brightness - 1.0f) / 5.0f); float glow_fin_mult = 1.25f + ( (m_brightness - 1.0f) / 2.0f); diff --git a/examples/31-rsm/reflectiveshadowmap.cpp b/examples/31-rsm/reflectiveshadowmap.cpp index 3f4d0fdac..5d7c1ac4e 100644 --- a/examples/31-rsm/reflectiveshadowmap.cpp +++ b/examples/31-rsm/reflectiveshadowmap.cpp @@ -477,12 +477,8 @@ public: bx::mtxLookAt(smView, lightEye, lightAt); const float area = 10.0f; - bgfx::RendererType::Enum renderer = bgfx::getRendererType(); - bool flipV = false - || renderer == bgfx::RendererType::OpenGL - || renderer == bgfx::RendererType::OpenGLES - ; - bx::mtxOrtho(smProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, flipV); + const bgfx::Caps* caps = bgfx::getCaps(); + bx::mtxOrtho(smProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(RENDER_PASS_SHADOW_MAP, smView, smProj); bgfx::setViewFrameBuffer(RENDER_PASS_SHADOW_MAP, m_shadowBuffer); bgfx::setViewRect(RENDER_PASS_SHADOW_MAP, 0, 0, SHADOW_MAP_DIM, SHADOW_MAP_DIM); @@ -578,7 +574,7 @@ public: // Set up transform matrix for fullscreen quad float orthoProj[16]; - bx::mtxOrtho(orthoProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); + bx::mtxOrtho(orthoProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(RENDER_PASS_COMBINE, NULL, orthoProj); bgfx::setViewRect(RENDER_PASS_COMBINE, 0, 0, uint16_t(m_width), uint16_t(m_height) ); // Bind vertex buffer and draw quad diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index fc106dcda..6962d097e 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -805,7 +805,8 @@ struct Imgui bgfx::setViewName(_view, "IMGUI"); bgfx::setViewSeq(_view, true); - const bgfx::HMD* hmd = bgfx::getHMD(); + const bgfx::HMD* hmd = bgfx::getHMD(); + const bgfx::Caps* caps = bgfx::getCaps(); if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) { m_viewWidth = _width / 2; @@ -824,15 +825,15 @@ struct Imgui float ortho[2][16]; const float viewOffset = _surfaceWidth/4.0f; const float viewWidth = _surfaceWidth/2.0f; - bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset0); - bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset1); + bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset0, caps->homogeneousDepth); + bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset1, caps->homogeneousDepth); bgfx::setViewTransform(_view, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]); bgfx::setViewRect(_view, 0, 0, hmd->width, hmd->height); } else { float ortho[16]; - bx::mtxOrtho(ortho, 0.0f, (float)m_surfaceWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f); + bx::mtxOrtho(ortho, 0.0f, (float)m_surfaceWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(_view, NULL, ortho); bgfx::setViewRect(_view, 0, 0, _width, _height); } diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index 77d8def63..1c7c717be 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -72,8 +72,9 @@ struct OcornutImguiContext const float height = io.DisplaySize.y; { + const bgfx::Caps* caps = bgfx::getCaps(); float ortho[16]; - bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f); + bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(m_viewId, NULL, ortho); } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 70fbec596..0cb318d82 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2649,7 +2649,7 @@ namespace bgfx { namespace gl GL_CHECK(glUniform1i(program.m_sampler[0], 0) ); float proj[16]; - bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f); + bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, true); GL_CHECK(glUniformMatrix4fv(program.m_predefined[0].m_loc , 1 diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index 24e9b6c05..2358365a3 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -786,7 +786,8 @@ int _main_(int _argc, char** _argv) PosUvColorVertex::init(); - bgfx::RendererType::Enum type = bgfx::getRendererType(); + const bgfx::Caps* caps = bgfx::getCaps(); + bgfx::RendererType::Enum type = caps->rendererType; bgfx::ShaderHandle vsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture"); bgfx::ShaderHandle fsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture"); @@ -1064,7 +1065,7 @@ int _main_(int _argc, char** _argv) float ortho[16]; - bx::mtxOrtho(ortho, 0.0f, float(width), float(height), 0.0f, 0.0f, 1000.0f); + bx::mtxOrtho(ortho, 0.0f, float(width), float(height), 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(BACKGROUND_VIEW_ID, NULL, ortho); bgfx::setViewRect(BACKGROUND_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) ); @@ -1091,7 +1092,7 @@ int _main_(int _argc, char** _argv) float px = posx.getValue(); float py = posy.getValue(); - bx::mtxOrtho(ortho, px-width/2, px+width/2, py+height/2, py-height/2, 0.0f, 1000.0f); + bx::mtxOrtho(ortho, px-width/2, px+width/2, py+height/2, py-height/2, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth); bgfx::setViewTransform(IMAGE_VIEW_ID, NULL, ortho); bgfx::setViewRect(IMAGE_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) );