Project

General

Profile

« Previous | Next » 

Revision 41a85bb7

Added by Leszek Koltunski over 6 years ago

Convert everythig to GLES31 (there were some GLES30 remnants)

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRendererPicker.java
26 26
import javax.microedition.khronos.egl.EGLConfig;
27 27
import javax.microedition.khronos.opengles.GL10;
28 28

  
29
import android.opengl.GLES30;
29
import android.opengl.GLES31;
30 30
import android.opengl.GLSurfaceView;
31 31
import android.opengl.Matrix;
32 32

  
......
105 105

  
106 106
	@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
107 107
	  {
108
		GLES30.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
108
		GLES31.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
109 109

  
110 110
		final float eyeX = 0.0f;
111 111
		final float eyeY = 0.0f;
......
142 142
		  + "  gl_FragColor = v_Color;    \n"
143 143
		  + "  }                          \n";
144 144

  
145
		int vertexShaderHandle = GLES30.glCreateShader(GLES30.GL_VERTEX_SHADER);
145
		int vertexShaderHandle = GLES31.glCreateShader(GLES31.GL_VERTEX_SHADER);
146 146

  
147 147
		if (vertexShaderHandle != 0)
148 148
		  {
149
			GLES30.glShaderSource(vertexShaderHandle, vertexShader);
150
      GLES30.glCompileShader(vertexShaderHandle);
149
			GLES31.glShaderSource(vertexShaderHandle, vertexShader);
150
      GLES31.glCompileShader(vertexShaderHandle);
151 151

  
152 152
      final int[] compileStatus = new int[1];
153
			GLES30.glGetShaderiv(vertexShaderHandle, GLES30.GL_COMPILE_STATUS, compileStatus, 0);
153
			GLES31.glGetShaderiv(vertexShaderHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);
154 154

  
155 155
			if (compileStatus[0] == 0)
156 156
  			{
157
				GLES30.glDeleteShader(vertexShaderHandle);
157
				GLES31.glDeleteShader(vertexShaderHandle);
158 158
				vertexShaderHandle = 0;
159 159
	  		}
160 160
		  }
......
164 164
			throw new RuntimeException("Error creating vertex shader.");
165 165
		  }
166 166

  
167
		int fragmentShaderHandle = GLES30.glCreateShader(GLES30.GL_FRAGMENT_SHADER);
167
		int fragmentShaderHandle = GLES31.glCreateShader(GLES31.GL_FRAGMENT_SHADER);
168 168

  
169 169
		if (fragmentShaderHandle != 0)
170 170
		  {
171
			GLES30.glShaderSource(fragmentShaderHandle, fragmentShader);
172
      GLES30.glCompileShader(fragmentShaderHandle);
171
			GLES31.glShaderSource(fragmentShaderHandle, fragmentShader);
172
      GLES31.glCompileShader(fragmentShaderHandle);
173 173

  
174 174
			final int[] compileStatus = new int[1];
175
			GLES30.glGetShaderiv(fragmentShaderHandle, GLES30.GL_COMPILE_STATUS, compileStatus, 0);
175
			GLES31.glGetShaderiv(fragmentShaderHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);
176 176

  
177 177
			if (compileStatus[0] == 0)
178 178
			  {
179
				GLES30.glDeleteShader(fragmentShaderHandle);
179
				GLES31.glDeleteShader(fragmentShaderHandle);
180 180
				fragmentShaderHandle = 0;
181 181
			  }
182 182
		  }
......
186 186
			throw new RuntimeException("Error creating fragment shader.");
187 187
		  }
188 188

  
189
		int programHandle = GLES30.glCreateProgram();
189
		int programHandle = GLES31.glCreateProgram();
190 190

  
191 191
		if (programHandle != 0)
192 192
		  {
193
			GLES30.glAttachShader(programHandle, vertexShaderHandle);
194
      GLES30.glAttachShader(programHandle, fragmentShaderHandle);
195
			GLES30.glBindAttribLocation(programHandle, 0, "a_Position");
196
			GLES30.glBindAttribLocation(programHandle, 1, "a_Color");
197
			GLES30.glLinkProgram(programHandle);
193
			GLES31.glAttachShader(programHandle, vertexShaderHandle);
194
      GLES31.glAttachShader(programHandle, fragmentShaderHandle);
195
			GLES31.glBindAttribLocation(programHandle, 0, "a_Position");
196
			GLES31.glBindAttribLocation(programHandle, 1, "a_Color");
197
			GLES31.glLinkProgram(programHandle);
198 198

  
199 199
			final int[] linkStatus = new int[1];
200
			GLES30.glGetProgramiv(programHandle, GLES30.GL_LINK_STATUS, linkStatus, 0);
200
			GLES31.glGetProgramiv(programHandle, GLES31.GL_LINK_STATUS, linkStatus, 0);
201 201

  
202 202
			if (linkStatus[0] == 0)
203 203
			  {
204
				GLES30.glDeleteProgram(programHandle);
204
				GLES31.glDeleteProgram(programHandle);
205 205
				programHandle = 0;
206 206
			  }
207 207
		  }
