void BuiltinResources::generateTextures() { StringStream ss; SPtr<PixelData> blackPixelData = PixelData::create(2, 2, 1, PF_RGBA8); blackPixelData->setColorAt(Color::Black, 0, 0); blackPixelData->setColorAt(Color::Black, 0, 1); blackPixelData->setColorAt(Color::Black, 1, 0); blackPixelData->setColorAt(Color::Black, 1, 1); SPtr<Texture> blackTexture = Texture::_createPtr(blackPixelData); SPtr<PixelData> whitePixelData = PixelData::create(2, 2, 1, PF_RGBA8); whitePixelData->setColorAt(Color::White, 0, 0); whitePixelData->setColorAt(Color::White, 0, 1); whitePixelData->setColorAt(Color::White, 1, 0); whitePixelData->setColorAt(Color::White, 1, 1); SPtr<Texture> whiteTexture = Texture::_createPtr(whitePixelData); SPtr<PixelData> normalPixelData = PixelData::create(2, 2, 1, PF_RGBA8); Color encodedNormal(0.5f, 0.5f, 1.0f); normalPixelData->setColorAt(encodedNormal, 0, 0); normalPixelData->setColorAt(encodedNormal, 0, 1); normalPixelData->setColorAt(encodedNormal, 1, 0); normalPixelData->setColorAt(encodedNormal, 1, 1); SPtr<Texture> normalTexture = Texture::_createPtr(normalPixelData); // Save all textures Path outputDir = mBuiltinDataFolder + TEXTURE_FOLDER; auto saveTexture = [&](const Path& path, const SPtr<Texture>& texture, const String& uuid) { HResource textureResource = gResources()._createResourceHandle(texture, UUID(uuid)); gResources().save(textureResource, path, true); mResourceManifest->registerResource(textureResource.getUUID(), path); }; Path whitePath = outputDir + TextureWhiteFile; saveTexture(whitePath, whiteTexture, "1f7d0e3f-d81b-42ee-9d31-cb6c6fc55824"); Path blackPath = outputDir + TextureBlackFile; saveTexture(blackPath, blackTexture, "149a5c05-9570-4915-9dbd-69acf88b865b"); Path normalPath = outputDir + TextureNormalFile; saveTexture(normalPath, normalTexture, "afb29163-1ef0-4440-9cfb-c1ebb3b3d452"); }
void TextureCoreManager::onStartUp() { // White built-in texture SPtr<TextureCore> whiteTexture = createTexture(TEX_TYPE_2D, 2, 2, 1, 0, PF_R8G8B8A8, TU_STATIC); SPtr<PixelData> whitePixelData = PixelData::create(2, 2, 1, PF_R8G8B8A8); whitePixelData->setColorAt(Color::White, 0, 0); whitePixelData->setColorAt(Color::White, 0, 1); whitePixelData->setColorAt(Color::White, 1, 0); whitePixelData->setColorAt(Color::White, 1, 1); whiteTexture->writeData(*whitePixelData); TextureCore::WHITE = whiteTexture; // Black built-in texture SPtr<TextureCore> blackTexture = createTexture(TEX_TYPE_2D, 2, 2, 1, 0, PF_R8G8B8A8, TU_STATIC); SPtr<PixelData> blackPixelData = PixelData::create(2, 2, 1, PF_R8G8B8A8); blackPixelData->setColorAt(Color::Black, 0, 0); blackPixelData->setColorAt(Color::Black, 0, 1); blackPixelData->setColorAt(Color::Black, 1, 0); blackPixelData->setColorAt(Color::Black, 1, 1); blackTexture->writeData(*blackPixelData); TextureCore::BLACK = blackTexture; // Normal (Y = Up) built-in texture SPtr<TextureCore> normalTexture = createTexture(TEX_TYPE_2D, 2, 2, 1, 0, PF_R8G8B8A8, TU_STATIC); SPtr<PixelData> normalPixelData = PixelData::create(2, 2, 1, PF_R8G8B8A8); Color encodedNormal(0.5f, 0.5f, 1.0f); normalPixelData->setColorAt(encodedNormal, 0, 0); normalPixelData->setColorAt(encodedNormal, 0, 1); normalPixelData->setColorAt(encodedNormal, 1, 0); normalPixelData->setColorAt(encodedNormal, 1, 1); normalTexture->writeData(*normalPixelData); TextureCore::NORMAL = normalTexture; }