Project

General

Profile

« Previous | Next » 

Revision 194ab46f

Added by Leszek Koltunski almost 8 years ago

Try using OpenGL ES 3.0 everywhere (but if device does not support it, try creating 2.0 context - this is important because of the emulator!)

View differences:

src/main/java/org/distorted/library/Distorted.java
21 21

  
22 22
import android.content.Context;
23 23
import android.content.res.Resources;
24
import android.opengl.GLES20;
24
import android.opengl.GLES30;
25 25
import org.distorted.library.program.*;
26 26

  
27 27
import java.io.InputStream;
......
113 113
    {
114 114
    final Resources resources = context.getResources();
115 115

  
116
    GLES20.glDepthFunc(GLES20.GL_LEQUAL);
117
    GLES20.glEnable(GLES20.GL_BLEND);
118
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
119
    GLES20.glEnable(GLES20.GL_CULL_FACE);
120
    GLES20.glCullFace(GLES20.GL_BACK);
121
    GLES20.glFrontFace(GLES20.GL_CW);
116
    GLES30.glDepthFunc(GLES30.GL_LEQUAL);
117
    GLES30.glEnable(GLES30.GL_BLEND);
118
    GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE_MINUS_SRC_ALPHA);
119
    GLES30.glEnable(GLES30.GL_CULL_FACE);
120
    GLES30.glCullFace(GLES30.GL_BACK);
121
    GLES30.glFrontFace(GLES30.GL_CW);
122 122

  
123 123
    DistortedEffects.createProgram(resources);
124 124
    EffectQueuePostprocess.createProgram(resources);
src/main/java/org/distorted/library/DistortedEffects.java
20 20
package org.distorted.library;
21 21

  
22 22
import android.content.res.Resources;
23
import android.opengl.GLES20;
23
import android.opengl.GLES30;
24 24
import android.opengl.Matrix;
25 25

  
26 26
import org.distorted.library.message.EffectListener;
......
125 125
    mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
126 126

  
127 127
    int debugProgramH = mDebugProgram.getProgramHandle();
128
    mObjDH      = GLES20.glGetUniformLocation( debugProgramH, "u_objD");
129
    mMVPMatrixH = GLES20.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
128
    mObjDH      = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
129
    mMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
130 130
    // END DEBUG  //////////////////////////////////////
131 131
    }
132 132

  
......
225 225
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
226 226
    Matrix.multiplyMM  ( mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
227 227

  
228
    GLES20.glUniform2f( mObjDH , 2*halfX, 2*halfY);
229
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
228
    GLES30.glUniform2f( mObjDH , 2*halfX, 2*halfY);
229
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
230 230

  
231
    GLES20.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES20.GL_FLOAT, false, 0, mQuadPositions);
232
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
231
    GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
232
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
233 233
    }
234 234

  
235 235
///////////////////////////////////////////////////////////////////////////////////////////////////
......
242 242
    mP.compute(currTime);
243 243

  
244 244
    float halfZ = halfInputW*mesh.zFactor;
245
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
245
    GLES30.glViewport(0, 0, df.mWidth, df.mHeight);
246 246

  
247 247
    if( mP.mNumEffects==0 )
248 248
      {
......
251 251
      mM.send(df,halfInputW,halfInputH,halfZ);
252 252
      mV.send(halfInputW,halfInputH,halfZ);
253 253
      mF.send(halfInputW,halfInputH);
254
      GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
255
      GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
256
      GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
257
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
254
      GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
255
      GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
256
      GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
257
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
258 258
      }
259 259
    else
