Example #1
0
        public bool IsCompatible(IGLPixelFormat pixelFormat, IGLDataFormat dataFormat)
        {
            switch (GLValue)
            {
            case Values.GL_RED:
                return(pixelFormat.Channels >= 1);

            case Values.GL_RGB:
            case Values.GL_R3_G3_B2:
            case Values.GL_RGB4:
            case Values.GL_RGB5:
            case Values.GL_RGB8:
            case Values.GL_RGB10:
            case Values.GL_RGB12:
            case Values.GL_RGB16:
                return(pixelFormat.Channels >= 3);

            case Values.GL_RGBA:
            case Values.GL_RGBA2:
            case Values.GL_RGBA4:
            case Values.GL_RGB5_A1:
            case Values.GL_RGBA8:
            case Values.GL_RGB10_A2:
            case Values.GL_RGBA12:
            case Values.GL_RGBA16:
                return(pixelFormat.Channels == 4);
            }
            return(false);
        }
Example #2
0
        public CoreTexture ToCoreTexture(GenericImage image, IGLDataFormat dataFormat)
        {
            CoreTexture texture = new CoreTexture();

            texture.glType                = dataFormat.Value;
            texture.glFormat              = Value;
            texture.glTypeSize            = 1;
            texture.pixelWidth            = image.width;
            texture.pixelHeight           = image.height;
            texture.pixelDepth            = image.depth == 1 ? 0 : image.depth;
            texture.numberOfFaces         = image.faces;
            texture.numberOfArrayElements = image.arrays == 1 ? 0 : image.arrays;

            texture.mipmapLevels = new CoreTextureMipmapLevel[image.mipmapLevels.Length];
            for (int mip = 0; mip < texture.mipmapLevels.Length; ++mip)
            {
                CoreTextureMipmapLevel mipTexture = new CoreTextureMipmapLevel();

                mipTexture.pixels         = ToCoreMipTexture(image, dataFormat, mip).ToArray();
                texture.mipmapLevels[mip] = mipTexture;
            }

            texture.keyValuePairs = new CoreTextureKeyValuePair[1] {
                new CoreTextureKeyValuePair("FileGenerator", "KTXToolkit by Tiemo Jung")
            };

            return(texture);
        }
Example #3
0
        protected List <byte> ToCoreMipTexturePixel(GenericImage image, IGLDataFormat dataFormat, int mipIndex, int pixelIndex)
        {
            List <byte> byteBuffer = new List <byte>();

            for (int channel = 0; channel < Channels; ++channel)
            {
                byteBuffer.AddRange(ToCoreMipTexturePixelAtIndex(image, dataFormat, mipIndex, pixelIndex, channel));
            }

            return(byteBuffer);
        }
Example #4
0
        protected List <double> ToGenericImagePixel(CoreTexture texture, IGLDataFormat dataFormat, int mipIndex, int pixelIndex)
        {
            List <double> byteBuffer = new List <double>();

            for (int channel = 0; channel < Channels; ++channel)
            {
                byteBuffer.Add(ToGenericImagePixelAtPixel(texture, dataFormat, mipIndex, pixelIndex, channel));
            }

            return(byteBuffer);
        }
Example #5
0
        override protected byte[] ToCoreMipTexturePixelAtIndex(GenericImage image, IGLDataFormat dataFormat, int mipIndex, int pixelIndex, int channelIndex)
        {
            long offset = pixelIndex * image.channels;

            if (channelIndex == 0)
            {
                return(dataFormat.ToCoreFormat(image.mipmapLevels[mipIndex].pixels, (int)offset, 2, (int)image.channels));
            }
            else if (channelIndex == 2)
            {
                return(dataFormat.ToCoreFormat(image.mipmapLevels[mipIndex].pixels, (int)offset, 0, (int)image.channels));
            }
            else
            {
                return(dataFormat.ToCoreFormat(image.mipmapLevels[mipIndex].pixels, (int)offset, channelIndex, (int)image.channels));
            }
        }
Example #6
0
        override protected double ToGenericImagePixelAtPixel(CoreTexture texture, IGLDataFormat dataFormat, int mipIndex, int pixelIndex, int channelIndex)
        {
            long offset = pixelIndex * dataFormat.PixelSize(Channels);

            if (channelIndex == 0)
            {
                return(dataFormat.ToGenericFormat(texture.mipmapLevels[mipIndex].pixels, (int)offset, 2, Channels));
            }
            else if (channelIndex == 2)
            {
                return(dataFormat.ToGenericFormat(texture.mipmapLevels[mipIndex].pixels, (int)offset, 0, Channels));
            }
            else
            {
                return(dataFormat.ToGenericFormat(texture.mipmapLevels[mipIndex].pixels, (int)offset, channelIndex, Channels));
            }
        }
