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.content.Context;
|
23
|
import android.content.res.Resources;
|
24
|
import android.opengl.GLES30;
|
25
|
import org.distorted.library.program.*;
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
/**
|
29
|
* A singleton class used to control various global settings.
|
30
|
*/
|
31
|
public class Distorted
|
32
|
{
|
33
|
/**
|
34
|
* When creating an instance of a DistortedTexture (or Tree) from another instance, do not clone anything.
|
35
|
* Used in the copy constructor.
|
36
|
*/
|
37
|
public static final int CLONE_NOTHING = 0x0;
|
38
|
/**
|
39
|
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
|
40
|
* backing up our DistortedTexture.
|
41
|
* <p>
|
42
|
* This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
|
43
|
* apply different effects. Used in the copy constructor.
|
44
|
*/
|
45
|
public static final int CLONE_SURFACE = 0x1;
|
46
|
/**
|
47
|
* When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
|
48
|
* <p>
|
49
|
* This way we can have two different DistortedEffects sharing the MATRIX queue.
|
50
|
*/
|
51
|
public static final int CLONE_MATRIX = 0x2;
|
52
|
/**
|
53
|
* When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
|
54
|
* <p>
|
55
|
* This way we can have two different DistortedEffects sharing the VERTEX queue.
|
56
|
*/
|
57
|
public static final int CLONE_VERTEX = 0x4;
|
58
|
/**
|
59
|
* When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
|
60
|
* <p>
|
61
|
* This way we can have two different DistortedEffects sharing the FRAGMENT queue.
|
62
|
*/
|
63
|
public static final int CLONE_FRAGMENT= 0x8;
|
64
|
/**
|
65
|
* When creating an instance of a DistortedEffects from another instance, clone the PostProcess Effects.
|
66
|
* <p>
|
67
|
* This way we can have two different DistortedEffects sharing the POSTPROCESS queue.
|
68
|
*/
|
69
|
public static final int CLONE_POSTPROCESS= 0x10;
|
70
|
/**
|
71
|
* When creating an instance of a DistortedNode from another instance, clone the children Nodes.
|
72
|
* <p>
|
73
|
* This is mainly useful for creating many similar sub-trees and rendering then at different places
|
74
|
* on the screen with (optionally) different Effects.
|
75
|
*/
|
76
|
public static final int CLONE_CHILDREN= 0x20;
|
77
|
|
78
|
private static boolean mInitialized=false;
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
// private: hide this from Javadoc
|
82
|
|
83
|
private Distorted()
|
84
|
{
|
85
|
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
static boolean isInitialized()
|
91
|
{
|
92
|
return mInitialized;
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
/**
|
97
|
* When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
|
98
|
* I.e. best called from GLSurfaceView.onCreate().
|
99
|
* <p>
|
100
|
* Needs to be called from a thread holding the OpenGL context.
|
101
|
*
|
102
|
* @param context Context of the App using the library - used to open up Resources and read Shader code.
|
103
|
* @throws FragmentCompilationException
|
104
|
* @throws VertexCompilationException
|
105
|
* @throws VertexUniformsException
|
106
|
* @throws FragmentUniformsException
|
107
|
* @throws LinkingException
|
108
|
*/
|
109
|
public static void onCreate(final Context context)
|
110
|
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
111
|
{
|
112
|
final Resources resources = context.getResources();
|
113
|
|
114
|
GLES30.glDepthFunc(GLES30.GL_LEQUAL);
|
115
|
GLES30.glEnable(GLES30.GL_BLEND);
|
116
|
GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE_MINUS_SRC_ALPHA);
|
117
|
GLES30.glEnable(GLES30.GL_CULL_FACE);
|
118
|
GLES30.glCullFace(GLES30.GL_BACK);
|
119
|
GLES30.glFrontFace(GLES30.GL_CW);
|
120
|
|
121
|
DistortedEffects.createProgram(resources);
|
122
|
EffectQueuePostprocess.createProgram(resources);
|
123
|
|
124
|
DistortedNode.reset();
|
125
|
EffectMessageSender.startSending();
|
126
|
|
127
|
mInitialized = true;
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
/**
|
132
|
* Call this so that the Library can release its internal data structures.
|
133
|
* Must be called from Activity.onDestroy().
|
134
|
*/
|
135
|
public static void onDestroy()
|
136
|
{
|
137
|
DistortedSurface.onDestroy();
|
138
|
DistortedNode.onDestroy();
|
139
|
EffectQueue.onDestroy();
|
140
|
DistortedEffects.onDestroy();
|
141
|
DistortedAttachDaemon.onDestroy();
|
142
|
EffectMessageSender.stopSending();
|
143
|
|
144
|
mInitialized = false;
|
145
|
}
|
146
|
}
|