empaempa / GLOW

GLOW is a WebGL wrapper, which focuses on easy creation and use of shaders.
http://i-am-glow.com
MIT License
244 stars 28 forks source link

GLOW.ShaderUtils.createMultiple only supports triangles #5

Open neilmendoza opened 12 years ago

neilmendoza commented 12 years ago

GLOW.ShaderUtils.createMultiple doesn't work for points. As far as I can see Glow only deals with indexed rendering, i.e. glDrawElements rather than glDrawArrays. For drawing points, glDrawArrays would may be better anyway, as there wouldn't be shared vertices. This function would then no longer be necessary as the limitation is on the size of the data type of the index array.

empaempa commented 12 years ago

Good point! (pun intended) I haven't really dealt with DrawArrays before but I guess a nice way of implementing it would be to simply NOT have elements/points/triangles/triangleFan/triangleStrip in the shader config object. If it's lacking, we simply make a drawArrays instead of drawElements. I'll look into it - do you need it quickly?

empaempa commented 12 years ago

...or not. You need to know what type (TRIANGLE etc.) to draw. Any suggestions on how to set this up in a nice, consistent maner?

empaempa commented 12 years ago

Ok, I did like this now... in the shader config object, set the length as a number where elements used to be. For example...

myShaderConfig = { triangles: 10 * 3, data: { // your data here } }

...to use drawArrays for 10 triangles. Side note: I've also added .offset to GLOW.Elements (which is still used in the drawArray case, just that its .elements is undefined) so you can offset or set the first when drawing.

If you have a better idea on how to handle this, please let me know - I'm all ears :)

neilmendoza commented 12 years ago

Thanks for the quick update! I should probably have better things to do than creating issues on Xmas day ;) Hopefully DrawArrays isn't using 16 bit indices under the hood otherwise the 65536 limit will still be there, will give it a go.

Off the top of my head, coming from OpenGL, I might have done something like this...

Indexed

myShaderConfig = {
  indices: myIndices, 
  data: {
    vertices: myVerts,
    primitive: GL.TRIANGLES
  }
}

Non-indexed

myShaderConfig = {
  data: {
    vertices: myVerts, 
    primitive: GL.TRIANGLES
  }
}

...where primitive defaults to something (maybe triangles), and if there's no index array then it just works out what to do from the size of the vertex array. Will have a think about it some more.

Happy holidays!

empaempa commented 12 years ago

I should, too, but things like these are just too much fun :)

Yeah, I was thinking about figuring out the length using one of the attributes but I thought the ability to set the amount was nice. Now I think about it, you're probably right - most times you're not interested in setting the length but just get them all drawn. I'd look into changing into...

Indexed

myShaderConfig = {
  indices: myIndices, // the 'indices' property could also be triangles/points/etc and then you don't have to define...
  primitive: GL.POINTS, // if left out, defaults to GL.TRIANGLES
  data: {
    // attributes and uniforms
  }
};

Non-Indexed


myShaderConfig = {
  primitive: GL.POINTS, // if left out, defaults to GL.TRIANGLES
  data: {
    // attributes and uniforms
  }
};

Thanks for the input! Happy new year!

(BTW: if you publish anything using GLOW, please let me know!)

empaempa commented 12 years ago

Ok, done. Please pull. And read the latest post on http://i-am-glow.com :D

neilmendoza commented 12 years ago

Changes look great! Thanks for the mention on the blog :)

Will let you know when I get around to publishing something...