Revision b7074bc6
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/main/DistortedFramebuffer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.main; |
21 | 21 |
|
22 |
import android.opengl.GLES31; |
|
22 |
import android.opengl.GLES30; |
|
23 |
import android.util.Log; |
|
23 | 24 |
|
24 | 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 26 |
/** |
... | ... | |
41 | 42 |
|
42 | 43 |
if( mColorCreated==NOT_CREATED_YET ) |
43 | 44 |
{ |
44 |
GLES31.glGenTextures( mNumFBOs*mNumColors, mColorH, 0);
|
|
45 |
GLES31.glGenFramebuffers(mNumFBOs, mFBOH, 0);
|
|
45 |
GLES30.glGenTextures( mNumFBOs*mNumColors, mColorH, 0);
|
|
46 |
GLES30.glGenFramebuffers(mNumFBOs, mFBOH, 0);
|
|
46 | 47 |
|
47 | 48 |
for(int i=0; i<mNumFBOs; i++) |
48 | 49 |
{ |
49 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
50 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
50 | 51 |
|
51 | 52 |
for(int j=0; j<mNumColors; j++) |
52 | 53 |
{ |
53 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors+j]);
|
|
54 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
55 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
56 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
57 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR);
|
|
58 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mRealWidth, mRealHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null);
|
|
54 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[i*mNumColors+j]);
|
|
55 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
56 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
57 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
58 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
|
|
59 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mRealWidth, mRealHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
|
|
59 | 60 |
} |
60 | 61 |
|
61 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors], 0);
|
|
62 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
62 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[i*mNumColors], 0);
|
|
63 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
63 | 64 |
} |
64 | 65 |
|
65 | 66 |
// TODO |
66 | 67 |
mColorCreated = checkStatus("color"); |
67 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
68 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
68 | 69 |
} |
69 | 70 |
|
70 | 71 |
////////////////////////////////////////////////////////////// |
... | ... | |
72 | 73 |
|
73 | 74 |
if( mDepthStencilCreated==NOT_CREATED_YET ) // we need to create a new DEPTH or STENCIL attachment |
74 | 75 |
{ |
75 |
GLES31.glGenTextures(mNumFBOs, mDepthStencilH, 0);
|
|
76 |
GLES30.glGenTextures(mNumFBOs, mDepthStencilH, 0);
|
|
76 | 77 |
|
77 | 78 |
for(int i=0; i<mNumFBOs; i++) |
78 | 79 |
{ |
79 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[i]);
|
|
80 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
81 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
82 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
83 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_NEAREST);
|
|
80 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthStencilH[i]);
|
|
81 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
82 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
83 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
84 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
|
|
84 | 85 |
|
85 | 86 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
86 | 87 |
{ |
87 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null);
|
|
88 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_INT, null);
|
|
88 | 89 |
} |
89 | 90 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
90 | 91 |
{ |
91 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null);
|
|
92 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES30.GL_DEPTH_STENCIL, GLES30.GL_UNSIGNED_INT_24_8, null);
|
|
92 | 93 |
} |
93 | 94 |
} |
94 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
95 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
95 | 96 |
|
96 | 97 |
for(int i=0; i<mNumFBOs; i++) |
97 | 98 |
{ |
98 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
99 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
99 | 100 |
|
100 | 101 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
101 | 102 |
{ |
102 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
103 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
103 | 104 |
} |
104 | 105 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
105 | 106 |
{ |
106 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
107 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[i], 0);
|
|
107 | 108 |
} |
108 | 109 |
} |
109 | 110 |
|
110 | 111 |
// TODO |
111 | 112 |
mDepthStencilCreated = checkStatus("depth"); |
112 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
113 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
113 | 114 |
} |
114 | 115 |
|
115 | 116 |
////////////////////////////////////////////////////////////// |
... | ... | |
124 | 125 |
|
125 | 126 |
for(int i=0; i<mNumFBOs; i++) |
126 | 127 |
{ |
127 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]);
|
|
128 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0);
|
|
129 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0);
|
|
128 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[i]);
|
|
129 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, 0, 0);
|
|
130 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, 0, 0);
|
|
130 | 131 |
mDepthStencilH[i]=0; |
131 | 132 |
} |
132 | 133 |
|
133 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
134 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
134 |
GLES30.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
135 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
135 | 136 |
} |
136 | 137 |
} |
137 | 138 |
|
... | ... | |
140 | 141 |
|
141 | 142 |
private int checkStatus(String message) |
142 | 143 |
{ |
143 |
int status = GLES31.glCheckFramebufferStatus(GLES31.GL_FRAMEBUFFER);
|
|
144 |
int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
|
|
144 | 145 |
|
145 |
if(status != GLES31.GL_FRAMEBUFFER_COMPLETE)
|
|
146 |
if(status != GLES30.GL_FRAMEBUFFER_COMPLETE)
|
|
146 | 147 |
{ |
147 |
android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status);
|
|
148 |
Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status); |
|
148 | 149 |
|
149 |
GLES31.glDeleteTextures(1, mColorH, 0);
|
|
150 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0);
|
|
151 |
GLES31.glDeleteFramebuffers(1, mFBOH, 0);
|
|
150 |
GLES30.glDeleteTextures(1, mColorH, 0);
|
|
151 |
GLES30.glDeleteTextures(1, mDepthStencilH, 0);
|
|
152 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0);
|
|
152 | 153 |
mFBOH[0]= 0; |
153 | 154 |
|
154 | 155 |
return FAILED_TO_CREATE; |
... | ... | |
164 | 165 |
{ |
165 | 166 |
if( mColorH[0]>0 ) |
166 | 167 |
{ |
167 |
GLES31.glDeleteTextures(mNumFBOs*mNumColors, mColorH, 0);
|
|
168 |
GLES30.glDeleteTextures(mNumFBOs*mNumColors, mColorH, 0);
|
|
168 | 169 |
mColorCreated = NOT_CREATED_YET; |
169 | 170 |
|
170 | 171 |
for(int i=0; i<mNumFBOs*mNumColors; i++) mColorH[i] = 0; |
... | ... | |
172 | 173 |
|
173 | 174 |
if( mDepthStencilH[0]>0 ) |
174 | 175 |
{ |
175 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
176 |
GLES30.glDeleteTextures(mNumFBOs, mDepthStencilH, 0);
|
|
176 | 177 |
mDepthStencilCreated = NOT_CREATED_YET; |
177 | 178 |
|
178 | 179 |
for(int i=0; i<mNumFBOs; i++) mDepthStencilH[i] = 0; |
179 | 180 |
} |
180 | 181 |
|
181 |
GLES31.glDeleteFramebuffers(mNumFBOs, mFBOH, 0);
|
|
182 |
GLES30.glDeleteFramebuffers(mNumFBOs, mFBOH, 0);
|
|
182 | 183 |
for(int i=0; i<mNumFBOs; i++) mFBOH[i] = 0; |
183 | 184 |
} |
184 | 185 |
|
... | ... | |
205 | 206 |
{ |
206 | 207 |
if( texture>=0 && texture<mNumColors && fbo>=0 && fbo<mNumFBOs && mColorH[mNumColors*fbo + texture]>0 ) |
207 | 208 |
{ |
208 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
209 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[mNumColors*fbo + texture]);
|
|
209 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
210 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[mNumColors*fbo + texture]);
|
|
210 | 211 |
return true; |
211 | 212 |
} |
212 | 213 |
|
... | ... | |
262 | 263 |
{ |
263 | 264 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
264 | 265 |
{ |
265 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
266 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture]);
|
|
266 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
267 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture]);
|
|
267 | 268 |
return true; |
268 | 269 |
} |
269 | 270 |
|
... | ... | |
280 | 281 |
{ |
281 | 282 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
282 | 283 |
{ |
283 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture], 0);
|
|
284 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[2*mCurrFBO+texture], 0);
|
|
284 | 285 |
} |
285 | 286 |
} |
286 | 287 |
|
Also available in: Unified diff
Lower requirements - now only OpenGL ES 3.0 is required; if running on such platform, OIT part of the API ( which is the only one which actually requires 3.1) is switched off.