IUnknown* DX11Engine::createTexture2D_SRV(IUnknown* pDeviceIn, const Texture& info, const char* buffer, size_t size, const char* name) const { auto pDevice = reinterpret_cast<ID3D11Device*>(pDeviceIn); HRESULT hr; D3D11_TEXTURE2D_DESC tex = { uint32_t(info.mWidth), uint32_t(info.mHeight), uint32_t(info.mMipCount), uint32_t(info.mArraySize), info.mFormat, { 1, 0 }, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0 }; if(info.eMiscGenerateMipMaps) { tex.MipLevels = 0; tex.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; tex.BindFlags |= D3D11_BIND_RENDER_TARGET; } uint32_t bpp = getBitsPerPixel(info.mFormat); int level = 1; if (info.eMiscGenerateMipMaps) level = log2i(std::max(info.mWidth, info.mHeight)) + 1; boost::container::small_vector<D3D11_SUBRESOURCE_DATA, 12> subres(level); int w = info.mWidth; int h = info.mHeight; for (int i = 0; i != level; ++i) { subres[i] = D3D11_SUBRESOURCE_DATA{ buffer, w * bpp / 8, 0 }; buffer += mipmap_size<1>(w, h, bpp); w = next_mip_size(w); h = next_mip_size(h); } std::unique_ptr<ID3D11Texture2D, COMDeleter> pTex; std::unique_ptr<ID3D11ShaderResourceView, COMDeleter> pSRV; CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(D3D11_SRV_DIMENSION_TEXTURE2D); V(pDevice->CreateTexture2D(&tex, subres.data(), ref(pTex))); V(pDevice->CreateShaderResourceView(pTex.get(), &srvDesc, ref(pSRV))); STAR_SET_DEBUG_NAME(pSRV, size, name); return pSRV.release(); }
/** * Attempt to find an entry in a single resource bundle. This is * a one-sided lookup. findInStaticStore() performs up to two such * lookups, one for the source, and one for the target. * * Do not perform fallback. Return 0 on failure. * * On success, create a new Entry object, populate it, and return it. * The caller owns the returned object. */ TransliteratorEntry* TransliteratorRegistry::findInBundle(const TransliteratorSpec& specToOpen, const TransliteratorSpec& specToFind, const UnicodeString& variant, UTransDirection direction) { UnicodeString utag; UnicodeString resStr; int32_t pass; for (pass=0; pass<2; ++pass) { utag.truncate(0); // First try either TransliteratorTo_xxx or // TransliterateFrom_xxx, then try the bidirectional // Transliterate_xxx. This precedence order is arbitrary // but must be consistent and documented. if (pass == 0) { utag.append(direction == UTRANS_FORWARD ? TRANSLITERATE_TO : TRANSLITERATE_FROM, -1); } else { utag.append(TRANSLITERATE, -1); } UnicodeString s(specToFind.get()); utag.append(s.toUpper("")); UErrorCode status = U_ZERO_ERROR; ResourceBundle subres(specToOpen.getBundle().get( CharString().appendInvariantChars(utag, status).data(), status)); if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) { continue; } s.truncate(0); if (specToOpen.get() != LocaleUtility::initNameFromLocale(subres.getLocale(), s)) { continue; } if (variant.length() != 0) { status = U_ZERO_ERROR; resStr = subres.getStringEx( CharString().appendInvariantChars(variant, status).data(), status); if (U_SUCCESS(status)) { // Exit loop successfully break; } } else { // Variant is empty, which means match the first variant listed. status = U_ZERO_ERROR; resStr = subres.getStringEx(1, status); if (U_SUCCESS(status)) { // Exit loop successfully break; } } } if (pass==2) { // Failed return NULL; } // We have succeeded in loading a string from the locale // resources. Create a new registry entry to hold it and return it. TransliteratorEntry *entry = new TransliteratorEntry(); if (entry != 0) { // The direction is always forward for the // TransliterateTo_xxx and TransliterateFrom_xxx // items; those are unidirectional forward rules. // For the bidirectional Transliterate_xxx items, // the direction is the value passed in to this // function. int32_t dir = (pass == 0) ? UTRANS_FORWARD : direction; entry->entryType = TransliteratorEntry::LOCALE_RULES; entry->stringArg = resStr; entry->intArg = dir; } return entry; }