Revision 78ff6ea9
Added by Leszek Koltunski almost 5 years ago
| src/main/java/org/distorted/library/effect/FragmentEffect.java | ||
|---|---|---|
| 33 | 33 | 
    */  | 
| 34 | 34 | 
    public static final int NUM_FLOAT_UNIFORMS = 12;  | 
| 35 | 35 | 
    /**  | 
| 36 | 
       * 1: the name
   | 
|
| 36 | 
       * 4: the name, unused, unused, unused
   | 
|
| 37 | 37 | 
    */  | 
| 38 | 
      public static final int NUM_INT_UNIFORMS = 1;
   | 
|
| 38 | 
      public static final int NUM_INT_UNIFORMS = 4;
   | 
|
| 39 | 39 | 
     | 
| 40 | 40 | 
    static final int VALUES_OFFSET = 0;  | 
| 41 | 41 | 
    static final int CENTER_OFFSET = 5;  | 
| ... | ... | |
| 67 | 67 | 
     | 
| 68 | 68 | 
    mGLSL +=  | 
| 69 | 69 | 
     | 
| 70 | 
             "if( fName[i]=="+effect1+")\n"
   | 
|
| 70 | 
             "if( fProperties[i].x =="+effect1+")\n"
   | 
|
| 71 | 71 | 
            +  "{\n"
   | 
| 72 | 72 | 
    + "degree = sign(degree); \n"  | 
| 73 | 73 | 
    + code +"\n"  | 
| 74 | 74 | 
    + "}\n"  | 
| 75 | 75 | 
    +"else\n"  | 
| 76 | 
            +"if( fName[i]=="+effect2+")\n"
   | 
|
| 76 | 
            +"if( fProperties[i].x =="+effect2+")\n"
   | 
|
| 77 | 77 | 
            +  "{\n"
   | 
| 78 | 78 | 
    + code +"\n"  | 
| 79 | 79 | 
    + "}\n"  | 
| src/main/java/org/distorted/library/effect/MatrixEffectShear.java | ||
|---|---|---|
| 29 | 29 | 
    */  | 
| 30 | 30 | 
    public class MatrixEffectShear extends MatrixEffect  | 
