@@ -21,7 +21,7 @@ package starling.styles
2121 import starling.rendering.VertexDataFormat ;
2222 import starling.textures.Texture ;
2323
24- /** Provides a way to batch up to 4 different textures in one draw call, at the cost of more complex custom Fragment Shaders
24+ /** Provides a way to batch up to 5 (baseline profile) or 16 different textures in one draw call, at the cost of more complex custom Fragment Shaders
2525 * To use this, set Mesh.defaultStyle to MultiTextureStyle (ideally before Starling is initialised!)
2626 **/
2727 public class MultiTextureStyle extends MeshStyle
@@ -32,7 +32,13 @@ package starling.styles
3232
3333 private static var _MAX_NUM_TEXTURES : int = 5 ;
3434
35- /** Maximum number of textures that can be batched. */
35+ /**
36+ * Maximum number of textures that can be batched.
37+ * Default value is 5 (which is the absolute max with baseline profile)
38+ * until <code >MultiTextureStyle.init()</code > has been called with Starling started
39+ * You can call it manually if you want/need, otherwise it will be called by the
40+ * first MultiTextureStyle instance created.
41+ */
3642 public static function get MAX_NUM_TEXTURES ():int { return _MAX_NUM_TEXTURES ; }
3743
3844 private var _dirty : Boolean = true ;
@@ -46,8 +52,19 @@ package starling.styles
4652 public static function set maxTextures (value :int ):void
4753 {
4854 if (! _initDone ) init ();
49- value = value < 1 ? 1 : value ;
50- sMaxTextures = value > _MAX_NUM_TEXTURES ? _MAX_NUM_TEXTURES : value ;
55+
56+ if (! _initDone )
57+ {
58+ // we don't know the profile yet, allow a max value of 16 (absolute max on non-baseline profile)
59+ // that number might be reduced when we can finally check profile
60+ value = value < 1 ? 1 : value > 16 ? 16 : value ;
61+ sMaxTextures = value ;
62+ }
63+ else
64+ {
65+ value = value < 1 ? 1 : value ;
66+ sMaxTextures = value > _MAX_NUM_TEXTURES ? _MAX_NUM_TEXTURES : value ;
67+ }
5168 }
5269
5370 private static var _TEXTURE_INDEX_FACTOR : Number ;
@@ -56,6 +73,7 @@ package starling.styles
5673 public static function init ():void
5774 {
5875 if (_initDone ) return ;
76+ if (Starling. current == null ) return ;
5977
6078 if (Starling. current . profile. indexOf ("baseline" ) != - 1 )
6179 {
@@ -68,6 +86,8 @@ package starling.styles
6886 _TEXTURE_INDEX_FACTOR = 1.0 ;
6987 }
7088
89+ if (sMaxTextures > _MAX_NUM_TEXTURES ) sMaxTextures = _MAX_NUM_TEXTURES ;
90+
7191 _initDone = true ;
7292 }
7393
0 commit comments