graphics: Appropriate rendering of edges on linear filter (Reland)

Fixes #456
This commit is contained in:
Hajime Hoshi
2017-12-03 21:13:21 +09:00
parent 8091aa5190
commit 1152439e65
15 changed files with 176 additions and 86 deletions

View File

@@ -77,8 +77,6 @@ func (p Program) id() programID {
func init() {
// Accessing the prototype is rquired on Safari.
c := js.Global.Get("WebGLRenderingContext").Get("prototype")
Nearest = Filter(c.Get("NEAREST").Int())
Linear = Filter(c.Get("LINEAR").Int())
VertexShader = ShaderType(c.Get("VERTEX_SHADER").Int())
FragmentShader = ShaderType(c.Get("FRAGMENT_SHADER").Int())
ArrayBuffer = BufferType(c.Get("ARRAY_BUFFER").Int())
@@ -159,7 +157,7 @@ func (c *Context) BlendFunc(mode CompositeMode) {
gl.BlendFunc(int(s), int(d))
}
func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (Texture, error) {
func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error) {
gl := c.gl
t := gl.CreateTexture()
if t == nil {
@@ -168,8 +166,8 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
c.BindTexture(Texture{t})
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int(filter))
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, int(filter))
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
// TODO: Can we use glTexSubImage2D with linear filtering?
@@ -348,12 +346,14 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
gl := c.gl
l := c.locationCache.GetUniformLocation(c, p, location)
switch len(v) {
case 2:
gl.Call("uniform2fv", l.Object, v)
case 4:
gl.Call("uniform4fv", l.Object, v)
case 16:
gl.UniformMatrix4fv(l.Object, false, v)
default:
panic("not reach")
panic("not reached")
}
}