XNA Creators Club Online
Page 1 of 1 (18 items)
Sort Posts: Previous Next

GraphicsDevice.Texture[] on Zune?

Last post 05-16-2008 7:15 AM by Gunston. 17 replies.
  • 05-15-2008 2:42 PM

    GraphicsDevice.Texture[] on Zune?

    How can i release a texture from the graphics device on the zune? I am unable to 'detatch' a texture from the graphics device after rendering using sprite batch unless i re-create the render target i used:

    http://nopaste.com/p/at07TT0z9

     

    in order to get the texture off the graphics device i have to create a whole new texture. I'd rather not have to create a new render target each frame:

     

    protected override void Draw(GameTime gameTime)
    {
    renderTarget = new RenderTarget2D(GraphicsDevice,
    gfxConfig.BackBufferWidth, gfxConfig.BackBufferHeight, 1, SurfaceFormat.Color);


     

    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 05-15-2008 3:01 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Doh, answered to fast. nevermind this.
  • 05-15-2008 3:05 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    The reason that works for you is because you are also using textures in your game. I am ONLY using one texture (a render target) that I use to render to in software. If i were using another texture the device would unlock my render target texture and everything would be fine.

     

    I need a way to set "GraphicsDevice.Texture[0] = null;" since i only use one texture .

    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 05-15-2008 3:06 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    You have tried calling Dispose() and setting the texture to null I'm assuming but just to make sure.
  • 05-15-2008 3:08 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    I cannot dispose the texture since the device has a reference to it that i am unable to release from the device givent the lack of GraphicsDevice.Texture[]
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 05-15-2008 3:12 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Looking at your code, what your trying to do is draw a texture dynamically and then display that on the GraphicsDevice correct?

    This is how I do that :

        /// <summary>
        /// Base class for dynamically generated backgrounds
        /// </summary>
        class Background : Texture2D
        {
            public Background( GraphicsDevice device, int width, int height )
                : base( device, width, height, 1, TextureUsage.None, SurfaceFormat.Color )
            {
            }
        }

        class GradientBackground : Background
        {
            public GradientBackground( GraphicsDevice graphicsDevice, int width, int height, Color startColor, Color endColor, int steps )
                : base( graphicsDevice, width, height )
            {
                if ( steps > height || steps < 0 )
                    throw new ArgumentOutOfRangeException( "steps", "Must be in the range of [ 0, height ]." );

                Color[] data = new Color[ width * height ];

                int rowsPerStep = width / steps;

                int currentPixel = 0;
                for ( int i = 0; i < steps; i++ )
                {
                    byte red = (byte)( startColor.R + ( endColor.R - startColor.R / steps * i ) );
                    byte green = (byte)( startColor.G + ( endColor.G - startColor.G / steps * i ) );
                    byte blue = (byte)( startColor.B + ( endColor.B - startColor.B / steps * i ) );

                    Color pixelColor = new Color( red, green, blue );

                    for ( int row = 0; row < rowsPerStep; row++ )
                        for ( int pixel = 0; pixel < height; pixel++ )
                        {
                            data[ currentPixel++ ] = pixelColor;
                        }
                }

                SetData( data );
            }
        }

    And if you wanted to update it during you update method you could do that too.

  • 05-15-2008 3:15 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Are you actually using a RenderTarget2D or just a Texture2D? I know in my software renderer attempt I just used a Texture2D and used SpriteBatch to blit the result to the screen. I never had any issues with editing it (on Zune) after that fact. On the PC, however, I did see the same problems you are having. If you want, I've (temporarily) uploaded my project here: http://www.gravelyn.com/temp/Zune3D.zip. (Edit: I should warn everyone that this is ugly code. I was just slamming things together to try and get it working, so I apologize if it doesn't make much sense)

    Nick Gravelyn -- Microsoft XNA MVP
    Blog | XNA Wiki | FX-izer | EasyZip | Current Adventures | Next-Gen
  • 05-15-2008 3:20 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Try creating a new windows 3.0 project and paste my code in there and run it, should draw lines on the screen, now remove the 'new render target 2d' from the beginning of the draw() method and you'll see my problem.
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 05-15-2008 3:21 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Ok, the more I read and answer too quickly, the more I realize I don't understand why you want to remove the texture from the GraphicsDevice?

    Damn, ok trying that now...
  • 05-15-2008 3:23 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Because I am only using one texture and i cannot re-use it until it is released from the device itself. It cannot be destroyed until the device releases it, hence the issue.
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 05-15-2008 3:24 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Yes, on the PC I get the same issue as you do even with my code. On the Zune, though, I don't get that exception. Do you get an exception when running your code on the Zune or just the PC?

    Nick Gravelyn -- Microsoft XNA MVP
    Blog | XNA Wiki | FX-izer | EasyZip | Current Adventures | Next-Gen
  • 05-15-2008 3:37 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    The 'Exception' you are refering to is an OutOfMemoryException? I got that using Ziggy's code with the new RenderTarget in the Draw method, but I don't get any Exceptions if it's commented out. Maybe were are hitting hardware differences? My Zune is an original.

    Edit: Ok , on the PC I get an InvalidOperationException.
  • 05-15-2008 3:42 PM In reply to