......
211 211
			throw new RuntimeException("Error creating program.");
212 212
		  }
213 213

  
214
    mMVPMatrixH = GLES30.glGetUniformLocation(programHandle, "u_MVPMatrix");
215
    mPositionH  = GLES30.glGetAttribLocation(programHandle, "a_Position");
216
    mColorH     = GLES30.glGetAttribLocation(programHandle, "a_Color");
214
    mMVPMatrixH = GLES31.glGetUniformLocation(programHandle, "u_MVPMatrix");
215
    mPositionH  = GLES31.glGetAttribLocation(programHandle, "a_Position");
216
    mColorH     = GLES31.glGetAttribLocation(programHandle, "a_Color");
217 217

  
218
    GLES30.glUseProgram(programHandle);
218
    GLES31.glUseProgram(programHandle);
219 219
	  }
220 220

  
221 221
///////////////////////////////////////////////////////////////////////////////////////////////////
......
225 225
	  mHeight = height;
226 226
	  mWidth  = width;
227 227

  
228
		GLES30.glViewport(0, 0, width, height);
228
		GLES31.glViewport(0, 0, width, height);
229 229

  
230 230
		final float ratio  = (float) width / height;
231 231
		final float left   =-ratio;
......
243 243

  
244 244
	@Override public void onDrawFrame(GL10 glUnused)
245 245
	  {
246
		GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
247
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPTriangleMatrix, 0);
246
		GLES31.glClear(GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_COLOR_BUFFER_BIT);
247
    GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPTriangleMatrix, 0);
248 248

  
249 249
    ///////// 'white-black-yellow' triangle //////
250 250
    mTriangleVert.position(POSITION_OFFSET);
251
    GLES30.glVertexAttribPointer(mPositionH, POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, STRIDE_BYTES, mTriangleVert);
252
    GLES30.glEnableVertexAttribArray(mPositionH);
251
    GLES31.glVertexAttribPointer(mPositionH, POSITION_DATA_SIZE, GLES31.GL_FLOAT, false, STRIDE_BYTES, mTriangleVert);
252
    GLES31.glEnableVertexAttribArray(mPositionH);
253 253
    mTriangleVert.position(COLOR_OFFSET);
254
    GLES30.glVertexAttribPointer(mColorH, COLOR_DATA_SIZE, GLES30.GL_FLOAT, false, STRIDE_BYTES, mTriangleVert);
255
    GLES30.glEnableVertexAttribArray(mColorH);
254
    GLES31.glVertexAttribPointer(mColorH, COLOR_DATA_SIZE, GLES31.GL_FLOAT, false, STRIDE_BYTES, mTriangleVert);
255
    GLES31.glEnableVertexAttribArray(mColorH);
256 256

  
257
		GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPTriangleMatrix, 0);
258
		GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3);
257
		GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPTriangleMatrix, 0);
258
		GLES31.glDrawArrays(GLES31.GL_TRIANGLES, 0, 3);
259 259

  
260 260
    //////// 'current position' square ///////////
261 261
    mSquareVert.position(POSITION_OFFSET);
262
    GLES30.glVertexAttribPointer(mPositionH, POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, STRIDE_BYTES, mSquareVert);
263
    GLES30.glEnableVertexAttribArray(mPositionH);
262
    GLES31.glVertexAttribPointer(mPositionH, POSITION_DATA_SIZE, GLES31.GL_FLOAT, false, STRIDE_BYTES, mSquareVert);
263
    GLES31.glEnableVertexAttribArray(mPositionH);
264 264
    mSquareVert.position(COLOR_OFFSET);
265
    GLES30.glVertexAttribPointer(mColorH, COLOR_DATA_SIZE, GLES30.GL_FLOAT, false, STRIDE_BYTES, mSquareVert);
266
    GLES30.glEnableVertexAttribArray(mColorH);
265
    GLES31.glVertexAttribPointer(mColorH, COLOR_DATA_SIZE, GLES31.GL_FLOAT, false, STRIDE_BYTES, mSquareVert);
266
    GLES31.glEnableVertexAttribArray(mColorH);
267 267

  
268 268
    Matrix.multiplyMM(mMVPSquareMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
269 269
    Matrix.multiplyMM(mMVPSquareMatrix, 0, mProjectionMatrix, 0, mMVPSquareMatrix, 0);
270 270

  
271
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPSquareMatrix, 0);
272
		GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0,4);
271
    GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPSquareMatrix, 0);
272
		GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0,4);
273 273
	  }
274 274
  }
src/main/java/org/distorted/examples/bitmaptree/BitmapTreeRenderer.java
47 47

  
48 48
import android.graphics.Bitmap;
49 49
import android.graphics.BitmapFactory;
50
import android.opengl.GLES30;
50
import android.opengl.GLES31;
51 51
import android.opengl.GLSurfaceView;
52 52

  
53 53
///////////////////////////////////////////////////////////////////////////////////////////////////
......
89 89

  
90 90
   private void setDepthPriv()
91 91
     {
92
     if( mDepth ) mRoot.glEnable (GLES30.GL_DEPTH_TEST);
93
     else         mRoot.glDisable(GLES30.GL_DEPTH_TEST);
92
     if( mDepth ) mRoot.glEnable (GLES31.GL_DEPTH_TEST);
93
     else         mRoot.glDisable(GLES31.GL_DEPTH_TEST);
94 94

  
95 95
     mRoot.glDepthMask(mDepth);
96 96

  
......
145 145
      // TODO
146 146
      // This appears to be needed in case we create the app anew with NO DEPTH
147 147
      // (i.e. we set 'no depth' and then rotate screen). Investigate.
148
      GLES30.glEnable(GLES30.GL_CULL_FACE);
149
      GLES30.glCullFace(GLES30.GL_BACK);
150
      GLES30.glFrontFace(GLES30.GL_CW);
148
      GLES31.glEnable(GLES31.GL_CULL_FACE);
149
      GLES31.glCullFace(GLES31.GL_BACK);
150
      GLES31.glFrontFace(GLES31.GL_CW);
151 151

  
152 152
      InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.monalisa);
153 153
      InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.grid);
src/main/java/org/distorted/examples/check/CheckRenderer.java
49 49
import android.content.DialogInterface;
50 50
import android.graphics.Bitmap;
51 51
import android.graphics.BitmapFactory;
52
import android.opengl.GLES30;
52
import android.opengl.GLES31;
53 53
import android.opengl.GLSurfaceView;
54 54
import android.util.Log;
55 55

  
......
214 214
      
215 215
        String ver;
216 216
      
217
        ver = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);   
217
        ver = GLES31.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION);
218 218
        compilationResult += "\n\nGLSL version: "+(ver==null ? "null" : ver);
219
        ver = GLES30.glGetString(GLES30.GL_VERSION);  
219
        ver = GLES31.glGetString(GLES31.GL_VERSION);
220 220
        compilationResult += "\nGL version: "+(ver==null ? "null" : ver);
221
        ver = GLES30.glGetString(GLES30.GL_VENDOR);   
221
        ver = GLES31.glGetString(GLES31.GL_VENDOR);
222 222
        compilationResult += "\nGL vendor: "+(ver==null ? "null" : ver);
223
        ver = GLES30.glGetString(GLES30.GL_RENDERER);    
223
        ver = GLES31.glGetString(GLES31.GL_RENDERER);
224 224
        compilationResult += "\nGL renderer: "+(ver==null ? "null" : ver);
225 225
      
226 226
        CheckActivity act = (CheckActivity)mView.getContext();
src/main/java/org/distorted/examples/plainmonalisa/RenderThread.java
23 23
import android.graphics.BitmapFactory;
24 24
import android.opengl.EGL14;
25 25
import android.opengl.EGLSurface;
26
import android.opengl.GLES30;
26
import android.opengl.GLES31;
27 27
import android.os.Looper;
28 28
import android.util.Log;
29 29
import android.view.Surface;
30 30
import android.view.SurfaceHolder;
31 31
import android.view.SurfaceView;
32 32

  
33
import org.distorted.library.effect.EffectName;
34 33
import org.distorted.library.effect.MatrixEffectMove;
35 34
import org.distorted.library.effect.MatrixEffectScale;
36 35
import org.distorted.library.effect.VertexEffectDistort;
......
119 118

  
120 119
  private static void checkGlError(String op)
