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

GraphicsDevice.Texture[] on Zune?

Last post 5/16/2008 7:15 AM by Gunston. 17 replies.
  • 5/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
  • 5/15/2008 3:01 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Doh, answered to fast. nevermind this.
  • 5/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
  • 5/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.
  • 5/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
  • 5/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.

  • 5/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)
  • 5/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
  • 5/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...
  • 5/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
  • 5/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?
  • 5/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.
  • 5/15/2008 3:42 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Try running it on the PC, There apparantly are differences between the two in how they function. I am currently testing on PC since my zune is at home.
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 5/15/2008 3:53 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Yeah, I'm seeing that now too. Even with my example from above just using a Texture2D I can get the InvalidOperationException on the PC but it is working fine on the Zune, if I try to update the Texture after I have rendered it using a SpriteBatch. I wonder if it fails on the Xbox too.
  • 5/15/2008 4:11 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    It will fail on Xbox I'm guessing. The reason it probably doesn't on Zune is because the Zune doesn't have a GPU or video memory. So there is no device taking ownership of that data. Just a guess, but it makes sense.
  • 5/15/2008 7:14 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    //Member variables
    Texture2D dummyTex;

    //LoadContent Method
    dummyTex = new Texture2D(graphics.GraphicsDevice, 1, 1);

    //Draw Method
    spriteBatch.Begin();
    spriteBatch.Draw(dummyTex, Vector2.Zero, Color.White);
    spriteBatch.End();

    // Update the texture here...
    myFavouriteTexture.SetData<xxxx>(...); // No longer set on the device!

     

     

     

  • 5/15/2008 8:35 PM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Thanks AJ, that's what we'll need to resort to for now. Next up: getting my Zune un-bricked :)
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 5/16/2008 7:15 AM In reply to

    Re: GraphicsDevice.Texture[] on Zune?

    Ziggy

    Did XNA brick your Zune?!  Anyone else had this experience...?!  I just ordered an 8GB Zune to play with (I'm in the UK).  Just occurred to me that there might be warranty issues running XNA on the Zune and bricking it.  Is this even possible?  Is this a non-issue?

    Anyway, I'd appreciate a comment from someone in the Microsoft XNA team.

    EDIT: See discussion here http://forums.xna.com/thread/62088.aspx.

    Thanks.

    - Gunston

Page 1 of 1 (18 items) Previous Next