Project

General

Profile

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

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

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.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
class UniformBlockAssociation
31
  {
32
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
33
  private static final int DEFAULT_ASSOCIATION = 0xffffffff;
34

    
35
  private final InternalBuffer mUBO;
36
  private final int[] mAssociations;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  UniformBlockAssociation()
41
    {
42
    mAssociations= new int[BLOCK_SIZE/4];
43

    
44
    for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
45
      {
46
      mAssociations[4*i  ] = DEFAULT_ASSOCIATION;
47
      mAssociations[4*i+2] = i;
48
      }
49

    
50
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  UniformBlockAssociation(UniformBlockAssociation original)
56
    {
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
  boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
67
    {
68
    return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
74
    {
75
    mAssociations[4*comp  ] = andAssociation;
76
    mAssociations[4*comp+2] = equAssociation;
77

    
78
    mUBO.invalidate();
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  int getIndex()
84
    {
85
    return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  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
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  void markForDeletion()
99
    {
100
    mUBO.markForDeletion();
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  }
(11-11/12)