OpenGL ES 2.0 blitFromMemory possible bug

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Hi everyone!

I'm getting a terrible headache while trying to blit from memory an OpenGL ES 2.0 texture.

I've looked at the code, and i see that either i create the texture with R8G8B8 or B8G8R8, the GLES2 native format remains to GL_RGB.

Ok, so, i'm setting my texture to R8G8B8 and my pixel box to R8G8B8, same format, both on RGB, so not format conversions expected, but when running the code, i see that the program is going into this piece of code:

Code: Select all

else
        {
            allocateBuffer();
            scaled = src;

            if (src.format == PF_R8G8B8)
            {
                scaled.format = PF_B8G8R8;
                PixelUtil::bulkPixelConversion(src, scaled);
            }
        }
So i think: "hey men, if my texture is R8G8B8 with GL format set to GL_RGB, why is making a pixels conversion to BGR? :shock: . The result is that my image has the R and B channels changed, and a performance problem... (instruments says that the conversion takes 25-30% of frame time).

Ok, so i think, lets set the pixel buffer to PF_B8G8R8, but if i do this, the program now goes from this piece of code:

Code: Select all

   else if ((src.format != mFormat) ||
                 ((GLES2PixelUtil::getGLOriginFormat(src.format) == 0) && (src.format != PF_R8G8B8)))
        {
            // Extents match, but format is not accepted as valid source format for GL
            // do conversion in temporary buffer
            allocateBuffer();
            scaled = mBuffer.getSubVolume(dstBox);
            PixelUtil::bulkPixelConversion(src, scaled);
            
            if(mFormat == PF_A4R4G4B4)
            {
                // ARGB->BGRA
                GLES2PixelUtil::convertToGLformat(scaled, scaled);
            }
        }
Different formats (texture R8G8B8 and pixel box B8G8R8), means pixel conversion again...

The last try, if I set the texture format to B8G8R8 to match pixel box, in the texture creation process, GL creates again a GL_RGB texture, so the format is set again to R8G8B8 and we go again to the code before...

Any ideas? i think that the first case is the right one, but i think that the condition to make the conversion is wrong... if the GL texture is always GL_RGB, i think that the condition must be:

Code: Select all

else
        {
            allocateBuffer();
            scaled = src;

            if (src.format == PF_B8G8R8)
            {
                scaled.format = PF_R8G8B8;
                PixelUtil::bulkPixelConversion(src, scaled);
            }
        }
With this change, my problems go away! :D

Thanks in advance!
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Thanks for bringing this up. I have a patch for you to test out and see if it improves the situation.
You do not have the required permissions to view the files attached to this post.
Last edited by masterfalcon on Sat Apr 14, 2012 5:30 am, edited 1 time in total.
Reason: Fixed shadow crash and cleaned up patch
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Any luck with that patch?
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

masterfalcon wrote:Any luck with that patch?
Sorry masterfalcon, i hadn't time to test it, i'll try to test it tomorrow :)
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Sounds great, I've got yet another patch to go with it as well. Let me know how it goes.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

It seems that i haven't the correct version to apply the patch :(

I'll try to get a fresh trunk checkout tomorrow...
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Any luck?
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Unfortunately, at this moment, this project task has been marked as finished :( , and i haven't a mac in my home to test it.

But don't worry, i'll try to test the patch in some coffee-break... :wink:

BTW, what is the revision which you use for the patch?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

I don't recall exactly but it should apply cleanly against the latest.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Uhm, i'm getting errors while compiling current trunk.

First, XCode says for all targets: "cc1plus: error: unrecognized command line option "-Wno-unused-but-set-parameter""
Second, its complaining about extra commas in a bunch of files, since it has never complained about that. :|
Third, i see that the compiler is set at LLVM 1.7, is this right?
Fourth, altough visibility flags seems to be right in the CMake, all targets has "Symbols hidden by default" unchecked.

Using XCode 3.2.6 and GCC 4.2

Really strange :|
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Hmm, you could try setting gcc as the compiler for all targets. Could be that that options wasn't supported with LLVM 1.7. Another option would be upgrading to Xcode 4.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

I'm still here :P , i've requested the update to XCode 4, but we must update the OSX, so it will take a while...
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Patch applied at last! same problem.

Texture and pixel box created with pixel format PF_R8G8B8. But the render system performs a pixel bulk conversion from R8G8B8 to B8G8R8 :(

Here is the piece of code where is the problem:

OgreGLES2HardwarePixelBuffer.cpp:152

Code: Select all

else
        {
            allocateBuffer();
            scaled = src;

           if (src.format == PF_R8G8B8)
            {
                scaled.format = PF_B8G8R8;
                PixelUtil::bulkPixelConversion(src, scaled);
            }
        }
If the texture has been created with GL_RGB format, what is making a conversion to B8G8R8? whats the point for making this PF_R8G8B8 check? (what happens if instead of having a GL_RGB texture i've another one?)

Cheers! :D
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Does it work as expected if that if block is removed? I probably just missed it.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

masterfalcon wrote:Does it work as expected if that if block is removed? I probably just missed it.
Yes, removing:

Code: Select all

 if (src.format == PF_R8G8B8)
            {
                scaled.format = PF_B8G8R8;
                PixelUtil::bulkPixelConversion(src, scaled);
            }
Solves the problem :wink:
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Oh ok, good. How is performance with all of that taken care of? Better than before I hope.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

masterfalcon wrote:Oh ok, good. How is performance with all of that taken care of? Better than before I hope.
In our 3GS, the bulkPixelConversion takes around 60% of processing time :lol: , now its taking 0 :mrgreen:
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

Excellent! I have a little more cleanup and more floating point format support to do before I commit this for 1.8.1.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by masterfalcon »

I do have one quick question for you. Colors are correct for you, right? I'm tracking a R/B swap bug. I think it's freeimage but I haven't tried manual textures yet.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Yes, colors are correct for me. Or at least i think that. BTW textures loaded with FreeImage looks right.
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Re: OpenGL ES 2.0 blitFromMemory possible bug

Post by Brocan »

Ok, i've discovered what is this code for, without:

Code: Select all

 if (src.format == PF_R8G8B8)
            {
                scaled.format = PF_B8G8R8;
                PixelUtil::bulkPixelConversion(src, scaled);
            }
the RGB textures are show with B and R channels swapped. The RGBA textures works well.

So, i'll start again to solve the problem described in the first post using another way :?

Edit: Ok! it seems that 1.8.1 has solved that problem, now if I set pixel box and texture as PF_B8G8R8, the camera texture shows in the right way! :D :D . Thanks to masterfalcon for your awesome work!