Example #1
0
        /// <summary>
        /// Create a new mipmap with the data all set to 0.
        /// </summary>
        public Mipmap2D(int width, int height, int channels, int bitDepth, TEXTURE_MIPMAP mode = TEXTURE_MIPMAP.BOX, int minLevel = -1)
            : base(width, height, channels, bitDepth)
        {
            MipmapMode = mode;

            int min = Math.Min(width, height);

            Levels = (int)(Math.Log(min) / Math.Log(2)) + 1;

            if (minLevel > -1 && Levels > minLevel)
            {
                Levels = minLevel;
            }

            Data = new List <TextureData2D>(Levels);

            int w = Width;
            int h = Height;

            for (int i = 0; i < Levels; i++)
            {
                Data.Add(TextureData2D.CreateData(w, h, channels, bitDepth));
                w /= 2;
                h /= 2;
            }
        }
Example #2
0
        private void CreateData(int width, int height, int channels, int bitDepth, TEXTURE_MIPMAP mode)
        {
            Data = null;

            if (mode != TEXTURE_MIPMAP.NONE)
            {
                Data = new Mipmap2D(width, height, channels, bitDepth, mode);
            }
            else
            {
                Data = TextureData2D.CreateData(width, height, channels, bitDepth);
            }
        }
Example #3
0
        public void DimensionsCorrect()
        {
            int            width    = 64;
            int            height   = 128;
            int            channels = 3;
            int            bitDepth = 8;
            TEXTURE_MIPMAP mode     = TEXTURE_MIPMAP.BOX;

            Mipmap2D mipmap = new Mipmap2D(width, height, channels, bitDepth, mode);

            Assert.AreEqual(width, mipmap.GetWidth());
            Assert.AreEqual(height, mipmap.GetHeight());
            Assert.AreEqual(channels, mipmap.Channels);
            Assert.AreEqual(bitDepth, mipmap.BitDepth);
            Assert.AreEqual(mode, mipmap.MipmapMode);
            Assert.IsInstanceOfType(mipmap.GetData(0), typeof(TextureData2D8));
        }
Example #4
0
        public Texture2D(int width, int height, int channels, int bitDepth, TEXTURE_MIPMAP mipmap)
        {
            if (channels < 1)
            {
                throw new ArgumentException("Channels must be at least 1");
            }
            if (width < 1)
            {
                throw new ArgumentException("Width must be at least 1");
            }
            if (height < 1)
            {
                throw new ArgumentException("Height must be at least 1");
            }

            CreateData(width, height, channels, bitDepth, mipmap);
        }