Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a me.Path2D API for better abstraction between Canvas and WebGL #648

Closed
agmcleod opened this issue Feb 10, 2015 · 8 comments
Closed

Comments

@agmcleod
Copy link
Collaborator

drawShape : function (shape) {

This method uses stroke calls. It should be an option to do stroke or fill.

@agmcleod agmcleod added this to the 2.2.0 milestone Feb 10, 2015
@parasyte
Copy link
Collaborator

Reminder: We don't have fill operations in the WebGL compositor.

@agmcleod
Copy link
Collaborator Author

Oh that's a good point, hmmm.

@parasyte
Copy link
Collaborator

We will need an equivalent of the Canvas Path API to support all of the fill operations in WebGL. At the moment we can only fill rectangles using the quad shader.

@obiot obiot modified the milestones: 3.0.0, 2.2.0 Jul 9, 2015
@obiot
Copy link
Member

obiot commented Jul 9, 2015

moving to 3.0.0, looks like too many changes to have this ready for 2.2.0

@obiot
Copy link
Member

obiot commented Aug 21, 2015

looking at this old ticket, we already have some fill[Shape] function :
https://github.com/melonjs/melonJS/blob/master/src/video/canvas/canvas_renderer.js#L223

but to make it generic, i would rather keep only the generic drawShape one as the public one :
https://github.com/melonjs/melonJS/blob/master/src/video/canvas/canvas_renderer.js#L500

and then mimic the canvas API by adding a fillStyle and setStroke properties or function that can be called before and after the drawShape function

note: Flash defines a beginFill and endFill function, we could reuse the same approach and extend to stroke with beginStroke and endStroke ?
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001280.html

that would give the following semantic :

renderer.beginFill(0x333333);
renderer.beginStroke(0xFFFFFF);

renderer.drawShape(myShape);

renderer.endFill(); // optional if subsequent shapes should use the same
renderer.endStroke(); // optional if subsequent shapes should use the same

@parasyte
Copy link
Collaborator

That Flash API doesn't feel much like Canvas. What we really need to do is polyfill the Path2D API: https://developer.mozilla.org/en-US/docs/Web/API/Path2D (and implement it directly for WebGL) as a replacement for custom stuff like drawShape.

@obiot
Copy link
Member

obiot commented Aug 21, 2015

oh, i like that idea even better !

@obiot obiot changed the title Update drawShape in renderer to allow stroke/fill option Add a Path2D API polyfill as a replacement for custom function like drawShape Sep 3, 2015
@obiot obiot modified the milestones: 3.1.0, 3.0.0 Sep 3, 2015
@obiot obiot modified the milestones: 4.0.0, 3.1.0 Apr 4, 2016
@obiot obiot modified the milestones: Future, 4.0.0 Sep 15, 2016
obiot added a commit that referenced this issue Dec 11, 2018
obiot added a commit that referenced this issue Dec 13, 2018
- ellipse drawing is approximative and aliased, proper way to get a clean circle is probably through a shader
- also optimized/prevented buffer allocation when drawing shapes in WebGL (by passing the _glPoints (former _linePoints) array  and the actual "used" len to the drawLine method)
@obiot
Copy link
Member

obiot commented Dec 14, 2018

both renderer now support stroke and fill operations for all me.Shape objects, what we need now is a path2d implementation to provide one more layer of abstraction when drawing these shapes and move away drawing code from both corresponding renderer.

@obiot obiot changed the title Add a Path2D API polyfill as a replacement for custom function like drawShape Add a me.Path2D API for better abstraction between Canvas and WebGL Dec 14, 2018
@melonjs melonjs locked and limited conversation to collaborators Sep 6, 2021
@obiot obiot closed this as completed Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants