Project

General

Profile

« Previous | Next » 

Revision c834348d

Added by Leszek Koltunski almost 8 years ago

Make it possible to render each DistortedNode with adjustable OpeGL state (writeing to Color, Depth,Stencil buffers, DEPTH, STENCIL, BLENDING on.off, etc)

View differences:

src/main/java/org/distorted/library/DistortedNode.java
44 44
  private MeshObject mMesh;
45 45
  private DistortedEffects mEffects;
46 46
  private DistortedInputSurface mSurface;
47
  private DistortedRenderState mState;
47 48
  private NodeData mData;
48 49

  
49 50
  private ArrayList<DistortedNode> mChildren;
......
227 228
    if( input.setAsInput() )
228 229
      {
229 230
      ret++;
231
      mState.apply();
230 232
      mEffects.drawPriv(halfX, halfY, mMesh, surface, currTime);
231 233
      }
232 234

  
......
248 250
    mSurface       = surface;
249 251
    mEffects       = effects;
250 252
    mMesh          = mesh;
253
    mState         = new DistortedRenderState();
251 254
    mChildren      = null;
252 255
    mNumChildren   = new int[1];
253 256
    mNumChildren[0]= 0;
......
284 287
    {
285 288
    mEffects= new DistortedEffects(node.mEffects,flags);
286 289
    mMesh   = node.mMesh;
290
    mState  = new DistortedRenderState();
287 291
    mParent = null;
288 292

  
289 293
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
......
521 525
    return mData.mFBO;
522 526
    }
523 527

  
528

  
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
/**
531
 * When rendering this Node, use ColorMask (r,g,b,a).
532
 *
533
 * @param r Write to the RED color channel when rendering this Node?
534
 * @param g Write to the GREEN color channel when rendering this Node?
535
 * @param b Write to the BLUE color channel when rendering this Node?
536
 * @param a Write to the ALPHA channel when rendering this Node?
537
 */
538
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
539
    {
540
    mState.glColorMask(r,g,b,a);
541
    }
542

  
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544
/**
545
 * When rendering this Node, switch on writing to Depth buffer?
546
 *
547
 * @param mask Write to the Depth buffer when rendering this Node?
548
 */
549
  public void glDepthMask(boolean mask)
550
    {
551
    mState.glDepthMask(mask);
552
    }
553

  
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556
 * When rendering this Node, which bits of the Stencil buffer to write to?
557
 *
558
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
559
 */
560
  public void glStencilMask(int mask)
561
    {
562
    mState.glStencilMask(mask);
563
    }
564

  
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566
/**
567
 * When rendering this Node, which Tests to enable?
568
 *
569
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
570
 */
571
  public void glEnable(int test)
572
    {
573
    mState.glEnable(test);
574
    }
575

  
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577
/**
578
 * When rendering this Node, which Tests to enable?
579
 *
580
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
581
 */
582
  public void glDisable(int test)
583
    {
584
    mState.glDisable(test);
585
    }
586

  
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
/**
589
 * When rendering this Node, use the following StencilFunc.
590
 *
591
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
592
 * @param ref  Reference valut to compare our stencil with.
593
 * @param mask Mask used when comparing.
594
 */
595
  public void glStencilFunc(int func, int ref, int mask)
596
    {
597
    mState.glStencilFunc(func,ref,mask);
598
    }
599

  
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * When rendering this Node, use the following StencilOp.
603
 * <p>
604
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
605
 *
606
 * @param sfail  What to do when Stencil Test fails.
607
 * @param dpfail What to do when Depth Test fails.
608
 * @param dppass What to do when Depth Test passes.
609
 */
610
  public void glStencilOp(int sfail, int dpfail, int dppass)
611
    {
612
    mState.glStencilOp(sfail,dpfail,dppass);
613
    }
614

  
615
///////////////////////////////////////////////////////////////////////////////////////////////////
616
/**
617
 * When rendering this Node, use the following DepthFunc.
618
 *
619
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
620
 */
621
  public void glDepthFunc(int func)
622
    {
623
    mState.glDepthFunc(func);
624
    }
625

  
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627
/**
628
 * When rendering this Node, use the following Blending mode.
629
 * <p>
630
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
631
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
632
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
633
 *
634
 * @param src Source Blend function
635
 * @param dst Destination Blend function
636
 */
637
  public void glBlendFunc(int src, int dst)
638
    {
639
    mState.glBlendFunc(src,dst);
640
    }
524 641
  }
src/main/java/org/distorted/library/DistortedOutputSurface.java
143 143
      DistortedSurface.debugLists();
144 144
      }
145 145
*/
146
    GLES30.glEnable(GLES30.GL_BLEND);
147
    GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE_MINUS_SRC_ALPHA);
146
    // mark OpenGL state as unknown
147
    DistortedRenderState.reset();
148 148

  
149 149
    int numRenders = 0;
150 150

  
......
163 163
  public void setAsOutput()
164 164
    {
165 165
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
166

  
167
    if( mDepthCreated==CREATED )
168
      {
169
      GLES30.glEnable(GLES30.GL_DEPTH_TEST);
170
      GLES30.glDepthMask(true);
171
      }
172
    else
173
      {
174
      GLES30.glDisable(GLES30.GL_DEPTH_TEST);
175
      GLES30.glDepthMask(false);
176
      }
177 166
    }
