Project

General

Profile

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

library / src / main / java / org / distorted / library / uniformblock / UniformBlockIntUniforms.java @ d23592bb

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library 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 GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
package org.distorted.library.uniformblock;
22

    
23
import android.opengl.GLES30;
24

    
25
import org.distorted.library.effect.Effect;
26
import org.distorted.library.main.InternalBuffer;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
/**
30
 * Not part of public API, do not document
31
 *
32
 * @y.exclude
33
 */
34
public class UniformBlockIntUniforms
35
  {
36
  private InternalBuffer mUBO;
37
  private final int[] mArray;
38
  private final int mNumUniforms, mSize;
39
  private final boolean mReallyUseUBO;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  public UniformBlockIntUniforms(int numUniforms, int size, boolean reallyUse)
44
    {
45
    mNumUniforms = numUniforms;
46
    mSize        = size;
47
    mArray       = new int[mNumUniforms*mSize];
48
    mReallyUseUBO= reallyUse;
49

    
50
    if( mReallyUseUBO )
51
      {
52
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
53
      }
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  public UniformBlockIntUniforms(UniformBlockIntUniforms original)
59
    {
60
    mNumUniforms = original.mNumUniforms;
61
    mSize        = original.mSize;
62
    mArray       = new int[mNumUniforms*mSize];
63
    mReallyUseUBO= original.mReallyUseUBO;
64

    
65
    System.arraycopy(original.mArray, 0, mArray, 0, mSize);
66

    
67
    if( mReallyUseUBO )
68
      {
69
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
70
      }
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  public int getIndex()
76
    {
77
    return mUBO.createImmediatelyInt( 4*mNumUniforms*mSize, mArray);
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  public void remove(int pos, int numEffects)
83
    {
84
    System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
85

    
86
    if( mReallyUseUBO )
87
      {
88
      mUBO.invalidate();
89
      }
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public void makeHole(int pos, int numEffects)
95
    {
96
    System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) );
97

    
98
    if( mReallyUseUBO )
99
      {
100
      mUBO.invalidate();
101
      }
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  public void addOrdinal(int pos, int ordinal)
107
    {
108
    mArray[mNumUniforms*pos] = ordinal;
109

    
110
    if( mReallyUseUBO )
111
      {
112
      mUBO.invalidate();
113
      }
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public void addAssociations(int pos, Effect effect)
119
    {
120
    effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3);
121

    
122
    if( mReallyUseUBO )
123
      {
124
      mUBO.invalidate();
125
      }
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  public void markForDeletion()
131
    {
132
    if( mReallyUseUBO )
133
      {
134
      mUBO.markForDeletion();
135
      }
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public int[] getBackingArray()
141
    {
142
    return mArray;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public void print(int num)
148
    {
149
    StringBuilder builder = new StringBuilder();
150

    
151
    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
152
    builder.append(':');
153

    
154
    for(int i=0; i<6; i++)
155
      {
156
      builder.append(' ');
157
      builder.append(mArray[4*i  ]);
158
      builder.append(' ');
159
      builder.append(mArray[4*i+1]);
160
      builder.append(' ');
161
      builder.append(mArray[4*i+2]);
162
      builder.append(',');
163
      }
164

    
165
    builder.append(' ');
166
    builder.append('(');
167
    builder.append(num);
168
    builder.append(')');
169

    
170
    String res = builder.toString();
171

    
172
    android.util.Log.e("ubp", res);
173
    }
174
  }
(4-4/4)