Changeset 57709 in webkit
- Timestamp:
- Apr 15, 2010 7:01:34 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r57708 r57709 1 2010-04-15 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Dimitri Glazkov. 4 5 Index validation code validates too many vertex attributes 6 https://bugs.webkit.org/show_bug.cgi?id=31892 7 8 * fast/canvas/webgl/index-validation-expected.txt: Add new test cases for index validations. 9 * fast/canvas/webgl/script-tests/index-validation.js: Ditto. 10 1 11 2010-04-15 Jian Li <jianli@chromium.org> 2 12 -
trunk/LayoutTests/fast/canvas/webgl/index-validation-expected.txt
r57015 r57709 1 Test of get calls against GL objects like getBufferParameter, etc.1 Test of validating indices for drawElements(). 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 4 5 Testing with valid indices 5 6 PASS gl.checkFramebufferStatus(gl.FRAMEBUFFER) is gl.FRAMEBUFFER_COMPLETE 7 PASS gl.getError() is 0 8 PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined. 9 PASS gl.getError() is 0 10 Testing with out-of-range indices 11 Enable vertices, valid 12 PASS gl.getError() is 0 13 PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined. 14 PASS gl.getError() is 0 15 Enable normals, out-of-range 16 PASS gl.getError() is 0 17 PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined. 18 PASS gl.getError() is gl.INVALID_OPERATION 19 Test with enabled attribute that does not belong to current program 20 Enable an extra attribute with null 21 PASS gl.getError() is 0 22 PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined. 23 PASS gl.getError() is 0 24 Enable an extra attribute with insufficient data buffer 6 25 PASS gl.getError() is 0 7 26 PASS gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0) is undefined. -
trunk/LayoutTests/fast/canvas/webgl/script-tests/index-validation.js
r57234 r57709 1 description("Test of get calls against GL objects like getBufferParameter, etc.");1 description("Test of validating indices for drawElements()."); 2 2 3 3 var gl = create3DContext(); … … 5 5 6 6 // 3 vertices => 1 triangle, interleaved data 7 var data = new WebGLFloatArray([0, 0, 0, 1, 8 0, 0, 1, 9 1, 0, 0, 1, 10 0, 0, 1, 11 1, 1, 1, 1, 12 0, 0, 1]); 7 var dataComplete = new WebGLFloatArray([0, 0, 0, 1, 8 0, 0, 1, 9 1, 0, 0, 1, 10 0, 0, 1, 11 1, 1, 1, 1, 12 0, 0, 1]); 13 var dataIncomplete = new WebGLFloatArray([0, 0, 0, 1, 14 0, 0, 1, 15 1, 0, 0, 1, 16 0, 0, 1, 17 1, 1, 1, 1]); 13 18 var indices = new WebGLUnsignedShortArray([0, 1, 2]); 14 19 15 var buffer = gl.createBuffer(); 16 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 17 gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); 20 debug("Testing with valid indices"); 21 22 var bufferComplete = gl.createBuffer(); 23 gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete); 24 gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW); 18 25 var elements = gl.createBuffer(); 19 26 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); … … 24 31 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0); 25 32 gl.enableVertexAttribArray(vertexLoc); 26 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 3* gl.sizeInBytes(gl.FLOAT));33 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT)); 27 34 gl.enableVertexAttribArray(normalLoc); 28 35 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); … … 31 38 shouldBe('gl.getError()', '0'); 32 39 40 debug("Testing with out-of-range indices"); 41 42 var bufferIncomplete = gl.createBuffer(); 43 gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete); 44 gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW); 45 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0); 46 gl.enableVertexAttribArray(vertexLoc); 47 gl.disableVertexAttribArray(normalLoc); 48 debug("Enable vertices, valid"); 49 shouldBe('gl.getError()', '0'); 50 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); 51 shouldBe('gl.getError()', '0'); 52 debug("Enable normals, out-of-range"); 53 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT)); 54 gl.enableVertexAttribArray(normalLoc); 55 shouldBe('gl.getError()', '0'); 56 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); 57 shouldBe('gl.getError()', 'gl.INVALID_OPERATION'); 58 59 debug("Test with enabled attribute that does not belong to current program"); 60 61 gl.disableVertexAttribArray(normalLoc); 62 var extraLoc = Math.max(vertexLoc, normalLoc) + 1; 63 gl.enableVertexAttribArray(extraLoc); 64 debug("Enable an extra attribute with null"); 65 shouldBe('gl.getError()', '0'); 66 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); 67 shouldBe('gl.getError()', '0'); 68 debug("Enable an extra attribute with insufficient data buffer"); 69 gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT)); 70 shouldBe('gl.getError()', '0'); 71 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); 72 shouldBe('gl.getError()', '0'); 73 33 74 successfullyParsed = true; -
trunk/WebCore/ChangeLog
r57705 r57709 1 2010-04-15 Zhenyao Mo <zmo@google.com> 2 3 Reviewed by Dimitri Glazkov. 4 5 Index validation code validates too many vertex attributes 6 https://bugs.webkit.org/show_bug.cgi?id=31892 7 8 * html/canvas/WebGLProgram.cpp: 9 (WebCore::WebGLProgram::cacheActiveAttribLocations): Cache active attribute locations for a program at linkProgram time. 10 (WebCore::WebGLProgram::getActiveAttribLocation): Get the cached attribute location. 11 (WebCore::WebGLProgram::numActiveAttribLocations): Get the number of cached attribute locations. 12 * html/canvas/WebGLProgram.h: Add attribute locations member. 13 * html/canvas/WebGLRenderingContext.cpp: 14 (WebCore::WebGLRenderingContext::validateRenderingState): Add logic not to validate those attributes that do not belong to the current program. 15 (WebCore::WebGLRenderingContext::linkProgram): Call cacheActiveAttribLocations(). 16 1 17 2010-04-16 Adam Roben <aroben@apple.com> 2 18 -
trunk/WebCore/html/canvas/WebGLProgram.cpp
r50725 r57709 49 49 } 50 50 51 bool WebGLProgram::cacheActiveAttribLocations() 52 { 53 m_activeAttribLocations.clear(); 54 if (!object()) 55 return false; 56 GraphicsContext3D* context3d = context()->graphicsContext3D(); 57 int linkStatus; 58 context3d->getProgramiv(this, GraphicsContext3D::LINK_STATUS, &linkStatus); 59 if (!linkStatus) 60 return false; 61 62 int numAttribs = 0; 63 context3d->getProgramiv(this, GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs); 64 m_activeAttribLocations.resize(static_cast<size_t>(numAttribs)); 65 for (int i = 0; i < numAttribs; ++i) { 66 ActiveInfo info; 67 context3d->getActiveAttrib(this, i, info); 68 m_activeAttribLocations[i] = context3d->getAttribLocation(this, info.name.charactersWithNullTermination()); 69 } 70 71 return true; 72 } 73 74 int WebGLProgram::numActiveAttribLocations() 75 { 76 return static_cast<int>(m_activeAttribLocations.size()); 77 } 78 79 int WebGLProgram::getActiveAttribLocation(int index) 80 { 81 if (index < 0 || index >= numActiveAttribLocations()) 82 return -1; 83 return m_activeAttribLocations[static_cast<size_t>(index)]; 84 } 85 51 86 } 52 87 -
trunk/WebCore/html/canvas/WebGLProgram.h
r50725 r57709 31 31 #include <wtf/PassRefPtr.h> 32 32 #include <wtf/RefCounted.h> 33 #include <wtf/Vector.h> 33 34 34 35 namespace WebCore { … … 39 40 40 41 static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); 42 43 // cacheActiveAttribLocation() is only called once after linkProgram() 44 // succeeds. 45 bool cacheActiveAttribLocations(); 46 int numActiveAttribLocations(); 47 int getActiveAttribLocation(int index); 41 48 42 49 protected: … … 44 51 45 52 virtual void _deleteObject(Platform3DObject); 53 54 private: 55 Vector<int> m_activeAttribLocations; 46 56 }; 47 57 -
trunk/WebCore/html/canvas/WebGLRenderingContext.cpp
r57574 r57709 694 694 bool WebGLRenderingContext::validateRenderingState(long numElementsRequired) 695 695 { 696 if (!m_currentProgram) 697 return false; 698 696 699 // Look in each enabled vertex attrib and find the smallest buffer size 697 700 long smallestNumElements = LONG_MAX; 698 for (unsigned i = 0; i < m_vertexAttribState.size(); ++i) { 699 const VertexAttribState& state = m_vertexAttribState[i]; 700 if (state.enabled && state.numElements < smallestNumElements) 701 smallestNumElements = state.numElements; 701 int numActiveAttribLocations = m_currentProgram->numActiveAttribLocations(); 702 int numAttribStates = static_cast<int>(m_vertexAttribState.size()); 703 for (int i = 0; i < numActiveAttribLocations; ++i) { 704 int loc = m_currentProgram->getActiveAttribLocation(i); 705 if (loc >=0 && loc < numAttribStates) { 706 const VertexAttribState& state = m_vertexAttribState[loc]; 707 if (state.enabled && state.numElements < smallestNumElements) 708 smallestNumElements = state.numElements; 709 } 702 710 } 703 711 … … 1570 1578 return; 1571 1579 m_context->linkProgram(program); 1580 program->cacheActiveAttribLocations(); 1572 1581 cleanupAfterGraphicsCall(false); 1573 1582 }
Note: See TracChangeset
for help on using the changeset viewer.