Beispiel #1
0
        private static void RenderFunc(
            IRayTracer rayTracer,
            int pixelWidth,
            ConcurrentQueue <int> rowQueue,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            try
            {
                while (rowQueue.TryDequeue(out int y))
                {
                    var rowPixels = new List <PixelData>();
                    for (var x = 0; x < pixelWidth; x++)
                    {
                        rowPixels.Add(rayTracer.GetPixelColor(x, y));
                    }

                    resultQueue.Enqueue(new RenderLineResult(y, rowPixels));
                    queueDataAvailableEvent.Set();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #2
0
        private static void RenderFunc(
            IRayTracer rayTracer,
            ConcurrentQueue <int> rowQueue,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            while (rowQueue.TryDequeue(out var y))
            {
                // Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} starting to render row: {y}");
                var rowPixels = new List <ColorVector>();
                for (var x = 0; x < rayTracer.RenderData.Width; x++)
                {
                    rowPixels.Add(rayTracer.GetPixelColor(x, y));
                }

                resultQueue.Enqueue(new RenderLineResult(y, rowPixels));
                queueDataAvailableEvent.Set();
            }
        }
Beispiel #3
0
 private static void RenderFunc(
     IRayTracer rayTracer,
     ConcurrentQueue <RenderInput> inputQueue,
     ConcurrentQueue <RenderResult> resultQueue,
     AutoResetEvent queueDataAvailableEvent)
 {
     try
     {
         while (inputQueue.TryDequeue(out RenderInput input))
         {
             var pixelData = rayTracer.GetPixelColor(input.X, input.Y);
             resultQueue.Enqueue(new RenderResult(input.X, input.Y, pixelData));
             queueDataAvailableEvent.Set();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }