Project

General

Profile

Download (4.91 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effectqueue / UniformBlockProperties.java @ 78ff6ea9

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
  }
(6-6/6)