forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticTilemapLayerWebGLRenderer.js
More file actions
89 lines (72 loc) · 3.21 KB
/
Copy pathStaticTilemapLayerWebGLRenderer.js
File metadata and controls
89 lines (72 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Identity = require('../../renderer/webgl/mvp/Identity');
var Scale = require('../../renderer/webgl/mvp/Scale');
var Translate = require('../../renderer/webgl/mvp/Translate');
var ViewLoad2D = require('../../renderer/webgl/mvp/ViewLoad2D');
/**
* 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
*
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.Tilemaps.StaticTilemapLayer} src - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
{
var gl = renderer.gl;
var pipeline = src.pipeline;
renderer.flush();
// Restore when we're done
var pipelineVertexBuffer = pipeline.vertexBuffer;
Identity(src);
Translate(src, src.x - (camera.scrollX * src.scrollFactorX), src.y - (camera.scrollY * src.scrollFactorY), 0);
Scale(src, src.scaleX, src.scaleY, 1);
ViewLoad2D(src, camera.matrix.matrix);
renderer.setPipeline(pipeline);
// The above alters the uniforms, so make sure we call it _after_ setting the MVP stuff above
renderer.setMatrix4(pipeline.program, 'uModelMatrix', false, src.modelMatrix);
renderer.setMatrix4(pipeline.program, 'uViewMatrix', false, src.viewMatrix);
renderer.setMatrix4(pipeline.program, 'uProjectionMatrix', false, pipeline.projectionMatrix);
for (var i = 0; i < src.tileset.length; i++)
{
var tileset = src.tileset[i];
var vertexCount = src.vertexCount[i];
src.upload(camera, i);
if (vertexCount > 0)
{
if (pipeline.forceZero)
{
// Light Pipeline, or similar
pipeline.setGameObject(src, tileset);
}
else
{
renderer.setTextureZero(tileset.glTexture);
}
gl.drawArrays(gl.TRIANGLES, 0, vertexCount);
}
}
renderer.resetTextures();
// Restore the pipeline buffer
pipeline.vertexBuffer = pipelineVertexBuffer;
renderer.currentVertexBuffer = pipelineVertexBuffer;
pipeline.setAttribPointers();
// Reset the uniforms
renderer.setMatrix4(pipeline.program, 'uModelMatrix', false, pipeline.modelMatrix);
renderer.setMatrix4(pipeline.program, 'uViewMatrix', false, pipeline.viewMatrix);
renderer.setMatrix4(pipeline.program, 'uProjectionMatrix', false, pipeline.projectionMatrix);
};
module.exports = StaticTilemapLayerWebGLRenderer;