260 260
      {
......
268 268
        mProgram.useProgram();
269 269
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
270 270
        mBufferFBO.setAsOutput();
271
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
272
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
271
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
272
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
273 273
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
274 274
        mV.send(halfInputW,halfInputH,halfZ);
275 275
        mF.send(halfInputW,halfInputH);
276
        GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
277
        GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
278
        GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
279
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
276
        GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
277
        GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
278
        GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
279
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
280 280

  
281 281
        Matrix.setIdentityM(mTmpMatrix, 0);
282 282
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
......
296 296
   
297 297
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
298 298
    {
299
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
299
    GLES30.glViewport(0, 0, df.mWidth, df.mHeight);
300 300

  
301 301
    Matrix.setIdentityM(mTmpMatrix, 0);
302 302
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
......
307 307
    EffectQueueFragment.sendZero();
308 308
    EffectQueuePostprocess.sendZero(df.mWidth, df.mHeight, mMVPMatrix);
309 309

  
310
    GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
311
    GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
312
    GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
313
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
310
    GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
311
    GLES30.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
312
    GLES30.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
313
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
314 314
    }
315 315
    
316 316
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedFramebuffer.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import android.opengl.GLES20;
22
import android.opengl.GLES30;
23 23
import android.opengl.Matrix;
24 24

  
25 25
import java.util.Iterator;
......
70 70
    {
71 71
    if( colorIds[0]==NOT_CREATED_YET )
72 72
      {
73
      GLES20.glGenTextures(1, colorIds, 0);
74
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, colorIds[0]);
75
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
76
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
77
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
78
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
79
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mTexWidth, mTexHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
80

  
81
      GLES20.glGenFramebuffers(1, fboIds, 0);
82
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
83
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, colorIds[0], 0);
73
      GLES30.glGenTextures(1, colorIds, 0);
74
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
75
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
76
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
77
      GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
78
      GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
79
      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mTexWidth, mTexHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null);
80

  
81
      GLES30.glGenFramebuffers(1, fboIds, 0);
82
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
83
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, colorIds[0], 0);
84 84

  
85 85
      checkStatus("color");
86 86
      }
87 87
    if( mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
88 88
      {
89
      GLES20.glGenTextures(1, depthIds, 0);
90
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, depthIds[0]);
91
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
92
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
93
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
94
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
95
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT, null);
89
      GLES30.glGenTextures(1, depthIds, 0);
90
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, depthIds[0]);
91
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
92
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);
93
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
94
      GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
95
      GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_UNSIGNED_SHORT, null);
96 96

  
97
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
98
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D, depthIds[0], 0);
97
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
98
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, depthIds[0], 0);
99 99

  
100 100
      checkStatus("depth");
101 101
      }
102 102
    if( !mDepthWanted && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
103 103
      {
104
      GLES20.glDeleteTextures(1, depthIds, 0);
104
      GLES30.glDeleteTextures(1, depthIds, 0);
105 105
      depthIds[0]=NOT_CREATED_YET;
106 106
      }
107 107
    }
......
110 110

  
111 111
  private boolean checkStatus(String message)
112 112
    {
113
    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
113
    int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
114 114

  
115
    if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
115
    if(status != GLES30.GL_FRAMEBUFFER_COMPLETE)
116 116
      {
117 117
      android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status);
118 118

  
119
      GLES20.glDeleteTextures(1, colorIds, 0);
120
      GLES20.glDeleteTextures(1, depthIds, 0);
121
      GLES20.glDeleteFramebuffers(1, fboIds, 0);
119
      GLES30.glDeleteTextures(1, colorIds, 0);
120
      GLES30.glDeleteTextures(1, depthIds, 0);
121
      GLES30.glDeleteFramebuffers(1, fboIds, 0);
122 122
      fboIds[0]   = 0;
123 123
      colorIds[0] = FAILED_TO_CREATE;
124 124
      depthIds[0] = FAILED_TO_CREATE;
......
140 140

  
141 141
      if( depthIds[0]>=0 )
142 142
        {
143
        GLES20.glDeleteTextures(1, depthIds, 0);
143
        GLES30.glDeleteTextures(1, depthIds, 0);
144 144
        depthIds[0]=NOT_CREATED_YET;
145 145
        }
146 146

  
147
      GLES20.glDeleteTextures(1, colorIds, 0);
147
      GLES30.glDeleteTextures(1, colorIds, 0);
148 148
      colorIds[0] = NOT_CREATED_YET;
149 149

  
150
      GLES20.glDeleteFramebuffers(1, fboIds, 0);
150
      GLES30.glDeleteFramebuffers(1, fboIds, 0);
151 151
      fboIds[0] = 0;
152 152
      }
