Project

General

Profile

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

library / src / main / java / org / distorted / library / uniformblock / UniformBlockFloatUniforms.java @ 8c57d77b

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.main.DistortedLibrary;
26
import org.distorted.library.main.InternalBuffer;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

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

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

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

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

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

    
66
    System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
67

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

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

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

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

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public float[] getBackingArray()
116
    {
117
    return mArray;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public void print(int num)
123
    {
124
    StringBuilder builder = new StringBuilder();
125

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

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

    
140
    builder.append(' ');
141
    builder.append('(');
142
    builder.append(num);
143
    builder.append(')');
144

    
145
    String res = builder.toString();
146

    
147
    DistortedLibrary.logMessage("UniformBlockFloatUniforms: "+res);
148
    }
149
  }
(3-3/4)