Skip to content

Instantly share code, notes, and snippets.

@ssylvan
Last active September 7, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssylvan/80debcac11605f357e5a45d7aa55058d to your computer and use it in GitHub Desktop.
Save ssylvan/80debcac11605f357e5a45d7aa55058d to your computer and use it in GitHub Desktop.
// 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