Converting back to GLKit, with compat. layer.

Going back to GL, but abstracting away from a standard GLKit setup so we can swap in different drawing systems and approaches easily.

WIP: Not completely converted yet, but running for CG drawing.

• New model class(es), Scene. Currently holds and manages scene state (viewFocus) and 
	• SceneForCG and SceneForGLK handle drawing-system specific stuff.
	• SceneUtil has some generic util stuff.  I guess I like the approach of Ruby modules, even if mixing-in is manual.
• SceneViewController renamed/branched to SceneViewControllerForCG and SceneViewControllerForGLK
	• SceneViewControllerProtocol for interface agreeance
	• SceneViewControllerUtil for common functionality
• Switched AppDelegate over to use SceneViewControllerForCG.
• SceneViewController…s now takes a Scene instance as an initializer argument (or via property), and report input to the Scene.  Also sets up the SceneView with the Scene.
• Converted SceneViewControllerForCG's (previously SceneViewController's) _lastFiveDrawIntervals, _validDrawIntervalsCount and _lastFiveUpdateIntervals, _validUpdateIntervalsCount CFTimeInterval[]s and ints to _recentDrawIntervals and _recentUpdateIntervals NSMutableArrays, respectively.  The performance benefits weren't outweighing the C-array management headaches, especially now that the functionality has been shifted to SceneViewControllerUtil.
• SceneView just patches draw calls over to the Scene now.
	• GL drawing just uses SceneForGLK directly by delegation.
• xcodeproj file updated for all this, of course.
Refactored drawing into VisRep classes per entity

So the idea here is that rather than breaking draw routines by rendering system and genericized primitive shape, or by rendering system and specific visual entity, or lumping into collections per rendering system, we're instead grouping by visual entity so that alternate rendering code can be side-by-side and stylistic state (constant or variable) can be centralized in OO-oriented instances.

Also, I feel these VisReps should be able to persist their own state, yet be disposable and effortlessly recreatable.  They very much represent how the user perceives them; they shouldn't jump in appearance while in the field of view or nearby (in the user's visual awareness), but can alter or reset minimally when outside of that.

• The drawing that was previously all done in ArenaVisRep is now broken into new BackgroundVisRep, RingVisRep, OutsideRingVisRep, and InsideRingVisRep classes.
	• All of the VisReps are now contained within a VisRep subdir.
• Added validation to each of the VisReps, using a standardized validation pass.
	• Created a Validating protocol to standardize the valid property, isValid accessor, and validateBeingQuiet:terse: method.
