Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / UniformBlockAssociation.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 UniformBlockAssociation
31 97755c02 Leszek Koltunski
  {
32 a2878a67 Leszek Koltunski
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
33 97755c02 Leszek Koltunski
  private static final int DEFAULT_ASSOCIATION = 0xffffffff;
34
35 78ff6ea9 Leszek Koltunski
  private final InternalBuffer mUBO;
36
  private final int[] mAssociations;
37 97755c02 Leszek Koltunski
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39 41b3ada0 Leszek Koltunski
40 a2878a67 Leszek Koltunski
  UniformBlockAssociation()
41 97755c02 Leszek Koltunski
    {
42 a2878a67 Leszek Koltunski
    mAssociations= new int[BLOCK_SIZE/4];
43 97755c02 Leszek Koltunski
44
    for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
45
      {
46 41b3ada0 Leszek Koltunski
      mAssociations[4*i  ] = DEFAULT_ASSOCIATION;
47
      mAssociations[4*i+2] = i;
48 97755c02 Leszek Koltunski
      }
49
50
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
51
    }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55 a2878a67 Leszek Koltunski
  UniformBlockAssociation(UniformBlockAssociation original)
56 97755c02 Leszek Koltunski
    {
57
    int size = original.mAssociations.length;
58
    mAssociations= new int[size];
59
    System.arraycopy(original.mAssociations, 0, mAssociations, 0, size);
60
61
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
62
    }
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66 728a7820 Leszek Koltunski
  boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
67
    {
68
    return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
69
    }
70 97755c02 Leszek Koltunski
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 728a7820 Leszek Koltunski
  void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
74
    {
75
    mAssociations[4*comp  ] = andAssociation;
76
    mAssociations[4*comp+2] = equAssociation;
77 97755c02 Leszek Koltunski
78 728a7820 Leszek Koltunski
    mUBO.invalidate();
79
    }
80 97755c02 Leszek Koltunski
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83 728a7820 Leszek Koltunski
  int getIndex()
84
    {
85
    return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
86
    }
87 97755c02 Leszek Koltunski
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90 728a7820 Leszek Koltunski
  void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
91
    {
92
    mAssociations[4*compTo  ] = assocFrom.mAssociations[4*compFrom  ];
93
    mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
94
    }
95
96 8b36dabf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
  void markForDeletion()
99
    {
100
    mUBO.markForDeletion();
101
    }
102
103 728a7820 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105
  void print()
106
    {
107
    StringBuilder builder = new StringBuilder();
108
109
    builder.append(mUBO.getID());
110
    builder.append(' ');
111
112
    for(int i=0; i<8; i++)
113
      {
114
      builder.append(mAssociations[4*i]);
115
      builder.append(' ');
116
      builder.append(mAssociations[4*i+2]);
117
      builder.append(' ');
118
      }
119
120
    String res = builder.toString();
121
122
    android.util.Log.e("uba", res);
123
    }
124 97755c02 Leszek Koltunski
  }