| 31 | 31 | 
      {
   | 
| 32 | 
    private Data3D mShear, mCenter;  | 
|
| 32 | 
      private final Data3D mShear, mCenter;
   | 
|
| 33 | 33 | 
     | 
| 34 | 34 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 35 | 35 | 
    /**  | 
| src/main/java/org/distorted/library/effect/VertexEffectShear.java | ||
|---|---|---|
| 29 | 29 | 
      {
   | 
| 30 | 30 | 
    private static final EffectName NAME = EffectName.VERTEX_SHEAR;  | 
| 31 | 31 | 
     | 
| 32 | 
    private Data3D mShear;  | 
|
| 33 | 
    private Data3D mCenter;  | 
|
| 32 | 
    private final Data3D mShear, mCenter;  | 
|
| 34 | 33 | 
     | 
| 35 | 34 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 36 | 35 | 
    /**  | 
| src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
|---|---|---|
| 39 | 39 | 
      {
   | 
| 40 | 40 | 
    public static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL)  | 
| 41 | 41 | 
     | 
| 42 | 
    static final int PROP_VERT_UBO_BINDING = 5;  | 
|
| 43 | 
    static final int PROP_FRAG_UBO_BINDING = 6;  | 
|
| 44 | 
     | 
|
| 42 | 45 | 
    private static final int CREATE = 0;  | 
| 43 | 46 | 
    private static final int ATTACH = 1;  | 
| 44 | 47 | 
    private static final int DETACH = 2;  | 
| ... | ... | |
| 47 | 50 | 
    long mTime;  | 
| 48 | 51 | 
    int mNumEffects; // 'ToBe' will be more than mNumEffects if doWork() hasn't  | 
| 49 | 52 | 
    private int mNumEffectsToBe; // added them yet (or less if it hasn't removed some yet)  | 
| 50 | 
      private int mNumFloatUniforms, mNumIntUniforms;
   | 
|
| 53 | 
      private final int mNumFloatUniforms;
   | 
|
| 51 | 54 | 
    Effect[] mEffects;  | 
| 52 | 55 | 
     | 
| 53 | 56 | 
    float[] mFloatUniforms;  | 
| 54 | 
      int[] mIntUniforms;
   | 
|
| 57 | 
      UniformBlockProperties mUBP;
   | 
|
| 55 | 58 | 
     | 
| 56 | 59 | 
    private long mID;  | 
| 57 | 
    private int mIndex;  | 
|
| 60 | 
      private final int mIndex;
   | 
|
| 58 | 61 | 
    private boolean mCreated;  | 
| 59 | 62 | 
     | 
| 60 | 63 | 
    private static class Job  | 
| ... | ... | |
| 74 | 77 | 
    }  | 
| 75 | 78 | 
    }  | 
| 76 | 79 | 
     | 
| 77 | 
      private ArrayList<Job> mJobs = new ArrayList<>();
   | 
|
| 80 | 
      private final ArrayList<Job> mJobs;
   | 
|
| 78 | 81 | 
     | 
| 79 | 82 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 80 | 83 | 
     | 
| ... | ... | |
| 87 | 90 | 
    mNumEffectsToBe = 0;  | 
| 88 | 91 | 
    mIndex = index;  | 
| 89 | 92 | 
    mNumFloatUniforms = numFloatUniforms;  | 
| 90 | 
    mNumIntUniforms = numIntUniforms;  | 
|
| 93 | 
     | 
|
| 94 | 
    mUBP = new UniformBlockProperties(numIntUniforms);  | 
|
| 95 | 
    mJobs = new ArrayList<>();  | 
|
| 91 | 96 | 
     | 
| 92 | 97 | 
    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number  | 
| 93 | 98 | 
    InternalMaster.newSlave(this); // of uniforms later, on first render.  | 
| ... | ... | |
| 107 | 112 | 
    mNumEffectsToBe = 0;  | 
| 108 | 113 | 
    mIndex = source.mIndex;  | 
| 109 | 114 | 
    mNumFloatUniforms = source.mNumFloatUniforms;  | 
| 110 | 
    mNumIntUniforms = source.mNumIntUniforms;  | 
|
| 115 | 
     | 
|
| 116 | 
    mUBP = new UniformBlockProperties(source.mUBP);  | 
|
| 117 | 
    mJobs = new ArrayList<>();  | 
|
| 111 | 118 | 
     | 
| 112 | 119 | 
    int numJobs = source.mJobs.size();  | 
| 113 | 120 | 
     | 
| ... | ... | |
| 128 | 135 | 
    mNumEffectsToBe = source.mNumEffectsToBe;  | 
| 129 | 136 | 
    mIndex = source.mIndex;  | 
| 130 | 137 | 
    mNumFloatUniforms = source.mNumFloatUniforms;  | 
| 131 | 
    mNumIntUniforms = source.mNumIntUniforms;  | 
|
| 138 | 
     | 
|
| 139 | 
    mUBP = new UniformBlockProperties(source.mUBP);  | 
|
| 140 | 
    mJobs = new ArrayList<>();  | 
|
| 132 | 141 | 
     | 
| 133 | 142 | 
    int max = InternalStackFrameList.getMax(mIndex);  | 
| 134 | 143 | 
     | 
| ... | ... | |
| 136 | 145 | 
            {
   | 
| 137 | 146 | 
    mEffects = new Effect[max];  | 
| 138 | 147 | 
    mFloatUniforms = new float[max*source.mNumFloatUniforms];  | 
| 139 | 
    mIntUniforms = new int[max*source.mNumIntUniforms];  | 
|
| 140 | 148 | 
     | 
| 141 | 149 | 
    if( mNumEffects>=0 )  | 
| 142 | 150 | 
              {
   | 
| 143 | 151 | 
    System.arraycopy(source.mEffects, 0, mEffects, 0, mNumEffects);  | 
| 144 | 152 | 
    }  | 
| 145 | 
     | 
|
| 146 | 
    if( mNumIntUniforms*mNumEffects>=0 )  | 
|
| 147 | 
              {
   | 
|
| 148 | 
    System.arraycopy(source.mIntUniforms, 0, mIntUniforms, 0, mNumIntUniforms*mNumEffects);  | 
|
| 149 | 
    }  | 
|
| 150 | 153 | 
    }  | 
| 151 | 154 | 
    }  | 
| 152 | 155 | 
    }  | 
| ... | ... | |
| 173 | 176 | 
     | 
| 174 | 177 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 175 | 178 | 
     | 
| 176 | 
    public static void send(EffectQueue[] queues, float distance, float mipmap,  | 
|
| 179 | 
      public static void send(EffectQueue[] queues, int programH, float distance, float mipmap,
   | 
|
| 177 | 180 | 
    float[] projection, float inflate, int variant )  | 
| 178 | 181 | 
        {
   | 
| 179 | 182 | 
    ((EffectQueueMatrix )queues[0]).send(distance, mipmap, projection, variant);  | 
| 180 | 
    ((EffectQueueVertex )queues[1]).send(inflate, variant);  | 
|
| 181 | 
    ((EffectQueueFragment)queues[2]).send(variant);  | 
|
| 183 | 
        ((EffectQueueVertex  )queues[1]).send(inflate, programH, variant);
   | 
|
| 184 | 
        ((EffectQueueFragment)queues[2]).send(programH, variant);
   | 
|
| 182 | 185 | 
    }  | 
| 183 | 186 | 
     | 
| 184 | 187 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| ... | ... | |
| 252 | 255 | 
    mNumEffects--;  | 
| 253 | 256 | 
    mEffects[pos].remQueue(this);  | 
| 254 | 257 | 
    System.arraycopy(mEffects, pos+1, mEffects, pos, mNumEffects-pos);  | 
| 255 | 
          System.arraycopy(mIntUniforms, mNumIntUniforms*(pos+1), mIntUniforms, mNumIntUniforms*pos, mNumIntUniforms*(mNumEffects-pos) );
   | 
|
| 258 | 
          mUBP.remove(pos, mNumEffects);
   | 
|
| 256 | 259 | 
    mEffects[mNumEffects] = null;  | 
| 257 | 260 | 
    }  | 
| 258 | 261 | 
    }  | 
| ... | ... | |
| 261 | 264 | 
     | 
| 262 | 265 | 
    private void addNow(int pos, Effect effect)  | 
| 263 | 266 | 
        {
   | 
| 264 | 
    mEffects[pos] = effect;  | 
|
| 265 | 
    mIntUniforms[mNumIntUniforms*pos] = effect.getName().ordinal();  | 
|
| 266 | 
     | 
|
| 267 | 
    mEffects[pos] = effect;  | 
|
| 268 | 
    mUBP.addOrdinal(pos, effect.getName().ordinal() );  | 
|
| 267 | 269 | 
    effect.addQueue(this);  | 
| 268 | 270 | 
     | 
| 269 | 271 | 
    if( mIndex==EffectType.VERTEX.ordinal() )  | 
| 270 | 272 | 
          {
   | 
| 271 | 
          effect.writeAssociations(mIntUniforms, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3);
   | 
|
| 273 | 
          mUBP.addAssociations(pos,effect);
   | 
|
| 272 | 274 | 
    }  | 
| 273 | 275 | 
    }  | 
| 274 | 276 | 
     | 
| ... | ... | |
| 411 | 413 | 
          {
   | 
| 412 | 414 | 
    if (mEffects[j].getID() == effectID)  | 
| 413 | 415 | 
            {
   | 
| 414 | 
            mEffects[j].writeAssociations(mIntUniforms, mNumIntUniforms*j+1, mNumIntUniforms*j+3);
   | 
|
| 416 | 
            mUBP.addAssociations(j,mEffects[j]);
   | 
|
| 415 | 417 | 
    }  | 
| 416 | 418 | 
    }  | 
| 417 | 419 | 
    }  | 
| ... | ... | |
| 435 | 437 | 
                           {
   | 
| 436 | 438 | 
    mEffects = new Effect[max];  | 
| 437 | 439 | 
    mFloatUniforms = new float[max*job.num1];  | 
| 438 | 
                           mIntUniforms   = new int[max*job.num2];
   | 
|
| 440 | 
                           mUBP           = new UniformBlockProperties(job.num2);
   | 
|
| 439 | 441 | 
    }  | 
| 440 | 442 | 
    mCreated = true;  | 
| 441 | 443 | 
     | 
| ... | ... | |
| 452 | 454 | 
    }  | 
| 453 | 455 | 
    else if( position<=mNumEffects )  | 
| 454 | 456 | 
                             {
   | 
| 455 | 
                             System.arraycopy(mEffects    , position, mEffects    , position+1, mNumEffects-position);
   | 
|
| 456 | 
                             System.arraycopy(mIntUniforms, mNumIntUniforms*position, mIntUniforms, mNumIntUniforms*(position+1), mNumIntUniforms*(mNumEffects-position) );
   | 
|
| 457 | 
                             System.arraycopy(mEffects, position, mEffects, position+1, mNumEffects-position);
   | 
|
| 458 | 
                             mUBP.makeHole(position, mNumEffects);
   | 
|
| 457 | 459 | 
    addNow(position,job.effect);  | 
| 458 | 460 | 
    mNumEffects++;  | 
| 459 | 461 | 
    changed = true;  | 
| src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java | ||
|---|---|---|
| 34 | 34 | 
     | 
| 35 | 35 | 
    private static final int INDEX = EffectType.FRAGMENT.ordinal();  | 
| 36 | 36 | 
     | 
| 37 | 
      private static int[] mNumEffectsH = new int[MAIN_VARIANTS];
   | 
|
| 38 | 
      private static int[] mNameH       = new int[MAIN_VARIANTS];
   | 
|
| 39 | 
      private static int[] mUniformsH   = new int[MAIN_VARIANTS];
   | 
|
| 37 | 
      private final static int[] mNumEffectsH   = new int[MAIN_VARIANTS];
   | 
|
| 38 | 
      private final static int[] mUniformsH     = new int[MAIN_VARIANTS];
   | 
|
| 39 | 
      private final static int[] mPropBlockIndex= new int[MAIN_VARIANTS];
   | 
|
| 40 | 40 | 
     | 
| 41 | 41 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 42 | 42 | 
     | 
| ... | ... | |
| 56 | 56 | 
     | 
| 57 | 57 | 
    static void uniforms(int mProgramH, int variant)  | 
| 58 | 58 | 
        {
   | 
| 59 | 
        mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "fNumEffects");
   | 
|
| 60 | 
        mNameH[variant]      = GLES30.glGetUniformLocation( mProgramH, "fName");
   | 
|
| 61 | 
        mUniformsH[variant]  = GLES30.glGetUniformLocation( mProgramH, "fUniforms");
   | 
|
| 59 | 
        mNumEffectsH[variant]    = GLES30.glGetUniformLocation  ( mProgramH, "fNumEffects");
   | 
|
| 60 | 
        mUniformsH[variant]      = GLES30.glGetUniformLocation  ( mProgramH, "fUniforms");
   | 
|
| 61 | 
        mPropBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
   | 
|
| 62 | 62 | 
    }  | 
| 63 | 63 | 
     | 
| 64 | 64 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| ... | ... | |
| 82 | 82 | 
     | 
| 83 | 83 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 84 | 84 | 
     | 
| 85 | 
    void send(int variant)  | 
|
| 85 | 
      void send(int programH, int variant)
   | 
|
| 86 | 86 | 
        {
   | 
| 87 | 87 | 
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);  | 
| 88 | 88 | 
     | 
| 89 | 89 | 
    if( mNumEffects>0 )  | 
| 90 | 90 | 
          {
   | 
| 91 | 
    GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mIntUniforms , 0);  | 
|
| 91 | 
    int index = mUBP.getIndex();  | 
|
| 92 | 
    GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, PROP_FRAG_UBO_BINDING, index);  | 
|
| 93 | 
    GLES30.glUniformBlockBinding(programH, mPropBlockIndex[variant], PROP_FRAG_UBO_BINDING);  | 
|
| 92 | 94 | 
    GLES30.glUniform4fv( mUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms, 0);  | 
| 93 | 95 | 
    }  | 
| 94 | 96 | 
    }  | 
| src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
|---|---|---|
| 190 | 190 | 
    EffectQueueVertex vertex = (EffectQueueVertex)queues[1];  | 
| 191 | 191 | 
     | 
| 192 | 192 | 
    matrix.send(distance, mipmap, projection, 2);  | 
| 193 | 
    vertex.send(mHalo*0.01f,2);  | 
|
| 193 | 
        vertex.send(mHalo*0.01f,mPreProgramH,2);
   | 
|
| 194 | 194 | 
     | 
| 195 | 195 | 
    if( mA!=0.0f )  | 
| 196 | 196 | 
          {
   | 
| src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
|---|---|---|
| 38 | 38 | 
     | 
| 39 | 39 | 
    private static final int INDEX = EffectType.VERTEX.ordinal();  | 
| 40 | 40 | 
     | 
| 41 | 
      private static int[] mNumEffectsH = new int[MAIN_VARIANTS];
   | 
|
| 42 | 
      private static int[] mInflateH    = new int[MAIN_VARIANTS];
   | 
|
| 43 | 
      private static int[] mPropertiesH = new int[MAIN_VARIANTS];
   | 
|
| 44 | 
      private static int[] mUniformsH   = new int[MAIN_VARIANTS];
   | 
|
| 41 | 
      private final static int[] mNumEffectsH   = new int[MAIN_VARIANTS];
   | 
|
| 42 | 
      private final static int[] mInflateH      = new int[MAIN_VARIANTS];
   | 
|
| 43 | 
      private final static int[] mUniformsH     = new int[MAIN_VARIANTS];
   | 
|
| 44 | 
      private final static int[] mPropBlockIndex= new int[MAIN_VARIANTS];
   | 
|
| 45 | 45 | 
     | 
| 46 | 46 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 47 | 47 | 
     | 
| ... | ... | |
| 61 | 61 | 
     | 
| 62 | 62 | 
    static void uniforms(int mProgramH, int variant)  | 
| 63 | 63 | 
        {
   | 
| 64 | 
        mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
   | 
|
| 65 | 
        mInflateH[variant]   = GLES30.glGetUniformLocation( mProgramH, "u_Inflate");
   | 
|
| 66 | 
        mPropertiesH[variant]= GLES30.glGetUniformLocation( mProgramH, "vProperties");
   | 
|
| 67 | 
        mUniformsH[variant]  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
   | 
|
| 64 | 
        mNumEffectsH[variant]    = GLES30.glGetUniformLocation  ( mProgramH, "vNumEffects");
   | 
|
| 65 | 
        mInflateH[variant]       = GLES30.glGetUniformLocation  ( mProgramH, "u_Inflate");
   | 
|
| 66 | 
        mUniformsH[variant]      = GLES30.glGetUniformLocation  ( mProgramH, "vUniforms");
   | 
|
| 67 | 
        mPropBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
   | 
|
| 68 | 68 | 
    }  | 
| 69 | 69 | 
     | 
| 70 | 70 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| ... | ... | |
| 96 | 96 | 
    *  | 
| 97 | 97 | 
    * @y.exclude  | 
| 98 | 98 | 
    */  | 
| 99 | 
    public void send(float inflate, int variant)  | 
|
| 99 | 
      public void send(float inflate, int programH, int variant)
   | 
|
| 100 | 100 | 
        {
   | 
| 101 | 101 | 
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);  | 
| 102 | 102 | 
    GLES30.glUniform1f( mInflateH[variant] , inflate );  | 
| 103 | 103 | 
     | 
| 104 | 104 | 
    if( mNumEffects>0 )  | 
| 105 | 105 | 
          {
   | 
| 106 | 
    GLES30.glUniform4iv( mPropertiesH[variant], mNumEffects, mIntUniforms , 0);  | 
|
| 106 | 
    int index = mUBP.getIndex();  | 
|
| 107 | 
    GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, PROP_VERT_UBO_BINDING, index);  | 
|
| 108 | 
    GLES30.glUniformBlockBinding(programH, mPropBlockIndex[variant], PROP_VERT_UBO_BINDING);  | 
|
| 107 | 109 | 
    GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0);  | 
| 108 | 110 | 
    }  | 
| 109 | 111 | 
    }  | 
| src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java | ||
|---|---|---|
| 1 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 2 | 
    // Copyright 2021 Leszek Koltunski //  | 
|
| 3 | 
    // //  | 
|
| 4 | 
    // This file is part of Distorted. //  | 
|
| 5 | 
    // //  | 
|
| 6 | 
    // Distorted is free software: you can redistribute it and/or modify //  | 
|
| 7 | 
    // it under the terms of the GNU General Public License as published by //  | 
|
| 8 | 
    // the Free Software Foundation, either version 2 of the License, or //  | 
|
| 9 | 
    // (at your option) any later version. //  | 
|
| 10 | 
    // //  | 
|
| 11 | 
    // Distorted is distributed in the hope that it will be useful, //  | 
|
| 12 | 
    // but WITHOUT ANY WARRANTY; without even the implied warranty of //  | 
|
| 13 | 
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //  | 
|
| 14 | 
    // GNU General Public License for more details. //  | 
|
| 15 | 
    // //  | 
|
| 16 | 
    // You should have received a copy of the GNU General Public License //  | 
|
| 17 | 
    // along with Distorted. If not, see <http://www.gnu.org/licenses/>. //  | 
|
| 18 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 19 | 
     | 
