theproadam / renderXF

High performance software rendering in c#
MIT License
11 stars 4 forks source link

Blitting into a bitmap is a no-op #3

Closed kf6kjg closed 3 years ago

kf6kjg commented 3 years ago

If you don't get to it first, I probably will.

Method renderX::BlitInto(BitMap, Rectangle) is currently a no-op. This functionality is core to my needs: I do not have a screen or window to draw to, only a bitmap or equivalent.

theproadam commented 3 years ago

@kf6kjg Try using the BitmapUtility.

kf6kjg commented 3 years ago

Ok, that seems to work though with an occasional crash:

            var xbmu = new BitmapUtility(mapbmp.Bitmap);
            GL.Blit();
            xbmu.CopyFrom(GL, 0, 0, mapbmp.Width, mapbmp.Height - 1); // BUG: Leaves black lines on the edges. But if I don't subtract the one pixel I get a crash.  Implies bug in the underlying code.

Should I Blit then CopyFrom as shown or the other way 'round?

theproadam commented 3 years ago

GL.Blit() will only copy the frameBuffers contents onto the form you selected, so it would be logical for first copy the contents of the bitmap onto the renderXF frameBuffer, and then copy that to the form.

Additionally I strongly suggest using the using statement as it ensures the bitmap bits are locked and then freed once the using statement ends, so the app wont be reading possible garbage left over by the GC.

// Lock the bits
using (BitmapUtility xbmu = new BitmapUtility(infoBitmap))
{
    xbmu.CopyFrom(GL, 0, 0, 300, 100);
}
// Bits are free'd

As for the crashing for the minus 1 issue, I will try to release a fixed version later today, as I remember dealing with these kinds of issues when writing the improved bitmap blitter for DrawXF.

kf6kjg commented 3 years ago

Thank you. I'll get switched over to the using syntax shortly.

So in my case, where I have no form, I don't need the Blit call.

At risk of going off topic should I switch over to xfdraw?

theproadam commented 3 years ago

@kf6kjg Currently XFDraw doesn't have custom shader support, but it should have the basic custom shaders in less than a week. Because of this I would suggest waiting before commencing and new projects, however if you cannot wait id suggest just using renderXF.

kf6kjg commented 3 years ago

BlitInto is now gone, replaced by the fully formed BlitIntoBitmap. Thank you.