Skip to content

Commit 77e9ddd

Browse files
authored
Merge pull request #1248 from Vareniel/melonEditorDev/WebGL-rendering-fix
fix WEBGL rendering and Light2d blendmode (thanks @Vareniel)
2 parents 3944671 + 2dfbfad commit 77e9ddd

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/melonjs/src/renderable/light2d.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ export default class Light2d extends Renderable {
174174
return true;
175175
}
176176

177+
/**
178+
* preDraw this Light2d (automatically called by melonJS)
179+
* Note: The renderer should set the blend mode again (after drawing other Light2d objects)
180+
* to ensure colors blend correctly in the CanvasRenderer.
181+
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance
182+
*/
183+
preDraw(renderer) {
184+
super.preDraw(renderer);
185+
renderer.setBlendMode(this.blendMode);
186+
}
187+
177188
/**
178189
* draw this Light2d (automatically called by melonJS)
179190
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance

packages/melonjs/src/video/webgl/compositors/quad_compositor.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default class QuadCompositor extends Compositor {
100100
h = pixels.height,
101101
premultipliedAlpha = true,
102102
mipmap = true,
103+
texture,
103104
) {
104105
const gl = this.gl;
105106
const isPOT = isPowerOfTwo(w) && isPowerOfTwo(h);
@@ -114,9 +115,12 @@ export default class QuadCompositor extends Compositor {
114115
? gl.REPEAT
115116
: gl.CLAMP_TO_EDGE;
116117

117-
const texture = gl.createTexture();
118+
let currentTexture = texture;
119+
if (!currentTexture) {
120+
currentTexture = gl.createTexture();
121+
}
118122

119-
this.bindTexture2D(texture, unit);
123+
this.bindTexture2D(currentTexture, unit);
120124

121125
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, rs);
122126
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, rt);
@@ -170,7 +174,7 @@ export default class QuadCompositor extends Compositor {
170174
gl.generateMipmap(gl.TEXTURE_2D);
171175
}
172176

173-
return texture;
177+
return currentTexture;
174178
}
175179

176180
/**
@@ -250,6 +254,8 @@ export default class QuadCompositor extends Compositor {
250254
w,
251255
h,
252256
texture.premultipliedAlpha,
257+
undefined,
258+
texture2D,
253259
);
254260
} else {
255261
this.bindTexture2D(texture2D, unit);

0 commit comments

Comments
 (0)