Project

General

Profile

« Previous | Next » 

Revision c5369f1b

Added by Leszek Koltunski about 7 years ago

Major: change of API.

Split DFramebuffer into Framebuffer and Screen; introduce the 'DistortedInputSurface' and 'DistortedOutputSurface' interfaces.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
183 183
// DEBUG ONLY
184 184

  
185 185
  @SuppressWarnings("unused")
186
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedFramebuffer df, float[] mvp, float[] vertices)
186
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices)
187 187
    {
188 188
    int len  = vertices.length/3;
189 189
    int minx = Integer.MAX_VALUE;
......
194 194

  
195 195
    float x,y,z, X,Y,W, ndcX,ndcY;
196 196

  
197
    DistortedProjection projection = surface.getProjection();
198

  
197 199
    for(int i=0; i<len; i++)
198 200
      {
199 201
      x = 2*halfX*vertices[3*i  ];
......
207 209
      ndcX = X/W;
208 210
      ndcY = Y/W;
209 211

  
210
      wx = (int)(df.mWidth *(ndcX+1)/2);
211
      wy = (int)(df.mHeight*(ndcY+1)/2);
212
      wx = (int)(projection.mWidth *(ndcX+1)/2);
213
      wy = (int)(projection.mHeight*(ndcY+1)/2);
212 214

  
213 215
      if( wx<minx ) minx = wx;
214 216
      if( wx>maxx ) maxx = wx;
......
217 219
      }
218 220

  
219 221
    mDebugProgram.useProgram();
220
    df.setAsOutput();
222
    surface.setAsOutput();
221 223

  
222 224
    Matrix.setIdentityM( mTmpMatrix, 0);
223
    Matrix.translateM  ( mTmpMatrix, 0, minx-df.mWidth/2, maxy-df.mHeight/2, -df.mDistance);
225
    Matrix.translateM  ( mTmpMatrix, 0, minx-projection.mWidth/2, maxy-projection.mHeight/2, -projection.mDistance);
224 226
    Matrix.scaleM      ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
225 227
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
226
    Matrix.multiplyMM  ( mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
228
    Matrix.multiplyMM  ( mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0);
227 229

  
228 230
    GLES30.glUniform2f( mObjDH , 2*halfX, 2*halfY);
229 231
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
......
234 236

  
235 237
///////////////////////////////////////////////////////////////////////////////////////////////////
236 238

  
237
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
239
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
238 240
    {
239 241
    mM.compute(currTime);
240 242
    mV.compute(currTime);
......
242 244
    mP.compute(currTime);
243 245

  
244 246
    float halfZ = halfInputW*mesh.zFactor;
245
    GLES30.glViewport(0, 0, df.mWidth, df.mHeight);
247
    DistortedProjection projection = surface.getProjection();
248
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
246 249

  
247 250
    if( mP.mNumEffects==0 )
248 251
      {
249 252
      mProgram.useProgram();
250
      df.setAsOutput();
251
      mM.send(df,halfInputW,halfInputH,halfZ);
253
      surface.setAsOutput();
254
      mM.send(projection,halfInputW,halfInputH,halfZ);
252 255
      mV.send(halfInputW,halfInputH,halfZ);
253 256
      mF.send(halfInputW,halfInputH);
254 257
      GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
......
260 263
      {
261 264
      if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
262 265
        {
263
        mM.constructMatrices(df,halfInputW,halfInputH);
264
        mP.render(2*halfInputW, 2*halfInputH, mM.getMVP(), df);
266
        mM.constructMatrices(projection,halfInputW,halfInputH);
267
        mP.render(2*halfInputW, 2*halfInputH, mM.getMVP(), surface);
265 268
        }
266 269
      else
267 270
        {
268 271
        mProgram.useProgram();
269
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
272
        mBufferFBO.resizeFast(projection.mWidth, projection.mHeight);
270 273
        mBufferFBO.setAsOutput();
271 274
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
272 275
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
273
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
276
        mM.send(mBufferFBO.getProjection(),halfInputW,halfInputH,halfZ);
274 277
        mV.send(halfInputW,halfInputH,halfZ);
275 278
        mF.send(halfInputW,halfInputH);
276 279
        GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
......
279 282
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
280 283

  
281 284
        Matrix.setIdentityM(mTmpMatrix, 0);
282
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
283
        Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
285
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -projection.mDistance);
286
        Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0);
284 287

  
285 288
        mBufferFBO.setAsInput();
286
        mP.render(df.mWidth, df.mHeight, mMVPMatrix, df);
289
        mP.render(projection.mWidth, projection.mHeight, mMVPMatrix, surface);
287 290
        }
288 291
      }
289 292

  
......
294 297

  
295 298
///////////////////////////////////////////////////////////////////////////////////////////////////
296 299
   
297
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
300
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedProjection projection)
298 301
    {
299
    GLES30.glViewport(0, 0, df.mWidth, df.mHeight);
302
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
300 303

  
301 304
    Matrix.setIdentityM(mTmpMatrix, 0);
302
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
303
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
305
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -projection.mDistance);
306
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0);
304 307

  
305
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
308
    EffectQueueMatrix.sendZero(projection,halfInputW,halfInputH,halfInputW*mesh.zFactor);
306 309
    EffectQueueVertex.sendZero();
307 310
    EffectQueueFragment.sendZero();
308 311

  

Also available in: Unified diff