GetGLFormat() static private method

static private GetGLFormat ( this format, GraphicsDevice graphicsDevice, PixelInternalFormat &glInternalFormat, PixelFormat &glFormat, PixelType &glType ) : void
format this
graphicsDevice GraphicsDevice
glInternalFormat PixelInternalFormat
glFormat PixelFormat
glType PixelType
return void
Example #1
0
 internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget)
 {
     if (graphicsDevice == null)
     {
         throw new ArgumentNullException("graphicsDevice");
     }
     this.GraphicsDevice = graphicsDevice;
     this.size           = size;
     this.format         = format;
     this.levelCount     = mipMap ? Texture.CalculateMipLevels(size, 0, 0) : 1;
     this.glTarget       = TextureTarget.TextureCubeMap;
     GL.GenTextures(1, out this.glTexture);
     GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? 9987 : 9729);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, 9729);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, 33071);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, 33071);
     GraphicsExtensions.GetGLFormat(format, out this.glInternalFormat, out this.glFormat, out this.glType);
     for (int index = 0; index < 6; ++index)
     {
         TextureTarget glCubeFace = this.GetGLCubeFace((CubeMapFace)index);
         if (this.glFormat == (PixelFormat)34467)
         {
             throw new NotImplementedException();
         }
         GL.TexImage2D(glCubeFace, 0, this.glInternalFormat, size, size, 0, this.glFormat, this.glType, IntPtr.Zero);
     }
     if (!mipMap)
     {
         return;
     }
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, 1);
 }
Example #2
0
        internal Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format, bool renderTarget)
        {
            Texture2D texture2D = this;

            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("Graphics Device Cannot Be Null");
            }
            this.GraphicsDevice = graphicsDevice;
            this.width          = width;
            this.height         = height;
            this.format         = format;
            this.levelCount     = mipmap ? Texture.CalculateMipLevels(width, height, 0) : 1;
            this.glTarget       = TextureTarget.Texture2D;
            Threading.BlockOnUIThread((Action)(() =>
            {
                int local_0 = GraphicsExtensions.GetBoundTexture2D();
                texture2D.GenerateGLTextureIfRequired();
                GraphicsExtensions.GetGLFormat(format, out texture2D.glInternalFormat, out texture2D.glFormat, out texture2D.glType);
                if (texture2D.glFormat == (OpenTK.Graphics.OpenGL.PixelFormat) 34467)
                {
                    int local_1_1;
                    switch (format)
                    {
                    case SurfaceFormat.Dxt1:
                        local_1_1 = (texture2D.width + 3) / 4 * ((texture2D.height + 3) / 4) * 8;
                        break;

                    case SurfaceFormat.Dxt3:
                    case SurfaceFormat.Dxt5:
                        local_1_1 = (texture2D.width + 3) / 4 * ((texture2D.height + 3) / 4) * 16;
                        break;

                    case SurfaceFormat.RgbPvrtc2Bpp:
                    case SurfaceFormat.RgbaPvrtc2Bpp:
                        local_1_1 = (Math.Max(texture2D.width, 8) * Math.Max(texture2D.height, 8) * 2 + 7) / 8;
                        break;

                    case SurfaceFormat.RgbPvrtc4Bpp:
                    case SurfaceFormat.RgbaPvrtc4Bpp:
                        local_1_1 = (Math.Max(texture2D.width, 16) * Math.Max(texture2D.height, 8) * 4 + 7) / 8;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                    GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, texture2D.glInternalFormat, texture2D.width, texture2D.height, 0, local_1_1, IntPtr.Zero);
                }
                else
                {
                    GL.TexImage2D(TextureTarget.Texture2D, 0, texture2D.glInternalFormat, texture2D.width, texture2D.height, 0, texture2D.glFormat, texture2D.glType, IntPtr.Zero);
                }
                GL.BindTexture(TextureTarget.Texture2D, local_0);
            }));
        }
Example #3
0
 public Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format)
 {
     this.GraphicsDevice = graphicsDevice;
     this.Width          = width;
     this.Height         = height;
     this.Depth          = depth;
     this.glTarget       = TextureTarget.Texture3D;
     GL.GenTextures(1, out this.glTexture);
     GL.BindTexture(this.glTarget, this.glTexture);
     GraphicsExtensions.GetGLFormat(format, out this.glInternalFormat, out this.glFormat, out this.glType);
     GL.TexImage3D(this.glTarget, 0, this.glInternalFormat, width, height, depth, 0, this.glFormat, this.glType, IntPtr.Zero);
     if (mipMap)
     {
         throw new NotImplementedException();
     }
 }
Example #4
0
 public Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format)
 {
     if (graphicsDevice == null)
     {
         throw new ArgumentNullException("graphicsDevice");
     }
     this.GraphicsDevice = graphicsDevice;
     this.width          = width;
     this.height         = height;
     this.depth          = depth;
     this.levelCount     = 1;
     this.glTarget       = TextureTarget.Texture3D;
     GL.GenTextures(1, out this.glTexture);
     GL.BindTexture(this.glTarget, this.glTexture);
     GraphicsExtensions.GetGLFormat(format, out this.glInternalFormat, out this.glFormat, out this.glType);
     GL.TexImage3D(this.glTarget, 0, this.glInternalFormat, width, height, depth, 0, this.glFormat, this.glType, IntPtr.Zero);
     if (mipMap)
     {
         throw new NotImplementedException("Texture3D does not yet support mipmaps.");
     }
 }
Example #5
0
        public TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format)
        {
            this.size       = size;
            this.levelCount = 1;
            this.glTarget   = TextureTarget.TextureCubeMap;
            GL.GenTextures(1, out this.glTexture);
            GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? 9987 : 9729);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, 9729);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, 33071);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, 33071);
            GraphicsExtensions.GetGLFormat(format, out this.glInternalFormat, out this.glFormat, out this.glType);
            for (int index = 0; index < 6; ++index)
            {
                TextureTarget glCubeFace = this.GetGLCubeFace((CubeMapFace)index);
                if (this.glFormat == (PixelFormat)34467)
                {
                    throw new NotImplementedException();
                }
                GL.TexImage2D(glCubeFace, 0, this.glInternalFormat, size, size, 0, this.glFormat, this.glType, IntPtr.Zero);
            }
            if (!mipMap)
            {
                return;
            }
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, 1);
            int num1 = this.size;

            while (num1 > 1)
            {
                num1 /= 2;
                TextureCube textureCube = this;
                int         num2        = textureCube.levelCount + 1;
                textureCube.levelCount = num2;
            }
        }