mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
graphics: Temporary hack for mobile browers
roundTexel doesn't work well on moible browsers
This commit is contained in:
parent
723d153800
commit
aea2e491c3
@ -14,6 +14,12 @@
|
|||||||
|
|
||||||
package graphics
|
package graphics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
|
)
|
||||||
|
|
||||||
type shaderId int
|
type shaderId int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -22,11 +28,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func shader(id shaderId) string {
|
func shader(id shaderId) string {
|
||||||
return shaders[id]
|
s := shaders[id]
|
||||||
|
defs := []string{}
|
||||||
|
if web.IsMobileBrowser() {
|
||||||
|
defs = append(defs, "#define IS_MOBILE_BROWSER")
|
||||||
|
}
|
||||||
|
s = strings.Replace(s, "{{Definitions}}", strings.Join(defs, "\n"), -1)
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
var shaders = map[shaderId]string{
|
var shaders = map[shaderId]string{
|
||||||
shaderVertexModelview: `
|
shaderVertexModelview: `
|
||||||
|
{{Definitions}}
|
||||||
|
|
||||||
uniform mat4 projection_matrix;
|
uniform mat4 projection_matrix;
|
||||||
attribute vec2 vertex;
|
attribute vec2 vertex;
|
||||||
attribute vec4 tex_coord;
|
attribute vec4 tex_coord;
|
||||||
@ -60,17 +74,28 @@ precision mediump float;
|
|||||||
#define highp
|
#define highp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
{{Definitions}}
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform mat4 color_matrix;
|
uniform mat4 color_matrix;
|
||||||
uniform vec4 color_matrix_translation;
|
uniform vec4 color_matrix_translation;
|
||||||
uniform int filter_type;
|
|
||||||
uniform vec2 source_size;
|
uniform vec2 source_size;
|
||||||
|
uniform int filter_type;
|
||||||
|
|
||||||
varying vec2 varying_tex_coord;
|
varying vec2 varying_tex_coord;
|
||||||
varying vec2 varying_tex_coord_min;
|
varying vec2 varying_tex_coord_min;
|
||||||
varying vec2 varying_tex_coord_max;
|
varying vec2 varying_tex_coord_max;
|
||||||
|
|
||||||
vec2 roundTexel(vec2 p) {
|
vec2 roundTexel(vec2 p) {
|
||||||
|
#if defined(IS_MOBILE_BROWSER)
|
||||||
|
// This is a temporary hack: on mobile browsers like Android Chrome,
|
||||||
|
// the code to round a float might cause unexpected behavior.
|
||||||
|
// This is confirmed with rendering a relatively large (e.g. 4096x512) image
|
||||||
|
// with specifying a source rectangle near its edges.
|
||||||
|
// TODO: examples/moire doesn't work anyway.
|
||||||
|
// TODO: Does this function work on an Android native app?
|
||||||
|
return p;
|
||||||
|
#else
|
||||||
vec2 factor = 1.0 / (source_size * 256.0);
|
vec2 factor = 1.0 / (source_size * 256.0);
|
||||||
if (factor.x > 0.0) {
|
if (factor.x > 0.0) {
|
||||||
p.x -= mod(p.x + factor.x * 0.5, factor.x) - factor.x * 0.5;
|
p.x -= mod(p.x + factor.x * 0.5, factor.x) - factor.x * 0.5;
|
||||||
@ -79,6 +104,7 @@ vec2 roundTexel(vec2 p) {
|
|||||||
p.y -= mod(p.y + factor.y * 0.5, factor.y) - factor.y * 0.5;
|
p.y -= mod(p.y + factor.y * 0.5, factor.y) - factor.y * 0.5;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 getColorAt(vec2 pos) {
|
vec4 getColorAt(vec2 pos) {
|
||||||
|
Loading…
Reference in New Issue
Block a user