public int GetTex(string guid)
        {
            int index;

            if (guidToIndex.TryGetValue(guid, out index))
            {
                usageCount[index]++;
            }
            else
            {
                if (indexPool.Length <= 0)
                {
                    throw new Exception("Texture Pool out of Range!!");
                }
                index = indexPool[indexPool.Length - 1];
                indexPool.RemoveLast();
                usageCount[index] = 1;
                guidToIndex.Add(guid, index);
                msb.Clear();
                msb.Add(ClusterMatResources.texturePath);
                msb.Add(guid);
                msb.Add(".mtex");
                streamer.AddStreamingCommand(msb.str, rt, index, streamingIndex);
                //TODO
                //Streaming Load Texture
            }

            return(index);
        }
 private void LoadThreadUpdate()
 {
     while (initialized)
     {
         while (true)
         {
             LoadCommand commd;
             lock (allCommands)
             {
                 if (allCommands.Count <= 0)
                 {
                     break;
                 }
                 commd = allCommands[0];
                 allCommands.RemoveAt(0);
             }
             msb.Clear();
             msb.Add(commd.paths.Ptr(), commd.paths.Length);
             commd.paths.Dispose();
             using (FileStream reader = new FileStream(msb.str, FileMode.Open, FileAccess.Read))
             {
                 reader.Read(loadBytes, 0, Mathf.Min(loadBytes.Length, (int)reader.Length));
             }
             targetUpdateTex  = commd.targetTex;
             currentLoadSlice = 0;
             targetIndex      = commd.targetIndex;
             updateIndex      = commd.formatIndex;
             //TODO
             mainThreadSyncEvent.WaitOne();
         }
         commandEmptyEvent.WaitOne();
     }
 }
Exemple #3
0
 private void Awake()
 {
     if (!msb.isCreated)
     {
         msb = new MStringBuilder(30);
     }
     msb.Clear();
     msb.Add("Assets/BinaryData/Irradiance/");
     msb.Add(probeName);
     msb.Add(".mpipe");
     if (!System.IO.File.Exists(msb.str))
     {
         Debug.LogError("Probe: " + probeName + "read Error! ");
         Destroy(gameObject);
         return;
     }
     else
     {
         using (System.IO.FileStream fs = new System.IO.FileStream(msb.str, System.IO.FileMode.Open, System.IO.FileAccess.Read))
         {
             byte[] arr = GetByteArray(fs.Length);
             fs.Read(arr, 0, (int)fs.Length);
             int3 *res = (int3 *)arr.Ptr();
             resolution = *res;
             if (resolution.x * resolution.y * resolution.z * sizeof(float3x3) != fs.Length - sizeof(int3))
             {
                 Debug.LogError("Data size incorrect!");
                 Destroy(gameObject);
                 return;
             }
             NativeArray <float3x3> allDatas = new NativeArray <float3x3>(resolution.x * resolution.y * resolution.z, Allocator.Temp);
             UnsafeUtility.MemCpy(allDatas.GetUnsafePtr(), res + 1, sizeof(float3x3) * allDatas.Length);
             RenderTextureDescriptor desc = new RenderTextureDescriptor
             {
                 colorFormat       = RenderTextureFormat.ARGBHalf,
                 dimension         = TextureDimension.Tex3D,
                 enableRandomWrite = true,
                 width             = resolution.x,
                 height            = resolution.y,
                 volumeDepth       = resolution.z,
                 msaaSamples       = 1
             };
             src0             = new RenderTexture(desc);
             src1             = new RenderTexture(desc);
             desc.colorFormat = RenderTextureFormat.RHalf;
             src2             = new RenderTexture(desc);
             shBuffer         = new ComputeBuffer(allDatas.Length, sizeof(float3x3));
             shBuffer.SetData(allDatas);
             ComputeShader shader = resources.shaders.occlusionProbeCalculate;
             int3 *        arrPtr = (int3 *)resolutionArray.Ptr();
             *arrPtr = resolution;
             shader.SetBuffer(2, "_SHBuffer", shBuffer);
             shader.SetTexture(2, "_Src0", src0);
             shader.SetTexture(2, "_Src1", src1);
             shader.SetTexture(2, "_Src2", src2);
             shader.SetInts("_Resolution", resolutionArray);
             shader.Dispatch(2, Mathf.CeilToInt(resolution.x / 4f), Mathf.CeilToInt(resolution.y / 4f), Mathf.CeilToInt(resolution.z / 4f));
             shBuffer.Dispose();
             allDatas.Dispose();
         }
     }
 }
 public void GetString(MStringBuilder msb)
 {
     msb.Clear();
     msb.Add((char *)ptr, CHAR_LENGTH);
 }