Added MESA-specific optimizations and compatibility. Fixed Linux build.