178 167

  
179 168
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedRenderState.java
35 35
  private static int sStencilFuncFunc, sStencilFuncRef, sStencilFuncMask;
36 36
  private static int sStencilOpSfail, sStencilOpDpfail, sStencilOpDppass;
37 37
  private static int sDepthFunc;
38
  private static int sBlend;
39
  private static int sBlendSrc, sBlendDst;
38 40

  
39 41
  private int mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA;
40 42
  private int mDepthMask;
......
44 46
  private int mStencilFuncFunc, mStencilFuncRef, mStencilFuncMask;
45 47
  private int mStencilOpSfail, mStencilOpDpfail, mStencilOpDppass;
46 48
  private int mDepthFunc;
49
  private int mBlend;
50
  private int mBlendSrc, mBlendDst;
47 51

  
48 52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
// default: color writes on, depth test and writes on, blending on, stencil off.
49 54

  
50 55
  DistortedRenderState()
51 56
    {
......
53 58
    mColorMaskG = 1;
54 59
    mColorMaskB = 1;
55 60
    mColorMaskA = 1;
56
    mDepthMask  = 1;
57
    mStencilMask= 0x11111111;
61

  
58 62
    mDepthTest  = 1;
59
    mStencilTest= 0;
63
    mDepthMask  = 1;
64
    mDepthFunc  = GLES30.GL_LEQUAL;
60 65

  
66
    mBlend      = 1;
67
    mBlendSrc   = GLES30.GL_SRC_ALPHA;
68
    mBlendDst   = GLES30.GL_ONE_MINUS_SRC_ALPHA;
69

  
70
    mStencilTest     = 0;
71
    mStencilMask     = 0x11111111;
61 72
    mStencilFuncFunc = GLES30.GL_NEVER;
62 73
    mStencilFuncRef  = 0;
63 74
    mStencilFuncMask = 0x11111111;
64 75
    mStencilOpSfail  = GLES30.GL_KEEP;
65 76
    mStencilOpDpfail = GLES30.GL_KEEP;
66 77
    mStencilOpDppass = GLES30.GL_KEEP;
67
    mDepthFunc       = GLES30.GL_LEQUAL;
68 78
    }
69 79

  
70 80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
// reset state of everything to 'unknown'
71 82

  
72 83
  static void reset()
73 84
    {
......
75 86
    sColorMaskG = -1;
76 87
    sColorMaskB = -1;
77 88
    sColorMaskA = -1;
78
    sDepthMask  = -1;
79
    sStencilMask= -1;
89

  
80 90
    sDepthTest  = -1;
81
    sStencilTest= -1;
91
    sDepthMask  = -1;
92
    sDepthFunc  = -1;
93

  
94
    sBlend      = -1;
95
    sBlendSrc   = -1;
96
    sBlendDst   = -1;
82 97

  
98
    sStencilTest     = -1;
99
    sStencilMask     = -1;
83 100
    sStencilFuncFunc = -1;
84 101
    sStencilFuncRef  = -1;
85 102
    sStencilFuncMask = -1;
86 103
    sStencilOpSfail  = -1;
87 104
    sStencilOpDpfail = -1;
88 105
    sStencilOpDppass = -1;
89
    sDepthFunc       = -1;
90 106
    }
91 107

  
92 108
///////////////////////////////////////////////////////////////////////////////////////////////////
......
124 140
        }
125 141
      }
126 142

  
143
    if( mBlend!=sBlend )
144
      {
145
      sBlend = mBlend;
146
      if( sBlend==0 ) GLES30.glDisable(GLES30.GL_BLEND);
147
      else
148
        {
149
        GLES30.glEnable(GLES30.GL_BLEND);
150

  
151
        if( mBlendSrc!=sBlendSrc || mBlendDst!=sBlendDst )
152
          {
153
          sBlendSrc = mBlendSrc;
154
          sBlendDst = mBlendDst;
155
          GLES30.glBlendFunc(sBlendSrc,sBlendDst);
156
          }
157
        }
158
      }
159

  
127 160
    if( mStencilTest!=sStencilTest )
128 161
      {
129 162
      sStencilTest = mStencilTest;
......
187 220
    {
188 221
         if( test==GLES30.GL_DEPTH_TEST   ) mDepthTest   = 1;
189 222
    else if( test==GLES30.GL_STENCIL_TEST ) mStencilTest = 1;
223
    else if( test==GLES30.GL_BLEND        ) mBlend       = 1;
190 224
    }
191 225

  
192 226
///////////////////////////////////////////////////////////////////////////////////////////////////
......
195 229
    {
196 230
         if( test==GLES30.GL_DEPTH_TEST   ) mDepthTest   = 0;
197 231
    else if( test==GLES30.GL_STENCIL_TEST ) mStencilTest = 0;
232
    else if( test==GLES30.GL_BLEND        ) mBlend       = 0;
198 233
    }
199 234

  
200 235
///////////////////////////////////////////////////////////////////////////////////////////////////
......
221 256
    {
222 257
    mDepthFunc = func;
223 258
    }
259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
  void glBlendFunc(int src, int dst)
263
    {
264
    mBlendSrc = src;
265
    mBlendDst = dst;
266
    }
267

  
224 268
}

Also available in: Unified diff