gldtTexImage2D function

void gldtTexImage2D(
  1. int target,
  2. int level,
  3. int internalformat,
  4. int width,
  5. int height,
  6. int border,
  7. int format,
  8. Uint8List pixels, {
  9. bool inverted = true,
})

Implementation

void gldtTexImage2D(int target, int level, int internalformat, int width,
    int height, int border, int format, Uint8List pixels,
    {bool inverted = true}) {
  Pointer<Uint8> callocPixelsPointer(
      Uint8List pixels, int height, bool inverted) {
    var pixelsPointer = calloc<Uint8>(pixels.length);
    var radix = pixels.length ~/ height;
    var index = 0;
    for (var h = 0; h < height; h++) {
      var pos = h;
      if (inverted == true) {
        pos = height - h - 1;
      }
      var values = pixels.getRange(pos * radix, (pos + 1) * radix);
      for (var value in values) {
        (pixelsPointer + index).value = value;
        index++;
      }
    }
    return pixelsPointer;
  }

  var pixelsPointer = callocPixelsPointer(pixels, height, inverted);
  glTexImage2D(target, level, internalformat, width, height, border, format,
      GL_UNSIGNED_BYTE, pixelsPointer.cast<Void>());
  calloc.free(pixelsPointer);
}