|
| 20 | 
    package org.distorted.library.effectqueue;  | 
|
| 21 | 
     | 
|
| 22 | 
    import android.opengl.GLES30;  | 
|
| 23 | 
     | 
|
| 24 | 
    import org.distorted.library.effect.Effect;  | 
|
| 25 | 
    import org.distorted.library.main.InternalBuffer;  | 
|
| 26 | 
     | 
|
| 27 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 28 | 
     | 
|
| 29 | 
    class UniformBlockProperties  | 
|
| 30 | 
      {
   | 
|
| 31 | 
    private static final int NUM_BYTES = 4*100;  | 
|
| 32 | 
     | 
|
| 33 | 
    private final InternalBuffer mUBO;  | 
|
| 34 | 
    private final int[] mProperties;  | 
|
| 35 | 
    private final int mNumIntUniforms;  | 
|
| 36 | 
     | 
|
| 37 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 38 | 
     | 
|
| 39 | 
    UniformBlockProperties(int numUniforms)  | 
|
| 40 | 
        {
   | 
|
| 41 | 
    mProperties= new int[NUM_BYTES/4];  | 
|
| 42 | 
    mNumIntUniforms = numUniforms;  | 
|
| 43 | 
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);  | 
|
| 44 | 
    }  | 
|
| 45 | 
     | 
