// Reads a scene frame from the GPU backbuffer and sends it via ZMQ. void sendFrameOnWire() { // Read pixels from screen backbuffer (expensive). rendered_frame.ReadPixels(new Rect(0, 0, state.screenWidth, state.screenHeight), 0, 0); rendered_frame.Apply(); // Might not actually be needed since only applies setpixel changes. byte[] raw = rendered_frame.GetRawTextureData(); // Compress and send the image in a different thread. Task.Run(() => { // Get metadata RenderMetadata_t metadata = new RenderMetadata_t(state); // Create packet metadata var msg = new NetMQMessage(); msg.Append(JsonConvert.SerializeObject(metadata)); // Process each camera's image, compress the image, and serialize the result. // Compression is disabled for now... // Stride is also disabled for now. Outputs RGB blocks with stride 3. List <byte[]> images = state.cameras.AsParallel().Select(cam => get_raw_image(cam, raw, metadata.cameraIDs.Count())).ToList(); // Append images to message images.ForEach(image => msg.Append(image)); // Send the message. lock (socket_lock) { push_socket.TrySendMultipartMessage(msg); } }); }