mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
opengl: Remove struct usages to avoid copying (program)
This commit is contained in:
parent
2fbfd0bdcb
commit
c6cf8e5184
@ -54,7 +54,7 @@ const (
|
||||
invalidFramebuffer = (1 << 32) - 1
|
||||
)
|
||||
|
||||
func (p Program) id() programID {
|
||||
func getProgramID(p Program) programID {
|
||||
return programID(p)
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,7 @@ type Shader struct {
|
||||
*js.Object
|
||||
}
|
||||
|
||||
type Program struct {
|
||||
*js.Object
|
||||
}
|
||||
type Program interface{}
|
||||
|
||||
type Buffer struct {
|
||||
*js.Object
|
||||
@ -68,8 +66,8 @@ var (
|
||||
invalidFramebuffer = Framebuffer{}
|
||||
)
|
||||
|
||||
func (p Program) id() programID {
|
||||
return programID(p.Get("__ebiten_programId").Int())
|
||||
func getProgramID(p Program) programID {
|
||||
return programID(p.(*js.Object).Get("__ebiten_programId").Int())
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -301,7 +299,7 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
||||
gl := c.gl
|
||||
p := gl.CreateProgram()
|
||||
if p == nil {
|
||||
return Program{nil}, errors.New("opengl: glCreateProgram failed")
|
||||
return nil, errors.New("opengl: glCreateProgram failed")
|
||||
}
|
||||
p.Set("__ebiten_programId", c.lastProgramID)
|
||||
c.lastProgramID++
|
||||
@ -311,27 +309,27 @@ func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
||||
}
|
||||
gl.LinkProgram(p)
|
||||
if !gl.GetProgramParameterb(p, gl.LINK_STATUS) {
|
||||
return Program{nil}, errors.New("opengl: program error")
|
||||
return nil, errors.New("opengl: program error")
|
||||
}
|
||||
return Program{p}, nil
|
||||
return Program(p), nil
|
||||
}
|
||||
|
||||
func (c *Context) UseProgram(p Program) {
|
||||
gl := c.gl
|
||||
gl.UseProgram(p.Object)
|
||||
gl.UseProgram(p.(*js.Object))
|
||||
}
|
||||
|
||||
func (c *Context) DeleteProgram(p Program) {
|
||||
gl := c.gl
|
||||
if !gl.IsProgram(p.Object) {
|
||||
if !gl.IsProgram(p.(*js.Object)) {
|
||||
return
|
||||
}
|
||||
gl.DeleteProgram(p.Object)
|
||||
gl.DeleteProgram(p.(*js.Object))
|
||||
}
|
||||
|
||||
func (c *Context) getUniformLocationImpl(p Program, location string) uniformLocation {
|
||||
gl := c.gl
|
||||
return uniformLocation(gl.GetUniformLocation(p.Object, location))
|
||||
return uniformLocation(gl.GetUniformLocation(p.(*js.Object), location))
|
||||
}
|
||||
|
||||
func (c *Context) UniformInt(p Program, location string, v int) {
|
||||
@ -357,7 +355,7 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
|
||||
|
||||
func (c *Context) getAttribLocationImpl(p Program, location string) attribLocation {
|
||||
gl := c.gl
|
||||
return attribLocation(gl.GetAttribLocation(p.Object, location))
|
||||
return attribLocation(gl.GetAttribLocation(p.(*js.Object), location))
|
||||
}
|
||||
|
||||
func (c *Context) VertexAttribPointer(p Program, location string, size int, dataType DataType, stride int, offset int) {
|
||||
|
@ -53,7 +53,7 @@ var (
|
||||
invalidFramebuffer = Framebuffer(mgl.Framebuffer{(1 << 32) - 1})
|
||||
)
|
||||
|
||||
func (p Program) id() programID {
|
||||
func getProgramID(p Program) programID {
|
||||
return programID(p.Value)
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ func newLocationCache() *locationCache {
|
||||
}
|
||||
|
||||
func (c *locationCache) GetUniformLocation(context *Context, p Program, location string) uniformLocation {
|
||||
id := p.id()
|
||||
id := getProgramID(p)
|
||||
if _, ok := c.uniformLocationCache[id]; !ok {
|
||||
c.uniformLocationCache[id] = map[string]uniformLocation{}
|
||||
}
|
||||
@ -42,7 +42,7 @@ func (c *locationCache) GetUniformLocation(context *Context, p Program, location
|
||||
}
|
||||
|
||||
func (c *locationCache) GetAttribLocation(context *Context, p Program, location string) attribLocation {
|
||||
id := p.id()
|
||||
id := getProgramID(p)
|
||||
if _, ok := c.attribLocationCache[id]; !ok {
|
||||
c.attribLocationCache[id] = map[string]attribLocation{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user