1515import org .joml .Matrix3fc ;
1616import org .joml .Matrix4fc ;
1717import org .lwjgl .BufferUtils ;
18- import org .lwjgl .opengl .GL13 ;
19- import org .lwjgl .opengl .GL20 ;
2018import org .slf4j .Logger ;
2119import org .slf4j .LoggerFactory ;
2220import org .terasology .engine .core .GameThread ;
3735import java .util .Collections ;
3836import java .util .EnumSet ;
3937import java .util .Map ;
40- import java .util .Set ;
4138
4239public class GLSLMaterial extends BaseMaterial {
4340
@@ -50,7 +47,6 @@ public class GLSLMaterial extends BaseMaterial {
5047 private TIntObjectMap <Texture > textureMap = new TIntObjectHashMap <>();
5148
5249 private GLSLShader shader ;
53- private boolean activeFeaturesChanged ;
5450 private TObjectIntMap <UniformId > uniformLocationMap = new TObjectIntHashMap <>();
5551
5652 private EnumSet <ShaderProgramFeature > activeFeatures = Sets .newEnumSet (Collections .emptyList (), ShaderProgramFeature .class );
@@ -83,14 +79,14 @@ public static GLSLMaterial create(ResourceUrn urn, LwjglGraphicsProcessing graph
8379
8480 @ Override
8581 public void enable () {
86- if (shaderManager .getActiveMaterial () != this || activeFeaturesChanged ) {
87- GL13 .glActiveTexture (GL13 .GL_TEXTURE0 );
88- GL20 .glUseProgram (getActiveShaderProgramId ());
89-
90- // Make sure the shader manager knows that this program is currently active
91- shaderManager .setActiveMaterial (this );
92- activeFeaturesChanged = false ;
93- }
82+ // if (shaderManager.getActiveMaterial() != this || activeFeaturesChanged) {
83+ // GL13.glActiveTexture(GL13.GL_TEXTURE0);
84+ // GL20.glUseProgram(getActiveShaderProgramId());
85+ //
86+ // // Make sure the shader manager knows that this program is currently active
87+ // shaderManager.setActiveMaterial(this);
88+ // activeFeaturesChanged = false;
89+ // }
9490 }
9591
9692 @ Override
@@ -123,25 +119,25 @@ public boolean isRenderable() {
123119
124120 @ Override
125121 public void recompile () {
126- TIntIntIterator it = disposalAction .shaderPrograms .iterator ();
127- while (it .hasNext ()) {
128- it .advance ();
129- GL20 .glDeleteProgram (it .value ());
130- }
131- disposalAction .shaderPrograms .clear ();
132- uniformLocationMap .clear ();
133- bindMap .clear ();
134-
135- disposalAction .shaderPrograms .put (0 , shader .linkShaderProgram (0 ));
136- for (Set <ShaderProgramFeature > permutation : Sets .powerSet (shader .getAvailableFeatures ())) {
137- int featureMask = ShaderProgramFeature .getBitset (permutation );
138- disposalAction .shaderPrograms .put (featureMask , shader .linkShaderProgram (featureMask ));
139- }
140-
141- //resolves #966
142- //Some of the uniforms are not updated constantly between frames
143- //this function will rebind any uniforms that are not bound
144- rebindVariables (materialData );
122+ // TIntIntIterator it = disposalAction.shaderPrograms.iterator();
123+ // while (it.hasNext()) {
124+ // it.advance();
125+ // GL20.glDeleteProgram(it.value());
126+ // }
127+ // disposalAction.shaderPrograms.clear();
128+ // uniformLocationMap.clear();
129+ // bindMap.clear();
130+ //
131+ // disposalAction.shaderPrograms.put(0, shader.linkShaderProgram(0));
132+ // for (Set<ShaderProgramFeature> permutation : Sets.powerSet(shader.getAvailableFeatures())) {
133+ // int featureMask = ShaderProgramFeature.getBitset(permutation);
134+ // disposalAction.shaderPrograms.put(featureMask, shader.linkShaderProgram(featureMask));
135+ // }
136+ //
137+ // //resolves #966
138+ // //Some of the uniforms are not updated constantly between frames
139+ // //this function will rebind any uniforms that are not bound
140+ // rebindVariables(materialData);
145141 }
146142
147143 @ Override
@@ -226,7 +222,7 @@ public void activateFeature(ShaderProgramFeature feature) {
226222 if (shader .getAvailableFeatures ().contains (feature )) {
227223 activeFeatures .add (feature );
228224 activeFeaturesMask = ShaderProgramFeature .getBitset (activeFeatures );
229- activeFeaturesChanged = true ;
225+ // activeFeaturesChanged = true;
230226 } else {
231227 logger .error ("Attempt to activate unsupported feature {} for material {} using shader {}" , feature , getUrn (), shader .getUrn ());
232228 }
@@ -236,7 +232,7 @@ public void activateFeature(ShaderProgramFeature feature) {
236232 public void deactivateFeature (ShaderProgramFeature feature ) {
237233 if (activeFeatures .remove (feature )) {
238234 activeFeaturesMask = ShaderProgramFeature .getBitset (activeFeatures );
239- activeFeaturesChanged = true ;
235+ // activeFeaturesChanged = true;
240236 }
241237 }
242238
@@ -275,25 +271,25 @@ public void setFloat(String desc, float f, boolean currentOnly) {
275271
276272 @ Override
277273 public void setFloat1 (String desc , FloatBuffer buffer , boolean currentOnly ) {
278- if (isDisposed ()) {
279- return ;
280- }
281- if (currentOnly ) {
282- enable ();
283- int id = getUniformLocation (getActiveShaderProgramId (), desc );
284- GL20 .glUniform1fv (id , buffer );
285- } else {
286- TIntIntIterator it = disposalAction .shaderPrograms .iterator ();
287- while (it .hasNext ()) {
288- it .advance ();
289-
290- GL20 .glUseProgram (it .value ());
291- int id = getUniformLocation (it .value (), desc );
292- GL20 .glUniform1fv (id , buffer );
293- }
294-
295- restoreStateAfterUniformsSet ();
296- }
274+ // if (isDisposed()) {
275+ // return;
276+ // }
277+ // if (currentOnly) {
278+ // enable();
279+ // int id = getUniformLocation(getActiveShaderProgramId(), desc);
280+ // GL20.glUniform1fv(id, buffer);
281+ // } else {
282+ // TIntIntIterator it = disposalAction.shaderPrograms.iterator();
283+ // while (it.hasNext()) {
284+ // it.advance();
285+ //
286+ // GL20.glUseProgram(it.value());
287+ // int id = getUniformLocation(it.value(), desc);
288+ // GL20.glUniform1fv(id, buffer);
289+ // }
290+ //
291+ // restoreStateAfterUniformsSet();
292+ // }
297293 }
298294
299295 @ Override
@@ -581,25 +577,12 @@ private int getActiveShaderProgramId() {
581577 return disposalAction .shaderPrograms .get (activeFeaturesMask );
582578 }
583579
584- private int getUniformLocation (int activeShaderProgramId , String desc ) {
585- UniformId id = new UniformId (activeShaderProgramId , desc );
586-
587- if (uniformLocationMap .containsKey (id )) {
588- return uniformLocationMap .get (id );
589- }
590-
591- int loc = GL20 .glGetUniformLocation (activeShaderProgramId , desc );
592- uniformLocationMap .put (id , loc );
593-
594- return loc ;
595- }
596-
597580 private void restoreStateAfterUniformsSet () {
598- if (shaderManager .getActiveMaterial () == this ) {
599- GL20 .glUseProgram (getActiveShaderProgramId ());
600- } else {
601- enable ();
602- }
581+ // if (shaderManager.getActiveMaterial() == this) {
582+ // GL20.glUseProgram(getActiveShaderProgramId());
583+ // } else {
584+ // enable();
585+ // }
603586 }
604587
605588 private static final class UniformId {
0 commit comments