153 153

  
......
158 158

  
159 159
  void setAsOutput()
160 160
    {
161
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
161
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fboIds[0]);
162 162

  
163 163
    if( depthIds[0]!=NOT_CREATED_YET )
164 164
      {
165
      GLES20.glEnable(GLES20.GL_DEPTH_TEST);
166
      GLES20.glDepthMask(true);
165
      GLES30.glEnable(GLES30.GL_DEPTH_TEST);
166
      GLES30.glDepthMask(true);
167 167
      }
168 168
    else
169 169
      {
170
      GLES20.glDisable(GLES20.GL_DEPTH_TEST);
171
      GLES20.glDepthMask(false);
170
      GLES30.glDisable(GLES30.GL_DEPTH_TEST);
171
      GLES30.glDepthMask(false);
172 172
      }
173 173
    }
174 174

  
......
176 176

  
177 177
  void setAsInput()
178 178
    {
179
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, colorIds[0]);
179
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, colorIds[0]);
180 180
    }
181 181

  
182 182
///////////////////////////////////////////////////////////////////////////////////////////////////
......
388 388
      DistortedFramebuffer.deleteAllMarked();
389 389
      DistortedTexture.deleteAllMarked();
390 390
      createFBO();
391
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fbo.colorIds[0]);
391
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, fbo.colorIds[0]);
392 392
      effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, mesh, this, time);
393 393
      }
394 394
    }
src/main/java/org/distorted/library/DistortedTexture.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.Matrix;
24
import android.opengl.GLES20;
24
import android.opengl.GLES30;
25 25
import android.opengl.GLUtils;
26 26

  
27 27
import java.util.Iterator;
......
84 84

  
85 85
      if( mTextureDataH[0]==0 )
86 86
        {
87
        GLES20.glGenTextures(1, mTextureDataH, 0);
88
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
89
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
90
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
91
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
92
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
93
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
87
        GLES30.glGenTextures(1, mTextureDataH, 0);
88
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
89
        GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR );
90
        GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR );
91
        GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE );
92
        GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE );
93
        GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
94 94
        }
95 95
      else
96 96
        {
97
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
98
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0,0,0,flipBitmap(mBmp));
97
        GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
98
        GLUtils.texSubImage2D(GLES30.GL_TEXTURE_2D, 0,0,0,flipBitmap(mBmp));
99 99
        }
100 100

  
101 101
      mBmp = null;
