From 7ef9d80a7272d9cb93fc3d75634fed06243bd0e5 Mon Sep 17 00:00:00 2001 From: rachytski Date: Mon, 2 May 2011 18:15:56 +0300 Subject: [PATCH] rendering only opaque pixels on SkinPage when using multisampling. --- qt/widgets.cpp | 3 ++- qt_tstfrm/tstwidgets.cpp | 3 ++- yg/geometry_batcher.cpp | 8 +++++++- yg/resource_manager.cpp | 11 +++++++++-- yg/resource_manager.hpp | 6 +++++- yg/skin.cpp | 4 ++-- yg/skin.hpp | 2 ++ yg/skin_loader.cpp | 2 +- yg/skin_page.cpp | 15 ++++++++++----- yg/skin_page.hpp | 8 ++++++-- yg/yg_tests/skin_loader_test.cpp | 2 +- yg/yg_tests/skin_test.cpp | 2 +- 12 files changed, 48 insertions(+), 18 deletions(-) diff --git a/qt/widgets.cpp b/qt/widgets.cpp index 3a3ec25564..58a84690f8 100644 --- a/qt/widgets.cpp +++ b/qt/widgets.cpp @@ -55,7 +55,8 @@ namespace qt GetPlatform().ReadPathForFile("fonts_blacklist.txt").c_str(), 2000000, yg::Rt8Bpp, - !yg::gl::g_isBufferObjectsSupported)); + !yg::gl::g_isBufferObjectsSupported, + !GetPlatform().IsMultiSampled())); m_resourceManager->addFonts(GetPlatform().GetFontNames()); diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index f6cd81df52..2aee740694 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -60,7 +60,8 @@ void GLDrawWidget::initializeGL() GetPlatform().ReadPathForFile("fonts_blacklist.txt").c_str(), 2000000, yg::Rt8Bpp, - !yg::gl::g_isBufferObjectsSupported)); + !yg::gl::g_isBufferObjectsSupported, + !GetPlatform().IsMultiSampled())); m_resourceManager->addFonts(GetPlatform().GetFontNames()); diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index f83e39a32d..963c823b59 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -43,11 +43,17 @@ namespace yg { OGLCHECK(glEnable(GL_TEXTURE_2D)); + if (!m_isAntiAliased) + { + OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + OGLCHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + } + OGLCHECK(glEnable(GL_DEPTH_TEST)); OGLCHECK(glDepthFunc(GL_LEQUAL)); OGLCHECK(glEnable(GL_ALPHA_TEST)); - OGLCHECK(glAlphaFunc(GL_GREATER, 0)); + OGLCHECK(glAlphaFunc(GL_GREATER, 0.0)); OGLCHECK(glEnable(GL_BLEND)); OGLCHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index 585c878cff..f4611f84b1 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -23,14 +23,16 @@ namespace yg size_t texWidth, size_t texHeight, size_t texCount, char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxGlyphCacheSize, RtFormat fmt, - bool useVA) + bool useVA, + bool fillSkinAlpha) : m_textureWidth(texWidth), m_textureHeight(texHeight), m_vbSize(vbSize), m_ibSize(ibSize), m_smallVBSize(smallVBSize), m_smallIBSize(smallIBSize), m_blitVBSize(blitVBSize), m_blitIBSize(blitIBSize), m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize)), m_format(fmt), - m_useVA(useVA) + m_useVA(useVA), + m_fillSkinAlpha(fillSkinAlpha) { if (useVA) LOG(LINFO, ("buffer objects are unsupported. using client vertex array instead.")); @@ -254,4 +256,9 @@ namespace yg throw std::runtime_error("unknows render target format"); }; } + + bool ResourceManager::fillSkinAlpha() const + { + return m_fillSkinAlpha; + } } diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index 8fd3e4de98..f9e6653dad 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -64,6 +64,7 @@ namespace yg RtFormat m_format; bool m_useVA; + bool m_fillSkinAlpha; public: @@ -73,7 +74,8 @@ namespace yg size_t texWidth, size_t texHeight, size_t texCount, char const * blocksFile, char const * whileListFile, char const * blackListFile, size_t maxGlyphCacheSize, RtFormat fmt, - bool useVA); + bool useVA, + bool fillSkinAlpha); shared_ptr const & getTexture(string const & fileName); @@ -102,6 +104,8 @@ namespace yg void enterForeground(); shared_ptr createRenderTarget(unsigned w, unsigned h); + + bool fillSkinAlpha() const; }; Skin * loadSkin(shared_ptr const & resourceManager, diff --git a/yg/skin.cpp b/yg/skin.cpp index 951bbcefdd..fc34c57a1e 100644 --- a/yg/skin.cpp +++ b/yg/skin.cpp @@ -46,7 +46,7 @@ namespace yg for (size_t i = 0; i < count; ++i) { uint8_t pageID = (uint8_t)m_pages.size(); - m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, pageID))); + m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, pageID, m_resourceManager->fillSkinAlpha()))); m_pages.back()->addOverflowFn(bind(&Skin::onTextOverflow, this, pageID), 0); } } @@ -60,7 +60,7 @@ namespace yg for (size_t i = 0; i < count; ++i) { uint8_t pageID = (uint8_t)m_pages.size(); - m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, pageID))); + m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, pageID, m_resourceManager->fillSkinAlpha()))); m_pages.back()->addOverflowFn(bind(&Skin::onDynamicOverflow, this, pageID), 0); } } diff --git a/yg/skin.hpp b/yg/skin.hpp index 4b87e75571..bbcc596b1f 100644 --- a/yg/skin.hpp +++ b/yg/skin.hpp @@ -61,6 +61,8 @@ namespace yg shared_ptr m_resourceManager; + bool m_fillAlpha; + void clearHandles(); Skin(shared_ptr const & resourceManager, diff --git a/yg/skin_loader.cpp b/yg/skin_loader.cpp index 3bb9576643..94a60ef7eb 100644 --- a/yg/skin_loader.cpp +++ b/yg/skin_loader.cpp @@ -76,7 +76,7 @@ namespace yg void SkinLoader::popPage() { - m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, m_fileName.c_str(), m_pages.size()))); + m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, m_fileName.c_str(), m_pages.size(), m_resourceManager->fillSkinAlpha()))); TStylesList::iterator prevIt = m_stylesList.end(); diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index 62969aa9f2..f4bac85b34 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -99,20 +99,24 @@ namespace yg SkinPage::SkinPage(shared_ptr const & resourceManager, char const * name, - uint8_t pageID) + uint8_t pageID, + bool fillAlpha) : m_texture(resourceManager->getTexture(name)), m_isDynamic(false), - m_pageID(pageID) + m_pageID(pageID), + m_fillAlpha(fillAlpha) { m_packer = m2::Packer(m_texture->width(), m_texture->height(), 0x00FFFFFF - 1); } SkinPage::SkinPage(shared_ptr const & resourceManager, - uint8_t pageID) + uint8_t pageID, + bool fillAlpha) : m_resourceManager(resourceManager), m_isDynamic(true), - m_pageID(pageID) + m_pageID(pageID), + m_fillAlpha(fillAlpha) { m_packer = m2::Packer(m_resourceManager->textureWidth(), m_resourceManager->textureHeight(), @@ -431,7 +435,8 @@ namespace yg if (alpha != 0) { v(x, y) = penColor; - gil::get_color(v(x, y), gil::alpha_t()) = alpha; + if (m_fillAlpha) + gil::get_color(v(x, y), gil::alpha_t()) = alpha; } } } diff --git a/yg/skin_page.hpp b/yg/skin_page.hpp index fb9f196e7e..90a17bf3ad 100644 --- a/yg/skin_page.hpp +++ b/yg/skin_page.hpp @@ -117,6 +117,8 @@ namespace yg bool m_isDynamic; uint32_t m_pageID; + bool m_fillAlpha; + /// number of pending rendering commands, /// that are using this skin_page uint32_t m_activeCommands; @@ -142,11 +144,13 @@ namespace yg /// creation of a static page SkinPage(shared_ptr const & resourceManager, char const * name, - uint8_t pageID); + uint8_t pageID, + bool fillAlpha); /// creation of a dynamic page SkinPage(shared_ptr const & resourceManager, - uint8_t pageID); + uint8_t pageID, + bool fillAlpha); void reserveTexture() const; void freeTexture(); diff --git a/yg/yg_tests/skin_loader_test.cpp b/yg/yg_tests/skin_loader_test.cpp index 6dd5326a96..4beac9007c 100644 --- a/yg/yg_tests/skin_loader_test.cpp +++ b/yg/yg_tests/skin_loader_test.cpp @@ -8,6 +8,6 @@ UNIT_TEST(SkinLoaderTest_Main) { GL_TEST_START; - shared_ptr rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, "", "", "", 2000000, yg::Rt8Bpp, false)); + shared_ptr rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, "", "", "", 2000000, yg::Rt8Bpp, false, false)); /*yg::Skin * skin = */loadSkin(rm, "basic.skn", 2, 2); }; diff --git a/yg/yg_tests/skin_test.cpp b/yg/yg_tests/skin_test.cpp index 3b57a68bc0..dea1b6bd3c 100644 --- a/yg/yg_tests/skin_test.cpp +++ b/yg/yg_tests/skin_test.cpp @@ -9,7 +9,7 @@ UNIT_TEST(SkinTest_Main) { GL_TEST_START; - shared_ptr rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 100, 100, 1, 128, 128, 15, "", "", "", 2000000, yg::Rt8Bpp, false)); + shared_ptr rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 100, 100, 1, 128, 128, 15, "", "", "", 2000000, yg::Rt8Bpp, false, false)); yg::Skin * skin = loadSkin(rm, "test.skn", 2, 2); double p0 [] = {1, 1};