1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
package org.distorted.examples.flatblur;
|
21
|
|
22
|
import android.opengl.GLSurfaceView;
|
23
|
|
24
|
import org.distorted.library.effect.EffectQuality;
|
25
|
import org.distorted.library.effect.MatrixEffectMove;
|
26
|
import org.distorted.library.effect.MatrixEffectScale;
|
27
|
import org.distorted.library.effect.PostprocessEffectBlur;
|
28
|
import org.distorted.library.main.DistortedEffects;
|
29
|
import org.distorted.library.main.DistortedLibrary;
|
30
|
import org.distorted.library.main.DistortedNode;
|
31
|
import org.distorted.library.main.DistortedScreen;
|
32
|
import org.distorted.library.main.DistortedTexture;
|
33
|
import org.distorted.library.mesh.MeshQuad;
|
34
|
import org.distorted.library.type.Static2D;
|
35
|
import org.distorted.library.type.Static3D;
|
36
|
|
37
|
import javax.microedition.khronos.egl.EGLConfig;
|
38
|
import javax.microedition.khronos.opengles.GL10;
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
class FlatBlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
43
|
{
|
44
|
private static final int HALO = 15;
|
45
|
|
46
|
private final GLSurfaceView mView;
|
47
|
private final DistortedScreen mScreen;
|
48
|
private final PostprocessEffectBlur mBlur;
|
49
|
private final DistortedNode mRedNode;
|
50
|
private final Static2D mBlurStrength;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
FlatBlurRenderer(GLSurfaceView v)
|
55
|
{
|
56
|
mView = v;
|
57
|
mScreen = new DistortedScreen();
|
58
|
|
59
|
int x = 50;
|
60
|
int scale = 200;
|
61
|
mRedNode = createNode(-x,0,1,scale,0xffff0000);
|
62
|
DistortedNode whiteNode = createNode(x,0,1,scale,0xffffffff);
|
63
|
|
64
|
mScreen.attach(mRedNode);
|
65
|
mScreen.attach(whiteNode);
|
66
|
|
67
|
mBlurStrength = new Static2D(HALO,0);
|
68
|
mBlur = new PostprocessEffectBlur(mBlurStrength);
|
69
|
mBlur.setQuality(EffectQuality.MEDIUM);
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
private DistortedNode createNode(int x, int y, int z, int scale, int color)
|
75
|
{
|
76
|
DistortedTexture texture = new DistortedTexture();
|
77
|
texture.setColorARGB(color);
|
78
|
MeshQuad mesh = new MeshQuad();
|
79
|
DistortedEffects effects = new DistortedEffects();
|
80
|
|
81
|
Static3D move = new Static3D(x,y,z);
|
82
|
|
83
|
MatrixEffectMove mainMove = new MatrixEffectMove(move);
|
84
|
MatrixEffectScale mainScale= new MatrixEffectScale(scale);
|
85
|
|
86
|
effects.apply(mainScale);
|
87
|
effects.apply(mainMove);
|
88
|
|
89
|
return new DistortedNode(texture,effects,mesh);
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public void onDrawFrame(GL10 glUnused)
|
95
|
{
|
96
|
mScreen.render(System.currentTimeMillis());
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
102
|
{
|
103
|
mScreen.resize(width,height);
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
109
|
{
|
110
|
PostprocessEffectBlur.enable();
|
111
|
DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
|
112
|
}
|
113
|
|
114
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115
|
|
116
|
public void distortedException(Exception ex)
|
117
|
{
|
118
|
android.util.Log.e("SetTexture", ex.getMessage() );
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
public void enableBlur(boolean enable)
|
124
|
{
|
125
|
DistortedEffects effects = mRedNode.getEffects();
|
126
|
long id = mBlur.getID();
|
127
|
|
128
|
if( enable ) effects.abortById(id);
|
129
|
else effects.apply(mBlur);
|
130
|
}
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
public void setBlurStrength(int strength)
|
135
|
{
|
136
|
mBlurStrength.set(HALO,strength*0.5f);
|
137
|
}
|
138
|
}
|