• Eliminated ArenaVisRep's initWithPPI in favor of a PPI property.  (PPI is likely moving/change soon anyway.)
• Memoized pseudo-constants moved to the top of each file, with unique names (which makes them much easier to debug, and makes it easier understand that they're not instance-scope).
• Memoized pseudo-constant accessor logic cleaned up:
	• MemoizedInitializerForUIBezierPath typedef for the block being used
	• Blocks take in a handle to the static var now (instead of referencing them directly), and are passed the address of the static var.

Also:
• Changed SceneForCG's clearingColor to 50% gray.  This makes mistakes easier to spot (which is the current primary intent of clear-filling here).
• A few added and updated #pragma mark sections here and there.
• Updated xcodeproj file with additions and moves.

Notes:
• Currently a bit of duped code for the circle paths.
• All that validation stuff is stupid overkill, actually.  A good idea for elsewhere or the future, but I think I'm going to remove it from here for now and replace it with something much simpler.
Removed unnecessary instance variable initializers

Forgot that all for new instances is zeroed in Obj-C.  Many of these initializers weren't necessary.  I left in the ones that seem to have equivalent zero and non-zero states (booleans, starting indexes).
Removed all that validation junk

Removed it and replaced with what I really needed:
• PPI failsafe check before drawing
• Better nil cascading (early fetch, return on nil) for UIBezierPath pseudo-constants that rely on each other (so that a nil path earlier leads to a nil path, not a funky one)

I guess I was thinking I was in Ruby again and this would wrap up with a nice DSL-like syntax, which it totally didn't.

Also:
• Added `UIBezierPath *` return type to block definitions (in addition to the type).  Obj-C gets cranky when you have an alternate code flow that returns nil.  Added to all of them because consistency is cool.
Merge-update from branch 'master' into refactor/re-gl-ize
Fixed summa mora that whitespace.

• Spaces to tab indentation.
• Removed a stray space.
Setting up SceneViewControllerForGLK

Set up SceneViewControllerForGLK like SceneViewControllerForCG in respect to usage, and copied in GL essentials from an earlier version of SceneViewController (aaa249f^ “Elimnated GLKViewController, building its fuctionality into SceneViewController”^).

Currently minimally working (confirmed to be clearing via the `glClearColor` call in SceneForGLK#glkView:drawInRect:).  But hey, that's something!

• Switched to use SceneViewControllerForGLK and SceneForGLK in AppDelegate.

For SceneViewControllerForGLK:
• Added `Scene <GLKViewDelegate> *` instance var.  Chose to go with this over SceneForCLK because it describes just what we need to be happy, not unnecessary specifics.
	• Removed existing `Scene *` var.
• Created glkView casting accessor and overrode setView to vet only GLKViews (breaks Liskov substitution principle), and scene facade accessor which vets only what is allowed by the `Scene <GLKViewDelegate> *glkScene` property.
	• Using getter/setter methods explicitly within these setters/getters (also defining `self` or `super`) rather than using properties in order to make sure we're calling what we thing we're calling.
• Added `EAGLContext *` and `GLKBaseEffect *` instance vars and properties, for use with GL setup/teardown.
• GLKit-specific setup/teardown in loadView, viewDidLoad. didReceiveMemoryWarning methods.  Mostly what was in the old SceneViewController, with a bit of clean-up.
• Added GL setup/teardown methods setUpGL and tearDownGL;
	• Currently quite a bit of commented-out code in here.  Will be cleaned up— just trying to get this all working.

For SceneForGLK:
• Copied in kIrrelevantHue, kCircleRadius, clearingColor, circleFillColor, and circleEdgeColor from SceneForCG (will be consolidated later).
• Created empty drawContentLayerWithin:forView:, drawOverlayLayerWithin:forView:, drawCircleWithin:forView:, drawPrototypeNameOnLine:within:forView:, drawFramerateOnLine:within:forView: methods, to parallel SceneForCG methods.
• Basic GL clearing code (and commented-out draw code) in glkView:drawInRect:.
• In SceneForCG, moved clearingColor fill from drawWithin:forView to front-end method view:drawInRect: to match GL clearing in SceneForGLK#glkCiew:drawInRect:.
• Switched clearingColor in both SceneForCG and SceneForGLK to RGB (rather than the `WithWhite:` which generates in grayscale colorspace or something) for compat with glClearColor (it's easier said than done to get RGB values out of a non-RGB UIColor).

Also:
• Made kDisplayRefreshRate, kCircleRadius, and kIrrelevantHue consts (in both SceneViewControllerForCG & ForGLK) static; compiler complains if a const by the same name is used in multiple places and I can't remember why but staticing fixes it.
• Added `preferredFramesPerSecond` and `framesPerSecond` properties to SceneViewControllerProtocol to match GLKViewController and allow us to use these cross-`SceneViewControllerFor…`-class.
• Cleaned up SceneViewController#loadView code.
• Added `view:drawInRect:` to SceneForCG's header.
• Minor line spacing, variable naming, and comment improvements.
UIViewController isViewWindowless extension

UIViewController+SDTAdditions class extension with isViewWindowless method, in order to make `self.view.window == nil` (used commonly in didReceiveMemoryWarning) a bit more readable.

• Added UIViewController+SDTAdditions to project, included in Prefix file.
• Used in SceneViewControllerForCG and SceneViewControllerForGLK.
Finally drawing a circle.

Drawing the little blue overlay circle in SceneForGLK.

But the view frustums shaders matrices whatevers aren't set up.  Soon.

• Needs clean-up: there's a bunch of commented-out debug code lingering about.
• Added/uncommented draw calls to draw(ContentLayer/OverlayLayer/Circle/PrototypeNameOnLine:/FramerateOnLine:)Within:forView.  They're empty anyway.
WIP: It's a circle! (Fine oval, whatever.)

Yep, that's something.  But only slightly more than nothing.

Generally a lot of parallelizing SceneViewControllerForCG and SceneViewControllerForGLK here.  And fixes.  And GL setup code that I don't understand.

Fixes:
• Say, `SceneViewControllerForGLK#setUpGL` does a bunch of neat stuff… but doesn't get called from anywhere.  Hmm…  (Now called from viewDidLoad.)
• Um… where's the `dealloc` method for SceneViewControllerForGLK?  (Added, with appropriate releases.)
• Removed SceneViewControllerForCG's _viewLoaded state variable.  It's covered quite well by the present/nil state of the UIViewController parent class's view property.
• Now calling super within SceneViewControllerForCG's viewWillAppear: and viewDidAppear:.  Oops.

GL Machining:
• SceneViewControllerForGLK#setUpGL changed to use constantColor, per Learning OpenGL ES For iOS.  Commented out old light0 code (b/c it may be needed shortly; it's not exactly showing glColors).
• SceneViewControllerForGLK#setUpGL calling `[baseEffect prepareToDraw]`.  I feel it warrants reiteration that I really don't know what this does, 2
• SceneForGLK#drawCircleWithin: is now setting a glColor and translating the matrix (with a push and pop).  Also commented-out scale.
• SceneForGLK#glkView:drawInRect: is now correctly setting up the projection and modelview matrices.  I think.
• SceneForGLK#glkView:drawInRect: is enabling GL_BLEND and setting the blend function.  I'm not sure if this is the right place for this.
• SceneViewControllerForGLK now has an optional (commented-out, uck) context line for OpenGL ES 1.
• Suffixed GL “name” variables with `GLIdent`, to show that they're special GL-assigned identifiers.

Other Machining:
• SceneForGLK got a non-retaining baseEffect accessor, set and unset by SceneViewControllerForGLK.
• Bumped up preferredFramesPerSecond to 60 (set in AppDelegate).  This is primarily to get a better feel of how performant sloppy code is (even if 30 is the eventual target).
• Pausing the viewController in AppDelegate's applicationWillResignActive: and unpausing in applicationDidBecomeActive:.
	• Added paused property to SceneViewControllerProtocol.
• Nilling out (releasing) the viewController in AppDelegate's applicationWillTerminate: and applicationDidEnterBackground:.  I'm not sure if this is completely correct, but if it isn't we should be seeing hard failures shortly.
• Moved SceneViewControllerForCG/ForGLK's view unloading logic (and safeguards) from viewDidUnload to unloadView, and now calling that from didReceiveMemoryWarning and dealloc.
	• Added viewWillUnload, and viewDidUnload (both called by unlaodView, and the system in ≤iOS 5).
• Changed SceneViewControllerForGLK to use `SceneForGLK` instead of `Scene <GLKViewDelegate>`.  This makes access to the baseEffect much easier, albeit being less flexible (but there are so many that would just type it `id` and call it a day, so eh).

Reorganization:
• Turned stock usage comments in AppDelegate into @purpose function-level doc comments.
• SceneViewControllerRecentIntervalInfo struct, containing the 3 state elements necessary for FPS calculation: an intervals NSMutableArray, a maxSampleCount int, and a mostRecentIndex int.
• Moved interval update logic into SceneViewControllerUtil, taking either individual NSMutableArray, max count (previously assumed to be 5), and index elements or a SceneViewControllerRecentIntervalInfo struct element.
• Set up FPS calculation in SceneViewControllerForGLK using the SceneViewControllerRecentIntervalInfo struct and new SceneViewControllerUtil methods, and updated SceneViewControllerForCG to the same.
• Renamed SceneViewControllerForCG's common init from initState to initCommon and added the same to SceneViewControllerForGLK.
• Rearranged methods in SceneViewControllerForCG a bit to match the same `#pragma mark` groupings used by SceneViewControllerForGLK, and added a couple on both sides.
• Changed SceneForGLK#glkView:drawInRect:'s color extraction from the clearingColor UIColor to use simpler local variable names (red, green, etc. instead of clearColorRed, clearColorGreen) since this should be (and likely will be) wrapped up soon anyway.

Issues:
• SceneForGLK is preparing the GLKBaseEffect, which is assigned by hand from SceneViewControllerForGLK.  This is just nasty dependency-wise, and largely stems from my lack of understanding of why I need to make the prepareForDraw call.
• A lot of commented-out GL code.  I don't know what half this shit does.
• The matrix translate (and scale when it was uncommented, IIRC) within SceneForGLK#drawCircleWithin: doesn't really seem to be having any effect.  I hate Calculus.
• There's some debug SDTLogs floating about.  These shouldn't be here, given the current `debug/*` branch practice.

P.S. I gotta remember to move things around only in separate commits, otherwise it gets messy.
Removed debugging GL-oriented SDTLogs.
Mild code clean-up and modifications.

• AppDelegate sets the `SceneViewController…` as the window's `rootViewController` rather than adding the `SceneViewController…`'s view as a subview manually.
	• Also avoiding unnecessary property accesses and preparing the SceneViewController completely before setting to the property.
• Variables holding GL object names now have a ‘_glObjectName’ suffix instead of ‘GLIdent’.
	» I keep going back an forth on this one; ‘_glHandle’ seems to be the most technical, but “handle” isn't used in their docs.  Either way, the unit qualifier suffix (explicit logical suffix) helps.
	» It's not used anywhere (uncommented-out) right now anyway.
• Removed OpenGLES1 line.  We won't be using 1.
• Enabled baseEffect.colorMaterialEnabled.  Might need this.
• Moved GL_BLEND enable and set the blend function to GL_SRC_ALPHA/GL_ONE_MINUS_SRC_ALPHA from `glkView:drawInRect:` to `setUpGL`.
• Added VerticeData struct with GLKVector3 array and count int to SceneForGLK, for easier passing of created vertex data.
• Created SceneForGLK `createCircleVertices:` method to wrap up circle vertex calculation.
	• Uses arrays of `GLKVector3`s instead of just `GLfloat`s.
	• `_r` unit qualifier suffix is now `_rad`.
	• Returns the data in a VerticeData.
	• Note: Currently freeiing with just `free()` in `drawCircleWithin:forView:`.  This should probably be wrapped up for balance.
• Const'd `sliceCount`; doesn't really matter though.
• Minor comment additions and changes.
Working blue circle

The blue circle drawn by `drawCircleWithin:` is now working and nearly identical to CG rendition (by difference filtering screengrabs even).

Thing that were necessary to fix the ¼-screen white oval:
• `baseEffect.transform.projectionMatrix` and `baseEffect.transform.modelviewMatrix` are used to set the matrices with GLKit, not `glMatrixMode(GL_PROJECTION)` and `glMatrixMode(GL_MODELVIEW)`.  Setting those instead, and saving off the GLKMatrix4 and restoring it rather than `PushMatrix`/`PopMatrix`ing.
	• Now properly setting the size of the projection matrix in `glkView:drawInRect:`.
	• Now setting the modelview matrix to identity (or optionally 0.5-scale to be retina-ignorant) in `glkView:drawInRect:`.
	• Now properly translating (centering) and scaling (for both the circle and its border) the modelview matrix in `drawCircleWithin:`.
• `baseEffect.constantColor` is now set instead of its equivalent, `glColor`. 

Circle border:
• Added kCircleEdgeWidth constant to SceneForCG and SceneForGLK.
• Cloned `createCircleVertices:` to `createCircleVertices:hole:`, which although based on the same logic draws a circle with an inner circle cut out (size determined by the `holeRatio`) by creating a tri strip (effectively a quad strip) with one pair of tris (quad) for each slice.
	» This may be better done with a stencil buffer.  I plan to try this and maintain both implementation, performance testing later on.
	» Border is center-aligned (half outside of the fill, half overdrawing the fill) like CoreGraphics.
	» Has a `sliceCount`, `triCount`, and a `vertexCount` (and related iterators) to keep track of things.
• `drawCircleWithin:forView:` changed to have multiple funky bracketed scopes (for now) in order to get both the fill and border draws working.  This'll be revised soon.

Other improvements:
• Changed sliceCount to 32.  It's fast and looks great (with multisampling, especially).
• Calling `GLKVector3Make()` instead of setting `x`, `y`, and `z` individually.  _It's just cooler._

Other unnecessary, and removed (or commented out):
• The colorMaterialEnabled setting in `setUpGL` isn't needed for this (it's more of a lighting thing).
• The constantColor set in `setUpGL` is redundant (the default is already opaque white) and overridden before any and every draw call happens.
• The glViewport and glScissor calls.  I don't think these belong here, or should be called directly like this.
• `glPushMatrix` and `glPopMatrix` within `glkView:drawInRect:`.  Already mentioned above but worth noting that these are unnecessary in any form because the matrices are set up clean at the beginning of the draw.
• The `prepareToDraw` in `glkView:drawInRect:`.  I had no idea what it did when I put it here.
• An old `@fixme` on the glDrawArrays vertex count argument.

Remaining issues:
• We're still creating and freeing the vertices on every draw call.  Soon to be abstracted away, I hope.
Touch-Up: Missed one intended `GLKVector3Make()` call
Cleaned up old GL code.

Removed commented-out stuff:
• GLKView calls glViewport for us before every frame; we don't need to touch it.
• glScissor is unnecessary; the default is effectively the entire viewport.
• Retina half-scale modelviewMatrix call.  Don't need it (yet).
• Direct glMatrixMode/glLoadIdentity/glOrtho/glScale setup calls.  Handled by the GLKBaseEffect transform set.
• light0 calls.  No lighting here.
• Push/PopMatrix stuff.
• Extra unnecessary prepareToDraw calls.
• glColor4f calls.
• A lot left-over vertex stuff in setUpGL.
• A lot left-over vertex stuff in glkView:drawInRect:.

Clean-up:
• Moved prepareToDraw to the end of setUpGL.
UIColor extension w/ UIColorValues and accessors

Created UIColor+SDTAdditions with:
• UIColorValues struct, a pure-data storage type for HSBA, RGBA, or WA (white/alpha) color values.
• get…Values accessors methods for HSBA, RGBA, and WA.

Added to project and prefix file.
Now nearly matching the CoreGraphics version.

It's surprisingly fast (60 FPS with plenty of head room) even though it's drawing quite a few polys (256 slices for some of the bigger circles) and is unnecessarily repetitive (reloading vertex data onto the card on every draw).  Performance oddly drags on the iOS Simulator though.

After some clean-up, minor fixes, and addition of missing border (and _maybe_ that BG texture), we should be able to call this refactor complete.  It is a bit sloppy and repetitive right now (intentionally to an extent, in order to properly understand what we need where before wrapping up in models).

Bringing SceneViewControllerForGLK and SceneForGLK up to speed:
• UIResponder touch-handling methods (touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:, touchesCancelled:withEvent:) and state vars (_startTouchPosition and _prevTouchPosition) copied to SceneViewControllerForGLK from SceneViewControllerForCG.
	» These should also probably be in SceneViewControllerUtil.  I'm starting to really loathe this disjoint inheritance.
• SceneForGLK#drawContentLayerWithin:forView: fleshed out with focus-shifting transformation code (and arena draw call), akin to SceneForCG's equivalent.
	• Minor clean-up in SceneForCG#drawContentLayerWithin:forView: of renaming `theViewFocus_px` to just `viewFocus_px`.

VisRep GL drawing:
• Added glDrawUsing: to all the VisReps (Arena, Background, InsideRing, OutsideRing, and Ring).
	• ArenaVisRep#glDrawUsing: has call-outs to the other VisReps, like cgDrawWithin: (but with modelview resets before each).
	• BackgroundVisRep#glDrawUsing fills, but does not apply the texture (yet, or maybe not ever since the style may be changing soon).
	• InsideRingVisRep#glDrawUsing & OutsideRingVisRep#glDrawUsing fill their circles, but do not border them (yet).
	• OutsideRingVisRep#glDrawUsing 
• Renamed ArenaVisRep#drawWithin: to cgDrawWithin:.  I'm not sure how I missed this.
• Added lazy-init static-indefinitely-stored accessors using MemoizedVarInitializerForVerticeData to do the math and create the vertices, akin to the existing accessors for BezierPaths.
	» Still a lot of repeated code between classes (VerticeData struct, vertex calculation code, maybe some other stuff).  Ugg.
	• These methods are all (currently) copies or minor modifications of the circle and ring calculation methods createCircleVertices: and createRingVertices:hole: in SceneForGLK.
• static consts set up in each class for repeated stuff like sliceCount and oversizeRatio.

Overall clean-up and refactorings:
• `VerticeData` struct changed to more-common `_VerticeData` naming with typedef to `VerticeData`.
• `assemblyMode` GLenum added to VerticeData, intended for the glDrawArrays mode arg (GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, etc.).
• Using UIColorValues4 and accessors to simplify the process of color-grabbing for `baseEffect.constantColor`.
• Caching GLKBaseEffect in a baseEffect local var where repeatedly used.  Not sure why I wasn't doing this.
• Switched to a model of storing the modelview matrix outside of the draw method and restoring afterwards, rather than saving and restoring inside the draw method.
	» Although this is against the typical clean-up-after-yourself approach, it bit me hard once already when I missed a closing restore.  This way is much safer and saner.
	» Unfortunately, this may be a little less performant, since the restore happens regardless of changes to the matrix.  However, GLKBaseEffect may be making this negligible by only talking to GL with the end-result matrices in the call to prepareToDraw (this is likely the intent.)
	» Discovered this methodology via Apple docs/code, I believe.
• Switched naming from using `ModelviewMatrix` (such as `saveModelviewMatrix`) to just `Modelview` (`savedModelview`), or in some tightly-scoped instances just `modelview`.
	» It's easier, and AFAICDetermine it's non-ambiguous.
Merge branch 'master' into refactor/re-gl-ize

Conflicts in:
	App/ArenaVisRep.m
	App/SceneView.m
Which have evolved into:
	App/SceneForCG.m
	App/SceneForGLK.m
	App/VisReps/InsideRingVisRep.m
	App/VisReps/OutsideRingVisRep.m
	App/VisReps/RingVisRep.m

Resolved by moving the changes into the new locations.  This makes the CG drawing work as it does on master, but not GLK without further changes/additions.
GLK positioning now matching merged-in CG positioning
Rotated the calculation for each ring by half-a-slice

This makes the circles look just a little nicer near the pixel-aligned edges (top, right, bottom, left) at a minor cost of a little more roughness at the 45°-aligned edges (TR, BR, BL, TL).

As a result:
• Removed simple calculations for ring top-inner and top-outer and circle top-point (leaving center-point as-is), as the first couple of points also need trig now.
• Slice-calc loops now start `sliceI` at -1 instead of 0, so that we calculate those first points (I know, weird math).
• And of course, half the slice's angular delta subtracted as a part of each point's angle calculation.