Skip to content

Commit

Permalink
Auto merge of #11168 - daoshengmu:texSubImage2D, r=emilio
Browse files Browse the repository at this point in the history
Implement WebGL TexSubImage2D

Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data:
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

Either:
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because I have run the wpt test of texSubImage2D.html, and it works.

Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process.

I have implemented ```TexSubImage2D``` follow [the spec](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8). This is my first version of implementation, and I notice I can reuse the code from ```TexImage2D```. Therefore, I would like to discuss make ```validate_tex_image2D_from_buffer``` and ```validate_tex_image2D_from_source``` to remove duplicate code.

Part of #10209

<!-- 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/11168)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jun 10, 2016
2 parents 6f9016c + fd32bd5 commit 5e8ab6c
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 125 deletions.
403 changes: 300 additions & 103 deletions components/script/dom/webglrenderingcontext.rs

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion components/script/dom/webgltexture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ impl WebGLTexture {
height: u32,
depth: u32,
internal_format: u32,
level: u32) -> WebGLResult<()> {
level: u32,
data_type: Option<u32>) -> WebGLResult<()> {
let image_info = ImageInfo {
width: width,
height: height,
depth: depth,
internal_format: Some(internal_format),
is_initialized: true,
data_type: data_type,
};

let face = match target {
Expand Down Expand Up @@ -274,6 +276,7 @@ impl WebGLTexture {
depth: 0,
internal_format: base_image_info.internal_format,
is_initialized: base_image_info.is_initialized(),
data_type: base_image_info.data_type,
};

self.set_image_infos_at_level(level, image_info);
Expand Down Expand Up @@ -346,6 +349,7 @@ pub struct ImageInfo {
depth: u32,
internal_format: Option<u32>,
is_initialized: bool,
data_type: Option<u32>,
}

impl ImageInfo {
Expand All @@ -356,6 +360,7 @@ impl ImageInfo {
depth: 0,
internal_format: None,
is_initialized: false,
data_type: None,
}
}

Expand All @@ -371,6 +376,10 @@ impl ImageInfo {
self.internal_format
}

pub fn data_type(&self) -> Option<u32> {
self.data_type
}

fn is_power_of_two(&self) -> bool {
self.width.is_power_of_two() && self.height.is_power_of_two() && self.depth.is_power_of_two()
}
Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/webidls/WebGLRenderingContext.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ interface WebGLRenderingContextBase
void texParameterf(GLenum target, GLenum pname, GLfloat param);
void texParameteri(GLenum target, GLenum pname, GLint param);

//void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
// GLsizei width, GLsizei height,
// GLenum format, GLenum type, ArrayBufferView? pixels);
//void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
// GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type, optional object data);
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, TexImageSource? source); // May throw DOMException

void uniform1f(WebGLUniformLocation? location, GLfloat x);
//void uniform1fv(WebGLUniformLocation? location, Float32Array v);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,107 @@
[tex-image-and-sub-image-2d-with-array-buffer-view.html]
type: testharness
[WebGL test #0: successfullyParsed should be true. Was false.]

[WebGL test #0: at (0, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
[WebGL test #1: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #1: successfullyParsed should be true. Was false.]
[WebGL test #2: at (0, 0) expected: 0,0,255,255 was 255,0,0,255]
expected: FAIL

[WebGL test #0: at (0, 0) expected: 0,255,0,255 was 255,0,0,255]
[WebGL test #3: at (0, 4) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #1: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
[WebGL test #4: at (8, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #5: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #6: at (0, 0) expected: 0,0,255,255 was 255,0,0,255]
expected: FAIL

[WebGL test #7: at (0, 4) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #8: at (8, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #9: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #10: at (8, 8) expected: 0,0,255,255 was 255,0,0,255]
expected: FAIL

[WebGL test #11: at (8, 12) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #12: GL error before texture upload]
expected: FAIL

[WebGL test #25: GL error before texture upload]
expected: FAIL

[WebGL test #26: at (0, 0) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #27: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #28: at (0, 0) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #29: at (0, 4) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #2: successfullyParsed should be true. Was false.]
[WebGL test #30: at (8, 0) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #31: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #32: at (0, 0) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #33: at (0, 4) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #34: at (8, 0) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #35: at (0, 8) expected: 255,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #36: at (8, 8) expected: 0,0,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #37: at (8, 12) expected: 255,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #38: GL error before texture upload]
expected: FAIL

[WebGL test #40: at (0, 8) expected: 0,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #42: at (0, 4) expected: 0,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #44: at (0, 8) expected: 0,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #46: at (0, 4) expected: 0,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #48: at (0, 8) expected: 0,0,0,255 was 0,255,0,255]
expected: FAIL

[WebGL test #50: at (8, 12) expected: 0,0,0,255 was 0,0,255,255]
expected: FAIL

[WebGL test #51: GL error before texture upload]
expected: FAIL

[WebGL test #52: successfullyParsed should be true. Was false.]
expected: FAIL
Loading

0 comments on commit 5e8ab6c

Please sign in to comment.