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.main;
|
21
|
|
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
|
abstract class InternalObject
|
34
|
{
|
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
|
static final int STORAGE_COMMON = 0;
|
45
|
static final int STORAGE_PRIVATE = 1;
|
46
|
|
47
|
static final int JOB_CREATE = 0;
|
48
|
static final int JOB_DELETE = 1;
|
49
|
|
50
|
private long mID;
|
51
|
private int mType;
|
52
|
private int mStorage;
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
abstract void create();
|
57
|
abstract void delete();
|
58
|
abstract void recreate();
|
59
|
abstract String printDetails();
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
void print(String msg)
|
64
|
{
|
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
|
InternalObject(int type, int storage)
|
81
|
{
|
82
|
mType = type;
|
83
|
mStorage = storage;
|
84
|
mID = InternalStackFrameList.getCurrentFrame().generateID(mType,mStorage);
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
void markWasCreatedImmediately()
|
90
|
{
|
91
|
InternalStackFrameList.getCurrentFrame().addToDoneList(this,mStorage);
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
void markForCreation()
|
97
|
{
|
98
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_CREATE);
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
void removeFromDone()
|
104
|
{
|
105
|
InternalStackFrameList.removeFromDone(this,mStorage);
|
106
|
}
|
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
|
public void markForDeletion()
|
115
|
{
|
116
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_DELETE);
|
117
|
}
|
118
|
|
119
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
/**
|
121
|
* Return unique ID of this Object.
|
122
|
*/
|
123
|
public long getID()
|
124
|
{
|
125
|
return mID;
|
126
|
}
|
127
|
}
|