|
| 46 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 47 | 
     | 
|
| 48 | 
    UniformBlockProperties(UniformBlockProperties original)  | 
|
| 49 | 
        {
   | 
|
| 50 | 
    int size = original.mProperties.length;  | 
|
| 51 | 
    mProperties= new int[size];  | 
|
| 52 | 
    System.arraycopy(original.mProperties, 0, mProperties, 0, size);  | 
|
| 53 | 
    mNumIntUniforms = original.mNumIntUniforms;  | 
|
| 54 | 
     | 
|
| 55 | 
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);  | 
|
| 56 | 
    }  | 
|
| 57 | 
     | 
|
| 58 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 59 | 
     | 
|
| 60 | 
    int getIndex()  | 
|
| 61 | 
        {
   | 
|
| 62 | 
    return mUBO.createImmediatelyInt( NUM_BYTES, mProperties);  | 
|
| 63 | 
    }  | 
|
| 64 | 
     | 
|
| 65 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 66 | 
     | 
|
| 67 | 
    void remove(int pos, int numEffects)  | 
|
| 68 | 
        {
   | 
|
| 69 | 
    System.arraycopy(mProperties, mNumIntUniforms*(pos+1), mProperties, mNumIntUniforms*pos, mNumIntUniforms*(numEffects-pos) );  | 
|
| 70 | 
    mUBO.invalidate();  | 
|
| 71 | 
    }  | 
