Revision 7304d89f
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
30 | 30 |
private static final int TEXTURE_NOT_CREATED_YET = -2; |
31 | 31 |
private static final int TEXTURE_DONT_CREATE = -3; |
32 | 32 |
|
33 |
private int mFramebufferID, mTextureID; |
|
34 | 33 |
private float mX, mY; |
35 | 34 |
private float mFOV; |
36 | 35 |
|
36 |
private int[] texIds = new int[1]; |
|
37 |
private int[] fboIds = new int[1]; |
|
38 |
|
|
37 | 39 |
int mWidth,mHeight,mDepth,mDistance; |
38 | 40 |
float[] mProjectionMatrix; |
39 | 41 |
boolean mMarked; |
... | ... | |
80 | 82 |
|
81 | 83 |
private boolean createFBO() |
82 | 84 |
{ |
83 |
int[] texIds = new int[1]; |
|
84 |
int[] fboIds = new int[1]; |
|
85 |
|
|
86 | 85 |
GLES20.glGenTextures(1, texIds, 0); |
87 |
mTextureID = texIds[0]; |
|
88 | 86 |
|
89 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
|
|
87 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
|
|
90 | 88 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
91 | 89 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); |
92 | 90 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); |
... | ... | |
95 | 93 |
|
96 | 94 |
GLES20.glGenFramebuffers(1, fboIds, 0); |
97 | 95 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
98 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mTextureID, 0);
|
|
96 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0);
|
|
99 | 97 |
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); |
100 | 98 |
|
101 | 99 |
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE) |
... | ... | |
104 | 102 |
|
105 | 103 |
GLES20.glDeleteTextures(1, texIds, 0); |
106 | 104 |
GLES20.glDeleteFramebuffers(1, fboIds, 0); |
107 |
mFramebufferID = 0;
|
|
108 |
mTextureID = TEXTURE_FAILED_TO_CREATE;
|
|
105 |
fboIds[0] = 0;
|
|
106 |
texIds[0] = TEXTURE_FAILED_TO_CREATE;
|
|
109 | 107 |
return false; |
110 | 108 |
} |
111 | 109 |
|
112 |
mFramebufferID = fboIds[0]; |
|
113 |
|
|
114 |
android.util.Log.e("FBO", "creating ("+mWidth+","+mHeight+") "+mFramebufferID); |
|
110 |
android.util.Log.e("FBO", "creating ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
115 | 111 |
|
116 | 112 |
return true; |
117 | 113 |
} |
... | ... | |
121 | 117 |
|
122 | 118 |
private void deleteFBO() |
123 | 119 |
{ |
124 |
android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+mFramebufferID); |
|
125 |
|
|
126 |
int[] texIds = new int[1]; |
|
127 |
int[] fboIds = new int[1]; |
|
128 |
|
|
129 |
texIds[0] = mTextureID; |
|
130 |
fboIds[0] = mFramebufferID; |
|
120 |
android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
131 | 121 |
|
132 | 122 |
GLES20.glDeleteTextures(1, texIds, 0); |
133 | 123 |
GLES20.glDeleteFramebuffers(1, fboIds, 0); |
134 | 124 |
|
135 |
mFramebufferID = 0;
|
|
136 |
mTextureID = TEXTURE_NOT_CREATED_YET;
|
|
125 |
fboIds[0] = 0;
|
|
126 |
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
|
137 | 127 |
} |
138 | 128 |
|
139 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
141 | 131 |
|
142 | 132 |
void release() |
143 | 133 |
{ |
144 |
if( mTextureID>=0 ) deleteFBO();
|
|
134 |
if( texIds[0]>=0 ) deleteFBO();
|
|
145 | 135 |
|
146 | 136 |
mProjectionMatrix = null; |
147 | 137 |
mMarked = false; |
... | ... | |
151 | 141 |
|
152 | 142 |
void reset() |
153 | 143 |
{ |
154 |
mTextureID = TEXTURE_NOT_CREATED_YET;
|
|
144 |
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
|
155 | 145 |
} |
156 | 146 |
|
157 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
163 | 153 |
|
164 | 154 |
mHeight = height; |
165 | 155 |
mWidth = width; |
166 |
mFramebufferID = -1;
|
|
167 |
mTextureID = TEXTURE_NOT_CREATED_YET;
|
|
156 |
fboIds[0] = -1;
|
|
157 |
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
|
168 | 158 |
mFOV = 60.0f; |
169 | 159 |
mX = 0.0f; |
170 | 160 |
mY = 0.0f; |
... | ... | |
182 | 172 |
{ |
183 | 173 |
mProjectionMatrix = new float[16]; |
184 | 174 |
|
185 |
mFramebufferID = fbo;
|
|
186 |
mTextureID = TEXTURE_DONT_CREATE;
|
|
175 |
fboIds[0] = fbo;
|
|
176 |
texIds[0] = TEXTURE_DONT_CREATE;
|
|
187 | 177 |
mFOV = 60.0f; |
188 | 178 |
mX = 0.0f; |
189 | 179 |
mY = 0.0f; |
... | ... | |
195 | 185 |
|
196 | 186 |
public void markForDeletion() |
197 | 187 |
{ |
198 |
android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+mFramebufferID);
|
|
188 |
android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+fboIds[0]);
|
|
199 | 189 |
|
200 | 190 |
DistortedFramebufferList.markForDeletion(); |
201 | 191 |
mMarked = true; |
... | ... | |
223 | 213 |
|
224 | 214 |
createProjection(); |
225 | 215 |
|
226 |
if( mTextureID>0 ) markForDeletion();
|
|
216 |
if( texIds[0]>0 ) markForDeletion();
|
|
227 | 217 |
} |
228 | 218 |
} |
229 | 219 |
|
... | ... | |
231 | 221 |
|
232 | 222 |
public int getFBO() |
233 | 223 |
{ |
234 |
return mFramebufferID;
|
|
224 |
return fboIds[0];
|
|
235 | 225 |
} |
236 | 226 |
|
237 | 227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
239 | 229 |
|
240 | 230 |
public void setOutput() |
241 | 231 |
{ |
242 |
if( mTextureID==TEXTURE_NOT_CREATED_YET ) createFBO();
|
|
232 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
|
|
243 | 233 |
|
244 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFramebufferID);
|
|
234 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
|
245 | 235 |
} |
246 | 236 |
|
247 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
249 | 239 |
|
250 | 240 |
public void setInput() |
251 | 241 |
{ |
252 |
if( mTextureID==TEXTURE_NOT_CREATED_YET ) createFBO();
|
|
242 |
if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
|
|
253 | 243 |
|
254 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
|
|
244 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
|
|
255 | 245 |
} |
256 | 246 |
|
257 | 247 |
} |
Also available in: Unified diff
Cleanup