From f2460b34da56f264b29622811df858dddf6fd00d Mon Sep 17 00:00:00 2001 From: faiface Date: Fri, 2 Dec 2016 18:15:47 +0100 Subject: [PATCH] add ContextHolder --- pixelgl/interface.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/pixelgl/interface.go b/pixelgl/interface.go index 2b7fbd6..2a272b0 100644 --- a/pixelgl/interface.go +++ b/pixelgl/interface.go @@ -36,13 +36,7 @@ type Doer interface { // // This type does *not* represent an OpenGL context in the OpenGL terminology. type Context struct { - vertexFormat VertexFormat - shader *Shader -} - -// VertexFormat returns the current vertex format. -func (c Context) VertexFormat() VertexFormat { - return c.vertexFormat + shader *Shader } // Shader returns the current shader. @@ -50,18 +44,19 @@ func (c Context) Shader() *Shader { return c.shader } -// WithVertexFormat returns a copy of this context with the specified vertex format. -func (c Context) WithVertexFormat(vf VertexFormat) Context { - return Context{ - vertexFormat: vf, - shader: c.shader, - } -} - // WithShader returns a copy of this context with the specified shader. func (c Context) WithShader(s *Shader) Context { return Context{ - vertexFormat: c.vertexFormat, - shader: s, + shader: s, } } + +// ContextHolder is a root Doer with no parent. It simply forwards a context to a child. +type ContextHolder struct { + Context +} + +// Do calls sub and passes it the held context. +func (ch *ContextHolder) Do(sub func(ctx Context)) { + sub(ch.Context) +}