mikeyoung
Posts: 34
Joined: Fri Jul 04, 2014 3:05 am
Location: Melbourne Australia

Cant render large bitmap

Thu Oct 22, 2015 12:46 am

Hi

I have a small test application written in Qt5.5 using the QOpenGLWidget. It simply loads in bitmap images and displays them as a texture.
I'm completely new to all this and after a week of very very slow progress, I now have this working.
I developed the code on a desktop Ubuntu machine and all is OK.
When I deployed the application to RPi (v2), The first bitmap is displayed properly but then subsequent bitmaps are just black.
I played around with this, going back and fro from using the dev PC and Rpi and discovered that if the bitmaps are small (768x576) then the RPi is happy and will load and display images at 4 images per second with no problems. However, when the bitmaps get up to 1024 x 768 only some of the images load and display. As I increase the bitmap to 1280x960 only the very first image loads and displays then all subsequent images show a black screen. This happens even if i load and display each image manual on a click of a button (ie its not a problem with speed)
I even tried loading 3 images as QImages at startup and then just creating textures from them, but have the same results.

Since this all works fine on the desktop PC, I'm thinking it has to be a problem with some settings on the RPi. I've tried increasing the framebuffer size in config.txt, but thats all I know how to do.

Any pointers would be very greatly appreciated.

Mike

User avatar
Paeryn
Posts: 2952
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Cant render large bitmap

Thu Oct 22, 2015 5:28 pm

You've probably ran out of memory for the textures. After you load each texture with glTexImage2D() check if GL has flagged an error

Code: Select all

  GLenum err;

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1280, 960, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data); // Load your texture
  err = glGetError();
  if (err == GL_OUT_OF_MEMORY) {
    puts("Ran out of memory allocating texture!"); // You ran out of memory
  };
You said you increased the framebuffer size in config.txt - that won't make much difference to how much memory is available for storing textures, if you are running out of memory then you probably need to increase the GPU/ARM memory split with GPU_MEM=512 (change the value depending on what model you have and how much you want to give to the GPU, 944 is the max for RPi2, it defaults to 64 I think).
She who travels light — forgot something.

mikeyoung
Posts: 34
Joined: Fri Jul 04, 2014 3:05 am
Location: Melbourne Australia

Re: Cant render large bitmap

Thu Oct 22, 2015 11:52 pm

Thank Paeryn for your answer.

You are spot on with your diagnosis.

By the time I got back to this message I had found the problem. I am frequently updating the texture. I do this by using "delete imageTexture" before creating a new texture with the latest image from my camera. I discovered that my very first texture, being loaded by default when the widget is created was not being deleted. When I deleted this initial texture, before loading another image it all worked correctly.

Later in the day I needed to display two OpenGLWidgets and 2 textures simultaneously side by side. When i did the the same problem occurred again - black screen. At this point I researched about the GPU ram and increased it from the default 64MB to 128MB. That solved the problem.

Don't understand why 64MB could not handle two 3.68MByte textures, but then it does not matter to me now - its all working

User avatar
Paeryn
Posts: 2952
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Cant render large bitmap

Fri Oct 23, 2015 2:00 am

Just because you've deleted a texture doesn't mean that openGL has released the memory for it, it may still have an internal pointer to it that is live and so keeps it in memory until it's safe to discard it.

The GPU needs a fair bit of memory :-
The GPU runs it's own OS so it needs space for all it's code and data (it's more than just a GPU),
You have a full-screen framebuffer,
With a full-screen openGL layer you need space for 3 more full-screens (I'm sure the RPi defaults to triple-buffering, if not then 2 for double-buffering), plus space for all the openGL state,
What memory it has available may become fragmented, if there isn't a contiguous block of memory large enough for the texture then it will fail even if the total free memory is large enough (I doubt that the VC4 implements MMUs on it's texture units).
Probably other things eat up memory too ...
She who travels light — forgot something.

Return to “OpenGLES”