121 120
    {
122
    int error = GLES30.glGetError();
121
    int error = GLES31.glGetError();
123 122

  
124
    if (error != GLES30.GL_NO_ERROR)
123
    if (error != GLES31.GL_NO_ERROR)
125 124
      {
126 125
      String msg = op + ": glError 0x" + Integer.toHexString(error);
127 126
      Log.e(TAG, msg);
src/main/java/org/distorted/examples/save/SaveRenderer.java
30 30

  
31 31
import org.distorted.examples.R;
32 32

  
33
import org.distorted.library.effect.EffectName;
34 33
import org.distorted.library.effect.MatrixEffectMove;
35 34
import org.distorted.library.effect.MatrixEffectScale;
36 35
import org.distorted.library.effect.VertexEffectSink;
......
47 46

  
48 47
import android.graphics.Bitmap;
49 48
import android.graphics.BitmapFactory;
50
import android.opengl.GLES30;
49
import android.opengl.GLES31;
51 50
import android.opengl.GLSurfaceView;
52 51
import android.os.Environment;
53 52

  
......
170 169

  
171 170
      if( textureID>=0 )
172 171
        {
173
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureID);
174
        GLES30.glReadPixels( 0, 0, fW, fH, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, buf);
172
        GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, textureID);
173
        GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf);
175 174
        SaveWorkerThread.newBuffer(buf,fW,fH,mPath);
176 175
        }
177 176
      else
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java
28 28

  
29 29
import org.distorted.examples.R;
30 30

  
31
import org.distorted.library.effect.EffectName;
32 31
import org.distorted.library.effect.FragmentEffectAlpha;
33 32
import org.distorted.library.effect.MatrixEffectMove;
34 33
import org.distorted.library.effect.MatrixEffectRotate;
......
52 51
import android.graphics.Canvas;
53 52
import android.graphics.Paint;
54 53
import android.graphics.Typeface;
55
import android.opengl.GLES30;
54
import android.opengl.GLES31;
56 55
import android.opengl.GLSurfaceView;
57 56

  
58 57
///////////////////////////////////////////////////////////////////////////////////////////////////
......
432 431
        
433 432
        mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
434 433
        mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
435
        mBackground.glDisable(GLES30.GL_DEPTH_TEST);
434
        mBackground.glDisable(GLES31.GL_DEPTH_TEST);
436 435
        mBackground.glDepthMask(false);
437 436
        mCrawlEffects.registerForMessages(this);
438 437
        }
src/main/java/org/distorted/examples/stencil/StencilRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES30;
24
import android.opengl.GLES31;
25 25
import android.opengl.GLSurfaceView;
26 26

  
27 27
import org.distorted.examples.R;
......
118 118
      // Nothing - i.e. use default OpenGL settings (one difference - in Distorted, Depth Test is on by default).
119 119
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120 120
      // Stuff to do just before we render the Floor
121
      mFloorNode.glEnable(GLES30.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
122
      mFloorNode.glStencilFunc(GLES30.GL_ALWAYS, 1, 0xFF);                       // Set any stencil to 1
123
      mFloorNode.glStencilOp(GLES30.GL_KEEP, GLES30.GL_KEEP, GLES30.GL_REPLACE); // replace with 1 when we fail Depth test
121
      mFloorNode.glEnable(GLES31.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
122
      mFloorNode.glStencilFunc(GLES31.GL_ALWAYS, 1, 0xFF);                       // Set any stencil to 1
123
      mFloorNode.glStencilOp(GLES31.GL_KEEP, GLES31.GL_KEEP, GLES31.GL_REPLACE); // replace with 1 when we fail Depth test
124 124
      mFloorNode.glStencilMask(0xFF);                                            // Write to stencil buffer
125 125
      mFloorNode.glDepthMask(false);                                             // Don't write to depth buffer
126
      mFloorNode.glClear(GLES30.GL_STENCIL_BUFFER_BIT);                          // Clear stencil buffer (by default, with a 0)
126
      mFloorNode.glClear(GLES31.GL_STENCIL_BUFFER_BIT);                          // Clear stencil buffer (by default, with a 0)
127 127

  
128 128
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
129 129
      // Stuff to do just before we render the lower Cube
130
      mCube2Node.glEnable(GLES30.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
130
      mCube2Node.glEnable(GLES31.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
131 131
                                                                                 // no, this is not retained; we have to set
132 132
                                                                                 // this again even though Floor just set it
133
      mCube2Node.glStencilFunc(GLES30.GL_EQUAL, 1, 0xFF);                        // Pass test if stencil value is 1
133
      mCube2Node.glStencilFunc(GLES31.GL_EQUAL, 1, 0xFF);                        // Pass test if stencil value is 1
134 134
      mCube2Node.glStencilMask(0x00);                                            // Don't write anything to stencil buffer
135 135
      mCube2Node.glDepthMask(true);                                              // Write to depth buffer
136 136
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff