This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion
Parents
  • Note: This was originally posted on 22nd March 2013 at http://forums.arm.com

    After hearing what you said about switching entirely to openGL ES 3.0, probably does not sound like a good alternative due to the fact that you reminded me that very limited devices right now are on that openGL ES 3.0. In fact, it may be more interesting and educational to see how the alpha channel is applied to textures that are not meant for it, so I'm sticking to openGL ES 2.0 for now.As far as the errors are concerned, as you may have remembered from my original post that I was having both problems in non stopping loop in LogCat:1) Unable to read PKM file header 2) Not a PKM file.  For error 1 I've found out that if I had reading problems from the InputStream as you suggested I would only have this error.  I actually solved this error by changing the size of the array buffer as follows:  byte[] buf = new byte[4096];

    to

    byte[] buf = new byte[ETC1.ETC_PKM_HEADER_SIZE];

    I guess I had 4096 as an array size because I was following an example online and that's what they had in that example, which I never understood why. It makes more sense to have the ETC1.ETC_PKM_HEADER_SIZE as the buffer size because you're trying to put in the whole header (16 bytes) into the buffer, so you need to make sure you have enough space. The second error after some clever searching, reading pointer pop up tips at the part of the code that involves that error lead me to a clue. When I pointed to " if (!ETC1.isValid(headerBuffer)) " line of the code, the pop up tip told me that this line checks to see if the headerBuffer is properly. This gave me a hint to include ETC1.formatHeader (headerBuffer, width, height) in my code to properly format the header, and this is why I've been getting that error. Although I've solved both errors and made much progress working through my problems, I'm still having to deal with the problem of not being able to see anything on my screen and giving the black screen.  I'll keep you posted if I see some new progress.  Thanks

    Hi Irfan,

    I didn't spot you posted about the same issue twice - I've merged the threads and deleted the duplicate post without the code.

    You are right that the ETC1 format used by OpenGL ES 2.0 doesn't contain an alpha channel, but plenty of OpenGL ES 2.0 games and examples manage translucent water effects, so you don't need to move to OpenGL ES 3.0 just for that reason. Since there are not many commercial devices supporting OpenGL ES 3.0 yet perhaps aim to do the effect under OpenGL ES 2.0 to maximise the target market?

    There are a few ways to use both ETC1 and have an alpha channel, essentially it comes down to 2 choices.

    1) you could double the height of the texture, and keep only RGB color data in the top half, and put the alpha channel in the bottom half in grayscale. Then, your fragment shader changes to sample the top half of the texture to get the color data and samples the same texel in the bottom half to read the alpha value.

    2) you could have 2 ETC1 textures, one holding color data and one holding alpha data coded as grayscale. You sample both textures in your fragment shader to form the complete RGBA texture data.

    We have some sample code and a document that goes into more depth on these techniques here:

    http://malideveloper...alpha-channels/

    From the code posted, it looks like if you see the message "Unable to read PKM file header" then the code wasn't able to read even the ETC1 header bytes. Could it be a problem with the InputStream itself? You could try changing the code to print how many bytes were able to be read (we only know it's not the number that are in an ETC1 header). If for instance it comes back zero then something has gone wrong trying to read the stream at all. If it reads some but not enough for an ETC1 header then perhaps the file has become corrupt and truncated somehow.

    HTH, Pete
Reply
  • Note: This was originally posted on 22nd March 2013 at http://forums.arm.com

    After hearing what you said about switching entirely to openGL ES 3.0, probably does not sound like a good alternative due to the fact that you reminded me that very limited devices right now are on that openGL ES 3.0. In fact, it may be more interesting and educational to see how the alpha channel is applied to textures that are not meant for it, so I'm sticking to openGL ES 2.0 for now.As far as the errors are concerned, as you may have remembered from my original post that I was having both problems in non stopping loop in LogCat:1) Unable to read PKM file header 2) Not a PKM file.  For error 1 I've found out that if I had reading problems from the InputStream as you suggested I would only have this error.  I actually solved this error by changing the size of the array buffer as follows:  byte[] buf = new byte[4096];

    to

    byte[] buf = new byte[ETC1.ETC_PKM_HEADER_SIZE];

    I guess I had 4096 as an array size because I was following an example online and that's what they had in that example, which I never understood why. It makes more sense to have the ETC1.ETC_PKM_HEADER_SIZE as the buffer size because you're trying to put in the whole header (16 bytes) into the buffer, so you need to make sure you have enough space. The second error after some clever searching, reading pointer pop up tips at the part of the code that involves that error lead me to a clue. When I pointed to " if (!ETC1.isValid(headerBuffer)) " line of the code, the pop up tip told me that this line checks to see if the headerBuffer is properly. This gave me a hint to include ETC1.formatHeader (headerBuffer, width, height) in my code to properly format the header, and this is why I've been getting that error. Although I've solved both errors and made much progress working through my problems, I'm still having to deal with the problem of not being able to see anything on my screen and giving the black screen.  I'll keep you posted if I see some new progress.  Thanks

    Hi Irfan,

    I didn't spot you posted about the same issue twice - I've merged the threads and deleted the duplicate post without the code.

    You are right that the ETC1 format used by OpenGL ES 2.0 doesn't contain an alpha channel, but plenty of OpenGL ES 2.0 games and examples manage translucent water effects, so you don't need to move to OpenGL ES 3.0 just for that reason. Since there are not many commercial devices supporting OpenGL ES 3.0 yet perhaps aim to do the effect under OpenGL ES 2.0 to maximise the target market?

    There are a few ways to use both ETC1 and have an alpha channel, essentially it comes down to 2 choices.

    1) you could double the height of the texture, and keep only RGB color data in the top half, and put the alpha channel in the bottom half in grayscale. Then, your fragment shader changes to sample the top half of the texture to get the color data and samples the same texel in the bottom half to read the alpha value.

    2) you could have 2 ETC1 textures, one holding color data and one holding alpha data coded as grayscale. You sample both textures in your fragment shader to form the complete RGBA texture data.

    We have some sample code and a document that goes into more depth on these techniques here:

    http://malideveloper...alpha-channels/

    From the code posted, it looks like if you see the message "Unable to read PKM file header" then the code wasn't able to read even the ETC1 header bytes. Could it be a problem with the InputStream itself? You could try changing the code to print how many bytes were able to be read (we only know it's not the number that are in an ETC1 header). If for instance it comes back zero then something has gone wrong trying to read the stream at all. If it reads some but not enough for an ETC1 header then perhaps the file has become corrupt and truncated somehow.

    HTH, Pete
Children
No data