Revision 133cbb2b
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedTexture.java | ||
---|---|---|
39 | 39 |
* framework where one is able to mark for deletion at any time and actual deletion takes place |
40 | 40 |
* on the next render). |
41 | 41 |
*/ |
42 |
public class DistortedTexture |
|
42 |
public class DistortedTexture extends DistortedRenderable
|
|
43 | 43 |
{ |
44 | 44 |
private static boolean mListMarked = false; |
45 | 45 |
private static LinkedList<DistortedTexture> mList = new LinkedList<>(); |
46 | 46 |
|
47 | 47 |
private static int mTextureH; |
48 | 48 |
|
49 |
private int mSizeX, mSizeY; // in screen space |
|
50 |
float mHalfX, mHalfY; // halves of the above |
|
51 |
private long mID; |
|
52 | 49 |
private boolean mMarked; |
53 |
|
|
54 | 50 |
private Bitmap mBmp= null; |
55 |
private int[] mTextureDataH; |
|
56 | 51 |
|
57 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
58 | 53 |
// We have to flip vertically every single Bitmap that we get fed with. |
... | ... | |
75 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
76 | 71 |
// must be called from a thread holding OpenGL Context |
77 | 72 |
|
78 |
void createTexture()
|
|
73 |
void create() |
|
79 | 74 |
{ |
80 |
if( mBmp!=null && mTextureDataH!=null )
|
|
75 |
if( mBmp!=null && mColorH !=null )
|
|
81 | 76 |
{ |
82 |
//android.util.Log.e("Texture", "creating "+mID); |
|
83 |
|
|
84 |
if( mTextureDataH[0]==0 ) |
|
77 |
if( mColorH[0]==0 ) |
|
85 | 78 |
{ |
86 |
GLES30.glGenTextures(1, mTextureDataH, 0);
|
|
87 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
|
|
79 |
GLES30.glGenTextures(1, mColorH, 0);
|
|
80 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
|
|
88 | 81 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR ); |
89 | 82 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR ); |
90 | 83 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE ); |
... | ... | |
93 | 86 |
} |
94 | 87 |
else |
95 | 88 |
{ |
96 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
|
|
89 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
|
|
97 | 90 |
GLUtils.texSubImage2D(GLES30.GL_TEXTURE_2D, 0,0,0,flipBitmap(mBmp)); |
98 | 91 |
} |
99 | 92 |
|
... | ... | |
104 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
105 | 98 |
// must be called from a thread holding OpenGL Context |
106 | 99 |
|
107 |
private void deleteTexture()
|
|
100 |
private void delete() |
|
108 | 101 |
{ |
109 |
if( mTextureDataH!=null && mTextureDataH[0]>0 )
|
|
102 |
if( mColorH !=null && mColorH[0]>0 )
|
|
110 | 103 |
{ |
111 |
//android.util.Log.e("Texture", "deleting "+mID); |
|
112 |
|
|
113 |
GLES30.glDeleteTextures(1, mTextureDataH, 0); |
|
114 |
|
|
115 |
mTextureDataH[0] = 0; |
|
116 |
mID = 0; |
|
104 |
GLES30.glDeleteTextures(1, mColorH, 0); |
|
105 |
mColorH[0] = 0; |
|
117 | 106 |
} |
118 | 107 |
|
119 | 108 |
mMarked = false; |
120 | 109 |
} |
121 | 110 |
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
long getID() |
|
125 |
{ |
|
126 |
return mID; |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
boolean setAsInput() |
|
132 |
{ |
|
133 |
if( mID!=0 ) |
|
134 |
{ |
|
135 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]); |
|
136 |
return true; |
|
137 |
} |
|
138 |
|
|
139 |
return false; |
|
140 |
} |
|
141 |
|
|
142 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
143 | 112 |
|
144 | 113 |
static void getUniforms(int mProgramH) |
... | ... | |
173 | 142 |
|
174 | 143 |
if( tmp.mMarked ) |
175 | 144 |
{ |
176 |
tmp.deleteTexture();
|
|
145 |
tmp.delete(); |
|
177 | 146 |
iterator.remove(); |
178 | 147 |
} |
179 | 148 |
} |
... | ... | |
190 | 159 |
*/ |
191 | 160 |
public DistortedTexture(int width, int height) |
192 | 161 |
{ |
193 |
mSizeX= width ; mHalfX = mSizeX/2.0f; |
|
194 |
mSizeY= height; mHalfY = mSizeY/2.0f; |
|
195 |
|
|
196 |
mTextureDataH = new int[1]; |
|
197 |
mTextureDataH[0]= 0; |
|
198 |
mBmp = null; |
|
199 |
mID = 0; |
|
200 |
mMarked = false; |
|
162 |
mSizeX = width ; |
|
163 |
mSizeY = height; |
|
164 |
mColorH[0]= 0; |
|
165 |
mBmp = null; |
|
166 |
mMarked = false; |
|
201 | 167 |
|
202 | 168 |
mList.add(this); |
203 | 169 |
} |
... | ... | |
208 | 174 |
*/ |
209 | 175 |
public void markForDeletion() |
210 | 176 |
{ |
211 |
//android.util.Log.e("Texture", "marking for deletion "+mID); |
|
212 |
|
|
213 | 177 |
mListMarked = true; |
214 | 178 |
mMarked = true; |
215 | 179 |
} |
... | ... | |
227 | 191 |
public void setTexture(Bitmap bmp) |
228 | 192 |
{ |
229 | 193 |
mBmp= bmp; |
230 |
mID = bmp.hashCode(); |
|
231 |
|
|
232 |
//android.util.Log.e("Texture", "setting new bitmap "+mID); |
|
233 |
} |
|
234 |
|
|
235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
236 |
/** |
|
237 |
* Returns the height of the Texture. |
|
238 |
* |
|
239 |
* @return height of the object, in pixels. |
|
240 |
*/ |
|
241 |
public int getWidth() |
|
242 |
{ |
|
243 |
return mSizeX; |
|
244 |
} |
|
245 |
|
|
246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 |
/** |
|
248 |
* Returns the width of the Texture. |
|
249 |
* |
|
250 |
* @return width of the Object, in pixels. |
|
251 |
*/ |
|
252 |
public int getHeight() |
|
253 |
{ |
|
254 |
return mSizeY; |
|
255 |
} |
|
256 |
|
|
257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
258 |
/** |
|
259 |
* Returns the depth of the Texture. |
|
260 |
* <p> |
|
261 |
* Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine |
|
262 |
* 'depth' of a texture when rendered based only on the texture itself, that depends on the Mesh it is |
|
263 |
* rendered with. |
|
264 |
* |
|
265 |
* @return depth of the Object, in pixels. |
|
266 |
*/ |
|
267 |
public int getDepth(MeshObject mesh) |
|
268 |
{ |
|
269 |
return mesh==null ? 0 : (int)(mSizeX*mesh.zFactor); |
|
270 | 194 |
} |
271 | 195 |
} |
Also available in: Unified diff
Introduce DistortedRenderable, a base class for Texture and Framebuffer