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

Implement WebGLContext resize #519

Merged
merged 1 commit into from Nov 3, 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

Implement WebGLContext resize

  • Loading branch information
MortimerGoro committed Nov 3, 2016
commit d8bcc189809dddeb70cb44b28f1b055e3c73b23c
@@ -1042,6 +1042,10 @@ impl Device {
self.raw_textures.insert(texture_id, (x0, y0, width, height));
}

pub fn remove_raw_texture(&mut self, texture_id: TextureId) {
self.raw_textures.remove(&texture_id);
}

fn set_texture_parameters(&mut self, target: gl::GLuint, filter: TextureFilter) {
let filter = match filter {
TextureFilter::Nearest => {
@@ -134,6 +134,17 @@ impl GLContextWrapper {
}
}
}

pub fn resize(&mut self, size: &Size2D<i32>) -> Result<(), &'static str> {
match *self {
GLContextWrapper::Native(ref mut ctx) => {
ctx.resize(*size)
}
GLContextWrapper::OSMesa(ref mut ctx) => {
ctx.resize(*size)
}
}
}
}

pub type DeviceRect = TypedRect<i32, DevicePixel>;
@@ -338,6 +349,7 @@ pub enum TextureUpdateOp {
Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option<Vec<u8>>),
Update(u32, u32, u32, u32, TextureUpdateDetails),
Grow(u32, u32, ImageFormat, TextureFilter, RenderTargetMode),
Remove
}

pub struct TextureUpdate {
@@ -303,6 +303,21 @@ impl RenderBackend {
tx.send(Err("Not implemented yet".to_owned())).unwrap();
}
}
ApiMsg::ResizeWebGLContext(context_id, size) => {
let ctx = self.webgl_contexts.get_mut(&context_id).unwrap();
ctx.make_current();
match ctx.resize(&size) {
Ok(_) => {
// Update webgl texture size. Texture id may change too.
let (real_size, texture_id, _) = ctx.get_info();
self.resource_cache
.update_webgl_texture(context_id, TextureId::new(texture_id), real_size);
},
Err(msg) => {
error!("Error resizing WebGLContext: {}", msg);
}
}
}
ApiMsg::WebGLCommand(context_id, command) => {
// TODO: Buffer the commands and only apply them here if they need to
// be synchronous.
@@ -1033,6 +1033,9 @@ impl Renderer {
}
}
}
TextureUpdateOp::Remove => {
self.device.remove_raw_texture(update.id);
}
}
}
}
@@ -216,6 +216,18 @@ impl ResourceCache {
self.texture_cache.add_raw_update(texture_id, size);
}

pub fn update_webgl_texture(&mut self, id: WebGLContextId, texture_id: TextureId, size: Size2D<i32>) {
let prev_texture_id = *self.webgl_textures.get(&id).unwrap();

// Remove existing cache if texture id has changed
if prev_texture_id != texture_id {
self.texture_cache.add_raw_remove(prev_texture_id);
}
// Update new texture id and size
self.webgl_textures.insert(id, texture_id);
self.texture_cache.add_raw_update(texture_id, size);
}

pub fn add_resource_list(&mut self, resource_list: &ResourceList, frame_id: FrameId) {
// Update texture cache with any images that aren't yet uploaded to GPU.
resource_list.for_each_image(|image_key, image_rendering| {
@@ -779,6 +779,13 @@ impl TextureCache {
})
}

pub fn add_raw_remove(&mut self, id: TextureId) {

This comment has been minimized.

@emilio

emilio Nov 3, 2016

Member

add_raw_remove sounds a bit weird, though it follows the convention. I can't think of an immediately better name now, so I guess this is ok.

This comment has been minimized.

@kvark

kvark Nov 3, 2016

Member

yeah, it does follow the convention. Perhaps, the convention should be revised? as a separate PR

self.pending_updates.push(TextureUpdate {
id: id,
op: TextureUpdateOp::Remove
});
}

pub fn update(&mut self,
image_id: TextureCacheItemId,
width: u32,
@@ -229,6 +229,11 @@ impl RenderApi {
rx.recv().unwrap()
}

pub fn resize_webgl_context(&self, context_id: WebGLContextId, size: &Size2D<i32>) {
let msg = ApiMsg::ResizeWebGLContext(context_id, *size);
self.api_sender.send(msg).unwrap();
}

pub fn send_webgl_command(&self, context_id: WebGLContextId, command: WebGLCommand) {
let msg = ApiMsg::WebGLCommand(context_id, command);
self.api_sender.send(msg).unwrap();
@@ -55,6 +55,7 @@ pub enum ApiMsg {
TranslatePointToLayerSpace(Point2D<f32>, IpcSender<(Point2D<f32>, PipelineId)>),
GetScrollLayerState(IpcSender<Vec<ScrollLayerState>>),
RequestWebGLContext(Size2D<i32>, GLContextAttributes, IpcSender<Result<(WebGLContextId, GLLimits), String>>),
ResizeWebGLContext(WebGLContextId, Size2D<i32>),
WebGLCommand(WebGLContextId, WebGLCommand),
}

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