Project

General

Profile

« Previous | Next » 

Revision c638c1b0

Added by Leszek Koltunski over 7 years ago

Further progress with Postprocessing. Now the missing bits are:

- implement Distorted.getFBO()
- implement Distorted.clean()
- improve compilation of DistortedPrograms so that the NUM_POSTPROCESSING and names of POSTPROCESSING effects will be #defined.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
29 29
import org.distorted.library.type.Data5D;
30 30
import org.distorted.library.type.Static3D;
31 31

  
32
import java.nio.ByteBuffer;
33
import java.nio.ByteOrder;
34
import java.nio.FloatBuffer;
35

  
32 36
///////////////////////////////////////////////////////////////////////////////////////////////////
33 37
/**
34 38
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
......
37 41
 */
38 42
public class DistortedEffects
39 43
  {
44
  private static final int BYTES_PER_FLOAT   = 4; //
45
  private static final int POSITION_DATA_SIZE= 2; // Size of the position data in elements
46
  private static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements.
47
  private static final FloatBuffer mQuadPositions, mQuadTexture;
48

  
40 49
  private static long mNextID =0;
41 50
  private long mID;
42 51

  
......
47 56

  
48 57
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
49 58

  
59
  static
60
    {
61
    int dataLength = 4;
62

  
63
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
64
    float[] textureData = {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
65

  
66
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
67
    mQuadPositions.put(positionData).position(0);
68
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
69
    mQuadTexture.put(textureData).position(0);
70
    }
71

  
50 72
///////////////////////////////////////////////////////////////////////////////////////////////////
51 73
    
52 74
  private void initializeEffectLists(DistortedEffects d, int flags)
......
121 143
      }
122 144
    else
123 145
      {
124
      DistortedFramebuffer fbo = null;
125
      // TODO : set this as output
146
      DistortedFramebuffer buffer = Distorted.getFBO(df.mWidth,df.mHeight);
126 147

  
127
      // render to the FBO just like above
128
      /*
129
      GLES20.glViewport(0, 0, fbo.mWidth, fbo.mHeight);
148
      GLES20.glViewport(0, 0, buffer.mWidth, buffer.mHeight);
149
      buffer.setAsOutput();
130 150

  
131
      mM.send(fbo,halfInputW,halfInputH,halfZ);
151
      mM.send(buffer,halfInputW,halfInputH,halfZ);
132 152
      mV.send(halfInputW,halfInputH,halfZ);
133 153
      mF.send(halfInputW,halfInputH);
134 154

  
135 155
      mesh.draw();
136
      */
137 156

  
138 157
      GLES20.glUseProgram(Distorted.postProgramH);
158
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
159
      buffer.setAsInput();
160
      df.setAsOutput();
161
      mP.send(halfInputW,halfInputH);
139 162

  
140
      // apply postprocess effects
141
      mP.postprocess(fbo,df);
163
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
164
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
165
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
142 166
      }
143 167
    }
144 168

  

Also available in: Unified diff