add an important BeginEnder interface

This commit is contained in:
faiface 2016-11-22 23:18:04 +01:00
parent 44650c741f
commit b50852a3c2
1 changed files with 34 additions and 0 deletions

34
pixelgl/interface.go Normal file
View File

@ -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()
}