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.library;
|
21
|
|
22
|
import android.app.ActivityManager;
|
23
|
import android.content.Context;
|
24
|
import android.content.pm.ConfigurationInfo;
|
25
|
import android.content.res.Resources;
|
26
|
import org.distorted.library.program.*;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
/**
|
30
|
* A singleton class used to control various global settings.
|
31
|
*/
|
32
|
public class Distorted
|
33
|
{
|
34
|
static int GLSL;
|
35
|
static String GLSL_VERSION;
|
36
|
|
37
|
static int mMargin = 0;
|
38
|
|
39
|
/**
|
40
|
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
|
41
|
* backing up our DistortedTexture.
|
42
|
* <p>
|
43
|
* This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
|
44
|
* apply different effects. Used in the copy constructor.
|
45
|
*/
|
46
|
public static final int CLONE_SURFACE = 0x1;
|
47
|
/**
|
48
|
* When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
|
49
|
* <p>
|
50
|
* This way we can have two different DistortedEffects sharing the MATRIX queue.
|
51
|
*/
|
52
|
public static final int CLONE_MATRIX = 0x2;
|
53
|
/**
|
54
|
* When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
|
55
|
* <p>
|
56
|
* This way we can have two different DistortedEffects sharing the VERTEX queue.
|
57
|
*/
|
58
|
public static final int CLONE_VERTEX = 0x4;
|
59
|
/**
|
60
|
* When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
|
61
|
* <p>
|
62
|
* This way we can have two different DistortedEffects sharing the FRAGMENT queue.
|
63
|
*/
|
64
|
public static final int CLONE_FRAGMENT= 0x8;
|
65
|
/**
|
66
|
* When creating an instance of a DistortedEffects from another instance, clone the PostProcess Effects.
|
67
|
* <p>
|
68
|
* This way we can have two different DistortedEffects sharing the POSTPROCESS queue.
|
69
|
*/
|
70
|
public static final int CLONE_POSTPROCESS= 0x10;
|
71
|
/**
|
72
|
* When creating an instance of a DistortedNode from another instance, clone the children Nodes.
|
73
|
* <p>
|
74
|
* This is mainly useful for creating many similar sub-trees and rendering then at different places
|
75
|
* on the screen with (optionally) different Effects.
|
76
|
*/
|
77
|
public static final int CLONE_CHILDREN= 0x20;
|
78
|
|
79
|
private static boolean mInitialized=false;
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
// private: hide this from Javadoc
|
83
|
|
84
|
private Distorted()
|
85
|
{
|
86
|
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
static boolean isInitialized()
|
92
|
{
|
93
|
return mInitialized;
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
/**
|
98
|
* When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
|
99
|
* I.e. best called from GLSurfaceView.onCreate().
|
100
|
* <p>
|
101
|
* Needs to be called from a thread holding the OpenGL context.
|
102
|
*
|
103
|
* @param context Context of the App using the library - used to open up Resources and read Shader code.
|
104
|
* @throws FragmentCompilationException
|
105
|
* @throws VertexCompilationException
|
106
|
* @throws VertexUniformsException
|
107
|
* @throws FragmentUniformsException
|
108
|
* @throws LinkingException
|
109
|
*/
|
110
|
public static void onCreate(final Context context)
|
111
|
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
112
|
{
|
113
|
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
114
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
115
|
android.util.Log.e("DISTORTED", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
|
116
|
|
117
|
GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 300 : 100 );
|
118
|
GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 300 es\n");
|
119
|
|
120
|
final Resources resources = context.getResources();
|
121
|
DistortedEffects.createProgram(resources);
|
122
|
EffectQueuePostprocess.createProgram(resources);
|
123
|
EffectMessageSender.startSending();
|
124
|
|
125
|
mInitialized = true;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
/**
|
130
|
* Call this so that the Library can release its internal data structures.
|
131
|
* Must be called from Activity.onPause().
|
132
|
*/
|
133
|
public static void onPause()
|
134
|
{
|
135
|
DistortedObject.onPause();
|
136
|
DistortedNode.onPause();
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
/**
|
141
|
* Call this so that the Library can release its internal data structures.
|
142
|
* Must be called from Activity.onDestroy().
|
143
|
*/
|
144
|
public static void onDestroy()
|
145
|
{
|
146
|
DistortedObject.onDestroy();
|
147
|
DistortedNode.onDestroy();
|
148
|
DistortedEffects.onDestroy();
|
149
|
DistortedEffectsPostprocess.onDestroy();
|
150
|
DistortedMaster.onDestroy();
|
151
|
EffectQueue.onDestroy();
|
152
|
EffectMessageSender.stopSending();
|
153
|
|
154
|
mInitialized = false;
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public static void setMargin(int pixels)
|
160
|
{
|
161
|
mMargin = pixels;
|
162
|
}
|
163
|
}
|