use texture array instead of atlas for tiles
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
|
#define MILLIS_PER_TILE 4000u
|
||||||
|
|
||||||
in vec2 v_uv;
|
in vec2 v_uv;
|
||||||
flat in uint v_tileidx;
|
flat in uint v_tileidx;
|
||||||
out vec4 pixcolor;
|
out vec4 pixcolor;
|
||||||
uniform sampler2D t_atlas;
|
uniform sampler2DArray t_tiles;
|
||||||
uniform b_constants {
|
uniform b_constants {
|
||||||
uvec4 anim;
|
uvec4 anim;
|
||||||
float R1;
|
float R1;
|
||||||
@@ -19,8 +21,8 @@ uniform b_locals {
|
|||||||
void main() {
|
void main() {
|
||||||
vec2 anim_uv = v_uv;
|
vec2 anim_uv = v_uv;
|
||||||
if (v_tileidx < 128u && bool(anim[v_tileidx / 32u] & 1u << v_tileidx % 32u)) {
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ gfx_defines! {
|
|||||||
trans: gfx::ConstantBuffer<::view::Trans> = "b_trans",
|
trans: gfx::ConstantBuffer<::view::Trans> = "b_trans",
|
||||||
constants: gfx::ConstantBuffer<Constants> = "b_constants",
|
constants: gfx::ConstantBuffer<Constants> = "b_constants",
|
||||||
locals: gfx::ConstantBuffer<Locals> = "b_locals",
|
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",
|
pixcolor: gfx::RenderTarget<::view::ColorFormat> = "pixcolor",
|
||||||
depth: gfx::DepthTarget<::view::DepthFormat> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
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),
|
locals: factory.create_constant_buffer(1),
|
||||||
atlas: tile::get_tiles::<_, _, view::ColorFormat>(factory),
|
atlas: tile::get_tiles::<_, _, view::ColorFormat>(factory),
|
||||||
sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Scale,
|
sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Scale,
|
||||||
tex::WrapMode::Clamp)),
|
tex::WrapMode::Tile)),
|
||||||
f: PhantomData,
|
f: PhantomData,
|
||||||
|
|
||||||
vbuf: vertex_buffer,
|
vbuf: vertex_buffer,
|
||||||
|
|||||||
13
src/tile.rs
13
src/tile.rs
@@ -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 filename = "data/SHAPES.EGA";
|
||||||
let mut file = std::fs::File::open(Path::new(filename))
|
let mut file = std::fs::File::open(Path::new(filename))
|
||||||
.expect(&format!("failed opening tiles file: {}", filename));
|
.expect(&format!("failed opening tiles file: {}", filename));
|
||||||
let mut ega_vec = Vec::new();
|
let mut ega_bytes = Vec::new();
|
||||||
file.read_to_end(&mut ega_vec).expect("Read tiles file");
|
file.read_to_end(&mut ega_bytes).expect("Read tiles file");
|
||||||
let ega_page = ega::decode(&ega_vec, ega::Compression::UNCOMPRESSED, ega::Tiling::TILED(16));
|
let ega_page = ega::decode(&ega_bytes, ega::Compression::UNCOMPRESSED, ega::Tiling::TILED(16));
|
||||||
let tex = factory.create_texture_const_u8::<T>(tex::Kind::D2(16, 16 * 256,
|
let tiles: Vec<&[u8]> = ega_page.iter().collect();
|
||||||
tex::AaMode::Single),
|
let tex = factory.create_texture_const_u8::<T>(tex::Kind::D2Array(16, 16, 256,
|
||||||
&[&ega_page.data])
|
tex::AaMode::Single),
|
||||||
|
&tiles)
|
||||||
.expect("create tile texture");
|
.expect("create tile texture");
|
||||||
tex.1
|
tex.1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user