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

Multi-texture feature request #260

Open
mnordine opened this issue Feb 1, 2017 · 3 comments
Open

Multi-texture feature request #260

mnordine opened this issue Feb 1, 2017 · 3 comments

Comments

@mnordine
Copy link
Contributor

mnordine commented Feb 1, 2017

GPU draw calls can be a bottleneck, especially on older mobile devices. Other engines support "GPU multi-texturing". To improve performance, StageXL should support this feature. For reference, see:

http://www.goodboydigital.com/pixi-js-v4-batching/
https://phaser.io/tutorials/advanced-rendering-tutorial/part2

@bp74
Copy link
Owner

bp74 commented Feb 1, 2017

Hi,

Yes i know this feature from PixiJS and StageXL had this feature too :) StageXL was smart enough to batch draw calls for different textures together in one draw call, the same way as PixiJS does. It looks like a great feature but it is not! The problem is the code of the fragment shader and the way how you can access texture memory in WebGL1. The fragment shader needs to look something like this:

if (vTexture == 0.0) {
  color = texture2D(0, vCoordinates);
} else if (vTexture == 1.0) {
  color = texture2D(1, vCoordinates);
} else if (vTexture == 2.0) {
  color = texture2D(2, vCoordinates);
} if (vTexture == 3.0) {
  color = texture2D(3, vCoordinates);
} 

This is an anti pattern for shader code and makes rendering slow! Granted, it is faster than multiple draw calls, but still slower than correct texture management by the developer (combine all your images on a common texture). So i decided that it is a nice feature to write an article about (like PixiJS did) but not a good feature in reality.

Let's talk about WebGL2 - as you may have heard the latest versions of Chrome and Firefox added support for WebGL2. As soon as Dart provides the necessary APIs i will add a render path to StageXL for WebGL2, which supports reading from different textures much more nicely than WebGL1 does. To make a long story short, your requested feature will come once we have WebGL2 in StageXL.

@mnordine
Copy link
Contributor Author

mnordine commented Feb 1, 2017

Yes, I was aware it could complicate the shader code, but it seems it would be nice to have as an option perhaps? In some scenarios it may be worth it? A WebGL2 renderer does indeed look promising, but of course there's some mobile devices that will never get it, :(. iPad 2 and 3 for instance

@bp74
Copy link
Owner

bp74 commented Feb 1, 2017

Maybe i will build a small prototype you could use, but no promises :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants