Results 1 to 10 of 35

Thread: Pascal eXtended Library (aka Asphyre) released!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by SilverWarior View Post
    No there is a TCustomDrawableTexture that is intended to be used as a render target.
    Zimond also asked this by e-mail and I've explained that PXL does support render targets similar to earlier Asphyre versions, just now they are called "drawable textures" as you've accurately explained. This new name was chosen to be something in the middle between "render targets" in DX and "frame buffer objects" in GL. However, PXL introduces TBitmap in "PXL.Bitmaps.pas", which can be used as an alternative to TAtlasImage. TBitmap can have multiple internal "storage" options: system texture (so you can access it via Bitmap.Surface.Scanline, Bitmap.Surface.Pixels and so on), lockable texture or drawable texture (both of which can be accessed through Bitmap.Texture). The storage type is chosen and/or gets changed automatically depending on how you use it, but you can also control it explicitly via Storage property.

    TBitmap also owns "Canvas", so you can draw to it easily. Something like:
    Code:
      MyBitmap := TBitmap.Create(MyDevice); // MyDevice must be already initialized here.
      MyBitmap.SetSize(256, 256);
    
      // Render something on bitmap using GPU.
      if MyBitmap.Canvas.BeginScene then
      try
        // Draw something on bitmap (in this case, green rectangle filling entire surface).
        MyBitmap.Canvas.FillRect(0, 0, 256, 256, IntColorRGB(0, 255, 0));
    
        // Draw another bitmap onto this one.
        MyBitmap.Canvas.UseImage(AnotherBitmap);
        MyBitmap.Canvas.TexQuad(FloatRect4(30, 40, 128, 128), IntColorWhite4);
      finally
        MyBitmap.Canvas.EndScene;
      end;
    
      // Now access bitmap pixels directly (in this case, set one pixel to purple).
      MyBitmap.Surface.Pixels[25, 50] := IntColorRGB(255, 0, 255);
    
      // Save final scene to disk.
      MyBitmap.SaveToFile("test.png");
    What's great about that triple storage thing is that you can render to bitmap using GPU acceleration and then switch storage to "System" and access its pixels directly, if you have to. For obvious reasons, constantly changing bitmap storage type, especially for large bitmaps, is resource-intensive and should be done with care. The framework's official package has "Tunnel" sample that illustrates usage of bitmaps.
    Last edited by LP; 22-06-2016 at 08:30 PM. Reason: improved sample code

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •