mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #21461 - jdm:webgltmp2, r=nox
Various webgl fixes for framebuffer attachment test These changes resolve all panics on macOS when running framebuffer-object-attachment.html in headless and headful testing. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes OR - [x] Fixes #13710. Fixes #20570. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21461) <!-- Reviewable:end -->
This commit is contained in:
commit
26745b2741
12 changed files with 655 additions and 177 deletions
|
@ -11,7 +11,7 @@ use offscreen_gl_context::{GLLimits, GLVersion};
|
||||||
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods};
|
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods};
|
||||||
use offscreen_gl_context::{OSMesaContext, OSMesaContextHandle};
|
use offscreen_gl_context::{OSMesaContext, OSMesaContextHandle};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use super::webgl_thread::WebGLImpl;
|
use super::webgl_thread::{WebGLImpl, GLState};
|
||||||
|
|
||||||
/// The GLContextFactory is used to create shared GL contexts with the main thread GL context.
|
/// The GLContextFactory is used to create shared GL contexts with the main thread GL context.
|
||||||
/// Currently, shared textures are used to render WebGL textures into the WR compositor.
|
/// Currently, shared textures are used to render WebGL textures into the WR compositor.
|
||||||
|
@ -144,13 +144,13 @@ impl GLContextWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_command(&self, cmd: WebGLCommand) {
|
pub fn apply_command(&self, cmd: WebGLCommand, state: &mut GLState) {
|
||||||
match *self {
|
match *self {
|
||||||
GLContextWrapper::Native(ref ctx) => {
|
GLContextWrapper::Native(ref ctx) => {
|
||||||
WebGLImpl::apply(ctx, cmd);
|
WebGLImpl::apply(ctx, state, cmd);
|
||||||
}
|
}
|
||||||
GLContextWrapper::OSMesa(ref ctx) => {
|
GLContextWrapper::OSMesa(ref ctx) => {
|
||||||
WebGLImpl::apply(ctx, cmd);
|
WebGLImpl::apply(ctx, state, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,33 @@ use webrender_api;
|
||||||
/// It allows to get a WebGLThread handle for each script pipeline.
|
/// It allows to get a WebGLThread handle for each script pipeline.
|
||||||
pub use ::webgl_mode::WebGLThreads;
|
pub use ::webgl_mode::WebGLThreads;
|
||||||
|
|
||||||
|
struct GLContextData {
|
||||||
|
ctx: GLContextWrapper,
|
||||||
|
state: GLState,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GLState {
|
||||||
|
clear_color: (f32, f32, f32, f32),
|
||||||
|
scissor_test_enabled: bool,
|
||||||
|
stencil_write_mask: (u32, u32),
|
||||||
|
stencil_clear_value: i32,
|
||||||
|
depth_write_mask: bool,
|
||||||
|
depth_clear_value: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for GLState {
|
||||||
|
fn default() -> GLState {
|
||||||
|
GLState {
|
||||||
|
clear_color: (0., 0., 0., 0.),
|
||||||
|
scissor_test_enabled: false,
|
||||||
|
stencil_write_mask: (0, 0),
|
||||||
|
stencil_clear_value: 0,
|
||||||
|
depth_write_mask: true,
|
||||||
|
depth_clear_value: 1.,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A WebGLThread manages the life cycle and message multiplexing of
|
/// A WebGLThread manages the life cycle and message multiplexing of
|
||||||
/// a set of WebGLContexts living in the same thread.
|
/// a set of WebGLContexts living in the same thread.
|
||||||
pub struct WebGLThread<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> {
|
pub struct WebGLThread<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> {
|
||||||
|
@ -26,7 +53,7 @@ pub struct WebGLThread<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver
|
||||||
/// Channel used to generate/update or delete `webrender_api::ImageKey`s.
|
/// Channel used to generate/update or delete `webrender_api::ImageKey`s.
|
||||||
webrender_api: webrender_api::RenderApi,
|
webrender_api: webrender_api::RenderApi,
|
||||||
/// Map of live WebGLContexts.
|
/// Map of live WebGLContexts.
|
||||||
contexts: FnvHashMap<WebGLContextId, GLContextWrapper>,
|
contexts: FnvHashMap<WebGLContextId, GLContextData>,
|
||||||
/// Cached information for WebGLContexts.
|
/// Cached information for WebGLContexts.
|
||||||
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
|
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
|
||||||
/// Current bound context.
|
/// Current bound context.
|
||||||
|
@ -93,9 +120,9 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
WebGLMsg::CreateContext(version, size, attributes, result_sender) => {
|
WebGLMsg::CreateContext(version, size, attributes, result_sender) => {
|
||||||
let result = self.create_webgl_context(version, size, attributes);
|
let result = self.create_webgl_context(version, size, attributes);
|
||||||
result_sender.send(result.map(|(id, limits, share_mode)| {
|
result_sender.send(result.map(|(id, limits, share_mode)| {
|
||||||
let ctx = Self::make_current_if_needed(id, &self.contexts, &mut self.bound_context_id)
|
let data = Self::make_current_if_needed(id, &self.contexts, &mut self.bound_context_id)
|
||||||
.expect("WebGLContext not found");
|
.expect("WebGLContext not found");
|
||||||
let glsl_version = Self::get_glsl_version(ctx);
|
let glsl_version = Self::get_glsl_version(&data.ctx);
|
||||||
|
|
||||||
WebGLCreateContextResult {
|
WebGLCreateContextResult {
|
||||||
sender: WebGLMsgSender::new(id, webgl_chan.clone()),
|
sender: WebGLMsgSender::new(id, webgl_chan.clone()),
|
||||||
|
@ -139,8 +166,9 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
|
|
||||||
/// Handles a WebGLCommand for a specific WebGLContext
|
/// Handles a WebGLCommand for a specific WebGLContext
|
||||||
fn handle_webgl_command(&mut self, context_id: WebGLContextId, command: WebGLCommand) {
|
fn handle_webgl_command(&mut self, context_id: WebGLContextId, command: WebGLCommand) {
|
||||||
if let Some(ctx) = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id) {
|
let data = Self::make_current_if_needed_mut(context_id, &mut self.contexts, &mut self.bound_context_id);
|
||||||
ctx.apply_command(command);
|
if let Some(data) = data {
|
||||||
|
data.ctx.apply_command(command, &mut data.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,28 +186,28 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
|
|
||||||
/// Handles a lock external callback received from webrender::ExternalImageHandler
|
/// Handles a lock external callback received from webrender::ExternalImageHandler
|
||||||
fn handle_lock(&mut self, context_id: WebGLContextId, sender: WebGLSender<(u32, Size2D<i32>, usize)>) {
|
fn handle_lock(&mut self, context_id: WebGLContextId, sender: WebGLSender<(u32, Size2D<i32>, usize)>) {
|
||||||
let ctx = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
let data = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
||||||
.expect("WebGLContext not found in a WebGLMsg::Lock message");
|
.expect("WebGLContext not found in a WebGLMsg::Lock message");
|
||||||
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
||||||
// Insert a OpenGL Fence sync object that sends a signal when all the WebGL commands are finished.
|
// Insert a OpenGL Fence sync object that sends a signal when all the WebGL commands are finished.
|
||||||
// The related gl().wait_sync call is performed in the WR thread. See WebGLExternalImageApi for mor details.
|
// The related gl().wait_sync call is performed in the WR thread. See WebGLExternalImageApi for mor details.
|
||||||
let gl_sync = ctx.gl().fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0);
|
let gl_sync = data.ctx.gl().fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||||
info.gl_sync = Some(gl_sync);
|
info.gl_sync = Some(gl_sync);
|
||||||
// It is important that the fence sync is properly flushed into the GPU's command queue.
|
// It is important that the fence sync is properly flushed into the GPU's command queue.
|
||||||
// Without proper flushing, the sync object may never be signaled.
|
// Without proper flushing, the sync object may never be signaled.
|
||||||
ctx.gl().flush();
|
data.ctx.gl().flush();
|
||||||
|
|
||||||
sender.send((info.texture_id, info.size, gl_sync as usize)).unwrap();
|
sender.send((info.texture_id, info.size, gl_sync as usize)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles an unlock external callback received from webrender::ExternalImageHandler
|
/// Handles an unlock external callback received from webrender::ExternalImageHandler
|
||||||
fn handle_unlock(&mut self, context_id: WebGLContextId) {
|
fn handle_unlock(&mut self, context_id: WebGLContextId) {
|
||||||
let ctx = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
let data = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
||||||
.expect("WebGLContext not found in a WebGLMsg::Unlock message");
|
.expect("WebGLContext not found in a WebGLMsg::Unlock message");
|
||||||
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
||||||
if let Some(gl_sync) = info.gl_sync.take() {
|
if let Some(gl_sync) = info.gl_sync.take() {
|
||||||
// Release the GLSync object.
|
// Release the GLSync object.
|
||||||
ctx.gl().delete_sync(gl_sync);
|
data.ctx.gl().delete_sync(gl_sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +235,10 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
let id = WebGLContextId(self.next_webgl_id);
|
let id = WebGLContextId(self.next_webgl_id);
|
||||||
let (size, texture_id, limits) = ctx.get_info();
|
let (size, texture_id, limits) = ctx.get_info();
|
||||||
self.next_webgl_id += 1;
|
self.next_webgl_id += 1;
|
||||||
self.contexts.insert(id, ctx);
|
self.contexts.insert(id, GLContextData {
|
||||||
|
ctx,
|
||||||
|
state: Default::default(),
|
||||||
|
});
|
||||||
self.cached_context_info.insert(id, WebGLContextInfo {
|
self.cached_context_info.insert(id, WebGLContextInfo {
|
||||||
texture_id,
|
texture_id,
|
||||||
size,
|
size,
|
||||||
|
@ -232,10 +263,14 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
context_id: WebGLContextId,
|
context_id: WebGLContextId,
|
||||||
size: Size2D<i32>,
|
size: Size2D<i32>,
|
||||||
sender: WebGLSender<Result<(), String>>) {
|
sender: WebGLSender<Result<(), String>>) {
|
||||||
let ctx = Self::make_current_if_needed_mut(context_id, &mut self.contexts, &mut self.bound_context_id);
|
let data = Self::make_current_if_needed_mut(
|
||||||
match ctx.resize(size) {
|
context_id,
|
||||||
|
&mut self.contexts,
|
||||||
|
&mut self.bound_context_id
|
||||||
|
).expect("Missing WebGL context!");
|
||||||
|
match data.ctx.resize(size) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let (real_size, texture_id, _) = ctx.get_info();
|
let (real_size, texture_id, _) = data.ctx.get_info();
|
||||||
self.observer.on_context_resize(context_id, texture_id, real_size);
|
self.observer.on_context_resize(context_id, texture_id, real_size);
|
||||||
|
|
||||||
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
let info = self.cached_context_info.get_mut(&context_id).unwrap();
|
||||||
|
@ -306,7 +341,7 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
WebGLContextShareMode::Readback => {
|
WebGLContextShareMode::Readback => {
|
||||||
let pixels = Self::raw_pixels(&self.contexts[&context_id], info.size);
|
let pixels = Self::raw_pixels(&self.contexts[&context_id].ctx, info.size);
|
||||||
match info.image_key.clone() {
|
match info.image_key.clone() {
|
||||||
Some(image_key) => {
|
Some(image_key) => {
|
||||||
// ImageKey was already created, but WR Images must
|
// ImageKey was already created, but WR Images must
|
||||||
|
@ -339,18 +374,20 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
fn handle_dom_to_texture(&mut self, command: DOMToTextureCommand) {
|
fn handle_dom_to_texture(&mut self, command: DOMToTextureCommand) {
|
||||||
match command {
|
match command {
|
||||||
DOMToTextureCommand::Attach(context_id, texture_id, document_id, pipeline_id, size) => {
|
DOMToTextureCommand::Attach(context_id, texture_id, document_id, pipeline_id, size) => {
|
||||||
let ctx = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
let data = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
||||||
.expect("WebGLContext not found in a WebGL DOMToTextureCommand::Attach command");
|
.expect("WebGLContext not found in a WebGL DOMToTextureCommand::Attach command");
|
||||||
// Initialize the texture that WR will use for frame outputs.
|
// Initialize the texture that WR will use for frame outputs.
|
||||||
ctx.gl().tex_image_2d(gl::TEXTURE_2D,
|
data.ctx.gl().tex_image_2d(
|
||||||
0,
|
gl::TEXTURE_2D,
|
||||||
gl::RGBA as gl::GLint,
|
0,
|
||||||
size.width,
|
gl::RGBA as gl::GLint,
|
||||||
size.height,
|
size.width,
|
||||||
0,
|
size.height,
|
||||||
gl::RGBA,
|
0,
|
||||||
gl::UNSIGNED_BYTE,
|
gl::RGBA,
|
||||||
None);
|
gl::UNSIGNED_BYTE,
|
||||||
|
None
|
||||||
|
);
|
||||||
self.dom_outputs.insert(pipeline_id, DOMToTextureData {
|
self.dom_outputs.insert(pipeline_id, DOMToTextureData {
|
||||||
context_id, texture_id, document_id, size
|
context_id, texture_id, document_id, size
|
||||||
});
|
});
|
||||||
|
@ -361,14 +398,14 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
DOMToTextureCommand::Lock(pipeline_id, gl_sync, sender) => {
|
DOMToTextureCommand::Lock(pipeline_id, gl_sync, sender) => {
|
||||||
let contexts = &self.contexts;
|
let contexts = &self.contexts;
|
||||||
let bound_context_id = &mut self.bound_context_id;
|
let bound_context_id = &mut self.bound_context_id;
|
||||||
let result = self.dom_outputs.get(&pipeline_id).and_then(|data| {
|
let result = self.dom_outputs.get(&pipeline_id).and_then(|dom_data| {
|
||||||
let ctx = Self::make_current_if_needed(data.context_id, contexts, bound_context_id);
|
let data = Self::make_current_if_needed(dom_data.context_id, contexts, bound_context_id);
|
||||||
ctx.and_then(|ctx| {
|
data.and_then(|data| {
|
||||||
// The next glWaitSync call is used to synchronize the two flows of
|
// The next glWaitSync call is used to synchronize the two flows of
|
||||||
// OpenGL commands (WR and WebGL) in order to avoid using semi-ready WR textures.
|
// OpenGL commands (WR and WebGL) in order to avoid using semi-ready WR textures.
|
||||||
// glWaitSync doesn't block WebGL CPU thread.
|
// glWaitSync doesn't block WebGL CPU thread.
|
||||||
ctx.gl().wait_sync(gl_sync as gl::GLsync, 0, gl::TIMEOUT_IGNORED);
|
data.ctx.gl().wait_sync(gl_sync as gl::GLsync, 0, gl::TIMEOUT_IGNORED);
|
||||||
Some((data.texture_id.get(), data.size))
|
Some((dom_data.texture_id.get(), dom_data.size))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -390,28 +427,37 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
|
|
||||||
/// Gets a reference to a GLContextWrapper for a given WebGLContextId and makes it current if required.
|
/// Gets a reference to a GLContextWrapper for a given WebGLContextId and makes it current if required.
|
||||||
fn make_current_if_needed<'a>(context_id: WebGLContextId,
|
fn make_current_if_needed<'a>(context_id: WebGLContextId,
|
||||||
contexts: &'a FnvHashMap<WebGLContextId, GLContextWrapper>,
|
contexts: &'a FnvHashMap<WebGLContextId, GLContextData>,
|
||||||
bound_id: &mut Option<WebGLContextId>) -> Option<&'a GLContextWrapper> {
|
bound_id: &mut Option<WebGLContextId>) -> Option<&'a GLContextData> {
|
||||||
contexts.get(&context_id).and_then(|ctx| {
|
let data = contexts.get(&context_id);
|
||||||
|
|
||||||
|
if let Some(data) = data {
|
||||||
if Some(context_id) != *bound_id {
|
if Some(context_id) != *bound_id {
|
||||||
ctx.make_current();
|
data.ctx.make_current();
|
||||||
*bound_id = Some(context_id);
|
*bound_id = Some(context_id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Some(ctx)
|
data
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a mutable reference to a GLContextWrapper for a WebGLContextId and makes it current if required.
|
/// Gets a mutable reference to a GLContextWrapper for a WebGLContextId and makes it current if required.
|
||||||
fn make_current_if_needed_mut<'a>(context_id: WebGLContextId,
|
fn make_current_if_needed_mut<'a>(
|
||||||
contexts: &'a mut FnvHashMap<WebGLContextId, GLContextWrapper>,
|
context_id: WebGLContextId,
|
||||||
bound_id: &mut Option<WebGLContextId>) -> &'a mut GLContextWrapper {
|
contexts: &'a mut FnvHashMap<WebGLContextId, GLContextData>,
|
||||||
let ctx = contexts.get_mut(&context_id).expect("WebGLContext not found!");
|
bound_id: &mut Option<WebGLContextId>)
|
||||||
if Some(context_id) != *bound_id {
|
-> Option<&'a mut GLContextData>
|
||||||
ctx.make_current();
|
{
|
||||||
*bound_id = Some(context_id);
|
let data = contexts.get_mut(&context_id);
|
||||||
|
|
||||||
|
if let Some(ref data) = data {
|
||||||
|
if Some(context_id) != *bound_id {
|
||||||
|
data.ctx.make_current();
|
||||||
|
*bound_id = Some(context_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctx
|
|
||||||
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `webrender_api::ImageKey` that uses shared textures.
|
/// Creates a `webrender_api::ImageKey` that uses shared textures.
|
||||||
|
@ -636,7 +682,11 @@ pub struct WebGLImpl;
|
||||||
|
|
||||||
impl WebGLImpl {
|
impl WebGLImpl {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn apply<Native: NativeGLContextMethods>(ctx: &GLContext<Native>, command: WebGLCommand) {
|
pub fn apply<Native: NativeGLContextMethods>(
|
||||||
|
ctx: &GLContext<Native>,
|
||||||
|
state: &mut GLState,
|
||||||
|
command: WebGLCommand
|
||||||
|
) {
|
||||||
match command {
|
match command {
|
||||||
WebGLCommand::GetContextAttributes(ref sender) =>
|
WebGLCommand::GetContextAttributes(ref sender) =>
|
||||||
sender.send(*ctx.borrow_attributes()).unwrap(),
|
sender.send(*ctx.borrow_attributes()).unwrap(),
|
||||||
|
@ -667,13 +717,19 @@ impl WebGLImpl {
|
||||||
},
|
},
|
||||||
WebGLCommand::Clear(mask) =>
|
WebGLCommand::Clear(mask) =>
|
||||||
ctx.gl().clear(mask),
|
ctx.gl().clear(mask),
|
||||||
WebGLCommand::ClearColor(r, g, b, a) =>
|
WebGLCommand::ClearColor(r, g, b, a) => {
|
||||||
ctx.gl().clear_color(r, g, b, a),
|
state.clear_color = (r, g, b, a);
|
||||||
WebGLCommand::ClearDepth(depth) => {
|
ctx.gl().clear_color(r, g, b, a);
|
||||||
ctx.gl().clear_depth(depth.max(0.).min(1.) as f64)
|
}
|
||||||
|
WebGLCommand::ClearDepth(depth) => {
|
||||||
|
let value = depth.max(0.).min(1.) as f64;
|
||||||
|
state.depth_clear_value = value;
|
||||||
|
ctx.gl().clear_depth(value)
|
||||||
|
}
|
||||||
|
WebGLCommand::ClearStencil(stencil) => {
|
||||||
|
state.stencil_clear_value = stencil;
|
||||||
|
ctx.gl().clear_stencil(stencil);
|
||||||
}
|
}
|
||||||
WebGLCommand::ClearStencil(stencil) =>
|
|
||||||
ctx.gl().clear_stencil(stencil),
|
|
||||||
WebGLCommand::ColorMask(r, g, b, a) =>
|
WebGLCommand::ColorMask(r, g, b, a) =>
|
||||||
ctx.gl().color_mask(r, g, b, a),
|
ctx.gl().color_mask(r, g, b, a),
|
||||||
WebGLCommand::CopyTexImage2D(target, level, internal_format, x, y, width, height, border) =>
|
WebGLCommand::CopyTexImage2D(target, level, internal_format, x, y, width, height, border) =>
|
||||||
|
@ -684,21 +740,50 @@ impl WebGLImpl {
|
||||||
ctx.gl().cull_face(mode),
|
ctx.gl().cull_face(mode),
|
||||||
WebGLCommand::DepthFunc(func) =>
|
WebGLCommand::DepthFunc(func) =>
|
||||||
ctx.gl().depth_func(func),
|
ctx.gl().depth_func(func),
|
||||||
WebGLCommand::DepthMask(flag) =>
|
WebGLCommand::DepthMask(flag) => {
|
||||||
ctx.gl().depth_mask(flag),
|
state.depth_write_mask = flag;
|
||||||
|
ctx.gl().depth_mask(flag);
|
||||||
|
}
|
||||||
WebGLCommand::DepthRange(near, far) => {
|
WebGLCommand::DepthRange(near, far) => {
|
||||||
ctx.gl().depth_range(near.max(0.).min(1.) as f64, far.max(0.).min(1.) as f64)
|
ctx.gl().depth_range(near.max(0.).min(1.) as f64, far.max(0.).min(1.) as f64)
|
||||||
}
|
}
|
||||||
WebGLCommand::Disable(cap) =>
|
WebGLCommand::Disable(cap) => {
|
||||||
ctx.gl().disable(cap),
|
if cap == gl::SCISSOR_TEST {
|
||||||
WebGLCommand::Enable(cap) =>
|
state.scissor_test_enabled = false;
|
||||||
ctx.gl().enable(cap),
|
}
|
||||||
WebGLCommand::FramebufferRenderbuffer(target, attachment, renderbuffertarget, rb) =>
|
ctx.gl().disable(cap);
|
||||||
ctx.gl().framebuffer_renderbuffer(target, attachment, renderbuffertarget,
|
}
|
||||||
rb.map_or(0, WebGLRenderbufferId::get)),
|
WebGLCommand::Enable(cap) => {
|
||||||
WebGLCommand::FramebufferTexture2D(target, attachment, textarget, texture, level) =>
|
if cap == gl::SCISSOR_TEST {
|
||||||
ctx.gl().framebuffer_texture_2d(target, attachment, textarget,
|
state.scissor_test_enabled = true;
|
||||||
texture.map_or(0, WebGLTextureId::get), level),
|
}
|
||||||
|
ctx.gl().enable(cap);
|
||||||
|
}
|
||||||
|
WebGLCommand::FramebufferRenderbuffer(target, attachment, renderbuffertarget, rb) => {
|
||||||
|
let attach = |attachment| {
|
||||||
|
ctx.gl().framebuffer_renderbuffer(target, attachment,
|
||||||
|
renderbuffertarget,
|
||||||
|
rb.map_or(0, WebGLRenderbufferId::get))
|
||||||
|
};
|
||||||
|
if attachment == gl::DEPTH_STENCIL_ATTACHMENT {
|
||||||
|
attach(gl::DEPTH_ATTACHMENT);
|
||||||
|
attach(gl::STENCIL_ATTACHMENT);
|
||||||
|
} else {
|
||||||
|
attach(attachment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WebGLCommand::FramebufferTexture2D(target, attachment, textarget, texture, level) => {
|
||||||
|
let attach = |attachment| {
|
||||||
|
ctx.gl().framebuffer_texture_2d(target, attachment, textarget,
|
||||||
|
texture.map_or(0, WebGLTextureId::get), level)
|
||||||
|
};
|
||||||
|
if attachment == gl::DEPTH_STENCIL_ATTACHMENT {
|
||||||
|
attach(gl::DEPTH_ATTACHMENT);
|
||||||
|
attach(gl::STENCIL_ATTACHMENT);
|
||||||
|
} else {
|
||||||
|
attach(attachment)
|
||||||
|
}
|
||||||
|
}
|
||||||
WebGLCommand::FrontFace(mode) =>
|
WebGLCommand::FrontFace(mode) =>
|
||||||
ctx.gl().front_face(mode),
|
ctx.gl().front_face(mode),
|
||||||
WebGLCommand::DisableVertexAttribArray(attrib_id) =>
|
WebGLCommand::DisableVertexAttribArray(attrib_id) =>
|
||||||
|
@ -726,10 +811,18 @@ impl WebGLImpl {
|
||||||
ctx.gl().stencil_func(func, ref_, mask),
|
ctx.gl().stencil_func(func, ref_, mask),
|
||||||
WebGLCommand::StencilFuncSeparate(face, func, ref_, mask) =>
|
WebGLCommand::StencilFuncSeparate(face, func, ref_, mask) =>
|
||||||
ctx.gl().stencil_func_separate(face, func, ref_, mask),
|
ctx.gl().stencil_func_separate(face, func, ref_, mask),
|
||||||
WebGLCommand::StencilMask(mask) =>
|
WebGLCommand::StencilMask(mask) => {
|
||||||
ctx.gl().stencil_mask(mask),
|
state.stencil_write_mask = (mask, mask);
|
||||||
WebGLCommand::StencilMaskSeparate(face, mask) =>
|
ctx.gl().stencil_mask(mask);
|
||||||
ctx.gl().stencil_mask_separate(face, mask),
|
}
|
||||||
|
WebGLCommand::StencilMaskSeparate(face, mask) => {
|
||||||
|
if face == gl::FRONT {
|
||||||
|
state.stencil_write_mask.0 = mask;
|
||||||
|
} else {
|
||||||
|
state.stencil_write_mask.1 = mask;
|
||||||
|
}
|
||||||
|
ctx.gl().stencil_mask_separate(face, mask);
|
||||||
|
}
|
||||||
WebGLCommand::StencilOp(fail, zfail, zpass) =>
|
WebGLCommand::StencilOp(fail, zfail, zpass) =>
|
||||||
ctx.gl().stencil_op(fail, zfail, zpass),
|
ctx.gl().stencil_op(fail, zfail, zpass),
|
||||||
WebGLCommand::StencilOpSeparate(face, fail, zfail, zpass) =>
|
WebGLCommand::StencilOpSeparate(face, fail, zfail, zpass) =>
|
||||||
|
@ -1105,6 +1198,9 @@ impl WebGLImpl {
|
||||||
}
|
}
|
||||||
sender.send(value).unwrap();
|
sender.send(value).unwrap();
|
||||||
}
|
}
|
||||||
|
WebGLCommand::InitializeFramebuffer { color, depth, stencil } => {
|
||||||
|
Self::initialize_framebuffer(ctx.gl(), state, color, depth, stencil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: update test expectations in order to enable debug assertions
|
// TODO: update test expectations in order to enable debug assertions
|
||||||
|
@ -1115,6 +1211,62 @@ impl WebGLImpl {
|
||||||
assert_eq!(error, gl::NO_ERROR, "Unexpected WebGL error: 0x{:x} ({})", error, error);
|
assert_eq!(error, gl::NO_ERROR, "Unexpected WebGL error: 0x{:x} ({})", error, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn initialize_framebuffer(
|
||||||
|
gl: &gl::Gl,
|
||||||
|
state: &GLState,
|
||||||
|
color: bool,
|
||||||
|
depth: bool,
|
||||||
|
stencil: bool,
|
||||||
|
) {
|
||||||
|
let bits = [
|
||||||
|
(color, gl::COLOR_BUFFER_BIT),
|
||||||
|
(depth, gl::DEPTH_BUFFER_BIT),
|
||||||
|
(stencil, gl::STENCIL_BUFFER_BIT),
|
||||||
|
].iter().fold(0, |bits, &(enabled, bit)| bits | if enabled { bit } else { 0 });
|
||||||
|
|
||||||
|
if state.scissor_test_enabled {
|
||||||
|
gl.disable(gl::SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if color {
|
||||||
|
gl.clear_color(0., 0., 0., 0.);
|
||||||
|
}
|
||||||
|
|
||||||
|
if depth {
|
||||||
|
gl.depth_mask(true);
|
||||||
|
gl.clear_depth(1.);
|
||||||
|
}
|
||||||
|
|
||||||
|
if stencil {
|
||||||
|
gl.stencil_mask_separate(gl::FRONT, 0xFFFFFFFF);
|
||||||
|
gl.stencil_mask_separate(gl::BACK, 0xFFFFFFFF);
|
||||||
|
gl.clear_stencil(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.clear(bits);
|
||||||
|
|
||||||
|
if state.scissor_test_enabled {
|
||||||
|
gl.enable(gl::SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if color {
|
||||||
|
let (r, g, b, a) = state.clear_color;
|
||||||
|
gl.clear_color(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if depth {
|
||||||
|
gl.depth_mask(state.depth_write_mask);
|
||||||
|
gl.clear_depth(state.depth_clear_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if stencil {
|
||||||
|
let (front, back) = state.stencil_write_mask;
|
||||||
|
gl.stencil_mask_separate(gl::FRONT, front);
|
||||||
|
gl.stencil_mask_separate(gl::BACK, back);
|
||||||
|
gl.clear_stencil(state.stencil_clear_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn link_program(gl: &gl::Gl, program: WebGLProgramId) -> ProgramLinkInfo {
|
fn link_program(gl: &gl::Gl, program: WebGLProgramId) -> ProgramLinkInfo {
|
||||||
gl.link_program(program.get());
|
gl.link_program(program.get());
|
||||||
|
|
|
@ -296,6 +296,7 @@ pub enum WebGLCommand {
|
||||||
GetUniformFloat4(WebGLProgramId, i32, WebGLSender<[f32; 4]>),
|
GetUniformFloat4(WebGLProgramId, i32, WebGLSender<[f32; 4]>),
|
||||||
GetUniformFloat9(WebGLProgramId, i32, WebGLSender<[f32; 9]>),
|
GetUniformFloat9(WebGLProgramId, i32, WebGLSender<[f32; 9]>),
|
||||||
GetUniformFloat16(WebGLProgramId, i32, WebGLSender<[f32; 16]>),
|
GetUniformFloat16(WebGLProgramId, i32, WebGLSender<[f32; 16]>),
|
||||||
|
InitializeFramebuffer { color: bool, depth: bool, stencil: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_resource_id_struct {
|
macro_rules! define_resource_id_struct {
|
||||||
|
|
|
@ -18,6 +18,12 @@ use dom::webgltexture::WebGLTexture;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
|
pub enum CompleteForRendering {
|
||||||
|
Complete,
|
||||||
|
Incomplete,
|
||||||
|
MissingColorAttachment,
|
||||||
|
}
|
||||||
|
|
||||||
#[must_root]
|
#[must_root]
|
||||||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||||
enum WebGLFramebufferAttachment {
|
enum WebGLFramebufferAttachment {
|
||||||
|
@ -25,6 +31,31 @@ enum WebGLFramebufferAttachment {
|
||||||
Texture { texture: Dom<WebGLTexture>, level: i32 },
|
Texture { texture: Dom<WebGLTexture>, level: i32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WebGLFramebufferAttachment {
|
||||||
|
fn needs_initialization(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
WebGLFramebufferAttachment::Renderbuffer(ref r) => !r.is_initialized(),
|
||||||
|
WebGLFramebufferAttachment::Texture { .. } => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mark_initialized(&self) {
|
||||||
|
match *self {
|
||||||
|
WebGLFramebufferAttachment::Renderbuffer(ref r) => r.mark_initialized(),
|
||||||
|
WebGLFramebufferAttachment::Texture { .. } => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn root(&self) -> WebGLFramebufferAttachmentRoot {
|
||||||
|
match *self {
|
||||||
|
WebGLFramebufferAttachment::Renderbuffer(ref rb) =>
|
||||||
|
WebGLFramebufferAttachmentRoot::Renderbuffer(DomRoot::from_ref(&rb)),
|
||||||
|
WebGLFramebufferAttachment::Texture { ref texture, .. } =>
|
||||||
|
WebGLFramebufferAttachmentRoot::Texture(DomRoot::from_ref(&texture)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||||
pub enum WebGLFramebufferAttachmentRoot {
|
pub enum WebGLFramebufferAttachmentRoot {
|
||||||
Renderbuffer(DomRoot<WebGLRenderbuffer>),
|
Renderbuffer(DomRoot<WebGLRenderbuffer>),
|
||||||
|
@ -46,6 +77,7 @@ pub struct WebGLFramebuffer {
|
||||||
depth: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
depth: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
stencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
stencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
depthstencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
depthstencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
|
is_initialized: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLFramebuffer {
|
impl WebGLFramebuffer {
|
||||||
|
@ -56,11 +88,12 @@ impl WebGLFramebuffer {
|
||||||
target: Cell::new(None),
|
target: Cell::new(None),
|
||||||
is_deleted: Cell::new(false),
|
is_deleted: Cell::new(false),
|
||||||
size: Cell::new(None),
|
size: Cell::new(None),
|
||||||
status: Cell::new(constants::FRAMEBUFFER_UNSUPPORTED),
|
status: Cell::new(constants::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
|
||||||
color: DomRefCell::new(None),
|
color: DomRefCell::new(None),
|
||||||
depth: DomRefCell::new(None),
|
depth: DomRefCell::new(None),
|
||||||
stencil: DomRefCell::new(None),
|
stencil: DomRefCell::new(None),
|
||||||
depthstencil: DomRefCell::new(None),
|
depthstencil: DomRefCell::new(None),
|
||||||
|
is_initialized: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +160,12 @@ impl WebGLFramebuffer {
|
||||||
let has_s = s.is_some();
|
let has_s = s.is_some();
|
||||||
let has_zs = zs.is_some();
|
let has_zs = zs.is_some();
|
||||||
let attachments = [&*c, &*z, &*s, &*zs];
|
let attachments = [&*c, &*z, &*s, &*zs];
|
||||||
|
let attachment_constraints = [
|
||||||
|
&[constants::RGBA4, constants::RGB5_A1, constants::RGB565, constants::RGBA][..],
|
||||||
|
&[constants::DEPTH_COMPONENT16][..],
|
||||||
|
&[constants::STENCIL_INDEX8][..],
|
||||||
|
&[constants::DEPTH_STENCIL][..],
|
||||||
|
];
|
||||||
|
|
||||||
// From the WebGL spec, 6.6 ("Framebuffer Object Attachments"):
|
// From the WebGL spec, 6.6 ("Framebuffer Object Attachments"):
|
||||||
//
|
//
|
||||||
|
@ -148,17 +187,18 @@ impl WebGLFramebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut fb_size = None;
|
let mut fb_size = None;
|
||||||
for attachment in &attachments {
|
for (attachment, constraints) in attachments.iter().zip(&attachment_constraints) {
|
||||||
// Get the size of this attachment.
|
// Get the size of this attachment.
|
||||||
let size = match **attachment {
|
let (format, size) = match **attachment {
|
||||||
Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb)) => {
|
Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb)) => {
|
||||||
att_rb.size()
|
(Some(att_rb.internal_format()), att_rb.size())
|
||||||
}
|
}
|
||||||
Some(WebGLFramebufferAttachment::Texture { texture: ref att_tex, level } ) => {
|
Some(WebGLFramebufferAttachment::Texture { texture: ref att_tex, level } ) => {
|
||||||
let info = att_tex.image_info_at_face(0, level as u32);
|
let info = att_tex.image_info_at_face(0, level as u32);
|
||||||
Some((info.width() as i32, info.height() as i32))
|
(info.internal_format().map(|t| t.as_gl_constant()),
|
||||||
|
Some((info.width() as i32, info.height() as i32)))
|
||||||
}
|
}
|
||||||
None => None,
|
None => (None, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make sure that, if we've found any other attachment,
|
// Make sure that, if we've found any other attachment,
|
||||||
|
@ -171,6 +211,13 @@ impl WebGLFramebuffer {
|
||||||
fb_size = size;
|
fb_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(format) = format {
|
||||||
|
if constraints.iter().all(|c| *c != format) {
|
||||||
|
self.status.set(constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.size.set(fb_size);
|
self.size.set(fb_size);
|
||||||
|
|
||||||
|
@ -181,7 +228,7 @@ impl WebGLFramebuffer {
|
||||||
self.status.set(constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
|
self.status.set(constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.status.set(constants::FRAMEBUFFER_UNSUPPORTED);
|
self.status.set(constants::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,25 +236,52 @@ impl WebGLFramebuffer {
|
||||||
return self.status.get();
|
return self.status.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_status_for_rendering(&self) -> CompleteForRendering {
|
||||||
|
let result = self.check_status();
|
||||||
|
if result != constants::FRAMEBUFFER_COMPLETE {
|
||||||
|
return CompleteForRendering::Incomplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.color.borrow().is_none() {
|
||||||
|
return CompleteForRendering::MissingColorAttachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.is_initialized.get() {
|
||||||
|
let attachments = [
|
||||||
|
(&self.color, constants::COLOR_BUFFER_BIT),
|
||||||
|
(&self.depth, constants::DEPTH_BUFFER_BIT),
|
||||||
|
(&self.stencil, constants::STENCIL_BUFFER_BIT),
|
||||||
|
(&self.depthstencil, constants::DEPTH_BUFFER_BIT | constants::STENCIL_BUFFER_BIT)
|
||||||
|
];
|
||||||
|
let mut clear_bits = 0;
|
||||||
|
for &(attachment, bits) in &attachments {
|
||||||
|
if let Some(ref att) = *attachment.borrow() {
|
||||||
|
if att.needs_initialization() {
|
||||||
|
att.mark_initialized();
|
||||||
|
clear_bits |= bits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.upcast::<WebGLObject>().context().initialize_framebuffer(clear_bits);
|
||||||
|
self.is_initialized.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompleteForRendering::Complete
|
||||||
|
}
|
||||||
|
|
||||||
pub fn renderbuffer(&self, attachment: u32, rb: Option<&WebGLRenderbuffer>) -> WebGLResult<()> {
|
pub fn renderbuffer(&self, attachment: u32, rb: Option<&WebGLRenderbuffer>) -> WebGLResult<()> {
|
||||||
let binding = match attachment {
|
let binding = self.attachment_binding(attachment).ok_or(WebGLError::InvalidEnum)?;
|
||||||
constants::COLOR_ATTACHMENT0 => &self.color,
|
|
||||||
constants::DEPTH_ATTACHMENT => &self.depth,
|
|
||||||
constants::STENCIL_ATTACHMENT => &self.stencil,
|
|
||||||
constants::DEPTH_STENCIL_ATTACHMENT => &self.depthstencil,
|
|
||||||
_ => return Err(WebGLError::InvalidEnum),
|
|
||||||
};
|
|
||||||
|
|
||||||
let rb_id = match rb {
|
let rb_id = match rb {
|
||||||
Some(rb) => {
|
Some(rb) => {
|
||||||
|
if !rb.ever_bound() {
|
||||||
|
return Err(WebGLError::InvalidOperation);
|
||||||
|
}
|
||||||
*binding.borrow_mut() = Some(WebGLFramebufferAttachment::Renderbuffer(Dom::from_ref(rb)));
|
*binding.borrow_mut() = Some(WebGLFramebufferAttachment::Renderbuffer(Dom::from_ref(rb)));
|
||||||
Some(rb.id())
|
Some(rb.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => None
|
||||||
*binding.borrow_mut() = None;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.upcast::<WebGLObject>().context().send_command(
|
self.upcast::<WebGLObject>().context().send_command(
|
||||||
|
@ -219,38 +293,91 @@ impl WebGLFramebuffer {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if rb.is_none() {
|
||||||
|
self.detach_binding(binding, attachment);
|
||||||
|
}
|
||||||
|
|
||||||
self.update_status();
|
self.update_status();
|
||||||
|
self.is_initialized.set(false);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn attachment(&self, attachment: u32) -> Option<WebGLFramebufferAttachmentRoot> {
|
fn detach_binding(
|
||||||
let binding = match attachment {
|
&self,
|
||||||
constants::COLOR_ATTACHMENT0 => &self.color,
|
binding: &DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
constants::DEPTH_ATTACHMENT => &self.depth,
|
attachment: u32,
|
||||||
constants::STENCIL_ATTACHMENT => &self.stencil,
|
) {
|
||||||
constants::DEPTH_STENCIL_ATTACHMENT => &self.depthstencil,
|
*binding.borrow_mut() = None;
|
||||||
_ => return None,
|
if INTERESTING_ATTACHMENT_POINTS.contains(&attachment) {
|
||||||
|
self.reattach_depth_stencil();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn attachment_binding(
|
||||||
|
&self,
|
||||||
|
attachment: u32
|
||||||
|
) -> Option<&DomRefCell<Option<WebGLFramebufferAttachment>>>
|
||||||
|
{
|
||||||
|
match attachment {
|
||||||
|
constants::COLOR_ATTACHMENT0 => Some(&self.color),
|
||||||
|
constants::DEPTH_ATTACHMENT => Some(&self.depth),
|
||||||
|
constants::STENCIL_ATTACHMENT => Some(&self.stencil),
|
||||||
|
constants::DEPTH_STENCIL_ATTACHMENT => Some(&self.depthstencil),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reattach_depth_stencil(&self) {
|
||||||
|
let reattach = |attachment: &WebGLFramebufferAttachment, attachment_point| {
|
||||||
|
let context = self.upcast::<WebGLObject>().context();
|
||||||
|
match *attachment {
|
||||||
|
WebGLFramebufferAttachment::Renderbuffer(ref rb) => {
|
||||||
|
context.send_command(
|
||||||
|
WebGLCommand::FramebufferRenderbuffer(
|
||||||
|
constants::FRAMEBUFFER,
|
||||||
|
attachment_point,
|
||||||
|
constants::RENDERBUFFER,
|
||||||
|
Some(rb.id())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
WebGLFramebufferAttachment::Texture { ref texture, level } => {
|
||||||
|
context.send_command(
|
||||||
|
WebGLCommand::FramebufferTexture2D(
|
||||||
|
constants::FRAMEBUFFER,
|
||||||
|
attachment_point,
|
||||||
|
texture.target().expect("missing texture target"),
|
||||||
|
Some(texture.id()),
|
||||||
|
level
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
binding.borrow().as_ref().map(|bin| {
|
// Since the DEPTH_STENCIL attachment causes both the DEPTH and STENCIL
|
||||||
match bin {
|
// attachments to be overwritten, we need to ensure that we reattach
|
||||||
&WebGLFramebufferAttachment::Renderbuffer(ref rb) =>
|
// the DEPTH and STENCIL attachments when any of those attachments
|
||||||
WebGLFramebufferAttachmentRoot::Renderbuffer(DomRoot::from_ref(&rb)),
|
// is cleared.
|
||||||
&WebGLFramebufferAttachment::Texture { ref texture, .. } =>
|
if let Some(ref depth) = *self.depth.borrow() {
|
||||||
WebGLFramebufferAttachmentRoot::Texture(DomRoot::from_ref(&texture)),
|
reattach(depth, constants::DEPTH_ATTACHMENT);
|
||||||
}
|
}
|
||||||
})
|
if let Some(ref stencil) = *self.stencil.borrow() {
|
||||||
|
reattach(stencil, constants::STENCIL_ATTACHMENT);
|
||||||
|
}
|
||||||
|
if let Some(ref depth_stencil) = *self.depthstencil.borrow() {
|
||||||
|
reattach(depth_stencil, constants::DEPTH_STENCIL_ATTACHMENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn attachment(&self, attachment: u32) -> Option<WebGLFramebufferAttachmentRoot> {
|
||||||
|
let binding = self.attachment_binding(attachment)?;
|
||||||
|
binding.borrow().as_ref().map(WebGLFramebufferAttachment::root)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn texture2d(&self, attachment: u32, textarget: u32, texture: Option<&WebGLTexture>,
|
pub fn texture2d(&self, attachment: u32, textarget: u32, texture: Option<&WebGLTexture>,
|
||||||
level: i32) -> WebGLResult<()> {
|
level: i32) -> WebGLResult<()> {
|
||||||
let binding = match attachment {
|
let binding = self.attachment_binding(attachment).ok_or(WebGLError::InvalidEnum)?;
|
||||||
constants::COLOR_ATTACHMENT0 => &self.color,
|
|
||||||
constants::DEPTH_ATTACHMENT => &self.depth,
|
|
||||||
constants::STENCIL_ATTACHMENT => &self.stencil,
|
|
||||||
constants::DEPTH_STENCIL_ATTACHMENT => &self.depthstencil,
|
|
||||||
_ => return Err(WebGLError::InvalidEnum),
|
|
||||||
};
|
|
||||||
|
|
||||||
let tex_id = match texture {
|
let tex_id = match texture {
|
||||||
// Note, from the GLES 2.0.25 spec, page 113:
|
// Note, from the GLES 2.0.25 spec, page 113:
|
||||||
|
@ -304,7 +431,6 @@ impl WebGLFramebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
*binding.borrow_mut() = None;
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -319,19 +445,26 @@ impl WebGLFramebuffer {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if texture.is_none() {
|
||||||
|
self.detach_binding(binding, attachment);
|
||||||
|
}
|
||||||
|
|
||||||
self.update_status();
|
self.update_status();
|
||||||
|
self.is_initialized.set(false);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_matching_renderbuffers<F>(&self, rb: &WebGLRenderbuffer, mut closure: F)
|
fn with_matching_renderbuffers<F>(&self, rb: &WebGLRenderbuffer, mut closure: F)
|
||||||
where F: FnMut(&DomRefCell<Option<WebGLFramebufferAttachment>>)
|
where F: FnMut(&DomRefCell<Option<WebGLFramebufferAttachment>>, u32)
|
||||||
{
|
{
|
||||||
let attachments = [&self.color,
|
let attachments = [
|
||||||
&self.depth,
|
(&self.color, constants::COLOR_ATTACHMENT0),
|
||||||
&self.stencil,
|
(&self.depth, constants::DEPTH_ATTACHMENT),
|
||||||
&self.depthstencil];
|
(&self.stencil, constants::STENCIL_ATTACHMENT),
|
||||||
|
(&self.depthstencil, constants::DEPTH_STENCIL_ATTACHMENT)
|
||||||
|
];
|
||||||
|
|
||||||
for attachment in &attachments {
|
for (attachment, name) in &attachments {
|
||||||
let matched = {
|
let matched = {
|
||||||
match *attachment.borrow() {
|
match *attachment.borrow() {
|
||||||
Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb))
|
Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb))
|
||||||
|
@ -341,20 +474,22 @@ impl WebGLFramebuffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
closure(attachment);
|
closure(attachment, *name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_matching_textures<F>(&self, texture: &WebGLTexture, mut closure: F)
|
fn with_matching_textures<F>(&self, texture: &WebGLTexture, mut closure: F)
|
||||||
where F: FnMut(&DomRefCell<Option<WebGLFramebufferAttachment>>)
|
where F: FnMut(&DomRefCell<Option<WebGLFramebufferAttachment>>, u32)
|
||||||
{
|
{
|
||||||
let attachments = [&self.color,
|
let attachments = [
|
||||||
&self.depth,
|
(&self.color, constants::COLOR_ATTACHMENT0),
|
||||||
&self.stencil,
|
(&self.depth, constants::DEPTH_ATTACHMENT),
|
||||||
&self.depthstencil];
|
(&self.stencil, constants::STENCIL_ATTACHMENT),
|
||||||
|
(&self.depthstencil, constants::DEPTH_STENCIL_ATTACHMENT)
|
||||||
|
];
|
||||||
|
|
||||||
for attachment in &attachments {
|
for (attachment, name) in &attachments {
|
||||||
let matched = {
|
let matched = {
|
||||||
match *attachment.borrow() {
|
match *attachment.borrow() {
|
||||||
Some(WebGLFramebufferAttachment::Texture { texture: ref att_texture, .. })
|
Some(WebGLFramebufferAttachment::Texture { texture: ref att_texture, .. })
|
||||||
|
@ -364,33 +499,45 @@ impl WebGLFramebuffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
closure(attachment);
|
closure(attachment, *name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detach_renderbuffer(&self, rb: &WebGLRenderbuffer) {
|
pub fn detach_renderbuffer(&self, rb: &WebGLRenderbuffer) {
|
||||||
self.with_matching_renderbuffers(rb, |att| {
|
let mut depth_or_stencil_updated = false;
|
||||||
|
self.with_matching_renderbuffers(rb, |att, name| {
|
||||||
|
depth_or_stencil_updated |= INTERESTING_ATTACHMENT_POINTS.contains(&name);
|
||||||
*att.borrow_mut() = None;
|
*att.borrow_mut() = None;
|
||||||
self.update_status();
|
self.update_status();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if depth_or_stencil_updated {
|
||||||
|
self.reattach_depth_stencil();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detach_texture(&self, texture: &WebGLTexture) {
|
pub fn detach_texture(&self, texture: &WebGLTexture) {
|
||||||
self.with_matching_textures(texture, |att| {
|
let mut depth_or_stencil_updated = false;
|
||||||
|
self.with_matching_textures(texture, |att, name| {
|
||||||
|
depth_or_stencil_updated |= INTERESTING_ATTACHMENT_POINTS.contains(&name);
|
||||||
*att.borrow_mut() = None;
|
*att.borrow_mut() = None;
|
||||||
self.update_status();
|
self.update_status();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if depth_or_stencil_updated {
|
||||||
|
self.reattach_depth_stencil();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidate_renderbuffer(&self, rb: &WebGLRenderbuffer) {
|
pub fn invalidate_renderbuffer(&self, rb: &WebGLRenderbuffer) {
|
||||||
self.with_matching_renderbuffers(rb, |_att| {
|
self.with_matching_renderbuffers(rb, |_att, _| {
|
||||||
self.update_status();
|
self.update_status();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidate_texture(&self, texture: &WebGLTexture) {
|
pub fn invalidate_texture(&self, texture: &WebGLTexture) {
|
||||||
self.with_matching_textures(texture, |_att| {
|
self.with_matching_textures(texture, |_att, _name| {
|
||||||
self.update_status();
|
self.update_status();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -405,3 +552,9 @@ impl Drop for WebGLFramebuffer {
|
||||||
self.delete();
|
self.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static INTERESTING_ATTACHMENT_POINTS: &[u32] = &[
|
||||||
|
constants::DEPTH_ATTACHMENT,
|
||||||
|
constants::STENCIL_ATTACHMENT,
|
||||||
|
constants::DEPTH_STENCIL_ATTACHMENT,
|
||||||
|
];
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub struct WebGLRenderbuffer {
|
||||||
is_deleted: Cell<bool>,
|
is_deleted: Cell<bool>,
|
||||||
size: Cell<Option<(i32, i32)>>,
|
size: Cell<Option<(i32, i32)>>,
|
||||||
internal_format: Cell<Option<u32>>,
|
internal_format: Cell<Option<u32>>,
|
||||||
|
is_initialized: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLRenderbuffer {
|
impl WebGLRenderbuffer {
|
||||||
|
@ -34,6 +35,7 @@ impl WebGLRenderbuffer {
|
||||||
is_deleted: Cell::new(false),
|
is_deleted: Cell::new(false),
|
||||||
internal_format: Cell::new(None),
|
internal_format: Cell::new(None),
|
||||||
size: Cell::new(None),
|
size: Cell::new(None),
|
||||||
|
is_initialized: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +68,14 @@ impl WebGLRenderbuffer {
|
||||||
self.internal_format.get().unwrap_or(constants::RGBA4)
|
self.internal_format.get().unwrap_or(constants::RGBA4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mark_initialized(&self) {
|
||||||
|
self.is_initialized.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_initialized(&self) -> bool {
|
||||||
|
self.is_initialized.get()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn bind(&self, target: u32) {
|
pub fn bind(&self, target: u32) {
|
||||||
self.ever_bound.set(true);
|
self.ever_bound.set(true);
|
||||||
self.upcast::<WebGLObject>()
|
self.upcast::<WebGLObject>()
|
||||||
|
@ -76,6 +86,22 @@ impl WebGLRenderbuffer {
|
||||||
pub fn delete(&self) {
|
pub fn delete(&self) {
|
||||||
if !self.is_deleted.get() {
|
if !self.is_deleted.get() {
|
||||||
self.is_deleted.set(true);
|
self.is_deleted.set(true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
If a renderbuffer object is deleted while its image is attached to the currently
|
||||||
|
bound framebuffer, then it is as if FramebufferRenderbuffer had been called, with
|
||||||
|
a renderbuffer of 0, for each attachment point to which this image was attached
|
||||||
|
in the currently bound framebuffer.
|
||||||
|
- GLES 2.0, 4.4.3, "Attaching Renderbuffer Images to a Framebuffer"
|
||||||
|
*/
|
||||||
|
let currently_bound_framebuffer =
|
||||||
|
self.upcast::<WebGLObject>()
|
||||||
|
.context()
|
||||||
|
.bound_framebuffer();
|
||||||
|
if let Some(fb) = currently_bound_framebuffer {
|
||||||
|
fb.detach_renderbuffer(self);
|
||||||
|
}
|
||||||
|
|
||||||
self.upcast::<WebGLObject>()
|
self.upcast::<WebGLObject>()
|
||||||
.context()
|
.context()
|
||||||
.send_command(WebGLCommand::DeleteRenderbuffer(self.id));
|
.send_command(WebGLCommand::DeleteRenderbuffer(self.id));
|
||||||
|
|
|
@ -39,7 +39,7 @@ use dom::webgl_validations::types::{TexDataType, TexFormat, TexImageTarget};
|
||||||
use dom::webglactiveinfo::WebGLActiveInfo;
|
use dom::webglactiveinfo::WebGLActiveInfo;
|
||||||
use dom::webglbuffer::WebGLBuffer;
|
use dom::webglbuffer::WebGLBuffer;
|
||||||
use dom::webglcontextevent::WebGLContextEvent;
|
use dom::webglcontextevent::WebGLContextEvent;
|
||||||
use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferAttachmentRoot};
|
use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferAttachmentRoot, CompleteForRendering};
|
||||||
use dom::webglobject::WebGLObject;
|
use dom::webglobject::WebGLObject;
|
||||||
use dom::webglprogram::WebGLProgram;
|
use dom::webglprogram::WebGLProgram;
|
||||||
use dom::webglrenderbuffer::WebGLRenderbuffer;
|
use dom::webglrenderbuffer::WebGLRenderbuffer;
|
||||||
|
@ -339,10 +339,14 @@ impl WebGLRenderingContext {
|
||||||
// this: clear() and getParameter(IMPLEMENTATION_COLOR_READ_*).
|
// this: clear() and getParameter(IMPLEMENTATION_COLOR_READ_*).
|
||||||
fn validate_framebuffer(&self) -> WebGLResult<()> {
|
fn validate_framebuffer(&self) -> WebGLResult<()> {
|
||||||
match self.bound_framebuffer.get() {
|
match self.bound_framebuffer.get() {
|
||||||
Some(ref fb) if fb.check_status() != constants::FRAMEBUFFER_COMPLETE => {
|
Some(fb) => match fb.check_status_for_rendering() {
|
||||||
Err(InvalidFramebufferOperation)
|
CompleteForRendering::Complete => Ok(()),
|
||||||
|
CompleteForRendering::Incomplete =>
|
||||||
|
Err(InvalidFramebufferOperation),
|
||||||
|
CompleteForRendering::MissingColorAttachment =>
|
||||||
|
Err(InvalidOperation),
|
||||||
},
|
},
|
||||||
_ => Ok(()),
|
None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1057,6 +1061,21 @@ impl WebGLRenderingContext {
|
||||||
_ => Err(InvalidEnum),
|
_ => Err(InvalidEnum),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn initialize_framebuffer(&self, clear_bits: u32) {
|
||||||
|
if clear_bits == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.send_command(WebGLCommand::InitializeFramebuffer {
|
||||||
|
color: clear_bits & constants::COLOR_BUFFER_BIT != 0,
|
||||||
|
depth: clear_bits & constants::DEPTH_BUFFER_BIT != 0,
|
||||||
|
stencil: clear_bits & constants::STENCIL_BUFFER_BIT != 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bound_framebuffer(&self) -> Option<DomRoot<WebGLFramebuffer>> {
|
||||||
|
self.bound_framebuffer.get()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WebGLRenderingContext {
|
impl Drop for WebGLRenderingContext {
|
||||||
|
@ -1572,6 +1591,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
renderbuffer.bind(target);
|
renderbuffer.bind(target);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
if renderbuffer.is_some() {
|
||||||
|
self.webgl_error(InvalidOperation);
|
||||||
|
}
|
||||||
|
|
||||||
self.bound_renderbuffer.set(None);
|
self.bound_renderbuffer.set(None);
|
||||||
// Unbind the currently bound renderbuffer
|
// Unbind the currently bound renderbuffer
|
||||||
self.send_command(WebGLCommand::BindRenderbuffer(target, None));
|
self.send_command(WebGLCommand::BindRenderbuffer(target, None));
|
||||||
|
@ -1971,20 +1994,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
handle_potential_webgl_error!(self, self.validate_ownership(renderbuffer), return);
|
handle_potential_webgl_error!(self, self.validate_ownership(renderbuffer), return);
|
||||||
handle_object_deletion!(self, self.bound_renderbuffer, renderbuffer,
|
handle_object_deletion!(self, self.bound_renderbuffer, renderbuffer,
|
||||||
Some(WebGLCommand::BindRenderbuffer(constants::RENDERBUFFER, None)));
|
Some(WebGLCommand::BindRenderbuffer(constants::RENDERBUFFER, None)));
|
||||||
// From the GLES 2.0.25 spec, page 113:
|
|
||||||
//
|
|
||||||
// "If a renderbuffer object is deleted while its
|
|
||||||
// image is attached to the currently bound
|
|
||||||
// framebuffer, then it is as if
|
|
||||||
// FramebufferRenderbuffer had been called, with a
|
|
||||||
// renderbuffer of 0, for each attachment point to
|
|
||||||
// which this image was attached in the currently
|
|
||||||
// bound framebuffer."
|
|
||||||
//
|
|
||||||
if let Some(fb) = self.bound_framebuffer.get() {
|
|
||||||
fb.detach_renderbuffer(renderbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderbuffer.delete()
|
renderbuffer.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2020,18 +2029,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// From the GLES 2.0.25 spec, page 113:
|
|
||||||
//
|
|
||||||
// "If a texture object is deleted while its image is
|
|
||||||
// attached to the currently bound framebuffer, then
|
|
||||||
// it is as if FramebufferTexture2D had been called,
|
|
||||||
// with a texture of 0, for each attachment point to
|
|
||||||
// which this image was attached in the currently
|
|
||||||
// bound framebuffer."
|
|
||||||
if let Some(fb) = self.bound_framebuffer.get() {
|
|
||||||
fb.detach_texture(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
texture.delete()
|
texture.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2723,10 +2720,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
fn StencilMaskSeparate(&self, face: u32, mask: u32) {
|
fn StencilMaskSeparate(&self, face: u32, mask: u32) {
|
||||||
match face {
|
match face {
|
||||||
constants::FRONT | constants::BACK | constants::FRONT_AND_BACK =>
|
constants::FRONT |
|
||||||
|
constants::BACK |
|
||||||
|
constants::FRONT_AND_BACK =>
|
||||||
self.send_command(WebGLCommand::StencilMaskSeparate(face, mask)),
|
self.send_command(WebGLCommand::StencilMaskSeparate(face, mask)),
|
||||||
_ => return self.webgl_error(InvalidEnum),
|
_ => return self.webgl_error(InvalidEnum),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
|
|
|
@ -146,7 +146,7 @@ impl WebGLTexture {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_image_info = self.base_image_info().unwrap();
|
let base_image_info = self.base_image_info();
|
||||||
if !base_image_info.is_initialized() {
|
if !base_image_info.is_initialized() {
|
||||||
return Err(WebGLError::InvalidOperation);
|
return Err(WebGLError::InvalidOperation);
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,22 @@ impl WebGLTexture {
|
||||||
DOMToTextureCommand::Detach(self.id),
|
DOMToTextureCommand::Detach(self.id),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
If a texture object is deleted while its image is attached to the currently
|
||||||
|
bound framebuffer, then it is as if FramebufferTexture2D had been called, with
|
||||||
|
a texture of 0, for each attachment point to which this image was attached
|
||||||
|
in the currently bound framebuffer.
|
||||||
|
- GLES 2.0, 4.4.3, "Attaching Texture Images to a Framebuffer"
|
||||||
|
*/
|
||||||
|
let currently_bound_framebuffer =
|
||||||
|
self.upcast::<WebGLObject>()
|
||||||
|
.context()
|
||||||
|
.bound_framebuffer();
|
||||||
|
if let Some(fb) = currently_bound_framebuffer {
|
||||||
|
fb.detach_texture(self);
|
||||||
|
}
|
||||||
|
|
||||||
context.send_command(WebGLCommand::DeleteTexture(self.id));
|
context.send_command(WebGLCommand::DeleteTexture(self.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,7 +343,7 @@ impl WebGLTexture {
|
||||||
fn is_cube_complete(&self) -> bool {
|
fn is_cube_complete(&self) -> bool {
|
||||||
debug_assert_eq!(self.face_count.get(), 6);
|
debug_assert_eq!(self.face_count.get(), 6);
|
||||||
|
|
||||||
let image_info = self.base_image_info().unwrap();
|
let image_info = self.base_image_info();
|
||||||
if !image_info.is_defined() {
|
if !image_info.is_defined() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -389,10 +405,10 @@ impl WebGLTexture {
|
||||||
self.image_info_array.borrow_mut()[pos as usize] = image_info;
|
self.image_info_array.borrow_mut()[pos as usize] = image_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn base_image_info(&self) -> Option<ImageInfo> {
|
fn base_image_info(&self) -> ImageInfo {
|
||||||
assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT);
|
assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT);
|
||||||
|
|
||||||
Some(self.image_info_at_face(0, self.base_mipmap_level))
|
self.image_info_at_face(0, self.base_mipmap_level)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_attached_to_dom(&self) {
|
pub fn set_attached_to_dom(&self) {
|
||||||
|
|
|
@ -1,2 +1,97 @@
|
||||||
[webgl-specific-stencil-settings.html]
|
[webgl-specific-stencil-settings.html]
|
||||||
expected: CRASH
|
[WebGL test #623: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #642: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #565: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #611: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #555: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #629: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #513: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #584: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #578: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #620: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #614: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #650: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #488: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #543: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #501: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #590: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #2: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #534: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #632: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #494: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #626: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #537: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #658: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #507: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #571: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #5: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #546: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #549: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #667: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #540: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #552: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #617: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: wtu.dummySetProgramAndDrawNothing(gl)]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[framebuffer-object-attachment.html]
|
|
||||||
expected: CRASH
|
|
||||||
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -26,3 +26,12 @@
|
||||||
[WebGL test #16: Creating framebuffer from ALPHA texture succeeded even though it is not a renderable format]
|
[WebGL test #16: Creating framebuffer from ALPHA texture succeeded even though it is not a renderable format]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #32: getError expected: INVALID_OPERATION. Was NO_ERROR : should not be able to copyTexImage2D ALPHA from RGB]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #40: getError expected: INVALID_OPERATION. Was NO_ERROR : should not be able to copyTexImage2D RGBA from RGB]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #36: getError expected: INVALID_OPERATION. Was NO_ERROR : should not be able to copyTexImage2D LUMINANCE_ALPHA from RGB]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,34 @@
|
||||||
[framebuffer-object-attachment.html]
|
[framebuffer-object-attachment.html]
|
||||||
expected: CRASH
|
[WebGL test #13: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_INCOMPLETE_ATTACHMENT]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #20: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_INCOMPLETE_ATTACHMENT]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #30: getError expected: NO_ERROR. Was INVALID_ENUM : ]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #21: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_UNSUPPORTED]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #25: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_UNSUPPORTED]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #23: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_UNSUPPORTED]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #24: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_UNSUPPORTED]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #22: checkFramebufferStatus expects [FRAMEBUFFER_COMPLETE\], was FRAMEBUFFER_UNSUPPORTED]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #14: getError expected: NO_ERROR. Was INVALID_ENUM : ]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #16: gl.getParameter(gl.RED_BITS) + gl.getParameter(gl.GREEN_BITS) + gl.getParameter(gl.BLUE_BITS) + gl.getParameter(gl.ALPHA_BITS) >= 16 should be true. Was false.]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #59: getError expected: NO_ERROR. Was INVALID_ENUM : Query should not generate error]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
[framebuffer-texture-level1.html]
|
[framebuffer-texture-level1.html]
|
||||||
[WebGL test #1: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36054. Was 36061.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #3: getError expected: NO_ERROR. Was INVALID_VALUE : Setup framebuffer with texture should succeed.]
|
[WebGL test #3: getError expected: NO_ERROR. Was INVALID_VALUE : Setup framebuffer with texture should succeed.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[WebGL test #2: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36053. Was 36061.]
|
[WebGL test #2: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36053. Was 36055.]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[WebGL test #1: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36054. Was 36055.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue