Game running well with 2.1 but lots of issues with 2.5 and 3d branch

Topics: iOS
Jul 14, 2012 at 6:01 PM

Hello, 

I tried to port my game from WP7 to IOS using MonoGame, got lots of issues with 2.5.1 version connected with GetData method of Texture2D and threaded resource loading.

I then tried to use the latest 3d branch to see small improvements. GetData issue is still present and spritefonts are not displayed anymore.

In the end I tried the 2.1 version and now the game is running well with no change at all.

I've put more details and screenshots about the issues I encountered with the different versions of MonoGame I tried on my blog (http://xeno-bits.com/blog/?p=150

So basically should I stick to 2.1 or try to solve the issues with latest versions ? If so which one do you recommend to start with ?

Coordinator
Jul 15, 2012 at 9:30 AM

Hi

Thanks for the feedback, I'm not one of the iOS developers so I cant really comments on what works and doesnt on iOS. I do know that GetData does not seem to be implemented for iOS in the develop3d branch. Its also possible its not there for the 2.5.x releases as that release supported GLES2.0 rather than GLES1.1 .

Threaded loading is another area I'm unsure off, I know on android it was very tricky due to the lack of Shared Context support , but it should work on iOS. I will try to get one of the iOS developers to take a look.

It would be very helpful if you could post some test case sample code so that we can run it and replicate the issues.

Regards

Dean

Jul 15, 2012 at 9:31 PM

Thank you,

I'll try to reproduce the issue with smaller code samples and post them here then.

Jul 16, 2012 at 6:33 PM

I just noticed a similar issue in my game. It's using develop3d and it was fine until I merged recent changes back in. Now I am seeing the custom texture spritefont characters display as white blocks and some of the textures also having alpha issues. Also, it was only the first load of the menu system. In game it was fine, and when I dropped back to the menu system from game, the issue was gone. Guessing it is some sort of blend state initialisation issue.... anyone?

When I get a chance I'll do a binary-search-roll-back of MG and find the point at which it was introduced.

Aranda

Jul 16, 2012 at 6:43 PM

In case someone looks at this before I do, it very much looks like a default blend state has changed. Transparent textures in my menu system are coming out solid, including the sprite font characters (as per xenobits develop3d screenshot). 

Coordinator
Jul 16, 2012 at 10:06 PM

>  spritefonts are not displayed anymore

Note that in the develop3d branch all support for DXT compressed textures on iOS has been removed.  Why?  Because iOS doesn't support them.

This means you *must* use the new MonoGame content processors.  You can no longer just copy the WP7 XNB files across and add them to your iOS project.  See this wiki page for how to setup content building for various MonoGame platforms...

  https://github.com/mono/MonoGame/wiki/MonoGame-Content-Processing

 ... when generating content for iOS.  The new content processors properly create iOS compatible PVR compressed textures.

  - Tom

 

Jul 17, 2012 at 11:00 AM

Note that in the develop3d branch all support for DXT compressed textures on iOS has been removed.

Thanks for the info Tom, but in this case I don't think it's the issue. After my game returns to the menu system, my fonts are displayed correctly (and I think they were processed as Color format). Also, some of the textures have the alpha'd areas displayed as black. Need to do some more testing but perhaps it's NonPremultiplied blend mode.

Jul 18, 2012 at 6:30 PM

I found my particular issue. Turns out I'd been playing with my Developer Options (ICS) and turned on "Force GPU rendering - Use 2D harware acceleration in applications". Seemed harmless enough at the time :P. Sorry for the false lead xenobits, mine was completely unrelated to yours! Did you ever reproduce it in a small project?

Aranda

Jul 18, 2012 at 7:38 PM

I was able to reproduce the issue of black boxes on a small project using 2.5, now I need a bit more time as I'm trying to have some sprite properly displayed at the samte time, as I have in my game currently.

I'll then try to find out what are the differences between working and not working assets (it does not seem to be a matter of power of 2 dimensions at least).

I'll come back here with more details as soon as I'll have the time to complete more experiments.

Jul 22, 2012 at 10:40 AM

After getting time to investigate a bit more on the issues, here are some code samples used to reproduce it

Using Monogame 2.5.1

If I try to load a texture from a separate thread the texture will be rendered as a black shape, even if its dimension are power of 2 (I tried with a 50x60 (sprite1) and 128x128 (sprite2) png images)

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
          
            ThreadPool.QueueUserWorkItem(new WaitCallback(InitGameRes)); 
        }

        private void InitGameRes(object State)
        {
            m_sprite = Content.Load<Texture2D>("sprite1");
            m_sprite2 = Content.Load<Texture2D>("sprite2");
          
            m_resLoaded = true;
        }
       
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            spriteBatch.Begin();
            if (m_resLoaded)
            {
                spriteBatch.Draw(m_sprite, Vector2.Zero, Color.White);
                spriteBatch.Draw(m_sprite2, Vector2.Zero, Color.White);

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

Also if I try to get the texture2D data within the dedicated thread (see modified InitGameRes method below), the game will crash while trying to get data, I was able to reproduce it with the both GetData method I'm using in my game.

        private void InitGameRes(object State)
        {
            m_sprite = Content.Load<Texture2D>("sprite1");
            m_sprite2 = Content.Load<Texture2D>("sprite2");


            Color[] l_color = new Color[m_sprite2.Width * m_sprite2.Height];
            m_sprite.GetData(l_color);

            Color[] l_color2 = new Color[20 * 20];
            m_sprite.GetData<Color>(0, new Rectangle(0, 0, 20, 20), l_color2, 0, 20 * 20);

            m_resLoaded = true;
        }

In both case everything is working fine without the threaded loading (getdata is still not working in my game even outside the thread, I'll investigate more on this on my side), do you recommend maybe an other way to manage threaded assets loading ?

Developer
Dec 17, 2012 at 8:29 PM

+1 for me here. I just got our latest game on iOS using MonoGame 3D and when I try to "GetData<Color>" it throws "NotImplementedException".

Did I see someone had offered a PR for GetData<Color> recently ?? Was that for another platform other than iOS?

Coordinator
Dec 17, 2012 at 10:34 PM
There is an inefficient work-around implemented for Android in Texture2D, but it is definitely not recommended for anything performance sensitive (sets the texture as a render target, binds it, uses glReadPixels, then undoes the render target binding). OpenGL ES 2.0 just doesn't offer any API to retrieve texture pixel data.