Skip to content

Commit 18e3b93

Browse files
committed
Render Pass rendering on the screen
1 parent d7c1ef1 commit 18e3b93

2 files changed

Lines changed: 86 additions & 39 deletions

File tree

v3/src/gameobjects/renderpass/RenderPass.js

Lines changed: 81 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,66 @@ var RenderPass = new Class({
4848
state.game.renderer.currentTexture = null; // force rebinding of prev texture
4949
}
5050

51+
this.flipY = true;
5152
this.setPosition(x, y);
5253
this.setSize(width, height);
5354
this.setOrigin(0, 0);
5455

5556
},
5657

58+
clearColorBuffer: function (r, g, b, a)
59+
{
60+
var gl = this.renderer.gl;
61+
if (gl)
62+
{
63+
gl.bindFramebuffer(gl.FRAMBUFFER, this.passRenderTarget.framebufferObject);
64+
gl.clearColor(r, g, b, a);
65+
gl.clear(gl.COLOR_BUFFER_BIT);
66+
gl.bindFramebuffer(gl.FRAMBUFFER, null);
67+
}
68+
},
69+
70+
clearDepthStencilBuffers: function (depth, stencil)
71+
{
72+
var gl = this.renderer.gl;
73+
if (gl)
74+
{
75+
gl.bindFramebuffer(gl.FRAMBUFFER, this.passRenderTarget.framebufferObject);
76+
gl.clearDepth(depth);
77+
gl.clearStencil(stencil);
78+
gl.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
79+
gl.bindFramebuffer(gl.FRAMBUFFER, null);
80+
}
81+
},
82+
83+
clearAllBuffers: function (depth, stencil)
84+
{
85+
var gl = this.renderer.gl;
86+
if (gl)
87+
{
88+
gl.bindFramebuffer(gl.FRAMBUFFER, this.passRenderTarget.framebufferObject);
89+
gl.clearColor(r, g, b, a);
90+
gl.clearDepth(depth);
91+
gl.clearStencil(stencil);
92+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
93+
gl.bindFramebuffer(gl.FRAMBUFFER, null);
94+
}
95+
},
96+
5797
render: function (gameObject, camera)
5898
{
5999
var gl = this.renderer.gl;
60-
this.renderer.spriteBatch.addSprite(gameObject, camera);
61-
this.renderer.spriteBatch.flush(this.passShader, this.passRenderTarget.framebufferObject);
62-
this.renderer.setRenderer(null, null, null);
100+
if (gl)
101+
{
102+
this.renderer.spriteBatch.addSprite(gameObject, camera);
103+
this.renderer.spriteBatch.flush(this.passShader, this.passRenderTarget.framebufferObject);
104+
this.renderer.setRenderer(null, null, null);
105+
}
63106
},
64107

