Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded Uniform{2i, 2iv, 2fv, 3f, 3i, 3iv, 3fv} #10436
Conversation
highfive
commented
Apr 6, 2016
highfive
commented
Apr 6, 2016
| _cx: *mut JSContext, | ||
| uniform: Option<&WebGLUniformLocation>, | ||
| data: Option<*mut JSObject>) { | ||
| let data = match data { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 6, 2016
Member
if the passed location is null, data passed in will be silently ignored.
I assume that means that we should return early here and not throw any errors?
This comment has been minimized.
This comment has been minimized.
emilio
Apr 6, 2016
Member
That refers to the WebGLUniformLocation variable, which is ignored if it's null in Uniform2f()... That check should be repeated here though, since in the case null, null were registering an error when we should not.
This comment has been minimized.
This comment has been minimized.
autrilla
Apr 6, 2016
Author
Contributor
I suppose so, yes. The other previously implemented uniform vector functions didn't do it either, so should I fix that in this PR, or open an issue and handle it in another PR?
This comment has been minimized.
This comment has been minimized.
emilio
Apr 6, 2016
Member
Preferably fixing it here, but if you don't have the time or anything feel free to file an issue :)
| return self.webgl_error(InvalidOperation); | ||
| } | ||
|
|
||
| self.Uniform2f(uniform, data[0], data[1]); |
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 6, 2016
Member
I don't see how this works. This will only work for glUniform2fv(uniform, 1, data), i.e. uniform vec2 foo or uniform vec2 foo[1], but not for uniform vec2 foo[10], which is set as glUniform2fv(uniform, 10, data). In this case I'm assuming the WebGL API internally figures out the size because hey, we're not in C++-land anymore, but the behavior should be the same. We'll need a new message for it.
@emilio does this sound correct?
This comment has been minimized.
This comment has been minimized.
emilio
Apr 6, 2016
Member
Yep, that's true... We also do this in other parts of the code, so we should add Uniformxy messages that receive a Vec<y> and allow that.
If you want to do it for this PR, that would be just great, but if you'd prefer to land it as is and leaving it as a followup it'd be fine too.
|
|
|
@emilio could you review this changes to see if the general principle is fine? (Don't accept the PR or anything though) |
|
@autrilla: Yeah those changes look in the good direction :) |
aee94e6
to
1b160cd
|
This should do it. I still want to refactor it a bit because it is too copy-pasty (maybe with a macro?). Extracting parts of the function is a bit hard because errors are expected to be returned directly from the function and not sent to the ipc_renderer... If anyone has any ideas on doing this cleanly, I'd appreciate them! This should be covered by |
|
Ok, so I'd try to abstract all this in a function belonging to The key point here, is that the self.webgl_error(..);
return;So... It isn't hard to imagine a function like: fn validate_uniform_parameters<T>(&self, uniform: Option<&WebGLUniformLocation>, expected_size: u32, data: Option<&[T]>) -> bool {
let uniform = match uniform {
Some(uniform) => uniform,
None => return, // No error, as spec'd
};
let data = match data {
Some(data) => data,
None => {
self.webgl_error(InvalidOperation);
return false;
},
};
if data.len() % expected_size != 0 {
// ...
}
// ...
true
}That way it can be reused both in the vector and not vector function, with just an extra check on fn Uniform2i(&self, uniform: Option<&WebGLUniformLocation>, x: i32, y: i32) {
if !self.validate_uniform_parameters(uniform, 2, Some(&[x, y])) {
return; // Error handled above
}
self.ipc_renderer...
}
fn Uniform2iv(&self, uniform: Option<&WebGLUniformLocation>, data: Option<*mut JSObject>) {
let data_slice = data.and_then(|data| unsafe {
array_buffer_view_data_checked::<i32>(data)
});
if !self.validate_uniform_parameters(uniform, 2, data_slice) {
return; // Error handled above
}
self.ipc_renderer...
}Would something like that make sense? Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions. Comments from Reviewable |
|
@emilio yes, that makes sense. Not needing to return self.webgl error definitely makes things easier. I'll update the code and push it again |
|
Review status: 0 of 6 files reviewed at latest revision, 4 unresolved discussions. components/script/dom/webglrenderingcontext.rs, line 195 [r7] (raw file): components/script/dom/webglrenderingcontext.rs, line 216 [r7] (raw file): We know what the expected type should be, eg ( Also, why do you check for Even more, why splitting this and We should unify both functions, even when there are a few boilerplate arguments in the non-vector functions. components/script/dom/webglrenderingcontext.rs, line 240 [r7] (raw file): Comments from Reviewable |
|
components/script/dom/webglrenderingcontext.rs, line 216 [r7] (raw file): I think you're right on the rest. Comments from Reviewable |
|
components/script/dom/webglrenderingcontext.rs, line 263 [r7] (raw file): Comments from Reviewable |
|
|
|
@emilio review this whenever you get a chance, please |
|
So much cleaner! Great job! :) Left a few comments, mostly nits. This is ready to merge once they're adressed and the commits are squashed :P Reviewed 5 of 6 files at r8. components/script/dom/webglrenderingcontext.rs, line 82 [r8] (raw file): components/script/dom/webglrenderingcontext.rs, line 95 [r8] (raw file): components/script/dom/webglrenderingcontext.rs, line 222 [r8] (raw file): Ideally each block that could components/script/dom/webglrenderingcontext.rs, line 226 [r8] (raw file):
above this line would sufice :) components/script/dom/webglrenderingcontext.rs, line 232 [r8] (raw file): components/script/dom/webglrenderingcontext.rs, line 248 [r8] (raw file): components/script/dom/webglrenderingcontext.rs, line 1133 [r8] (raw file): Not too important, since we should copy it in the common case where the slice is valid, so I won't complain if you leave this as-is :) If you prefer to leave this as-is, please change the name to either components/script/dom/webglrenderingcontext.rs, line 1147 [r8] (raw file): Comments from Reviewable |
|
r=me with that typo corrected :P Review status: 4 of 5 files reviewed at latest revision, 10 unresolved discussions. components/script/dom/webglrenderingcontext.rs, line 237 [r9] (raw file): components/script/dom/webglrenderingcontext.rs, line 1148 [r9] (raw file): Comments from Reviewable |
|
r+? @emilio |
|
@bors-servo r=emilio |
|
|
Added Uniform{2i, 2iv, 2fv, 3f, 3i, 3iv, 3fv}
@emilio r?
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10436)
<!-- Reviewable:end -->
|
|
autrilla commentedApr 6, 2016
•
edited by KiChjang
@emilio r?
Partial #10417.
This change is