Example #7
0
        private void TransformTextureBack()
        {
            IGLDataFormat         dataFormat          = GetDataFormat(texture.glType);
            IGLPixelFormat        pixelFormat         = GetPixelFormat(texture.glFormat);
            IGLInteralPixelFormat internalPixelFormat = GetInternalPixelFormat(texture.glInternalFormat);

            CoreTexture tex = internalPixelFormat.ToCoreTexture(genericTexture, pixelFormat, dataFormat);

            if (tex != null)
            {
                texture = tex;
            }
            else
            {
                MessageBox.Show("Unable to convert image data", "Error while converting image data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #8
0
        protected List <byte> ToCoreMipTexture(GenericImage image, IGLDataFormat dataFormat, int mipIndex)
        {
            int x = (int)image.width >> (int)mipIndex;
            int y = (int)image.height >> (int)mipIndex;
            int z = (int)image.depth >> (int)mipIndex;

            x = x < 1 ? 1 : x;
            y = y < 1 ? 1 : y;
            z = z < 1 ? 1 : z;
            int pixels = (int)(image.faces * image.arrays * x * y * z);

            List <byte> byteBuffer = new List <byte>();

            for (int pixel = 0; pixel < pixels; ++pixel)
            {
                byteBuffer.AddRange(ToCoreMipTexturePixel(image, dataFormat, mipIndex, pixel));
            }
            return(byteBuffer);
        }
Example #9
0
        protected List <double> ToGenericMipImage(CoreTexture texture, IGLDataFormat dataFormat, int mipIndex)
        {
            int x = (int)texture.pixelWidth >> (int)mipIndex;
            int y = (int)texture.pixelHeight >> (int)mipIndex;
            int z = (int)texture.pixelDepth >> (int)mipIndex;

            x = x < 1 ? 1 : x;
            y = y < 1 ? 1 : y;
            z = z < 1 ? 1 : z;
            int pixels = (int)(texture.numberOfFaces * Math.Max(1, texture.numberOfArrayElements) * x * y * z);

            List <double> byteBuffer = new List <double>();

            for (int pixel = 0; pixel < pixels; ++pixel)
            {
                byteBuffer.AddRange(ToGenericImagePixel(texture, dataFormat, mipIndex, pixel));
            }
            return(byteBuffer);
        }
Example #10
0
        public GenericImage ToGenericImage(CoreTexture texture, IGLDataFormat dataFormat)
        {
            GenericImage image = null;

            if (texture.glFormat == Value && dataFormat.Value == texture.glType)
            {
                image              = new GenericImage();
                image.channels     = (uint)Channels;
                image.width        = texture.pixelWidth;
                image.height       = texture.pixelHeight;
                image.depth        = texture.pixelDepth != 0 ? texture.pixelDepth : 1;
                image.arrays       = texture.numberOfArrayElements != 0 ? texture.numberOfArrayElements : 1;
                image.faces        = texture.numberOfFaces;
                image.mipmapLevels = new GenericImageMipmapLevel[texture.mipmapLevels.Length];
                for (int level = 0; level < texture.mipmapLevels.Length; ++level)
                {
                    image.mipmapLevels[level]        = new GenericImageMipmapLevel();
                    image.mipmapLevels[level].pixels = ToGenericMipImage(texture, dataFormat, level).ToArray();
                }
            }

            return(image);
        }
Example #11
0
        private void UpdateGenericImage()
        {
            IGLDataFormat         dataFormat          = GetDataFormat(texture.glType);
            IGLPixelFormat        pixelFormat         = GetPixelFormat(texture.glFormat);
            IGLInteralPixelFormat internalPixelFormat = GetInternalPixelFormat(texture.glInternalFormat);

            genericTexture = null;
            if (internalPixelFormat != null)
            {
                genericTexture = internalPixelFormat.ToGenericImage(texture, pixelFormat, dataFormat);
            }

            if (genericTexture == null)
            {
                MessageBox.Show(this, "Unsupported format ( 0x"
                                + texture.glType.ToString("X4")
                                + ", 0x"
                                + texture.glFormat.ToString("X4")
                                + ", 0x"
                                + texture.glInternalFormat.ToString("X4")
                                + ")", "Unsupported Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #12
0
        virtual protected byte[] ToCoreMipTexturePixelAtIndex(GenericImage image, IGLDataFormat dataFormat, int mipIndex, int pixelIndex, int channelIndex)
        {
            long offset = pixelIndex * image.channels;

            return(dataFormat.ToCoreFormat(image.mipmapLevels[mipIndex].pixels, (int)offset, channelIndex, (int)image.channels));
        }
Example #13
0
        virtual protected double ToGenericImagePixelAtPixel(CoreTexture texture, IGLDataFormat dataFormat, int mipIndex, int pixelIndex, int channelIndex)
        {
            long offset = pixelIndex * dataFormat.PixelSize(Channels);

            return(dataFormat.ToGenericFormat(texture.mipmapLevels[mipIndex].pixels, (int)offset, channelIndex, Channels));
        }
Example #14
0
        public CoreTexture ToCoreTexture(GenericImage image, IGLPixelFormat pixelFormat, IGLDataFormat dataFormat)
        {
            CoreTexture tex = pixelFormat.ToCoreTexture(image, dataFormat);

            if (tex != null)
            {
                tex.glInternalFormat = Value;

                switch (GLValue)
                {
                case Values.GL_RED:
                    tex.glBaseInternalFormat = (UInt32)Values.GL_RED;
                    break;

                case Values.GL_RGB:
                case Values.GL_R3_G3_B2:
                case Values.GL_RGB4:
                case Values.GL_RGB5:
                case Values.GL_RGB8:
                case Values.GL_RGB10:
                case Values.GL_RGB12:
                case Values.GL_RGB16:
                    tex.glBaseInternalFormat = (UInt32)Values.GL_RGB;
                    break;

                case Values.GL_RGBA:
                case Values.GL_RGBA2:
                case Values.GL_RGBA4:
                case Values.GL_RGB5_A1:
                case Values.GL_RGBA8:
                case Values.GL_RGB10_A2:
                case Values.GL_RGBA12:
                case Values.GL_RGBA16:
                    tex.glBaseInternalFormat = (UInt32)Values.GL_RGBA;
                    break;
                }
            }
            return(tex);
        }
Example #15
0
 public GenericImage ToGenericImage(CoreTexture texture, IGLPixelFormat pixelFormat, IGLDataFormat dataFormat)
 {
     return(pixelFormat.ToGenericImage(texture, dataFormat));
 }