Revision af4cc5db
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedScreen.java | ||
---|---|---|
27 | 27 |
* <p> |
28 | 28 |
* User is able to render to it just like to a DistortedFramebuffer. |
29 | 29 |
*/ |
30 |
public class DistortedScreen extends DistortedRenderable implements DistortedOutputSurface
|
|
30 |
public class DistortedScreen extends DistortedOutputSurface |
|
31 | 31 |
{ |
32 |
private int[] mFBOH = new int[1]; |
|
33 |
private DistortedProjection mProjection; |
|
34 |
|
|
35 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 |
// here we don't manage underlying OpenGL assets ourselves |
|
36 | 34 |
|
37 | 35 |
public void create() {} |
38 | 36 |
void delete() {} |
... | ... | |
49 | 47 |
public DistortedScreen() |
50 | 48 |
{ |
51 | 49 |
super(0,0,DONT_CREATE); |
52 |
|
|
53 |
mProjection = new DistortedProjection(); |
|
54 |
mFBOH[0] = 0; |
|
55 | 50 |
} |
56 | 51 |
|
57 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
60 | 55 |
*/ |
61 | 56 |
public void setAsOutput() |
62 | 57 |
{ |
63 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
|
58 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
|
|
64 | 59 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST); |
65 | 60 |
GLES30.glDepthMask(true); |
66 | 61 |
} |
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
/** |
|
71 |
* Draw the (texture,mesh,effects) object to the Framebuffer. |
|
72 |
* <p> |
|
73 |
* Must be called from a thread holding OpenGL Context. |
|
74 |
* |
|
75 |
* @param surface InputSurface to skin our Mesh with. |
|
76 |
* @param mesh Class descendant from MeshObject |
|
77 |
* @param effects The DistortedEffects to use when rendering |
|
78 |
* @param time Current time, in milliseconds. |
|
79 |
*/ |
|
80 |
public void renderTo(DistortedInputSurface surface, MeshObject mesh, DistortedEffects effects, long time) |
|
81 |
{ |
|
82 |
surface.create(); // Watch out - this needs to be before |
|
83 |
create(); // the 'setAsInput' because this has side-effects! |
|
84 |
|
|
85 |
if( surface.setAsInput() ) |
|
86 |
{ |
|
87 |
DistortedRenderable.deleteAllMarked(); |
|
88 |
effects.drawPriv(surface.getWidth()/2.0f, surface.getHeight()/2.0f, mesh, this, time); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
/** |
|
94 |
* Draws the Tree, and all its children, to the Framebuffer. |
|
95 |
* <p> |
|
96 |
* Must be called from a thread holding OpenGL Context. |
|
97 |
* |
|
98 |
* @param dt DistortedTree to render. |
|
99 |
* @param time Current time, in milliseconds. This will be passed to all the Effects stored in the Tree. |
|
100 |
*/ |
|
101 |
public void renderTo(DistortedTree dt, long time) |
|
102 |
{ |
|
103 |
DistortedRenderable.deleteAllMarked(); |
|
104 |
create(); |
|
105 |
dt.drawRecursive(time,this); |
|
106 |
} |
|
107 |
|
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
/** |
|
110 |
* Create new Projection matrix. |
|
111 |
* |
|
112 |
* @param fov Vertical 'field of view' of the Projection frustrum (in degrees). |
|
113 |
* @param x X-coordinate of the point at which our camera looks at. 0 is the center. |
|
114 |
* @param y Y-coordinate of the point at which our camera looks at. 0 is the center. |
|
115 |
*/ |
|
116 |
public void setProjection(float fov, float x, float y) |
|
117 |
{ |
|
118 |
mProjection.set(fov,x,y); |
|
119 |
mProjection.createProjection(); |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
/** |
|
124 |
* Resize the underlying Projection. |
|
125 |
* |
|
126 |
* @param width The new width. |
|
127 |
* @param height The new height. |
|
128 |
*/ |
|
129 |
public void resize(int width, int height) |
|
130 |
{ |
|
131 |
if( mProjection.resize(width,height) ) |
|
132 |
{ |
|
133 |
mSizeX = width; |
|
134 |
mSizeY = height; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
/** |
|
140 |
* Return Projection stored in this Framebuffer. |
|
141 |
* |
|
142 |
* @return DistortedProjection object. |
|
143 |
*/ |
|
144 |
public DistortedProjection getProjection() |
|
145 |
{ |
|
146 |
return mProjection; |
|
147 |
} |
|
148 | 62 |
} |
Also available in: Unified diff
Simplify yesterday's refactoring.