Revision 2e49718d
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedTexture.java | ||
---|---|---|
24 | 24 |
import android.opengl.GLES30; |
25 | 25 |
import android.opengl.GLUtils; |
26 | 26 |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.LinkedList; |
|
29 |
|
|
30 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 28 |
/** |
32 | 29 |
* Class which represents a OpenGL Texture object. |
... | ... | |
41 | 38 |
*/ |
42 | 39 |
public class DistortedTexture extends DistortedRenderable |
43 | 40 |
{ |
44 |
private static boolean mListMarked = false; |
|
45 |
private static LinkedList<DistortedTexture> mList = new LinkedList<>(); |
|
46 |
|
|
47 |
private static int mTextureH; |
|
48 |
|
|
49 |
private boolean mMarked; |
|
50 | 41 |
private Bitmap mBmp= null; |
51 | 42 |
|
52 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
74 | 65 |
{ |
75 | 66 |
if( mBmp!=null && mColorH !=null ) |
76 | 67 |
{ |
77 |
if( mColorH[0]==0 )
|
|
68 |
if( mColorH[0]==NOT_CREATED_YET )
|
|
78 | 69 |
{ |
79 | 70 |
GLES30.glGenTextures(1, mColorH, 0); |
80 | 71 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]); |
... | ... | |
99 | 90 |
|
100 | 91 |
void delete() |
101 | 92 |
{ |
102 |
if( mColorH !=null && mColorH[0]>0 ) |
|
93 |
if( mColorH !=null && mColorH[0]>=0 )
|
|
103 | 94 |
{ |
104 | 95 |
GLES30.glDeleteTextures(1, mColorH, 0); |
105 |
mColorH[0] = 0;
|
|
96 |
mColorH[0] = NOT_CREATED_YET;
|
|
106 | 97 |
} |
107 |
|
|
108 |
mMarked = false; |
|
109 | 98 |
} |
110 | 99 |
|
111 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
112 | 101 |
|
113 | 102 |
static void getUniforms(int mProgramH) |
114 | 103 |
{ |
115 |
mTextureH= GLES30.glGetUniformLocation( mProgramH, "u_Texture");
|
|
104 |
int textureH= GLES30.glGetUniformLocation( mProgramH, "u_Texture");
|
|
116 | 105 |
|
117 | 106 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
118 |
GLES30.glUniform1i(mTextureH, 0); |
|
119 |
} |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
static synchronized void onDestroy() |
|
124 |
{ |
|
125 |
mListMarked = false; |
|
126 |
mList.clear(); |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
// must be called form a thread holding OpenGL Context |
|
131 |
|
|
132 |
static synchronized void deleteAllMarked() |
|
133 |
{ |
|
134 |
if( mListMarked ) |
|
135 |
{ |
|
136 |
DistortedTexture tmp; |
|
137 |
Iterator<DistortedTexture> iterator = mList.iterator(); |
|
138 |
|
|
139 |
while(iterator.hasNext()) |
|
140 |
{ |
|
141 |
tmp = iterator.next(); |
|
142 |
|
|
143 |
if( tmp.mMarked ) |
|
144 |
{ |
|
145 |
tmp.delete(); |
|
146 |
iterator.remove(); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
mListMarked = false; |
|
151 |
} |
|
107 |
GLES30.glUniform1i(textureH, 0); |
|
152 | 108 |
} |
153 | 109 |
|
154 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
159 | 115 |
*/ |
160 | 116 |
public DistortedTexture(int width, int height) |
161 | 117 |
{ |
162 |
mSizeX = width ; |
|
163 |
mSizeY = height; |
|
164 |
mColorH[0]= 0; |
|
165 |
mBmp = null; |
|
166 |
mMarked = false; |
|
167 |
|
|
168 |
mList.add(this); |
|
169 |
} |
|
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
/** |
|
173 |
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render. |
|
174 |
*/ |
|
175 |
public void markForDeletion() |
|
176 |
{ |
|
177 |
mListMarked = true; |
|
178 |
mMarked = true; |
|
118 |
super(width,height,NOT_CREATED_YET); |
|
119 |
mBmp= null; |
|
179 | 120 |
} |
180 | 121 |
|
181 | 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
187 | 128 |
* |
188 | 129 |
* @param bmp The android.graphics.Bitmap object to apply effects to and display. |
189 | 130 |
*/ |
190 |
|
|
191 | 131 |
public void setTexture(Bitmap bmp) |
192 | 132 |
{ |
193 | 133 |
mBmp= bmp; |
Also available in: Unified diff
progress with DistortedRenderable.
This introduces a regression with MultiBlur!