Skip to content

Commit a0d3137

Browse files
committed
Shapes and Graphics now set textures correctly (after batch texture changes)
1 parent 9dc53d1 commit a0d3137

8 files changed

Lines changed: 40 additions & 3 deletions

File tree

src/gameobjects/graphics/GraphicsWebGLRenderer.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
104104

105105
var getTint = Utils.getTintAppendFloatAlphaAndSwap;
106106

107+
var currentTexture = renderer.blankTexture.glTexture;
108+
107109
for (var cmdIndex = 0; cmdIndex < commands.length; cmdIndex++)
108110
{
109111
cmd = commands[cmdIndex];
@@ -130,6 +132,8 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
130132
case Commands.FILL_PATH:
131133
for (pathIndex = 0; pathIndex < path.length; pathIndex++)
132134
{
135+
pipeline.setTexture2D(currentTexture);
136+
133137
pipeline.batchFillPath(
134138
path[pathIndex].points,
135139
currentMatrix,
@@ -141,6 +145,8 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
141145
case Commands.STROKE_PATH:
142146
for (pathIndex = 0; pathIndex < path.length; pathIndex++)
143147
{
148+
pipeline.setTexture2D(currentTexture);
149+
144150
pipeline.batchStrokePath(
145151
path[pathIndex].points,
146152
lineWidth,
@@ -248,6 +254,7 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
248254
break;
249255

250256
case Commands.FILL_RECT:
257+
pipeline.setTexture2D(currentTexture);
251258
pipeline.batchFillRect(
252259
commands[++cmdIndex],
253260
commands[++cmdIndex],
@@ -259,6 +266,7 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
259266
break;
260267

261268
case Commands.FILL_TRIANGLE:
269+
pipeline.setTexture2D(currentTexture);
262270
pipeline.batchFillTriangle(
263271
commands[++cmdIndex],
264272
commands[++cmdIndex],
@@ -272,6 +280,7 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
272280
break;
273281

274282
case Commands.STROKE_TRIANGLE:
283+
pipeline.setTexture2D(currentTexture);
275284
pipeline.batchStrokeTriangle(
276285
commands[++cmdIndex],
277286
commands[++cmdIndex],
@@ -331,16 +340,18 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
331340
var mode = commands[++cmdIndex];
332341

333342
pipeline.currentFrame = frame;
334-
renderer.setTexture2D(frame.glTexture, 0);
343+
pipeline.setTexture2D(frame.glTexture, 0);
335344
pipeline.tintEffect = mode;
345+
346+
currentTexture = frame.glTexture;
347+
336348
break;
337349

338350
case Commands.CLEAR_TEXTURE:
339351
pipeline.currentFrame = renderer.blankTexture;
340-
renderer.setTexture2D(renderer.blankTexture.glTexture, 0);
341352
pipeline.tintEffect = 2;
353+
currentTexture = renderer.blankTexture.glTexture;
342354
break;
343-
344355
}
345356
}
346357
};

src/gameobjects/shape/FillPathWebGL.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var FillPathWebGL = function (pipeline, calcMatrix, src, alpha, dx, dy)
4949
var tx2 = calcMatrix.getX(x2, y2);
5050
var ty2 = calcMatrix.getY(x2, y2);
5151

52+
pipeline.setTexture2D();
53+
5254
pipeline.batchTri(tx0, ty0, tx1, ty1, tx2, ty2, 0, 0, 1, 1, fillTintColor, fillTintColor, fillTintColor, pipeline.tintEffect);
5355
}
5456
};

src/gameobjects/shape/StrokePathWebGL.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ var StrokePathWebGL = function (pipeline, src, alpha, dx, dy)
4747
var px2 = path[i] - dx;
4848
var py2 = path[i + 1] - dy;
4949

50+
pipeline.setTexture2D();
51+
5052
pipeline.batchLine(
5153
px1,
5254
py1,

src/gameobjects/shape/grid/GridWebGLRenderer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ var GridWebGLRenderer = function (renderer, src, interpolationPercentage, camera
133133
cw = (x < gridWidth - 1) ? cellWidthA : cellWidthB;
134134
ch = (y < gridHeight - 1) ? cellHeightA : cellHeightB;
135135

136+
pipeline.setTexture2D();
137+
136138
pipeline.batchFillRect(
137139
x * cellWidth,
138140
y * cellHeight,
@@ -173,6 +175,8 @@ var GridWebGLRenderer = function (renderer, src, interpolationPercentage, camera
173175
cw = (x < gridWidth - 1) ? cellWidthA : cellWidthB;
174176
ch = (y < gridHeight - 1) ? cellHeightA : cellHeightB;
175177

178+
pipeline.setTexture2D();
179+
176180
pipeline.batchFillRect(
177181
x * cellWidth,
178182
y * cellHeight,
@@ -197,13 +201,17 @@ var GridWebGLRenderer = function (renderer, src, interpolationPercentage, camera
197201
{
198202
var x1 = x * cellWidth;
199203

204+
pipeline.setTexture2D();
205+
200206
pipeline.batchLine(x1, 0, x1, height, 1, 1, 1, 0, false);
201207
}
202208

203209
for (y = 1; y < gridHeight; y++)
204210
{
205211
var y1 = y * cellHeight;
206212

213+
pipeline.setTexture2D();
214+
207215
pipeline.batchLine(0, y1, width, y1, 1, 1, 1, 0, false);
208216
}
209217
}

src/gameobjects/shape/isobox/IsoBoxWebGLRenderer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
9696

9797
x3 = calcMatrix.getX(0, sizeB - height);
9898
y3 = calcMatrix.getY(0, sizeB - height);
99+
100+
pipeline.setTexture2D();
99101

100102
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
101103
}
@@ -117,6 +119,8 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
117119

118120
x3 = calcMatrix.getX(-sizeA, -height);
119121
y3 = calcMatrix.getY(-sizeA, -height);
122+
123+
pipeline.setTexture2D();
120124

121125
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
122126
}
@@ -138,6 +142,8 @@ var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, came
138142

139143
x3 = calcMatrix.getX(sizeA, -height);
140144
y3 = calcMatrix.getY(sizeA, -height);
145+
146+
pipeline.setTexture2D();
141147

142148
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
143149
}

src/gameobjects/shape/isotriangle/IsoTriangleWebGLRenderer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ var IsoTriangleWebGLRenderer = function (renderer, src, interpolationPercentage,
9595

9696
var x3 = calcMatrix.getX(0, sizeB - height);
9797
var y3 = calcMatrix.getY(0, sizeB - height);
98+
99+
pipeline.setTexture2D();
98100

99101
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
100102
}
@@ -159,6 +161,8 @@ var IsoTriangleWebGLRenderer = function (renderer, src, interpolationPercentage,
159161
x2 = calcMatrix.getX(0, sizeB - height);
160162
y2 = calcMatrix.getY(0, sizeB - height);
161163
}
164+
165+
pipeline.setTexture2D();
162166

163167
pipeline.batchTri(x0, y0, x1, y1, x2, y2, 0, 0, 1, 1, tint, tint, tint, 2);
164168
}

src/gameobjects/shape/line/LineWebGLRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ var LineWebGLRenderer = function (renderer, src, interpolationPercentage, camera
6666
var startWidth = src._startWidth;
6767
var endWidth = src._endWidth;
6868

69+
pipeline.setTexture2D();
70+
6971
pipeline.batchLine(
7072
src.geom.x1 - dx,
7173
src.geom.y1 - dy,

src/gameobjects/shape/triangle/TriangleWebGLRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ var TriangleWebGLRenderer = function (renderer, src, interpolationPercentage, ca
7474
var x3 = src.geom.x3 - dx;
7575
var y3 = src.geom.y3 - dy;
7676

77+
pipeline.setTexture2D();
78+
7779
pipeline.batchFillTriangle(
7880
x1,
7981
y1,

0 commit comments

Comments
 (0)