Example #1
0
    void UpdateTextureCpu()
    {
        int jobCount = threadPool.threadCount * 4; // 特に根拠ない

        if (jobCount == 0)
        {
            jobCount = 1;
        }
        int begin = 0;
        int rest  = cpuData.Length;
        int unit  = (cpuData.Length + jobCount - 1) / jobCount;

        for (int i = 0; i < jobCount; i++)
        {
            int beginCaptured = begin;
            int countCaptured = (unit <= rest) ? unit : rest;
            threadPool.AddJob(() => Job(cpuData, beginCaptured, countCaptured));
            begin += countCaptured;
            rest  -= countCaptured;
        }
        threadPool.Wait();
        texture2d.SetPixels32(cpuData);
        texture2d.Apply();
        image.texture = texture2d;
    }