Revision c7da4e65
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
37 | 37 |
|
38 | 38 |
void create() |
39 | 39 |
{ |
40 |
if( mColorH[0]==NOT_CREATED_YET )
|
|
40 |
if( mColorCreated==NOT_CREATED_YET )
|
|
41 | 41 |
{ |
42 | 42 |
GLES30.glGenTextures(1, mColorH, 0); |
43 | 43 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]); |
... | ... | |
51 | 51 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]); |
52 | 52 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0); |
53 | 53 |
|
54 |
checkStatus("color"); |
|
54 |
mColorCreated = checkStatus("color");
|
|
55 | 55 |
} |
56 |
if( mDepthEnabled && mDepthH[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
|
|
56 |
if( mDepthCreated==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
|
|
57 | 57 |
{ |
58 | 58 |
GLES30.glGenTextures(1, mDepthH, 0); |
59 | 59 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthH[0]); |
... | ... | |
66 | 66 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]); |
67 | 67 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, mDepthH[0], 0); |
68 | 68 |
|
69 |
checkStatus("depth"); |
|
69 |
mDepthCreated = checkStatus("depth");
|
|
70 | 70 |
} |
71 |
if( !mDepthEnabled && mDepthH[0]!=NOT_CREATED_YET ) // we need to detach and recreate the DEPTH attachment.
|
|
71 |
if( mDepthCreated==DONT_CREATE && mDepthH[0]>0 ) // we need to detach and recreate the DEPTH attachment.
|
|
72 | 72 |
{ |
73 | 73 |
GLES30.glDeleteTextures(1, mDepthH, 0); |
74 |
mDepthH[0]=NOT_CREATED_YET;
|
|
74 |
mDepthH[0]=0;
|
|
75 | 75 |
} |
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 | 79 |
|
80 |
private boolean checkStatus(String message)
|
|
80 |
private int checkStatus(String message)
|
|
81 | 81 |
{ |
82 | 82 |
int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER); |
83 | 83 |
|
... | ... | |
88 | 88 |
GLES30.glDeleteTextures(1, mColorH, 0); |
89 | 89 |
GLES30.glDeleteTextures(1, mDepthH, 0); |
90 | 90 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0); |
91 |
mFBOH[0] = 0; |
|
92 |
mColorH[0] = FAILED_TO_CREATE; |
|
93 |
mDepthH[0] = FAILED_TO_CREATE; |
|
91 |
mFBOH[0]= 0; |
|
94 | 92 |
|
95 |
return false;
|
|
93 |
return FAILED_TO_CREATE;
|
|
96 | 94 |
} |
97 | 95 |
|
98 |
return true;
|
|
96 |
return CREATED;
|
|
99 | 97 |
} |
100 | 98 |
|
101 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
103 | 101 |
|
104 | 102 |
void delete() |
105 | 103 |
{ |
106 |
if( mColorH[0]>=0 )
|
|
104 |
if( mColorH[0]>0 ) |
|
107 | 105 |
{ |
108 |
if( mDepthH[0]>=0 )
|
|
106 |
if( mDepthH[0]>0 ) |
|
109 | 107 |
{ |
110 | 108 |
GLES30.glDeleteTextures(1, mDepthH, 0); |
111 |
mDepthH[0]=NOT_CREATED_YET; |
|
109 |
mDepthH[0]=0; |
|
110 |
mDepthCreated = NOT_CREATED_YET; |
|
112 | 111 |
} |
113 | 112 |
|
114 | 113 |
GLES30.glDeleteTextures(1, mColorH, 0); |
115 |
mColorH[0] = NOT_CREATED_YET; |
|
114 |
mColorH[0] = 0; |
|
115 |
mColorCreated = NOT_CREATED_YET; |
|
116 | 116 |
|
117 | 117 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0); |
118 | 118 |
mFBOH[0] = 0; |
... | ... | |
124 | 124 |
|
125 | 125 |
void recreate() |
126 | 126 |
{ |
127 |
if( mColorH[0]!=DONT_CREATE ) mColorH[0] = NOT_CREATED_YET;
|
|
128 |
if( mDepthEnabled ) mDepthH[0] = NOT_CREATED_YET;
|
|
127 |
if( mColorCreated!=DONT_CREATE ) mColorCreated = NOT_CREATED_YET;
|
|
128 |
if( mDepthCreated!=DONT_CREATE ) mDepthCreated = NOT_CREATED_YET;
|
|
129 | 129 |
} |
130 | 130 |
|
131 | 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
159 | 159 |
|
160 | 160 |
DistortedFramebuffer(boolean depthEnabled, int width, int height) |
161 | 161 |
{ |
162 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,true, depthEnabled);
|
|
162 |
super(width,height,NOT_CREATED_YET, (depthEnabled ? NOT_CREATED_YET:DONT_CREATE),NOT_CREATED_YET, true);
|
|
163 | 163 |
} |
164 | 164 |
|
165 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
175 | 175 |
@SuppressWarnings("unused") |
176 | 176 |
public DistortedFramebuffer(int width, int height, boolean depthEnabled) |
177 | 177 |
{ |
178 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false, depthEnabled);
|
|
178 |
super(width,height,NOT_CREATED_YET,(depthEnabled ? NOT_CREATED_YET:DONT_CREATE),NOT_CREATED_YET,false);
|
|
179 | 179 |
} |
180 | 180 |
|
181 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
189 | 189 |
@SuppressWarnings("unused") |
190 | 190 |
public DistortedFramebuffer(int width, int height) |
191 | 191 |
{ |
192 |
super(width,height,NOT_CREATED_YET,NOT_CREATED_YET,false,false);
|
|
192 |
super(width,height,NOT_CREATED_YET,DONT_CREATE,NOT_CREATED_YET,false);
|
|
193 | 193 |
} |
194 | 194 |
|
195 | 195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fix OutputSurface.resize(): before it couldn't be called mid-render.