Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture2D.GetData buggy for DXT textures #4276

Closed
Skeatwin opened this issue Nov 30, 2015 · 3 comments · Fixed by #5121
Closed

Texture2D.GetData buggy for DXT textures #4276

Skeatwin opened this issue Nov 30, 2015 · 3 comments · Fixed by #5121

Comments

@Skeatwin
Copy link

I use MonoGame 3.4 on Windows (Windows DirectX project) with Visual Studio 2015.
I have this texture into DXT1 format:
t

When I use this code:

        Texture2D texture;
        SpriteBatch spriteBatch;

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load Dxt1 texture (256x256).
            texture = Content.Load<Texture2D>("t");
            byte[] data = new byte[texture.Width * texture.Height / 2]; // Dxt1 correct data size
            texture.GetData(data);
            texture.SetData(data); // Now texture is corrupted.
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            spriteBatch.Draw(texture, Vector2.Zero, Color.White);

            spriteBatch.End();
            base.Draw(gameTime);
        }

I get this result:
t2

But, the same code with the texture into Color format (ARGB8) work fine.
I have also tried with DXT3 and DXT5 format and it's the same result as DXT1: texture is corrupted.

A previous issue thread #3590 suggest to change the type of struct to get texture data to avoid troubles, but no changes for DXT textures this time.

@tomspilman
Copy link
Member

Looks like how we're stepping thru the height.

https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Texture2D.DirectX.cs#L168

My guess is that we should be incrementing the row more than we are for DXT surfaces.

@KonajuGames
Copy link
Contributor

KonajuGames commented Dec 1, 2015 via email

@Skeatwin
Copy link
Author

Skeatwin commented Dec 2, 2015

I would like to help you but I don't think I am at the level... (off topic but great works for the 3.5 !)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants