Revision 638b5b5c
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
28 | 28 |
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedSlave |
29 | 29 |
{ |
30 | 30 |
private static final int NUM_MIPMAP = 4; |
31 |
static final int CUR_MIPMAP = 0;
|
|
31 |
static final int CUR_MIPMAP = 1;
|
|
32 | 32 |
|
33 | 33 |
private static final int ATTACH = 0; |
34 | 34 |
private static final int DETACH = 1; |
... | ... | |
101 | 101 |
|
102 | 102 |
mBuffer1 = new DistortedFramebuffer[NUM_MIPMAP]; |
103 | 103 |
mBuffer2 = new DistortedFramebuffer[NUM_MIPMAP]; |
104 |
mMipmap = 1.0f; |
|
104 |
|
|
105 |
mMipmap = (this instanceof DistortedScreen ? 0.5f : 1.0f); |
|
105 | 106 |
|
106 | 107 |
createProjection(); |
107 | 108 |
} |
... | ... | |
112 | 113 |
{ |
113 | 114 |
if( mWidth>0 && mHeight>1 ) |
114 | 115 |
{ |
116 |
float mw = mWidth;//mMipmap*mWidth; |
|
117 |
float mh = mHeight;//mMipmap*mHeight; |
|
118 |
|
|
115 | 119 |
if( mFOV>0.0f ) // perspective projection |
116 | 120 |
{ |
117 | 121 |
float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360); |
118 |
float q = mWidth*mNear;
|
|
119 |
float c = mHeight*mNear;
|
|
122 |
float q = mw*mNear;
|
|
123 |
float c = mh*mNear;
|
|
120 | 124 |
|
121 | 125 |
float left = -q/2; |
122 | 126 |
float right = +q/2; |
... | ... | |
124 | 128 |
float top = +c/2; |
125 | 129 |
float near = c/a; |
126 | 130 |
|
127 |
mDistance = mHeight/a;
|
|
131 |
mDistance = mh/a;
|
|
128 | 132 |
float far = 2*mDistance-near; |
129 | 133 |
|
130 | 134 |
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
131 | 135 |
} |
132 | 136 |
else // parallel projection |
133 | 137 |
{ |
134 |
float left = -mWidth /2.0f;
|
|
135 |
float right = +mWidth /2.0f;
|
|
136 |
float bottom = -mHeight/2.0f;
|
|
137 |
float top = +mHeight/2.0f;
|
|
138 |
float near = mWidth+mHeight-mHeight*(1.0f-mNear);
|
|
139 |
mDistance = mWidth+mHeight;
|
|
140 |
float far = mWidth+mHeight+mHeight*(1.0f-mNear);
|
|
138 |
float left = -mw/2.0f;
|
|
139 |
float right = +mw/2.0f;
|
|
140 |
float bottom = -mh/2.0f;
|
|
141 |
float top = +mh/2.0f;
|
|
142 |
float near = mw+mh-mh*(1.0f-mNear);
|
|
143 |
mDistance = mw+mh;
|
|
144 |
float far = mw+mh+mh*(1.0f-mNear);
|
|
141 | 145 |
|
142 | 146 |
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
143 | 147 |
} |
... | ... | |
302 | 306 |
} |
303 | 307 |
} |
304 | 308 |
|
309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
310 |
/** |
|
311 |
* Set mipmap level. |
|
312 |
* <p> |
|
313 |
* Trick for speeding up your renders - one can create a pyramid of OutputSurface objects, each next |
|
314 |
* one some constant FACTOR smaller than the previous (0.5 is the common value), then set the Mipmap |
|
315 |
* Level of the i-th object to be FACTOR^i (we start counting from 0). When rendering any scene into |
|
316 |
* such prepared OutputSurface, the library will make sure to scale any Effects used so that the end |
|
317 |
* scene will end up looking identical no matter which object we render to. Identical, that is, except |
|
318 |
* for the loss of quality and gain in speed associated with rendering to a smaller Surface. |
|
319 |
* |
|
320 |
* @param mipmap The mipmap level. Acceptable range: 0<mipmap<infinity, although mipmap>1 |
|
321 |
* does not make any sense (that would result in loss of speed and no gain in quality) |
|
322 |
*/ |
|
323 |
public void setMipmap(float mipmap) |
|
324 |
{ |
|
325 |
mMipmap = mipmap; |
|
326 |
createProjection(); |
|
327 |
} |
|
328 |
|
|
305 | 329 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
306 | 330 |
/** |
307 | 331 |
* Set the (R,G,B,A) values of GLES30.glClearColor() to set up color with which to clear |
Also available in: Unified diff
More MIPMAP work.