Microsoft.Xna.Framework.Graphics.GraphicsExtensions.GetGLFormat C# (CSharp) Method

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
		internal static void GetGLFormat (this SurfaceFormat format,
            GraphicsDevice graphicsDevice,
            out PixelInternalFormat glInternalFormat,
            out PixelFormat glFormat,
            out PixelType glType)
		{
			glInternalFormat = PixelInternalFormat.Rgba;
			glFormat = PixelFormat.Rgba;
			glType = PixelType.UnsignedByte;

		    var supportsSRgb = graphicsDevice.GraphicsCapabilities.SupportsSRgb;
			
			switch (format) {
			case SurfaceFormat.Color:
				glInternalFormat = PixelInternalFormat.Rgba;
				glFormat = PixelFormat.Rgba;
				glType = PixelType.UnsignedByte;
				break;
            case SurfaceFormat.ColorSRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Color;
                glInternalFormat = (PixelInternalFormat) 0x8C40; // PixelInternalFormat.Srgb;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.UnsignedByte;
                break;
			case SurfaceFormat.Bgr565:
				glInternalFormat = PixelInternalFormat.Rgb;
				glFormat = PixelFormat.Rgb;
				glType = PixelType.UnsignedShort565;
				break;
			case SurfaceFormat.Bgra4444:
#if IOS || ANDROID
				glInternalFormat = PixelInternalFormat.Rgba;
#else
				glInternalFormat = PixelInternalFormat.Rgba4;
#endif
				glFormat = PixelFormat.Rgba;
				glType = PixelType.UnsignedShort4444;
				break;
			case SurfaceFormat.Bgra5551:
				glInternalFormat = PixelInternalFormat.Rgba;
				glFormat = PixelFormat.Rgba;
				glType = PixelType.UnsignedShort5551;
				break;
			case SurfaceFormat.Alpha8:
				glInternalFormat = PixelInternalFormat.Luminance;
				glFormat = PixelFormat.Luminance;
				glType = PixelType.UnsignedByte;
				break;
#if !IOS && !ANDROID && !ANGLE
			case SurfaceFormat.Dxt1:
				glInternalFormat = PixelInternalFormat.CompressedRgbS3tcDxt1Ext;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt1SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt1;
                glInternalFormat = PixelInternalFormat.CompressedSrgbS3tcDxt1Ext;
                glFormat = (PixelFormat) All.CompressedTextureFormats;
                break;
            case SurfaceFormat.Dxt1a:
                glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
            case SurfaceFormat.Dxt3:
				glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt3SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt3;
                glInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                glFormat = (PixelFormat) All.CompressedTextureFormats;
                break;
			case SurfaceFormat.Dxt5:
				glInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt5SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt5;
                glInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                glFormat = (PixelFormat) All.CompressedTextureFormats;
                break;
			
			case SurfaceFormat.Single:
				glInternalFormat = PixelInternalFormat.R32f;
				glFormat = PixelFormat.Red;
				glType = PixelType.Float;
				break;

            case SurfaceFormat.HalfVector2:
                glInternalFormat = PixelInternalFormat.Rg16f;
				glFormat = PixelFormat.Rg;
				glType = PixelType.HalfFloat;
                break;

            // HdrBlendable implemented as HalfVector4 (see http://blogs.msdn.com/b/shawnhar/archive/2010/07/09/surfaceformat-hdrblendable.aspx)
            case SurfaceFormat.HdrBlendable:
            case SurfaceFormat.HalfVector4:
                glInternalFormat = PixelInternalFormat.Rgba16f;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.HalfFloat;
                break;

            case SurfaceFormat.HalfSingle:
                glInternalFormat = PixelInternalFormat.R16f;
                glFormat = PixelFormat.Red;
                glType = PixelType.HalfFloat;
                break;

            case SurfaceFormat.Vector2:
                glInternalFormat = PixelInternalFormat.Rg32f;
                glFormat = PixelFormat.Rg;
                glType = PixelType.Float;
                break;

            case SurfaceFormat.Vector4:
                glInternalFormat = PixelInternalFormat.Rgba32f;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.Float;
                break;

            case SurfaceFormat.NormalizedByte2:
                glInternalFormat = PixelInternalFormat.Rg8i;
                glFormat = PixelFormat.Rg;
                glType = PixelType.Byte;
                break;

            case SurfaceFormat.NormalizedByte4:
                glInternalFormat = PixelInternalFormat.Rgba8i;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.Byte;
                break;

            case SurfaceFormat.Rg32:
                glInternalFormat = PixelInternalFormat.Rg16ui;
                glFormat = PixelFormat.Rg;
                glType = PixelType.UnsignedShort;
                break;

            case SurfaceFormat.Rgba64:
                glInternalFormat = PixelInternalFormat.Rgba16ui;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.UnsignedShort;
                break;

            case SurfaceFormat.Rgba1010102:
                glInternalFormat = PixelInternalFormat.Rgb10A2ui;
                glFormat = PixelFormat.Rgba;
                glType = PixelType.UnsignedInt1010102;
                break;
#endif
				
#if ANDROID
			case SurfaceFormat.Dxt1:
                // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha)
                // XNA uses the RGB version.
                glInternalFormat = (PixelInternalFormat)0x83F0; 
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt1SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt1;
                glInternalFormat = (PixelInternalFormat)0x8C4C;
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
            case SurfaceFormat.Dxt1a:
                // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha)
                glInternalFormat = (PixelInternalFormat)0x83F1;
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
            case SurfaceFormat.Dxt3:
                glInternalFormat = (PixelInternalFormat)0x83F2;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt3SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt3;
                glInternalFormat = (PixelInternalFormat)0x8C4E;
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
			case SurfaceFormat.Dxt5:
                glInternalFormat = (PixelInternalFormat)0x83F3;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.Dxt5SRgb:
                if (!supportsSRgb)
                    goto case SurfaceFormat.Dxt5;
                glInternalFormat = (PixelInternalFormat)0x8C4F;
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
            case SurfaceFormat.RgbaAtcExplicitAlpha:
				glInternalFormat = (PixelInternalFormat)All.AtcRgbaExplicitAlphaAmd;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.RgbaAtcInterpolatedAlpha:
				glInternalFormat = (PixelInternalFormat)All.AtcRgbaInterpolatedAlphaAmd;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
            case SurfaceFormat.RgbEtc1:
                glInternalFormat = (PixelInternalFormat)0x8D64; // GL_ETC1_RGB8_OES
                glFormat = (PixelFormat)All.CompressedTextureFormats;
                break;
#endif
#if IOS || ANDROID
			case SurfaceFormat.RgbPvrtc2Bpp:
				glInternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc2Bppv1Img;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
			case SurfaceFormat.RgbPvrtc4Bpp:
				glInternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc4Bppv1Img;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
			case SurfaceFormat.RgbaPvrtc2Bpp:
				glInternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc2Bppv1Img;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
			case SurfaceFormat.RgbaPvrtc4Bpp:
				glInternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc4Bppv1Img;
				glFormat = (PixelFormat)All.CompressedTextureFormats;
				break;
#endif
            default:
				throw new NotSupportedException();
			}
		}

Usage Example

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);
 }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.GraphicsExtensions::GetGLFormat