Revision f85f2943
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/library/main/DistortedTexture.java | ||
---|---|---|
35 | 35 |
public class DistortedTexture extends InternalSurface |
36 | 36 |
{ |
37 | 37 |
private Bitmap mBmp; |
38 |
private boolean mBitmapInverted; |
|
38 | 39 |
|
39 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 |
// We have to flip vertically every single Bitmap that we get fed with.
|
|
41 |
// We have to vertically flip all the bitmaps passed here via setTexture().
|
|
41 | 42 |
// |
42 | 43 |
// Reason: textures read from files are the only objects in OpenGL which have their origins at the |
43 | 44 |
// upper-left corner. Everywhere else the origin is in the lower-left corner. Thus we have to flip. |
44 | 45 |
// The alternative solution, namely inverting the y-coordinate of the TexCoord does not really work- |
45 | 46 |
// i.e. it works only in case of rendering directly to the screen, but if we render to an FBO and |
46 | 47 |
// then take the FBO and render to screen, (DistortedNode does so!) things get inverted as textures |
47 |
// created from FBO have their origins in the lower-left... Mindfuck!
|
|
48 |
// created from FBO have their origins in the lower-left... |
|
48 | 49 |
|
49 | 50 |
private static Bitmap flipBitmap(Bitmap src) |
50 | 51 |
{ |
... | ... | |
72 | 73 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR ); |
73 | 74 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE ); |
74 | 75 |
GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE ); |
75 |
GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0); |
|
76 |
GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, mBitmapInverted ? mBmp : flipBitmap(mBmp), 0);
|
|
76 | 77 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
77 | 78 |
|
78 | 79 |
mBmp = null; |
... | ... | |
150 | 151 |
} |
151 | 152 |
else |
152 | 153 |
{ |
154 |
mBitmapInverted = false; |
|
155 |
mBmp= bmp; |
|
156 |
markForCreation(); |
|
157 |
return true; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
/** |
|
163 |
* Sets the underlying android.graphics.Bitmap object - this version assumes the object is already |
|
164 |
* flipped upside down. |
|
165 |
* <p> |
|
166 |
* You can only recycle() the passed Bitmap once the OpenGL context gets created (i.e. after call |
|
167 |
* to GLSurfaceView.onSurfaceCreated) because only after this point can the Library upload it to the GPU! |
|
168 |
* |
|
169 |
* @param bmp The (vertically flipped!) android.graphics.Bitmap object to apply effects to and display. |
|
170 |
* @return true if successful, false if texture too large. |
|
171 |
*/ |
|
172 |
public boolean setTextureAlreadyInverted(Bitmap bmp) |
|
173 |
{ |
|
174 |
int width = bmp.getWidth(); |
|
175 |
int height= bmp.getHeight(); |
|
176 |
int max = DistortedLibrary.getMaxTextureSize(); |
|
177 |
|
|
178 |
if( width>max || height>max ) |
|
179 |
{ |
|
180 |
android.util.Log.e("texture","error, trying to upload too large texture of size "+width+" x "+height+". Max is "+max); |
|
181 |
return false; |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
mBitmapInverted = true; |
|
153 | 186 |
mBmp= bmp; |
154 | 187 |
markForCreation(); |
155 | 188 |
return true; |
Also available in: Unified diff
FactorySticker: further improvements.