Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.InternalBuffer;
26
import org.distorted.library.mesh.MeshBase;
27

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

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

    
42
  public UniformBlockCenter()
43
    {
44
    mMax  = MeshBase.getMaxEffComponents();
45
    mArray= new float[4*mMax];
46
    mUBO  = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
47
    }
48

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

    
51
  public UniformBlockCenter(UniformBlockCenter original)
52
    {
53
    mMax = original.mMax;
54
    int size = original.mArray.length;
55
    mArray= new float[size];
56
    System.arraycopy(original.mArray, 0, mArray, 0, size);
57
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
58
    }
59

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

    
62
  public void setEffectCenterNow(int comp, float x, float y, float z)
63
    {
64
    if( comp>=0 )
65
      {
66
      mArray[4*comp  ] = x;
67
      mArray[4*comp+1] = y;
68
      mArray[4*comp+2] = z;
69
      }
70
    else
71
      {
72
      for(int i=0; i<mMax; i++)
73
        {
74
        mArray[4*i  ] = x;
75
        mArray[4*i+1] = y;
76
        mArray[4*i+2] = z;
77
        }
78
      }
79

    
80
    mUBO.invalidate();
81
    }
82

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

    
85
  public int getIndex()
86
    {
87
    return mUBO.createImmediatelyFloat( 16*mMax, mArray);
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
93
    {
94
    mArray[4*compTo  ] = blockFrom.mArray[4*compFrom  ];
95
    mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1];
96
    mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2];
97
    }
98

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

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

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

    
108
  public float[] getBackingArray()
109
    {
110
    return mArray;
111
    }
112
  }
(2-2/4)