void drawSpace(float xOffset, int width, int height) {
bindTexture(NAMED_PFBackground, 0, NAMED_TSpace);
drawQuadTexCoords(
- xOffset, 0.0f, 0.0f, 0.0f, 1.0f,
- xOffset + width, 0.0f, 0.0f, 2.0f, 1.0f,
- xOffset + width, height, 0.0f, 2.0f, 0.0f,
- xOffset, height, 0.0f, 0.0f, 0.0f);
+ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ width, 0.0f, 0.0f, 2.0f, 1.0f,
+ width, height, 0.0f, 2.0f, 0.0f,
+ 0.0f, height, 0.0f, 0.0f, 0.0f);
}
void drawLights(float xOffset, int width, int height) {
private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
- private final int mWidth;
- private final int mHeight;
+ private int mWidth;
+ private int mHeight;
@SuppressWarnings({"FieldCanBeLocal"})
private ScriptC mScript;
initRS();
}
+ void stop() {
+ mRS.contextBindRootScript(null);
+ }
+
+ void start() {
+ mRS.contextBindRootScript(mScript);
+ }
+
private void initRS() {
createProgramVertex();
createProgramFragmentStore();
sb.setRoot(true);
mScript = sb.create();
- mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ mScript.setClearColor(1.0f, 0.0f, 0.0f, 1.0f);
mScript.setTimeZone(TimeZone.getDefault().getID());
mScript.bindAllocation(mState, RSID_STATE);
mScript.bindAllocation(mParticles, RSID_PARTICLES);
mScript.bindAllocation(mParticlesBuffer, RSID_PARTICLES_BUFFER);
-
- mRS.contextBindRootScript(mScript);
}
private void createScriptStructures() {
void setOffsetX(float xOffset) {
mGalaxyState.xOffset = xOffset;
mState.data(mGalaxyState);
- }
+ }
+
+ void resize(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+
+ mGalaxyState.width = width;
+ mGalaxyState.height = height;
+ mState.data(mGalaxyState);
+
+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
+ }
static class GalaxyState {
public int width;
private void createProgramVertex() {
mPvOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS);
- //mPvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight);
- mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null);
mPvBackground = builder.create();
@Override
public void onDestroy() {
super.onDestroy();
+ destroyRenderer();
+ }
+
+ private void destroyRenderer() {
+ if (mRenderer != null) {
+ mRenderer.stop();
+ mRenderer = null;
+ }
}
@Override
public void onVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
+ if (visible) {
+ mRenderer.start();
+ } else {
+ mRenderer.stop();
+ }
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
- mRenderer = new GalaxyRS(width, height);
- mRenderer.init(mRs, getResources());
+ if (mRenderer == null) {
+ mRenderer = new GalaxyRS(width, height);
+ mRenderer.init(mRs, getResources());
+ mRenderer.start();
+ } else {
+ mRenderer.resize(width, height);
+ }
}
@Override
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
+ destroyRenderer();
}
}
}
\ No newline at end of file
private Resources mResources;
private RenderScript mRS;
- private final int mWidth;
- private final int mHeight;
+ private int mWidth;
+ private int mHeight;
@SuppressWarnings({ "FieldCanBeLocal" })
private ScriptC mScript;
private int mTriangles;
private final float[] mFloatData5 = new float[5];
+ private WorldState mWorldState;
public GrassRS(int width, int height) {
mWidth = width;
mResources = res;
initRS();
}
+
+ void stop() {
+ mRS.contextBindRootScript(null);
+ }
+
+ void start() {
+ mRS.contextBindRootScript(mScript);
+ }
+
+ void resize(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ mWorldState.width = width;
+ mWorldState.height = height;
+ mState.data(mWorldState);
+
+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
+
+ // TODO: REPOSITION BLADES
+ }
+
private void initRS() {
createProgramVertex();
createProgramFragmentStore();
mScript.bindAllocation(mState, RSID_STATE);
mScript.bindAllocation(mBlades, RSID_BLADES);
mScript.bindAllocation(mBladesBuffer, RSID_BLADES_BUFFER);
-
- mRS.contextBindRootScript(mScript);
}
private void createScriptStructures() {
}
private void createState() {
- WorldState state = new WorldState();
- state.width = mWidth;
- state.height = mHeight;
- state.bladesCount = BLADES_COUNT;
- state.trianglesCount = mTriangles;
+ mWorldState = new WorldState();
+ mWorldState.width = mWidth;
+ mWorldState.height = mHeight;
+ mWorldState.bladesCount = BLADES_COUNT;
+ mWorldState.trianglesCount = mTriangles;
mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
mState = Allocation.createTyped(mRS, mStateType);
- mState.data(state);
+ mState.data(mWorldState);
}
private void createBlades() {
@Override
public void onDestroy() {
super.onDestroy();
+ destroyRenderer();
+ }
+
+ private void destroyRenderer() {
+ if (mRenderer != null) {
+ mRenderer.stop();
+ mRenderer = null;
+ }
}
@Override
public void onVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
+ if (visible) {
+ mRenderer.start();
+ } else {
+ mRenderer.stop();
+ }
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
- mRenderer = new GrassRS(width, height);
- mRenderer.init(mRs, getResources());
+ if (mRenderer == null) {
+ mRenderer = new GrassRS(width, height);
+ mRenderer.init(mRs, getResources());
+ mRenderer.start();
+ } else {
+ mRenderer.resize(width, height);
+ }
}
@Override
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
+ destroyRenderer();
}
}
}