From bd1fc4439acfc67987e1ac4046b3c1c7c0c1361e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 4 Oct 2018 02:02:19 +0900 Subject: [PATCH] graphicsutil: Avoid passing NaN to shaders experimentally (#696) --- internal/graphics/shader.go | 6 +----- internal/graphicsutil/vertices.go | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index b567252dd..d7f1b63dd 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -56,13 +56,9 @@ varying vec2 varying_tex_coord_min; varying vec2 varying_tex_coord_max; varying vec4 varying_color_scale; -bool isNaN(float x) { - return x != x; -} - void main(void) { varying_tex_coord = vec2(tex_coord[0], tex_coord[1]); - if (!isNaN(tex_coord[2]) && !isNaN(tex_coord[3])) { + if (tex_coord[2] >= 0.0 && tex_coord[3] >= 0.0) { varying_tex_coord_min = vec2(min(tex_coord[0], tex_coord[2]), min(tex_coord[1], tex_coord[3])); varying_tex_coord_max = vec2(max(tex_coord[0], tex_coord[2]), max(tex_coord[1], tex_coord[3])); } else { diff --git a/internal/graphicsutil/vertices.go b/internal/graphicsutil/vertices.go index 785361d56..dd79f8ec6 100644 --- a/internal/graphicsutil/vertices.go +++ b/internal/graphicsutil/vertices.go @@ -15,8 +15,6 @@ package graphicsutil import ( - "math" - "github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/opengl" ) @@ -138,10 +136,6 @@ func QuadIndices() []uint16 { return quadIndices } -var ( - nan32 = float32(math.NaN()) -) - func Vertex(width, height int, dx, dy, sx, sy float32, cr, cg, cb, ca float32) []float32 { if !isPowerOf2(width) { panic("not reached") @@ -160,8 +154,8 @@ func Vertex(width, height int, dx, dy, sx, sy float32, cr, cg, cb, ca float32) [ vs[1] = dy vs[2] = sx / wf vs[3] = sy / hf - vs[4] = nan32 - vs[5] = nan32 + vs[4] = -1 + vs[5] = -1 vs[6] = cr vs[7] = cg vs[8] = cb