Skip to content

Commit

Permalink
[Examples] Started to replace static members in examples with local c…
Browse files Browse the repository at this point in the history
…lass members.

The way Android apps load native .so libs causes static members to be initialized only once.
After the app is closed, even when the main entry point has exited, the next re-launch of the app
will retain the previous values of those static members because JNI does not necessarily re-load the shared library.
This makes the app partially look as if it never re-loaded.
  • Loading branch information
LukasBanana committed Aug 8, 2024
1 parent 2dca042 commit b78b7e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
18 changes: 11 additions & 7 deletions examples/Cpp/PostProcessing/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class Example_PostProcessing : public ExampleBase
}
blurSettings;

struct Animation
{
Gs::Matrix4f rotation;
float innerModelRotation = 0.0f;
}
animation;

public:

Example_PostProcessing() :
Expand Down Expand Up @@ -428,17 +435,15 @@ class Example_PostProcessing : public ExampleBase
void SetSceneSettingsOuterModel(float deltaPitch, float deltaYaw)
{
// Rotate model around X and Y axes
static Gs::Matrix4f rotation;

Gs::Matrix4f deltaRotation;
Gs::RotateFree(deltaRotation, { 1, 0, 0 }, deltaPitch);
Gs::RotateFree(deltaRotation, { 0, 1, 0 }, deltaYaw);
rotation = deltaRotation * rotation;
animation.rotation = deltaRotation * animation.rotation;

// Transform scene mesh
sceneSettings.wMatrix.LoadIdentity();
Gs::Translate(sceneSettings.wMatrix, { 0, 0, 5 });
sceneSettings.wMatrix *= rotation;
sceneSettings.wMatrix *= animation.rotation;

// Set colors and matrix
sceneSettings.diffuse = { 0.6f, 0.6f, 0.6f, 1.0f };
Expand Down Expand Up @@ -484,8 +489,7 @@ class Example_PostProcessing : public ExampleBase
#endif

// Update rotation of inner model
static float innerModelRotation;
innerModelRotation += 0.01f;
animation.innerModelRotation += 0.01f;

// Update rotation of outer model
Gs::Vector2f mouseMotion
Expand Down Expand Up @@ -563,7 +567,7 @@ class Example_PostProcessing : public ExampleBase
commands->Draw(numSceneVertices, 0);

// Draw inner scene model
SetSceneSettingsInnerModel(innerModelRotation);
SetSceneSettingsInnerModel(animation.innerModelRotation);
commands->Draw(numSceneVertices, 0);
}
commands->EndRenderPass();
Expand Down
6 changes: 3 additions & 3 deletions examples/Cpp/ShadowMapping/Scene.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#version 140

#ifdef GL_ES
#if GL_ES
precision mediump float;
precision mediump sampler2DShadow;
#endif

// Specifies whether to enable Percentage-Closer-Filtering (PCF)
//#define ENABLE_PCF
#define ENABLE_PCF 0

#define PFC_OFFSET 0.005

Expand Down Expand Up @@ -36,7 +36,7 @@ void main()
shadowPos.xyz = shadowPos.xyz * vec3(0.5, -0.5, 0.5) + 0.5;

// Sample shadow map
#ifdef ENABLE_PCF
#if ENABLE_PCF
vec3[4] offsets = vec3[4](
vec3(-PFC_OFFSET, -PFC_OFFSET, 0),
vec3(-PFC_OFFSET, +PFC_OFFSET, 0),
Expand Down
4 changes: 4 additions & 0 deletions examples/Cpp/ShadowMapping/Scene.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#version 140

#if GL_ES
precision mediump float;
#endif

layout(std140) uniform Settings
{
mat4 wMatrix;
Expand Down
4 changes: 4 additions & 0 deletions examples/Cpp/ShadowMapping/ShadowMap.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#version 140

#if GL_ES
precision mediump float;
#endif

layout(std140) uniform Settings
{
mat4 wMatrix;
Expand Down

0 comments on commit b78b7e3

Please sign in to comment.