+ requestAnimationFrame(function(aTimestamp) { gMap.drawGL() });
+ },
+
+ drawGL: function() {
+ var wid = gMap.gl.drawingBufferWidth * gMap.zoomFactor; // Width in level 18 pixels.
+ var ht = gMap.gl.drawingBufferHeight * gMap.zoomFactor; // Height in level 18 pixels.
+ var size = gMap.tileSize * gMap.zoomFactor; // Tile size in level 18 pixels.
+
+ var xMin = gMap.pos.x - wid / 2; // Corners of the window in level 18 pixels.
+ var yMin = gMap.pos.y - ht / 2;
+ var xMax = gMap.pos.x + wid / 2;
+ var yMax = gMap.pos.y + ht / 2;
+
+ var txIndexList = [];
+ // Go through all the tiles in the map, find out if to draw them and do so.
+ for (var x = Math.floor(xMin / size); x < Math.ceil(xMax / size); x++) {
+ for (var y = Math.floor(yMin / size); y < Math.ceil(yMax / size); y++) { // slow script warnings on the tablet appear here!
+ // Round here is **CRUCIAL** otherwise the images are filtered
+ // and the performance sucks (more than expected).
+ var xoff = Math.round((x * size - xMin) / gMap.zoomFactor);
+ var yoff = Math.round((y * size - yMin) / gMap.zoomFactor);
+ // Draw the tile, first find out the index of the texture to use.
+ var norm = normalizeCoords({x: x, y: y, z: gMap.pos.z});
+ var tileKey = getTileKey(gMap.activeMap, norm);
+ var txIndex = gMap.glTextureKeys[tileKey];
+ if (!txIndex) { txIndex = 0; }
+ txIndexList.push(txIndex);
+ gMap.drawTileGL(xoff, yoff, txIndex);
+ }
+ }
+ console.log("Used Indexes: " + txIndexList.join(","));