mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #11458 - kevgs:log2, r=Manishearth
add log2(u32) and use it to prevent casting to and from float to int <!-- Please describe your changes on the following line: --> PR for #11440 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/11458) <!-- Reviewable:end -->
This commit is contained in:
commit
f2f2987e74
1 changed files with 5 additions and 1 deletions
|
@ -87,6 +87,10 @@ pub struct WebGLRenderingContext {
|
|||
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
|
||||
}
|
||||
|
||||
fn log2(n: u32) -> u32 {
|
||||
31 - n.leading_zeros()
|
||||
}
|
||||
|
||||
impl WebGLRenderingContext {
|
||||
fn new_inherited(global: GlobalRef,
|
||||
canvas: &HTMLCanvasElement,
|
||||
|
@ -402,7 +406,7 @@ impl WebGLRenderingContext {
|
|||
// the returned value of GL_MAX_TEXTURE_SIZE when
|
||||
// target is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE
|
||||
// when target is not GL_TEXTURE_2D.
|
||||
if level > (max as f32).log2() as i32 {
|
||||
if level > log2(max) as i32 {
|
||||
self.webgl_error(InvalidValue);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue