Revision 194ab46f
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library; |
21 | 21 |
|
22 |
import android.opengl.GLES20;
|
|
22 |
import android.opengl.GLES30;
|
|
23 | 23 |
import android.opengl.Matrix; |
24 | 24 |
|
25 | 25 |
import java.util.Iterator; |
... | ... | |
70 | 70 |
{ |
71 | 71 |
if( colorIds[0]==NOT_CREATED_YET ) |
72 | 72 |
{ |
73 |
GLES20.glGenTextures(1, colorIds, 0);
|
|
74 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, colorIds[0]);
|
|
75 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
|
|
76 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
|
|
77 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
|
|
78 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
|
|
79 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mTexWidth, mTexHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
|
|
80 |
|
|
81 |
GLES20.glGenFramebuffers(1, fboIds, 0);
|
|
82 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
|
83 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, colorIds[0], 0);
|
|
73 |
GLES30.glGenTextures(1, colorIds, 0);
|
|
74 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
|
|
75 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
76 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
77 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
78 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
|
|
79 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mTexWidth, mTexHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
|
|
80 |
|
|
81 |
GLES30.glGenFramebuffers(1, fboIds, 0);
|
|
82 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
|
|
83 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, colorIds[0], 0);
|
|
84 | 84 |
|
85 | 85 |
checkStatus("color"); |
86 | 86 |
} |
87 | 87 |
if( mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment |
88 | 88 |
{ |
89 |
GLES20.glGenTextures(1, depthIds, 0);
|
|
90 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, depthIds[0]);
|
|
91 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
|
|
92 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
|
|
93 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
|
|
94 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
|
|
95 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT, null);
|
|
89 |
GLES30.glGenTextures(1, depthIds, 0);
|
|
90 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, depthIds[0]);
|
|
91 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
92 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
93 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
94 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
|
|
95 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_SHORT, null);
|
|
96 | 96 |
|
97 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
|
98 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D, depthIds[0], 0);
|
|
97 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
|
|
98 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, depthIds[0], 0);
|
|
99 | 99 |
|
100 | 100 |
checkStatus("depth"); |
101 | 101 |
} |
102 | 102 |
if( !mDepthWanted && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment. |
103 | 103 |
{ |
104 |
GLES20.glDeleteTextures(1, depthIds, 0);
|
|
104 |
GLES30.glDeleteTextures(1, depthIds, 0);
|
|
105 | 105 |
depthIds[0]=NOT_CREATED_YET; |
106 | 106 |
} |
107 | 107 |
} |
... | ... | |
110 | 110 |
|
111 | 111 |
private boolean checkStatus(String message) |
112 | 112 |
{ |
113 |
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
|
|
113 |
int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
|
|
114 | 114 |
|
115 |
if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
|
|
115 |
if(status != GLES30.GL_FRAMEBUFFER_COMPLETE)
|
|
116 | 116 |
{ |
117 | 117 |
android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status); |
118 | 118 |
|
119 |
GLES20.glDeleteTextures(1, colorIds, 0);
|
|
120 |
GLES20.glDeleteTextures(1, depthIds, 0);
|
|
121 |
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
|
119 |
GLES30.glDeleteTextures(1, colorIds, 0);
|
|
120 |
GLES30.glDeleteTextures(1, depthIds, 0);
|
|
121 |
GLES30.glDeleteFramebuffers(1, fboIds, 0);
|
|
122 | 122 |
fboIds[0] = 0; |
123 | 123 |
colorIds[0] = FAILED_TO_CREATE; |
124 | 124 |
depthIds[0] = FAILED_TO_CREATE; |
... | ... | |
140 | 140 |
|
141 | 141 |
if( depthIds[0]>=0 ) |
142 | 142 |
{ |
143 |
GLES20.glDeleteTextures(1, depthIds, 0);
|
|
143 |
GLES30.glDeleteTextures(1, depthIds, 0);
|
|
144 | 144 |
depthIds[0]=NOT_CREATED_YET; |
145 | 145 |
} |
146 | 146 |
|
147 |
GLES20.glDeleteTextures(1, colorIds, 0);
|
|
147 |
GLES30.glDeleteTextures(1, colorIds, 0);
|
|
148 | 148 |
colorIds[0] = NOT_CREATED_YET; |
149 | 149 |
|
150 |
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
|
150 |
GLES30.glDeleteFramebuffers(1, fboIds, 0);
|
|
151 | 151 |
fboIds[0] = 0; |
152 | 152 |
} |
153 | 153 |
|
... | ... | |
158 | 158 |
|
159 | 159 |
void setAsOutput() |
160 | 160 |
{ |
161 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
|
|
161 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
|
|
162 | 162 |
|
163 | 163 |
if( depthIds[0]!=NOT_CREATED_YET ) |
164 | 164 |
{ |
165 |
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
|
166 |
GLES20.glDepthMask(true);
|
|
165 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST);
|
|
166 |
GLES30.glDepthMask(true);
|
|
167 | 167 |
} |
168 | 168 |
else |
169 | 169 |
{ |
170 |
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
|
|
171 |
GLES20.glDepthMask(false);
|
|
170 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST);
|
|
171 |
GLES30.glDepthMask(false);
|
|
172 | 172 |
} |
173 | 173 |
} |
174 | 174 |
|
... | ... | |
176 | 176 |
|
177 | 177 |
void setAsInput() |
178 | 178 |
{ |
179 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, colorIds[0]);
|
|
179 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
|
|
180 | 180 |
} |
181 | 181 |
|
182 | 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
388 | 388 |
DistortedFramebuffer.deleteAllMarked(); |
389 | 389 |
DistortedTexture.deleteAllMarked(); |
390 | 390 |
createFBO(); |
391 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fbo.colorIds[0]);
|
|
391 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, fbo.colorIds[0]);
|
|
392 | 392 |
effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, mesh, this, time); |
393 | 393 |
} |
394 | 394 |
} |
Also available in: Unified diff
Try using OpenGL ES 3.0 everywhere (but if device does not support it, try creating 2.0 context - this is important because of the emulator!)