1 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
2e569ff6
|
Leszek Koltunski
|
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl //
|
3 |
226144d0
|
leszek
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
226144d0
|
leszek
|
// //
|
6 |
2e569ff6
|
Leszek Koltunski
|
// This library is free software; you can redistribute it and/or //
|
7 |
|
|
// modify it under the terms of the GNU Lesser General Public //
|
8 |
|
|
// License as published by the Free Software Foundation; either //
|
9 |
|
|
// version 2.1 of the License, or (at your option) any later version. //
|
10 |
226144d0
|
leszek
|
// //
|
11 |
2e569ff6
|
Leszek Koltunski
|
// This library is distributed in the hope that it will be useful, //
|
12 |
226144d0
|
leszek
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
2e569ff6
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
226144d0
|
leszek
|
// //
|
16 |
2e569ff6
|
Leszek Koltunski
|
// You should have received a copy of the GNU Lesser General Public //
|
17 |
|
|
// License along with this library; if not, write to the Free Software //
|
18 |
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
22 |
226144d0
|
leszek
|
|
23 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24 |
|
|
/**
|
25 |
|
|
* Any Object which gets uploaded to GPU memory and thus needs to be re-created (transparently to
|
26 |
|
|
* applications!) whenever we lose OpenGL context.
|
27 |
|
|
*
|
28 |
|
|
* Keep all objects created in a static LinkedList. The point: we need to be able to mark
|
29 |
|
|
* Objects for deletion, and delete all marked Objects later at a convenient time (that's
|
30 |
|
|
* because we can only delete from a thread that holds the OpenGL context so here we provide a
|
31 |
|
|
* framework where one is able to mark for deletion at any time and actual deletion takes place
|
32 |
|
|
* on the next render).
|
33 |
|
|
*/
|
34 |
7602a827
|
Leszek Koltunski
|
abstract class InternalObject
|
35 |
226144d0
|
leszek
|
{
|
36 |
|
|
static final int FAILED_TO_CREATE = 1;
|
37 |
|
|
static final int NOT_CREATED_YET = 2;
|
38 |
|
|
static final int DONT_CREATE = 3;
|
39 |
|
|
static final int CREATED = 4;
|
40 |
|
|
|
41 |
|
|
static final int TYPE_USER = 0;
|
42 |
|
|
static final int TYPE_TREE = 1;
|
43 |
|
|
static final int TYPE_SYST = 2;
|
44 |
|
|
|
45 |
9ec374e8
|
Leszek Koltunski
|
static final int STORAGE_COMMON = 0;
|
46 |
|
|
static final int STORAGE_PRIVATE = 1;
|
47 |
226144d0
|
leszek
|
|
48 |
9ec374e8
|
Leszek Koltunski
|
static final int JOB_CREATE = 0;
|
49 |
|
|
static final int JOB_DELETE = 1;
|
50 |
9519d1b1
|
Leszek Koltunski
|
|
51 |
f7c72bd1
|
Leszek Koltunski
|
private final long mID;
|
52 |
|
|
private final int mType;
|
53 |
|
|
private final int mStorage;
|
54 |
226144d0
|
leszek
|
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
abstract void create();
|
58 |
|
|
abstract void delete();
|
59 |
|
|
abstract void recreate();
|
60 |
|
|
abstract String printDetails();
|
61 |
|
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
9ec374e8
|
Leszek Koltunski
|
void print(String msg)
|
65 |
226144d0
|
leszek
|
{
|
66 |
|
|
String str = "ID:"+mID;
|
67 |
|
|
|
68 |
|
|
switch(mType)
|
69 |
|
|
{
|
70 |
|
|
case TYPE_SYST: str+=" SYSTEM "; break;
|
71 |
|
|
case TYPE_USER: str+=" USER "; break;
|
72 |
|
|
case TYPE_TREE: str+=" TREE "; break;
|
73 |
|
|
default : str+=" ERROR? ";
|
74 |
|
|
}
|
75 |
|
|
|
76 |
8c57d77b
|
Leszek Koltunski
|
DistortedLibrary.logMessage("InternalObject: "+str+printDetails()+msg);
|
77 |
226144d0
|
leszek
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
9ec374e8
|
Leszek Koltunski
|
InternalObject(int type, int storage)
|
82 |
226144d0
|
leszek
|
{
|
83 |
9ec374e8
|
Leszek Koltunski
|
mType = type;
|
84 |
|
|
mStorage = storage;
|
85 |
|
|
mID = InternalStackFrameList.getCurrentFrame().generateID(mType,mStorage);
|
86 |
226144d0
|
leszek
|
}
|
87 |
|
|
|
88 |
22e60fba
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
void markWasCreatedImmediately()
|
91 |
|
|
{
|
92 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.getCurrentFrame().addToDoneList(this,mStorage);
|
93 |
22e60fba
|
Leszek Koltunski
|
}
|
94 |
|
|
|
95 |
226144d0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
d2039fdd
|
Leszek Koltunski
|
void markForCreation()
|
98 |
226144d0
|
leszek
|
{
|
99 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_CREATE);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103 |
|
|
|
104 |
|
|
void removeFromDone()
|
105 |
|
|
{
|
106 |
|
|
InternalStackFrameList.removeFromDone(this,mStorage);
|
107 |
226144d0
|
leszek
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
// PUBLIC API
|
111 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112 |
|
|
/**
|
113 |
|
|
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
|
114 |
|
|
*/
|
115 |
d2039fdd
|
Leszek Koltunski
|
public void markForDeletion()
|
116 |
226144d0
|
leszek
|
{
|
117 |
9ec374e8
|
Leszek Koltunski
|
InternalStackFrameList.markFor(this,mID,mStorage,JOB_DELETE);
|
118 |
226144d0
|
leszek
|
}
|
119 |
|
|
|
120 |
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
/**
|
122 |
|
|
* Return unique ID of this Object.
|
123 |
|
|
*/
|
124 |
|
|
public long getID()
|
125 |
|
|
{
|
126 |
|
|
return mID;
|
127 |
|
|
}
|
128 |
|
|
}
|