Last active
September 7, 2018 17:24
-
-
Save ssylvan/80debcac11605f357e5a45d7aa55058d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example: | |
ctx.ClearScreen(); | |
let ctx = ctx.BeginTriangleStrip(); // Old context is *consumed*, new context has different methods | |
// ctx.ClearScreen(); // ERRROR: not supported on this context | |
ctx.AddVertex(...); | |
ctx.AddVertex(...); | |
ctx.AddVertex(...); | |
let ctx = ctx.End(); | |
ctx.Present(); // This is now available. | |
// So basically, shadowing is neat when you have some kind of "protocol" and want to enforce it | |
// statically, because the same "object" can be in different states, represented by changing its | |
// type over time, which lets the compiler catch mistakes. | |
// Without shadowing this gets messier: | |
ctx.ClearScreen(); | |
let tri_strip_ctx = ctx.BeginTriangleStrip(); | |
tri_strip_ctx.AddVertex(...); | |
tri_strip_ctx.AddVertex(...); | |
tri_strip_ctx.AddVertex(...); | |
// What do we call this? It's conceptually the same as the first ctx.. Should we keep incrementing this number? | |
let ctx2 = tri_strip.End(); | |
ctx2.Present(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment