Project

General

Profile

« Previous | Next » 

Revision 7cf783cb

Added by Leszek Koltunski almost 8 years ago

Attempt to bring DTexture and DFramebuffer closer together.

View differences:

src/main/java/org/distorted/library/DistortedEffectQueues.java
199 199
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
200 200
    {
201 201
    tex.createTexture();
202
    df.setAsOutput();
202
    df.createFBO();
203
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, df.fboIds[0]);
203 204
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
204 205
    drawPriv(currTime, tex, grid, df);
205 206
    DistortedFramebuffer.deleteAllMarked();
src/main/java/org/distorted/library/DistortedFramebuffer.java
50 50

  
51 51
  private float mX, mY, mFOV;
52 52

  
53
  private int[] texIds = new int[1];
54
  private int[] fboIds = new int[1];
53
  int[] texIds = new int[1];
54
  int[] fboIds = new int[1];
55 55

  
56 56
  private boolean mMarked;
57 57

  
......
62 62
///////////////////////////////////////////////////////////////////////////////////////////////////
63 63
// Must be called from a thread holding OpenGL Context
64 64

  
65
  private boolean createFBO()
65
  boolean createFBO()
66 66
    {
67
    GLES20.glGenTextures(1, texIds, 0);
68
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
69
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
70
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
71
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
72
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
73
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
67
    if( texIds[0]==TEXTURE_NOT_CREATED_YET )
68
      {
69
      GLES20.glGenTextures(1, texIds, 0);
70
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
71
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
72
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
73
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
74
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
75
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
74 76

  
75
    GLES20.glGenFramebuffers(1, fboIds, 0);
76
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
77
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0);
77
      GLES20.glGenFramebuffers(1, fboIds, 0);
78
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
79
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIds[0], 0);
78 80

  
79
    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
81
      int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
80 82

  
81
    if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
82
      {
83
      android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status);
84
      GLES20.glDeleteTextures(1, texIds, 0);
85
      GLES20.glDeleteFramebuffers(1, fboIds, 0);
86
      fboIds[0] = 0;
87
      texIds[0] = TEXTURE_FAILED_TO_CREATE;
88
      return false;
89
      }
83
      if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
84
        {
85
        android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status);
86
        GLES20.glDeleteTextures(1, texIds, 0);
87
        GLES20.glDeleteFramebuffers(1, fboIds, 0);
88
        fboIds[0] = 0;
89
        texIds[0] = TEXTURE_FAILED_TO_CREATE;
90
        return false;
91
        }
90 92

  
91
    mList.add(this);
92
    //android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
93
      mList.add(this);
94
      //android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
95
      }
93 96

  
94 97
    return true;
95 98
    }
......
113 116
    mMarked = false;
114 117
    }
115 118

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
// Must be called from a thread holding OpenGL Context
118

  
119
  void setAsOutput()
120
    {
121
    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
122

  
123
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
124
    }
125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// Must be called from a thread holding OpenGL Context
128

  
129
  void setAsInput()
130
    {
131
    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
132

  
133
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
134
    }
135

  
136 119
///////////////////////////////////////////////////////////////////////////////////////////////////
137 120

  
138 121
  void reset()
......
180 163

  
181 164
  static synchronized void onDestroy()
182 165
    {
166
    // There are issues with this. Namely, if one
167
    // 1. creates a DObjectTree (somewhere else than onSurfaceCreated of constructor so it does not get re-created on re-launch)
168
    // 2. minimizes the app (here mList would be cleared)
169
    // 3. re-launches the app
170
    // 4. deletes some nodes
171
    // then the underlying Framebuffers will never be deleted!
172

  
183 173
    mListMarked = false;
184 174
    mList.clear();
185 175
    }
src/main/java/org/distorted/library/DistortedObjectTree.java
81 81
      }
82 82
    else
83 83
      {
84
      mData.mDF.createFBO();
85

  
84 86
      if( mData.numRendered==0 )
85 87
        {
86
        mData.mDF.setAsOutput();
88
        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mData.mDF.fboIds[0]);
87 89

  
88 90
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
89 91
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
......
106 108
      mData.numRendered++;
107 109
      mData.numRendered %= mData.numPointingNodes;
108 110

  
109
      df.setAsOutput();
110
      mData.mDF.setAsInput();
111
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, df.fboIds[0]);
112
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mData.mDF.texIds[0]);
111 113
      }
112 114
    
113 115
    mQueues.drawPriv(currTime, mTexture, mGrid, df);
......
475 477
 */
476 478
  public void draw(long currTime, DistortedFramebuffer df)
477 479
    {
478
    df.setAsOutput();
480
    df.createFBO();
481
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, df.fboIds[0]);
479 482
    drawRecursive(currTime,df);
480 483
    DistortedFramebuffer.deleteAllMarked();
481 484
    DistortedTexture.deleteAllMarked();

Also available in: Unified diff