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 GetVertexAttrib #10776

Merged
merged 1 commit into from May 18, 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

@@ -193,6 +193,15 @@ impl<T: JSTraceable> JSTraceable for Vec<T> {
}
}

impl<T: JSTraceable> JSTraceable for (T, T, T, T) {
fn trace(&self, trc: *mut JSTracer) {
self.0.trace(trc);
self.1.trace(trc);
self.2.trace(trc);
self.3.trace(trc);
}
}

// XXXManishearth Check if the following three are optimized to no-ops
// if e.trace() is a no-op (e.g it is an no_jsmanaged_fields type)
impl<T: JSTraceable + 'static> JSTraceable for SmallVec<[T; 1]> {
@@ -83,6 +83,8 @@ pub struct WebGLRenderingContext {
bound_buffer_array: MutNullableHeap<JS<WebGLBuffer>>,
bound_buffer_element_array: MutNullableHeap<JS<WebGLBuffer>>,
current_program: MutNullableHeap<JS<WebGLProgram>>,
#[ignore_heap_size_of = "Because it's small"]

This comment has been minimized.

@dzbarsky

dzbarsky Apr 27, 2016

Author Member

this was a hack, we probably need to implement this somewhere right?

current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,

This comment has been minimized.

@nox

nox Jul 31, 2018

Member

@dzbarsky Do you remember why it's necessary to keep the value of vertex attrib 0 on the DOM side?

This comment has been minimized.

@dzbarsky

dzbarsky Aug 2, 2018

Author Member

When I first implemented this in 2bf016f GetVertexAttrib had a path to serve 0/CURRENT_VERTEX_ATTRIB from DOM side - I don't recall why I did this though...perhaps it was a fast path or something?

This comment has been minimized.

@dzbarsky

dzbarsky Aug 2, 2018

Author Member

Oh I see now that this is the original place we added it :) Most likely I was cargo-culting the pattern of retaining state like current_program, though this one was likely not necessary. Oops!

This comment has been minimized.

@nox

nox Aug 2, 2018

Member

Seems like calling glGetVertexAttrib* with index 0 causes issues on some drivers.

}

impl WebGLRenderingContext {
@@ -111,6 +113,7 @@ impl WebGLRenderingContext {
bound_buffer_array: MutNullableHeap::new(None),
bound_buffer_element_array: MutNullableHeap::new(None),
current_program: MutNullableHeap::new(None),
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
}
})
}
@@ -175,6 +178,10 @@ impl WebGLRenderingContext {
return self.webgl_error(InvalidValue);
}

if indx == 0 {
self.current_vertex_attrib_0.set((x, y, z, w))
}

self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::VertexAttrib(indx, x, y, z, w)))
.unwrap();
@@ -1138,6 +1145,38 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
})
}

#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetVertexAttrib(&self, cx: *mut JSContext, index: u32, pname: u32) -> JSVal {
if index == 0 && pname == constants::CURRENT_VERTEX_ATTRIB {
let mut result = RootedValue::new(cx, UndefinedValue());
let (x, y, z, w) = self.current_vertex_attrib_0.get();
let attrib = vec![x, y, z, w];
unsafe {
attrib.to_jsval(cx, result.handle_mut());
}
return result.ptr
}

let (sender, receiver) = ipc::channel().unwrap();
self.ipc_renderer.send(CanvasMsg::WebGL(WebGLCommand::GetVertexAttrib(index, pname, sender))).unwrap();

match handle_potential_webgl_error!(self, receiver.recv().unwrap(), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Vertex attrib should not be string"),
WebGLParameter::Float(_) => panic!("Vertex attrib should not be float"),
WebGLParameter::FloatArray(val) => {
let mut result = RootedValue::new(cx, UndefinedValue());
unsafe {
val.to_jsval(cx, result.handle_mut());
}
result.ptr
}
WebGLParameter::Invalid => NullValue(),
}
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn Hint(&self, target: u32, mode: u32) {
if target != constants::GENERATE_MIPMAP_HINT {
@@ -595,7 +595,7 @@ interface WebGLRenderingContextBase

WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name);

//any getVertexAttrib(GLuint index, GLenum pname);
any getVertexAttrib(GLuint index, GLenum pname);

//[WebGLHandlesContextLoss] GLsizeiptr getVertexAttribOffset(GLuint index, GLenum pname);

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