@@ -257,7 +257,7 @@ public void setupLayoutBounds(int usingClipCount) {
257257 for (int index = 0 ; index < clippingContextListForMask .size (); index ++) {
258258 T_ClippingContext cc = clippingContextListForMask .get (index );
259259
260- cc .layoutChannelNo = 0 ; // どうせ毎回消すので固定で良い
260+ cc .layoutChannelIndex = 0 ; // どうせ毎回消すので固定で良い
261261 cc .layoutBounds .setX (0.0f );
262262 cc .layoutBounds .setY (0.0f );
263263 cc .layoutBounds .setWidth (1.0f );
@@ -272,25 +272,31 @@ public void setupLayoutBounds(int usingClipCount) {
272272
273273 // ひとつのRenderTextureを極力いっぱいに使ってマスクをレイアウトする。
274274 // マスクグループの数が4以下ならRGBA各チャンネルに1つずつマスクを配置し、5以上6以下ならRGBAを2,2,1,1と配置する。
275- int countPerSheetDiv = usingClipCount / renderTextureCount ; // レンダーテクスチャ1枚あたり何枚割り当てるか
276- int countPerSheetMod = usingClipCount % renderTextureCount ; // この番号のレンダーテクスチャまでに1つずつ配分する。
275+ // NOTE: 1枚に割り当てるマスクの分割数を取りたいため、小数点は切り上げる。
276+ final int countPerSheetDiv = (usingClipCount + renderTextureCount - 1 ) / renderTextureCount ; // レンダーテクスチャ1枚あたり何枚割り当てるか
277+ final int reduceLayoutTextureCount = usingClipCount % renderTextureCount ; // レイアウトの数を1枚減らすレンダーテクスチャの数(この数だけのレンダーテクスチャが対象)。
277278
278279 // RGBAを順番に使っていく。
279- final int div = countPerSheetDiv / COLOR_CHANNEL_COUNT ; // 1チャンネルに配置する基本のマスク個数
280- final int mod = countPerSheetDiv % COLOR_CHANNEL_COUNT ; // 余り、この番号のチャンネルまでに1つずつ配分する
280+ final int divCount = countPerSheetDiv / COLOR_CHANNEL_COUNT ; // 1チャンネルに配置する基本のマスク個数
281+ final int modCount = countPerSheetDiv % COLOR_CHANNEL_COUNT ; // 余り、この番号のチャンネルまでに1つずつ配分する(インデックスではない)
281282
282283 // RGBAそれぞれのチャンネルを用意していく(0:R , 1:G , 2:B, 3:A, )
283284 int curClipIndex = 0 ; // 順番に設定していく
284285
285- for (int renderTextureNo = 0 ; renderTextureNo < renderTextureCount ; renderTextureNo ++) {
286- for (int channelNo = 0 ; channelNo < COLOR_CHANNEL_COUNT ; channelNo ++) {
286+ for (int renderTextureIndex = 0 ; renderTextureIndex < renderTextureCount ; renderTextureIndex ++) {
287+ for (int channelIndex = 0 ; channelIndex < COLOR_CHANNEL_COUNT ; channelIndex ++) {
287288 // このチャンネルにレイアウトする数
288- int layoutCount = div + (channelNo < mod ? 1 : 0 );
289+ // NOTE: レイアウト数 = 1チャンネルに配置する基本のマスク + 余りのマスクを置くチャンネルなら1つ追加
290+ int layoutCount = divCount + (channelIndex < modCount ? 1 : 0 );
289291
290- // このレンダーテクスチャにまだ割り当てられていなければ追加する
291- final int checkChannelNo = mod + 1 >= COLOR_CHANNEL_COUNT ? 0 : mod + 1 ;
292- if (layoutCount < layoutCountMaxValue && channelNo == checkChannelNo ) {
293- layoutCount += renderTextureNo < countPerSheetMod ? 1 : 0 ;
292+ // レイアウトの数を1枚減らす場合にそれを行うチャンネルを決定
293+ // divが0の時は正常なインデックスの範囲になるように調整
294+ final int checkChannelIndex = modCount + (divCount < 1 ? -1 : 0 );
295+
296+ // 今回が対象のチャンネルかつ、レイアウトの数を1枚減らすレンダーテクスチャが存在する場合
297+ if (channelIndex == checkChannelIndex && reduceLayoutTextureCount > 0 ) {
298+ // 現在のレンダーテクスチャが、対象のレンダーテクスチャであればレイアウトの数を1枚減らす。
299+ layoutCount -= !(renderTextureIndex < reduceLayoutTextureCount ) ? 1 : 0 ;
294300 }
295301
296302 // 分割方法を決定する。
@@ -299,21 +305,21 @@ public void setupLayoutBounds(int usingClipCount) {
299305 } else if (layoutCount == 1 ) {
300306 // 全てをそのまま使う。
301307 T_ClippingContext cc = clippingContextListForMask .get (curClipIndex ++);
302- cc .layoutChannelNo = channelNo ;
308+ cc .layoutChannelIndex = channelIndex ;
303309 csmRectF bounds = cc .layoutBounds ;
304310
305311 bounds .setX (0.0f );
306312 bounds .setY (0.0f );
307313 bounds .setWidth (1.0f );
308314 bounds .setHeight (1.0f );
309315
310- cc .bufferIndex = renderTextureNo ;
316+ cc .bufferIndex = renderTextureIndex ;
311317 } else if (layoutCount == 2 ) {
312318 for (int i = 0 ; i < layoutCount ; i ++) {
313319 final int xpos = i % 2 ;
314320
315321 T_ClippingContext cc = clippingContextListForMask .get (curClipIndex ++);
316- cc .layoutChannelNo = channelNo ;
322+ cc .layoutChannelIndex = channelIndex ;
317323 csmRectF bounds = cc .layoutBounds ;
318324
319325 // UVを2つに分解して使う
@@ -322,7 +328,7 @@ public void setupLayoutBounds(int usingClipCount) {
322328 bounds .setWidth (0.5f );
323329 bounds .setHeight (1.0f );
324330
325- cc .bufferIndex = renderTextureNo ;
331+ cc .bufferIndex = renderTextureIndex ;
326332 }
327333 } else if (layoutCount <= 4 ) {
328334 // 4分割して使う
@@ -331,15 +337,15 @@ public void setupLayoutBounds(int usingClipCount) {
331337 final int ypos = i / 2 ;
332338
333339 T_ClippingContext cc = clippingContextListForMask .get (curClipIndex ++);
334- cc .layoutChannelNo = channelNo ;
340+ cc .layoutChannelIndex = channelIndex ;
335341 csmRectF bounds = cc .layoutBounds ;
336342
337343 bounds .setX (xpos * 0.5f );
338344 bounds .setY (ypos * 0.5f );
339345 bounds .setWidth (0.5f );
340346 bounds .setHeight (0.5f );
341347
342- cc .bufferIndex = renderTextureNo ;
348+ cc .bufferIndex = renderTextureIndex ;
343349 }
344350 } else if (layoutCount <= layoutCountMaxValue ) {
345351 // 9分割して使う
@@ -348,15 +354,15 @@ public void setupLayoutBounds(int usingClipCount) {
348354 final int ypos = i / 3 ;
349355
350356 T_ClippingContext cc = clippingContextListForMask .get (curClipIndex ++);
351- cc .layoutChannelNo = channelNo ;
357+ cc .layoutChannelIndex = channelIndex ;
352358 csmRectF bounds = cc .layoutBounds ;
353359
354360 bounds .setX (xpos / 3.0f );
355361 bounds .setY (ypos / 3.0f );
356362 bounds .setWidth (1.0f / 3.0f );
357363 bounds .setHeight (1.0f / 3.0f );
358364
359- cc .bufferIndex = renderTextureNo ;
365+ cc .bufferIndex = renderTextureIndex ;
360366 }
361367 }
362368 // マスクの制限枚数を超えた場合の処理
@@ -376,7 +382,7 @@ public void setupLayoutBounds(int usingClipCount) {
376382 // もちろん描画結果はろくなことにならない。
377383 for (int i = 0 ; i < layoutCount ; i ++) {
378384 T_ClippingContext cc = clippingContextListForMask .get (curClipIndex ++);
379- cc .layoutChannelNo = 0 ;
385+ cc .layoutChannelIndex = 0 ;
380386
381387 csmRectF bounds = cc .layoutBounds ;
382388 bounds .setX (0.0f );
@@ -407,8 +413,8 @@ public int getRenderTextureCount() {
407413 }
408414
409415 @ Override
410- public CubismRenderer .CubismTextureColor getChannelFlagAsColor (int channelNo ) {
411- return channelColors .get (channelNo );
416+ public CubismRenderer .CubismTextureColor getChannelFlagAsColor (int channelIndex ) {
417+ return channelColors .get (channelIndex );
412418 }
413419
414420 /**
0 commit comments