Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / UniformBlockAssociation.java @ a2878a67

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
  private InternalBuffer mUBO;
36
  private int[] mAssociations;
37
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 41b3ada0 Leszek Koltunski
   boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
67 97755c02 Leszek Koltunski
     {
68 41b3ada0 Leszek Koltunski
     return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
69 97755c02 Leszek Koltunski
     }
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 41b3ada0 Leszek Koltunski
   void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
74 97755c02 Leszek Koltunski
     {
75 41b3ada0 Leszek Koltunski
     mAssociations[4*comp  ] = andAssociation;
76
     mAssociations[4*comp+2] = equAssociation;
77 97755c02 Leszek Koltunski
78
     mUBO.invalidate();
79
     }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83
   int getIndex()
84
     {
85 a2878a67 Leszek Koltunski
     return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
86 97755c02 Leszek Koltunski
     }
87
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90 a2878a67 Leszek Koltunski
   void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
91 97755c02 Leszek Koltunski
     {
92 41b3ada0 Leszek Koltunski
     mAssociations[4*compTo  ] = assocFrom.mAssociations[4*compFrom  ];
93
     mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
94 97755c02 Leszek Koltunski
     }
95
  }