Project

General

Profile

Download (5.73 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / Distorted.java @ 2ed1c692

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 from another instance, clone the Bitmap that's
35
   * backing up our DistortedTexture.
36
   * <p>
37
   * This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
38
   * apply different effects. Used in the copy constructor.
39
   */
40
  public static final int CLONE_SURFACE = 0x1;
41
  /**
42
   * When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
43
   * <p>
44
   * This way we can have two different DistortedEffects sharing the MATRIX queue.
45
   */
46
  public static final int CLONE_MATRIX = 0x2;
47
  /**
48
   * When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
49
   * <p>
50
   * This way we can have two different DistortedEffects sharing the VERTEX queue.
51
   */
52
  public static final int CLONE_VERTEX  = 0x4;
53
  /**
54
   * When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
55
   * <p>
56
   * This way we can have two different DistortedEffects sharing the FRAGMENT queue.
57
   */
58
  public static final int CLONE_FRAGMENT= 0x8;
59
   /**
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
  /**
66
   * When creating an instance of a DistortedNode from another instance, clone the children Nodes.
67
   * <p>
68
   * 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
   */
71
  public static final int CLONE_CHILDREN= 0x20;
72

    
73
  private static boolean mInitialized=false;
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// private: hide this from Javadoc
77

    
78
  private Distorted()
79
    {
80
    
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  static boolean isInitialized()
86
    {
87
    return mInitialized;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
/**
92
 * When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
93
 * I.e. best called from GLSurfaceView.onCreate().
94
 * <p>
95
 * Needs to be called from a thread holding the OpenGL context.
96
 *   
97
 * @param context Context of the App using the library - used to open up Resources and read Shader code.
98
 * @throws FragmentCompilationException
99
 * @throws VertexCompilationException
100
 * @throws VertexUniformsException
101
 * @throws FragmentUniformsException
102
 * @throws LinkingException
103
 */
104
  public static void onCreate(final Context context)
105
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
106
    {
107
    final Resources resources = context.getResources();
108
    DistortedEffects.createProgram(resources);
109
    EffectQueuePostprocess.createProgram(resources);
110
    EffectMessageSender.startSending();
111

    
112
    mInitialized = true;
113
    }
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
    DistortedSurface.onDestroy();
123
    DistortedNode.onDestroy();
124
    EffectQueue.onDestroy();
125
    DistortedEffects.onDestroy();
126
    DistortedAttachDaemon.onDestroy();
127
    EffectMessageSender.stopSending();
128

    
129
    mInitialized = false;
130
    }
131
  }
(1-1/22)