private static unsafe List<Tuple<Point, uint>> ReadPixels(Rectangle target)
{
var result = new List<Tuple<Point, uint>>();
// get coded color.
using (var codedColor = new UnmanagedArray<Pixel>(target.Width * target.Height))
{
OpenGL.ReadPixels(target.X, target.Y, target.Width, target.Height,
OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, codedColor.Header);
var array = (Pixel*)codedColor.Header.ToPointer();
int index = 0;
var vertexIdList = new List<uint>();
for (int yOffset = target.Height - 1; yOffset >= 0; yOffset--)
{
for (int xOffset = 0; xOffset < target.Width; xOffset++)
{
Pixel pixel = array[index++];
// This is when (x, y) is not on background and some primitive is picked.
if (!pixel.IsWhite())
{
uint stageVertexId = pixel.ToStageVertexId();
if (!vertexIdList.Contains(stageVertexId))
{
result.Add(new Tuple<Point, uint>(
new Point(target.X + xOffset, target.Y + yOffset), stageVertexId));
vertexIdList.Add(stageVertexId);
}
}
}
}
}
return result;
}