Project

General

Profile

« Previous | Next » 

Revision 9ed80185

Added by Leszek Koltunski almost 7 years ago

Beginnings of support for multi-COLOR attachment Framebuffers.
This will be used in OutputSurface's Postprocessing Buffer.

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
38 38
    {
39 39
    if( mColorCreated==NOT_CREATED_YET )
40 40
      {
41
      GLES30.glGenTextures(1, mColorH, 0);
42
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]);
43
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
44
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
45
      GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
46
      GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
47
      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mWidth, mHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
48
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
49

  
41
      GLES30.glGenTextures( mNumColors, mColorH, 0);
50 42
      GLES30.glGenFramebuffers(1, mFBOH, 0);
51 43
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
52
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0);
44

  
45
      for(int i=0; i<mNumColors; i++)
46
        {
47
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[i]);
48
        GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
49
        GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
50
        GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
51
        GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
52
        GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mWidth, mHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
53
        GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0+i, GLES30.GL_TEXTURE_2D, mColorH[i], 0);
54
        }
55

  
56
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
53 57
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0);
54 58

  
55 59
      mColorCreated = checkStatus("color");
......
162 166
// inside a Tree of DistortedNodes (TREE)
163 167
// SYSTEM surfaces do not get removed in onDestroy().
164 168

  
165
  DistortedFramebuffer(int depthStencil, int type, int width, int height)
169
  DistortedFramebuffer(int numcolors, int depthStencil, int type, int width, int height)
166 170
    {
167
    super(width,height,NOT_CREATED_YET,depthStencil,NOT_CREATED_YET, type);
171
    super(width,height,NOT_CREATED_YET,numcolors,depthStencil,NOT_CREATED_YET, type);
168 172
    }
169 173

  
170 174
///////////////////////////////////////////////////////////////////////////////////////////////////
......
186 190
// PUBLIC API
187 191
///////////////////////////////////////////////////////////////////////////////////////////////////
188 192
/**
189
 * Create a new offscreen Framebuffer.
193
 * Create new offscreen Framebuffer with configurable number of COLOR, DEPTH and STENCIL attachments.
190 194
 *
191
 * @param width Width of the COLOR attachment.
192
 * @param height Height of the COLOR attachment.
195
 * @param width        Width of all the COLOR attachments.
196
 * @param height       Height of all the COLOR attachments.
197
 * @param numcolors    How many COLOR attachments to create?
193 198
 * @param depthStencil Add DEPTH or STENCIL attachment?
194 199
 *                     Valid values: NO_DEPTH_NO_STENCIL, DEPTH_NO_STENCIL, BOTH_DEPTH_STENCIL.
195 200
 */
196 201
  @SuppressWarnings("unused")
197
  public DistortedFramebuffer(int width, int height, int depthStencil)
202
  public DistortedFramebuffer(int width, int height, int numcolors, int depthStencil)
198 203
    {
199
    super(width,height,NOT_CREATED_YET,depthStencil,NOT_CREATED_YET,TYPE_USER);
204
    super(width,height,NOT_CREATED_YET,numcolors,depthStencil,NOT_CREATED_YET,TYPE_USER);
200 205
    }
201 206

  
202 207
///////////////////////////////////////////////////////////////////////////////////////////////////
203 208

  
204 209
/**
205
 * Create a new offscreen Framebuffer. No DEPTH or STENCIL buffer will be created.
210
 * Create new offscreen Framebuffer with COLOR0 attachment only.
206 211
 *
207
 * @param width Width of the COLOR attachment.
208
 * @param height Height of the COLOR attachment.
212
 * @param width Width of the COLOR0 attachment.
213
 * @param height Height of the COLOR0 attachment.
209 214
 */
210 215
  @SuppressWarnings("unused")
211 216
  public DistortedFramebuffer(int width, int height)
212 217
    {
213
    super(width,height,NOT_CREATED_YET, NO_DEPTH_NO_STENCIL,NOT_CREATED_YET,TYPE_USER);
218
    super(width,height,NOT_CREATED_YET, 1, NO_DEPTH_NO_STENCIL,NOT_CREATED_YET,TYPE_USER);
214 219
    }
215 220

  
216 221
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedNode.java
248 248
      {
249 249
      int width  = mFboW <= 0 ? mSurface.getWidth()  : mFboW;
250 250
      int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
251
      newData.mFBO = new DistortedFramebuffer(mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
251
      newData.mFBO = new DistortedFramebuffer(1,mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
252 252
      //android.util.Log.d("NODE", "creating new FBO "+newData.mFBO.getID() );
253 253
      }
254 254

  
......
322 322
        {
323 323
        int width  = mFboW <= 0 ? mSurface.getWidth()  : mFboW;
324 324
        int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
325
        mData.mFBO = new DistortedFramebuffer(mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
325
        mData.mFBO = new DistortedFramebuffer(1,mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
326 326
        }
327 327

  
328 328
      mData.mFBO.setAsOutput(currTime);
......
451 451
          depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
452 452
          }
453 453

  
454
        mSurface = new DistortedFramebuffer(depthStencil,DistortedSurface.TYPE_TREE,w,h);
454
        mSurface = new DistortedFramebuffer(1,depthStencil,DistortedSurface.TYPE_TREE,w,h);
455 455
        }
456 456
      }
457 457
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
src/main/java/org/distorted/library/DistortedOutputSurface.java
84 84

  
85 85
///////////////////////////////////////////////////////////////////////////////////////////////////
86 86

  
87
  DistortedOutputSurface(int width, int height, int createColor, int depthStencil, int fbo, int type)
87
  DistortedOutputSurface(int width, int height, int createColor, int numcolors, int depthStencil, int fbo, int type)
88 88
    {
89
    super(width,height,createColor,type);
89
    super(width,height,createColor,numcolors,type);
90 90

  
91 91
    mProjectionMatrix = new float[16];
92 92

  
......
191 191

  
192 192
          for(int j=0; j<EffectQuality.LENGTH; j++)
193 193
            {
194
            mBuffer1[j] = new DistortedFramebuffer(BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
195
            mBuffer2[j] = new DistortedFramebuffer(BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
194
            mBuffer1[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
195
            mBuffer2[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
196 196
            mBuffer1[j].mMipmap = mipmap;
197 197
            mBuffer2[j].mMipmap = mipmap;
198 198
            mipmap *= EffectQuality.MULTIPLIER;
src/main/java/org/distorted/library/DistortedRenderState.java
119 119
    {
120 120
    if( cState.colorMaskR!=1 || cState.colorMaskG!=1 || cState.colorMaskB!=1 || cState.colorMaskA!=1 )
121 121
      {
122
      sState.colorMaskR = cState.colorMaskR;
123
      sState.colorMaskG = cState.colorMaskG;
124
      sState.colorMaskB = cState.colorMaskB;
125
      sState.colorMaskA = cState.colorMaskA;
122 126
      cState.colorMaskR = 1;
123 127
      cState.colorMaskG = 1;
124 128
      cState.colorMaskB = 1;
......
127 131
      }
128 132
    if( cState.depthMask!=1 )
129 133
      {
134
      sState.depthMask = cState.depthMask;
130 135
      cState.depthMask = 1;
131 136
      GLES30.glDepthMask(true);
132 137
      }
133 138
    if( cState.stencilMask!= STENCIL_MASK )
134 139
      {
140
      sState.stencilMask = cState.stencilMask;
135 141
      cState.stencilMask = STENCIL_MASK;
136 142
      GLES30.glStencilMask(cState.stencilMask);
137 143
      }
src/main/java/org/distorted/library/DistortedScreen.java
53 53
    {
54 54
    // set color to 'DONT_CREATE' so that Screens will not get added to the Surface lists
55 55
    // set depth to 'CREATED' so that depth will be, by default, on.
56
    super(0,0,DONT_CREATE,DEPTH_NO_STENCIL,0,TYPE_USER);
56
    super(0,0,DONT_CREATE,1,DEPTH_NO_STENCIL,0,TYPE_USER);
57 57

  
58 58
    if( view!=null )
59 59
      {
src/main/java/org/distorted/library/DistortedSurface.java
24 24
abstract class DistortedSurface extends DistortedObject
25 25
{
26 26
  int mColorCreated;
27
  int[] mColorH = new int[1];
27
  int mNumColors;
28
  int[] mColorH;
28 29
  int mWidth, mHeight;
29 30

  
30 31
///////////////////////////////////////////////////////////////////////////////////////////////////
31 32

  
32
  DistortedSurface(int width, int height, int create, int type)
33
  DistortedSurface(int width, int height, int create, int numcolors, int type)
33 34
    {
34 35
    super(create,type);
35 36

  
37
    mNumColors    = numcolors;
36 38
    mWidth        = width ;
37 39
    mHeight       = height;
38 40
    mColorCreated = create;
39
    mColorH[0]    = 0;
41

  
42
    if( mNumColors>0 )
43
      {
44
      mColorH = new int[mNumColors];
45
      for( int i=0; i<mNumColors; i++ )  mColorH[i] = 0;
46
      }
40 47
    }
41 48

  
42 49
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedTexture.java
115 115

  
116 116
  public DistortedTexture(int width, int height, int type)
117 117
    {
118
    super(width,height,NOT_CREATED_YET,type);
118
    super(width,height,NOT_CREATED_YET,1,type);
119 119
    mBmp= null;
120 120
    }
121 121

  
......
127 127
 */
128 128
  public DistortedTexture(int width, int height)
129 129
    {
130
    super(width,height,NOT_CREATED_YET,TYPE_USER);
130
    super(width,height,NOT_CREATED_YET,1,TYPE_USER);
131 131
    mBmp= null;
132 132
    }
133 133

  

Also available in: Unified diff