|
| 72 | 
     | 
|
| 73 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 74 | 
     | 
|
| 75 | 
    void makeHole(int pos, int numEffects)  | 
|
| 76 | 
        {
   | 
|
| 77 | 
    System.arraycopy(mProperties, mNumIntUniforms*pos, mProperties, mNumIntUniforms*(pos+1), mNumIntUniforms*(numEffects-pos) );  | 
|
| 78 | 
    mUBO.invalidate();  | 
|
| 79 | 
    }  | 
|
| 80 | 
     | 
|
| 81 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 82 | 
     | 
|
| 83 | 
    void addOrdinal(int pos, int ordinal)  | 
|
| 84 | 
        {
   | 
|
| 85 | 
    mProperties[mNumIntUniforms*pos] = ordinal;  | 
|
| 86 | 
    mUBO.invalidate();  | 
|
| 87 | 
    }  | 
|
| 88 | 
     | 
|
| 89 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 90 | 
     | 
|
| 91 | 
    void addAssociations(int pos, Effect effect)  | 
|
| 92 | 
        {
   | 
|
| 93 | 
    effect.writeAssociations(mProperties, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3);  | 
|
| 94 | 
    mUBO.invalidate();  | 
|
| 95 | 
    }  | 
|
| 96 | 
     | 
|
| 97 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
|
| 98 | 
     | 
|
| 99 | 
    void print(int num)  | 
|
| 100 | 
        {
   | 
|
| 101 | 
    StringBuilder builder = new StringBuilder();  | 
|
| 102 | 
     | 
|
| 103 | 
    builder.append(mUBO.getID());  | 
|
| 104 | 
        builder.append(':');
   | 
|
| 105 | 
     | 
|
| 106 | 
    for(int i=0; i<6; i++)  | 
|
| 107 | 
          {
   | 
|
| 108 | 
          builder.append(' ');
   | 
|
| 109 | 
    builder.append(mProperties[4*i ]);  | 
|
| 110 | 
          builder.append(' ');
   | 
|
| 111 | 
    builder.append(mProperties[4*i+1]);  | 
|
| 112 | 
          builder.append(' ');
   | 
|
| 113 | 
    builder.append(mProperties[4*i+2]);  | 
|
| 114 | 
          builder.append(',');
   | 
|
| 115 | 
    }  | 
|
| 116 | 
     | 
|
| 117 | 
        builder.append(' ');
   | 
|
| 118 | 
        builder.append('(');
   | 
|
| 119 | 
    builder.append(num);  | 
|
| 120 | 
        builder.append(')');
   | 
|
| 121 | 
     | 
|
| 122 | 
    String res = builder.toString();  | 
|
| 123 | 
     | 
|
| 124 | 
        android.util.Log.e("ubp", res);
   | 
|
| 125 | 
    }  | 
|
| 126 | 
    }  | 
|
| src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
|---|---|---|
| 116 | 116 | 
    private static int mGLSL;  | 
| 117 | 117 | 
    private static String mGLSL_VERSION;  | 
| 118 | 118 | 
    private static boolean mOITCompilationAttempted;  | 
| 119 | 
    private static int mMaxTextureSize = Integer.MAX_VALUE;  | 
|
| 119 | 
     | 
|
| 120 | 
    private static int mMaxTextureSize = Integer.MAX_VALUE;  | 
|
| 121 | 
    private static int mMaxNumberOfVerUniforms = Integer.MAX_VALUE;  | 
|
| 122 | 
    private static int mMaxNumberOfFraUniforms = Integer.MAX_VALUE;  | 
|
| 120 | 123 | 
     | 
| 121 | 124 | 
    //////////////////////////////////////////////////////////////////////////////////////////////  | 
| 122 | 125 | 
    /// MAIN PROGRAM ///  | 
| ... | ... | |
| 547 | 550 | 
    mFullProgram.useProgram();  | 
| 548 | 551 | 
    mesh.bindVertexAttribs(mFullProgram);  | 
| 549 | 552 | 
    queue.compute(1);  | 
| 550 | 
    queue.send(0.0f,3);  | 
|
| 553 | 
        queue.send(0.0f,mFullProgramH,3);
   | 
|
| 551 | 554 | 
    mesh.send(mFullProgramH,3);  | 
| 552 | 555 | 
     | 
| 553 | 556 | 
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );  | 
| ... | ... | |
| 583 | 586 | 
    float mipmap = surface.mMipmap;  | 
| 584 | 587 | 
    float[] projection= surface.mProjectionMatrix;  | 
| 585 | 588 | 
     | 
| 586 | 
    EffectQueue.send(queues, distance, mipmap, projection, inflate, 1 );  | 
|
| 589 | 
          EffectQueue.send(queues, mMainOITProgramH, distance, mipmap, projection, inflate, 1 );
   | 
|
| 587 | 590 | 
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );  | 
| 588 | 591 | 
     | 