65108
getUniformLocation: function (uniformName)
66109
{
67-
var dstShader = this.dstShader;
110+
var passShader = this.passShader;
68111
var uniforms = this.uniforms;
69112
var location;
70113

@@ -74,7 +117,7 @@ var RenderPass = new Class({
74117
}
75118
else
76119
{
77-
location = dstShader.getUniformLocation(uniformName);
120+
location = passShader.getUniformLocation(uniformName);
78121
uniforms[uniformName] = location;
79122
}
80123

@@ -83,112 +126,112 @@ var RenderPass = new Class({
83126

84127
setFloat: function (uniformName, x)
85128
{
86-
var dstShader = this.dstShader;
129+
var passShader = this.passShader;
87130

88-
if (dstShader === null)
131+
if (passShader === null)
89132
return;
90133

91-
dstShader.setConstantFloat1(this.getUniformLocation(uniformName), x);
134+
passShader.setConstantFloat1(this.getUniformLocation(uniformName), x);
92135
},
93136

94137
setFloat2: function (uniformName, x, y)
95138
{
96-
var dstShader = this.dstShader;
139+
var passShader = this.passShader;
97140

98-
if (dstShader === null)
141+
if (passShader === null)
99142
return;
100143

101-
dstShader.setConstantFloat2(this.getUniformLocation(uniformName), x, y);
144+
passShader.setConstantFloat2(this.getUniformLocation(uniformName), x, y);
102145
},
103146

104147
setFloat3: function (uniformName, x, y, z)
105148
{
106-
var dstShader = this.dstShader;
149+
var passShader = this.passShader;
107150

108-
if (dstShader === null)
151+
if (passShader === null)
109152
return;
110153

111-
dstShader.setConstantFloat3(this.getUniformLocation(uniformName), x, y, z);
154+
passShader.setConstantFloat3(this.getUniformLocation(uniformName), x, y, z);
112155
},
113156

114157
setFloat4: function (uniformName, x, y, z, w)
115158
{
116-
var dstShader = this.dstShader;
159+
var passShader = this.passShader;
117160

118-
if (dstShader === null)
161+
if (passShader === null)
119162
return;
120163

121-
dstShader.setConstantFloat4(this.getUniformLocation(uniformName), x, y, z, w);
164+
passShader.setConstantFloat4(this.getUniformLocation(uniformName), x, y, z, w);
122165
},
123166

124167
setInt: function (uniformName, x)
125168
{
126-
var dstShader = this.dstShader;
169+
var passShader = this.passShader;
127170

128-
if (dstShader === null)
171+
if (passShader === null)
129172
return;
130173

131-
dstShader.setConstantInt1(this.getUniformLocation(uniformName), x);
174+
passShader.setConstantInt1(this.getUniformLocation(uniformName), x);
132175
},
133176

134177
setInt2: function (uniformName, x, y)
135178
{
136-
var dstShader = this.dstShader;
179+
var passShader = this.passShader;
137180

138-
if (dstShader === null)
181+
if (passShader === null)
139182
return;
140183

141-
dstShader.setConstantInt2(this.getUniformLocation(uniformName), x, y);
184+
passShader.setConstantInt2(this.getUniformLocation(uniformName), x, y);
142185
},
143186

144187
setInt3: function (uniformName, x, y, z)
145188
{
146-
var dstShader = this.dstShader;
189+
var passShader = this.passShader;
147190

148-
if (dstShader === null)
191+
if (passShader === null)
149192
return;
150193

151-
dstShader.setConstantInt3(this.getUniformLocation(uniformName), x, y, z);
194+
passShader.setConstantInt3(this.getUniformLocation(uniformName), x, y, z);
152195
},
153196

154197
setInt4: function (uniformName, x, y, z, w)
155198
{
156-
var dstShader = this.dstShader;
199+
var passShader = this.passShader;
157200

158-
if (dstShader === null)
201+
if (passShader === null)
159202
return;
160203

161-
dstShader.setConstantInt4(this.getUniformLocation(uniformName), x, y, z, w);
204+
passShader.setConstantInt4(this.getUniformLocation(uniformName), x, y, z, w);
162205
},
163206

164207
setMatrix2x2: function (uniformName, matrix)
165208
{
166-
var dstShader = this.dstShader;
209+
var passShader = this.passShader;
167210

168-
if (dstShader === null)
211+
if (passShader === null)
169212
return;
170213

171-
dstShader.setConstantMatrix2x2(this.getUniformLocation(uniformName), matrix);
214+
passShader.setConstantMatrix2x2(this.getUniformLocation(uniformName), matrix);
172215
},
173216

174217
setMatrix3x3: function (uniformName, matrix)
175218
{
176-
var dstShader = this.dstShader;
219+
var passShader = this.passShader;
177220

178-
if (dstShader === null)
221+
if (passShader === null)
179222
return;
180223

181-
dstShader.setConstantMatrix3x3(this.getUniformLocation(uniformName), matrix);
224+
passShader.setConstantMatrix3x3(this.getUniformLocation(uniformName), matrix);
182225
},
183226

184227
setMatrix4x4: function (uniformName, matrix)
185228
{
186-
var dstShader = this.dstShader;
229+
var passShader = this.passShader;
187230

188-
if (dstShader === null)
231+
if (passShader === null)
189232
return;
190233

191-
dstShader.setConstantMatrix4x4(this.getUniformLocation(uniformName), matrix);
234+
passShader.setConstantMatrix4x4(this.getUniformLocation(uniformName), matrix);
192235
}
193236

194237
});

v3/src/gameobjects/renderpass/RenderPassWebGLRenderer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var RenderPassWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
22
{
3-
3+
if (this.renderMask !== this.renderFlags)
4+
{
5+
return;
6+
}
7+
renderer.spriteBatch.addSpriteTexture(src, camera, src.passRenderTexture, src.width, src.height);
48
};
59

610
module.exports = RenderPassWebGLRenderer;

0 commit comments

Comments
 (0)