merge some interesting code from different branches.
thanks to galop1n for his work.
small improvement in shader caching
small random fixes in preparation for the big merge.