| 589 | 592 | 
    if( mesh.getShowNormals() )  | 
| 590 | 593 | 
            {
   | 
| 591 | 594 | 
    mMainProgram.useProgram();  | 
| 592 | 595 | 
    mesh.send(mMainProgramH,0);  | 
| 593 | 
    EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 );  | 
|
| 596 | 
            EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 );
   | 
|
| 594 | 597 | 
    displayNormals(projection,mesh);  | 
| 595 | 598 | 
    }  | 
| 596 | 599 | 
    }  | 
| ... | ... | |
| 617 | 620 | 
    float mipmap = surface.mMipmap;  | 
| 618 | 621 | 
    float[] projection= surface.mProjectionMatrix;  | 
| 619 | 622 | 
     | 
| 620 | 
    EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 );  | 
|
| 623 | 
          EffectQueue.send(queues, mMainProgramH, distance, mipmap, projection, inflate, 0 );
   | 
|
| 621 | 624 | 
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );  | 
| 622 | 625 | 
     | 
| 623 | 626 | 
    if( mesh.getShowNormals() ) displayNormals(projection,mesh);  | 
| ... | ... | |
| 984 | 987 | 
    mGLSL = (major==3 && minor==0) ? 300 : 310;  | 
| 985 | 988 | 
    }  | 
| 986 | 989 | 
     | 
| 987 | 
    int[] maxTextureSize = new int[1];  | 
|
| 988 | 
    GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);  | 
|
| 989 | 
    mMaxTextureSize = maxTextureSize[0];  | 
|
| 990 | 
    int[] tmp = new int[1];  | 
|
| 991 | 
    GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, tmp, 0);  | 
|
| 992 | 
    mMaxTextureSize = tmp[0];  | 
|
| 993 | 
    GLES30.glGetIntegerv(GLES30.GL_MAX_VERTEX_UNIFORM_VECTORS , tmp, 0);  | 
|
| 994 | 
    mMaxNumberOfVerUniforms = tmp[0];  | 
|
| 995 | 
    GLES30.glGetIntegerv(GLES30.GL_MAX_FRAGMENT_UNIFORM_VECTORS, tmp, 0);  | 
|
| 996 | 
    mMaxNumberOfFraUniforms = tmp[0];  | 
|
| 990 | 997 | 
     | 
| 991 | 998 | 
        android.util.Log.e("DISTORTED", "Using OpenGL ES "+major+"."+minor);
   | 
| 999 | 
        android.util.Log.e("DISTORTED", "max texture size: "+mMaxTextureSize);
   | 
|
| 1000 | 
        android.util.Log.e("DISTORTED", "max num vert: "+mMaxNumberOfVerUniforms);
   | 
|
| 1001 | 
        android.util.Log.e("DISTORTED", "max num frag: "+mMaxNumberOfFraUniforms);
   | 
|
| 1002 | 
     | 
|
| 992 | 1003 | 
    mGLSL_VERSION = "#version "+mGLSL+" es\n";  | 
| 993 | 1004 | 
     | 
| 994 | 1005 | 
    InternalStackFrameList.setInitialized(true);  | 
| src/main/java/org/distorted/library/mesh/MeshBase.java | ||
|---|---|---|
| 83 | 83 | 
    private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ  | 
| 84 | 84 | 
    private float[] mVertAttribs2; // packed: TexS,TexT, Component  | 
| 85 | 85 | 
    private float mInflate;  | 
| 86 | 
    private UniformBlockAssociation mUBA;  | 
|
| 87 | 
    private UniformBlockCenter mUBC;  | 
|
| 86 | 
       private final UniformBlockAssociation mUBA;
   | 
|
| 87 | 
       private final UniformBlockCenter mUBC;
   | 
|
| 88 | 88 | 
     | 
| 89 | 89 | 
    DeferredJobs.JobNode[] mJobNode;  | 
| 90 | 90 | 
     | 
| 91 | 
    private static int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];  | 
|
| 92 | 
    private static int[] mAssocBlockIndex = new int[EffectQueue.MAIN_VARIANTS];  | 
|
| 91 | 
       private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
   | 
|
| 92 | 
       private static final int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
   | 
|
| 93 | 93 | 
     | 
| 94 | 94 | 
    private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component  | 
| 95 | 95 | 
     | 
| 96 | 96 | 
    private static class TexComponent  | 
