From b50852a3c285a5163d7deea02b4b3b500bd7027a Mon Sep 17 00:00:00 2001 From: faiface Date: Tue, 22 Nov 2016 23:18:04 +0100 Subject: [PATCH] add an important BeginEnder interface --- pixelgl/interface.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pixelgl/interface.go diff --git a/pixelgl/interface.go b/pixelgl/interface.go new file mode 100644 index 0000000..90b433a --- /dev/null +++ b/pixelgl/interface.go @@ -0,0 +1,34 @@ +package pixelgl + +// BeginEnder is an interface for manipulating OpenGL state. +// +// OpenGL is a state machine and as such, it is natural to manipulate it in a begin-end manner. +// This interface is intended for all OpenGL objects, that can begin being active and end being active +// such as windows, vertex arrays, vertex buffers, textures, shaders, pretty much everything. +// +// It might seem natural to use BeginEnders this way: +// +// window.Begin() +// shader.Begin() +// texture.Begin() +// vertexarray.Begin() +// vertexarray.Draw() +// vertexarray.End() +// texture.End() +// shader.End() +// window.End() +// +// Don't do this! A better practice is to make a BeginEnder so that it wraps another BeginEnder like this: +// +// shader = NewShader(window) +// texture = NewTexture(shader) +// vertexarray = NewVertexArray(texture) +// // now, somewhere else in your code, instead of calling numerous Begin/Ends, you just calling +// vertexarray.Draw() +// +// The final single call to draw a vertex array executes all of the Begins and Ends, because the objects are +// wrapped around each other. +type BeginEnder interface { + Begin() + End() +}