Revision e6519ac8
Added by Leszek Koltunski about 6 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.GLES30;
|
|
22 |
import android.opengl.GLES31;
|
|
23 | 23 |
|
24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
/** |
... | ... | |
43 | 43 |
{ |
44 | 44 |
if( mColorCreated==NOT_CREATED_YET ) |
45 | 45 |
{ |
46 |
GLES30.glGenTextures( mNumColors, mColorH, 0);
|
|
47 |
GLES30.glGenFramebuffers(1, mFBOH, 0);
|
|
48 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
|
46 |
GLES31.glGenTextures( mNumColors, mColorH, 0);
|
|
47 |
GLES31.glGenFramebuffers(1, mFBOH, 0);
|
|
48 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
|
|
49 | 49 |
|
50 | 50 |
for(int i=0; i<mNumColors; i++) |
51 | 51 |
{ |
52 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[i]);
|
|
53 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
54 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
55 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
56 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
|
|
57 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mWidth, mHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
|
|
52 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[i]);
|
|
53 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
54 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
55 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
56 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR);
|
|
57 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mWidth, mHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null);
|
|
58 | 58 |
} |
59 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0);
|
|
60 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
61 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
59 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[0], 0);
|
|
60 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
61 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
62 | 62 |
|
63 | 63 |
mColorCreated = checkStatus("color"); |
64 | 64 |
} |
65 | 65 |
if( mDepthStencilCreated==NOT_CREATED_YET ) // we need to create a new DEPTH or STENCIL attachment |
66 | 66 |
{ |
67 |
GLES30.glGenTextures(1, mDepthStencilH, 0);
|
|
68 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthStencilH[0]);
|
|
69 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
|
|
70 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
|
|
71 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
|
|
72 |
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
|
|
67 |
GLES31.glGenTextures(1, mDepthStencilH, 0);
|
|
68 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[0]);
|
|
69 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT);
|
|
70 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
|
|
71 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
|
|
72 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_NEAREST);
|
|
73 | 73 |
|
74 | 74 |
if( mDepthStencil==DEPTH_NO_STENCIL ) |
75 | 75 |
{ |
76 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_INT, null);
|
|
76 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null);
|
|
77 | 77 |
} |
78 | 78 |
else if( mDepthStencil==BOTH_DEPTH_STENCIL ) |
79 | 79 |
{ |
80 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH24_STENCIL8, mWidth, mHeight, 0, GLES30.GL_DEPTH_STENCIL, GLES30.GL_UNSIGNED_INT_24_8, null);
|
|
80 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mWidth, mHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null);
|
|
81 | 81 |
} |
82 | 82 |
|
83 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
|
84 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
|
83 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
|
|
84 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
|
|
85 | 85 |
|
86 | 86 |
if( mDepthStencil==DEPTH_NO_STENCIL ) |
87 | 87 |
{ |
88 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[0], 0);
|
|
88 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[0], 0);
|
|
89 | 89 |
} |
90 | 90 |
else if( mDepthStencil==BOTH_DEPTH_STENCIL ) |
91 | 91 |
{ |
92 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthStencilH[0], 0);
|
|
92 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[0], 0);
|
|
93 | 93 |
} |
94 | 94 |
|
95 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
95 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
96 | 96 |
|
97 | 97 |
mDepthStencilCreated = checkStatus("depth"); |
98 | 98 |
} |
... | ... | |
101 | 101 |
// OpenGL ES 3.0.5 spec, chapter 4.4.2.4 : |
102 | 102 |
// "Note that the texture image is specifically not detached from any other framebuffer objects. |
103 | 103 |
// Detaching the texture image from any other framebuffer objects is the responsibility of the application." |
104 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
|
105 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT , GLES30.GL_TEXTURE_2D, 0, 0);
|
|
106 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, 0, 0);
|
|
107 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
104 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
|
|
105 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT , GLES31.GL_TEXTURE_2D, 0, 0);
|
|
106 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0);
|
|
107 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
|
|
108 | 108 |
|
109 |
GLES30.glDeleteTextures(1, mDepthStencilH, 0);
|
|
109 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0);
|
|
110 | 110 |
mDepthStencilH[0]=0; |
111 | 111 |
} |
112 | 112 |
} |
... | ... | |
115 | 115 |
|
116 | 116 |
private int checkStatus(String message) |
117 | 117 |
{ |
118 |
int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
|
|
118 |
int status = GLES31.glCheckFramebufferStatus(GLES31.GL_FRAMEBUFFER);
|
|
119 | 119 |
|
120 |
if(status != GLES30.GL_FRAMEBUFFER_COMPLETE)
|
|
120 |
if(status != GLES31.GL_FRAMEBUFFER_COMPLETE)
|
|
121 | 121 |
{ |
122 | 122 |
android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status); |
123 | 123 |
|
124 |
GLES30.glDeleteTextures(1, mColorH, 0);
|
|
125 |
GLES30.glDeleteTextures(1, mDepthStencilH, 0);
|
|
126 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0);
|
|
124 |
GLES31.glDeleteTextures(1, mColorH, 0);
|
|
125 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0);
|
|
126 |
GLES31.glDeleteFramebuffers(1, mFBOH, 0);
|
|
127 | 127 |
mFBOH[0]= 0; |
128 | 128 |
|
129 | 129 |
return FAILED_TO_CREATE; |
... | ... | |
139 | 139 |
{ |
140 | 140 |
if( mColorH[0]>0 ) |
141 | 141 |
{ |
142 |
GLES30.glDeleteTextures(1, mColorH, 0);
|
|
142 |
GLES31.glDeleteTextures(1, mColorH, 0);
|
|
143 | 143 |
mColorH[0] = 0; |
144 | 144 |
mColorCreated = NOT_CREATED_YET; |
145 | 145 |
} |
146 | 146 |
|
147 | 147 |
if( mDepthStencilH[0]>0 ) |
148 | 148 |
{ |
149 |
GLES30.glDeleteTextures(1, mDepthStencilH, 0);
|
|
149 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0);
|
|
150 | 150 |
mDepthStencilH[0]=0; |
151 | 151 |
mDepthStencilCreated = NOT_CREATED_YET; |
152 | 152 |
} |
153 | 153 |
|
154 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0);
|
|
154 |
GLES31.glDeleteFramebuffers(1, mFBOH, 0);
|
|
155 | 155 |
mFBOH[0] = 0; |
156 | 156 |
} |
157 | 157 |
|
... | ... | |
225 | 225 |
{ |
226 | 226 |
if( mColorH[0]>0 ) |
227 | 227 |
{ |
228 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
229 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
|
|
228 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
229 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[0]);
|
|
230 | 230 |
return true; |
231 | 231 |
} |
232 | 232 |
|
... | ... | |
243 | 243 |
{ |
244 | 244 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
245 | 245 |
{ |
246 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
|
|
247 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[texture]);
|
|
246 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
|
|
247 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[texture]);
|
|
248 | 248 |
return true; |
249 | 249 |
} |
250 | 250 |
|
... | ... | |
257 | 257 |
{ |
258 | 258 |
if( texture>=0 && texture<mNumColors && mColorH[texture]>0 ) |
259 | 259 |
{ |
260 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[texture], 0);
|
|
260 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[texture], 0);
|
|
261 | 261 |
} |
262 | 262 |
} |
263 | 263 |
|
Also available in: Unified diff
Up library requirements to OpenGL ES 3.1 (needed for the upcoming GL_SHADER_STORAGE_BUFFER)