Add setUniform(color)

This commit is contained in:
James Seibel
2021-11-27 10:32:04 -06:00
parent e840a23d01
commit 31035ccb1e
2 changed files with 8 additions and 11 deletions
@@ -291,8 +291,7 @@ public class LodRenderer
int cameraUniform = shaderProgram.getUniformLocation("cameraPos");
shaderProgram.setUniform(cameraUniform, getTranslatedCameraPos());
int fogColorUniform = shaderProgram.getUniformLocation("fogColor");
Color fogColor = getFogColor();
GL20.glUniform4f(fogColorUniform, fogColor.getRed() / 256.0f, fogColor.getGreen() / 256.0f, fogColor.getBlue() / 256.0f, fogColor.getAlpha() / 256.0f);
shaderProgram.setUniform(fogColorUniform, getFogColor());
// region dependent uniforms
@@ -480,7 +479,6 @@ public class LodRenderer
return fogConfig;
}
/** */
private Color getFogColor()
{
Color fogColor;
@@ -19,6 +19,7 @@
package com.seibel.lod.core.render.shader;
import java.awt.Color;
import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL20;
@@ -156,39 +157,31 @@ public class LodShaderProgram
/** Sets the uniform variable for specified location. */
public void setUniform(int location, boolean value)
{
GL20.glUniform1i(location, value ? 1 : 0);
}
/** Sets the uniform variable for specified location. */
public void setUniform(int location, int value)
{
GL20.glUniform1i(location, value);
}
/** Sets the uniform variable for specified location. */
public void setUniform(int location, float value)
{
GL20.glUniform1f(location, value);
}
/** Sets the uniform variable for specified location. */
public void setUniform(int location, Vec3f value)
{
GL20.glUniform3f(location, value.x, value.y, value.z);
}
/** Sets the uniform variable for specified location. */
public void setUniform(int location, Vec3d value)
{
GL20.glUniform3f(location, (float) value.x, (float) value.y, (float) value.z);
}
/** Sets the uniform variable for specified location. */
public void setUniform(int location, Mat4f value)
{
try (MemoryStack stack = MemoryStack.stackPush())
@@ -199,6 +192,12 @@ public class LodShaderProgram
}
}
/** Converts the color's RGBA values into values between 0 and 1. */
public void setUniform(int location, Color value)
{
GL20.glUniform4f(location, value.getRed() / 256.0f, value.getGreen() / 256.0f, value.getBlue() / 256.0f, value.getAlpha() / 256.0f);
}
}