1 |
c5369f1b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.library;
|
21 |
|
|
|
22 |
|
|
import android.opengl.GLES30;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
/**
|
26 |
|
|
* Class which represents the Screen.
|
27 |
|
|
* <p>
|
28 |
|
|
* User is able to render to it just like to a DistortedFramebuffer.
|
29 |
|
|
*/
|
30 |
|
|
public class DistortedScreen extends DistortedRenderable implements DistortedOutputSurface
|
31 |
|
|
{
|
32 |
|
|
private int[] mFBOH = new int[1];
|
33 |
|
|
private DistortedProjection mProjection;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public void create() {}
|
38 |
|
|
void delete() {}
|
39 |
|
|
void destroy() {}
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
// PUBLIC API
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
/**
|
45 |
|
|
* Create a new Screen.
|
46 |
|
|
* <p>
|
47 |
|
|
* Has to be followed by a 'resize()' to set the size.
|
48 |
|
|
*/
|
49 |
|
|
public DistortedScreen()
|
50 |
|
|
{
|
51 |
|
|
super(0,0,DONT_CREATE);
|
52 |
|
|
|
53 |
|
|
mProjection = new DistortedProjection();
|
54 |
|
|
mFBOH[0] = 0;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
/**
|
59 |
|
|
* Bind this Surface as a Framebuffer we can render to.
|
60 |
|
|
*/
|
61 |
|
|
public void setAsOutput()
|
62 |
|
|
{
|
63 |
|
|
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
|
64 |
|
|
GLES30.glEnable(GLES30.GL_DEPTH_TEST);
|
65 |
|
|
GLES30.glDepthMask(true);
|
66 |
|
|
}
|
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 |
|
|
}
|