diff options
author | Imanol Fernandez <mortimergoro@gmail.com> | 2016-12-01 00:39:32 +0100 |
---|---|---|
committer | Imanol Fernandez <mortimergoro@gmail.com> | 2016-12-01 00:56:59 +0100 |
commit | 8ba75c0545f26b7577a70aff71aa619128dc870b (patch) | |
tree | 998b35b85f53481bee1325d6544f60700812bc4b /components/script/dom/webglrenderingcontext.rs | |
parent | b3cdcfaa39a7933a9f87a6881f5d58e5afe94086 (diff) | |
download | servo-8ba75c0545f26b7577a70aff71aa619128dc870b.tar.gz servo-8ba75c0545f26b7577a70aff71aa619128dc870b.zip |
Implement WebGLContext resize, r=emilio
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index f43576fba63..4f87e2e9339 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -132,6 +132,10 @@ pub struct WebGLRenderingContext { current_program: MutNullableHeap<JS<WebGLProgram>>, #[ignore_heap_size_of = "Because it's small"] current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>, + #[ignore_heap_size_of = "Because it's small"] + current_scissor: Cell<(i32, i32, i32, i32)>, + #[ignore_heap_size_of = "Because it's small"] + current_clear_color: Cell<(f32, f32, f32, f32)>, } impl WebGLRenderingContext { @@ -162,6 +166,8 @@ impl WebGLRenderingContext { bound_renderbuffer: MutNullableHeap::new(None), current_program: MutNullableHeap::new(None), current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)), + current_scissor: Cell::new((0, 0, size.width, size.height)), + current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0)) } }) } @@ -202,6 +208,22 @@ impl WebGLRenderingContext { pub fn recreate(&self, size: Size2D<i32>) { self.ipc_renderer.send(CanvasMsg::Common(CanvasCommonMsg::Recreate(size))).unwrap(); + + // ClearColor needs to be restored because after a resize the GLContext is recreated + // and the framebuffer is cleared using the default black transparent color. + let color = self.current_clear_color.get(); + self.ipc_renderer + .send(CanvasMsg::WebGL(WebGLCommand::ClearColor(color.0, color.1, color.2, color.3))) + .unwrap(); + + // WebGL Spec: Scissor rect must not change if the canvas is resized. + // See: webgl/conformance-1.0.3/conformance/rendering/gl-scissor-canvas-dimensions.html + // NativeContext handling library changes the scissor after a resize, so we need to reset the + // default scissor when the canvas was created or the last scissor that the user set. + let rect = self.current_scissor.get(); + self.ipc_renderer + .send(CanvasMsg::WebGL(WebGLCommand::Scissor(rect.0, rect.1, rect.2, rect.3))) + .unwrap() } pub fn ipc_renderer(&self) -> IpcSender<CanvasMsg> { @@ -1135,6 +1157,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn ClearColor(&self, red: f32, green: f32, blue: f32, alpha: f32) { + self.current_clear_color.set((red, green, blue, alpha)); self.ipc_renderer .send(CanvasMsg::WebGL(WebGLCommand::ClearColor(red, green, blue, alpha))) .unwrap() @@ -1902,6 +1925,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return self.webgl_error(InvalidValue) } + self.current_scissor.set((x, y, width, height)); self.ipc_renderer .send(CanvasMsg::WebGL(WebGLCommand::Scissor(x, y, width, height))) .unwrap() |