Project

General

Profile

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

library / src / main / java / org / distorted / library / uniformblock / UniformBlockCenter.java @ 73bcf555

1 97755c02 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 de77a6c5 Leszek Koltunski
package org.distorted.library.uniformblock;
21 97755c02 Leszek Koltunski
22
import android.opengl.GLES30;
23
24
import org.distorted.library.main.InternalBuffer;
25 7958d843 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
26 97755c02 Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 de77a6c5 Leszek Koltunski
/**
29
 * Not part of public API, do not document
30
 *
31
 * @y.exclude
32
 */
33
public class UniformBlockCenter
34 97755c02 Leszek Koltunski
  {
35 78ff6ea9 Leszek Koltunski
  private final InternalBuffer mUBO;
36 de77a6c5 Leszek Koltunski
  private final float[] mArray;
37 7958d843 Leszek Koltunski
  private final int mMax;
38 97755c02 Leszek Koltunski
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40 41b3ada0 Leszek Koltunski
41 de77a6c5 Leszek Koltunski
  public UniformBlockCenter()
42 97755c02 Leszek Koltunski
    {
43 7958d843 Leszek Koltunski
    mMax  = MeshBase.getMaxEffComponents();
44
    mArray= new float[4*mMax];
45 73bcf555 Leszek Koltunski
    mUBO  = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
46 97755c02 Leszek Koltunski
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 de77a6c5 Leszek Koltunski
  public UniformBlockCenter(UniformBlockCenter original)
51 97755c02 Leszek Koltunski
    {
52 7958d843 Leszek Koltunski
    mMax = original.mMax;
53 de77a6c5 Leszek Koltunski
    int size = original.mArray.length;
54
    mArray= new float[size];
55
    System.arraycopy(original.mArray, 0, mArray, 0, size);
56 73bcf555 Leszek Koltunski
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
57 97755c02 Leszek Koltunski
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 de77a6c5 Leszek Koltunski
  public void setEffectCenterNow(int comp, float x, float y, float z)
62 7a9edb92 Leszek Koltunski
    {
63 06ed13b5 Leszek Koltunski
    if( comp>=0 )
64
      {
65
      mArray[4*comp  ] = x;
66
      mArray[4*comp+1] = y;
67
      mArray[4*comp+2] = z;
68
      }
69
    else
70
      {
71
      for(int i=0; i<mMax; i++)
72
        {
73
        mArray[4*i  ] = x;
74
        mArray[4*i+1] = y;
75
        mArray[4*i+2] = z;
76
        }
77
      }
78 97755c02 Leszek Koltunski
79 7a9edb92 Leszek Koltunski
    mUBO.invalidate();
80
    }
81 97755c02 Leszek Koltunski
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
84 de77a6c5 Leszek Koltunski
  public int getIndex()
85 7a9edb92 Leszek Koltunski
    {
86 7958d843 Leszek Koltunski
    return mUBO.createImmediatelyFloat( 16*mMax, mArray);
87 7a9edb92 Leszek Koltunski
    }
88 97755c02 Leszek Koltunski
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
91 de77a6c5 Leszek Koltunski
  public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
92 7a9edb92 Leszek Koltunski
    {
93 de77a6c5 Leszek Koltunski
    mArray[4*compTo  ] = blockFrom.mArray[4*compFrom  ];
94
    mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1];
95
    mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2];
96 7a9edb92 Leszek Koltunski
    }
97
98 8b36dabf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100 de77a6c5 Leszek Koltunski
  public void markForDeletion()
101 8b36dabf Leszek Koltunski
    {
102
    mUBO.markForDeletion();
103
    }
104
105 7a9edb92 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107 de77a6c5 Leszek Koltunski
  public float[] getBackingArray()
108 7a9edb92 Leszek Koltunski
    {
109 de77a6c5 Leszek Koltunski
    return mArray;
110 7a9edb92 Leszek Koltunski
    }
111 97755c02 Leszek Koltunski
  }