Project

General

Profile

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

library / src / main / java / org / distorted / library / Distorted.java @ 94f6d472

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 org.distorted.library.program.*;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
/**
28
 * A singleton class used to control various global settings.
29
 */
30
public class Distorted 
31
  {
32
  static int GLSL;
33
  static String GLSL_VERSION;
34

    
35
  /**
36
   * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
37
   * backing up our DistortedTexture.
38
   * <p>
39
   * This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
40
   * apply different effects. Used in the copy constructor.
41
   */
42
  public static final int CLONE_SURFACE = 0x1;
43
  /**
44
   * When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
45
   * <p>
46
   * This way we can have two different DistortedEffects sharing the MATRIX queue.
47
   */
48
  public static final int CLONE_MATRIX = 0x2;
49
  /**
50
   * When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
51
   * <p>
52
   * This way we can have two different DistortedEffects sharing the VERTEX queue.
53
   */
54
  public static final int CLONE_VERTEX  = 0x4;
55
  /**
56
   * When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
57
   * <p>
58
   * This way we can have two different DistortedEffects sharing the FRAGMENT queue.
59
   */
60
  public static final int CLONE_FRAGMENT= 0x8;
61
   /**
62
   * When creating an instance of a DistortedEffects from another instance, clone the PostProcess Effects.
63
   * <p>
64
   * This way we can have two different DistortedEffects sharing the POSTPROCESS queue.
65
   */
66
  public static final int CLONE_POSTPROCESS= 0x10;
67
  /**
68
   * When creating an instance of a DistortedNode from another instance, clone the children Nodes.
69
   * <p>
70
   * This is mainly useful for creating many similar sub-trees and rendering then at different places
71
   * on the screen with (optionally) different Effects.
72
   */
73
  public static final int CLONE_CHILDREN= 0x20;
74

    
75
  private static boolean mInitialized=false;
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// private: hide this from Javadoc
79

    
80
  private Distorted()
81
    {
82
    
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  static boolean isInitialized()
88
    {
89
    return mInitialized;
90
    }
91

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

    
112
    final Resources resources = context.getResources();
113
    DistortedEffects.createProgram(resources);
114
    EffectQueuePostprocess.createProgram(resources);
115
    EffectMessageSender.startSending();
116

    
117
    mInitialized = true;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
/**
122
 * Call this so that the Library can release its internal data structures.
123
 * Must be called from Activity.onDestroy(). 
124
 */
125
  public static void onDestroy()
126
    {
127
    DistortedSurface.onDestroy();
128
    DistortedNode.onDestroy();
129
    EffectQueue.onDestroy();
130
    DistortedEffects.onDestroy();
131
    DistortedAttachDaemon.onDestroy();
132
    EffectMessageSender.stopSending();
133

    
134
    mInitialized = false;
135
    }
136
  }
(1-1/23)