• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/wallpapers/Basic


Commit MetaInfo

修订版6a500a1d5e15bd5a563995f31d0796552cc13640 (tree)
时间2010-02-12 11:09:56
作者Jason Sams <rjsams@andr...>
CommiterJason Sams

Log Message

DO NOT MERGE. Port Froyo livewallpaper support to eclair for droid..

Update grass to use fragment shaders.

Create struct for blade data.

Use indicies to reduce grass cpu usage. Fix aliasing of tips of grass.

Update to new RS texture API.

Update to new RS element API.

Update to use RS generic attrib support.

Change to user attrib types.

Disable per touch logging.

Simplify the fall water script. Remove some dead code from the java layer that was left over from the old integer mesh.

Move Fall waveform calculation to vertex shader.

Add uses-feature to the manifest.

Enable red-pulses-only mode in Nexus wallpaper.

Also load textures with CLAMP for Droid compatiblity.

Bug: 2395147
Change-Id: Id310674e1c3160a545d632b286506e55e9cbc8ad

Fix shader problems in Nexus, er, Neural Network LW.

Change-Id: I852bdf4700d61f18a006ebcf619e9d4f3b51e4cd

Fix Galaxy in landscape mode.

Author: Romain Guy <romainguy@android.com>
Committer: Jason Sams <rjsams@android.com>
On branch droid
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: src/com/android/wallpaper/galaxy/GalaxyRS.java

更改概述

