Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize uvs when growing textures. #208

Merged
merged 1 commit into from Mar 1, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -336,7 +336,7 @@ impl<'a> BatchBuilder<'a> {
let white_image = resource_cache.get_dummy_color_image();
self.add_complex_clipped_rectangle(white_image.texture_id,
rect,
&white_image.uv_rect,
&white_image.uv_rect(),
&[*color, *color, *color, *color],
None,
resource_cache,
@@ -388,11 +388,12 @@ impl<'a> BatchBuilder<'a> {
bottom_right: Point2D::new(u1, v1),
};

let uv_size = image_info.uv_rect.bottom_right - image_info.uv_rect.top_left;
let uv_rect = image_info.uv_rect();
let uv_size = uv_rect.bottom_right - uv_rect.top_left;

let tile_params = TileParams {
u0: image_info.uv_rect.top_left.x,
v0: image_info.uv_rect.top_left.y,
u0: image_info.uv_rect().top_left.x,
v0: image_info.uv_rect().top_left.y,
u_size: uv_size.x,
v_size: uv_size.y,
};
@@ -444,7 +445,7 @@ impl<'a> BatchBuilder<'a> {
let rect = RectPolygon {
pos: Rect::new(Point2D::new(x, y),
Size2D::new(width, height)),
varyings: image_info.uv_rect,
varyings: image_info.uv_rect(),
};

let rect_buffer = match text_batches.entry(image_info.texture_id) {
@@ -512,7 +513,7 @@ impl<'a> BatchBuilder<'a> {

self.add_complex_clipped_rectangle(white_image.texture_id,
&piece_rect,
&white_image.uv_rect,
&white_image.uv_rect(),
&piece_colors,
None,
resource_cache,
@@ -584,7 +585,7 @@ impl<'a> BatchBuilder<'a> {
let rect =
Rect::new(Point2D::new(-length / 2.0 + midpoint.x, midpoint.y - height / 2.0),
Size2D::new(length, height));
let mut rect_uv = white_image.uv_rect;
let mut rect_uv = white_image.uv_rect();
rect_uv.bottom_left.x = -angle;

rectangles.push(GradientRect {
@@ -1075,7 +1076,7 @@ impl<'a> BatchBuilder<'a> {
&Rect::new(dot_rect.origin,
Size2D::new(dot_rect.size.width / 2.0,
dot_rect.size.height / 2.0)),
&color_image.uv_rect,
&color_image.uv_rect(),
dummy_mask_image.texture_id,
&dummy_mask_image.pixel_rect,
&colors,
@@ -1086,7 +1087,7 @@ impl<'a> BatchBuilder<'a> {
&Rect::new(dot_rect.top_right(),
Size2D::new(-dot_rect.size.width / 2.0,
dot_rect.size.height / 2.0)),
&color_image.uv_rect,
&color_image.uv_rect(),
dummy_mask_image.texture_id,
&dummy_mask_image.pixel_rect,
&colors,
@@ -1097,7 +1098,7 @@ impl<'a> BatchBuilder<'a> {
&Rect::new(dot_rect.bottom_right(),
Size2D::new(-dot_rect.size.width / 2.0,
-dot_rect.size.height / 2.0)),
&color_image.uv_rect,
&color_image.uv_rect(),
dummy_mask_image.texture_id,
&dummy_mask_image.pixel_rect,
&colors,
@@ -1108,7 +1109,7 @@ impl<'a> BatchBuilder<'a> {
&Rect::new(dot_rect.bottom_left(),
Size2D::new(dot_rect.size.width / 2.0,
-dot_rect.size.height / 2.0)),
&color_image.uv_rect,
&color_image.uv_rect(),
dummy_mask_image.texture_id,
&dummy_mask_image.pixel_rect,
&colors,
@@ -1560,7 +1561,7 @@ impl<'a> BatchBuilder<'a> {

let vertices_rect = Rect::new(*v0, Size2D::new(v1.x - v0.x, v1.y - v0.y));

let color_uv = RectUv::from_uv_rect_rotation_angle(&color_image.uv_rect,
let color_uv = RectUv::from_uv_rect_rotation_angle(&color_image.uv_rect(),
rotation_angle,
false);

@@ -461,7 +461,6 @@ pub struct TextureCacheItem {
pub user_data: TextureCacheItemUserData,

// The texture coordinates for this item
pub uv_rect: RectUv<f32>,
pub pixel_rect: RectUv<DevicePixel>,

// The size of the entire texture (not just the allocated rectangle)
@@ -507,13 +506,11 @@ impl TextureCacheItem {
user_x0: i32, user_y0: i32,
allocated_rect: Rect<u32>,
requested_rect: Rect<u32>,
texture_size: &Size2D<u32>,
uv_rect: RectUv<f32>)
texture_size: &Size2D<u32>)
-> TextureCacheItem {
TextureCacheItem {
texture_id: texture_id,
texture_size: *texture_size,
uv_rect: uv_rect,
pixel_rect: RectUv {
top_left: Point2D::new(DevicePixel::from_u32(requested_rect.origin.x),
DevicePixel::from_u32(requested_rect.origin.y)),
@@ -537,12 +534,26 @@ impl TextureCacheItem {
let texture_size = self.texture_size;
TextureImage {
texture_id: self.texture_id,
texel_uv: Rect::new(Point2D::new(self.uv_rect.top_left.x,
self.uv_rect.top_left.y),
Size2D::new(self.uv_rect.bottom_right.x - self.uv_rect.top_left.x,
self.uv_rect.bottom_right.y - self.uv_rect.top_left.y)),
pixel_uv: Point2D::new(self.uv_rect.top_left.x as u32 * texture_size.width,
self.uv_rect.top_left.y as u32 * texture_size.height),
texel_uv: Rect::new(
Point2D::new(self.uv_rect().top_left.x, self.uv_rect().top_left.y),
Size2D::new(self.uv_rect().bottom_right.x - self.uv_rect().top_left.x,
self.uv_rect().bottom_right.y - self.uv_rect().top_left.y)),
pixel_uv: Point2D::new(self.uv_rect().top_left.x as u32 * texture_size.width,
self.uv_rect().top_left.y as u32 * texture_size.height),
}
}

pub fn uv_rect(&self) -> RectUv<f32> {
let (width, height) = (self.texture_size.width as f32, self.texture_size.height as f32);
RectUv {
top_left: Point2D::new(self.pixel_rect.top_left.x.as_f32() / width,
self.pixel_rect.top_left.y.as_f32() / height),
top_right: Point2D::new(self.pixel_rect.top_right.x.as_f32() / width,
self.pixel_rect.top_right.y.as_f32() / height),
bottom_left: Point2D::new(self.pixel_rect.bottom_left.x.as_f32() / width,
self.pixel_rect.bottom_left.y.as_f32() / height),
bottom_right: Point2D::new(self.pixel_rect.bottom_right.x.as_f32() / width,
self.pixel_rect.bottom_right.y.as_f32() / height),
}
}
}
@@ -633,12 +644,6 @@ impl TextureCache {
// how the raster_jobs code works.
pub fn new_item_id(&mut self) -> TextureCacheItemId {
let new_item = TextureCacheItem {
uv_rect: RectUv {
top_left: Point2D::zero(),
top_right: Point2D::zero(),
bottom_left: Point2D::zero(),
bottom_right: Point2D::zero(),
},
user_data: TextureCacheItemUserData {
x0: 0,
y0: 0,
@@ -817,7 +822,7 @@ impl TextureCache {
let item = iter.free_list().get_mut(id);
if item.texture_id == old_texture_id {
item.texture_id = new_texture_id;
item.texture_size = Size2D::new(texture_size, texture_size)
item.texture_size = Size2D::new(texture_size, texture_size);
}
}
}
@@ -870,13 +875,7 @@ impl TextureCache {
user_x0, user_y0,
Rect::new(Point2D::zero(), requested_size),
Rect::new(Point2D::zero(), requested_size),
&requested_size,
RectUv {
top_left: Point2D::new(0.0, 0.0),
top_right: Point2D::new(1.0, 0.0),
bottom_left: Point2D::new(0.0, 1.0),
bottom_right: Point2D::new(1.0, 1.0),
});
&requested_size);
*self.items.get_mut(image_id) = cache_item;

return AllocationResult {
@@ -895,22 +894,11 @@ impl TextureCache {
location.y + border_size),
requested_size);

let u0 = requested_rect.origin.x as f32 / page.texture_size as f32;
let v0 = requested_rect.origin.y as f32 / page.texture_size as f32;
let u1 = u0 + requested_size.width as f32 / page.texture_size as f32;
let v1 = v0 + requested_size.height as f32 / page.texture_size as f32;
let cache_item = TextureCacheItem::new(page.texture_id,
user_x0, user_y0,
allocated_rect,
requested_rect,
&Size2D::new(page.texture_size,
page.texture_size),
RectUv {
top_left: Point2D::new(u0, v0),
top_right: Point2D::new(u1, v0),
bottom_left: Point2D::new(u0, v1),
bottom_right: Point2D::new(u1, v1)
});
&Size2D::new(page.texture_size, page.texture_size));
*self.items.get_mut(image_id) = cache_item;

AllocationResult {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.