Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / UniformBlockCenter.java @ 8b36dabf

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
package org.distorted.library.mesh;
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 a2878a67 Leszek Koltunski
class UniformBlockCenter
31 97755c02 Leszek Koltunski
  {
32 a2878a67 Leszek Koltunski
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
33 97755c02 Leszek Koltunski
34 78ff6ea9 Leszek Koltunski
  private final InternalBuffer mUBO;
35
  private final float[] mCenter;
36 97755c02 Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 41b3ada0 Leszek Koltunski
39 a2878a67 Leszek Koltunski
  UniformBlockCenter()
40 97755c02 Leszek Koltunski
    {
41 a2878a67 Leszek Koltunski
    mCenter= new float[BLOCK_SIZE/4];
42 97755c02 Leszek Koltunski
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
43
    }
44
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47 a2878a67 Leszek Koltunski
  UniformBlockCenter(UniformBlockCenter original)
48 97755c02 Leszek Koltunski
    {
49 a2878a67 Leszek Koltunski
    int size = original.mCenter.length;
50
    mCenter= new float[size];
51
    System.arraycopy(original.mCenter, 0, mCenter, 0, size);
52 97755c02 Leszek Koltunski
53
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
54
    }
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 7a9edb92 Leszek Koltunski
  void setEffectCenterNow(int comp, float x, float y, float z)
59
    {
60
    mCenter[4*comp  ] = x;
61
    mCenter[4*comp+1] = y;
62
    mCenter[4*comp+2] = z;
63 97755c02 Leszek Koltunski
64 7a9edb92 Leszek Koltunski
    mUBO.invalidate();
65
    }
66 97755c02 Leszek Koltunski
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 7a9edb92 Leszek Koltunski
  int getIndex()
70
    {
71
    return mUBO.createImmediatelyFloat( BLOCK_SIZE, mCenter);
72
    }
73 97755c02 Leszek Koltunski
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76 7a9edb92 Leszek Koltunski
  void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
77
    {
78
    mCenter[4*compTo  ] = blockFrom.mCenter[4*compFrom  ];
79
    mCenter[4*compTo+1] = blockFrom.mCenter[4*compFrom+1];
80
    mCenter[4*compTo+2] = blockFrom.mCenter[4*compFrom+2];
81
    }
82
83 8b36dabf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85
  void markForDeletion()
86
    {
87
    mUBO.markForDeletion();
88
    }
89
90 7a9edb92 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
  float[] getBackingArray()
93
    {
94
    return mCenter;
95
    }
96 97755c02 Leszek Koltunski
  }