Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.library.uniformblock;
21

    
22
import android.opengl.GLES30;
23

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

    
26
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
/**
30
 * Not part of public API, do not document
31
 *
32
 * @y.exclude
33
 */
34
public class UniformBlockCenter
35
  {
36
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
37

    
38
  private final InternalBuffer mUBO;
39
  private final float[] mArray;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  public UniformBlockCenter()
44
    {
45
    mArray= new float[BLOCK_SIZE/4];
46
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
47
    }
48

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

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

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  public void setEffectCenterNow(int comp, float x, float y, float z)
62
    {
63
    mArray[4*comp  ] = x;
64
    mArray[4*comp+1] = y;
65
    mArray[4*comp+2] = z;
66

    
67
    mUBO.invalidate();
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  public int getIndex()
73
    {
74
    return mUBO.createImmediatelyFloat( BLOCK_SIZE, mArray);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
80
    {
81
    mArray[4*compTo  ] = blockFrom.mArray[4*compFrom  ];
82
    mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1];
83
    mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2];
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  public void markForDeletion()
89
    {
90
    mUBO.markForDeletion();
91
    }
92

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

    
95
  public float[] getBackingArray()
96
    {
97
    return mArray;
98
    }
99
  }
(2-2/4)