updated xmobile backend with latest gogl code
This commit is contained in:
parent
eed8f3e241
commit
e4dae7a86f
4 changed files with 75 additions and 51 deletions
|
@ -141,6 +141,9 @@ func rewrite(filename, src string) (string, string) {
|
|||
params[2] = params[2][1 : len(params[2])-3]
|
||||
return "b.glctx.Uniform1fv(" + params[0] + ", " + params[2] + ")"
|
||||
})
|
||||
src = rewriteCalls(src, "b.glctx.UniformMatrix3fv", func(params []string) string {
|
||||
return "b.glctx.UniformMatrix3fv(" + params[0] + ", " + params[3][1:len(params[3])-3] + "[:])"
|
||||
})
|
||||
src = rewriteCalls(src, "b.glctx.TexImage2D", func(params []string) string {
|
||||
params = append(params[:5], params[6:]...)
|
||||
for i, param := range params {
|
||||
|
|
|
@ -53,11 +53,6 @@ func loadImage(b *XMobileBackend, src image.Image, tex gl.Texture) (*Image, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *image.Gray:
|
||||
img, err = loadImageGray(b, v, tex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case image.Image:
|
||||
img, err = loadImageConverted(b, v, tex)
|
||||
if err != nil {
|
||||
|
@ -100,36 +95,6 @@ func loadImageRGBA(b *XMobileBackend, src *image.RGBA, tex gl.Texture) (*Image,
|
|||
return img, nil
|
||||
}
|
||||
|
||||
func loadImageGray(b *XMobileBackend, src *image.Gray, tex gl.Texture) (*Image, error) {
|
||||
img := &Image{tex: tex, w: src.Bounds().Dx(), h: src.Bounds().Dy()}
|
||||
b.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
|
||||
b.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
||||
b.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
||||
b.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
||||
if err := glError(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if src.Stride == img.w {
|
||||
b.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, img.w, img.h, gl.ALPHA, gl.UNSIGNED_BYTE, src.Pix[0:])
|
||||
} else {
|
||||
data := make([]uint8, 0, img.w*img.h)
|
||||
for y := 0; y < img.h; y++ {
|
||||
start := y * src.Stride
|
||||
end := start + img.w
|
||||
data = append(data, src.Pix[start:end]...)
|
||||
}
|
||||
b.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, img.w, img.h, gl.ALPHA, gl.UNSIGNED_BYTE, data[0:])
|
||||
}
|
||||
if err := glError(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b.glctx.GenerateMipmap(gl.TEXTURE_2D)
|
||||
if err := glError(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func loadImageConverted(b *XMobileBackend, src image.Image, tex gl.Texture) (*Image, error) {
|
||||
img := &Image{tex: tex, w: src.Bounds().Dx(), h: src.Bounds().Dy()}
|
||||
b.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
|
||||
|
|
|
@ -134,9 +134,19 @@ precision mediump float;
|
|||
varying vec2 v_cp;
|
||||
uniform vec2 imageSize;
|
||||
uniform sampler2D image;
|
||||
uniform mat3 imageTransform;
|
||||
uniform vec2 repeat;
|
||||
uniform float globalAlpha;
|
||||
void main() {
|
||||
vec4 col = texture2D(image, mod(v_cp / imageSize, 1.0));
|
||||
vec3 tfpt = vec3(v_cp, 1.0) * imageTransform;
|
||||
vec2 imgpt = tfpt.xy / imageSize;
|
||||
vec4 col = texture2D(image, mod(imgpt, 1.0));
|
||||
if (imgpt.x < 0.0 || imgpt.x > 1.0) {
|
||||
col *= repeat.x;
|
||||
}
|
||||
if (imgpt.y < 0.0 || imgpt.y > 1.0) {
|
||||
col *= repeat.y;
|
||||
}
|
||||
col.a *= globalAlpha;
|
||||
gl_FragColor = col;
|
||||
}`
|
||||
|
@ -261,10 +271,20 @@ varying vec2 v_cp;
|
|||
varying vec2 v_atc;
|
||||
uniform vec2 imageSize;
|
||||
uniform sampler2D image;
|
||||
uniform mat3 imageTransform;
|
||||
uniform vec2 repeat;
|
||||
uniform sampler2D alphaTex;
|
||||
uniform float globalAlpha;
|
||||
void main() {
|
||||
vec4 col = texture2D(image, mod(v_cp / imageSize, 1.0));
|
||||
vec3 tfpt = vec3(v_cp, 1.0) * imageTransform;
|
||||
vec2 imgpt = tfpt.xy / imageSize;
|
||||
vec4 col = texture2D(image, mod(imgpt, 1.0));
|
||||
if (imgpt.x < 0.0 || imgpt.x > 1.0) {
|
||||
col *= repeat.x;
|
||||
}
|
||||
if (imgpt.y < 0.0 || imgpt.y > 1.0) {
|
||||
col *= repeat.y;
|
||||
}
|
||||
col.a *= texture2D(alphaTex, v_atc).a * globalAlpha;
|
||||
gl_FragColor = col;
|
||||
}`
|
||||
|
@ -406,6 +426,8 @@ type imagePatternShader struct {
|
|||
CanvasSize gl.Uniform
|
||||
ImageSize gl.Uniform
|
||||
Image gl.Uniform
|
||||
ImageTransform gl.Uniform
|
||||
Repeat gl.Uniform
|
||||
GlobalAlpha gl.Uniform
|
||||
}
|
||||
|
||||
|
@ -453,6 +475,8 @@ type imagePatternAlphaShader struct {
|
|||
CanvasSize gl.Uniform
|
||||
ImageSize gl.Uniform
|
||||
Image gl.Uniform
|
||||
ImageTransform gl.Uniform
|
||||
Repeat gl.Uniform
|
||||
AlphaTex gl.Uniform
|
||||
GlobalAlpha gl.Uniform
|
||||
}
|
||||
|
|
|
@ -425,13 +425,29 @@ func (b *XMobileBackend) useShader(style *backendbase.FillStyle) (vertexLoc gl.A
|
|||
return b.rgr.Vertex
|
||||
}
|
||||
if ip := style.ImagePattern; ip != nil {
|
||||
img := ip.(*ImagePattern).data.Image.(*Image)
|
||||
ipd := ip.(*ImagePattern).data
|
||||
img := ipd.Image.(*Image)
|
||||
b.glctx.UseProgram(b.ipr.ID)
|
||||
b.glctx.ActiveTexture(gl.TEXTURE0)
|
||||
b.glctx.BindTexture(gl.TEXTURE_2D, img.tex)
|
||||
b.glctx.Uniform2f(b.ipr.CanvasSize, float32(b.fw), float32(b.fh))
|
||||
b.glctx.Uniform2f(b.ipr.ImageSize, float32(img.w), float32(img.h))
|
||||
b.glctx.Uniform1i(b.ipr.Image, 0)
|
||||
var f32mat [9]float32
|
||||
for i, v := range ipd.Transform {
|
||||
f32mat[i] = float32(v)
|
||||
}
|
||||
b.glctx.UniformMatrix3fv(b.ipr.ImageTransform, f32mat[:])
|
||||
switch ipd.Repeat {
|
||||
case backendbase.Repeat:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 1, 1)
|
||||
case backendbase.RepeatX:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 1, 0)
|
||||
case backendbase.RepeatY:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 0, 1)
|
||||
case backendbase.NoRepeat:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 0, 0)
|
||||
}
|
||||
b.glctx.Uniform1f(b.ipr.GlobalAlpha, float32(style.Color.A)/255)
|
||||
return b.ipr.Vertex
|
||||
}
|
||||
|
@ -482,13 +498,29 @@ func (b *XMobileBackend) useAlphaShader(style *backendbase.FillStyle, alphaTexSl
|
|||
return b.rgar.Vertex, b.rgar.AlphaTexCoord
|
||||
}
|
||||
if ip := style.ImagePattern; ip != nil {
|
||||
img := ip.(*ImagePattern).data.Image.(*Image)
|
||||
ipd := ip.(*ImagePattern).data
|
||||
img := ipd.Image.(*Image)
|
||||
b.glctx.UseProgram(b.ipar.ID)
|
||||
b.glctx.ActiveTexture(gl.TEXTURE0)
|
||||
b.glctx.BindTexture(gl.TEXTURE_2D, img.tex)
|
||||
b.glctx.Uniform2f(b.ipar.CanvasSize, float32(b.fw), float32(b.fh))
|
||||
b.glctx.Uniform2f(b.ipar.ImageSize, float32(img.w), float32(img.h))
|
||||
b.glctx.Uniform1i(b.ipar.Image, 0)
|
||||
var f32mat [9]float32
|
||||
for i, v := range ipd.Transform {
|
||||
f32mat[i] = float32(v)
|
||||
}
|
||||
b.glctx.UniformMatrix3fv(b.ipr.ImageTransform, f32mat[:])
|
||||
switch ipd.Repeat {
|
||||
case backendbase.Repeat:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 1, 1)
|
||||
case backendbase.RepeatX:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 1, 0)
|
||||
case backendbase.RepeatY:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 0, 1)
|
||||
case backendbase.NoRepeat:
|
||||
b.glctx.Uniform2f(b.ipr.Repeat, 0, 0)
|
||||
}
|
||||
b.glctx.Uniform1i(b.ipar.AlphaTex, alphaTexSlot)
|
||||
b.glctx.Uniform1f(b.ipar.GlobalAlpha, float32(style.Color.A)/255)
|
||||
return b.ipar.Vertex, b.ipar.AlphaTexCoord
|
||||
|
|
Loading…
Reference in a new issue