Revision 7cf783cb
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
private float mX, mY, mFOV; |
52 | 52 |
|
53 |
private int[] texIds = new int[1];
|
|
54 |
private int[] fboIds = new int[1];
|
|
53 |
int[] texIds = new int[1]; |
|
54 |
int[] fboIds = new int[1]; |
|
55 | 55 |
|
56 | 56 |
private boolean mMarked; |
57 | 57 |
|
... | ... | |
62 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 63 |
// Must be called from a thread holding OpenGL Context |
64 | 64 |
|
65 |
private boolean createFBO()
|
|
65 |
boolean createFBO() |
|
66 | 66 |
{ |
67 |
GLES20.glGenTextures(1, texIds, 0); |
|
68 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]); |
|
69 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
|
70 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); |
|
71 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); |
|
72 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); |
|
73 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); |
|
67 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) |
|
68 |
{ |
|
69 |
GLES20.glGenTextures(1, texIds, 0); |
|
70 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]); |
|
71 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
|
72 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); |
|
73 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); |
|
74 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); |
|
75 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); |
|
74 | 76 |
|
75 |
GLES20.glGenFramebuffers(1, fboIds, 0); |
|
76 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
|
77 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0); |
|
77 |
GLES20.glGenFramebuffers(1, fboIds, 0);
|
|
78 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
|
79 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0);
|
|
78 | 80 |
|
79 |
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); |
|
81 |
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
|
|
80 | 82 |
|
81 |
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE) |
|
82 |
{ |
|
83 |
android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status); |
|
84 |
GLES20.glDeleteTextures(1, texIds, 0); |
|
85 |
GLES20.glDeleteFramebuffers(1, fboIds, 0); |
|
86 |
fboIds[0] = 0; |
|
87 |
texIds[0] = TEXTURE_FAILED_TO_CREATE; |
|
88 |
return false; |
|
89 |
} |
|
83 |
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
|
|
84 |
{
|
|
85 |
android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status);
|
|
86 |
GLES20.glDeleteTextures(1, texIds, 0);
|
|
87 |
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
|
88 |
fboIds[0] = 0;
|
|
89 |
texIds[0] = TEXTURE_FAILED_TO_CREATE;
|
|
90 |
return false;
|
|
91 |
}
|
|
90 | 92 |
|
91 |
mList.add(this); |
|
92 |
//android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
93 |
mList.add(this); |
|
94 |
//android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
95 |
} |
|
93 | 96 |
|
94 | 97 |
return true; |
95 | 98 |
} |
... | ... | |
113 | 116 |
mMarked = false; |
114 | 117 |
} |
115 | 118 |
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
// Must be called from a thread holding OpenGL Context |
|
118 |
|
|
119 |
void setAsOutput() |
|
120 |
{ |
|
121 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
122 |
|
|
123 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
|
124 |
} |
|
125 |
|
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
// Must be called from a thread holding OpenGL Context |
|
128 |
|
|
129 |
void setAsInput() |
|
130 |
{ |
|
131 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO(); |
|
132 |
|
|
133 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]); |
|
134 |
} |
|
135 |
|
|
136 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
137 | 120 |
|
138 | 121 |
void reset() |
... | ... | |
180 | 163 |
|
181 | 164 |
static synchronized void onDestroy() |
182 | 165 |
{ |
166 |
// There are issues with this. Namely, if one |
|
167 |
// 1. creates a DObjectTree (somewhere else than onSurfaceCreated of constructor so it does not get re-created on re-launch) |
|
168 |
// 2. minimizes the app (here mList would be cleared) |
|
169 |
// 3. re-launches the app |
|
170 |
// 4. deletes some nodes |
|
171 |
// then the underlying Framebuffers will never be deleted! |
|
172 |
|
|
183 | 173 |
mListMarked = false; |
184 | 174 |
mList.clear(); |
185 | 175 |
} |
Also available in: Unified diff
Attempt to bring DTexture and DFramebuffer closer together.