Announcement

Collapse
No announcement yet.

How to lock texture

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to lock texture

    How to convert these Asphyre code to Afterwarp.
    Does it similar to Texture.Update(...) ?

    Code:
    var
      pDest: Pointer;
      nPitch: Integer;
      ARGB: PByte;
      texture:TDX9LockableTexture
    begin
      texture := TDX9LockableTexture.Create;
      texture.Width := FWidth;
      texture.Height := FHeight;
      texture.Format := apf_A8R8G8B8;
      texture.Initialize;
    
      texture.Lock(Rect(0, 0, FWidth, FHeight), pDest, nPitch);
      ARGB := pDest;
      ......
      .....
      texture.Unlock;
    end;
    Another question:
    How to switch to full screen(real) mode ?

  • #2
    "Lockable" textures were mainly a representation of Direct3D 9 "managed" textures, which in PXL/Asphyre for DX10+ were emulated by always containing a copy of such texture in system memory and updating their counterpart in GPU after call to "Unlock". In newer APIs, since GPU memory is virtualized, there is no need for "managed" textures; in fact, for higher performance,"immutable" textures are preferred.

    Afterwarp supports multiple texture types and if you don't specify TextureDynamic flag, it'll use immutable textures. These can be updated via TTexture.Update or TTexture.Copy (on the driver level it means that a new texture with the given content will be created, while old one discarded). You can also download texture's content through TTexture.Save function.

    This would be an example of uploading (and possibly downloading) content to texture:
    Code:
    var
      LSurface: TRasterSurface;
      LSurfParams: TRasterSurfaceParameters;
      LTexture: TTexture;
      LParams: TTextureParameters;
      I, J: Integer;
      LDest: PIntColor;
    begin
      // Create surface in system memory.
      LSurface := RasterSurfaceInit(512, 512, TPixelFormat.RGBA8);
      if not LSurface.Initialized then
        Exit(False); // Could not create system surface.
      try
        LSurfParams := LSurface.Parameters;
    
        // Generate some texture pattern in code:
        for J := 0 to 511 do
        begin
          LDest := LSurfParams.Scanline[J];
    
          for I := 0 to 511 do
          begin
            if I + J mod 2 = 0 then
              LDest^ := $FFFFFFFF
            else
              LDest^ := $FF000000;
    
            Inc(LDest);
    
            // This would also work, but would be slightly slower:
            // LSurface.Pixels[I, J] := $FF00FF00;
          end;
        end;
    
        FillChar(LParams, SizeOf(TTextureParameters), 0);
        LParams.Width := 512;
        LParams.Height := 512;
        LParams.Format := TPixelFormat.RGBA8;
    
        LTexture := TextureInit(FDevice, LParams);
        if not LTexture.Initialized then
          Exit(False); // Could not create texture.
    
        // Upload content to texture.
        if not LTexture.Copy(LSurface, 0, ZeroPoint2i, ZeroIntRect) then
          Exit(False); // Could not update texture.
    
        // Download content from texture.
        //if not LTexture.Save(LSurface, 0, ZeroPoint2i, ZeroIntRect) then
        //  Exit(False);
      finally
        LSurface.Free;
      end;
    How to switch to full screen(real) mode ?
    Can you please clarify what you mean by full-screen? If you mean the application would occupy the whole screen, in Delphi/Lazarus this is achieved by setting Left/Top of the form to the origin of the appropriate monitor and ClientWidth/ClientHeight to the size of such monitor - this will effectively remove window border's and title, so application will be full-screen.

    Comment


    • #3
      1. Thank's for the example.Is there a easy way to read/write TTexture content directly ? But i need convert to TRasterSurface seem a bit inconvenient.

      2. I mean real full-screen, the image is always auto stretched to fit the entire pixels. Not does borderless windowed mode(fake full screen).The same as old Asphyre Plasma sample(press Alt+Enter)

      https://docs.microsoft.com/zh-tw/win...ectedfrom=MSDN
      https://docs.microsoft.com/zh-tw/win...ll-screen-mode
      Last edited by DraculaLin; 01-22-2020, 07:25 PM.

      Comment


      • #4
        Originally posted by DraculaLin View Post
        1. Thank's for the example.Is there a easy way to read/write TTexture content directly ? But i need convert to TRasterSurface seem a bit inconvenient.
        As I've mentioned above, you can update TTexture directly by calling TTexture.Update, for example:
        Code:
          LMyArray: array[0..511, 0..511] of TIntColor;
          LMyTexture: TTexture;
        begin
          LMyTexture.Update(@LMyArray[0, 0], 512 * SizeOf(TIntColor), 0, ZeroIntRect); // The second parameter is pitch (scanline size in bytes)
        Originally posted by DraculaLin View Post
        2. I mean real full-screen, the image is always auto stretched to fit the entire pixels. Not does borderless windowed mode(fake full screen).The same as old Asphyre Plasma sample(press Alt+Enter)
        Nowadays changing display resolution would mess up customer's icons and multi-monitor configuration, so this capability has been removed from Asphyre long time ago. However, you can simulate this easily by rendering your game content to a TTexture of fixed size, e.g. 640x480, then render such texture to application stretched to fill the entire area (for example, in borderless mode). In fact, you could use Afterwarp's cubic interpolation to produce a higher quality picture this way.

        I wouldn't call borderless window occupying the entire screen a "fake full screen" - most modern OSes such as Windows and Linux use GPU-based compositioning, so your window is fully GPU accelerated, there are no practical differences between non-full-screen and full-screen. Personally, if I would download an application that will be arrogant enough to try changing my display's resolution, it'll be quickly uninstalled.

        Comment


        • #5
          Originally posted by lifepower View Post
          Personally, if I would download an application that will be arrogant enough to try changing my display's resolution, it'll be quickly uninstalled.
          I totally agree with that. Thankfully exclusive fullscreens are a thing of the past. By rendering to a texture you can still choose the resolution and the aspect ratio as you like and it makes it possible to create some fullscreen effects like blurring or pixelating the whole screen at once.

          Comment

          Working...
          X