Announcement

Collapse
No announcement yet.

Update TTexture and dynamic array

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

  • Update TTexture and dynamic array

    How to support dynamic array ? these code show a incorrect image.
    Code:
    //LMyArray: array[0..511, 0..511] of TIntColor;
    LMyArray:array of array of TIntColor;
    LMyTexture: TTexture;
    begin
       SetLength(LMyArray,512,512);
       ......
       ......
       LMyTexture.Update(@LMyArray[0, 0], 512 * SizeOf(TIntColor), 0, ZeroIntRect);
    end;

  • #2
    I have attached TextureUpdate example both for Delphi and FPC/Lazarus that I've quickly baked some time ago, which shows how to upload pixels from a dynamic array.

    In your code, the fixed array (the one that you commented out) should work just fine. In case of your actual code, it won't work because you have dynamic array of dynamic array; in other words, it is an array of pointers, whereas each pointer is a also a dynamic array. This is rather an inefficient structure in terms of memory access, you'd better of using a single dynamic array like in the examples I've attached.

    However, if you really need to use such structure, you can try uploading a single horizontal scanline at a time, but in this case, you need to remove TextureDynamic flag if you've used one for creating the texture (dynamic textures can not be updated partially):
    Code:
    var
      LMyArray: array of array of TIntColor;
      I: Integer;
    begin
       LParameters := LMyTexture.Parameters;
       SetLength(LMyArray, LParameters.Height, LParameters.Width);
    
        // Fill LMyArray here...
    
        for I := 0 to Length(LMyArray) - 1 do
          FTexture.Update(@LMyArray[I, 0], 0, 0, IntRect(0, I, Length(LMyArray[I]), 1));
    end;
    Attached Files

    Comment


    • #3
      Thanks for the example,this way loading speed is still fast.

      Comment

      Working...
      X