示例#1
0
 public void addTexel(Texel tex)
 {
     texels[index] = tex;
     index++;
 }
示例#2
0
        public TexelIndex(Color[] texColors)
        {
            int mipLevels = (int)(Math.Log(texColors.Length) / Math.Log(4.0));

            EDebug.Log("TI miplevels " + mipLevels);

            int pixelCount = texColors.Length;

            //setup texels
            texelLevels = new TexelLevel[mipLevels];
            for (int i = 0; i < texelLevels.Length; i++)
            {
                texelLevels[i] = new TexelLevel(pixelCount);
                pixelCount    /= 4;
            }

            int sideDimension = (int)Math.Sqrt(texColors.Length); //256 becomes 16 , the side dimension

            for (int i = 0; i < texColors.Length; i += sideDimension * 2)
            {
                for (int j = 0; j < sideDimension; j += 2)
                {
                    int l = j + i;

                    Color[] targetC = new Color[4];
                    targetC[0] = texColors[l];
                    targetC[1] = texColors[l + 1];
                    targetC[2] = texColors[l + sideDimension];
                    targetC[3] = texColors[l + sideDimension + 1];

                    Texel tex = new TexelCalculation(targetC).getTexel();

                    texelLevels[0].addTexel(tex);
                }
            }

            TexelOps to = new TexelOps();

            Texel[] target = new Texel[4];

            for (int i = 0; i < texelLevels.Length - 1; i++) // for each level (except the last one)
            {
                TexelLevel texelLevel       = texelLevels[i];
                int        texelCount       = texelLevels[i].getTexelCount();
                int        mipSideDimension = (int)Math.Sqrt(texelCount);

                int capacity = (mipSideDimension ^ 2) / 4;
                //Debug.Log("mip side dimension :  " + mipSideDimension * 2);


                // combine 4 texels together and add the resulting texel to the next level
                for (int j = 0; j < texelCount; j += mipSideDimension * 2)
                {
                    for (int k = 0; k < mipSideDimension; k += 2)
                    {
                        int l = j + k;

                        target[0] = texelLevel.getTexel(l);
                        target[1] = texelLevel.getTexel(l + 1);
                        target[2] = texelLevel.getTexel(l + mipSideDimension);
                        target[3] = texelLevel.getTexel(l + mipSideDimension + 1);

                        Texel combinedTex = to.CombineTexels(target);

                        // add combined texel to next
                        texelLevels[i + 1].addTexel(combinedTex);

                        capacity++;
                    }
                }
            }
        }