use texture array instead of atlas for tiles

This commit is contained in:
2016-10-06 18:20:08 -07:00
parent 931bc1b0a8
commit 0275d01b96
3 changed files with 15 additions and 12 deletions

View File

@@ -1,9 +1,11 @@
#version 150
#define MILLIS_PER_TILE 4000u
in vec2 v_uv;
flat in uint v_tileidx;
out vec4 pixcolor;
uniform sampler2D t_atlas;
uniform sampler2DArray t_tiles;
uniform b_constants {
uvec4 anim;
float R1;
@@ -19,8 +21,8 @@ uniform b_locals {
void main() {
vec2 anim_uv = v_uv;
if (v_tileidx < 128u && bool(anim[v_tileidx / 32u] & 1u << v_tileidx % 32u)) {
anim_uv = vec2(v_uv.x, float((uint(v_uv.y * 1000.0) + millis / 4u) % 1000u) / 1000.0);
anim_uv = vec2(v_uv.x, v_uv.y + float(millis % MILLIS_PER_TILE) / MILLIS_PER_TILE);
}
vec2 uv = vec2(anim_uv.x, float(v_tileidx) / 256.0 + (1.0 - anim_uv.y) / 256.0);
pixcolor = texture(t_atlas, uv);
pixcolor = texture(t_tiles, vec3(anim_uv.x, 1.0 - anim_uv.y, v_tileidx));
}

View File

@@ -52,7 +52,7 @@ gfx_defines! {
trans: gfx::ConstantBuffer<::view::Trans> = "b_trans",
constants: gfx::ConstantBuffer<Constants> = "b_constants",
locals: gfx::ConstantBuffer<Locals> = "b_locals",
atlas: gfx::TextureSampler<[f32; 4]> = "t_atlas",
atlas: gfx::TextureSampler<[f32; 4]> = "t_tiles",
pixcolor: gfx::RenderTarget<::view::ColorFormat> = "pixcolor",
depth: gfx::DepthTarget<::view::DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
}
@@ -157,7 +157,7 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
locals: factory.create_constant_buffer(1),
atlas: tile::get_tiles::<_, _, view::ColorFormat>(factory),
sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Scale,
tex::WrapMode::Clamp)),
tex::WrapMode::Tile)),
f: PhantomData,
vbuf: vertex_buffer,

View File

@@ -22,12 +22,13 @@ pub fn get_tiles<R, F, T>(factory: &mut F) -> (//gfx::handle::Texture<R, T::Surf
let filename = "data/SHAPES.EGA";
let mut file = std::fs::File::open(Path::new(filename))
.expect(&format!("failed opening tiles file: {}", filename));
let mut ega_vec = Vec::new();
file.read_to_end(&mut ega_vec).expect("Read tiles file");
let ega_page = ega::decode(&ega_vec, ega::Compression::UNCOMPRESSED, ega::Tiling::TILED(16));
let tex = factory.create_texture_const_u8::<T>(tex::Kind::D2(16, 16 * 256,
tex::AaMode::Single),
&[&ega_page.data])
let mut ega_bytes = Vec::new();
file.read_to_end(&mut ega_bytes).expect("Read tiles file");
let ega_page = ega::decode(&ega_bytes, ega::Compression::UNCOMPRESSED, ega::Tiling::TILED(16));
let tiles: Vec<&[u8]> = ega_page.iter().collect();
let tex = factory.create_texture_const_u8::<T>(tex::Kind::D2Array(16, 16, 256,
tex::AaMode::Single),
&tiles)
.expect("create tile texture");
tex.1
}