anchor.diff:  
     if fUseVBO then
     begin
  +    BindVBOArray(vat_Tile);
       //Setup vertex and UV layout and offsets
       glEnableClientState(GL_VERTEX_ARRAY);
       glVertexPointer(3, GL_FLOAT, SizeOf(TTileVertice), Pointer(0));
  
positive.code:   pData[3] := $00000000;
    fTextB := TRender.GenTexture(4, 1, @pData[0], tf_RGBA8);
  
    fUseVBO := VBOSupported;
  
    if fUseVBO then
    begin
      glGenBuffers(1, @fVtxShd);
      glGenBuffers(1, @fIndShd);
    end;
  end;
  
  
  destructor TRenderTerrain.Destroy;
  begin
    fUseVBO := VBOSupported; //Could have been set to false if 3D rendering is enabled, so reset it
    if fUseVBO then
    begin
      //Since RenderTerrain is created fresh everytime fGame is created, we should clear
      //the buffers to avoid memory leaks.
      glDeleteBuffers(1, @fVtxShd);
      glDeleteBuffers(1, @fIndShd);
    end;
    inherited;
  end;
  
negative.code: 
    SizeX := Max(fClipRect.Right - fClipRect.Left, 0);
    SizeY := Max(fClipRect.Bottom - fClipRect.Top, 0);
  
    H := 0;
    Q := 0;
  
    TexOffsetWater := 0;
    TexOffsetFalls := 0;
    TexOffsetSwamp := 0;
  
    for AL := Low(TAnimLayer) to High(TAnimLayer) do
      case AL of
        alWater: TexOffsetWater := 300 * (aAnimStep mod 8 + 1);       // 300..2400
        alFalls: TexOffsetFalls := 300 * (aAnimStep mod 5 + 1 + 8);   // 2700..3900
        alSwamp: TexOffsetSwamp := 300 * ((aAnimStep mod 24) div 8 + 1 + 8 + 5); // 4200..4800
      end;
  
    SetLength(fTilesVtx, (SizeX + 1) * 4 * (SizeY + 1));
    SetLength(fAnimTilesVtx, (SizeX + 1) * 4 * (SizeY + 1));
    with gTerrain do
      if (MapX > 0) and (MapY > 0) then
        for I := 0 to SizeY do
          for K := 0 to SizeX do
          begin
            tX := K + fClipRect.Left;
            tY := I + fClipRect.Top;
            TexTileC := fTileUVLookup[Land[tY, tX].Terrain, Land[tY, tX].Rotation mod 4];
  
            //Fill Tile vertices array
            SetTileVertex(H,   tX-1, tY-1, False, TexTileC[1][1], TexTileC[1][2]);
            SetTileVertex(H+1, tX-1, tY,   True,  TexTileC[2][1], TexTileC[2][2]);
            SetTileVertex(H+2, tX,   tY,   True,  TexTileC[3][1], TexTileC[3][2]);
            SetTileVertex(H+3, tX,   tY-1, False, TexTileC[4][1], TexTileC[4][2]);
  
            //Fill tiles animation vertices array
            if not TryAddAnimTex(Q, tX, tY, TexOffsetWater) then  //every tile can have only 1 animation
              if not TryAddAnimTex(Q, tX, tY, TexOffsetFalls) then
                TryAddAnimTex(Q, tX, tY, TexOffsetSwamp);
  
            H := H + 4;
          end;
  
  
    //Cut animation vertices array to actual size
    SetLength(fAnimTilesVtx, Q);
  
    //Fill indexes array for tiles vertices array
    H := 0;
    SetLength(fTilesInd, (SizeX+1) * (SizeY+1) * 6);
    for I := 0 to SizeY do
      for K := 0 to SizeX do
      begin
        Row := (I * (SizeX + 1)) shl 2;
        fTilesInd[H+0] := Row + K shl 2; // shl 2 = *4
        fTilesInd[H+1] := Row + (K shl 2) + 1;
        fTilesInd[H+2] := Row + (K shl 2) + 2;
        fTilesInd[H+3] := Row + (K shl 2);
        fTilesInd[H+4] := Row + (K shl 2) + 3;
        fTilesInd[H+5] := Row + (K shl 2) + 2;
        H := H + 6;
      end;
  
    AnimCnt := Q div 4;
    //Fill indexes array for tiles animation vertices array
    H := 0;
    I := 0;
    SetLength(fAnimTilesInd, AnimCnt*6);
    while I < AnimCnt do
    begin
      fAnimTilesInd[H+0] := I shl 2; // shl 2 = *4
      fAnimTilesInd[H+1] := (I shl 2) + 1;
      fAnimTilesInd[H+2] := (I shl 2) + 2;
      fAnimTilesInd[H+3] := (I shl 2);
      fAnimTilesInd[H+4] := (I shl 2) + 3;
      fAnimTilesInd[H+5] := (I shl 2) + 2;
      H := H + 6;
      Inc(I);
    end;
  end;
  
  