Пример #1
0
void CShader::Initialize()
{
    super::Initialize();
    bool bRet = Compile(&m_uId, (const GLchar*)m_pData->GetBuffer(), m_pData->GetWritePos());
    BEYONDENGINE_UNUSED_PARAM(bRet);
    BEATS_SAFE_DELETE(m_pData);
    BEATS_ASSERT(bRet, _T("Compile shader %s failed!"), GetFilePath().c_str());
}
Пример #2
0
void CPropertyGridEditor::InsertProperty(CPropertyDescriptionBase* pProperty, bool InPtrProperty)
{
    EReflectPropertyType type = pProperty->GetType();
    switch (type)
    {
    case eRPT_Bool:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatBool(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Float:
    case eRPT_Double:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatFloat(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Int:
    case eRPT_UInt:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatNumber(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Enum:
        m_pGrid->AppendCols();
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Ptr:
        {
            BEATS_ASSERT(!InPtrProperty, _T("ptr property Can't nested in grid mode!"));
            BEYONDENGINE_UNUSED_PARAM(InPtrProperty);
            CPtrPropertyDescription* pPtrProperty = down_cast<CPtrPropertyDescription*>(pProperty);
            BEATS_ASSERT(pPtrProperty != NULL);
            size_t uGuid = pPtrProperty->GetDerivedGuid() == 0 ? pPtrProperty->GetPtrGuid() : pPtrProperty->GetDerivedGuid();
            CComponentProxy* pProxy = down_cast<CComponentProxy*>(CComponentProxyManager::GetInstance()->GetComponentTemplate(uGuid));
            const std::vector<CPropertyDescriptionBase*>* pPropertyPool = pProxy->GetPropertyPool();
            for (size_t i = 0; i < pPropertyPool->size(); ++i)
            {
                InsertProperty(pPropertyPool->at(i), true);
            }
        }
        break;
    default:
        BEATS_ASSERT(false, _T("Unsupport col format of property type %d in list property grid mode!"), type);
        break;
    }
}
const CFontGlyph *CFreetypeFontFace::PrepareChar(wchar_t character, bool& bGlyphRestFlag)
{
    bGlyphRestFlag = false;
    m_glyphMapLocker.lock();
    auto itr = m_glyphMap.find(character);
    CFreetypeFontGlyph *pGlyph = itr != m_glyphMap.end() ? down_cast<CFreetypeFontGlyph *>(itr->second) : nullptr;
    m_glyphMapLocker.unlock();

    if (!pGlyph)
    {
        float outlineWidth = GetBorderWeight() * GetScaleFactor();
        ApplyFTSize();
        FT_Face pFontFace = m_pFont->GetFontFace();
        BEATS_ASSERT(pFontFace != NULL);
        bool bFindCharacterGlyph = FT_Get_Char_Index(pFontFace, character) != 0;
        BEYONDENGINE_UNUSED_PARAM(bFindCharacterGlyph);
        BEATS_ASSERT(bFindCharacterGlyph, _T("Character %d can't be found in all font face!"), character);
        FT_Error err = FT_Load_Char(pFontFace, character, FT_LOAD_NO_BITMAP);
        BEYONDENGINE_UNUSED_PARAM(err);
        BEATS_ASSERT(!err);

        FT_GlyphSlot pGlyphSlot = pFontFace->glyph;
        BEATS_ASSERT(pGlyphSlot != NULL);
        int32_t nBorderAdvanceX = pGlyphSlot->metrics.horiAdvance >> FT_SHIFT_NUM;
        int32_t nBorderAdvanceY = m_nLineHeight + (uint32_t)ceil(outlineWidth * 2.0f);
        int32_t nFontAdvanceX = nBorderAdvanceX;
        int32_t nFontHeight = 0;
        int32_t nBorderOriginWidth = 0;
        int32_t nFontOriginWidth = 0;
        int32_t nBorderHeight = 0;
        FT_BBox borderBox;
        FT_BBox fontBox;
        int32_t x = 0, y = 0;
        if (pGlyphSlot->format == FT_GLYPH_FORMAT_OUTLINE)
        {
            FT_Library ftLib = CFont::GetLibrary();
            // Set up a stroker.
            FT_Stroker stroker;
            FT_Stroker_New(ftLib, &stroker);
            FT_Stroker_Set(stroker, (int32_t)(outlineWidth * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
            FT_Glyph pOutlineGlyph, pInnerGlyph;
            if (FT_Get_Glyph(pGlyphSlot, &pOutlineGlyph) == 0 && FT_Get_Glyph(pGlyphSlot, &pInnerGlyph) == 0)
            {
                FT_Glyph_StrokeBorder(&pOutlineGlyph, stroker, 0, 1);
                BEATS_ASSERT(pOutlineGlyph->format == FT_GLYPH_FORMAT_OUTLINE && pInnerGlyph->format == FT_GLYPH_FORMAT_OUTLINE);
                FT_Outline *pOutLine = &reinterpret_cast<FT_OutlineGlyph>(pOutlineGlyph)->outline;
                FT_Glyph_Get_CBox(pOutlineGlyph, FT_GLYPH_BBOX_GRIDFIT, &borderBox);
                FT_Glyph_Get_CBox(pInnerGlyph, FT_GLYPH_BBOX_GRIDFIT, &fontBox);

                nBorderOriginWidth = (borderBox.xMax - borderBox.xMin) >> FT_SHIFT_NUM;

                nFontOriginWidth = (fontBox.xMax - fontBox.xMin) >> FT_SHIFT_NUM;
                int32_t nBorderWidth = nextMOE(nBorderOriginWidth); // Because our GL_UNPACK_ALIGNMENT should be 8 here.
                nBorderHeight = (borderBox.yMax - borderBox.yMin) >> FT_SHIFT_NUM;
                nFontHeight = (fontBox.yMax - fontBox.yMin) >> FT_SHIFT_NUM;
                x = pGlyphSlot->metrics.horiBearingX >> FT_SHIFT_NUM;
                y = pGlyphSlot->metrics.horiBearingY >> FT_SHIFT_NUM;
                if(nBorderAdvanceX < x + nBorderOriginWidth) // It is true for most of the time, because border size always greater than nAdvanceX
                {
                    nBorderAdvanceX = x + nBorderOriginWidth;
                }
                if (nFontAdvanceX < x + nFontOriginWidth)
                {
                    nFontAdvanceX = nFontOriginWidth; 
                }
                if(m_uCurrX + x + nBorderWidth > PAGE_WIDTH)
                {
                    m_uCurrX = 0;
                    m_uCurrY += (nBorderAdvanceY + m_nBorderSpace);
                    if (m_uCurrY + nBorderAdvanceY > PAGE_HEIGHT)
                    {
                        BEATS_WARNING(false, "Freetype texture buffer overflow for %d glyphs, we will rebuild this texture buffer.", (uint32_t)m_glyphMap.size());
                        ResetGlyphs();
                        bGlyphRestFlag = true;
                        return nullptr;
                    }
                }

                int32_t nDataSize = nBorderWidth * nBorderHeight;
                float fBorderOffsetY = 1.0f; // Makes it look like a shadow.
                unsigned char* pBorderData = RenderFontDataToBmp(nBorderWidth, nBorderHeight, -borderBox.xMin, (int32_t)(-borderBox.yMin * fBorderOffsetY), pOutLine);

                FT_Outline *pInnerOutLine = &reinterpret_cast<FT_OutlineGlyph>(pInnerGlyph)->outline;
                unsigned char* pFontData = RenderFontDataToBmp(nBorderWidth, nBorderHeight, -borderBox.xMin, -borderBox.yMin, pInnerOutLine);

                unsigned char* pAllData = new unsigned char[nDataSize * 2];
                for (int32_t i = 0; i < nDataSize; ++i)
                {
                    pAllData[i * 2] = pBorderData[i];
                    pAllData[i * 2 + 1] = pFontData[i];
                }

                BEATS_ASSERT(m_pTexture.Get() != nullptr);
                GLint nX = MAX((int32_t)m_uCurrX + x, 0);
                GLint nY = MAX((int32_t)m_uCurrY + (m_nAscender - y), 0);
                SFontUpdateImageInfo* pImageInfo = new SFontUpdateImageInfo;
                pImageInfo->m_pTexture = m_pTexture;
                pImageInfo->m_nWidth = nBorderWidth;
                pImageInfo->m_nHeight = nBorderHeight;
                pImageInfo->m_x = nX;
                pImageInfo->m_y = nY;
                pImageInfo->m_pData = pAllData;
                m_fontUpdateImageCacheMutex.lock();
                m_fontUpdateImageCache.push_back(pImageInfo);
                m_fontUpdateImageCacheMutex.unlock();

                // Clean up afterwards.
                FT_Stroker_Done(stroker);
                FT_Done_Glyph(pOutlineGlyph);
                FT_Done_Glyph(pInnerGlyph);
                BEATS_SAFE_DELETE_ARRAY(pBorderData);
                BEATS_SAFE_DELETE_ARRAY(pFontData);
            }
Пример #4
0
void CLanguageManager::LoadFromFile(ELanguageType language)
{
#ifdef EDITOR_MODE
    BEYONDENGINE_UNUSED_PARAM(language);
    m_languageMap.clear();
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Resource);
    filePath.append(_T("/LanguageConfig.xml"));
    if (CFilePathTool::GetInstance()->Exists(filePath.c_str()))
    {
        rapidxml::file<> fdoc(filePath.c_str());
        rapidxml::xml_document<> doc;
        try
        {
            doc.parse<rapidxml::parse_default>(fdoc.data());
            doc.m_pszFilePath = filePath.c_str();
        }
        catch (rapidxml::parse_error &e)
        {
            TCHAR info[MAX_PATH];
            _stprintf(info, _T("Load file :%s Failed! error :%s"), filePath.c_str(), e.what());
            MessageBox(BEYONDENGINE_HWND, info, _T("Load File Failed"), MB_OK | MB_ICONERROR);
        }
        uint32_t uCounter = 0;
        rapidxml::xml_node<>* pRootNode = doc.first_node("Language");
        rapidxml::xml_node<>* pLanguageNode = pRootNode->first_node("LanguageNode");
        while (pLanguageNode != nullptr)
        {
            uCounter++;
            TString strEnum = pLanguageNode->first_attribute("Enum")->value();
            BEATS_ASSERT(!strEnum.empty());
            if (pLanguageNode->first_attribute("Tag"))
            {
                TString strTag = pLanguageNode->first_attribute("Tag")->value();
                m_languageTagMap[strEnum] = strTag;
            }
            BEATS_ASSERT(m_languageMap.find(strEnum) == m_languageMap.end());
            std::map<ELanguageType, TString>& curMap = m_languageMap[strEnum];
            rapidxml::xml_node<>* pLanguageValueNode = pLanguageNode->first_node();
            while (pLanguageValueNode != nullptr)
            {
                TString languageTypeStr = pLanguageValueNode->name();
                ELanguageType languageType = eLT_Count;
                for (int j = 0; j < eLT_Count; ++j)
                {
                    if (pszLanguageTypeString[j] == languageTypeStr)
                    {
                        languageType = (ELanguageType)j;
                        break;
                    }
                }
                BEATS_ASSERT(curMap.find(languageType) == curMap.end());
                const TCHAR* pszValue = pLanguageValueNode->first_attribute("Value")->value();
                BEATS_ASSERT(_tcslen(pszValue) > 0);
                curMap[languageType] = pszValue;
                pLanguageValueNode = pLanguageValueNode->next_sibling();
            }
            pLanguageNode = pLanguageNode->next_sibling();
        }
        BEATS_ASSERT((uint32_t)_ttoi(pRootNode->first_attribute("Count")->value()) == uCounter);
    }
#else
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language);
    filePath.append(_T("/")).append(pszLanguageTypeString[language]).append(_T(".bin"));
    bool bFindLanguageFile = CFilePathTool::GetInstance()->Exists(filePath.c_str());
    BEATS_ASSERT(bFindLanguageFile, "Can't Find language file %s", filePath.c_str());
    if (bFindLanguageFile)
    {
        int count = 0;
        CSerializer tmp(filePath.c_str());
        tmp >> count;
        m_texts.clear();
        for (int i = 0; i < count; ++i)
        {
            ELanguageTextType textId = (ELanguageTextType)i;
            std::string strValue;
            tmp >> strValue;
            m_texts.emplace(textId, strValue);
        }
        tmp >> count;
        for (int i = 0; i < count; ++i)
        {
            uint32_t key;
            tmp >> key;
            BEATS_ASSERT(m_texts.find((ELanguageTextType)key) == m_texts.end());
            tmp >> m_texts[(ELanguageTextType)key];
        }
    }
#endif
}