예제 #1
0
 private Action <TileStream> CacheTileTextures(TextureBundle targetTexture)
 {
     return(tileStream =>
     {
         commandBuffer.IssuePluginCustomTextureUpdateV2(
             Native.Graphic.GetTextureUpdateCallback(),
             tileStream.Texture.Y, (uint)tileStream.TextureIndex);
         commandBuffer.IssuePluginCustomTextureUpdateV2(
             Native.Graphic.GetTextureUpdateCallback(),
             tileStream.Texture.U, (uint)tileStream.TextureIndex + 1);
         commandBuffer.IssuePluginCustomTextureUpdateV2(
             Native.Graphic.GetTextureUpdateCallback(),
             tileStream.Texture.V, (uint)tileStream.TextureIndex + 2);
         commandBuffer.CopyTexture(
             tileStream.Texture.Y, 0, 0, 0, 0,
             tileWidth, tileHeight, targetTexture.Y, 0, 0,
             tileStream.OffsetX, tileStream.OffsetY);
         commandBuffer.CopyTexture(
             tileStream.Texture.U, 0, 0, 0, 0,
             tileUvWidth, tileUvHeight, targetTexture.U, 0, 0,
             tileStream.UvOffsetX, tileStream.UvOffsetY);
         commandBuffer.CopyTexture(
             tileStream.Texture.V, 0, 0, 0, 0,
             tileUvWidth, tileUvHeight, targetTexture.V, 0, 0,
             tileStream.UvOffsetX, tileStream.UvOffsetY);
     });
 }
예제 #2
0
    void RebuildAtlasData()
    {
        foreach (var obj in serializedObject.targetObjects)
        {
            var atlas           = (WorldAtlas)obj;
            var atlasData       = CreateInstance <WorldAtlasData>();
            var atlasClientData = CreateInstance <WorldAtlasClientData>();

            LoadTerrainTextures(atlas, atlasClientData);

            var bundles = new TextureBundle[atlas.materials.Length];
            LoadTextureChannel(atlas, bundles, (x) => x.albedo, (b, s) => { b.albedo = s; return(b); }, "Albedo");
            LoadTextureChannel(atlas, bundles, (x) => x.normals, (b, s) => { b.normals = s; return(b); }, "Normals");
            LoadRHOTextureChannel(atlas, bundles, atlasClientData);

            atlasClientData.block2TextureSet = TextureBundle.OptimizeShaderIndices(ref bundles);

            SetChannelTextureIndices(atlasClientData.block2TextureSet, bundles, (x) => x.albedo, (x) => atlasClientData.albedo.textureSet2ArrayIndex   = x);
            SetChannelTextureIndices(atlasClientData.block2TextureSet, bundles, (x) => x.normals, (x) => atlasClientData.normals.textureSet2ArrayIndex = x);
            SetChannelTextureIndices(atlasClientData.block2TextureSet, bundles, (x) => x.rho, (x) => atlasClientData.rho.textureSet2ArrayIndex         = x);

            atlasClientData.renderMaterials = atlas.renderMaterials;

            atlasClientData = SaveAtlasClientData(atlas, atlasClientData);

            atlasData.atlasClientData = new WorldAtlasClientData_WRef();
            atlasData.atlasClientData.AssignFromAsset(atlasClientData);
            SaveAtlasData(atlas, atlasData);
        }
    }
예제 #3
0
        static int AddNew(List <TextureBundle> arr, TextureBundle bundle)
        {
            var index = arr.Count;

            arr.Add(bundle);
            return(index);
        }
예제 #4
0
    void LoadTextureChannel(WorldAtlas atlas, TextureBundle[] bundles, Func <WorldAtlasMaterialTextures, WorldAtlasMaterialTextures.TextureSet> getTexSetChannel, Func <TextureBundle, TextureSet, TextureBundle> setBundleChannel, string channelName)
    {
        List <Texture2D>  textures;
        List <TextureSet> indices;

        LoadTextureList(atlas, out textures, out indices, getTexSetChannel, channelName);
        TextureBundle.CopyChannelTextureSet(bundles, indices, setBundleChannel);
    }
예제 #5
0
 public static bool Equals(TextureBundle a, TextureBundle b)
 {
     return(TextureSet.Equals(a.albedo, b.albedo) &&
            TextureSet.Equals(a.normals, b.normals) &&
            //TextureSet.Equals(a.roughness, b.roughness) &&
            //TextureSet.Equals(a.ao, b.ao) &&
            //TextureSet.Equals(a.height, b.height) &&
            TextureSet.Equals(a.rho, b.rho));
 }
예제 #6
0
        static int AddIndex(List <TextureBundle> arr, TextureBundle bundle)
        {
            var index = arr.FindIndex(0, arr.Count, x => Equals(x, bundle));

            if (index < 0)
            {
                return(AddNew(arr, bundle));
            }
            return(index);
        }
