MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / render

Method render

testbed/src/SceneDemo.cpp:176–310  ·  view source on GitHub ↗

Render the scene (in multiple passes for shadow mapping)

Source from the content-addressed store, hash-verified

174
175// Render the scene (in multiple passes for shadow mapping)
176void SceneDemo::render() {
177
178 // Update the VBO for the debug infos
179 updateDebugVBO();
180
181 glEnable(GL_DEPTH_TEST);
182 glEnable(GL_CULL_FACE);
183
184 glClearColor(mBackgroundColor.r, mBackgroundColor.g, mBackgroundColor.b, mBackgroundColor.a);
185
186 Matrix4 shadowMapProjMatrix[NB_SHADOW_MAPS];
187 openglframework::Matrix4 worldToLightCameraMatrix[NB_SHADOW_MAPS];
188 for (int i = 0; i < NB_SHADOW_MAPS; i++) {
189
190 shadowMapProjMatrix[i] = mShadowMapLightCameras[i].getProjectionMatrix();
191 worldToLightCameraMatrix[i] = mShadowMapLightCameras[i].getTransformMatrix().getInverse();
192 }
193
194 // ---------- Render the scene to generate the shadow map (first pass) ----------- //
195
196 // If Shadow Mapping is enabled
197 if (mIsShadowMappingEnabled) {
198
199 // Culling switching, rendering only backface, this is done to avoid self-shadowing
200 glCullFace(GL_BACK);
201
202 // For each shadow map
203 for (int i = 0; i < NB_SHADOW_MAPS; i++) {
204
205 mFBOShadowMap[i].bind();
206
207 // Bind the shader
208 mDepthShader.bind();
209
210 // Set the variables of the shader
211 mDepthShader.setMatrix4x4Uniform("projectionMatrix", shadowMapProjMatrix[i]);
212
213 // Set the viewport to render into the shadow map texture
214 glViewport(0, 0, SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
215
216 // Clear previous frame values
217 glClear(GL_DEPTH_BUFFER_BIT);
218
219 // Disable color rendering, we only want to write to the Z-Buffer
220 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
221
222 // Render the objects of the scene
223 renderSinglePass(mDepthShader, worldToLightCameraMatrix[i]);
224
225 // Unbind the shader
226 mDepthShader.unbind();
227
228 mFBOShadowMap[i].unbind();
229 }
230
231 glDisable(GL_POLYGON_OFFSET_FILL);
232 }
233

Callers 3

renderSinglePassMethod · 0.45
renderSinglePassMethod · 0.45

Calls 13

setMatrix4x4UniformMethod · 0.80
setVector3UniformMethod · 0.80
getOriginMethod · 0.80
getDiffuseColorMethod · 0.80
setIntUniformMethod · 0.80
setVector2UniformMethod · 0.80
Vector3Class · 0.50
Vector2Class · 0.50
getInverseMethod · 0.45
bindMethod · 0.45
unbindMethod · 0.45

Tested by

no test coverage detected