hi everyone! i'm having some issues while double buffering in A5.
this my code:
...where ScreenBuffer is an array where i'm storing color information encoded in long format (e.g.: 0xFFFFFF is white).
as you can see, what i'm doing is to draw in a buffered bitmap some pixels with a specific color, then set the screen's back buffer as the target bitmap to show those pixels on the screen, and then update the display screen. but the problem is that nothing comes up to the screen.
on the other hand, i can do that like this:
this last piece of code works fine, but the problem is that is very slow, since the display isn't double buffered.
any hints on how can i solve this problem? thank you all in advance!
]]>It already is double buffered.
You just need to lock the bitmap with al_lock_bitmap() to gain speed.
]]>thanks for your fast reply!
i've gained some speed, but still is pretty slow...
am i doing something wrong?
]]>You don't need that DoubleBuffer. You already have a double buffer by virtue of creating a display.
Furthermore, you definitely do not want to be creating a bitmap on every frame.
]]>Also, unless your ScreenBuffer array changes, you should draw it into a bitmap once, and then draw that bitmap instead of using al_put_pixel. And even if it does change, you may still want to have the results buffered in a bitmap, and only draw to it the parts that have changed.
]]>tried that already, but it's still VERY slow...
obviously there's something that i'm missing here...
]]>See my edit in my previous post.
]]>Also, unless your ScreenBuffer array changes, you should draw it into a bitmap once, and then draw that bitmap instead of using al_put_pixel. And even if it does change, you may still want to have the results buffered in a bitmap, and only draw to it the parts that have changed.
i can't do that, since what i'm developing is a NES emulator, so i can't know when the screen objects changes.
]]>How do you create ScreenBuffer? Is there a reason you cannot use a bitmap directly? (Edit: You probably cannot, depends on what techniques you are using to keep ScreenBuffer updated.)
You can also lock bitmaps this way:
Untested.
You are storing your ScreenBuffer as [x][y], but you should store it [y][x] for fastest access.
]]>despite i'm rendering 256*240 = 61440 pixels, which is a lot, i've never had speed issues with A4, but now i need A5 because i've to render 2 separate windows.
ScreenBuffer is just an array of long values:
long ScreenBuffer[256][240];
...wich i'm filling with some of these values:
]]>
ScreenBuffer is just an array of long values:
Right ... switch to be [y][x] (an array of horizontal lines) and try my memcpy code.
(And if you don't want to change your code a lot to test that out, simply pretend the display is 240x256 and draw it sideways.)
]]>i swapped Xs and Ys and got more speed. thanks a lot for that!
but your code have a casting error on this line:
data = lock->data;
"invalid conversion from 'void *' to 'uint8_t *'". i've tried to change the line to:
data = (void *)lock->data;
..and to:
data = (uint8_t *)lock->data;
...but then nothing comes up to the screen. any hints?
]]>"invalid conversion from 'void *' to 'uint8_t *'". i've tried to change the line to:
With C++ you need to cast it to uint8_t * yourself. Does this make any difference?
memcpy(data, ScreenBuffer + y, row_size);
Hmm, maybe it's picking up 0 for the alpha. Try using these as your colors: 0xFF757575... note the 0xff for alpha.
Or maybe use this format:
ALLEGRO_PIXEL_FORMAT_XRGB_8888
Not sure, but maybe the X means no alpha.
]]>added the "0xFF" prefix to all of the color codes and nothing.
your routine is much more faster than a simple lock/draw/unlock, but i'm still stucked with this speed issue
I still think you can do this:
ALLEGRO_BITMAP *ScreenBuffer = al_create_bitmap(256, 240);
And draw to it directly. Then use al_draw_bitmap() once per frame.
You can try out some of the techniques on this thread as opposed to using al_put_pixel() on it.
]]>ok, now i have speed ^^
but now i have another problem (no joke! please don't hit me :S). the image i'm getting is just 256*250 pixels. how can i enlarge it to a 512*480 pixels? i have the same old speed issues while using al_draw_scaled_bitmap(). there's another memcpy() routine out there that allows me to do that?
by the way, ALLEGRO_PIXEL_FORMAT_ARGB_8888 gave me the best performance
]]>With Windows (Direct3D) this might do the trick:
d = al_create_display(256, 240); al_resize_display(d, 512, 480);
If you don't acknowledge the resize event, the backbuffer stays the original size. I'd be interested to know if that works.
Otherwise... what did you end up doing? Did you convert ScreenBuffer to an ALLEGRO_BITMAP? How are you drawing to it?
]]>just build the app as a GUI app. you have to see it! it just flyes
thanks for your replies!
]]>If you don't acknowledge the resize event, the backbuffer stays the original size. I'd be interested to know if that works.
Oh god. What are you teaching people here
]]>