Closed
Bug 571054
Opened 14 years ago
Closed 14 years ago
emulate vertex attrib 0 on desktop GL
Categories
(Core :: Graphics: CanvasWebGL, defect)
Core
Graphics: CanvasWebGL
Tracking
()
RESOLVED
FIXED
Tracking | Status | |
---|---|---|
blocking2.0 | --- | betaN+ |
People
(Reporter: vlad, Assigned: bjacob)
Details
Attachments
(1 file, 2 obsolete files)
17.23 KB,
patch
|
vlad
:
review+
|
Details | Diff | Splinter Review |
See "vertex attribute 0" at http://khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences We need to essentially create a dummy array of the appropriate size and bind it there, and we need to keep track of VertexAttrib[1234]* calls for attribute 0.
Reporter | ||
Updated•14 years ago
|
Assignee: nobody → vladimir
Reporter | ||
Updated•14 years ago
|
Assignee: vladimir → bjacob
Reporter | ||
Updated•14 years ago
|
blocking2.0: --- → betaN+
Assignee | ||
Comment 1•14 years ago
|
||
At long last, here it is.
Attachment #470578 -
Flags: review?(vladimir)
Reporter | ||
Comment 2•14 years ago
|
||
Comment on attachment 470578 [details] [diff] [review] Handle vertex attrib 0 on desktop GL Ack.. like we discussed, don't use a VBO; there's no reason to, and there's unnecessary overhead and complexity in creating/managing it. Just create a client-side buffer (via new) and use glVertexAttribPointer directly with no VBO bound (0), and the only thing you have to do is restore the pointer and current VBO binding. Looks good other than that (though keep the same indentation style in your new VertexAttrib* methods -- e.g. NS_IMETHODIMP on its own line, WebGLContext:: at the start of a new one etc.).
Attachment #470578 -
Flags: review?(vladimir) → review-
Assignee | ||
Comment 3•14 years ago
|
||
Right, here's the new version.
Attachment #470578 -
Attachment is obsolete: true
Attachment #470809 -
Flags: review?(vladimir)
Reporter | ||
Comment 4•14 years ago
|
||
Why make this so complicated? It's unnecessary and premature optimization that complicates the code. There's no need for a WebGLVector4f type, and there's no need to keep this vector around in between calls to optimize for using the same value. float mAttrib0Value[4]; nsAutoArrayPtr<float> mVector; mVector = new float[length * 4]; float *fp = &mVector[0]; for (int i = 0; i < length; ++i) { *fp++ = mAttrib0Value[0]; *fp++ = mAttrib0Value[1]; *fp++ = mAttrib0Value[2]; *fp++ = mAttrib0Value[3]; } vertexAttribPointer(... mVector); And then after vertexAttribPointer has been reset, just mVector = nsnull;
Assignee | ||
Comment 5•14 years ago
|
||
But keeping the buffer around had another use: it allowed to avoid doing a malloc() on every draw-call. We're talking about 16 bytes per vertex here, and a typical complex scene would draw 1e+6 vertices per second, so we're talking about avoiding a traffic of 1e+7 bytes malloc'd and free'd per second. Is that really negligible?
Reporter | ||
Comment 6•14 years ago
|
||
Yes, because this situation will be extremely rare and easy to work around. Assigning constants to vertex attrib 0 is very uncommon, and if the shader compiler happens to pick 0 for an attrib that you want a constant for (say, a color), you can use bindAttribLocation to force something like your vertex coords to be 0.
Assignee | ||
Comment 7•14 years ago
|
||
Here you go!
Attachment #470809 -
Attachment is obsolete: true
Attachment #470877 -
Flags: review?(vladimir)
Attachment #470809 -
Flags: review?(vladimir)
Reporter | ||
Comment 8•14 years ago
|
||
Comment on attachment 470877 [details] [diff] [review] Handle vertex attrib 0 on desktop GL, version 3 Looks good, thanks!
Attachment #470877 -
Flags: review?(vladimir) → review+
Assignee | ||
Comment 9•14 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/8d80930e10f3
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•