差异

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -21,6 +21,8 @@
2121 xmlns:android="http://schemas.android.com/apk/res/android"
2222 package="com.android.wallpaper">
2323
24+ <uses-feature android:name="android.software.live_wallpaper" />
25+
2426 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2527 <uses-permission android:name="android.permission.CAMERA" />
2628
--- a/res/raw/fall.rs
+++ b/res/raw/fall.rs
@@ -26,21 +26,10 @@ float skyOffsetY;
2626 float g_DT;
2727 int g_LastTime;
2828
29-struct vert_s {
30- float x;
31- float y;
32- float z;
33- float s;
34- float t;
35-};
36-
3729 struct drop_s {
3830 float ampS;
3931 float ampE;
4032 float spread;
41- float spread2;
42- float invSpread;
43- float invSpread2;
4433 float x;
4534 float y;
4635 };
@@ -63,9 +52,7 @@ struct Leaves_s {
6352 };
6453
6554 struct Leaves_s gLeavesStore[LEAVES_COUNT];
66-
6755 struct Leaves_s* gLeaves[LEAVES_COUNT];
68-
6956 struct Leaves_s* gNextLeaves[LEAVES_COUNT];
7057
7158 void init() {
@@ -75,9 +62,6 @@ void init() {
7562 gDrops[ct].ampS = 0;
7663 gDrops[ct].ampE = 0;
7764 gDrops[ct].spread = 1;
78- gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread;
79- gDrops[ct].invSpread = 1 / gDrops[ct].spread;
80- gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread;
8165 }
8266 }
8367
@@ -107,10 +91,7 @@ void initLeaves() {
10791
10892 void updateDrop(int ct) {
10993 gDrops[ct].spread += 30.f * g_DT;
110- gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread;
111- gDrops[ct].invSpread = 1 / gDrops[ct].spread;
112- gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread;
113- gDrops[ct].ampE = gDrops[ct].ampS * gDrops[ct].invSpread;
94+ gDrops[ct].ampE = gDrops[ct].ampS / gDrops[ct].spread;
11495 }
11596
11697 void drop(int x, int y, float s) {
@@ -131,65 +112,20 @@ void drop(int x, int y, float s) {
131112 }
132113
133114 void generateRipples() {
134- int rippleMapSize = State->rippleMapSize;
135- int width = State->meshWidth;
136- int height = State->meshHeight;
137- int index = State->rippleIndex;
138- float ratio = (float)State->meshWidth / State->glWidth;
139- float xShift = State->xOffset * ratio * 2;
140-
141- float *vertices = loadSimpleMeshVerticesF(NAMED_WaterMesh, 0);
142- struct vert_s *vert = (struct vert_s *)vertices;
143-
144- float fw = 1.0f / width;
145- float fh = 1.0f / height;
146- int x, y, ct;
147- struct vert_s *v = vert;
148- for (y=0; y < height; y++) {
149- for (x=0; x < width; x++) {
150- struct drop_s * d = &gDrops[0];
151- float z = 0;
152-
153- for (ct = 0; ct < gMaxDrops; ct++) {
154- if (d->ampE > 0.01f) {
155- float dx = (d->x - xShift) - x;
156- float dy = d->y - y;
157- float dist2 = dx*dx + dy*dy;
158- if (dist2 < d->spread2) {
159- float dist = sqrtf(dist2);
160- float a = d->ampE * (dist * d->invSpread);
161- z += sinf(d->spread - dist) * a;
162- }
163- }
164- d++;
165- }
166- v->z = z;
167- v ++;
168- }
169- }
115+ int ct;
170116 for (ct = 0; ct < gMaxDrops; ct++) {
171- updateDrop(ct);
117+ struct drop_s * d = &gDrops[ct];
118+ vecF32_4_t *v = &Constants->Drop01;
119+ v += ct;
120+ v->x = d->x;
121+ v->y = d->y;
122+ v->z = d->ampE * 0.12f;
123+ v->w = d->spread;
172124 }
125+ Constants->Offset.x = State->xOffset;
173126
174- v = vert;
175- for (y = 0; y < height; y += 1) {
176- for (x = 0; x < width; x += 1) {
177- struct vec3_s n1, n2, n3;
178- vec3Sub(&n1, (struct vec3_s *)&(v+1)->x, (struct vec3_s *)&v->x);
179- vec3Sub(&n2, (struct vec3_s *)&(v+width)->x, (struct vec3_s *)&v->x);
180- vec3Cross(&n3, &n1, &n2);
181-
182- // Average of previous normal and N1 x N2
183- vec3Sub(&n1, (struct vec3_s *)&(v+width+1)->x, (struct vec3_s *)&v->x);
184- vec3Cross(&n2, &n1, &n2);
185- vec3Add(&n3, &n3, &n2);
186- //vec3Norm(&n3); // Not necessary for our constrained mesh.
187-
188- v->s = (float)x * fw + n3.x;// * 0.2;
189- v->t = (float)y * fh + n3.y;// * 0.2;
190- v->z = 0;
191- v += 1;
192- }
127+ for (ct = 0; ct < gMaxDrops; ct++) {
128+ updateDrop(ct);
193129 }
194130 }
195131
@@ -357,46 +293,8 @@ void drawLeaves() {
357293
358294 void drawRiverbed() {
359295 bindTexture(NAMED_PFBackground, 0, NAMED_TRiverbed);
360-
361- float matrix[16];
362- matrixLoadScale(matrix, 0.5f * 960.0f / 1024.0f, -1.0f * 800.0f / 1024.0f, 1.0f);
363- matrixTranslate(matrix, State->xOffset, 0.0f, 0.0f);
364- vpLoadTextureMatrix(matrix);
365-
366- drawSimpleMesh(NAMED_WaterMesh);
367-
368- matrixLoadIdentity(matrix);
369- vpLoadTextureMatrix(matrix);
370-}
371-
372-/*
373-void drawSky() {
374- color(1.0f, 1.0f, 1.0f, 0.5f);
375-
376- bindProgramFragment(NAMED_PFSky);
377- bindProgramFragmentStore(NAMED_PFSLeaf);
378- bindTexture(NAMED_PFSky, 0, NAMED_TSky);
379-
380- float x = skyOffsetX + State->skySpeedX;
381- float y = skyOffsetY + State->skySpeedY;
382-
383- if (x > 1.0f) x = 0.0f;
384- if (x < -1.0f) x = 0.0f;
385- if (y > 1.0f) y = 0.0f;
386-
387- skyOffsetX = x;
388- skyOffsetY = y;
389-
390- float matrix[16];
391- matrixLoadTranslate(matrix, x + State->xOffset, y, 0.0f);
392- vpLoadTextureMatrix(matrix);
393-
394296 drawSimpleMesh(NAMED_WaterMesh);
395-
396- matrixLoadIdentity(matrix);
397- vpLoadTextureMatrix(matrix);
398297 }
399-*/
400298
401299 int main(int index) {
402300 // Compute dt in seconds.
@@ -425,17 +323,17 @@ int main(int index) {
425323 genLeafDrop(gLeaves[i], randf(0.3f) + 0.1f);
426324 }
427325
428- generateRipples();
429- updateSimpleMesh(NAMED_WaterMesh);
430-
431326 if (State->rotate) {
432327 float matrix[16];
433328 matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);
434329 vpLoadModelMatrix(matrix);
435330 }
436331
332+ bindProgramVertex(NAMED_PVWater);
333+ generateRipples();
437334 drawRiverbed();
438- // drawSky();
335+
336+ bindProgramVertex(NAMED_PVSky);
439337 drawLeaves();
440338
441339 return 30;
--- a/res/raw/galaxy.rs
+++ b/res/raw/galaxy.rs
@@ -13,7 +13,7 @@
1313 // limitations under the License.
1414
1515 #pragma version(1)
16-#pragma stateVertex(PVBackground)
16+#pragma stateVertex(PVBkOrtho)
1717 #pragma stateRaster(parent)
1818 #pragma stateFragment(PFBackground)
1919 #pragma stateStore(PFSBackground)
@@ -51,25 +51,30 @@ float randomGauss() {
5151 return x1 * w;
5252 }
5353
54+float gSpeed[12000];
55+
5456 /**
5557 * Generates the properties for a given star.
5658 */
57-void createParticle(struct Stars_s *star, struct Particles_s *part, float scale) {
59+void createParticle(struct Particles_s *part, int idx, float scale) {
5860 float d = fabsf(randomGauss()) * State->galaxyRadius * 0.5f + randf(64.0f);
5961 float id = d / State->galaxyRadius;
6062 float z = randomGauss() * 0.4f * (1.0f - id);
6163 float p = -d * ELLIPSE_TWIST;
6264
65+ int r,g,b,a;
6366 if (d < State->galaxyRadius * 0.33f) {
64- part->r = (int) (220 + id * 35);
65- part->g = 220;
66- part->b = 220;
67+ r = (int) (220 + id * 35);
68+ g = 220;
69+ b = 220;
6770 } else {
68- part->r= 180;
69- part->g = 180;
70- part->b = (int) clampf(140.f + id * 115.f, 140.f, 255.f);
71+ r = 180;
72+ g = 180;
73+ b = (int) clampf(140.f + id * 115.f, 140.f, 255.f);
7174 }
72- part->a = (int) (140 + (1.0f - id) * 115);
75+ // Stash point size * 10 in Alpha
76+ a = (int) (randf2(1.2f, 2.1f) * 60);
77+ part->color = r | g<<8 | b<<16 | a<<24;
7378
7479 if (d > State->galaxyRadius * 0.15f) {
7580 z *= 0.6f * (1.0f - id);
@@ -80,14 +85,11 @@ void createParticle(struct Stars_s *star, struct Particles_s *part, float scale)
8085 // Map to the projection coordinates (viewport.x = -1.0 -> 1.0)
8186 d = mapf(-4.0f, State->galaxyRadius + 4.0f, 0.0f, scale, d);
8287
83- star->angle = randf(TWO_PI);
84- star->distance = d;
85- star->speed = randf2(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
86- star->s = cosf(p);
87- star->t = sinf(p);
88+ part->position.x = randf(TWO_PI);
89+ part->position.y = d;
90+ gSpeed[idx] = randf2(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
8891
89- part->z = z / 5.0f;
90- part->pointSize = randf2(1.2f, 2.1f) * 6;
92+ part->position.z = z / 5.0f;
9193 }
9294
9395 /**
@@ -98,15 +100,13 @@ void initParticles() {
98100 angle = 0.0f;
99101 }
100102
101- struct Stars_s *star = Stars;
102103 struct Particles_s *part = Particles;
103104 int particlesCount = State->particlesCount;
104105 float scale = State->galaxyRadius / (State->width * 0.5f);
105106
106107 int i;
107108 for (i = 0; i < particlesCount; i ++) {
108- createParticle(star, part, scale);
109- star++;
109+ createParticle(part, i, scale);
110110 part++;
111111 }
112112 }
@@ -121,7 +121,7 @@ void drawSpace(float xOffset, int width, int height) {
121121 }
122122
123123 void drawLights(float xOffset, int width, int height) {
124- bindProgramVertex(NAMED_PVStars);
124+ bindProgramVertex(NAMED_PVBkProj);
125125 bindProgramFragment(NAMED_PFBackground);
126126 bindTexture(NAMED_PFBackground, 0, NAMED_TLight1);
127127
@@ -158,26 +158,16 @@ void drawParticles(float xOffset, float offset, int width, int height) {
158158 vpLoadModelMatrix(matrix);
159159
160160 // quadratic attenuation
161- pointAttenuation(0.1f + 0.3f * fabsf(offset), 0.0f, 0.06f + 0.1f * fabsf(offset));
161+ //pointAttenuation(0.1f + 0.3f * fabsf(offset), 0.0f, 0.06f + 0.1f * fabsf(offset));
162162
163163 int radius = State->galaxyRadius;
164164 int particlesCount = State->particlesCount;
165165
166- struct Stars_s *star = Stars;
167166 struct Particles_s *vtx = Particles;
168167
169168 int i = 0;
170169 for ( ; i < particlesCount; i++) {
171- float a = star->angle + star->speed;
172- float x = star->distance * sinf(a);
173- float y = star->distance * cosf(a) * ELLIPSE_RATIO;
174-
175- vtx->x = star->t * x + star->s * y + xOffset;
176- vtx->y = star->s * x - star->t * y;
177-
178- star->angle = a;
179-
180- star++;
170+ vtx->position.x = vtx->position.x + gSpeed[i];
181171 vtx++;
182172 }
183173
--- a/res/raw/grass.rs
+++ b/res/raw/grass.rs
@@ -17,25 +17,8 @@
1717 #pragma stateFragment(PFBackground)
1818 #pragma stateStore(PFSBackground)
1919
20-#define RSID_STATE 0
21-#define RSID_BLADES 1
2220 #define RSID_BLADES_BUFFER 2
2321
24-#define BLADE_STRUCT_FIELDS_COUNT 13
25-#define BLADE_STRUCT_ANGLE 0
26-#define BLADE_STRUCT_SIZE 1
27-#define BLADE_STRUCT_XPOS 2
28-#define BLADE_STRUCT_YPOS 3
29-#define BLADE_STRUCT_OFFSET 4
30-#define BLADE_STRUCT_SCALE 5
31-#define BLADE_STRUCT_LENGTHX 6
32-#define BLADE_STRUCT_LENGTHY 7
33-#define BLADE_STRUCT_HARDNESS 8
34-#define BLADE_STRUCT_H 9
35-#define BLADE_STRUCT_S 10
36-#define BLADE_STRUCT_B 11
37-#define BLADE_STRUCT_TURBULENCEX 12
38-
3922 #define TESSELATION 0.5f
4023 #define HALF_TESSELATION 0.25f
4124
@@ -48,6 +31,21 @@
4831
4932 #define REAL_TIME 1
5033
34+void updateBlades()
35+{
36+ int bladesCount = State->bladesCount;
37+ struct Blades_s *bladeStruct = Blades;
38+
39+ int i;
40+ for (i = 0; i < bladesCount; i ++) {
41+ float xpos = randf2(-State->width, State->width);
42+ bladeStruct->xPos = xpos;
43+ bladeStruct->turbulencex = xpos * 0.006f;
44+ bladeStruct->yPos = State->height;
45+ bladeStruct++;
46+ }
47+}
48+
5149 float time(int isPreview) {
5250 if (REAL_TIME && !isPreview) {
5351 return (hour() * 3600.0f + minute() * 60.0f + second()) / SECONDS_IN_DAY;
@@ -88,91 +86,62 @@ void drawSunset(int width, int height) {
8886 drawRect(0.0f, 0.0f, width, height, 0.0f);
8987 }
9088
91-int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor,
89+int drawBlade(struct Blades_s *bladeStruct, float *bladeBuffer, int *bladeColor,
9290 float brightness, float xOffset, float now) {
9391
94- float offset = bladeStruct[BLADE_STRUCT_OFFSET];
95- float scale = bladeStruct[BLADE_STRUCT_SCALE];
96- float angle = bladeStruct[BLADE_STRUCT_ANGLE];
97- float hardness = bladeStruct[BLADE_STRUCT_HARDNESS];
98- float turbulenceX = bladeStruct[BLADE_STRUCT_TURBULENCEX];
99-
100- float xpos = bladeStruct[BLADE_STRUCT_XPOS] + xOffset;
101- float ypos = bladeStruct[BLADE_STRUCT_YPOS];
92+ float scale = bladeStruct->scale;
93+ float angle = bladeStruct->angle;
94+ float xpos = bladeStruct->xPos + xOffset;
95+ int size = bladeStruct->size;
10296
103- float lengthX = bladeStruct[BLADE_STRUCT_LENGTHX];
104- float lengthY = bladeStruct[BLADE_STRUCT_LENGTHY];
97+ int color = hsbToAbgr(bladeStruct->h, bladeStruct->s,
98+ lerpf(0, bladeStruct->b, brightness), 1.0f);
10599
106- int size = bladeStruct[BLADE_STRUCT_SIZE];
107-
108- float h = bladeStruct[BLADE_STRUCT_H];
109- float s = bladeStruct[BLADE_STRUCT_S];
110- float b = bladeStruct[BLADE_STRUCT_B];
111-
112- int color = hsbToAbgr(h, s, lerpf(0, b, brightness), 1.0f);
113-
114- float newAngle = (turbulencef2(turbulenceX, now, 4.0f) - 0.5f) * 0.5f;
115- angle = clampf(angle + (newAngle + offset - angle) * 0.15f, -MAX_BEND, MAX_BEND);
100+ float newAngle = (turbulencef2(bladeStruct->turbulencex, now, 4.0f) - 0.5f) * 0.5f;
101+ angle = clampf(angle + (newAngle + bladeStruct->offset - angle) * 0.15f, -MAX_BEND, MAX_BEND);
116102
117103 float currentAngle = HALF_PI;
118104
119105 float bottomX = xpos;
120- float bottomY = ypos;
106+ float bottomY = bladeStruct->yPos;
121107
122- float d = angle * hardness;
108+ float d = angle * bladeStruct->hardness;
123109
124- int triangles = size * 2;
110+
111+ float si = size * scale;
112+ float bottomLeft = bottomX - si;
113+ float bottomRight = bottomX + si;
114+ float bottom = bottomY + HALF_TESSELATION;
115+
116+ bladeColor[0] = color; // V1.ABGR
117+ bladeBuffer[1] = bottomLeft; // V1.X
118+ bladeBuffer[2] = bottom; // V1.Y
119+ bladeColor[5] = color; // V2.ABGR
120+ bladeBuffer[6] = bottomRight; // V2.X
121+ bladeBuffer[7] = bottom; // V2.Y
122+ bladeBuffer += 10;
123+ bladeColor += 10;
125124
126125 for ( ; size > 0; size -= 1) {
127- float topX = bottomX - cosf_fast(currentAngle) * lengthX;
128- float topY = bottomY - sinf_fast(currentAngle) * lengthY;
126+ float topX = bottomX - cosf_fast(currentAngle) * bladeStruct->lengthX;
127+ float topY = bottomY - sinf_fast(currentAngle) * bladeStruct->lengthY;
129128
130- float si = size * scale;
129+ si = (float)size * scale;
131130 float spi = si - scale;
132131
133- float bottomLeft = bottomX - si;
134- float bottomRight = bottomX + si;
135132 float topLeft = topX - spi;
136133 float topRight = topX + spi;
137- float bottom = bottomY + HALF_TESSELATION;
138134
139- // First triangle
140135 bladeColor[0] = color; // V1.ABGR
136+ bladeBuffer[1] = topLeft; // V2.X
137+ bladeBuffer[2] = topY; // V2.Y
141138
142- bladeBuffer[1] = bottomLeft; // V1.X
143- bladeBuffer[2] = bottom; // V1.Y
144-
145- bladeColor[5] = color; // V1.ABGR
146-
147- bladeBuffer[6] = topLeft; // V2.X
148- bladeBuffer[7] = topY; // V2.Y
149-
150- bladeColor[10] = color; // V3.ABGR
151-
152- bladeBuffer[11] = topRight; // V3.X
153- bladeBuffer[12] = topY; // V3.Y
154-
155- // Second triangle
156- bladeBuffer += 15;
157- bladeColor += 15;
158-
159- bladeColor[0] = color; // V1.ABGR
160-
161- bladeBuffer[1] = bottomLeft; // V1.X
162- bladeBuffer[2] = bottom; // V1.Y
163-
164- bladeColor[5] = color; // V2.ABGR
165-
166- bladeBuffer[6] = topRight; // V2.X
167- bladeBuffer[7] = topY; // V2.Y
168-
169- bladeColor[10] = color; // V3.ABGR
170-
171- bladeBuffer[11] = bottomRight; // V3.X
172- bladeBuffer[12] = bottom; // V3.Y
139+ bladeColor[5] = color; // V3.ABGR
140+ bladeBuffer[6] = topRight; // V3.X
141+ bladeBuffer[7] = topY; // V3.Y
173142
174- bladeBuffer += 15;
175- bladeColor += 15;
143+ bladeBuffer += 10;
144+ bladeColor += 10;
176145
177146 bottomX = topX;
178147 bottomY = topY;
@@ -180,21 +149,20 @@ int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor,
180149 currentAngle += d;
181150 }
182151
183- bladeStruct[BLADE_STRUCT_ANGLE] = angle;
152+ bladeStruct->angle = angle;
184153
185- // 3 vertices per triangle, 5 properties per vertex (RGBA, X, Y, S, T)
186- return triangles * 15;
154+ // 2 vertices per triangle, 5 properties per vertex (RGBA, X, Y, S, T)
155+ return bladeStruct->size * 10 + 10;
187156 }
188157
189158 void drawBlades(float brightness, float xOffset) {
190159 // For anti-aliasing
191- bindTexture(NAMED_PFBackground, 0, NAMED_TAa);
160+ bindTexture(NAMED_PFGrass, 0, NAMED_TAa);
192161
193162 int bladesCount = State->bladesCount;
194- int trianglesCount = State->trianglesCount;
195163
196164 int i = 0;
197- float *bladeStruct = loadArrayF(RSID_BLADES, 0);
165+ struct Blades_s *bladeStruct = Blades;
198166 float *bladeBuffer = loadArrayF(RSID_BLADES_BUFFER, 0);
199167 int *bladeColor = loadArrayI32(RSID_BLADES_BUFFER, 0);
200168
@@ -204,11 +172,11 @@ void drawBlades(float brightness, float xOffset) {
204172 int offset = drawBlade(bladeStruct, bladeBuffer, bladeColor, brightness, xOffset, now);
205173 bladeBuffer += offset;
206174 bladeColor += offset;
207- bladeStruct += BLADE_STRUCT_FIELDS_COUNT;
175+ bladeStruct ++;
208176 }
209177
210178 uploadToBufferObject(NAMED_BladesBuffer);
211- drawSimpleMeshRange(NAMED_BladesMesh, 0, trianglesCount * 3);
179+ drawSimpleMeshRange(NAMED_BladesMesh, 0, State->indexCount);
212180 }
213181
214182 int main(int launchID) {
@@ -262,7 +230,8 @@ int main(int launchID) {
262230 newB = 0.0f;
263231 }
264232
233+ bindProgramFragment(NAMED_PFGrass);
265234 drawBlades(newB, x);
266235
267- return 30;
236+ return 50;
268237 }
--- a/res/raw/nexus.rs
+++ b/res/raw/nexus.rs
@@ -14,7 +14,6 @@
1414
1515 #pragma version(1)
1616 #pragma stateVertex(PVOrtho)
17-#pragma stateFragment(PFTexture)
1817 #pragma stateStore(PSSolid)
1918
2019 #define MAX_PULSES 20
@@ -48,18 +47,21 @@ int gNow;
4847
4948
5049 void setColor(int c) {
51- if (c == 0) {
50+ if (State->mode == 1) {
51+ // sholes red
52+ color(0.9f, 0.1f, 0.1f, 0.8f);
53+ } else if (c == 0) {
5254 // red
53- color(1.0f, 0.0f, 0.0f, 1.0f);
55+ color(1.0f, 0.0f, 0.0f, 0.8f);
5456 } else if (c == 1) {
5557 // green
56- color(0.0f, 0.6f, 0.0f, 1.0f);
58+ color(0.0f, 0.8f, 0.0f, 0.8f);
5759 } else if (c == 2) {
5860 // blue
59- color(0.0f, 0.4f, 0.8f, 1.0f);
61+ color(0.0f, 0.4f, 0.9f, 0.8f);
6062 } else if (c == 3) {
6163 // yellow
62- color(1.0f, 0.8f, 0.0f, 1.0f);
64+ color(1.0f, 0.8f, 0.0f, 0.8f);
6365 }
6466 }
6567
@@ -115,7 +117,8 @@ void initPulses() {
115117 }
116118
117119 void drawBackground(int width, int height) {
118- bindTexture(NAMED_PFTexture, 0, NAMED_TBackground);
120+ bindProgramFragment(NAMED_PFTexture565);
121+ bindTexture(NAMED_PFTexture565, 0, NAMED_TBackground);
119122 color(1.0f, 1.0f, 1.0f, 1.0f);
120123 if (State->rotate) {
121124 drawRect(0.0f, 0.0f, height*2, width, 0.0f);
@@ -267,8 +270,8 @@ int main(int index) {
267270 gNow = uptimeMillis();
268271
269272 if (Command->command != 0) {
270- debugF("x", Command->x);
271- debugF("y", Command->y);
273+ //debugF("x", Command->x);
274+ //debugF("y", Command->y);
272275 Command->command = 0;
273276 addTap(Command->x, Command->y);
274277 }
--- /dev/null
+++ b/res/values/integers.xml
@@ -0,0 +1,3 @@
1+<resources>
2+ <integer name="nexus_mode">0</integer>
3+</resources>
--- a/src/com/android/wallpaper/fall/FallRS.java
+++ b/src/com/android/wallpaper/fall/FallRS.java
@@ -17,6 +17,7 @@
1717 package com.android.wallpaper.fall;
1818
1919 import android.os.Bundle;
20+import android.renderscript.Element;
2021 import android.renderscript.ScriptC;
2122 import android.renderscript.ProgramFragment;
2223 import android.renderscript.ProgramStore;
@@ -28,11 +29,10 @@ import android.renderscript.Type;
2829 import android.renderscript.SimpleMesh;
2930 import android.renderscript.Script;
3031 import static android.renderscript.Sampler.Value.LINEAR;
31-import static android.renderscript.Sampler.Value.WRAP;
32+import static android.renderscript.Sampler.Value.CLAMP;
3233 import static android.renderscript.ProgramStore.DepthFunc.*;
3334 import static android.renderscript.ProgramStore.BlendDstFunc;
3435 import static android.renderscript.ProgramStore.BlendSrcFunc;
35-import static android.renderscript.ProgramFragment.EnvMode.*;
3636 import static android.renderscript.Element.*;
3737
3838 import android.app.WallpaperManager;
@@ -49,16 +49,20 @@ class FallRS extends RenderScriptScene {
4949 private static final int MESH_RESOLUTION = 48;
5050
5151 private static final int RSID_STATE = 0;
52+ private static final int RSID_CONSTANTS = 1;
53+ private static final int RSID_DROP = 2;
5254
5355 private static final int TEXTURES_COUNT = 2;
5456 private static final int RSID_TEXTURE_RIVERBED = 0;
5557 private static final int RSID_TEXTURE_LEAVES = 1;
5658 private static final int RSID_TEXTURE_SKY = 2;
5759
58- private static final int RSID_RIPPLE_MAP = 1;
59- private static final int RSID_DROP = 2;
6060
6161
62+ static class Defines {
63+
64+ };
65+
6266 private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
6367
6468 @SuppressWarnings({"FieldCanBeLocal"})
@@ -71,6 +75,7 @@ class FallRS extends RenderScriptScene {
7175 private ProgramStore mPfsLeaf;
7276 @SuppressWarnings({"FieldCanBeLocal"})
7377 private ProgramVertex mPvSky;
78+ private ProgramVertex mPvWater;
7479 private ProgramVertex.MatrixAllocation mPvOrthoAlloc;
7580 @SuppressWarnings({"FieldCanBeLocal"})
7681 private Sampler mSampler;
@@ -81,14 +86,13 @@ class FallRS extends RenderScriptScene {
8186 private Type mStateType;
8287 private Type mDropType;
8388 private int mMeshWidth;
89+ private Allocation mUniformAlloc;
8490
8591 private int mMeshHeight;
8692 @SuppressWarnings({"FieldCanBeLocal"})
8793 private SimpleMesh mMesh;
8894 private WorldState mWorldState;
8995
90- private Allocation mRippleMap;
91-
9296 private float mGlHeight;
9397
9498 public FallRS(int width, int height) {
@@ -114,7 +118,7 @@ class FallRS extends RenderScriptScene {
114118 }
115119 return null;
116120 }
117-
121+
118122 @Override
119123 public void start() {
120124 super.start();
@@ -139,16 +143,19 @@ class FallRS extends RenderScriptScene {
139143
140144 @Override
141145 protected ScriptC createScript() {
146+ createMesh();
147+ createState();
142148 createProgramVertex();
143149 createProgramFragmentStore();
144150 createProgramFragment();
145- createMesh();
146- createScriptStructures();
147151 loadTextures();
148152
153+
154+
149155 ScriptC.Builder sb = new ScriptC.Builder(mRS);
150156 sb.setType(mStateType, "State", RSID_STATE);
151157 sb.setType(mDropType, "Drop", RSID_DROP);
158+ sb.setType(mUniformAlloc.getType(), "Constants", RSID_CONSTANTS);
152159 sb.setScript(mResources, R.raw.fall);
153160 Script.Invokable invokable = sb.addInvokable("initLeaves");
154161 sb.setRoot(true);
@@ -158,7 +165,7 @@ class FallRS extends RenderScriptScene {
158165 script.setTimeZone(TimeZone.getDefault().getID());
159166
160167 script.bindAllocation(mState, RSID_STATE);
161- script.bindAllocation(mRippleMap, RSID_RIPPLE_MAP);
168+ script.bindAllocation(mUniformAlloc, RSID_CONSTANTS);
162169 script.bindAllocation(mDropState, RSID_DROP);
163170
164171 invokable.execute();
@@ -167,8 +174,7 @@ class FallRS extends RenderScriptScene {
167174 }
168175
169176 private void createMesh() {
170- SimpleMesh.TriangleMeshBuilder tmb = new SimpleMesh.TriangleMeshBuilder(mRS, 3,
171- SimpleMesh.TriangleMeshBuilder.TEXTURE_0);
177+ SimpleMesh.TriangleMeshBuilder tmb = new SimpleMesh.TriangleMeshBuilder(mRS, 2, 0);
172178
173179 final int width = mWidth > mHeight ? mHeight : mWidth;
174180 final int height = mWidth > mHeight ? mWidth : mHeight;
@@ -186,11 +192,9 @@ class FallRS extends RenderScriptScene {
186192 hResolution += 2;
187193
188194 for (int y = 0; y <= hResolution; y++) {
189- final float yOffset = y * quadHeight - glHeight / 2.0f - quadHeight;
190- final float t = 1.0f - y / (float) hResolution;
195+ final float yOffset = (((float)y / hResolution) * 2.f - 1.f) * height / width;
191196 for (int x = 0; x <= wResolution; x++) {
192- tmb.setTexture(x / (float) wResolution, t);
193- tmb.addVertex(-1.0f + x * quadWidth - quadWidth, yOffset, 0.0f);
197+ tmb.addVertex(((float)x / wResolution) * 2.f - 1.f, yOffset);
194198 }
195199 }
196200
@@ -217,26 +221,12 @@ class FallRS extends RenderScriptScene {
217221 mMeshHeight = hResolution + 1;
218222 }
219223
220- private void createScriptStructures() {
221- final int rippleMapSize = (mMeshWidth + 2) * (mMeshHeight + 2);
222-
223- createState(rippleMapSize);
224- createRippleMap(rippleMapSize);
225- }
226-
227- private void createRippleMap(int rippleMapSize) {
228- final int[] rippleMap = new int[rippleMapSize * 2];
229- mRippleMap = Allocation.createSized(mRS, USER_I32(mRS), rippleMap.length);
230- mRippleMap.data(rippleMap);
231- }
232-
233224 static class WorldState {
234225 public int frameCount;
235226 public int width;
236227 public int height;
237228 public int meshWidth;
238229 public int meshHeight;
239- public int rippleMapSize;
240230 public int rippleIndex;
241231 public int leavesCount;
242232 public float glWidth;
@@ -253,13 +243,12 @@ class FallRS extends RenderScriptScene {
253243 public int dropY;
254244 }
255245
256- private void createState(int rippleMapSize) {
246+ private void createState() {
257247 mWorldState = new WorldState();
258248 mWorldState.width = mWidth;
259249 mWorldState.height = mHeight;
260250 mWorldState.meshWidth = mMeshWidth;
261251 mWorldState.meshHeight = mMeshHeight;
262- mWorldState.rippleMapSize = rippleMapSize;
263252 mWorldState.rippleIndex = 0;
264253 mWorldState.glWidth = 2.0f;
265254 mWorldState.glHeight = mGlHeight;
@@ -280,7 +269,7 @@ class FallRS extends RenderScriptScene {
280269 mDropState = Allocation.createTyped(mRS, mDropType);
281270 mDropState.data(mDrop);
282271 }
283-
272+
284273 private void loadTextures() {
285274 final Allocation[] textures = new Allocation[TEXTURES_COUNT];
286275 textures[RSID_TEXTURE_RIVERBED] = loadTexture(R.drawable.pond, "TRiverbed");
@@ -311,20 +300,20 @@ class FallRS extends RenderScriptScene {
311300 Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
312301 sampleBuilder.setMin(LINEAR);
313302 sampleBuilder.setMag(LINEAR);
314- sampleBuilder.setWrapS(WRAP);
315- sampleBuilder.setWrapT(WRAP);
303+ sampleBuilder.setWrapS(CLAMP);
304+ sampleBuilder.setWrapT(CLAMP);
316305 mSampler = sampleBuilder.create();
317306
318- ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
319- builder.setTexEnable(true, 0);
320- builder.setTexEnvMode(REPLACE, 0);
307+ ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
308+ builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
309+ ProgramFragment.Builder.Format.RGBA, 0);
321310 mPfBackground = builder.create();
322311 mPfBackground.setName("PFBackground");
323312 mPfBackground.bindSampler(mSampler, 0);
324313
325- builder = new ProgramFragment.Builder(mRS, null, null);
326- builder.setTexEnable(true, 0);
327- builder.setTexEnvMode(MODULATE, 0);
314+ builder = new ProgramFragment.Builder(mRS);
315+ builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
316+ ProgramFragment.Builder.Format.RGBA, 0);
328317 mPfSky = builder.create();
329318 mPfSky.setName("PFSky");
330319 mPfSky.bindSampler(mSampler, 0);
@@ -353,10 +342,157 @@ class FallRS extends RenderScriptScene {
353342 mPvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight);
354343
355344 ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null);
356- builder.setTextureMatrixEnable(true);
357345 mPvSky = builder.create();
358346 mPvSky.bindAllocation(mPvOrthoAlloc);
359347 mPvSky.setName("PVSky");
348+
349+ float dw = 480.f / mMeshWidth;
350+ float dh = 800.f / mMeshHeight;
351+
352+ Element.Builder eb = new Element.Builder(mRS);
353+ // Make this an array when we can.
354+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop01");
355+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop02");
356+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop03");
357+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop04");
358+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop05");
359+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop06");
360+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop07");
361+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop08");
362+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop09");
363+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop10");
364+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Offset");
365+ Element e = eb.create();
366+
367+ mUniformAlloc = Allocation.createSized(mRS, e, 1);
368+
369+
370+ ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS);
371+ String t = new String("void main() {\n" +
372+ " vec4 pos;\n" +
373+ " pos.x = ATTRIB_position.x;\n" +
374+ " pos.y = ATTRIB_position.y;\n" +
375+ " pos.z = 0.0;\n" +
376+ " pos.w = 1.0;\n" +
377+ " gl_Position = pos;\n" +
378+
379+ // When we resize the texture we will need to tweak this.
380+ " varTex0.x = (pos.x + 1.0) * 0.25;\n" +
381+ " varTex0.x += UNI_Offset.x * 0.5 * 0.85;\n" +
382+ " varTex0.y = (pos.y + 1.6666) * 0.33;\n" +
383+ " varTex0.w = 0.0;\n" +
384+ " varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
385+
386+ " pos.x += UNI_Offset.x * 2.0;\n" +
387+ " pos.x += 1.0;\n" +
388+ " pos.y += 1.0;\n" +
389+ " pos.x *= 25.0;\n" +
390+ " pos.y *= 42.0;\n" +
391+
392+ " vec2 delta;\n" +
393+ " float dist;\n" +
394+ " float amp;\n" +
395+
396+ " delta = UNI_Drop01.xy - pos.xy;\n" +
397+ " dist = length(delta);\n" +
398+ " if (dist < UNI_Drop01.w) { \n" +
399+ " amp = UNI_Drop01.z * dist;\n" +
400+ " amp /= UNI_Drop01.w * UNI_Drop01.w;\n" +
401+ " amp *= sin(UNI_Drop01.w - dist);\n" +
402+ " varTex0.xy += delta * amp;\n" +
403+ " }\n" +
404+
405+ " delta = UNI_Drop02.xy - pos.xy;\n" +
406+ " dist = length(delta);\n" +
407+ " if (dist < UNI_Drop02.w) { \n" +
408+ " amp = UNI_Drop02.z * dist;\n" +
409+ " amp /= UNI_Drop02.w * UNI_Drop02.w;\n" +
410+ " amp *= sin(UNI_Drop02.w - dist);\n" +
411+ " varTex0.xy += delta * amp;\n" +
412+ " }\n" +
413+
414+ " delta = UNI_Drop03.xy - pos.xy;\n" +
415+ " dist = length(delta);\n" +
416+ " if (dist < UNI_Drop03.w) { \n" +
417+ " amp = UNI_Drop03.z * dist;\n" +
418+ " amp /= UNI_Drop03.w * UNI_Drop03.w;\n" +
419+ " amp *= sin(UNI_Drop03.w - dist);\n" +
420+ " varTex0.xy += delta * amp;\n" +
421+ " }\n" +
422+
423+ " delta = UNI_Drop04.xy - pos.xy;\n" +
424+ " dist = length(delta);\n" +
425+ " if (dist < UNI_Drop04.w) { \n" +
426+ " amp = UNI_Drop04.z * dist;\n" +
427+ " amp /= UNI_Drop04.w * UNI_Drop04.w;\n" +
428+ " amp *= sin(UNI_Drop04.w - dist);\n" +
429+ " varTex0.xy += delta * amp;\n" +
430+ " }\n" +
431+
432+ " delta = UNI_Drop05.xy - pos.xy;\n" +
433+ " dist = length(delta);\n" +
434+ " if (dist < UNI_Drop05.w) { \n" +
435+ " amp = UNI_Drop05.z * dist;\n" +
436+ " amp /= UNI_Drop05.w * UNI_Drop05.w;\n" +
437+ " amp *= sin(UNI_Drop05.w - dist);\n" +
438+ " varTex0.xy += delta * amp;\n" +
439+ " }\n" +
440+
441+ " delta = UNI_Drop06.xy - pos.xy;\n" +
442+ " dist = length(delta);\n" +
443+ " if (dist < UNI_Drop06.w) { \n" +
444+ " amp = UNI_Drop06.z * dist;\n" +
445+ " amp /= UNI_Drop06.w * UNI_Drop06.w;\n" +
446+ " amp *= sin(UNI_Drop06.w - dist);\n" +
447+ " varTex0.xy += delta * amp;\n" +
448+ " }\n" +
449+
450+ " delta = UNI_Drop07.xy - pos.xy;\n" +
451+ " dist = length(delta);\n" +
452+ " if (dist < UNI_Drop07.w) { \n" +
453+ " amp = UNI_Drop07.z * dist;\n" +
454+ " amp /= UNI_Drop07.w * UNI_Drop07.w;\n" +
455+ " amp *= sin(UNI_Drop07.w - dist);\n" +
456+ " varTex0.xy += delta * amp;\n" +
457+ " }\n" +
458+
459+ " delta = UNI_Drop08.xy - pos.xy;\n" +
460+ " dist = length(delta);\n" +
461+ " if (dist < UNI_Drop08.w) { \n" +
462+ " amp = UNI_Drop08.z * dist;\n" +
463+ " amp /= UNI_Drop08.w * UNI_Drop08.w;\n" +
464+ " amp *= sin(UNI_Drop08.w - dist);\n" +
465+ " varTex0.xy += delta * amp;\n" +
466+ " }\n" +
467+
468+ " delta = UNI_Drop09.xy - pos.xy;\n" +
469+ " dist = length(delta);\n" +
470+ " if (dist < UNI_Drop09.w) { \n" +
471+ " amp = UNI_Drop09.z * dist;\n" +
472+ " amp /= UNI_Drop09.w * UNI_Drop09.w;\n" +
473+ " amp *= sin(UNI_Drop09.w - dist);\n" +
474+ " varTex0.xy += delta * amp;\n" +
475+ " }\n" +
476+
477+ " delta = UNI_Drop10.xy - pos.xy;\n" +
478+ " dist = length(delta);\n" +
479+ " if (dist < UNI_Drop10.w) { \n" +
480+ " amp = UNI_Drop10.z * dist;\n" +
481+ " amp /= UNI_Drop10.w * UNI_Drop10.w;\n" +
482+ " amp *= sin(UNI_Drop10.w - dist);\n" +
483+ " varTex0.xy += delta * amp;\n" +
484+ " }\n" +
485+
486+
487+ "}\n");
488+ sb.setShader(t);
489+ sb.addConstant(mUniformAlloc.getType());
490+ sb.addInput(mMesh.getVertexType(0).getElement());
491+ mPvWater = sb.create();
492+ mPvWater.bindAllocation(mPvOrthoAlloc);
493+ mPvWater.setName("PVWater");
494+ mPvWater.bindConstants(mUniformAlloc, 1);
495+
360496 }
361497
362498 void addDrop(float x, float y) {
--- a/src/com/android/wallpaper/galaxy/GalaxyRS.java
+++ b/src/com/android/wallpaper/galaxy/GalaxyRS.java
@@ -33,7 +33,6 @@ import static android.renderscript.Sampler.Value.WRAP;
3333 import static android.renderscript.ProgramStore.DepthFunc.*;
3434 import static android.renderscript.ProgramStore.BlendDstFunc;
3535 import static android.renderscript.ProgramStore.BlendSrcFunc;
36-import static android.renderscript.ProgramFragment.EnvMode.*;
3736 import static android.renderscript.Element.*;
3837 import android.graphics.Bitmap;
3938 import android.graphics.BitmapFactory;
@@ -48,8 +47,7 @@ class GalaxyRS extends RenderScriptScene {
4847 private static final int PARTICLES_COUNT = 12000;
4948
5049 private static final int RSID_STATE = 0;
51- private static final int RSID_PARTICLES = 1;
52- private static final int RSID_PARTICLES_BUFFER = 2;
50+ private static final int RSID_PARTICLES_BUFFER = 1;
5351
5452 private static final int TEXTURES_COUNT = 3;
5553 private static final int RSID_TEXTURE_SPACE = 0;
@@ -67,7 +65,9 @@ class GalaxyRS extends RenderScriptScene {
6765 @SuppressWarnings({"FieldCanBeLocal"})
6866 private ProgramStore mPfsLights;
6967 @SuppressWarnings({"FieldCanBeLocal"})
70- private ProgramVertex mPvBackground;
68+ private ProgramVertex mPvBkOrtho;
69+ @SuppressWarnings({"FieldCanBeLocal"})
70+ private ProgramVertex mPvBkProj;
7171 @SuppressWarnings({"FieldCanBeLocal"})
7272 private ProgramVertex mPvStars;
7373 @SuppressWarnings({"FieldCanBeLocal"})
@@ -84,8 +84,6 @@ class GalaxyRS extends RenderScriptScene {
8484 private GalaxyState mGalaxyState;
8585 private Type mStateType;
8686 private Allocation mState;
87- private Allocation mParticles;
88- private Type mParticlesType;
8987 private Allocation mParticlesBuffer;
9088 @SuppressWarnings({"FieldCanBeLocal"})
9189 private SimpleMesh mParticlesMesh;
@@ -100,17 +98,16 @@ class GalaxyRS extends RenderScriptScene {
10098
10199 @Override
102100 protected ScriptC createScript() {
101+ createScriptStructures();
103102 createProgramVertex();
104103 createProgramRaster();
105104 createProgramFragmentStore();
106105 createProgramFragment();
107- createScriptStructures();
108106 loadTextures();
109107
110108 ScriptC.Builder sb = new ScriptC.Builder(mRS);
111109 sb.setType(mStateType, "State", RSID_STATE);
112110 sb.setType(mParticlesMesh.getVertexType(0), "Particles", RSID_PARTICLES_BUFFER);
113- sb.setType(mParticlesType, "Stars", RSID_PARTICLES);
114111 mInitParticles = sb.addInvokable("initParticles");
115112 sb.setScript(mResources, R.raw.galaxy);
116113 sb.setRoot(true);
@@ -120,7 +117,6 @@ class GalaxyRS extends RenderScriptScene {
120117 script.setTimeZone(TimeZone.getDefault().getID());
121118
122119 script.bindAllocation(mState, RSID_STATE);
123- script.bindAllocation(mParticles, RSID_PARTICLES);
124120 script.bindAllocation(mParticlesBuffer, RSID_PARTICLES_BUFFER);
125121 mInitParticles.execute();
126122
@@ -130,14 +126,14 @@ class GalaxyRS extends RenderScriptScene {
130126 private void createScriptStructures() {
131127 createState();
132128 createParticlesMesh();
133- createParticles();
134129 }
135130
136131 private void createParticlesMesh() {
137132 final Builder elementBuilder = new Builder(mRS);
138- elementBuilder.addUNorm8RGBA("");
139- elementBuilder.addFloatXYZ("");
140- elementBuilder.addFloatPointSize("");
133+ elementBuilder.add(Element.createAttrib(mRS, Element.DataType.UNSIGNED_8,
134+ Element.DataKind.USER, 4), "color");
135+ elementBuilder.add(Element.createAttrib(mRS, Element.DataType.FLOAT_32,
136+ Element.DataKind.USER, 3), "position");
141137 final Element vertexElement = elementBuilder.create();
142138
143139 final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS);
@@ -167,6 +163,8 @@ class GalaxyRS extends RenderScriptScene {
167163 mState.data(mGalaxyState);
168164
169165 mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
166+ mPvProjectionAlloc.setupProjectionNormalized(mWidth, mHeight);
167+
170168 mInitParticles.execute();
171169 }
172170
@@ -180,14 +178,6 @@ class GalaxyRS extends RenderScriptScene {
180178 public int scale;
181179 }
182180
183- static class GalaxyParticle {
184- public float angle;
185- public float distance;
186- public float speed;
187- public float s;
188- public float t;
189- }
190-
191181 private void createState() {
192182 boolean isPreview = isPreview();
193183
@@ -207,11 +197,6 @@ class GalaxyRS extends RenderScriptScene {
207197 mState.data(mGalaxyState);
208198 }
209199
210- private void createParticles() {
211- mParticlesType = Type.createFromClass(mRS, GalaxyParticle.class, PARTICLES_COUNT, "Particle");
212- mParticles = Allocation.createTyped(mRS, mParticlesType);
213- }
214-
215200 private void loadTextures() {
216201 mTextures = new Allocation[TEXTURES_COUNT];
217202
@@ -249,9 +234,9 @@ class GalaxyRS extends RenderScriptScene {
249234 samplerBuilder.setWrapT(WRAP);
250235 mSampler = samplerBuilder.create();
251236
252- ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
253- builder.setTexEnable(true, 0);
254- builder.setTexEnvMode(REPLACE, 0);
237+ ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
238+ builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
239+ ProgramFragment.Builder.Format.RGB, 0);
255240 mPfBackground = builder.create();
256241 mPfBackground.setName("PFBackground");
257242 mPfBackground.bindSampler(mSampler, 0);
@@ -263,10 +248,10 @@ class GalaxyRS extends RenderScriptScene {
263248 samplerBuilder.setWrapT(WRAP);
264249 mStarSampler = samplerBuilder.create();
265250
266- builder = new ProgramFragment.Builder(mRS, null, null);
251+ builder = new ProgramFragment.Builder(mRS);
267252 builder.setPointSpriteTexCoordinateReplacement(true);
268- builder.setTexEnable(true, 0);
269- builder.setTexEnvMode(MODULATE, 0);
253+ builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
254+ ProgramFragment.Builder.Format.RGBA, 0);
270255 mPfStars = builder.create();
271256 mPfStars.setName("PFStars");
272257 mPfBackground.bindSampler(mStarSampler, 0);
@@ -294,15 +279,40 @@ class GalaxyRS extends RenderScriptScene {
294279 mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
295280
296281 ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null);
297- mPvBackground = builder.create();
298- mPvBackground.bindAllocation(mPvOrthoAlloc);
299- mPvBackground.setName("PVBackground");
282+ mPvBkOrtho = builder.create();
283+ mPvBkOrtho.bindAllocation(mPvOrthoAlloc);
284+ mPvBkOrtho.setName("PVBkOrtho");
300285
301286 mPvProjectionAlloc = new ProgramVertex.MatrixAllocation(mRS);
302287 mPvProjectionAlloc.setupProjectionNormalized(mWidth, mHeight);
303288
304289 builder = new ProgramVertex.Builder(mRS, null, null);
305- mPvStars = builder.create();
290+ mPvBkProj = builder.create();
291+ mPvBkProj.bindAllocation(mPvProjectionAlloc);
292+ mPvBkProj.setName("PVBkProj");
293+
294+ ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS);
295+ String t = "void main() {\n" +
296+ " float dist = ATTRIB_position.y;\n" +
297+ " float angle = ATTRIB_position.x;\n" +
298+ " float x = dist * sin(angle);\n" +
299+ " float y = dist * cos(angle) * 0.892;\n" +
300+ " float p = dist * 5.5;\n" +
301+ " float s = cos(p);\n" +
302+ " float t = sin(p);\n" +
303+ " vec4 pos;\n" +
304+ " pos.x = t * x + s * y;\n" +
305+ " pos.y = s * x - t * y;\n" +
306+ " pos.z = ATTRIB_position.z;\n" +
307+ " pos.w = 1.0;\n" +
308+ " gl_Position = UNI_MVP * pos;\n" +
309+ " gl_PointSize = ATTRIB_color.a * 10.0;\n" +
310+ " varColor.rgb = ATTRIB_color.rgb;\n" +
311+ " varColor.a = 1.0;\n" +
312+ "}\n";
313+ sb.setShader(t);
314+ sb.addInput(mParticlesMesh.getVertexType(0).getElement());
315+ mPvStars = sb.create();
306316 mPvStars.bindAllocation(mPvProjectionAlloc);
307317 mPvStars.setName("PVStars");
308318 }
--- a/src/com/android/wallpaper/grass/GrassRS.java
+++ b/src/com/android/wallpaper/grass/GrassRS.java
@@ -17,7 +17,6 @@
1717 package com.android.wallpaper.grass;
1818
1919 import android.renderscript.Sampler;
20-import static android.renderscript.ProgramFragment.EnvMode.*;
2120 import static android.renderscript.ProgramStore.DepthFunc.*;
2221 import static android.renderscript.ProgramStore.BlendSrcFunc;
2322 import static android.renderscript.ProgramStore.BlendDstFunc;
@@ -53,7 +52,7 @@ class GrassRS extends RenderScriptScene {
5352 @SuppressWarnings({"UnusedDeclaration"})
5453 private static final String LOG_TAG = "Grass";
5554 private static final boolean DEBUG = false;
56-
55+
5756 private static final int LOCATION_UPDATE_MIN_TIME = DEBUG ? 5 * 60 * 1000 : 60 * 60 * 1000; // 1 hour
5857 private static final int LOCATION_UPDATE_MIN_DISTANCE = DEBUG ? 10 : 150 * 1000; // 150 km
5958
@@ -63,32 +62,35 @@ class GrassRS extends RenderScriptScene {
6362 private static final int RSID_STATE = 0;
6463 private static final int RSID_BLADES = 1;
6564 private static final int BLADES_COUNT = 200;
66- private static final int BLADE_STRUCT_FIELDS_COUNT = 13;
67- private static final int BLADE_STRUCT_ANGLE = 0;
68- private static final int BLADE_STRUCT_SIZE = 1;
69- private static final int BLADE_STRUCT_XPOS = 2;
70- private static final int BLADE_STRUCT_YPOS = 3;
71- private static final int BLADE_STRUCT_OFFSET = 4;
72- private static final int BLADE_STRUCT_SCALE = 5;
73- private static final int BLADE_STRUCT_LENGTHX = 6;
74- private static final int BLADE_STRUCT_LENGTHY = 7;
75- private static final int BLADE_STRUCT_HARDNESS = 8;
76- private static final int BLADE_STRUCT_H = 9;
77- private static final int BLADE_STRUCT_S = 10;
78- private static final int BLADE_STRUCT_B = 11;
79- private static final int BLADE_STRUCT_TURBULENCEX = 12;
65+
66+ class BladesStruct {
67+ public float angle;
68+ public int size;
69+ public float xPos;
70+ public float yPos;
71+ public float offset;
72+ public float scale;
73+ public float lengthX;
74+ public float lengthY;
75+ public float hardness;
76+ public float h;
77+ public float s;
78+ public float b;
79+ public float turbulencex;
80+ };
8081
8182 private static final int RSID_BLADES_BUFFER = 2;
8283
84+ private ScriptC.Invokable mUpdateBladesInvokable;
8385 @SuppressWarnings({ "FieldCanBeLocal" })
8486 private ProgramFragment mPfBackground;
8587 @SuppressWarnings({ "FieldCanBeLocal" })
88+ private ProgramFragment mPfGrass;
89+ @SuppressWarnings({ "FieldCanBeLocal" })
8690 private ProgramStore mPfsBackground;
8791 @SuppressWarnings({ "FieldCanBeLocal" })
8892 private ProgramVertex mPvBackground;
8993 @SuppressWarnings({"FieldCanBeLocal"})
90- private Sampler mSampler;
91- @SuppressWarnings({"FieldCanBeLocal"})
9294 private ProgramVertex.MatrixAllocation mPvOrthoAlloc;
9395
9496 @SuppressWarnings({ "FieldCanBeLocal" })
@@ -97,13 +99,17 @@ class GrassRS extends RenderScriptScene {
9799 private Type mStateType;
98100 private Allocation mState;
99101
102+ private Type mBladesType;
100103 private Allocation mBlades;
101104 private Allocation mBladesBuffer;
105+ private Allocation mBladesIndicies;
102106 @SuppressWarnings({"FieldCanBeLocal"})
103107 private SimpleMesh mBladesMesh;
104108
105- private int mTriangles;
106- private float[] mBladesData;
109+
110+ private int mVerticies;
111+ private int mIndicies;
112+ private int[] mBladeSizes;
107113 private final float[] mFloatData5 = new float[5];
108114
109115 private WorldState mWorldState;
@@ -132,7 +138,7 @@ class GrassRS extends RenderScriptScene {
132138 filter.addAction(Intent.ACTION_DATE_CHANGED);
133139 filter.addAction(Intent.ACTION_TIME_CHANGED);
134140 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
135-
141+
136142 mContext.registerReceiver(mTimezoneTracker, filter);
137143 }
138144
@@ -153,7 +159,7 @@ class GrassRS extends RenderScriptScene {
153159 mContext.unregisterReceiver(mTimezoneTracker);
154160 mTimezoneTracker = null;
155161 }
156-
162+
157163 if (mLocationUpdater != null) {
158164 mLocationManager.removeUpdates(mLocationUpdater);
159165 mLocationUpdater = null;
@@ -168,27 +174,24 @@ class GrassRS extends RenderScriptScene {
168174 mWorldState.height = height;
169175 mState.data(mWorldState);
170176
171- final float[] blades = mBladesData;
172- for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) {
173- updateBlade(blades, i);
174- }
175- mBlades.data(blades);
176-
177- mPvOrthoAlloc.setupOrthoWindow(width, height);
177+ mUpdateBladesInvokable.execute();
178+ mPvOrthoAlloc.setupOrthoWindow(width, height);
178179 }
179180
180181 @Override
181182 protected ScriptC createScript() {
182183 createProgramVertex();
183184 createProgramFragmentStore();
185+ loadTextures();
184186 createProgramFragment();
185187 createScriptStructures();
186- loadTextures();
187188
188189 ScriptC.Builder sb = new ScriptC.Builder(mRS);
189190 sb.setType(mStateType, "State", RSID_STATE);
191+ sb.setType(mBladesType, "Blades", RSID_BLADES);
190192 sb.setScript(mResources, R.raw.grass);
191193 sb.setRoot(true);
194+ mUpdateBladesInvokable = sb.addInvokable("updateBlades");
192195
193196 ScriptC script = sb.create();
194197 script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -214,7 +217,7 @@ class GrassRS extends RenderScriptScene {
214217
215218 static class WorldState {
216219 public int bladesCount;
217- public int trianglesCount;
220+ public int indexCount;
218221 public int width;
219222 public int height;
220223 public float xOffset;
@@ -232,7 +235,7 @@ class GrassRS extends RenderScriptScene {
232235 mWorldState.width = mWidth;
233236 mWorldState.height = mHeight;
234237 mWorldState.bladesCount = BLADES_COUNT;
235- mWorldState.trianglesCount = mTriangles;
238+ mWorldState.indexCount = mIndicies;
236239 mWorldState.isPreview = isPreview ? 1 : 0;
237240 if (isPreview) {
238241 mWorldState.xOffset = 0.5f;
@@ -244,32 +247,35 @@ class GrassRS extends RenderScriptScene {
244247 }
245248
246249 private void createBlades() {
247- int triangles = 0;
248-
249- mBladesData = new float[BLADES_COUNT * BLADE_STRUCT_FIELDS_COUNT];
250-
251- final float[] blades = mBladesData;
252- for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) {
253- triangles += createBlade(blades, i);
250+ mVerticies = 0;
251+ mIndicies = 0;
252+
253+ mBladesType = Type.createFromClass(mRS, BladesStruct.class, BLADES_COUNT, "Blade");
254+ mBlades = Allocation.createTyped(mRS, mBladesType);
255+ BladesStruct bs = new BladesStruct();
256+
257+ mBladeSizes = new int[BLADES_COUNT];
258+ for (int i = 0; i < BLADES_COUNT; i++) {
259+ createBlade(bs);
260+ mIndicies += bs.size * 2 * 3;
261+ mVerticies += bs.size + 2;
262+ mBlades.subData(i, bs);
263+ mBladeSizes[i] = bs.size;
254264 }
255265
256- mBlades = Allocation.createSized(mRS, USER_F32(mRS), blades.length);
257- mBlades.data(blades);
258-
259- mTriangles = triangles;
260-
261- createMesh(triangles);
266+ createMesh();
262267 }
263268
264- private void createMesh(int triangles) {
269+ private void createMesh() {
265270 Builder elementBuilder = new Builder(mRS);
266- elementBuilder.addUNorm8RGBA();
267- elementBuilder.addFloatXY();
268- elementBuilder.addFloatST();
271+ elementBuilder.add(Element.ATTRIB_COLOR_U8_4(mRS), "color");
272+ elementBuilder.add(Element.ATTRIB_POSITION_2(mRS), "position");
273+ elementBuilder.add(Element.ATTRIB_TEXTURE_2(mRS), "texture");
269274 final Element vertexElement = elementBuilder.create();
270275
271276 final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS);
272- final int vertexSlot = meshBuilder.addVertexType(vertexElement, triangles * 3);
277+ final int vertexSlot = meshBuilder.addVertexType(vertexElement, mVerticies * 2);
278+ meshBuilder.setIndexType(Element.INDEX_16(mRS), mIndicies);
273279 meshBuilder.setPrimitive(Primitive.TRIANGLE);
274280 mBladesMesh = meshBuilder.create();
275281 mBladesMesh.setName("BladesMesh");
@@ -277,74 +283,65 @@ class GrassRS extends RenderScriptScene {
277283 mBladesBuffer = mBladesMesh.createVertexAllocation(vertexSlot);
278284 mBladesBuffer.setName("BladesBuffer");
279285 mBladesMesh.bindVertexAllocation(mBladesBuffer, 0);
286+ mBladesIndicies = mBladesMesh.createIndexAllocation();
287+ mBladesMesh.bindIndexAllocation(mBladesIndicies);
280288
281289 // Assign the texture coordinates of each triangle
282290 final float[] floatData = mFloatData5;
283291 final Allocation buffer = mBladesBuffer;
284292
285- int bufferIndex = 0;
286- for (int i = 0; i < triangles; i += 2) {
287- floatData[3] = 0.0f;
288- floatData[4] = 1.0f;
289- buffer.subData1D(bufferIndex, 1, floatData);
290- bufferIndex++;
293+ short[] idx = new short[mIndicies];
291294
295+ int bufferIndex = 0;
296+ int i2 = 0;
297+ for (int i = 0; i < mVerticies; i +=2) {
292298 floatData[3] = 0.0f;
293299 floatData[4] = 0.0f;
294- buffer.subData1D(bufferIndex, 1, floatData);
295- bufferIndex++;
300+ buffer.subData1D(bufferIndex++, 1, floatData);
296301
297302 floatData[3] = 1.0f;
298303 floatData[4] = 0.0f;
299- buffer.subData1D(bufferIndex, 1, floatData);
300- bufferIndex++;
301-
302- floatData[3] = 0.0f;
303- floatData[4] = 0.0f;
304- buffer.subData1D(bufferIndex, 1, floatData);
305- bufferIndex++;
306-
307- floatData[3] = 1.0f;
308- floatData[4] = 1.0f;
309- buffer.subData1D(bufferIndex, 1, floatData);
310- bufferIndex++;
304+ buffer.subData1D(bufferIndex++, 1, floatData);
305+ }
311306
312- floatData[3] = 1.0f;
313- floatData[4] = 0.0f;
314- buffer.subData1D(bufferIndex, 1, floatData);
315- bufferIndex++;
307+ int idxIdx = 0;
308+ int vtxIdx = 0;
309+ for (int i = 0; i < mBladeSizes.length; i++) {
310+ for (int ct = 0; ct < mBladeSizes[i]; ct ++) {
311+ idx[idxIdx + 0] = (short)(vtxIdx + 0);
312+ idx[idxIdx + 1] = (short)(vtxIdx + 1);
313+ idx[idxIdx + 2] = (short)(vtxIdx + 2);
314+ idx[idxIdx + 3] = (short)(vtxIdx + 1);
315+ idx[idxIdx + 4] = (short)(vtxIdx + 3);
316+ idx[idxIdx + 5] = (short)(vtxIdx + 2);
317+ idxIdx += 6;
318+ vtxIdx += 2;
319+ }
320+ vtxIdx += 2;
316321 }
317- }
318322
319- private void updateBlade(float[] blades, int index) {
320- final int xpos = random(-mWidth, mWidth);
321- blades[index + BLADE_STRUCT_XPOS] = xpos;
322- blades[index + BLADE_STRUCT_TURBULENCEX] = xpos * 0.006f;
323- blades[index + BLADE_STRUCT_YPOS] = mHeight;
323+ mBladesIndicies.data(idx);
324+ mBladesIndicies.uploadToBufferObject();
324325 }
325326
326- private int createBlade(float[] blades, int index) {
327+ private void createBlade(BladesStruct blades) {
327328 final float size = random(4.0f) + 4.0f;
328329 final int xpos = random(-mWidth, mWidth);
329330
330331 //noinspection PointlessArithmeticExpression
331- blades[index + BLADE_STRUCT_ANGLE] = 0.0f;
332- blades[index + BLADE_STRUCT_SIZE] = size / TESSELATION;
333- blades[index + BLADE_STRUCT_XPOS] = xpos;
334- blades[index + BLADE_STRUCT_YPOS] = mHeight;
335- blades[index + BLADE_STRUCT_OFFSET] = random(0.2f) - 0.1f;
336- blades[index + BLADE_STRUCT_SCALE] = 4.0f / (size / TESSELATION) +
337- (random(0.6f) + 0.2f) * TESSELATION;
338- blades[index + BLADE_STRUCT_LENGTHX] = (random(4.5f) + 3.0f) * TESSELATION * size;
339- blades[index + BLADE_STRUCT_LENGTHY] = (random(5.5f) + 2.0f) * TESSELATION * size;
340- blades[index + BLADE_STRUCT_HARDNESS] = (random(1.0f) + 0.2f) * TESSELATION;
341- blades[index + BLADE_STRUCT_H] = random(0.02f) + 0.2f;
342- blades[index + BLADE_STRUCT_S] = random(0.22f) + 0.78f;
343- blades[index + BLADE_STRUCT_B] = random(0.65f) + 0.35f;
344- blades[index + BLADE_STRUCT_TURBULENCEX] = xpos * 0.006f;
345-
346- // Each blade is made of "size" quads, so we double to count the triangles
347- return (int) (blades[index + BLADE_STRUCT_SIZE]) * 2;
332+ blades.angle = 0.0f;
333+ blades.size = (int)(size / TESSELATION);
334+ blades.xPos = xpos;
335+ blades.yPos = mHeight;
336+ blades.offset = random(0.2f) - 0.1f;
337+ blades.scale = 4.0f / (size / TESSELATION) + (random(0.6f) + 0.2f) * TESSELATION;
338+ blades.lengthX = (random(4.5f) + 3.0f) * TESSELATION * size;
339+ blades.lengthY = (random(5.5f) + 2.0f) * TESSELATION * size;
340+ blades.hardness = (random(1.0f) + 0.2f) * TESSELATION;
341+ blades.h = random(0.02f) + 0.2f;
342+ blades.s = random(0.22f) + 0.78f;
343+ blades.b = random(0.65f) + 0.35f;
344+ blades.turbulencex = xpos * 0.006f;
348345 }
349346
350347 private void loadTextures() {
@@ -367,10 +364,21 @@ class GrassRS extends RenderScriptScene {
367364 final Type.Builder builder = new Type.Builder(mRS, A_8(mRS));
368365 builder.add(Dimension.X, width);
369366 builder.add(Dimension.Y, height);
367+ builder.add(Dimension.LOD, 1);
370368
371369 final Allocation allocation = Allocation.createTyped(mRS, builder.create());
372- allocation.data(data);
373370 allocation.setName(name);
371+
372+ int[] grey1 = new int[] {0x3f3f3f3f};
373+ int[] grey2 = new int[] {0x00000000};
374+ Allocation.Adapter2D a = allocation.createAdapter2D();
375+ a.setConstraint(Dimension.LOD, 0);
376+ a.subData(0, 0, 4, 1, data);
377+ a.setConstraint(Dimension.LOD, 1);
378+ a.subData(0, 0, 2, 1, grey1);
379+ a.setConstraint(Dimension.LOD, 2);
380+ a.subData(0, 0, 1, 1, grey2);
381+
374382 return allocation;
375383 }
376384
@@ -383,18 +391,29 @@ class GrassRS extends RenderScriptScene {
383391
384392 private void createProgramFragment() {
385393 Sampler.Builder samplerBuilder = new Sampler.Builder(mRS);
386- samplerBuilder.setMin(LINEAR);
394+ samplerBuilder.setMin(LINEAR_MIP_LINEAR);
387395 samplerBuilder.setMag(LINEAR);
388396 samplerBuilder.setWrapS(WRAP);
389397 samplerBuilder.setWrapT(WRAP);
390- mSampler = samplerBuilder.create();
391-
392- ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
393- builder.setTexEnable(true, 0);
394- builder.setTexEnvMode(REPLACE, 0);
398+ Sampler sl = samplerBuilder.create();
399+
400+ samplerBuilder.setMin(NEAREST);
401+ samplerBuilder.setMag(NEAREST);
402+ Sampler sn = samplerBuilder.create();
403+
404+ ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
405+ builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
406+ ProgramFragment.Builder.Format.ALPHA, 0);
407+ mPfGrass = builder.create();
408+ mPfGrass.setName("PFGrass");
409+ mPfGrass.bindSampler(sl, 0);
410+
411+ builder = new ProgramFragment.Builder(mRS);
412+ builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
413+ ProgramFragment.Builder.Format.RGB, 0);
395414 mPfBackground = builder.create();
396415 mPfBackground.setName("PFBackground");
397- mPfBackground.bindSampler(mSampler, 0);
416+ mPfBackground.bindSampler(sn, 0);
398417 }
399418
400419 private void createProgramFragmentStore() {
@@ -412,7 +431,6 @@ class GrassRS extends RenderScriptScene {
412431 mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
413432
414433 ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
415- pvb.setTextureMatrixEnable(true);
416434 mPvBackground = pvb.create();
417435 mPvBackground.bindAllocation(mPvOrthoAlloc);
418436 mPvBackground.setName("PVBackground");
--- a/src/com/android/wallpaper/nexus/NexusRS.java
+++ b/src/com/android/wallpaper/nexus/NexusRS.java
@@ -18,15 +18,15 @@ package com.android.wallpaper.nexus;
1818
1919 import static android.renderscript.Element.RGBA_8888;
2020 import static android.renderscript.Element.RGB_565;
21-import static android.renderscript.ProgramFragment.EnvMode.MODULATE;
22-import static android.renderscript.ProgramFragment.EnvMode.REPLACE;
2321 import static android.renderscript.ProgramStore.DepthFunc.ALWAYS;
2422 import static android.renderscript.Sampler.Value.LINEAR;
23+import static android.renderscript.Sampler.Value.CLAMP;
2524 import static android.renderscript.Sampler.Value.WRAP;
2625
2726 import com.android.wallpaper.R;
2827 import com.android.wallpaper.RenderScriptScene;
2928
29+import android.content.res.Resources;
3030 import android.graphics.Bitmap;
3131 import android.graphics.BitmapFactory;
3232 import android.graphics.Rect;
@@ -56,6 +56,7 @@ class NexusRS extends RenderScriptScene {
5656 private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
5757
5858 private ProgramFragment mPfTexture;
59+ private ProgramFragment mPfTexture565;
5960
6061 private ProgramFragment mPfColor;
6162
@@ -67,7 +68,8 @@ class NexusRS extends RenderScriptScene {
6768
6869 private ProgramVertex.MatrixAllocation mPvOrthoAlloc;
6970
70- private Sampler mSampler;
71+ private Sampler mClampSampler;
72+ private Sampler mWrapSampler;
7173
7274 private Allocation mState;
7375
@@ -148,6 +150,7 @@ class NexusRS extends RenderScriptScene {
148150 public int rotate;
149151 public int isPreview;
150152 public float xOffset;
153+ public int mode;
151154 }
152155
153156 static class CommandState {
@@ -163,6 +166,12 @@ class NexusRS extends RenderScriptScene {
163166 mWorldState.rotate = mWidth > mHeight ? 1 : 0;
164167 mWorldState.isPreview = isPreview() ? 1 : 0;
165168
169+ try {
170+ mWorldState.mode = mResources.getInteger(R.integer.nexus_mode);
171+ } catch (Resources.NotFoundException exc) {
172+ mWorldState.mode = 0; // standard nexus mode
173+ }
174+
166175 mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
167176 mState = Allocation.createTyped(mRS, mStateType);
168177 mState.data(mWorldState);
@@ -203,26 +212,37 @@ class NexusRS extends RenderScriptScene {
203212 }
204213
205214 private void createProgramFragment() {
215+ // sampler and program fragment for pulses
206216 Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
207217 sampleBuilder.setMin(LINEAR);
208218 sampleBuilder.setMag(LINEAR);
209219 sampleBuilder.setWrapS(WRAP);
210220 sampleBuilder.setWrapT(WRAP);
211- mSampler = sampleBuilder.create();
212-
213- ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
214- builder.setTexEnable(true, 0);
215- builder.setTexEnvMode(MODULATE, 0);
221+ mWrapSampler = sampleBuilder.create();
222+ ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
223+ builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
224+ ProgramFragment.Builder.Format.RGBA, 0);
216225 mPfTexture = builder.create();
217226 mPfTexture.setName("PFTexture");
218- mPfTexture.bindSampler(mSampler, 0);
227+ mPfTexture.bindSampler(mWrapSampler, 0);
219228
220- builder = new ProgramFragment.Builder(mRS, null, null);
221- builder.setTexEnable(true, 0);
222- builder.setTexEnvMode(REPLACE, 0);
229+ builder = new ProgramFragment.Builder(mRS);
230+ builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
231+ ProgramFragment.Builder.Format.RGB, 0);
223232 mPfColor = builder.create();
224233 mPfColor.setName("PFColor");
225- mPfColor.bindSampler(mSampler, 0);
234+ mPfColor.bindSampler(mWrapSampler, 0);
235+
236+ // sampler and program fragment for background image
237+ sampleBuilder.setWrapS(CLAMP);
238+ sampleBuilder.setWrapT(CLAMP);
239+ mClampSampler = sampleBuilder.create();
240+ builder = new ProgramFragment.Builder(mRS);
241+ builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
242+ ProgramFragment.Builder.Format.RGB, 0);
243+ mPfTexture565 = builder.create();
244+ mPfTexture565.setName("PFTexture565");
245+ mPfTexture565.bindSampler(mClampSampler, 0);
226246 }
227247
228248 private void createProgramFragmentStore() {
@@ -278,4 +298,4 @@ class NexusRS extends RenderScriptScene {
278298 mCommand.command = command;
279299 mCommandAllocation.data(mCommand);
280300 }
281-}
\ No newline at end of file
301+}