Fix T41620

Issue here is that indices of edges will be incorrect when index of
vertices forming the edge is 3-0 or 2-0.

There are still issues here at uv edges where seam polygons intersect
each other but to solve that we need a better pass that detects uv edges
and pushes polygons along the "normal" of the edge instead of scaling
the polygon itself.
Support more object types scene-scale (on creation)

- lamp
- camera
- font
- empty & effector

Also fix inconsistency with apply transform
(modified shape-keys for meshes but not curve/lattice)
Cycles: Rebuild BVH from scratch if loading cache failed

Before this Cycles used to try using the cache even so it knew for the
fact that reading it from the disk failed. This change doesn't make it
more stable if someone will try to trick Cycles and give malformed data
but it solves general cases when Blender crashed during the cache write
and will preserve rendering from crashing when trying to use that partial
cache.
Expose preview setting operators on menus for sequencer and timeline
(could not find them anywhere before)
Fix opencollada not compiling after recent changes.
Cleanup: Event defines -> enums.

Also made all event type values as hexadecimal (mixing decimal, hexa and char values
is a nice way to make mistakes)!
Events: Fix ISKEYBOARD macro seeing INPUTCHANGE, WINDEACTIVATE and TIMER events
as keyboard ones!!!

Note: better solution would be to move those 'internal' events to the 0x5xxx area,
but need to talk with the team to be sure this won't break something first.
Fix T41665, stroke jittering used when setting the clone cursor
BMesh: report errors for invalid operator use

- invalid htype's into a slot
- duplicate htype's args to BMO_op_vinitf
Fix editmesh-connect with hidden geometry

- ignore hidden faces & verts
- when cutting a pair, select edges co-linear to the cut.

Also support creating a buffer from hidden elem's even if BMO_FLAG_RESPECT_HIDE is enabled.
(if the hflag used includes BM_ELEM_HIDDEN).
Fix editmesh-connect with adjacent vert selection

The result of running connect wasn't deterministic when adjacent vertices selected.
Fix second part of T41068 -- reflection mapping was wrong

Few things:
- reflect() takes arguments in this order: N, I, it was swapped
  in the previous code for some reason.

- Normal and view vectors are to be normalized. For the view
  vector we're now using shade_view() in order to deal with the
  ortho camera. However, Cycles does not support ortho camera
  for reflection, but this is easy to do in a separate commit.

- Reflection vector is to be in the world space. Kudos to
  Antony Riakiotakis for figuring this out!
Support window coordinates in cycles nodes.
A bit of a code cleanup in GLSL shader
Hacky fix for cleanup rBc23733d290c095ab77310b55c75293465891d5b8
Fixes localview and view-local layers

- Drawing grease pencil fail without scene-lock.
- Converting to curve failed without scene-lock.
- Outliner drag into viewport failed with local-view.
Hacky fixes can apply to more then one compiler.
TODO: really get rid of any and all bare #include <windows.h> in
the codebase in favour of central BLI_winstuff.h.
Better fix for T41464: Material Boundary bug in Freestyle.

The problem addressed here is that there was no mean to check if an iterator
points the last of the elements being iterated over.  Such checking is necessary
to reliably dereference the iterator (i.e., calling the operator*() method of the
underlying C++ iterator object).

Now Interface0DIterator and StrokeVertexIterator have an .at_last property
to check if an iterator points the last element.  Using this new API feature,
the present commit partly reverts the previous commit rBeb8964fb7f19 to
better address T41464.

Differential revision: https://developer.blender.org/D752

Author: flokkievids (Folkert de Vries)

Reviewed by: kjym3 (Tamito Kajiyama)
Fix T41682.

Bring back shading in texture painting.

This works now but it uses 3 texture units instead of two. Most GPUs of
DirectX 8 (OpenGL 1.4 should cover that) functionality even should have
those, but some old GPUs might not work with that. In any case, I hope
we will be moving to OpenGL 2.1 requirement soon anyway where 4-8
texture units are usually the norm.
Fix erase alpha not having any output on viewport after last commit.