Project

General

Profile

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

library / src / main / java / org / distorted / library / uniformblock / UniformBlockFloatUniforms.java @ 2b7d2abb

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.uniformblock;
21

    
22
import android.opengl.GLES30;
23

    
24
import org.distorted.library.main.InternalBuffer;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

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

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public UniformBlockFloatUniforms(UniformBlockFloatUniforms original)
58
    {
59
    mNumUniforms = original.mNumUniforms;
60
    mSize        = original.mSize;
61
    mArray= new float[mNumUniforms*mSize];
62
    mReallyUseUBO= original.mReallyUseUBO;
63

    
64
    System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
65

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  public void markForDeletion()
94
    {
95
    if( mReallyUseUBO )
96
      {
97
      mUBO.markForDeletion();
98
      }
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public void invalidate()
104
    {
105
    if( mReallyUseUBO )
106
      {
107
      mUBO.invalidate();
108
      }
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public float[] getBackingArray()
114
    {
115
    return mArray;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public void print(int num)
121
    {
122
    StringBuilder builder = new StringBuilder();
123

    
124
    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
125
    builder.append(':');
126

    
127
    for(int i=0; i<6; i++)
128
      {
129
      builder.append(' ');
130
      builder.append(mArray[4*i  ]);
131
      builder.append(' ');
132
      builder.append(mArray[4*i+1]);
133
      builder.append(' ');
134
      builder.append(mArray[4*i+2]);
135
      builder.append(',');
136
      }
137

    
138
    builder.append(' ');
139
    builder.append('(');
140
    builder.append(num);
141
    builder.append(')');
142

    
143
    String res = builder.toString();
144

    
145
    android.util.Log.e("ubp", res);
146
    }
147
  }
(3-3/4)