| 1 |
baa47ae9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Distorted. //
|
| 5 |
|
|
// //
|
| 6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
| 7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
| 8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
| 9 |
|
|
// (at your option) any later version. //
|
| 10 |
|
|
// //
|
| 11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
| 12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
| 13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
| 14 |
|
|
// GNU General Public License for more details. //
|
| 15 |
|
|
// //
|
| 16 |
|
|
// You should have received a copy of the GNU General Public License //
|
| 17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
| 18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
|
| 20 |
32d08f39
|
Leszek Koltunski
|
package org.distorted.examples.stencil;
|
| 21 |
baa47ae9
|
Leszek Koltunski
|
|
| 22 |
|
|
import android.app.Activity;
|
| 23 |
|
|
import android.os.Bundle;
|
| 24 |
aedd9013
|
leszek
|
import android.view.View;
|
| 25 |
baa47ae9
|
Leszek Koltunski
|
|
| 26 |
aedd9013
|
leszek
|
import org.distorted.examples.R;
|
| 27 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.Distorted;
|
| 28 |
baa47ae9
|
Leszek Koltunski
|
|
| 29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 30 |
|
|
|
| 31 |
32d08f39
|
Leszek Koltunski
|
public class StencilActivity extends Activity
|
| 32 |
baa47ae9
|
Leszek Koltunski
|
{
|
| 33 |
aedd9013
|
leszek
|
private boolean mScreen;
|
| 34 |
baa47ae9
|
Leszek Koltunski
|
|
| 35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 36 |
|
|
|
| 37 |
|
|
@Override
|
| 38 |
aedd9013
|
leszek
|
protected void onCreate(Bundle savedState)
|
| 39 |
baa47ae9
|
Leszek Koltunski
|
{
|
| 40 |
aedd9013
|
leszek
|
super.onCreate(savedState);
|
| 41 |
|
|
setContentView(R.layout.stencillayout);
|
| 42 |
|
|
|
| 43 |
|
|
if( savedState==null )
|
| 44 |
|
|
{
|
| 45 |
|
|
mScreen = true;
|
| 46 |
|
|
}
|
| 47 |
baa47ae9
|
Leszek Koltunski
|
}
|
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 50 |
|
|
|
| 51 |
|
|
@Override
|
| 52 |
|
|
protected void onPause()
|
| 53 |
|
|
{
|
| 54 |
aedd9013
|
leszek
|
StencilSurfaceView view = (StencilSurfaceView) this.findViewById(R.id.stencilSurfaceView);
|
| 55 |
|
|
|
| 56 |
|
|
view.onPause();
|
| 57 |
8beaa293
|
Leszek Koltunski
|
Distorted.onPause();
|
| 58 |
baa47ae9
|
Leszek Koltunski
|
super.onPause();
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 62 |
|
|
|
| 63 |
|
|
@Override
|
| 64 |
|
|
protected void onResume()
|
| 65 |
|
|
{
|
| 66 |
aedd9013
|
leszek
|
StencilSurfaceView view = (StencilSurfaceView) this.findViewById(R.id.stencilSurfaceView);
|
| 67 |
|
|
|
| 68 |
baa47ae9
|
Leszek Koltunski
|
super.onResume();
|
| 69 |
aedd9013
|
leszek
|
view.onResume();
|
| 70 |
baa47ae9
|
Leszek Koltunski
|
}
|
| 71 |
|
|
|
| 72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 73 |
|
|
|
| 74 |
|
|
@Override
|
| 75 |
|
|
protected void onDestroy()
|
| 76 |
|
|
{
|
| 77 |
8beaa293
|
Leszek Koltunski
|
Distorted.onDestroy();
|
| 78 |
baa47ae9
|
Leszek Koltunski
|
super.onDestroy();
|
| 79 |
|
|
}
|
| 80 |
aedd9013
|
leszek
|
|
| 81 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 82 |
|
|
|
| 83 |
|
|
public void Screen(View v)
|
| 84 |
|
|
{
|
| 85 |
|
|
StencilSurfaceView view = (StencilSurfaceView) this.findViewById(R.id.stencilSurfaceView);
|
| 86 |
|
|
StencilRenderer renderer = view.getRenderer();
|
| 87 |
|
|
|
| 88 |
|
|
renderer.setScreen(true);
|
| 89 |
|
|
mScreen = true;
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 93 |
|
|
|
| 94 |
|
|
public void Framebuffer(View v)
|
| 95 |
|
|
{
|
| 96 |
|
|
StencilSurfaceView view = (StencilSurfaceView) this.findViewById(R.id.stencilSurfaceView);
|
| 97 |
|
|
StencilRenderer renderer = view.getRenderer();
|
| 98 |
|
|
|
| 99 |
|
|
renderer.setScreen(false);
|
| 100 |
|
|
mScreen = false;
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 104 |
|
|
|
| 105 |
|
|
@Override
|
| 106 |
|
|
public void onSaveInstanceState(Bundle savedInstanceState)
|
| 107 |
|
|
{
|
| 108 |
|
|
super.onSaveInstanceState(savedInstanceState);
|
| 109 |
|
|
savedInstanceState.putBoolean("screen", mScreen);
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 113 |
|
|
|
| 114 |
|
|
@Override
|
| 115 |
|
|
public void onRestoreInstanceState(Bundle savedInstanceState)
|
| 116 |
|
|
{
|
| 117 |
|
|
super.onRestoreInstanceState(savedInstanceState);
|
| 118 |
|
|
|
| 119 |
|
|
mScreen = savedInstanceState.getBoolean("screen");
|
| 120 |
|
|
|
| 121 |
|
|
if(mScreen) Screen(null);
|
| 122 |
|
|
else Framebuffer(null);
|
| 123 |
|
|
}
|
| 124 |
baa47ae9
|
Leszek Koltunski
|
}
|