mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
opengl: Change Shader/Program/Buffer to js.Value
This commit is contained in:
parent
2497b64cf7
commit
3fbe8d8ecb
@ -29,9 +29,9 @@ import (
|
|||||||
type (
|
type (
|
||||||
Texture js.Value
|
Texture js.Value
|
||||||
Framebuffer js.Value
|
Framebuffer js.Value
|
||||||
Shader interface{}
|
Shader js.Value
|
||||||
Program interface{}
|
Program js.Value
|
||||||
Buffer interface{}
|
Buffer js.Value
|
||||||
uniformLocation js.Value
|
uniformLocation js.Value
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ type programID int
|
|||||||
var InvalidTexture = Texture(js.Null)
|
var InvalidTexture = Texture(js.Null)
|
||||||
|
|
||||||
func getProgramID(p Program) programID {
|
func getProgramID(p Program) programID {
|
||||||
return programID(p.(js.Value).Get("__ebiten_programId").Int())
|
return programID(js.Value(p).Get("__ebiten_programId").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -241,46 +241,46 @@ func (c *Context) NewShader(shaderType ShaderType, source string) (Shader, error
|
|||||||
gl := c.gl
|
gl := c.gl
|
||||||
s := gl.Call("createShader", int(shaderType))
|
s := gl.Call("createShader", int(shaderType))
|
||||||
if s == js.Null {
|
if s == js.Null {
|
||||||
return nil, fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
|
return Shader(js.Null), fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.Call("shaderSource", s, source)
|
gl.Call("shaderSource", js.Value(s), source)
|
||||||
gl.Call("compileShader", s)
|
gl.Call("compileShader", js.Value(s))
|
||||||
|
|
||||||
if !gl.Call("getShaderParameter", s, gl.Get("COMPILE_STATUS")).Bool() {
|
if !gl.Call("getShaderParameter", js.Value(s), gl.Get("COMPILE_STATUS")).Bool() {
|
||||||
log := gl.Call("getShaderInfoLog", s)
|
log := gl.Call("getShaderInfoLog", js.Value(s))
|
||||||
return nil, fmt.Errorf("opengl: shader compile failed: %s", log)
|
return Shader(js.Null), fmt.Errorf("opengl: shader compile failed: %s", log)
|
||||||
}
|
}
|
||||||
return s, nil
|
return Shader(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) DeleteShader(s Shader) {
|
func (c *Context) DeleteShader(s Shader) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.Call("deleteShader", s)
|
gl.Call("deleteShader", js.Value(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
func (c *Context) NewProgram(shaders []Shader) (Program, error) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
p := gl.Call("createProgram")
|
p := gl.Call("createProgram")
|
||||||
if p == js.Null {
|
if p == js.Null {
|
||||||
return nil, errors.New("opengl: glCreateProgram failed")
|
return Program(js.Null), errors.New("opengl: glCreateProgram failed")
|
||||||
}
|
}
|
||||||
p.Set("__ebiten_programId", int(c.lastProgramID))
|
p.Set("__ebiten_programId", int(c.lastProgramID))
|
||||||
c.lastProgramID++
|
c.lastProgramID++
|
||||||
|
|
||||||
for _, shader := range shaders {
|
for _, shader := range shaders {
|
||||||
gl.Call("attachShader", p, shader)
|
gl.Call("attachShader", js.Value(p), js.Value(shader))
|
||||||
}
|
}
|
||||||
gl.Call("linkProgram", p)
|
gl.Call("linkProgram", js.Value(p))
|
||||||
if !gl.Call("getProgramParameter", p, gl.Get("LINK_STATUS")).Bool() {
|
if !gl.Call("getProgramParameter", js.Value(p), gl.Get("LINK_STATUS")).Bool() {
|
||||||
return nil, errors.New("opengl: program error")
|
return Program(js.Null), errors.New("opengl: program error")
|
||||||
}
|
}
|
||||||
return p, nil
|
return Program(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) UseProgram(p Program) {
|
func (c *Context) UseProgram(p Program) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.Call("useProgram", p)
|
gl.Call("useProgram", js.Value(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) DeleteProgram(p Program) {
|
func (c *Context) DeleteProgram(p Program) {
|
||||||
@ -293,7 +293,7 @@ func (c *Context) DeleteProgram(p Program) {
|
|||||||
|
|
||||||
func (c *Context) getUniformLocationImpl(p Program, location string) uniformLocation {
|
func (c *Context) getUniformLocationImpl(p Program, location string) uniformLocation {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
return uniformLocation(gl.Call("getUniformLocation", p, location))
|
return uniformLocation(gl.Call("getUniformLocation", js.Value(p), location))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) UniformInt(p Program, location string, v int) {
|
func (c *Context) UniformInt(p Program, location string, v int) {
|
||||||
@ -351,7 +351,7 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
|
|||||||
|
|
||||||
func (c *Context) getAttribLocationImpl(p Program, location string) attribLocation {
|
func (c *Context) getAttribLocationImpl(p Program, location string) attribLocation {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
return attribLocation(gl.Call("getAttribLocation", p, location).Int())
|
return attribLocation(gl.Call("getAttribLocation", js.Value(p), location).Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) VertexAttribPointer(p Program, location string, size int, dataType DataType, stride int, offset int) {
|
func (c *Context) VertexAttribPointer(p Program, location string, size int, dataType DataType, stride int, offset int) {
|
||||||
@ -375,22 +375,22 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
|
|||||||
func (c *Context) NewArrayBuffer(size int) Buffer {
|
func (c *Context) NewArrayBuffer(size int) Buffer {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
b := gl.Call("createBuffer")
|
b := gl.Call("createBuffer")
|
||||||
gl.Call("bindBuffer", int(ArrayBuffer), b)
|
gl.Call("bindBuffer", int(ArrayBuffer), js.Value(b))
|
||||||
gl.Call("bufferData", int(ArrayBuffer), size, int(DynamicDraw))
|
gl.Call("bufferData", int(ArrayBuffer), size, int(DynamicDraw))
|
||||||
return b
|
return Buffer(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) NewElementArrayBuffer(size int) Buffer {
|
func (c *Context) NewElementArrayBuffer(size int) Buffer {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
b := gl.Call("createBuffer")
|
b := gl.Call("createBuffer")
|
||||||
gl.Call("bindBuffer", int(ElementArrayBuffer), b)
|
gl.Call("bindBuffer", int(ElementArrayBuffer), js.Value(b))
|
||||||
gl.Call("bufferData", int(ElementArrayBuffer), size, int(DynamicDraw))
|
gl.Call("bufferData", int(ElementArrayBuffer), size, int(DynamicDraw))
|
||||||
return b
|
return Buffer(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
|
func (c *Context) BindBuffer(bufferType BufferType, b Buffer) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.Call("bindBuffer", int(bufferType), b)
|
gl.Call("bindBuffer", int(bufferType), js.Value(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ArrayBufferSubData(data []float32) {
|
func (c *Context) ArrayBufferSubData(data []float32) {
|
||||||
@ -405,7 +405,7 @@ func (c *Context) ElementArrayBufferSubData(data []uint16) {
|
|||||||
|
|
||||||
func (c *Context) DeleteBuffer(b Buffer) {
|
func (c *Context) DeleteBuffer(b Buffer) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.Call("deleteBuffer", b)
|
gl.Call("deleteBuffer", js.Value(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
|
func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user