Project

General

Profile

« Previous | Next » 

Revision c638c1b0

Added by Leszek Koltunski almost 8 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/Distorted.java
83 83
  static int mainProgramH, postProgramH;
84 84

  
85 85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// private: hide this from Javadoc
86 87

  
87 88
  private Distorted()
88 89
    {
89 90
    
90 91
    }
91 92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  static DistortedFramebuffer getFBO(int w, int h)
96
    {
97
    // TODO: a static factory of Framebuffers.
98

  
99
    return null;
100
    }
101

  
92 102
///////////////////////////////////////////////////////////////////////////////////////////////////
93 103

  
94 104
  static boolean isInitialized()
......
96 106
    return (mMainProgramAttributes!=null);
97 107
    }
98 108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
/**
111
 * Release all internal memory caches (in particular the FBOs used as buffers for postprocessing)
112
 */
113
  public static void clean()
114
    {
115
    // TODO
116
    }
117

  
99 118
///////////////////////////////////////////////////////////////////////////////////////////////////
100 119
/**
101 120
 * When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
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

  
src/main/java/org/distorted/library/EffectQueuePostprocess.java
98 98
    mTime = currTime;  
99 99
    }  
100 100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

  
103
  void postprocess(DistortedFramebuffer input, DistortedFramebuffer output)
104
    {
105
    // 1. Set input's COLOR0 as input texture
106
    // 2. Set output as output FBO
107
    // 3. set Vieport
108
    // 4. call send()
109
    // 5. render a quad:
110
    /*
111
    GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], MeshObject.POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mMeshPositions);
112
    GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], MeshObject.TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mMeshTexture);
113
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
114
    */
115
    }
116

  
117 101
///////////////////////////////////////////////////////////////////////////////////////////////////
118 102

  
119 103
  protected void moveEffect(int index)
......
125 109

  
126 110
///////////////////////////////////////////////////////////////////////////////////////////////////
127 111

  
128
  synchronized void send(float objX, float objY)
112
  synchronized void send(float halfX, float halfY)
129 113
    {
130 114
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
131
    GLES20.glUniform2f( mObjDH , objX, objY);
115
    GLES20.glUniform2f( mObjDH , halfX, halfY);
132 116

  
133 117
    if( mNumEffects>0 )
134 118
      {
......
139 123

  
140 124
///////////////////////////////////////////////////////////////////////////////////////////////////
141 125

  
142
  synchronized static void sendZero(float objX, float objY)
126
  synchronized static void sendZero(float halfX, float halfY)
143 127
    {
144 128
    GLES20.glUniform1i( mNumEffectsH, 0);
145
    GLES20.glUniform2f( mObjDH , objX, objY);
129
    GLES20.glUniform2f( mObjDH , halfX, halfY);
146 130
    }
147 131

  
148 132
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/raw/post_vertex_shader.glsl
17 17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18 18
//////////////////////////////////////////////////////////////////////////////////////////////
19 19

  
20
uniform vec2 u_objD;             // half of object width x half of object height.
21
                                 // point (0,0) is the center of the object
22

  
20 23
attribute vec2 a_Position;       // Per-vertex position information we will pass in.
21 24
attribute vec2 a_TexCoordinate;  // Per-vertex texture coordinate information we will pass in.
22 25
varying   vec2 v_TexCoordinate;  //
......
27 30
void main()
28 31
  {
29 32
  v_TexCoordinate = a_TexCoordinate;
30
  gl_Position = vec4(a_Position, 0.0, 1.0);
33
  gl_Position = vec4( 2.0*u_objD*a_Position, 0.0, 1.0);
31 34
  }

Also available in: Unified diff