Revision e6cf7d50
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
private boolean mMarked; |
58 | 58 |
|
59 |
int mWidth,mHeight,mDepth,mDistance; |
|
59 |
int mWidth,mHeight,mDepth; |
|
60 |
float mDistance; |
|
60 | 61 |
float[] mProjectionMatrix; |
61 | 62 |
|
62 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 64 |
|
64 | 65 |
private void createProjection() |
65 | 66 |
{ |
66 |
if( mWidth>0 && mHeight>0 )
|
|
67 |
if( mWidth>0 && mHeight>1 )
|
|
67 | 68 |
{ |
68 | 69 |
if( mFOV>0.0f ) // perspective projection |
69 | 70 |
{ |
70 |
float left = (-mX-mWidth/2 )/mHeight;
|
|
71 |
float right = (-mX+mWidth/2 )/mHeight;
|
|
72 |
float bottom = (-mY-mHeight/2)/mHeight; |
|
73 |
float top = (-mY+mHeight/2)/mHeight; |
|
74 |
float near = (float)( (top-bottom) / (2*Math.tan(mFOV*Math.PI/360)) );
|
|
75 |
mDistance = (int)(mHeight*near/(top-bottom));
|
|
71 |
float left = (-mX-mWidth /2.0f)/mHeight;
|
|
72 |
float right = (-mX+mWidth /2.0f)/mHeight;
|
|
73 |
float bottom = (-mY-mHeight/2.0f)/mHeight;
|
|
74 |
float top = (-mY+mHeight/2.0f)/mHeight;
|
|
75 |
float near = (top-bottom) / (2.0f*(float)Math.tan(mFOV*Math.PI/360));
|
|
76 |
mDistance = mHeight*near/(top-bottom);
|
|
76 | 77 |
float far = 2*mDistance-near; |
77 | 78 |
mDepth = (int)((far-near)/2); |
78 | 79 |
|
... | ... | |
80 | 81 |
} |
81 | 82 |
else // parallel projection |
82 | 83 |
{ |
83 |
float left = -mX-mWidth/2;
|
|
84 |
float right = -mX+mWidth/2;
|
|
85 |
float bottom = -mY-mHeight/2; |
|
86 |
float top = -mY+mHeight/2; |
|
87 |
float near = (float)( (top-bottom) / (2*Math.tan(Math.PI/360)) );
|
|
88 |
mDistance = (int)(mHeight*near/(top-bottom));
|
|
84 |
float left = -mX-mWidth /2.0f;
|
|
85 |
float right = -mX+mWidth /2.0f;
|
|
86 |
float bottom = -mY-mHeight/2.0f;
|
|
87 |
float top = -mY+mHeight/2.0f;
|
|
88 |
float near = (top-bottom) / (2.0f*(float)Math.tan(Math.PI/360));
|
|
89 |
mDistance = mHeight*near/(top-bottom);
|
|
89 | 90 |
float far = 2*mDistance-near; |
90 | 91 |
mDepth = (int)((far-near)/2); |
91 | 92 |
|
... | ... | |
130 | 131 |
} |
131 | 132 |
|
132 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
133 |
// must be called form a thread holding OpenGL Context
|
|
134 |
// must be called from a thread holding OpenGL Context
|
|
134 | 135 |
|
135 | 136 |
private void deleteFBO() |
136 | 137 |
{ |
137 |
android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
138 |
|
|
139 |
GLES20.glDeleteTextures(1, texIds, 0); |
|
140 |
GLES20.glDeleteFramebuffers(1, fboIds, 0); |
|
141 |
|
|
142 |
fboIds[0] = 0; |
|
143 |
texIds[0] = TEXTURE_NOT_CREATED_YET; |
|
144 |
} |
|
138 |
if( texIds[0]>=0 ) |
|
139 |
{ |
|
140 |
android.util.Log.e("FBO", "deleting ("+mWidth+","+mHeight+") "+fboIds[0]); |
|
145 | 141 |
|
146 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
147 |
// must be called from a thread holding OpenGL Context
|
|
142 |
GLES20.glDeleteTextures(1, texIds, 0);
|
|
143 |
GLES20.glDeleteFramebuffers(1, fboIds, 0);
|
|
148 | 144 |
|
149 |
private void delete()
|
|
150 |
{
|
|
151 |
if( texIds[0]>=0 ) deleteFBO();
|
|
145 |
fboIds[0] = 0;
|
|
146 |
texIds[0] = TEXTURE_NOT_CREATED_YET;
|
|
147 |
}
|
|
152 | 148 |
|
153 |
mProjectionMatrix = null; |
|
154 | 149 |
mMarked = false; |
155 | 150 |
} |
156 | 151 |
|
... | ... | |
185 | 180 |
|
186 | 181 |
if( tmp.mMarked ) |
187 | 182 |
{ |
188 |
tmp.delete(); |
|
183 |
tmp.deleteFBO();
|
|
189 | 184 |
iterator.remove(); |
190 | 185 |
} |
191 | 186 |
} |
Also available in: Unified diff
1. (hopefully) finish the 'Save' app (now we can adjust the size of the resulting file)
2. Fix one long-standing bug in almost every single app.