Project

General

Profile

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

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

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.effect.Effect;
25
import org.distorted.library.main.InternalBuffer;
26

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
  public UniformBlockIntUniforms(int numUniforms, int size)
42
    {
43
    mNumUniforms = numUniforms;
44
    mSize        = size;
45
    mArray= new int[mNumUniforms*mSize];
46
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  public UniformBlockIntUniforms(UniformBlockIntUniforms original)
52
    {
53
    mNumUniforms = original.mNumUniforms;
54
    mSize        = original.mSize;
55
    mArray= new int[mNumUniforms*mSize];
56
    System.arraycopy(original.mArray, 0, mArray, 0, mSize);
57
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  public int getIndex()
63
    {
64
    return mUBO.createImmediatelyInt( 4*mNumUniforms*mSize, mArray);
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public void remove(int pos, int numEffects)
70
    {
71
    System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
72
    mUBO.invalidate();
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public void makeHole(int pos, int numEffects)
78
    {
79
    System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) );
80
    mUBO.invalidate();
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  public void addOrdinal(int pos, int ordinal)
86
    {
87
    mArray[mNumUniforms*pos] = ordinal;
88
    mUBO.invalidate();
89
    }
90

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

    
93
  public void addAssociations(int pos, Effect effect)
94
    {
95
    effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3);
96
    mUBO.invalidate();
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public void markForDeletion()
102
    {
103
    mUBO.markForDeletion();
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void print(int num)
109
    {
110
    StringBuilder builder = new StringBuilder();
111

    
112
    builder.append(mUBO.getID());
113
    builder.append(':');
114

    
115
    for(int i=0; i<6; i++)
116
      {
117
      builder.append(' ');
118
      builder.append(mArray[4*i  ]);
119
      builder.append(' ');
120
      builder.append(mArray[4*i+1]);
121
      builder.append(' ');
122
      builder.append(mArray[4*i+2]);
123
      builder.append(',');
124
      }
125

    
126
    builder.append(' ');
127
    builder.append('(');
128
    builder.append(num);
129
    builder.append(')');
130

    
131
    String res = builder.toString();
132

    
133
    android.util.Log.e("ubp", res);
134
    }
135
  }
(4-4/4)