コード例 #1
0
        private static int getImageSize(RenderableTex t)
        {
            switch (t.pixelInternalFormat)
            {
            case PixelInternalFormat.CompressedRgbaS3tcDxt1Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext:
            case PixelInternalFormat.CompressedRedRgtc1:
            case PixelInternalFormat.CompressedSignedRedRgtc1:
                return(t.width * t.height / 2);

            case PixelInternalFormat.CompressedRgbaS3tcDxt3Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext:
            case PixelInternalFormat.CompressedRgbaS3tcDxt5Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext:
            case PixelInternalFormat.CompressedSignedRgRgtc2:
            case PixelInternalFormat.CompressedRgRgtc2:
            case PixelInternalFormat.CompressedRgbaBptcUnorm:
            case PixelInternalFormat.CompressedSrgbAlphaBptcUnorm:
                return(t.width * t.height);

            case PixelInternalFormat.Rgba:
                return(t.ImageSize);

            default:
                return(t.ImageSize);
            }
        }
コード例 #2
0
        public static int GenerateOpenGLTexture(RenderableTex t, Bitmap bitmap, bool generateMips = false)
        {
            if (!t.GLInitialized)
            {
                return(-1);
            }

            int texID = GL.GenTexture();

            GL.BindTexture(t.TextureTarget, texID);

            BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                              ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            bitmap.UnlockBits(data);

            if (generateMips)
            {
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            }

            return(texID);
        }
コード例 #3
0
        public STGenericTexture()
        {
            RenderableTex = new RenderableTex();
            RenderableTex.GLInitialized = false;

            RedChannel        = STChannelType.Red;
            GreenChannel      = STChannelType.Green;
            BlueChannel       = STChannelType.Blue;
            AlphaChannel      = STChannelType.Alpha;
            DisplayProperties = new DefaultTextureProperties(this);
        }
コード例 #4
0
        public static unsafe Bitmap GLTextureToBitmap(RenderableTex t)
        {
            Bitmap bitmap = new Bitmap(t.width, t.height);

            System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, t.width, t.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GL.BindTexture(TextureTarget.Texture2D, t.TexID);
            GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);

            bitmap.UnlockBits(bitmapData);
            return(bitmap);
        }
コード例 #5
0
        public void LoadOpenGLTexture()
        {
            if (!Runtime.UseOpenGL)
            {
                return;
            }

            if (RenderableTex == null)
            {
                RenderableTex = new RenderableTex();
            }

            RenderableTex.GLInitialized = false;
            RenderableTex.LoadOpenGLTexture(this);
        }
コード例 #6
0
        public static RenderableTex FromBitmap(Bitmap bitmap)
        {
            RenderableTex tex = new RenderableTex();

            tex.TextureTarget       = TextureTarget.Texture2D;
            tex.TextureWrapS        = TextureWrapMode.Repeat;
            tex.TextureWrapT        = TextureWrapMode.Repeat;
            tex.TextureMinFilter    = TextureMinFilter.Linear;
            tex.TextureMagFilter    = TextureMagFilter.Linear;
            tex.width               = bitmap.Width;
            tex.height              = bitmap.Height;
            tex.pixelInternalFormat = PixelInternalFormat.Rgb8;
            tex.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
            tex.GLInitialized       = true;
            tex.TexID               = GenerateOpenGLTexture(tex, bitmap);
            return(tex);
        }
コード例 #7
0
        public static int GenerateOpenGLTexture(RenderableTex t, List <STGenericTexture.Surface> ImageData)
        {
            if (!t.GLInitialized)
            {
                return(-1);
            }

            int texID = GL.GenTexture();

            GL.BindTexture(t.TextureTarget, texID);
            if (t.IsCubeMap)
            {
                if (t.pixelInternalFormat != PixelInternalFormat.Rgba)
                {
                    for (int mipLevel = 0; mipLevel < ImageData[0].mipmaps.Count; mipLevel++)
                    {
                        int width  = Math.Max(1, t.width >> mipLevel);
                        int height = Math.Max(1, t.height >> mipLevel);

                        for (int i = 0; i < 6; i++)
                        {
                            t.LoadCompressedMips(TextureTarget.TextureCubeMapPositiveX + i, ImageData[i], width, height, mipLevel);
                        }

                        break;
                    }
                }
                else
                {
                    for (int mipLevel = 0; mipLevel < ImageData[0].mipmaps.Count; mipLevel++)
                    {
                        int width  = Math.Max(1, t.width >> mipLevel);
                        int height = Math.Max(1, t.height >> mipLevel);

                        for (int i = 0; i < 6; i++)
                        {
                            t.LoadUncompressedMips(TextureTarget.TextureCubeMapPositiveX + i, ImageData[i], width, height, mipLevel);
                        }

                        break;
                    }
                }

                GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
                //   if (ImageData[0].mipmaps.Count == 1)
            }
            else
            {
                if (t.pixelInternalFormat != PixelInternalFormat.Rgba)
                {
                    for (int mipLevel = 0; mipLevel < ImageData[0].mipmaps.Count; mipLevel++)
                    {
                        t.LoadCompressedMips(t.TextureTarget, ImageData[0], t.width, t.height, mipLevel);
                    }
                }
                else
                {
                    for (int mipLevel = 0; mipLevel < ImageData[0].mipmaps.Count; mipLevel++)
                    {
                        t.LoadUncompressedMips(t.TextureTarget, ImageData[0], t.width, t.height, mipLevel);
                    }
                }

                if (ImageData[0].mipmaps.Count == 1)
                {
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                }
            }

            return(texID);
        }