......
111 111
      {
112 112
      //android.util.Log.e("Texture", "deleting "+mID);
113 113

  
114
      GLES20.glDeleteTextures(1, mTextureDataH, 0);
114
      GLES30.glDeleteTextures(1, mTextureDataH, 0);
115 115

  
116 116
      mTextureDataH[0] = 0;
117 117
      mBitmapSet= false;
......
133 133
    {
134 134
    if( mBitmapSet )
135 135
      {
136
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
136
      GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mTextureDataH[0]);
137 137
      return true;
138 138
      }
139 139

  
......
144 144

  
145 145
  static void getUniforms(int mProgramH)
146 146
    {
147
    mTextureH= GLES20.glGetUniformLocation( mProgramH, "u_Texture");
147
    mTextureH= GLES30.glGetUniformLocation( mProgramH, "u_Texture");
148 148

  
149
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
150
    GLES20.glUniform1i(mTextureH, 0);
149
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
150
    GLES30.glUniform1i(mTextureH, 0);
151 151
    }
152 152

  
153 153
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedTree.java
22 22
import java.util.ArrayList;
23 23
import java.util.HashMap;
24 24

  
25
import android.opengl.GLES20;
25
import android.opengl.GLES30;
26 26

  
27 27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 28
/**
......
214 214
        {
215 215
        mData.mFBO.setAsOutput();
216 216

  
217
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
218
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
217
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
218
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
219 219

  
220 220
        if( mTexture.setAsInput() )
221 221
          DistortedEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mMesh, mData.mFBO);
src/main/java/org/distorted/library/EffectQueueFragment.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import android.opengl.GLES20;
22
import android.opengl.GLES30;
23 23

  
24 24
import org.distorted.library.message.EffectMessage;
25 25
import org.distorted.library.type.Data1D;
......
54 54

  
55 55
  static void getUniforms(int mProgramH)
56 56
    {
57
    mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "fNumEffects");
58
    mTypeH      = GLES20.glGetUniformLocation( mProgramH, "fType");
59
    mUniformsH  = GLES20.glGetUniformLocation( mProgramH, "fUniforms");
57
    mNumEffectsH= GLES30.glGetUniformLocation( mProgramH, "fNumEffects");
58
    mTypeH      = GLES30.glGetUniformLocation( mProgramH, "fType");
59
    mUniformsH  = GLES30.glGetUniformLocation( mProgramH, "fUniforms");
60 60
    }
61 61

  
62 62
///////////////////////////////////////////////////////////////////////////////////////////////////
......
115 115
  
116 116
  synchronized void send(float halfX, float halfY)
117 117
    {
118
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
118
    GLES30.glUniform1i( mNumEffectsH, mNumEffects);
119 119

  
120 120
    if( mNumEffects>0 )
121 121
      {
......
127 127
        mUniforms[NUM_UNIFORMS*i+7] = mCache[NUM_CACHE*i+3];
128 128
        }
129 129

  
130
      GLES20.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
131
      GLES20.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
130
      GLES30.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
131
      GLES30.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
132 132
      }  
133 133
    }
134 134

  
......
136 136

  
137 137
  synchronized static void sendZero()
138 138
    {
139
    GLES20.glUniform1i( mNumEffectsH, 0);
139
    GLES30.glUniform1i( mNumEffectsH, 0);
140 140
    }
141 141

  
142 142
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueueMatrix.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import android.opengl.GLES20;
22
import android.opengl.GLES30;
23 23
import android.opengl.Matrix;
24 24

  
25 25
import org.distorted.library.message.EffectMessage;
......
191 191

  
192 192
  static void getUniforms(int mProgramH)
193 193
    {
194
    mObjDH     = GLES20.glGetUniformLocation(mProgramH, "u_objD");
195
    mDepthH    = GLES20.glGetUniformLocation(mProgramH, "u_Depth");
196
    mMVPMatrixH= GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
197
    mMVMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVMatrix"); 
194
    mObjDH     = GLES30.glGetUniformLocation(mProgramH, "u_objD");
195
    mDepthH    = GLES30.glGetUniformLocation(mProgramH, "u_Depth");
196
    mMVPMatrixH= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
197
    mMVMatrixH = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix"); 
198 198
    }
199 199

  
200 200
///////////////////////////////////////////////////////////////////////////////////////////////////
......
288 288
    {
289 289
    constructMatrices(df,halfX,halfY);
290 290

  
291
    GLES20.glUniform3f( mObjDH , halfX, halfY, halfZ);
292
    GLES20.glUniform1f( mDepthH, df.mDepth);
293
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0);
294
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
291
    GLES30.glUniform3f( mObjDH , halfX, halfY, halfZ);
292
    GLES30.glUniform1f( mDepthH, df.mDepth);
293
    GLES30.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0);
294
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
295 295
    }
296 296

  
297 297
///////////////////////////////////////////////////////////////////////////////////////////////////
......
303 303
    Matrix.translateM(mTmpMatrix, 0, halfX-df.mWidth/2, df.mHeight/2-halfY, -df.mDistance);
304 304
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
305 305
    
306
    GLES20.glUniform3f( mObjDH , halfX, halfY, halfZ);
307
    GLES20.glUniform1f( mDepthH, df.mDepth);
308
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0);
309
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
306
    GLES30.glUniform3f( mObjDH , halfX, halfY, halfZ);
307
    GLES30.glUniform1f( mDepthH, df.mDepth);
308
    GLES30.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0);
309
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
310 310
    }
311 311

  
312 312
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueuePostprocess.java
20 20
package org.distorted.library;
21 21

  
22 22
import android.content.res.Resources;
23
import android.opengl.GLES20;
23
import android.opengl.GLES30;
24 24

  
25 25
import org.distorted.library.message.EffectMessage;
26 26
import org.distorted.library.program.DistortedProgram;
......
105 105

  
106 106
  private static void getUniforms(int mProgramH)
107 107
    {
108
    mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "pNumEffects");
109
    mTypeH      = GLES20.glGetUniformLocation( mProgramH, "pType");
110
    mUniformsH  = GLES20.glGetUniformLocation( mProgramH, "pUniforms");
111
    mObjDH      = GLES20.glGetUniformLocation( mProgramH, "u_objD");
112
    mMVPMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
108
    mNumEffectsH= GLES30.glGetUniformLocation( mProgramH, "pNumEffects");
109
    mTypeH      = GLES30.glGetUniformLocation( mProgramH, "pType");
110
    mUniformsH  = GLES30.glGetUniformLocation( mProgramH, "pUniforms");
111
    mObjDH      = GLES30.glGetUniformLocation( mProgramH, "u_objD");
112
    mMVPMatrixH = GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
113 113
    }
114 114

  
115 115
///////////////////////////////////////////////////////////////////////////////////////////////////
......
160 160

  
161 161
  synchronized static void sendZero(float w, float h, float[] mvp)
162 162
    {
163
    GLES20.glUniform1i( mNumEffectsH, 0);
164
    GLES20.glUniform2f( mObjDH , w, h);
165
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
163
    GLES30.glUniform1i( mNumEffectsH, 0);
164
    GLES30.glUniform2f( mObjDH , w, h);
165
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
166 166
    }
167 167

  
168 168
///////////////////////////////////////////////////////////////////////////////////////////////////
......
174 174
    mProgram.useProgram();
175 175
    df.setAsOutput();
176 176

  
177
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
178
    GLES20.glUniform2f( mObjDH , w, h );
179
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
177
    GLES30.glUniform1i( mNumEffectsH, mNumEffects);
178
    GLES30.glUniform2f( mObjDH , w, h );
179
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
180 180

  
181 181
    if( mNumEffects>0 )
182 182
      {
183
      GLES20.glUniform1iv( mTypeH    ,                  mNumEffects, mName    ,0);
184
      GLES20.glUniform4fv( mUniformsH, (NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
183
      GLES30.glUniform1iv( mTypeH    ,                  mNumEffects, mName    ,0);
184
      GLES30.glUniform4fv( mUniformsH, (NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
185 185
      }
186 186

  
187
    GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
188
    GLES20.glVertexAttribPointer(mProgram.mAttribute[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
189
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
187
    GLES30.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
188
    GLES30.glVertexAttribPointer(mProgram.mAttribute[1], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mQuadTexture);
189
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
190 190
    }
191 191

  
192 192
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueueVertex.java
19 19

  
20 20
package org.distorted.library;
21 21

  
22
import android.opengl.GLES20;
22
import android.opengl.GLES30;
23 23

  
24 24
import org.distorted.library.message.EffectMessage;
25 25
import org.distorted.library.type.Data1D;
......
60 60

  
61 61
  static void getUniforms(int mProgramH)
62 62
    {
63
    mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "vNumEffects");
64
    mTypeH      = GLES20.glGetUniformLocation( mProgramH, "vType");
65
    mUniformsH  = GLES20.glGetUniformLocation( mProgramH, "vUniforms");
63
    mNumEffectsH= GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
64
    mTypeH      = GLES30.glGetUniformLocation( mProgramH, "vType");
65
    mUniformsH  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
66 66
    }
67 67

  
68 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
135 135

  
136 136
  synchronized void send(float halfX, float halfY, float halfZ)
137 137
    {
138
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
138
    GLES30.glUniform1i( mNumEffectsH, mNumEffects);
139 139
      
140 140
    if( mNumEffects>0 )
141 141
      {
......
146 146
        mUniforms[NUM_UNIFORMS*i+7] = mCache[NUM_CACHE*i+2]-halfZ;
147 147
        }
148 148

  
149
      GLES20.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
150
      GLES20.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
149
      GLES30.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
150
      GLES30.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
151 151
      }
152 152
    }
153 153

  
......
155 155

  
156 156
  synchronized static void sendZero()
157 157
    {
158
    GLES20.glUniform1i( mNumEffectsH, 0);
158
    GLES30.glUniform1i( mNumEffectsH, 0);
159 159
    }
160 160
  
161 161
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/program/DistortedProgram.java
19 19

  
20 20
package org.distorted.library.program;
21 21

  
22
import android.opengl.GLES20;
22
import android.opengl.GLES30;
23 23
import android.os.Build;
24 24

  
25 25
import org.distorted.library.DistortedEffects;
......
47 47
  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
48 48
  throws LinkingException
49 49
    {
50
    int programHandle = GLES20.glCreateProgram();
50
    int programHandle = GLES30.glCreateProgram();
51 51

  
52 52
    if (programHandle != 0)
53 53
      {
54
      GLES20.glAttachShader(programHandle, vertexShaderHandle);
55
      GLES20.glAttachShader(programHandle, fragmentShaderHandle);
54
      GLES30.glAttachShader(programHandle, vertexShaderHandle);
55
      GLES30.glAttachShader(programHandle, fragmentShaderHandle);
56 56

  
57 57
      if (attributes != null)
58 58
        {
......
60 60

  
61 61
        for (int i = 0; i < size; i++)
62 62
          {
63
          GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
63
          GLES30.glBindAttribLocation(programHandle, i, attributes[i]);
64 64
          }
65 65
        }
66 66

  
67
      GLES20.glLinkProgram(programHandle);
67
      GLES30.glLinkProgram(programHandle);
68 68

  
69 69
      final int[] linkStatus = new int[1];
70
      GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);
70
      GLES30.glGetProgramiv(programHandle, GLES30.GL_LINK_STATUS, linkStatus, 0);
71 71

  
72
      if (linkStatus[0] != GLES20.GL_TRUE )
72
      if (linkStatus[0] != GLES30.GL_TRUE )
73 73
        {
74
        String error = GLES20.glGetProgramInfoLog(programHandle);
75
        GLES20.glDeleteProgram(programHandle);
74
        String error = GLES30.glGetProgramInfoLog(programHandle);
75
        GLES30.glDeleteProgram(programHandle);
76 76
        throw new LinkingException(error);
77 77
        }
78 78

  
79 79
      final int[] numberOfUniforms = new int[1];
80
      GLES20.glGetProgramiv(programHandle, GLES20.GL_ACTIVE_UNIFORMS, numberOfUniforms, 0);
80
      GLES30.glGetProgramiv(programHandle, GLES30.GL_ACTIVE_UNIFORMS, numberOfUniforms, 0);
81 81

  
82 82
      //android.util.Log.d("program", "number of active uniforms="+numberOfUniforms[0]);
83 83
      }
......
181 181
    int maxV,maxF;
182 182
    int[] param = new int[1];
183 183

  
184
    GLES20.glGetIntegerv(GLES20.GL_MAX_VERTEX_UNIFORM_VECTORS, param, 0);
184
    GLES30.glGetIntegerv(GLES30.GL_MAX_VERTEX_UNIFORM_VECTORS, param, 0);
185 185
    maxV = param[0];
186
    GLES20.glGetIntegerv(GLES20.GL_MAX_FRAGMENT_UNIFORM_VECTORS, param, 0);
186
    GLES30.glGetIntegerv(GLES30.GL_MAX_FRAGMENT_UNIFORM_VECTORS, param, 0);
187 187
    maxF = param[0];
188 188

  
189 189
    //Log.d("program", "Max vectors in vertex shader: "+maxV);
......
210 210
  private static int compileShader(final int shaderType, final String shaderSource)
211 211
  throws FragmentCompilationException,VertexCompilationException
212 212
    {
213
    int shaderHandle = GLES20.glCreateShader(shaderType);
213
    int shaderHandle = GLES30.glCreateShader(shaderType);
214 214

  
215 215
    if (shaderHandle != 0)
216 216
      {
217
      GLES20.glShaderSource(shaderHandle, shaderSource);
218
      GLES20.glCompileShader(shaderHandle);
217
      GLES30.glShaderSource(shaderHandle, shaderSource);
218
      GLES30.glCompileShader(shaderHandle);
219 219
      final int[] compileStatus = new int[1];
220
      GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
220
      GLES30.glGetShaderiv(shaderHandle, GLES30.GL_COMPILE_STATUS, compileStatus, 0);
221 221

  
222
      if (compileStatus[0] != GLES20.GL_TRUE )
222
      if (compileStatus[0] != GLES30.GL_TRUE )
223 223
        {
224
        GLES20.glDeleteShader(shaderHandle);
224
        GLES30.glDeleteShader(shaderHandle);
225 225
        shaderHandle = 0;
226 226
        }
227 227
      }
228 228

  
229 229
    if (shaderHandle == 0)
230 230
      {
231
      String error = GLES20.glGetShaderInfoLog(shaderHandle);
231
      String error = GLES30.glGetShaderInfoLog(shaderHandle);
232 232

  
233 233
      switch(shaderType)
234 234
        {
235
        case GLES20.GL_VERTEX_SHADER  : throw new VertexCompilationException(error);
236
        case GLES20.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);
235
        case GLES30.GL_VERTEX_SHADER  : throw new VertexCompilationException(error);
236
        case GLES30.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);
237 237
        default                       : throw new RuntimeException(error);
238 238
        }
239 239
      }
......
268 268

  
269 269
    sanitizeMaxValues();
270 270

  
271
    final int vertexShaderHandle   = compileShader(GLES20.GL_VERTEX_SHADER  , vertexHeader   + vertexShader  );
272
    final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
271
    final int vertexShaderHandle   = compileShader(GLES30.GL_VERTEX_SHADER  , vertexHeader   + vertexShader  );
272
    final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
273 273

  
274 274
    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName);
275 275

  
......
277 277

  
278 278
    for(int i=0; i<mNumAttributes; i++)
279 279
      {
280
      mAttribute[i] = GLES20.glGetAttribLocation( mProgramHandle, mAttributeName[i]);
280
      mAttribute[i] = GLES30.glGetAttribLocation( mProgramHandle, mAttributeName[i]);
281 281
      }
282 282
    }
283 283

  
......
298 298
 */
299 299
  public void useProgram()
300 300
    {
301
    GLES20.glUseProgram(mProgramHandle);
301
    GLES30.glUseProgram(mProgramHandle);
302 302

  
303 303
    for(int i=0; i<mNumAttributes; i++)
304
      GLES20.glEnableVertexAttribArray(mAttribute[i]);
304
      GLES30.glEnableVertexAttribArray(mAttribute[i]);
305 305
    }
306 306
  }
307 307

  

Also available in: Unified diff