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

This commit is contained in:
Hajime Hoshi
2017-12-11 23:07:01 +09:00
parent 362d1c417f
commit 723d153800
15 changed files with 180 additions and 86 deletions

View File

@@ -25,11 +25,13 @@ import (
mgl "golang.org/x/mobile/gl"
)
type Texture mgl.Texture
type Framebuffer mgl.Framebuffer
type Shader mgl.Shader
type Program mgl.Program
type Buffer mgl.Buffer
type (
Texture mgl.Texture
Framebuffer mgl.Framebuffer
Shader mgl.Shader
Program mgl.Program
Buffer mgl.Buffer
)
func (t Texture) equals(other Texture) bool {
return t == other
@@ -39,8 +41,10 @@ func (f Framebuffer) equals(other Framebuffer) bool {
return f == other
}
type uniformLocation mgl.Uniform
type attribLocation mgl.Attrib
type (
uniformLocation mgl.Uniform
attribLocation mgl.Attrib
)
type programID uint32
@@ -54,8 +58,6 @@ func (p Program) id() programID {
}
func init() {
Nearest = mgl.NEAREST
Linear = mgl.LINEAR
VertexShader = mgl.VERTEX_SHADER
FragmentShader = mgl.FRAGMENT_SHADER
ArrayBuffer = mgl.ARRAY_BUFFER
@@ -127,7 +129,7 @@ func (c *Context) BlendFunc(mode CompositeMode) {
gl.BlendFunc(mgl.Enum(s), mgl.Enum(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.Value <= 0 {
@@ -136,8 +138,8 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4)
c.BindTexture(Texture(t))
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, int(filter))
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_FILTER, int(filter))
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, mgl.NEAREST)
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_FILTER, mgl.NEAREST)
var p []uint8
if pixels != nil {
@@ -317,12 +319,14 @@ func (c *Context) UniformFloats(p Program, location string, v []float32) {
gl := c.gl
l := mgl.Uniform(c.locationCache.GetUniformLocation(c, p, location))
switch len(v) {
case 2:
gl.Uniform2fv(l, v)
case 4:
gl.Uniform4fv(l, v)
case 16:
gl.UniformMatrix4fv(l, v)
default:
panic("not reach")
panic("not reached")
}
}