Revision e7a20702
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
273 | 273 |
public void renderTo(DistortedTexture tex, GridObject grid, DistortedEffects effects, long time) |
274 | 274 |
{ |
275 | 275 |
tex.createTexture(); |
276 |
tex.setAsInput(); |
|
276 | 277 |
createFBO(); |
277 | 278 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
278 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]); |
|
279 | 279 |
effects.drawPriv(tex.mHalfX, tex.mHalfY, grid, this, time); |
280 | 280 |
DistortedFramebuffer.deleteAllMarked(); |
281 | 281 |
DistortedTexture.deleteAllMarked(); |
src/main/java/org/distorted/library/DistortedTexture.java | ||
---|---|---|
51 | 51 |
private long mID; |
52 | 52 |
private boolean mMarked; |
53 | 53 |
|
54 |
private Bitmap[] mBmp= null; //
|
|
55 |
int[] mTextureDataH; // have to be shared among all the cloned Objects
|
|
56 |
boolean[] mBitmapSet; //
|
|
54 |
private Bitmap mBmp= null;
|
|
55 |
private int[] mTextureDataH;
|
|
56 |
private boolean mBitmapSet;
|
|
57 | 57 |
|
58 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 59 |
// We have to flip vertically every single Bitmap that we get fed with. |
... | ... | |
78 | 78 |
|
79 | 79 |
void createTexture() |
80 | 80 |
{ |
81 |
if( mBmp[0]!=null && mTextureDataH!=null )
|
|
81 |
if( mBmp!=null && mTextureDataH!=null ) |
|
82 | 82 |
{ |
83 | 83 |
//android.util.Log.e("Texture", "creating "+mID); |
84 | 84 |
|
... | ... | |
90 | 90 |
GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE ); |
91 | 91 |
GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE ); |
92 | 92 |
|
93 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp[0]), 0);
|
|
94 |
mBmp[0] = null;
|
|
93 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0); |
|
94 |
mBmp = null; |
|
95 | 95 |
} |
96 | 96 |
} |
97 | 97 |
|
... | ... | |
107 | 107 |
GLES20.glDeleteTextures(1, mTextureDataH, 0); |
108 | 108 |
|
109 | 109 |
mTextureDataH[0] = 0; |
110 |
mBitmapSet[0] = false;
|
|
110 |
mBitmapSet= false; |
|
111 | 111 |
} |
112 | 112 |
|
113 | 113 |
mMarked = false; |
... | ... | |
120 | 120 |
return mID; |
121 | 121 |
} |
122 | 122 |
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
boolean setAsInput() |
|
126 |
{ |
|
127 |
if( mBitmapSet ) |
|
128 |
{ |
|
129 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]); |
|
130 |
return true; |
|
131 |
} |
|
132 |
|
|
133 |
return false; |
|
134 |
} |
|
135 |
|
|
123 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 137 |
|
125 | 138 |
static void getUniforms(int mProgramH) |
... | ... | |
176 | 189 |
|
177 | 190 |
mTextureDataH = new int[1]; |
178 | 191 |
mTextureDataH[0]= 0; |
179 |
mBmp = new Bitmap[1]; |
|
180 |
mBmp[0] = null; |
|
181 |
mBitmapSet = new boolean[1]; |
|
182 |
mBitmapSet[0] = false; |
|
192 |
mBmp = null; |
|
193 |
mBitmapSet = false; |
|
183 | 194 |
mID = 0; |
184 | 195 |
mMarked = false; |
185 | 196 |
|
186 | 197 |
mList.add(this); |
187 | 198 |
} |
188 | 199 |
|
189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 |
|
|
191 |
/** |
|
192 |
* Copy constructor. |
|
193 |
* <p> |
|
194 |
* Whatever we do not clone gets created just like in the default constructor. |
|
195 |
* |
|
196 |
* @param dt Source object to create our object from |
|
197 |
* @param flags A bitmask of values specifying what to copy. |
|
198 |
* Only possibilities: CLONE_BITMAP or CLONE_NOTHING. |
|
199 |
*/ |
|
200 |
|
|
201 |
public DistortedTexture(DistortedTexture dt, int flags) |
|
202 |
{ |
|
203 |
mSizeX= dt.mSizeX ; mHalfX = mSizeX/2.0f; |
|
204 |
mSizeY= dt.mSizeY ; mHalfY = mSizeY/2.0f; |
|
205 |
|
|
206 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
|
207 |
{ |
|
208 |
mTextureDataH = dt.mTextureDataH; |
|
209 |
mBmp = dt.mBmp; |
|
210 |
mBitmapSet = dt.mBitmapSet; |
|
211 |
mID = dt.getID(); |
|
212 |
} |
|
213 |
else |
|
214 |
{ |
|
215 |
mTextureDataH = new int[1]; |
|
216 |
mTextureDataH[0]= 0; |
|
217 |
mBitmapSet = new boolean[1]; |
|
218 |
mBitmapSet[0] = false; |
|
219 |
mBmp = new Bitmap[1]; |
|
220 |
mBmp[0] = null; |
|
221 |
mID = 0; |
|
222 |
} |
|
223 |
|
|
224 |
mMarked = false; |
|
225 |
|
|
226 |
mList.add(this); |
|
227 |
} |
|
228 |
|
|
229 | 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 | 201 |
/** |
231 | 202 |
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render. |
... | ... | |
250 | 221 |
|
251 | 222 |
public void setTexture(Bitmap bmp) |
252 | 223 |
{ |
253 |
mBitmapSet[0] = true;
|
|
254 |
mBmp[0] = bmp;
|
|
255 |
mID = bmp.hashCode();
|
|
224 |
mBitmapSet = true; |
|
225 |
mBmp = bmp; |
|
226 |
mID = bmp.hashCode(); |
|
256 | 227 |
|
257 | 228 |
//android.util.Log.e("Texture", "setting new bitmap "+mID); |
258 | 229 |
} |
src/main/java/org/distorted/library/DistortedTree.java | ||
---|---|---|
208 | 208 |
|
209 | 209 |
if( mNumChildren[0]<=0 ) |
210 | 210 |
{ |
211 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.mTextureDataH[0]);
|
|
211 |
mTexture.setAsInput();
|
|
212 | 212 |
} |
213 | 213 |
else |
214 | 214 |
{ |
... | ... | |
221 | 221 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
222 | 222 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
223 | 223 |
|
224 |
if( mTexture.mBitmapSet[0] ) |
|
225 |
{ |
|
226 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.mTextureDataH[0]); |
|
224 |
if( mTexture.setAsInput() ) |
|
227 | 225 |
mEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mGrid, mData.mDF); |
228 |
} |
|
229 | 226 |
|
230 | 227 |
synchronized(this) |
231 | 228 |
{ |
... | ... | |
295 | 292 |
public DistortedTree(DistortedTree node, int flags) |
296 | 293 |
{ |
297 | 294 |
mParent = null; |
298 |
mTexture= new DistortedTexture(node.mTexture,flags); |
|
299 | 295 |
mEffects= new DistortedEffects(node.mEffects,flags); |
300 | 296 |
mGrid = node.mGrid; |
301 | 297 |
|
298 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
|
299 |
{ |
|
300 |
mTexture = node.mTexture; |
|
301 |
} |
|
302 |
else |
|
303 |
{ |
|
304 |
mTexture = new DistortedTexture(node.mTexture.getWidth(), node.mTexture.getHeight()); |
|
305 |
} |
|
302 | 306 |
if( (flags & Distorted.CLONE_CHILDREN) != 0 ) |
303 | 307 |
{ |
304 | 308 |
mChildren = node.mChildren; |
Also available in: Unified diff
Simplify DistortedTexture.