예제 #7
0
        private void Start()
        {
            var hasConfig = Native.LoadEnvConfig();

            Config.TexturePoolSize = int.Parse(Native.LoadEnvConfigEntry("System.TexturePoolSize"));
            Debug.Log("Config.TexturePoolSize " + Config.TexturePoolSize);
            Assert.IsTrue(hasConfig);
            Native.Initialize();
            var mpdUrl = Native.Dash.Create();

            Debug.Log("Mpd URL " + mpdUrl);
            Native.Dash.GraphicInfo(ref frameCol, ref frameRow, ref frameWidth, ref frameHeight);
            Debug.Log("Frame Width " + frameWidth + " Height " + frameHeight + " Col " + frameCol + " Row " + frameRow);
            Assert.IsTrue(frameWidth > 0 && frameWidth % frameCol == 0);
            Assert.IsTrue(frameHeight > 0 && frameHeight % frameRow == 0);
            frameTexture             = new TextureBundle(frameWidth, frameHeight, true);
            frameTextureReadyQueue   = new Queue <TextureBundle>(Config.TexturePoolSize);
            frameTexturePrepareQueue = Enumerable.Range(0, Config.TexturePoolSize)
                                       .Select(
                index =>
            {
                var textureBundle = new TextureBundle(frameWidth, frameHeight, true)
                {
                    Index = index
                };
                return(textureBundle);
            })
                                       .Aggregate(new Queue <TextureBundle>(Config.TexturePoolSize),
                                                  (prepareQueue, texture) =>
            {
                prepareQueue.Enqueue(texture);
                return(prepareQueue);
            });
            Assert.AreEqual(frameTextureReadyQueue.Count, 0);
            Assert.AreEqual(frameTexturePrepareQueue.Count, Config.TexturePoolSize);
            sphereMaterial.SetTexture("_YTex", frameTexture.Y);
            sphereMaterial.SetTexture("_UTex", frameTexture.U);
            sphereMaterial.SetTexture("_VTex", frameTexture.V);
            tileWidth    = frameWidth / frameCol;
            tileHeight   = frameHeight / frameRow;
            tileUvWidth  = tileWidth / 2;
            tileUvHeight = tileHeight / 2;
            Debug.Log("Tile Width " + tileWidth + " Height " + tileHeight);
            tileStreamList = CreateTileList();
            commandBuffer  = new CommandBuffer();
            Native.Dash.Prefetch();
            Debug.Log("FrameRender launch");
            RenderState.UpdatePendingCount = tileStreamList.Count;
            trace = new Tracer();
            trace.InfoEvent("unity", "start");
            readyTileCollection   = new BlockingCollection <TileStream[]>(tileStreamList.Count);
            pollCancelTokenSource = new CancellationTokenSource();
            pollTileTask          = Task.Factory.StartNew(
                ProduceReadyTileStreams(pollCancelTokenSource.Token), TaskCreationOptions.LongRunning);
        }
예제 #8
0
        private void ReadAllTextures(BinaryReader reader)
        {
            TextureBundles = new TextureBundle[TextureInfos.Length];
            Textures       = new Bitmap[TextureBundles.Length];

            for (int i = 0; i < TextureInfos.Length; i++)
            {
                TextureBundle bundle = (TextureBundles[i] = new TextureBundle(reader, Header, TextureInfos[i]));
                Textures[i] = bundle.CreateTexture(FetchPalette(bundle.TextureFormat, bundle.PaletteIndex));
            }
        }
예제 #9
0
        public GxtBinary(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            Header = new SceGxtHeader(stream);

            Func <Stream, SceGxtTextureInfo> textureInfoGeneratorFunc;

            switch (Header.Version)
            {
            case 0x10000003: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV301(s)); }); break;

            case 0x10000002: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV201(s)); }); break;

            case 0x10000001: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV101(s)); }); break;

            default: throw new VersionNotImplementedException(Header.Version);
            }

            TextureInfos = new SceGxtTextureInfo[Header.NumTextures];
            for (int i = 0; i < TextureInfos.Length; i++)
            {
                TextureInfos[i] = textureInfoGeneratorFunc(stream);
            }

            // TODO: any other way to detect these?
            if (Encoding.ASCII.GetString(reader.ReadBytes(4)) == BUVChunk.ExpectedMagicNumber)
            {
                stream.Seek(-4, SeekOrigin.Current);
                BUVChunk = new BUVChunk(stream);
            }

            ReadAllBasePalettes(reader);
            ReadAllTextures(reader);

            if (BUVChunk != null)
            {
                // TODO: is it always texture 0?
                TextureBundle bundle = TextureBundles[0];

                BUVTextures = new Bitmap[BUVChunk.Entries.Length];
                for (int i = 0; i < BUVTextures.Length; i++)
                {
                    BUVEntry entry = BUVChunk.Entries[i];
                    using (Bitmap sourceImage = bundle.CreateTexture(FetchPalette(bundle.TextureFormat, entry.PaletteIndex)))
                    {
                        BUVTextures[i] = sourceImage.Clone(new Rectangle(entry.X, entry.Y, entry.Width, entry.Height), sourceImage.PixelFormat);
                    }
                }
            }
        }
예제 #10
0
 private void OverwriteMainTextures(TextureBundle sourceTexture)
 {
     commandBuffer.CopyTexture(sourceTexture.Y, frameTexture.Y);
     commandBuffer.CopyTexture(sourceTexture.U, frameTexture.U);
     commandBuffer.CopyTexture(sourceTexture.V, frameTexture.V);
 }
예제 #11
0
    void LoadRHOTextureChannel(WorldAtlas atlas, TextureBundle[] bundles, WorldAtlasClientData clientData)
    {
        var table = LoadRHOTextureTable(atlas);

        TextureBundle.CopyChannelTextureSet(bundles, table.indices, (b, s) => { b.rho = s; return(b); });
    }