mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
opengl: Reduce global variables
This commit is contained in:
parent
93f9d9fbb0
commit
ccf0acf7ca
@ -66,6 +66,7 @@ type context struct {
|
|||||||
gl *webgl.Context
|
gl *webgl.Context
|
||||||
lastFramebuffer Framebuffer
|
lastFramebuffer Framebuffer
|
||||||
locationCache *locationCache
|
locationCache *locationCache
|
||||||
|
lastProgramID programID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() *Context {
|
func NewContext() *Context {
|
||||||
@ -206,8 +207,6 @@ func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
|
|||||||
return Framebuffer{f}, nil
|
return Framebuffer{f}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastBindedFramebuffer *js.Object
|
|
||||||
|
|
||||||
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
|
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
|
||||||
// TODO: Not sure if Flush is needed here.
|
// TODO: Not sure if Flush is needed here.
|
||||||
if f.Object == nil {
|
if f.Object == nil {
|
||||||
@ -266,16 +265,14 @@ func (c *Context) GlslHighpSupported() bool {
|
|||||||
return gl.Call("getShaderPrecisionFormat", gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).Get("precision").Int() != 0
|
return gl.Call("getShaderPrecisionFormat", gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).Get("precision").Int() != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastProgramID programID = 0
|
|
||||||
|
|
||||||
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
p := gl.CreateProgram()
|
p := gl.CreateProgram()
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return Program{nil}, errors.New("opengl: glCreateProgram failed")
|
return Program{nil}, errors.New("opengl: glCreateProgram failed")
|
||||||
}
|
}
|
||||||
p.Set("__ebiten_programId", lastProgramID)
|
p.Set("__ebiten_programId", c.lastProgramID)
|
||||||
lastProgramID++
|
c.lastProgramID++
|
||||||
|
|
||||||
for _, shader := range shaders {
|
for _, shader := range shaders {
|
||||||
gl.AttachShader(p, shader.Object)
|
gl.AttachShader(p, shader.Object)
|
||||||
|
Loading…
Reference in New Issue
Block a user