Skip to content

Commit d0de931

Browse files
committed
per point coloring for line rendering
1 parent fd71283 commit d0de931

5 files changed

Lines changed: 76 additions & 66 deletions

File tree

v3/src/gameobjects/graphics/Commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ module.exports = {
1111
STROKE_PATH: 9,
1212
FILL_TRIANGLE: 10,
1313
STROKE_TRIANGLE: 11,
14-
LINE_WIDTH_TO: 12,
15-
MOVE_WIDTH_TO: 13
14+
LINE_FX_TO: 12,
15+
MOVE_FX_TO: 13
1616
};

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,19 @@ var Graphics = new Class({
148148
);
149149
},
150150

151-
lineWidthTo: function (x, y, width)
151+
lineFxTo: function (x, y, width, rgb)
152152
{
153153
this.commandBuffer.push(
154-
Commands.LINE_WIDTH_TO,
155-
x, y, width
154+
Commands.LINE_FX_TO,
155+
x, y, width, rgb, 1
156156
);
157157
},
158158

159-
moveWidthTo: function (x, y, width)
159+
moveFxTo: function (x, y, width, rgb)
160160
{
161161
this.commandBuffer.push(
162-
Commands.MOVE_WIDTH_TO,
163-
x, y, width
162+
Commands.MOVE_FX_TO,
163+
x, y, width, rgb, 1
164164
);
165165
},
166166

v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,20 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
158158
index += 2;
159159
break;
160160

161-
case Commands.LINE_WIDTH_TO:
161+
case Commands.LINE_FX_TO:
162162
ctx.lineTo(
163163
commandBuffer[index + 1],
164164
commandBuffer[index + 2]
165165
);
166-
index += 3;
166+
index += 5;
167167
break;
168168

169-
case Commands.MOVE_WIDTH_TO:
169+
case Commands.MOVE_FX_TO:
170170
ctx.moveTo(
171171
commandBuffer[index + 1],
172172
commandBuffer[index + 2]
173173
);
174-
index += 3;
174+
index += 5;
175175
break;
176176

177177
default:

v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ var sin = Math.sin;
66
var sqrt = Math.sqrt;
77
var tempMatrix = new TransformMatrix();
88

9-
var Point = function (x, y, width)
9+
var Point = function (x, y, width, rgb, alpha)
1010
{
1111
this.x = x;
1212
this.y = y;
1313
this.width = width;
14+
this.rgb = rgb;
15+
this.alpha = alpha;
1416
};
1517

16-
var Path = function (x, y, width)
18+
var Path = function (x, y, width, rgb, alpha)
1719
{
1820
this.points = [];
1921
this.pointsLength = 1;
20-
this.points[0] = new Point(x, y, width);
22+
this.points[0] = new Point(x, y, width, rgb, alpha);
2123
};
2224

2325
var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
@@ -275,23 +277,41 @@ var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, ca
275277
cmdIndex += 2;
276278
break;
277279

278-
case Commands.LINE_WIDTH_TO:
280+
case Commands.LINE_FX_TO:
279281
if (lastPath !== null)
280282
{
281-
lastPath.points.push(new Point(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3]));
283+
lastPath.points.push(new Point(
284+
commandBuffer[cmdIndex + 1],
285+
commandBuffer[cmdIndex + 2],
286+
commandBuffer[cmdIndex + 3],
287+
commandBuffer[cmdIndex + 4],
288+
commandBuffer[cmdIndex + 5]
289+
));
282290
}
283291
else
284292
{
285-
lastPath = new Path(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3]);
293+
lastPath = new Path(
294+
commandBuffer[cmdIndex + 1],
295+
commandBuffer[cmdIndex + 2],
296+
commandBuffer[cmdIndex + 3],
297+
commandBuffer[cmdIndex + 4],
298+
commandBuffer[cmdIndex + 5]
299+
);
286300
pathArray.push(lastPath);
287301
}
288-
cmdIndex += 3;
302+
cmdIndex += 5;
289303
break;
290304

