summaryrefslogtreecommitdiffstats
path: root/src/com/android/magicsmoke/clouds.rs
diff options
context:
space:
mode:
authorFredrik Ehnbom <fehnbom@nvidia.com>2010-10-12 09:34:04 -0700
committerMarco Nelissen <marcone@google.com>2010-10-13 09:55:17 -0700
commit229c496d4a47bd610c97af0578ce6b1e2a982c57 (patch)
tree28155fdf543f80c64cc728340cfb7651b6c520da /src/com/android/magicsmoke/clouds.rs
parentca13e07c26186e2b82721564f63108c286b5216d (diff)
downloadandroid_packages_wallpapers_MagicSmoke-229c496d4a47bd610c97af0578ce6b1e2a982c57.tar.gz
android_packages_wallpapers_MagicSmoke-229c496d4a47bd610c97af0578ce6b1e2a982c57.tar.bz2
android_packages_wallpapers_MagicSmoke-229c496d4a47bd610c97af0578ce6b1e2a982c57.zip
Performance optimizations for MagicSmoke
The MagicSmoke wallpaper was modified to be single pass multi texture rather than blended multipass. Change-Id: If838a4abd2c3fa73def46c47d1f362c8a2af3363
Diffstat (limited to 'src/com/android/magicsmoke/clouds.rs')
-rw-r--r--src/com/android/magicsmoke/clouds.rs176
1 files changed, 113 insertions, 63 deletions
diff --git a/src/com/android/magicsmoke/clouds.rs b/src/com/android/magicsmoke/clouds.rs
index 9cd28cc..5e67950 100644
--- a/src/com/android/magicsmoke/clouds.rs
+++ b/src/com/android/magicsmoke/clouds.rs
@@ -44,10 +44,33 @@ float gAlphaMul;
int gPreMul;
int gBlendFunc;
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-rs_program_store gPFSBackgroundOne;
-rs_program_store gPFSBackgroundSrc;
+typedef struct VertexShaderConstants_s {
+ float4 layer0;
+ float4 layer1;
+ float4 layer2;
+ float4 layer3;
+ float4 layer4;
+} VertexShaderConstants;
+VertexShaderConstants *gVSConstants;
+
+typedef struct FragmentShaderConstants_s {
+ float4 clearColor;
+} FragmentShaderConstants;
+FragmentShaderConstants *gFSConstants;
+
+typedef struct VertexInputs_s {
+ float4 position;
+ float2 texture0;
+} VertexInputs;
+VertexInputs *gVS;
+
+
+rs_program_fragment gPF5tex;
+rs_program_vertex gPV5tex;
+rs_program_fragment gPF4tex;
+rs_program_vertex gPV4tex;
+
+rs_program_store gPStore;
rs_allocation gTnoise1;
rs_allocation gTnoise2;
@@ -78,33 +101,81 @@ static int currentpreset;
static int lastuptime;
static float timedelta;
static float4 clearColor = {0.5f, 0.0f, 0.0f, 1.0f};
-
-void drawCloud(rs_matrix4x4 *ident, rs_allocation allocat, int idx) {
- rs_matrix4x4 mat1;
- float z = -8.f * idx;
- rsMatrixLoad(&mat1, ident);
- rsMatrixTranslate(&mat1, -gXOffset * 8.f * idx, -gTilt * idx / 3.f, 0.f);
- rsMatrixRotate(&mat1, rotation[idx], 0.f, 0.f, 1.f);
- rsgProgramVertexLoadModelMatrix(&mat1);
-
- rsgBindTexture(gPFBackground, 0, allocat);
- rsgDrawQuadTexCoords(
- -1200.0f, -1200.0f, z, // space
- 0.f + xshift[idx], 0.f, // texture
- 1200, -1200.0f, z, // space
- scale[idx] + xshift[idx], 0.f, // texture
- 1200, 1200.0f, z, // space
- scale[idx] + xshift[idx], scale[idx], // texture
- -1200.0f, 1200.0f, z, // space
- 0.f + xshift[idx], scale[idx]); // texture
+int countTextures()
+{
+ int pos = 0;
+ for (int i = 0; i < 5; i++)
+ {
+ if (gTextureMask & (1<<i))
+ pos++;
+ }
+ return pos;
+}
+#define rotate(s, a) \
+do { \
+ float __agl = (3.1415927f / 180.0f) * a; \
+ s.x = sin(__agl); \
+ s.y = cos(__agl); \
+} while (0)
+
+void update()
+{
+ rs_program_vertex pv = gPV5tex;
+ rs_program_fragment pf = gPF5tex;
+
+ if (countTextures() == 4)
+ {
+ pv = gPV4tex;
+ pf = gPF4tex;
+ }
+ rsgBindProgramFragment(pf);
+ rsgBindProgramVertex(pv);
+ rsgBindProgramStore(gPStore);
+
+ rotate(gVSConstants->layer0, rotation[0]);
+ rotate(gVSConstants->layer1, rotation[1]);
+ rotate(gVSConstants->layer2, rotation[2]);
+ rotate(gVSConstants->layer3, rotation[3]);
+ rotate(gVSConstants->layer4, rotation[4]);
+
+ gVSConstants->layer0.w = -gXOffset * 0 + xshift[0];
+ gVSConstants->layer1.w = -gXOffset * 8 + xshift[1];
+ gVSConstants->layer2.w = -gXOffset * 16 + xshift[2];
+ gVSConstants->layer3.w = -gXOffset * 24 + xshift[3];
+ gVSConstants->layer4.w = -gXOffset * 32 + xshift[4];
+
+ float m = 0.35f;
+ gVSConstants->layer0.z = m * scale[0];
+ gVSConstants->layer1.z = m * scale[1];
+ gVSConstants->layer2.z = m * scale[2];
+ gVSConstants->layer3.z = m * scale[3];
+ gVSConstants->layer4.z = m * scale[4];
+
+ gFSConstants->clearColor = clearColor;
+
+ int pos = 0;
+ for (int i = 0; i < 5; i++)
+ {
+ if (gTextureMask & (1<<i))
+ {
+ switch (i)
+ {
+ case 0: rsgBindTexture(pf, pos, gTextureSwap != 0 ? gTnoise5 : gTnoise1); break;
+ case 1: rsgBindTexture(pf, pos, gTnoise2); break;
+ case 2: rsgBindTexture(pf, pos, gTnoise3); break;
+ case 3: rsgBindTexture(pf, pos, gTnoise4); break;
+ case 4: rsgBindTexture(pf, pos, gTnoise5); break;
+ default: break;
+ }
+ pos++;
+ }
+ }
}
-void drawClouds(rs_matrix4x4 *ident) {
- rs_matrix4x4 mat1;
- rsMatrixLoad(&mat1, ident);
-
- if (gRotate != 0) {
- rotation[0] += 0.10 * timedelta;
+void drawClouds() {
+ if (gRotate != 0)
+ {
+ rotation[0] += 0.100f * timedelta;
rotation[1] += 0.102f * timedelta;
rotation[2] += 0.106f * timedelta;
rotation[3] += 0.114f * timedelta;
@@ -113,34 +184,31 @@ void drawClouds(rs_matrix4x4 *ident) {
int mask = gTextureMask;
if (mask & 1) {
- xshift[0] += 0.0010f * timedelta;
- if (gTextureSwap != 0) {
- drawCloud(&mat1, gTnoise5, 0);
- } else {
- drawCloud(&mat1, gTnoise1, 0);
- }
+ xshift[0] += 0.00100f * timedelta;
}
-
if (mask & 2) {
- xshift[1] += 0.00106 * timedelta;
- drawCloud(&mat1, gTnoise2, 1);
+ xshift[1] += 0.00106f * timedelta;
}
-
if (mask & 4) {
xshift[2] += 0.00114f * timedelta;
- drawCloud(&mat1, gTnoise3, 2);
}
-
if (mask & 8) {
xshift[3] += 0.00118f * timedelta;
- drawCloud(&mat1, gTnoise4, 3);
}
-
if (mask & 16) {
xshift[4] += 0.00127f * timedelta;
- drawCloud(&mat1, gTnoise5, 4);
}
+ update();
+
+ float z = 0;
+ rsgDrawQuad(
+ -1.0f, -1.0f, z,
+ 1.0f, -1.0f, z,
+ 1.0f, 1.0f, z,
+ -1.0f, 1.0f, z
+ );
+
// Make sure the texture coordinates don't continuously increase
int i;
for(i = 0; i < 5; i++) {
@@ -303,23 +371,6 @@ void init() {
int root(int launchID) {
int i;
- rs_matrix4x4 ident;
- float masterscale = 0.0041f;// / (gXOffset * 4.f + 1.f);
-
- rsgBindProgramVertex(gPVBackground);
- rsgBindProgramFragment(gPFBackground);
-
- rsMatrixLoadIdentity(&ident);
- rsMatrixTranslate(&ident, -gXOffset, 0.f, 0.f);
- rsMatrixScale(&ident, masterscale, masterscale, masterscale);
- //rsMatrixRotate(&ident, 0.f, 0.f, 0.f, 1.f);
- rsMatrixRotate(&ident, -gTilt, 1.f, 0.f, 0.f);
-
- if (gBlendFunc) {
- rsgBindProgramStore(gPFSBackgroundOne);
- } else {
- rsgBindProgramStore(gPFSBackgroundSrc);
- }
int now = (int)rsUptimeMillis();
timedelta = ((float)(now - lastuptime)) / 44.f;
@@ -338,14 +389,13 @@ int root(int launchID) {
clearColor.z = ((float)(gBackCol & 0xff)) / 255.0f;
makeTextures();
}
- rsgClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
if (gTextureSwap != 0) {
scale[0] = .25f;
} else {
scale[0] = 4.f;
}
- drawClouds(&ident);
+ drawClouds();
return 55;
}