1 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
226144d0
|
leszek
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
226144d0
|
leszek
|
// 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 |
46b572b5
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
226144d0
|
leszek
|
// 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 |
46b572b5
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
226144d0
|
leszek
|
|
22 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
/**
|
24 |
|
|
* Any Object which gets uploaded to GPU memory and thus needs to be re-created (transparently to
|
25 |
|
|
* applications!) whenever we lose OpenGL context.
|
26 |
|
|
*
|
27 |
|
|
* Keep all objects created in a static LinkedList. The point: we need to be able to mark
|
28 |
|
|
* Objects for deletion, and delete all marked Objects later at a convenient time (that's
|
29 |
|
|
* because we can only delete from a thread that holds the OpenGL context so here we provide a
|
30 |
|
|
* framework where one is able to mark for deletion at any time and actual deletion takes place
|
31 |
|
|
* on the next render).
|
32 |
|
|
*/
|
33 |
7602a827
|
Leszek Koltunski
|
abstract class InternalObject
|
34 |
226144d0
|
leszek
|
{
|
35 |
|
|
static final int FAILED_TO_CREATE = 1;
|
36 |
|
|
static final int NOT_CREATED_YET = 2;
|
37 |
|
|
static final int DONT_CREATE = 3;
|
38 |
|
|
static final int CREATED = 4;
|
39 |
|
|
|
40 |
|
|
static final int TYPE_USER = 0;
|
41 |
|
|
static final int TYPE_TREE = 1;
|
42 |
|
|
static final int TYPE_SYST = 2;
|
43 |
|
|
|
44 |
9ec374e8
|
Leszek Koltunski
|
static final int STORAGE_COMMON = 0;
|
45 |
|
|
static final int STORAGE_PRIVATE = 1;
|
46 |
226144d0
|
leszek
|
|
47 |
9ec374e8
|
Leszek Koltunski
|
static final int JOB_CREATE = 0;
|
48 |
|
|
static final int JOB_DELETE = 1;
|
49 |
9519d1b1
|
Leszek Koltunski
|
|
50 |
|
|
private long mID;
|
51 |
|
|
private int mType;
|
52 |
9ec374e8
|
Leszek Koltunski
|
private int mStorage;
|
53 |
226144d0
|
leszek
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
abstract void create();
|
57 |
|
|
abstract void delete();
|
58 |
|
|
abstract void recreate();
|
59 |
|
|
abstract String printDetails();
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
9ec374e8
|
Leszek Koltunski
|
void print(String msg)
|
64 |
226144d0
|
leszek
|
{
|
65 |
|
|
String str = "ID:"+mID;
|
66 |
|
|
|
67 |
|
|
switch(mType)
|
68 |
|
|
{
|
69 |
|
|
case TYPE_SYST: str+=" SYSTEM "; break;
|
70 |
|
|
case TYPE_USER: str+=" USER "; break;
|
71 |
|
|
case TYPE_TREE: str+=" TREE "; break;
|
72 |
|
|
default : str+=" ERROR? ";
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
android.util.Log.e("Object", str+printDetails()+msg);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
|
80 |
9ec374e8
|
Leszek Koltunski
|
InternalObject(int type, int storage)
|
81 |
226144d0
|
leszek
|
{
|
82 |
9ec374e8
|
Leszek Koltunski
|
mType = type;
|
83 |
|
|
mStorage = storage;
|
84 |
|
|
mID = InternalStackFrameList.getCurrentFrame().generateID(mType,mStorage);
|
85 |
226144d0
|
leszek
|
}
|
86 |
|
|
|
87 |
22e60fba
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
void markWasCreatedImmediately()
|
90 |
|
|
{
|
91 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.getCurrentFrame().addToDoneList(this,mStorage);
|
92 |
22e60fba
|
Leszek Koltunski
|
}
|
93 |
|
|
|
94 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95 |
|
|
|
96 |
d2039fdd
|
Leszek Koltunski
|
void markForCreation()
|
97 |
226144d0
|
leszek
|
{
|
98 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_CREATE);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
void removeFromDone()
|
104 |
|
|
{
|
105 |
|
|
InternalStackFrameList.removeFromDone(this,mStorage);
|
106 |
226144d0
|
leszek
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
// PUBLIC API
|
110 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111 |
|
|
/**
|
112 |
|
|
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
|
113 |
|
|
*/
|
114 |
d2039fdd
|
Leszek Koltunski
|
public void markForDeletion()
|
115 |
226144d0
|
leszek
|
{
|
116 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_DELETE);
|
117 |
226144d0
|
leszek
|
}
|
118 |
|
|
|
119 |
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
/**
|
121 |
|
|
* Return unique ID of this Object.
|
122 |
|
|
*/
|
123 |
|
|
public long getID()
|
124 |
|
|
{
|
125 |
|
|
return mID;
|
126 |
|
|
}
|
127 |
|
|
}
|