本文整理汇总了Golang中golang.org/x/mobile/gl.Context.CreateProgram方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.CreateProgram方法的具体用法?Golang Context.CreateProgram怎么用?Golang Context.CreateProgram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/mobile/gl.Context
的用法示例。
在下文中一共展示了Context.CreateProgram方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateProgram
// CreateProgram creates, compiles, and links a gl.Program.
func CreateProgram(glctx gl.Context, vertexSrc, fragmentSrc string) (gl.Program, error) {
program := glctx.CreateProgram()
if program.Value == 0 {
return gl.Program{}, fmt.Errorf("glutil: no programs available")
}
vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexSrc)
if err != nil {
return gl.Program{}, err
}
fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentSrc)
if err != nil {
glctx.DeleteShader(vertexShader)
return gl.Program{}, err
}
glctx.AttachShader(program, vertexShader)
glctx.AttachShader(program, fragmentShader)
glctx.LinkProgram(program)
// Flag shaders for deletion when program is unlinked.
glctx.DeleteShader(vertexShader)
glctx.DeleteShader(fragmentShader)
if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 {
defer glctx.DeleteProgram(program)
return gl.Program{}, fmt.Errorf("glutil: %s", glctx.GetProgramInfoLog(program))
}
return program, nil
}
示例2: LoadProgram
// LoadProgram reads shader sources from the asset repository, compiles, and
// links them into a program.
func LoadProgram(glctx gl.Context, vertexAsset, fragmentAsset string) (program gl.Program, err error) {
log.Println("LoadProgram:", vertexAsset, fragmentAsset)
program = glctx.CreateProgram()
if program.Value == 0 {
return gl.Program{}, fmt.Errorf("glutil: no programs available")
}
err = LoadShaders(glctx, program, vertexAsset, fragmentAsset)
return
}
示例3: CreateAndLink
func (prg *Program) CreateAndLink(ctx gl.Context, compilers ...func(gl.Context) gl.Shader) {
prg.Program = ctx.CreateProgram()
for _, c := range compilers {
s := c(ctx)
ctx.AttachShader(prg.Program, s)
defer ctx.DeleteShader(s)
}
ctx.LinkProgram(prg.Program)
if ctx.GetProgrami(prg.Program, gl.LINK_STATUS) == 0 {
log.Fatalf("program link: %s", ctx.GetProgramInfoLog(prg.Program))
}
}