291-
case Commands.MOVE_WIDTH_TO:
292-
lastPath = new Path(commandBuffer[cmdIndex + 1], commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3]);
305+
case Commands.MOVE_FX_TO:
306+
lastPath = new Path(
307+
commandBuffer[cmdIndex + 1],
308+
commandBuffer[cmdIndex + 2],
309+
commandBuffer[cmdIndex + 3],
310+
commandBuffer[cmdIndex + 4],
311+
commandBuffer[cmdIndex + 5]
312+
);
293313
pathArray.push(lastPath);
294-
cmdIndex += 3;
314+
cmdIndex += 5;
295315
break;
296316

297317
default:

v3/src/renderer/webgl/batches/shape/ShapeBatch.js

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ ShapeBatch.prototype = {
162162
/* Graphics Game Object properties */
163163
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
164164
/* line properties */
165-
ax, ay, bx, by, aLineWidth, bLineWidth, lineColor, lineAlpha,
165+
ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha,
166166
/* transform */
167167
a, b, c, d, e, f
168168
) {
@@ -203,34 +203,34 @@ ShapeBatch.prototype = {
203203

204204
vertexBufferF32[vertexOffset++] = x0;
205205
vertexBufferF32[vertexOffset++] = y0;
206-
vertexBufferU32[vertexOffset++] = lineColor;
206+
vertexBufferU32[vertexOffset++] = bLineColor;
207207
vertexBufferF32[vertexOffset++] = lineAlpha;
208208
vertexBufferF32[vertexOffset++] = x1;
209209
vertexBufferF32[vertexOffset++] = y1;
210-
vertexBufferU32[vertexOffset++] = lineColor;
210+
vertexBufferU32[vertexOffset++] = aLineColor;
211211
vertexBufferF32[vertexOffset++] = lineAlpha;
212212
vertexBufferF32[vertexOffset++] = x2;
213213
vertexBufferF32[vertexOffset++] = y2;
214-
vertexBufferU32[vertexOffset++] = lineColor;
214+
vertexBufferU32[vertexOffset++] = bLineColor;
215215
vertexBufferF32[vertexOffset++] = lineAlpha;
216216
vertexBufferF32[vertexOffset++] = x1;
217217
vertexBufferF32[vertexOffset++] = y1;
218-
vertexBufferU32[vertexOffset++] = lineColor;
218+
vertexBufferU32[vertexOffset++] = aLineColor;
219219
vertexBufferF32[vertexOffset++] = lineAlpha;
220220
vertexBufferF32[vertexOffset++] = x3;
221221
vertexBufferF32[vertexOffset++] = y3;
222-
vertexBufferU32[vertexOffset++] = lineColor;
222+
vertexBufferU32[vertexOffset++] = aLineColor;
223223
vertexBufferF32[vertexOffset++] = lineAlpha;
224224
vertexBufferF32[vertexOffset++] = x2;
225225
vertexBufferF32[vertexOffset++] = y2;
226-
vertexBufferU32[vertexOffset++] = lineColor;
226+
vertexBufferU32[vertexOffset++] = bLineColor;
227227
vertexBufferF32[vertexOffset++] = lineAlpha;
228228

229229
return [
230-
x0, y0,
231-
x1, y1,
232-
x2, y2,
233-
x3, y3
230+
x0, y0, bLineColor,
231+
x1, y1, aLineColor,
232+
x2, y2, bLineColor,
233+
x3, y3, aLineColor
234234
];
235235

236236
},
@@ -266,7 +266,7 @@ ShapeBatch.prototype = {
266266
point0.x, point0.y,
267267
point1.x, point1.y,
268268
point0.width / 2, point1.width / 2,
269-
lineColor, lineAlpha,
269+
point0.rgb, point1.rgb, lineAlpha,
270270
a, b, c, d, e, f
271271
);
272272
polylines.push(line);
@@ -286,44 +286,34 @@ ShapeBatch.prototype = {
286286
curr = polylines[index];
287287
vertexOffset = vertexDataBuffer.allocate(24)
288288

289-
x0 = last[2 * 2 + 0];
290-
y0 = last[2 * 2 + 1];
291-
x1 = last[2 * 0 + 0];
292-
y1 = last[2 * 0 + 1];
293-
x2 = curr[2 * 3 + 0];
294-
y2 = curr[2 * 3 + 1];
295-
296-
vertexBufferF32[vertexOffset++] = x0;
297-
vertexBufferF32[vertexOffset++] = y0;
298-
vertexBufferU32[vertexOffset++] = lineColor;
289+
vertexBufferF32[vertexOffset++] = last[3 * 2 + 0];
290+
vertexBufferF32[vertexOffset++] = last[3 * 2 + 1];
291+
vertexBufferU32[vertexOffset++] = last[3 * 2 + 2];
299292
vertexBufferF32[vertexOffset++] = lineAlpha;
300-
vertexBufferF32[vertexOffset++] = x1;
301-
vertexBufferF32[vertexOffset++] = y1;
302-
vertexBufferU32[vertexOffset++] = lineColor;
293+
294+
vertexBufferF32[vertexOffset++] = last[3 * 0 + 0];
295+
vertexBufferF32[vertexOffset++] = last[3 * 0 + 1];
296+
vertexBufferU32[vertexOffset++] = last[3 * 0 + 2];
303297
vertexBufferF32[vertexOffset++] = lineAlpha;
304-
vertexBufferF32[vertexOffset++] = x2;
305-
vertexBufferF32[vertexOffset++] = y2;
306-
vertexBufferU32[vertexOffset++] = lineColor;
298+
299+
vertexBufferF32[vertexOffset++] = curr[3 * 3 + 0];
300+
vertexBufferF32[vertexOffset++] = curr[3 * 3 + 1];
301+
vertexBufferU32[vertexOffset++] = curr[3 * 3 + 2];
307302
vertexBufferF32[vertexOffset++] = lineAlpha;
308303

309-
x0 = last[2 * 0 + 0];
310-
y0 = last[2 * 0 + 1];
311-
x1 = last[2 * 2 + 0];
312-
y1 = last[2 * 2 + 1];
313-
x2 = curr[2 * 1 + 0];
314-
y2 = curr[2 * 1 + 1];
315-
316-
vertexBufferF32[vertexOffset++] = x0;
317-
vertexBufferF32[vertexOffset++] = y0;
318-
vertexBufferU32[vertexOffset++] = lineColor;
304+
vertexBufferF32[vertexOffset++] = last[3 * 0 + 0];
305+
vertexBufferF32[vertexOffset++] = last[3 * 0 + 1];
306+
vertexBufferU32[vertexOffset++] = last[3 * 0 + 2];
319307
vertexBufferF32[vertexOffset++] = lineAlpha;
320-
vertexBufferF32[vertexOffset++] = x1;
321-
vertexBufferF32[vertexOffset++] = y1;
322-
vertexBufferU32[vertexOffset++] = lineColor;
308+
309+
vertexBufferF32[vertexOffset++] = last[3 * 2 + 0];
310+
vertexBufferF32[vertexOffset++] = last[3 * 2 + 1];
311+
vertexBufferU32[vertexOffset++] = last[3 * 2 + 2];
323312
vertexBufferF32[vertexOffset++] = lineAlpha;
324-
vertexBufferF32[vertexOffset++] = x2;
325-
vertexBufferF32[vertexOffset++] = y2;
326-
vertexBufferU32[vertexOffset++] = lineColor;
313+
314+
vertexBufferF32[vertexOffset++] = curr[3 * 1 + 0];
315+
vertexBufferF32[vertexOffset++] = curr[3 * 1 + 1];
316+
vertexBufferU32[vertexOffset++] = curr[3 * 1 + 2];
327317
vertexBufferF32[vertexOffset++] = lineAlpha;
328318

329319
this.vertexCount += 6;

0 commit comments

Comments
 (0)