Project

General

Profile

« Previous | Next » 

Revision 2ab60f72

Added by Leszek Koltunski about 6 years ago

SSBO: something is working already, although we still get the 4 bytes back from the shader in reverse order ( so '17'=0x00000011 written by the shader becomes '285212672 = 0x11000000' )

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
162 162
    createProjection();
163 163
    }
164 164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
  void error(String msg)
168
    {
169
    int err = GLES31.glGetError();
170

  
171
    if( err != GLES31.GL_NO_ERROR )
172
      {
173
      android.util.Log.e("surface", msg+" error: "+err);
174
      }
175
    }
176

  
165 177
///////////////////////////////////////////////////////////////////////////////////////////////////
166 178
// Must be called from a thread holding OpenGL Context
167 179

  
......
173 185

  
174 186
      // here bind the new SSBO and map it
175 187
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
188
      error("pre1");
176 189
      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
177
      mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_WRITE_BIT | GLES31.GL_MAP_WRITE_BIT );
178
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,1, mSSBO[0]);
190
      error("pre2");
191
      mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT );
192
      error("pre3");
193
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]);
194
      error("pre4");
179 195
      }
180 196

  
181 197
    mSurfaceID = mSurfaceCounter.returnNext();
src/main/java/org/distorted/library/main/DistortedScreen.java
137 137
 */
138 138
  public DistortedScreen()
139 139
    {
140
    // set color to 'DONT_CREATE' so that Screens will not get added to the Surface lists
141
    // set depth to 'CREATED' so that depth will be, by default, on.
142
    super(0,0,DONT_CREATE,1,DEPTH_NO_STENCIL,0,TYPE_USER);
140
    // Screen also has to be created (3rd arg 'NOT_CREATED_YET') because of the SSBO inside OutputSurface.
141
    super(0,0,NOT_CREATED_YET,1,DEPTH_NO_STENCIL,0,TYPE_USER);
143 142

  
144 143
    mInitialized = false;
145 144
    }
src/main/res/raw/main_fragment_shader.glsl
43 43
                                        // next describes the Region, i.e. area over which the effect is active.
44 44
#endif    // NUM_FRAGMENT>0
45 45

  
46
layout (std140,binding=1) buffer SSBO   // PER-SURFACE count of transparent fragments.
46
layout (std140,binding=0) buffer SSBO   // PER-SURFACE count of transparent fragments.
47 47
  {                                     // Can be buffered, i.e. if we are for example
48
  int count[];                          // triple-buffered, then surfaceID=N uses 3
48
  int ssbocount[];                      // triple-buffered, then surfaceID=N uses 3
49 49
  };                                    // consecutive counts (N,N+1,N+2) during 3
50 50
                                        // consecutive frames.
51 51
uniform int u_currentIndex;             // Index into the count[] array we are supposed to be using
......
73 73
    }
74 74
#endif
75 75

  
76
  count[0]=17;
76
  ssbocount[0]=17;
77 77

  
78 78
  FRAG_COLOR = vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a);
79 79
  }

Also available in: Unified diff