mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Removed drawStaticTilemapLayer
method and updated layer vertex code
This commit is contained in:
parent
4d30de536e
commit
1941d8a494
3 changed files with 86 additions and 72 deletions
|
@ -344,47 +344,12 @@ var TextureTintPipeline = new Class({
|
|||
resize: function (width, height, resolution)
|
||||
{
|
||||
WebGLPipeline.prototype.resize.call(this, width, height, resolution);
|
||||
|
||||
this.projOrtho(0, this.width, this.height, 0, -1000.0, 1000.0);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders immediately a static tilemap. This function won't use
|
||||
* the batching functionality of the pipeline.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawStaticTilemapLayer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Tilemaps.StaticTilemapLayer} tilemap - [description]
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description]
|
||||
*/
|
||||
drawStaticTilemapLayer: function (tilemap)
|
||||
{
|
||||
if (tilemap.vertexCount > 0)
|
||||
{
|
||||
var pipelineVertexBuffer = this.vertexBuffer;
|
||||
var gl = this.gl;
|
||||
var renderer = this.renderer;
|
||||
var frame = tilemap.tileset.image.get();
|
||||
|
||||
if (renderer.currentPipeline &&
|
||||
renderer.currentPipeline.vertexCount > 0)
|
||||
{
|
||||
renderer.flush();
|
||||
}
|
||||
|
||||
this.vertexBuffer = tilemap.vertexBuffer;
|
||||
renderer.setPipeline(this);
|
||||
renderer.setTexture2D(frame.source.glTexture, 0);
|
||||
gl.drawArrays(this.topology, 0, tilemap.vertexCount);
|
||||
this.vertexBuffer = pipelineVertexBuffer;
|
||||
}
|
||||
|
||||
this.viewIdentity();
|
||||
this.modelIdentity();
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders contents of a ParticleEmitterManager. It'll batch all particles if possible.
|
||||
*
|
||||
|
|
|
@ -238,8 +238,9 @@ var StaticTilemapLayer = new Class({
|
|||
var gl = renderer.gl;
|
||||
var vertexBuffer = this.vertexBuffer;
|
||||
var bufferData = this.bufferData;
|
||||
var voffset = 0;
|
||||
var voffset = -1;
|
||||
var vertexCount = 0;
|
||||
var tintEffect = false;
|
||||
var bufferSize = (mapWidth * mapHeight) * pipeline.vertexSize * 6;
|
||||
|
||||
if (bufferData === null)
|
||||
|
@ -258,7 +259,11 @@ var StaticTilemapLayer = new Class({
|
|||
for (col = 0; col < mapWidth; ++col)
|
||||
{
|
||||
tile = mapData[row][col];
|
||||
if (tile === null || tile.index === -1) { continue; }
|
||||
|
||||
if (tile === null || tile.index === -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var tx = tile.pixelX;
|
||||
var ty = tile.pixelY;
|
||||
|
@ -266,7 +271,11 @@ var StaticTilemapLayer = new Class({
|
|||
var tyh = ty + tile.height;
|
||||
|
||||
texCoords = tileset.getTileTextureCoordinates(tile.index);
|
||||
if (texCoords === null) { continue; }
|
||||
|
||||
if (texCoords === null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var u0 = texCoords.x / width;
|
||||
var v0 = texCoords.y / height;
|
||||
|
@ -281,46 +290,58 @@ var StaticTilemapLayer = new Class({
|
|||
var ty2 = tyh;
|
||||
var tx3 = txw;
|
||||
var ty3 = ty;
|
||||
|
||||
var tint = Utils.getTintAppendFloatAlpha(0xffffff, camera.alpha * this.alpha * tile.alpha);
|
||||
|
||||
vertexViewF32[voffset + 0] = tx0;
|
||||
vertexViewF32[voffset + 1] = ty0;
|
||||
vertexViewF32[voffset + 2] = u0;
|
||||
vertexViewF32[voffset + 3] = v0;
|
||||
vertexViewU32[voffset + 4] = tint;
|
||||
vertexViewF32[voffset + 5] = tx1;
|
||||
vertexViewF32[voffset + 6] = ty1;
|
||||
vertexViewF32[voffset + 7] = u0;
|
||||
vertexViewF32[voffset + 8] = v1;
|
||||
vertexViewU32[voffset + 9] = tint;
|
||||
vertexViewF32[voffset + 10] = tx2;
|
||||
vertexViewF32[voffset + 11] = ty2;
|
||||
vertexViewF32[voffset + 12] = u1;
|
||||
vertexViewF32[voffset + 13] = v1;
|
||||
vertexViewU32[voffset + 14] = tint;
|
||||
vertexViewF32[voffset + 15] = tx0;
|
||||
vertexViewF32[voffset + 16] = ty0;
|
||||
vertexViewF32[voffset + 17] = u0;
|
||||
vertexViewF32[voffset + 18] = v0;
|
||||
vertexViewU32[voffset + 19] = tint;
|
||||
vertexViewF32[voffset + 20] = tx2;
|
||||
vertexViewF32[voffset + 21] = ty2;
|
||||
vertexViewF32[voffset + 22] = u1;
|
||||
vertexViewF32[voffset + 23] = v1;
|
||||
vertexViewU32[voffset + 24] = tint;
|
||||
vertexViewF32[voffset + 25] = tx3;
|
||||
vertexViewF32[voffset + 26] = ty3;
|
||||
vertexViewF32[voffset + 27] = u1;
|
||||
vertexViewF32[voffset + 28] = v0;
|
||||
vertexViewU32[voffset + 29] = tint;
|
||||
vertexViewF32[++voffset] = tx0;
|
||||
vertexViewF32[++voffset] = ty0;
|
||||
vertexViewF32[++voffset] = u0;
|
||||
vertexViewF32[++voffset] = v0;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
vertexViewF32[++voffset] = tx1;
|
||||
vertexViewF32[++voffset] = ty1;
|
||||
vertexViewF32[++voffset] = u0;
|
||||
vertexViewF32[++voffset] = v1;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
vertexViewF32[++voffset] = tx2;
|
||||
vertexViewF32[++voffset] = ty2;
|
||||
vertexViewF32[++voffset] = u1;
|
||||
vertexViewF32[++voffset] = v1;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
vertexViewF32[++voffset] = tx0;
|
||||
vertexViewF32[++voffset] = ty0;
|
||||
vertexViewF32[++voffset] = u0;
|
||||
vertexViewF32[++voffset] = v0;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
vertexViewF32[++voffset] = tx2;
|
||||
vertexViewF32[++voffset] = ty2;
|
||||
vertexViewF32[++voffset] = u1;
|
||||
vertexViewF32[++voffset] = v1;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
vertexViewF32[++voffset] = tx3;
|
||||
vertexViewF32[++voffset] = ty3;
|
||||
vertexViewF32[++voffset] = u1;
|
||||
vertexViewF32[++voffset] = v0;
|
||||
vertexViewF32[++voffset] = tintEffect;
|
||||
vertexViewU32[++voffset] = tint;
|
||||
|
||||
voffset += 30;
|
||||
vertexCount += 6;
|
||||
}
|
||||
}
|
||||
|
||||
this.vertexCount = vertexCount;
|
||||
this.dirty = false;
|
||||
|
||||
if (vertexBuffer === null)
|
||||
{
|
||||
vertexBuffer = renderer.createVertexBuffer(bufferData, gl.STATIC_DRAW);
|
||||
|
|
|
@ -8,9 +8,12 @@ var GameObject = require('../../gameobjects/GameObject');
|
|||
|
||||
/**
|
||||
* Renders this Game Object with the WebGL Renderer to the given Camera.
|
||||
*
|
||||
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
|
||||
* This method should not be called directly. It is a utility function of the Render module.
|
||||
*
|
||||
* A Static Tilemap Layer renders immediately and does not use any batching.
|
||||
*
|
||||
* @method Phaser.Tilemaps.StaticTilemapLayer#renderWebGL
|
||||
* @since 3.0.0
|
||||
* @private
|
||||
|
@ -29,7 +32,32 @@ var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPerc
|
|||
|
||||
src.upload(camera);
|
||||
|
||||
this.pipeline.drawStaticTilemapLayer(src, camera);
|
||||
if (src.vertexCount > 0)
|
||||
{
|
||||
var gl = renderer.gl;
|
||||
var pipeline = this.pipeline;
|
||||
var pipelineVertexBuffer = pipeline.vertexBuffer;
|
||||
|
||||
var frame = src.tileset.image.get();
|
||||
|
||||
if (renderer.currentPipeline && renderer.currentPipeline.vertexCount > 0)
|
||||
{
|
||||
renderer.flush();
|
||||
}
|
||||
|
||||
pipeline.vertexBuffer = src.vertexBuffer;
|
||||
|
||||
renderer.setPipeline(pipeline);
|
||||
|
||||
renderer.setTexture2D(frame.source.glTexture, 0);
|
||||
|
||||
gl.drawArrays(pipeline.topology, 0, src.vertexCount);
|
||||
|
||||
pipeline.vertexBuffer = pipelineVertexBuffer;
|
||||
|
||||
pipeline.viewIdentity();
|
||||
pipeline.modelIdentity();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = StaticTilemapLayerWebGLRenderer;
|
||||
|
|
Loading…
Reference in a new issue