internal XNATextureCubeImplementation(XFG.GraphicsDevice device, int size, bool genMipMaps, SurfaceFormat format)
            : base(size, format)
        {
            _graphicsDevice = device;

            _textureCube = new XFG.TextureCube(device, size, genMipMaps, XNAHelper.ToXNASurfaceFormat(format));
        }
        internal XNATextureCubeImplementation(XFG.GraphicsDevice device, int size, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
            : base(size, format, depthFormat, multiSampleCount, usage)
        {
            _graphicsDevice = device;

            _textureCube = new XFG.RenderTargetCube(device, size, genMipMaps, XNAHelper.ToXNASurfaceFormat(format), XNAHelper.ToXNADepthFormat(depthFormat), multiSampleCount, (XFG.RenderTargetUsage)usage);
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        public static TextureCube DDSFromStreamEXT(
            GraphicsDevice graphicsDevice,
            Stream stream
            )
        {
            TextureCube result;

            // Begin BinaryReader, ignoring a tab!
            using (BinaryReader reader = new BinaryReader(stream))
            {
                int           width, height, levels;
                SurfaceFormat format;
                Texture.ParseDDS(
                    reader,
                    out format,
                    out width,
                    out height,
                    out levels
                    );

                // Allocate/Load texture
                result = new TextureCube(
                    graphicsDevice,
                    width,
                    levels > 1,
                    format
                    );

                byte[] tex = null;
                if (stream is MemoryStream &&
                    ((MemoryStream)stream).TryGetBuffer(out tex))
                {
                    for (int face = 0; face < 6; face += 1)
                    {
                        for (int i = 0; i < levels; i += 1)
                        {
                            int mipLevelSize = Texture.CalculateDDSLevelSize(
                                width >> i,
                                width >> i,
                                format
                                );
                            result.SetData(
                                (CubeMapFace)face,
                                i,
                                null,
                                tex,
                                (int)stream.Seek(0, SeekOrigin.Current),
                                mipLevelSize
                                );
                            stream.Seek(
                                mipLevelSize,
                                SeekOrigin.Current
                                );
                        }
                    }
                }
                else
                {
                    for (int face = 0; face < 6; face += 1)
                    {
                        for (int i = 0; i < levels; i += 1)
                        {
                            tex = reader.ReadBytes(Texture.CalculateDDSLevelSize(
                                                       width >> i,
                                                       width >> i,
                                                       format
                                                       ));
                            result.SetData(
                                (CubeMapFace)face,
                                i,
                                null,
                                tex,
                                0,
                                tex.Length
                                );
                        }
                    }
                }

                // End BinaryReader
            }

            // Finally.
            return(result);
        }
Exemple #5
0
        public static bool TryParse(Stream s, GraphicsDevice g, ContentManager c, out Effect fx, ref List <object> refs, ParsingFlags ps = ParsingFlags.None)
        {
            fx = null;
            StreamReader f = new StreamReader(new BufferedStream(s));

            // Get The Arguments From The Material File
            List <string[]> args = new List <string[]>();

            while (!f.EndOfStream)
            {
                string line = f.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                string[] split = line.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                if (split.Length < 1)
                {
                    continue;
                }
                split[0] = split[0].Trim().ToLower();
                switch (split[0])
                {
                case "fx": if (split.Length >= 2)
                    {
                        args.Add(split);
                    }
                    break;

                case "fxpt": if (split.Length >= 3)
                    {
                        args.Add(split);
                    }
                    break;

                case "fxptc": if (split.Length >= 3)
                    {
                        args.Add(split);
                    }
                    break;

                case "fxpf": if (split.Length >= 4)
                    {
                        args.Add(split);
                    }
                    break;
                }
            }

            // Get The Effect For This Material
            Predicate <string[]> fxMatch = (a) => { return(a[0].Equals("fx")); };

            string[] fxArg = args.Find(fxMatch);
            if (fxArg == null)
            {
                return(false);
            }
            args.RemoveAll(fxMatch);


            // Try To Create The Effect
            if (ps.HasFlag(ParsingFlags.LoadEffectByteCode))
            {
                try {
                    byte[] code = null;
                    using (FileStream fxs = File.OpenRead(fxArg[1].Trim())) {
                        code = new byte[fxs.Length];
                        fxs.Read(code, 0, code.Length);
                    }
                    fx = new Effect(g, code);
                }
                catch (Exception) { fx = null; return(false); }
            }
            else
            {
                try { fx = c.Load <Effect>(fxArg[1].Trim()); }
                catch (Exception) { fx = null; return(false); }
            }

            // Will Attempt To Set As Many Uniforms As Possible Without Raising Errors
            foreach (string[] arg in args)
            {
                switch (arg[0])
                {
                case "fxpt":
                    EffectParameter fxpt = fx.Parameters[arg[1].Trim()];
                    if (fxpt == null)
                    {
                        continue;
                    }
                    try {
                        Texture2D t = null;
                        if (ps.HasFlag(ParsingFlags.LoadTextureStream))
                        {
                            using (FileStream ts = File.OpenRead(arg[2].Trim())) {
                                t = Texture2D.FromStream(g, ts);
                            }
                        }
                        else
                        {
                            t = c.Load <Texture2D>(arg[2].Trim());
                        }
                        if (t != null)
                        {
                            refs.Add(t);
                            fxpt.SetValue(t);
                        }
                    }
                    catch (Exception) { continue; }
                    break;

                case "fxptc":     // Texture Cube Parameter
                    EffectParameter fxptc = fx.Parameters[arg[1].Trim()];
                    if (fxptc == null)
                    {
                        continue;
                    }
                    try {
                        TextureCube tc = c.Load <TextureCube>(arg[2].Trim());
                        if (tc != null)
                        {
                            refs.Add(tc);
                            fxptc.SetValue(tc);
                        }
                    }
                    catch (Exception) { continue; }
                    break;

                case "fxpf":     // Vector Parameter
                    EffectParameter fxptv = fx.Parameters[arg[1].Trim()];
                    int             comps;
                    if (fxptv == null || !int.TryParse(arg[2], out comps))
                    {
                        continue;
                    }
                    string[] sc = arg[3].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (sc.Length != comps)
                    {
                        continue;
                    }
                    switch (comps)
                    {
                    case 1:
                        float v1;
                        if (float.TryParse(sc[0], out v1))
                        {
                            fxptv.SetValue(v1);
                        }
                        break;

                    case 2:
                        Vector2 v2 = Vector2.Zero;
                        if (float.TryParse(sc[0], out v2.X) &&
                            float.TryParse(sc[1], out v2.Y)
                            )
                        {
                            fxptv.SetValue(v2);
                        }
                        break;

                    case 3:
                        Vector3 v3 = Vector3.Zero;
                        if (float.TryParse(sc[0], out v3.X) &&
                            float.TryParse(sc[1], out v3.Y) &&
                            float.TryParse(sc[2], out v3.Z)
                            )
                        {
                            fxptv.SetValue(v3);
                        }
                        break;

                    case 4:
                        Vector4 v4 = Vector4.Zero;
                        if (float.TryParse(sc[0], out v4.X) &&
                            float.TryParse(sc[1], out v4.Y) &&
                            float.TryParse(sc[2], out v4.Z) &&
                            float.TryParse(sc[3], out v4.W)
                            )
                        {
                            fxptv.SetValue(v4);
                        }
                        break;

                    default:
                        if (comps > 4)
                        {
                            float[] vn  = new float[comps];
                            bool    vnc = true;
                            for (int i = 0; i < sc.Length && i < vn.Length && vnc; i++)
                            {
                                if (!float.TryParse(sc[i], out vn[i]))
                                {
                                    vnc = false;
                                }
                            }
                            if (vnc)
                            {
                                fxptv.SetValue(vn);
                            }
                        }
                        break;
                    }
                    break;
                }
            }
            return(true);
        }
Exemple #6
0
		/// <summary>
		///
		/// </summary>
		private void CreateCubeTexture()
		{
			Debug.Assert( SrcWidth > 0 && SrcHeight > 0 );

			// use current back buffer format for render textures, else use the one
			// defined by this texture format
			XFG.SurfaceFormat xnaPixelFormat =
				( Usage == TextureUsage.RenderTarget ) ? _bbPixelFormat : ( (XFG.SurfaceFormat)ChooseXnaFormat() );

			// how many mips to use?  make sure its at least one
			int numMips = ( MipmapCount > 0 ) ? MipmapCount : 1;
            
            //see comment in CreateNormalTexture() -DoubleA

            //MipmapsHardwareGenerated = false;
            //if ( _devCaps.TextureCapabilities.SupportsMipCubeMap )
            //{
            //    MipmapsHardwareGenerated = true /*this.CanAutoGenMipMaps( xnaUsage, XFG.ResourceType.TextureCube, xnaPixelFormat ) */;
            //    if ( MipmapsHardwareGenerated )
            //    {
            //        numMips = 0;
            //    }
            //}
            //else
            //{
            //    // no mip map support for this kind of texture
            //    MipmapCount = 0;
            //    numMips = 1;
            //}

			if ( Usage == TextureUsage.RenderTarget )
			{
                renderTarget = (XFG.Texture)(new XFG.RenderTargetCube(_device, SrcWidth, _mipmapCount > 0 ? true : false, xnaPixelFormat, XFG.DepthFormat.Depth24Stencil8)) as XFG.RenderTarget2D;
				_cubeTexture = ( (XFG.Texture)renderTarget ) as XFG.RenderTargetCube;
                
				CreateDepthStencil();
			}
			else
			{
				// create the cube texture
                _cubeTexture = new XFG.TextureCube(_device, SrcWidth, (_mipmapCount > 0) ? true : false, xnaPixelFormat);
				// store base reference to the texture
			}

			_texture = _cubeTexture;

			SetFinalAttributes( SrcWidth, SrcHeight, 1, XnaHelper.Convert( xnaPixelFormat ) );

			if ( MipmapsHardwareGenerated )
			{
                //Generating mip maps API is no longer exposed. RenderTargets will auto-generate their mipmaps
                //but for other textures you're S.O.L. -DoubleA. See Shawn Hargreaves response to this thread: http://forums.create.msdn.com/forums/p/71559/436835.aspx
				//_texture.GenerateMipMaps( GetBestFilterMethod() );
			}
		}
Exemple #7
0
		/// <summary>
		///
		/// </summary>
		private void LoadCubeTexture()
		{
			Debug.Assert( this.TextureType == TextureType.CubeMap, "this.TextureType == TextureType.CubeMap" );

			if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" )
			{
				AxiomContentManager acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "" );
				_cubeTexture = acm.Load<XFG.TextureCube>( Name );
				_texture = _cubeTexture;
				internalResourcesCreated = true;
			}
#if !( XBOX || XBOX360 )
			else
			{
                /* Use internal .dds loader instead */
                //if ( Name.EndsWith( ".dds" ) )
                //{
                //    Stream stream = ResourceGroupManager.Instance.OpenResource( Name );
                //    _cubeTexture = XFG.TextureCube.FromFile( _device, stream );
                //    stream.Close();
                //}
                //else
				{
					this.ConstructCubeFaceNames( Name );
					// Load from 6 separate files
					// Use Axiom codecs
					List<Image> images = new List<Image>();

					int pos = Name.LastIndexOf( "." );
					string ext = Name.Substring( pos + 1 );

					for ( int i = 0; i < 6; i++ )
					{
						Stream strm = ResourceGroupManager.Instance.OpenResource( cubeFaceNames[ i ], Group, true, this );
						var image = Image.FromStream( strm, ext );
						images.Add( image );
						strm.Close();
					}

					LoadImages( images.ToArray() );
				}
				_texture = _cubeTexture;
				internalResourcesCreated = true;
			}
#endif
		}
Exemple #8
0
		protected override void freeInternalResources()
		{
			if ( this._texture != null )
			{
				this._texture.Dispose();
				this._texture = null;
			}

			if ( this._normTexture != null )
			{
				this._normTexture.Dispose();
				this._normTexture = null;
			}

			if ( this._cubeTexture != null )
			{
				this._cubeTexture.Dispose();
				this._cubeTexture = null;
			}

			if ( this._volumeTexture != null )
			{
				this._volumeTexture.Dispose();
				this._volumeTexture = null;
			}
		}