Project

General

Profile

« Previous | Next » 

Revision af4cc5db

Added by Leszek Koltunski about 7 years ago

Simplify yesterday's refactoring.

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
28 28
 * User is able to create offscreen FBOs and both a) render to them b) use their COLOR0 attachment as
29 29
 * an input texture.
30 30
 */
31
public class DistortedFramebuffer extends DistortedRenderable implements DistortedInputSurface, DistortedOutputSurface
31
public class DistortedFramebuffer extends DistortedOutputSurface implements DistortedInputSurface
32 32
  {
33 33
  private int[] mDepthH = new int[1];
34 34
  private int[] mFBOH   = new int[1];
35 35
  private boolean mDepthEnabled;
36
  private DistortedProjection mProjection;
37 36

  
38 37
///////////////////////////////////////////////////////////////////////////////////////////////////
39 38
// Must be called from a thread holding OpenGL Context
......
136 135
// if new size fits into the size of the underlying Texture, just change the projection without
137 136
// reallocating the Texture. Otherwise, we need to reallocate.
138 137
//
139
// Must be called form a thread holding the OpenGL context.
138
// Must be called from a thread holding the OpenGL context.
140 139

  
141 140
  void resizeFast(int width, int height)
142 141
    {
143
    if( mProjection.resize(width,height) )
142
    if( mWidth!=width || mHeight!=height )
144 143
      {
144
      mWidth = width;
145
      mHeight= height;
146
      createProjection();
147

  
145 148
      if( width> mSizeX || height> mSizeY)
146 149
        {
147 150
        mSizeX = width;
......
167 170
  public DistortedFramebuffer(int width, int height, boolean depthEnabled)
168 171
    {
169 172
    super(width,height,NOT_CREATED_YET);
170

  
171
    mProjection  = new DistortedProjection(width,height);
172 173
    mDepthEnabled= depthEnabled;
173 174
    mFBOH[0]     = NOT_CREATED_YET;
174 175
    mDepthH[0]   = NOT_CREATED_YET;
......
186 187
  public DistortedFramebuffer(int width, int height)
187 188
    {
188 189
    super(width,height,NOT_CREATED_YET);
189

  
190
    mProjection  = new DistortedProjection(width,height);
191 190
    mDepthEnabled= false;
192 191
    mFBOH[0]     = NOT_CREATED_YET;
193 192
    mDepthH[0]   = NOT_CREATED_YET;
......
196 195
///////////////////////////////////////////////////////////////////////////////////////////////////
197 196
/**
198 197
 * Bind the underlying rectangle of pixels as a OpenGL Texture.
198
 *
199
 * @returns <code>true</code> if successful.
199 200
 */
200 201
  public boolean setAsInput()
201 202
    {
......
240 241
    mDepthEnabled = enable;
241 242
    }
242 243

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
/**
246
 * Draw the (texture,mesh,effects) object to the Framebuffer.
247
 * <p>
248
 * Must be called from a thread holding OpenGL Context.
249
 *
250
 * @param surface InputSurface to skin our Mesh with.
251
 * @param mesh Class descendant from MeshObject
252
 * @param effects The DistortedEffects to use when rendering
253
 * @param time Current time, in milliseconds.
254
 */
255
  public void renderTo(DistortedInputSurface surface, MeshObject mesh, DistortedEffects effects, long time)
256
    {
257
    surface.create();  // Watch out  - this needs to be before
258
    create();          // the 'setAsInput' because this has side-effects!
259

  
260
    if( surface.setAsInput() )
261
      {
262
      DistortedRenderable.deleteAllMarked();
263
      effects.drawPriv(surface.getWidth()/2.0f, surface.getHeight()/2.0f, mesh, this, time);
264
      }
265
    }
266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268
/**
269
 * Draws the Tree, and all its children, to the Framebuffer.
270
 * <p>
271
 * Must be called from a thread holding OpenGL Context.
272
 *
273
 * @param dt DistortedTree to render.
274
 * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the Tree.
275
 */
276
  public void renderTo(DistortedTree dt, long time)
277
    {
278
    DistortedRenderable.deleteAllMarked();
279
    create();
280
    dt.drawRecursive(time,this);
281
    }
282

  
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
/**
285
 * Create new Projection matrix.
286
 *
287
 * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
288
 * @param x X-coordinate of the point at which our camera looks at. 0 is the center.
289
 * @param y Y-coordinate of the point at which our camera looks at. 0 is the center.
290
 */
291
  public void setProjection(float fov, float x, float y)
292
    {
293
    mProjection.set(fov,x,y);
294
    mProjection.createProjection();
295
    }
296

  
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
/**
299
 * Resize the underlying Framebuffer.
300
 *
301
 * @param width The new width.
302
 * @param height The new height.
303
 */
304
  public void resize(int width, int height)
305
    {
306
    if( mProjection.resize(width,height) )
307
      {
308
      mSizeX = width;
309
      mSizeY = height;
310
      if( mColorH[0]>0 ) markForDeletion();
311
      }
312
    }
313

  
314 244
///////////////////////////////////////////////////////////////////////////////////////////////////
315 245
/**
316 246
 * Return the ID of the Texture (COLOR attachment 0) that's backing this FBO.
......
337 267
    {
338 268
    return mDepthEnabled;
339 269
    }
340

  
341
//////////////////////////////////////////////////////////////////////////////////////////////////
342
/**
343
 * Return Projection stored in this Framebuffer.
344
 *
345
 * @return DistortedProjection object.
346
 */
347
  public DistortedProjection getProjection()
348
    {
349
    return mProjection;
350
    }
351 270
  }

Also available in: Unified diff