graphicsdriver: Refactoring

This improved FPS on mobiles a little bit. Maybe now texture2D is
called only when necessary, but not sure.
This commit is contained in:
Hajime Hoshi 2019-02-17 17:31:05 +09:00
parent 742bbb4ccd
commit cbb0a1da95
3 changed files with 14 additions and 15 deletions

View File

@ -968,7 +968,7 @@ func TestImageStretch(t *testing.T) {
want = color.RGBA{0xff, 0, 0, 0xff}
}
if got != want {
t.Errorf("At(%d, %d) (i=%d): got: %#v, want: %#v", 0, i+j, i, got, want)
t.Fatalf("At(%d, %d) (i=%d): got: %#v, want: %#v", 0, i+j, i, got, want)
}
}
}

View File

@ -120,17 +120,16 @@ struct GetColorFromTexel;
template<uint8_t address>
struct GetColorFromTexel<FILTER_NEAREST, address> {
inline float4 Do(VertexOut v, texture2d<float> texture, constant float2& source_size, float scale) {
constexpr sampler texture_sampler(filter::nearest);
float2 p = AdjustTexelByAddress<address>(v.tex, v.tex_region);
if (p.x < v.tex_region[0] ||
p.y < v.tex_region[1] ||
v.tex_region[2] <= p.x ||
v.tex_region[3] <= p.y) {
return 0.0;
}
if (v.tex_region[0] <= p.x &&
v.tex_region[1] <= p.y &&
p.x < v.tex_region[2] &&
p.y < v.tex_region[3]) {
constexpr sampler texture_sampler(filter::nearest);
return texture.sample(texture_sampler, p);
}
return 0.0;
}
};
template<uint8_t address>

View File

@ -197,12 +197,12 @@ void main(void) {
#if defined(FILTER_NEAREST)
pos = adjustTexelByAddress(pos, varying_tex_region);
color = texture2D(texture, pos);
if (pos.x < varying_tex_region[0] ||
pos.y < varying_tex_region[1] ||
varying_tex_region[2] <= pos.x ||
varying_tex_region[3] <= pos.y) {
color = vec4(0, 0, 0, 0);
if (varying_tex_region[0] <= pos.x &&
varying_tex_region[1] <= pos.y &&
pos.x < varying_tex_region[2] &&
pos.y < varying_tex_region[3]) {
color = texture2D(texture, pos);
}
#endif