| 97 | 97 | 
         {
   | 
| 98 | 98 | 
    private int mEndIndex;  | 
| 99 | 
    private Static4D mTextureMap;  | 
|
| 99 | 
         private final Static4D mTextureMap;
   | 
|
| 100 | 100 | 
     | 
| 101 | 101 | 
    TexComponent(int end)  | 
| 102 | 102 | 
           {
   | 
| src/main/java/org/distorted/library/mesh/UniformBlockAssociation.java | ||
|---|---|---|
| 32 | 32 | 
    private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;  | 
| 33 | 33 | 
    private static final int DEFAULT_ASSOCIATION = 0xffffffff;  | 
| 34 | 34 | 
     | 
| 35 | 
    private InternalBuffer mUBO;  | 
|
| 36 | 
    private int[] mAssociations;  | 
|
| 35 | 
      private final InternalBuffer mUBO;
   | 
|
| 36 | 
      private final int[] mAssociations;
   | 
|
| 37 | 37 | 
     | 
| 38 | 38 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 39 | 39 | 
     | 
| src/main/java/org/distorted/library/mesh/UniformBlockCenter.java | ||
|---|---|---|
| 31 | 31 | 
      {
   | 
| 32 | 32 | 
    private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;  | 
| 33 | 33 | 
     | 
| 34 | 
    private InternalBuffer mUBO;  | 
|
| 35 | 
    private float[] mCenter;  | 
|
| 34 | 
      private final InternalBuffer mUBO;
   | 
|
| 35 | 
      private final float[] mCenter;
   | 
|
| 36 | 36 | 
     | 
| 37 | 37 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| 38 | 38 | 
     | 
| src/main/java/org/distorted/library/type/Dynamic.java | ||
|---|---|---|
| 185 | 185 | 
    mLastPos = -1;  | 
| 186 | 186 | 
    mAccessType= ACCESS_TYPE_RANDOM;  | 
| 187 | 187 | 
    mConvexity = 1.0f;  | 
| 188 | 
        mStartTime = 0;
   | 
|
| 188 | 
        mStartTime = -1;
   | 
|
| 189 | 189 | 
    mCorrectedTime = 0;  | 
| 190 | 190 | 
     | 
| 191 | 191 | 
    baseV = new float[mDimension][mDimension];  | 
| ... | ... | |
| 587 | 587 | 
    */  | 
| 588 | 588 | 
    public void resetToBeginning()  | 
| 589 | 589 | 
        {
   | 
| 590 | 
        mStartTime = 0;
   | 
|
| 590 | 
        mStartTime = -1;
   | 
|
| 591 | 591 | 
    }  | 
| 592 | 592 | 
     | 
| 593 | 593 | 
    ///////////////////////////////////////////////////////////////////////////////////////////////////  | 
| ... | ... | |
| 686 | 686 | 
    return false;  | 
| 687 | 687 | 
    }  | 
| 688 | 688 | 
     | 
| 689 | 
        if( mStartTime==0 )
   | 
|
| 689 | 
        if( mStartTime==-1 )
   | 
|
| 690 | 690 | 
          {
   | 
| 691 | 691 | 
    mStartTime = time;  | 
| 692 | 692 | 
    mLastPos = -1;  | 
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 46 | 46 | 
     | 
| 47 | 47 | 
    #if NUM_FRAGMENT>0  | 
| 48 | 48 | 
    uniform int fNumEffects; // total number of fragment effects  | 
| 49 | 
    uniform int fName[NUM_FRAGMENT]; // their namess.  | 
|
| 49 | 
     | 
|
| 50 | 
    layout (std140) uniform fUniformProperties  | 
|
| 51 | 
      {
   | 
|
| 52 | 
    ivec4 fProperties[NUM_FRAGMENT]; // their properties, 4 ints:  | 
|
| 53 | 
    // name of the effect, unused, unused, unused  | 
|
| 54 | 
    };  | 
|
| 55 | 
     | 
|
| 50 | 56 | 
    uniform vec4 fUniforms[3*NUM_FRAGMENT]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].  | 
| 51 | 57 | 
    // The first vec4 is the Interpolated values,  | 
| 52 | 58 | 
    // second vec4: first float - cache, next 3: Center, the third - the Region.  | 
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 46 | 46 | 
     | 
| 47 | 47 | 
    #if NUM_VERTEX>0  | 
| 48 | 48 | 
    uniform int vNumEffects; // total number of vertex effects  | 
| 49 | 
    uniform ivec4 vProperties[NUM_VERTEX];// their properties, 4 ints:  | 
|
| 49 | 
     | 
|
| 50 | 
    layout (std140) uniform vUniformProperties  | 
|
| 51 | 
      {
   | 
|
| 52 | 
    ivec4 vProperties[NUM_VERTEX]; // their properties, 4 ints:  | 
|
| 50 | 53 | 
    // 1: name of the effect  | 
| 51 | 54 | 
    // 2: effect's AND association  | 
| 52 | 55 | 
    // 3: reserved int (probably another AND assoc in the future)  | 
| 53 | 56 | 
    // 4: effect's EQU association  | 
| 57 | 
    };  | 
|
| 54 | 58 | 
     | 
| 55 | 59 | 
    uniform vec4 vUniforms[3*NUM_VERTEX]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].  | 
| 56 | 60 | 
    // The first vec4 is the Interpolated values,  | 
Also available in: Unified diff
Convert the Integer part (i.e. effect names and the two associations) of vertex and fragment shaders to Uniform Buffer Objects.
Next: convert the last part, i.e. the float effect parameters.