StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Any plan to expose the Material of a shape Graphics ? #8

Closed yderidde closed 12 years ago

yderidde commented 12 years ago

Basically in case we want to create custom graphics optimized routine using custom shaders, would be nice to architect the Shape so we can easily swap for another Graphics implementation somehow so as developers we are not limited to the shaders and features you expose into Graphics.

I believe today one solution would be to extend Shape or create our own type of Shape which would use an extended version of Graphics.

jonathanrpace commented 12 years ago

"I believe today one solution would be to extend Shape or create our own type of Shape which would use an extended version of Graphics."

Yep, that's currently the easiest way to get custom behaviour. Inside your version of 'Graphics' you would have full access to materials/shaders/vertex data to do whatever you like. You would also need to extend Fill and Stroke if you wanted to get some really custom behaviours (something that required additional vertex data for example).

I'd like to make the current graphics API a little more flexible, but still retain its purpose of providing simple access to the underlying Fills and Strokes.

I'm currently leaning towards something like this

shape.graphics.materialLineStyle( thickness, someMaterial )
shape.graphics.beginMaterialFill( someMaterial)
shape.graphics.drawRectangle(0,0,100,100)

This would draw a rectangle with a stroke and fill rendered with a custom material (implementing starling.display.materials.IMaterial).

Would this provide the sort of flexibility you need? I'd be interesting in hearing what else you'd add your own graphics implementation.

yderidde commented 12 years ago

It would definitely already give much more flexibility if we can provide an IMaterial that way.

Well, about my custom graphics implementation it is mainly to use custom shaders that are very specific to my use cases where i want to do the work within the shader with the use of Vertex Constants for performance reasons. So i would need to be able to get back a reference of my shader to explicitly set my vertex constants when needed (from a user interaction or whatever).

So i was thinking that being able to get back the reference of the material was handy but I think your solution is even better as we would set the material and therefore we would know about its reference ;)

yderidde commented 12 years ago

I would also like to explain in more details my app use-case and usage of stage3d with intense vector based drawing. Discuss performance optimisation etc. But would be better if we can take this offline. please send me an email to yanivderidder@gmail.com

Thanks very much.

sumit51 commented 12 years ago

I would also like to explain in more details

jonathanrpace commented 12 years ago

@sumit51 - I contacted you on Thursday and again today via private mail, but not heard back from you yet.

@yderidde - The beginMaterialFill and materialLineStyle updates have just gone in. Additionally, there's a 'Plane' primitive you could use that should give you faster performance than graphics.drawRect().

yderidde commented 12 years ago

@jonathanrpace Thanks ! Will have a look :+1: