1 |
d333eb6b
|
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 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
21 |
|
|
|
22 |
7845dc66
|
Leszek Koltunski
|
import android.content.Context;
|
23 |
d6e94c84
|
Leszek Koltunski
|
import android.content.res.Resources;
|
24 |
432442f9
|
Leszek Koltunski
|
import org.distorted.library.program.*;
|
25 |
6a06a912
|
Leszek Koltunski
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
|
|
/**
|
28 |
|
|
* A singleton class used to control various global settings.
|
29 |
|
|
*/
|
30 |
|
|
public class Distorted
|
31 |
39cbf9dc
|
Leszek Koltunski
|
{
|
32 |
f2367b75
|
Leszek Koltunski
|
static final String glslVersion="#version 300 es\n";
|
33 |
6a06a912
|
Leszek Koltunski
|
/**
|
34 |
cacc63de
|
Leszek Koltunski
|
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
|
35 |
|
|
* backing up our DistortedTexture.
|
36 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
37 |
cacc63de
|
Leszek Koltunski
|
* This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
|
38 |
6a06a912
|
Leszek Koltunski
|
* apply different effects. Used in the copy constructor.
|
39 |
|
|
*/
|
40 |
29a06526
|
Leszek Koltunski
|
public static final int CLONE_SURFACE = 0x1;
|
41 |
6a06a912
|
Leszek Koltunski
|
/**
|
42 |
cacc63de
|
Leszek Koltunski
|
* When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
|
43 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
44 |
cacc63de
|
Leszek Koltunski
|
* This way we can have two different DistortedEffects sharing the MATRIX queue.
|
45 |
6a06a912
|
Leszek Koltunski
|
*/
|
46 |
015642fb
|
Leszek Koltunski
|
public static final int CLONE_MATRIX = 0x2;
|
47 |
6a06a912
|
Leszek Koltunski
|
/**
|
48 |
cacc63de
|
Leszek Koltunski
|
* When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
|
49 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
50 |
cacc63de
|
Leszek Koltunski
|
* This way we can have two different DistortedEffects sharing the VERTEX queue.
|
51 |
6a06a912
|
Leszek Koltunski
|
*/
|
52 |
|
|
public static final int CLONE_VERTEX = 0x4;
|
53 |
|
|
/**
|
54 |
cacc63de
|
Leszek Koltunski
|
* When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
|
55 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
56 |
cacc63de
|
Leszek Koltunski
|
* This way we can have two different DistortedEffects sharing the FRAGMENT queue.
|
57 |
6a06a912
|
Leszek Koltunski
|
*/
|
58 |
|
|
public static final int CLONE_FRAGMENT= 0x8;
|
59 |
d6e94c84
|
Leszek Koltunski
|
/**
|
60 |
|
|
* When creating an instance of a DistortedEffects from another instance, clone the PostProcess Effects.
|
61 |
|
|
* <p>
|
62 |
|
|
* This way we can have two different DistortedEffects sharing the POSTPROCESS queue.
|
63 |
|
|
*/
|
64 |
|
|
public static final int CLONE_POSTPROCESS= 0x10;
|
65 |
6a06a912
|
Leszek Koltunski
|
/**
|
66 |
a09ada4c
|
Leszek Koltunski
|
* When creating an instance of a DistortedNode from another instance, clone the children Nodes.
|
67 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
68 |
cacc63de
|
Leszek Koltunski
|
* This is mainly useful for creating many similar sub-trees and rendering then at different places
|
69 |
|
|
* on the screen with (optionally) different Effects.
|
70 |
6a06a912
|
Leszek Koltunski
|
*/
|
71 |
d6e94c84
|
Leszek Koltunski
|
public static final int CLONE_CHILDREN= 0x20;
|
72 |
b3618cb5
|
Leszek Koltunski
|
|
73 |
55c14a19
|
Leszek Koltunski
|
private static boolean mInitialized=false;
|
74 |
6a06a912
|
Leszek Koltunski
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
c638c1b0
|
Leszek Koltunski
|
// private: hide this from Javadoc
|
77 |
6a06a912
|
Leszek Koltunski
|
|
78 |
|
|
private Distorted()
|
79 |
|
|
{
|
80 |
|
|
|
81 |
|
|
}
|
82 |
|
|
|
83 |
421c2728
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
|
|
static boolean isInitialized()
|
86 |
|
|
{
|
87 |
55c14a19
|
Leszek Koltunski
|
return mInitialized;
|
88 |
421c2728
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
/**
|
92 |
|
|
* When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
|
93 |
432442f9
|
Leszek Koltunski
|
* I.e. best called from GLSurfaceView.onCreate().
|
94 |
6a06a912
|
Leszek Koltunski
|
* <p>
|
95 |
432442f9
|
Leszek Koltunski
|
* Needs to be called from a thread holding the OpenGL context.
|
96 |
6a06a912
|
Leszek Koltunski
|
*
|
97 |
015642fb
|
Leszek Koltunski
|
* @param context Context of the App using the library - used to open up Resources and read Shader code.
|
98 |
6a06a912
|
Leszek Koltunski
|
* @throws FragmentCompilationException
|
99 |
|
|
* @throws VertexCompilationException
|
100 |
|
|
* @throws VertexUniformsException
|
101 |
|
|
* @throws FragmentUniformsException
|
102 |
|
|
* @throws LinkingException
|
103 |
|
|
*/
|
104 |
432442f9
|
Leszek Koltunski
|
public static void onCreate(final Context context)
|
105 |
|
|
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
106 |
d6e94c84
|
Leszek Koltunski
|
{
|
107 |
|
|
final Resources resources = context.getResources();
|
108 |
c90b9e01
|
Leszek Koltunski
|
DistortedEffects.createProgram(resources);
|
109 |
|
|
EffectQueuePostprocess.createProgram(resources);
|
110 |
6a06a912
|
Leszek Koltunski
|
EffectMessageSender.startSending();
|
111 |
c90b9e01
|
Leszek Koltunski
|
|
112 |
|
|
mInitialized = true;
|
113 |
6a06a912
|
Leszek Koltunski
|
}
|
114 |
|
|
|
115 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
/**
|
117 |
|
|
* Call this so that the Library can release its internal data structures.
|
118 |
|
|
* Must be called from Activity.onDestroy().
|
119 |
|
|
*/
|
120 |
|
|
public static void onDestroy()
|
121 |
|
|
{
|
122 |
af4cc5db
|
Leszek Koltunski
|
DistortedSurface.onDestroy();
|
123 |
a09ada4c
|
Leszek Koltunski
|
DistortedNode.onDestroy();
|
124 |
7b8086eb
|
Leszek Koltunski
|
EffectQueue.onDestroy();
|
125 |
421c2728
|
Leszek Koltunski
|
DistortedEffects.onDestroy();
|
126 |
c204c69d
|
leszek
|
DistortedAttachDaemon.onDestroy();
|
127 |
6a06a912
|
Leszek Koltunski
|
EffectMessageSender.stopSending();
|
128 |
f8686932
|
Leszek Koltunski
|
|
129 |
55c14a19
|
Leszek Koltunski
|
mInitialized = false;
|
130 |
6a06a912
|
Leszek Koltunski
|
}
|
131 |
39cbf9dc
|
Leszek Koltunski
|
}
|