base mod created
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Framebuffer
|
||||
{
|
||||
public int framebufferTextureWidth;
|
||||
public int framebufferTextureHeight;
|
||||
public int framebufferWidth;
|
||||
public int framebufferHeight;
|
||||
public boolean useDepth;
|
||||
public int framebufferObject;
|
||||
public int framebufferTexture;
|
||||
public int depthBuffer;
|
||||
public float[] framebufferColor;
|
||||
public int framebufferFilter;
|
||||
|
||||
public Framebuffer(int width, int height, boolean useDepthIn)
|
||||
{
|
||||
this.useDepth = useDepthIn;
|
||||
this.framebufferObject = -1;
|
||||
this.framebufferTexture = -1;
|
||||
this.depthBuffer = -1;
|
||||
this.framebufferColor = new float[4];
|
||||
this.framebufferColor[0] = 1.0F;
|
||||
this.framebufferColor[1] = 1.0F;
|
||||
this.framebufferColor[2] = 1.0F;
|
||||
this.framebufferColor[3] = 0.0F;
|
||||
this.createBindFramebuffer(width, height);
|
||||
}
|
||||
|
||||
public void createBindFramebuffer(int width, int height)
|
||||
{
|
||||
if (!OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
this.framebufferWidth = width;
|
||||
this.framebufferHeight = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.enableDepth();
|
||||
|
||||
if (this.framebufferObject >= 0)
|
||||
{
|
||||
this.deleteFramebuffer();
|
||||
}
|
||||
|
||||
this.createFramebuffer(width, height);
|
||||
this.checkFramebufferComplete();
|
||||
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteFramebuffer()
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
this.unbindFramebufferTexture();
|
||||
this.unbindFramebuffer();
|
||||
|
||||
if (this.depthBuffer > -1)
|
||||
{
|
||||
OpenGlHelper.glDeleteRenderbuffers(this.depthBuffer);
|
||||
this.depthBuffer = -1;
|
||||
}
|
||||
|
||||
if (this.framebufferTexture > -1)
|
||||
{
|
||||
TextureUtil.deleteTexture(this.framebufferTexture);
|
||||
this.framebufferTexture = -1;
|
||||
}
|
||||
|
||||
if (this.framebufferObject > -1)
|
||||
{
|
||||
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, 0);
|
||||
OpenGlHelper.glDeleteFramebuffers(this.framebufferObject);
|
||||
this.framebufferObject = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createFramebuffer(int width, int height)
|
||||
{
|
||||
this.framebufferWidth = width;
|
||||
this.framebufferHeight = height;
|
||||
this.framebufferTextureWidth = width;
|
||||
this.framebufferTextureHeight = height;
|
||||
|
||||
if (!OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
this.framebufferClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.framebufferObject = OpenGlHelper.glGenFramebuffers();
|
||||
this.framebufferTexture = TextureUtil.glGenTextures();
|
||||
|
||||
if (this.useDepth)
|
||||
{
|
||||
this.depthBuffer = OpenGlHelper.glGenRenderbuffers();
|
||||
}
|
||||
|
||||
this.setFramebufferFilter(9728);
|
||||
GlStateManager.bindTexture(this.framebufferTexture);
|
||||
GlStateManager.glTexImage2D(3553, 0, 32856, this.framebufferTextureWidth, this.framebufferTextureHeight, 0, 6408, 5121, (IntBuffer)null);
|
||||
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, this.framebufferObject);
|
||||
OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, this.framebufferTexture, 0);
|
||||
|
||||
if (this.useDepth)
|
||||
{
|
||||
OpenGlHelper.glBindRenderbuffer(OpenGlHelper.GL_RENDERBUFFER, this.depthBuffer);
|
||||
if (!this.stencilEnabled)
|
||||
{
|
||||
OpenGlHelper.glRenderbufferStorage(OpenGlHelper.GL_RENDERBUFFER, 33190, this.framebufferTextureWidth, this.framebufferTextureHeight);
|
||||
OpenGlHelper.glFramebufferRenderbuffer(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_DEPTH_ATTACHMENT, OpenGlHelper.GL_RENDERBUFFER, this.depthBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenGlHelper.glRenderbufferStorage(OpenGlHelper.GL_RENDERBUFFER, org.lwjgl.opengl.EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, this.framebufferTextureWidth, this.framebufferTextureHeight);
|
||||
OpenGlHelper.glFramebufferRenderbuffer(OpenGlHelper.GL_FRAMEBUFFER, org.lwjgl.opengl.EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, OpenGlHelper.GL_RENDERBUFFER, this.depthBuffer);
|
||||
OpenGlHelper.glFramebufferRenderbuffer(OpenGlHelper.GL_FRAMEBUFFER, org.lwjgl.opengl.EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, OpenGlHelper.GL_RENDERBUFFER, this.depthBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
this.framebufferClear();
|
||||
this.unbindFramebufferTexture();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFramebufferFilter(int framebufferFilterIn)
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
this.framebufferFilter = framebufferFilterIn;
|
||||
GlStateManager.bindTexture(this.framebufferTexture);
|
||||
GlStateManager.glTexParameteri(3553, 10241, framebufferFilterIn);
|
||||
GlStateManager.glTexParameteri(3553, 10240, framebufferFilterIn);
|
||||
GlStateManager.glTexParameteri(3553, 10242, 10496);
|
||||
GlStateManager.glTexParameteri(3553, 10243, 10496);
|
||||
GlStateManager.bindTexture(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkFramebufferComplete()
|
||||
{
|
||||
int i = OpenGlHelper.glCheckFramebufferStatus(OpenGlHelper.GL_FRAMEBUFFER);
|
||||
|
||||
if (i != OpenGlHelper.GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
if (i == OpenGlHelper.GL_FB_INCOMPLETE_ATTACHMENT)
|
||||
{
|
||||
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
||||
}
|
||||
else if (i == OpenGlHelper.GL_FB_INCOMPLETE_MISS_ATTACH)
|
||||
{
|
||||
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
|
||||
}
|
||||
else if (i == OpenGlHelper.GL_FB_INCOMPLETE_DRAW_BUFFER)
|
||||
{
|
||||
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
|
||||
}
|
||||
else if (i == OpenGlHelper.GL_FB_INCOMPLETE_READ_BUFFER)
|
||||
{
|
||||
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException("glCheckFramebufferStatus returned unknown status:" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void bindFramebufferTexture()
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
GlStateManager.bindTexture(this.framebufferTexture);
|
||||
}
|
||||
}
|
||||
|
||||
public void unbindFramebufferTexture()
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
GlStateManager.bindTexture(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void bindFramebuffer(boolean p_147610_1_)
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, this.framebufferObject);
|
||||
|
||||
if (p_147610_1_)
|
||||
{
|
||||
GlStateManager.viewport(0, 0, this.framebufferWidth, this.framebufferHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unbindFramebuffer()
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFramebufferColor(float red, float green, float blue, float alpha)
|
||||
{
|
||||
this.framebufferColor[0] = red;
|
||||
this.framebufferColor[1] = green;
|
||||
this.framebufferColor[2] = blue;
|
||||
this.framebufferColor[3] = alpha;
|
||||
}
|
||||
|
||||
public void framebufferRender(int width, int height)
|
||||
{
|
||||
this.framebufferRenderExt(width, height, true);
|
||||
}
|
||||
|
||||
public void framebufferRenderExt(int width, int height, boolean p_178038_3_)
|
||||
{
|
||||
if (OpenGlHelper.isFramebufferEnabled())
|
||||
{
|
||||
GlStateManager.colorMask(true, true, true, false);
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.depthMask(false);
|
||||
GlStateManager.matrixMode(5889);
|
||||
GlStateManager.loadIdentity();
|
||||
GlStateManager.ortho(0.0D, (double)width, (double)height, 0.0D, 1000.0D, 3000.0D);
|
||||
GlStateManager.matrixMode(5888);
|
||||
GlStateManager.loadIdentity();
|
||||
GlStateManager.translate(0.0F, 0.0F, -2000.0F);
|
||||
GlStateManager.viewport(0, 0, width, height);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableAlpha();
|
||||
|
||||
if (p_178038_3_)
|
||||
{
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableColorMaterial();
|
||||
}
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.bindFramebufferTexture();
|
||||
float f = (float)width;
|
||||
float f1 = (float)height;
|
||||
float f2 = (float)this.framebufferWidth / (float)this.framebufferTextureWidth;
|
||||
float f3 = (float)this.framebufferHeight / (float)this.framebufferTextureHeight;
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuffer();
|
||||
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
bufferbuilder.pos(0.0D, (double)f1, 0.0D).tex(0.0D, 0.0D).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos((double)f, (double)f1, 0.0D).tex((double)f2, 0.0D).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos((double)f, 0.0D, 0.0D).tex((double)f2, (double)f3).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos(0.0D, 0.0D, 0.0D).tex(0.0D, (double)f3).color(255, 255, 255, 255).endVertex();
|
||||
tessellator.draw();
|
||||
this.unbindFramebufferTexture();
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void framebufferClear()
|
||||
{
|
||||
this.bindFramebuffer(true);
|
||||
GlStateManager.clearColor(this.framebufferColor[0], this.framebufferColor[1], this.framebufferColor[2], this.framebufferColor[3]);
|
||||
int i = 16384;
|
||||
|
||||
if (this.useDepth)
|
||||
{
|
||||
GlStateManager.clearDepth(1.0D);
|
||||
i |= 256;
|
||||
}
|
||||
|
||||
GlStateManager.clear(i);
|
||||
this.unbindFramebuffer();
|
||||
}
|
||||
|
||||
/*================================ FORGE START ================================================*/
|
||||
private boolean stencilEnabled = false;
|
||||
/**
|
||||
* Attempts to enabled 8 bits of stencil buffer on this FrameBuffer.
|
||||
* Modders must call this directly to set things up.
|
||||
* This is to prevent the default cause where graphics cards do not support stencil bits.
|
||||
* Modders should check the below 'isStencilEnabled' to check if another modder has already enabled them.
|
||||
*
|
||||
* Note:
|
||||
* As of now the only thing that is checked is if FBOs are supported entirely, in the future
|
||||
* we may expand to check for errors.
|
||||
*
|
||||
* @return True if the FBO was re-initialized with stencil bits.
|
||||
*/
|
||||
public boolean enableStencil()
|
||||
{
|
||||
if (!OpenGlHelper.isFramebufferEnabled()) return false;
|
||||
stencilEnabled = true;
|
||||
this.createBindFramebuffer(framebufferWidth, framebufferHeight);
|
||||
return true; //TODO: Find a way to detect if this failed?
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns wither or not this FBO has been successfully initialized with stencil bits.
|
||||
* If not, and a modder wishes it to be, they must call enableStencil.
|
||||
*/
|
||||
public boolean isStencilEnabled()
|
||||
{
|
||||
return this.stencilEnabled;
|
||||
}
|
||||
/*================================ FORGE END ================================================*/
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.util.JsonException;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Shader
|
||||
{
|
||||
private final ShaderManager manager;
|
||||
public final Framebuffer framebufferIn;
|
||||
public final Framebuffer framebufferOut;
|
||||
private final List<Object> listAuxFramebuffers = Lists.<Object>newArrayList();
|
||||
private final List<String> listAuxNames = Lists.<String>newArrayList();
|
||||
private final List<Integer> listAuxWidths = Lists.<Integer>newArrayList();
|
||||
private final List<Integer> listAuxHeights = Lists.<Integer>newArrayList();
|
||||
private Matrix4f projectionMatrix;
|
||||
|
||||
public Shader(IResourceManager resourceManager, String programName, Framebuffer framebufferInIn, Framebuffer framebufferOutIn) throws JsonException, IOException
|
||||
{
|
||||
this.manager = new ShaderManager(resourceManager, programName);
|
||||
this.framebufferIn = framebufferInIn;
|
||||
this.framebufferOut = framebufferOutIn;
|
||||
}
|
||||
|
||||
public void deleteShader()
|
||||
{
|
||||
this.manager.deleteShader();
|
||||
}
|
||||
|
||||
public void addAuxFramebuffer(String auxName, Object auxFramebufferIn, int width, int height)
|
||||
{
|
||||
this.listAuxNames.add(this.listAuxNames.size(), auxName);
|
||||
this.listAuxFramebuffers.add(this.listAuxFramebuffers.size(), auxFramebufferIn);
|
||||
this.listAuxWidths.add(this.listAuxWidths.size(), Integer.valueOf(width));
|
||||
this.listAuxHeights.add(this.listAuxHeights.size(), Integer.valueOf(height));
|
||||
}
|
||||
|
||||
private void preRender()
|
||||
{
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.disableFog();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableColorMaterial();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.bindTexture(0);
|
||||
}
|
||||
|
||||
public void setProjectionMatrix(Matrix4f projectionMatrixIn)
|
||||
{
|
||||
this.projectionMatrix = projectionMatrixIn;
|
||||
}
|
||||
|
||||
public void render(float partialTicks)
|
||||
{
|
||||
this.preRender();
|
||||
this.framebufferIn.unbindFramebuffer();
|
||||
float f = (float)this.framebufferOut.framebufferTextureWidth;
|
||||
float f1 = (float)this.framebufferOut.framebufferTextureHeight;
|
||||
GlStateManager.viewport(0, 0, (int)f, (int)f1);
|
||||
this.manager.addSamplerTexture("DiffuseSampler", this.framebufferIn);
|
||||
|
||||
for (int i = 0; i < this.listAuxFramebuffers.size(); ++i)
|
||||
{
|
||||
this.manager.addSamplerTexture(this.listAuxNames.get(i), this.listAuxFramebuffers.get(i));
|
||||
this.manager.getShaderUniformOrDefault("AuxSize" + i).set((float)((Integer)this.listAuxWidths.get(i)).intValue(), (float)((Integer)this.listAuxHeights.get(i)).intValue());
|
||||
}
|
||||
|
||||
this.manager.getShaderUniformOrDefault("ProjMat").set(this.projectionMatrix);
|
||||
this.manager.getShaderUniformOrDefault("InSize").set((float)this.framebufferIn.framebufferTextureWidth, (float)this.framebufferIn.framebufferTextureHeight);
|
||||
this.manager.getShaderUniformOrDefault("OutSize").set(f, f1);
|
||||
this.manager.getShaderUniformOrDefault("Time").set(partialTicks);
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
this.manager.getShaderUniformOrDefault("ScreenSize").set((float)minecraft.displayWidth, (float)minecraft.displayHeight);
|
||||
this.manager.useShader();
|
||||
this.framebufferOut.framebufferClear();
|
||||
this.framebufferOut.bindFramebuffer(false);
|
||||
GlStateManager.depthMask(false);
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuffer();
|
||||
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
bufferbuilder.pos(0.0D, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos((double)f, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos((double)f, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex();
|
||||
bufferbuilder.pos(0.0D, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex();
|
||||
tessellator.draw();
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
this.manager.endShader();
|
||||
this.framebufferOut.unbindFramebuffer();
|
||||
this.framebufferIn.unbindFramebufferTexture();
|
||||
|
||||
for (Object object : this.listAuxFramebuffers)
|
||||
{
|
||||
if (object instanceof Framebuffer)
|
||||
{
|
||||
((Framebuffer)object).unbindFramebufferTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ShaderManager getShaderManager()
|
||||
{
|
||||
return this.manager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderDefault extends ShaderUniform
|
||||
{
|
||||
public ShaderDefault()
|
||||
{
|
||||
super("dummy", 4, 1, (ShaderManager)null);
|
||||
}
|
||||
|
||||
public void set(float p_148090_1_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(float p_148087_1_, float p_148087_2_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(float p_148095_1_, float p_148095_2_, float p_148095_3_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(float p_148081_1_, float p_148081_2_, float p_148081_3_, float p_148081_4_)
|
||||
{
|
||||
}
|
||||
|
||||
public void setSafe(float p_148092_1_, float p_148092_2_, float p_148092_3_, float p_148092_4_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(int p_148083_1_, int p_148083_2_, int p_148083_3_, int p_148083_4_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(float[] p_148097_1_)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
|
||||
{
|
||||
}
|
||||
|
||||
public void set(Matrix4f matrix)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,418 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.Closeable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.util.JsonException;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderGroup
|
||||
{
|
||||
private final Framebuffer mainFramebuffer;
|
||||
private final IResourceManager resourceManager;
|
||||
private final String shaderGroupName;
|
||||
private final List<Shader> listShaders = Lists.<Shader>newArrayList();
|
||||
private final Map<String, Framebuffer> mapFramebuffers = Maps.<String, Framebuffer>newHashMap();
|
||||
private final List<Framebuffer> listFramebuffers = Lists.<Framebuffer>newArrayList();
|
||||
private Matrix4f projectionMatrix;
|
||||
private int mainFramebufferWidth;
|
||||
private int mainFramebufferHeight;
|
||||
private float time;
|
||||
private float lastStamp;
|
||||
|
||||
public ShaderGroup(TextureManager p_i1050_1_, IResourceManager resourceManagerIn, Framebuffer mainFramebufferIn, ResourceLocation p_i1050_4_) throws JsonException, IOException, JsonSyntaxException
|
||||
{
|
||||
this.resourceManager = resourceManagerIn;
|
||||
this.mainFramebuffer = mainFramebufferIn;
|
||||
this.time = 0.0F;
|
||||
this.lastStamp = 0.0F;
|
||||
this.mainFramebufferWidth = mainFramebufferIn.framebufferWidth;
|
||||
this.mainFramebufferHeight = mainFramebufferIn.framebufferHeight;
|
||||
this.shaderGroupName = p_i1050_4_.toString();
|
||||
this.resetProjectionMatrix();
|
||||
this.parseGroup(p_i1050_1_, p_i1050_4_);
|
||||
}
|
||||
|
||||
public void parseGroup(TextureManager p_152765_1_, ResourceLocation p_152765_2_) throws JsonException, IOException, JsonSyntaxException
|
||||
{
|
||||
JsonParser jsonparser = new JsonParser();
|
||||
IResource iresource = null;
|
||||
|
||||
try
|
||||
{
|
||||
iresource = this.resourceManager.getResource(p_152765_2_);
|
||||
JsonObject jsonobject = jsonparser.parse(IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
|
||||
if (JsonUtils.isJsonArray(jsonobject, "targets"))
|
||||
{
|
||||
JsonArray jsonarray = jsonobject.getAsJsonArray("targets");
|
||||
int i = 0;
|
||||
|
||||
for (JsonElement jsonelement : jsonarray)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.initTarget(jsonelement);
|
||||
}
|
||||
catch (Exception exception1)
|
||||
{
|
||||
JsonException jsonexception1 = JsonException.forException(exception1);
|
||||
jsonexception1.prependJsonKey("targets[" + i + "]");
|
||||
throw jsonexception1;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if (JsonUtils.isJsonArray(jsonobject, "passes"))
|
||||
{
|
||||
JsonArray jsonarray1 = jsonobject.getAsJsonArray("passes");
|
||||
int j = 0;
|
||||
|
||||
for (JsonElement jsonelement1 : jsonarray1)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.parsePass(p_152765_1_, jsonelement1);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
JsonException jsonexception2 = JsonException.forException(exception);
|
||||
jsonexception2.prependJsonKey("passes[" + j + "]");
|
||||
throw jsonexception2;
|
||||
}
|
||||
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception2)
|
||||
{
|
||||
JsonException jsonexception = JsonException.forException(exception2);
|
||||
jsonexception.setFilenameAndFlush(p_152765_2_.getResourcePath());
|
||||
throw jsonexception;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
}
|
||||
}
|
||||
|
||||
private void initTarget(JsonElement p_148027_1_) throws JsonException
|
||||
{
|
||||
if (JsonUtils.isString(p_148027_1_))
|
||||
{
|
||||
this.addFramebuffer(p_148027_1_.getAsString(), this.mainFramebufferWidth, this.mainFramebufferHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(p_148027_1_, "target");
|
||||
String s = JsonUtils.getString(jsonobject, "name");
|
||||
int i = JsonUtils.getInt(jsonobject, "width", this.mainFramebufferWidth);
|
||||
int j = JsonUtils.getInt(jsonobject, "height", this.mainFramebufferHeight);
|
||||
|
||||
if (this.mapFramebuffers.containsKey(s))
|
||||
{
|
||||
throw new JsonException(s + " is already defined");
|
||||
}
|
||||
|
||||
this.addFramebuffer(s, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
private void parsePass(TextureManager p_152764_1_, JsonElement json) throws JsonException, IOException
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(json, "pass");
|
||||
String s = JsonUtils.getString(jsonobject, "name");
|
||||
String s1 = JsonUtils.getString(jsonobject, "intarget");
|
||||
String s2 = JsonUtils.getString(jsonobject, "outtarget");
|
||||
Framebuffer framebuffer = this.getFramebuffer(s1);
|
||||
Framebuffer framebuffer1 = this.getFramebuffer(s2);
|
||||
|
||||
if (framebuffer == null)
|
||||
{
|
||||
throw new JsonException("Input target '" + s1 + "' does not exist");
|
||||
}
|
||||
else if (framebuffer1 == null)
|
||||
{
|
||||
throw new JsonException("Output target '" + s2 + "' does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
Shader shader = this.addShader(s, framebuffer, framebuffer1);
|
||||
JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "auxtargets", (JsonArray)null);
|
||||
|
||||
if (jsonarray != null)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (JsonElement jsonelement : jsonarray)
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonelement, "auxtarget");
|
||||
String s4 = JsonUtils.getString(jsonobject1, "name");
|
||||
String s3 = JsonUtils.getString(jsonobject1, "id");
|
||||
Framebuffer framebuffer2 = this.getFramebuffer(s3);
|
||||
|
||||
if (framebuffer2 == null)
|
||||
{
|
||||
String[] rl = ResourceLocation.splitObjectName(s3);
|
||||
ResourceLocation resourcelocation = new ResourceLocation(rl[0], "textures/effect/" + rl[1] + ".png");
|
||||
IResource iresource = null;
|
||||
|
||||
try
|
||||
{
|
||||
iresource = this.resourceManager.getResource(resourcelocation);
|
||||
}
|
||||
catch (FileNotFoundException var29)
|
||||
{
|
||||
throw new JsonException("Render target or texture '" + s3 + "' does not exist");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
}
|
||||
|
||||
p_152764_1_.bindTexture(resourcelocation);
|
||||
ITextureObject lvt_20_2_ = p_152764_1_.getTexture(resourcelocation);
|
||||
int lvt_21_1_ = JsonUtils.getInt(jsonobject1, "width");
|
||||
int lvt_22_1_ = JsonUtils.getInt(jsonobject1, "height");
|
||||
boolean lvt_23_1_ = JsonUtils.getBoolean(jsonobject1, "bilinear");
|
||||
|
||||
if (lvt_23_1_)
|
||||
{
|
||||
GlStateManager.glTexParameteri(3553, 10241, 9729);
|
||||
GlStateManager.glTexParameteri(3553, 10240, 9729);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.glTexParameteri(3553, 10241, 9728);
|
||||
GlStateManager.glTexParameteri(3553, 10240, 9728);
|
||||
}
|
||||
|
||||
shader.addAuxFramebuffer(s4, Integer.valueOf(lvt_20_2_.getGlTextureId()), lvt_21_1_, lvt_22_1_);
|
||||
}
|
||||
else
|
||||
{
|
||||
shader.addAuxFramebuffer(s4, framebuffer2, framebuffer2.framebufferTextureWidth, framebuffer2.framebufferTextureHeight);
|
||||
}
|
||||
}
|
||||
catch (Exception exception1)
|
||||
{
|
||||
JsonException jsonexception = JsonException.forException(exception1);
|
||||
jsonexception.prependJsonKey("auxtargets[" + i + "]");
|
||||
throw jsonexception;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
JsonArray jsonarray1 = JsonUtils.getJsonArray(jsonobject, "uniforms", (JsonArray)null);
|
||||
|
||||
if (jsonarray1 != null)
|
||||
{
|
||||
int l = 0;
|
||||
|
||||
for (JsonElement jsonelement1 : jsonarray1)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.initUniform(jsonelement1);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
JsonException jsonexception1 = JsonException.forException(exception);
|
||||
jsonexception1.prependJsonKey("uniforms[" + l + "]");
|
||||
throw jsonexception1;
|
||||
}
|
||||
|
||||
++l;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initUniform(JsonElement json) throws JsonException
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(json, "uniform");
|
||||
String s = JsonUtils.getString(jsonobject, "name");
|
||||
ShaderUniform shaderuniform = ((Shader)this.listShaders.get(this.listShaders.size() - 1)).getShaderManager().getShaderUniform(s);
|
||||
|
||||
if (shaderuniform == null)
|
||||
{
|
||||
throw new JsonException("Uniform '" + s + "' does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] afloat = new float[4];
|
||||
int i = 0;
|
||||
|
||||
for (JsonElement jsonelement : JsonUtils.getJsonArray(jsonobject, "values"))
|
||||
{
|
||||
try
|
||||
{
|
||||
afloat[i] = JsonUtils.getFloat(jsonelement, "value");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
JsonException jsonexception = JsonException.forException(exception);
|
||||
jsonexception.prependJsonKey("values[" + i + "]");
|
||||
throw jsonexception;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
break;
|
||||
case 1:
|
||||
shaderuniform.set(afloat[0]);
|
||||
break;
|
||||
case 2:
|
||||
shaderuniform.set(afloat[0], afloat[1]);
|
||||
break;
|
||||
case 3:
|
||||
shaderuniform.set(afloat[0], afloat[1], afloat[2]);
|
||||
break;
|
||||
case 4:
|
||||
shaderuniform.set(afloat[0], afloat[1], afloat[2], afloat[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Framebuffer getFramebufferRaw(String attributeName)
|
||||
{
|
||||
return this.mapFramebuffers.get(attributeName);
|
||||
}
|
||||
|
||||
public void addFramebuffer(String name, int width, int height)
|
||||
{
|
||||
Framebuffer framebuffer = new Framebuffer(width, height, true);
|
||||
framebuffer.setFramebufferColor(0.0F, 0.0F, 0.0F, 0.0F);
|
||||
this.mapFramebuffers.put(name, framebuffer);
|
||||
|
||||
if (width == this.mainFramebufferWidth && height == this.mainFramebufferHeight)
|
||||
{
|
||||
this.listFramebuffers.add(framebuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteShaderGroup()
|
||||
{
|
||||
for (Framebuffer framebuffer : this.mapFramebuffers.values())
|
||||
{
|
||||
framebuffer.deleteFramebuffer();
|
||||
}
|
||||
|
||||
for (Shader shader : this.listShaders)
|
||||
{
|
||||
shader.deleteShader();
|
||||
}
|
||||
|
||||
this.listShaders.clear();
|
||||
}
|
||||
|
||||
public Shader addShader(String programName, Framebuffer framebufferIn, Framebuffer framebufferOut) throws JsonException, IOException
|
||||
{
|
||||
Shader shader = new Shader(this.resourceManager, programName, framebufferIn, framebufferOut);
|
||||
this.listShaders.add(this.listShaders.size(), shader);
|
||||
return shader;
|
||||
}
|
||||
|
||||
private void resetProjectionMatrix()
|
||||
{
|
||||
this.projectionMatrix = new Matrix4f();
|
||||
this.projectionMatrix.setIdentity();
|
||||
this.projectionMatrix.m00 = 2.0F / (float)this.mainFramebuffer.framebufferTextureWidth;
|
||||
this.projectionMatrix.m11 = 2.0F / (float)(-this.mainFramebuffer.framebufferTextureHeight);
|
||||
this.projectionMatrix.m22 = -0.0020001999F;
|
||||
this.projectionMatrix.m33 = 1.0F;
|
||||
this.projectionMatrix.m03 = -1.0F;
|
||||
this.projectionMatrix.m13 = 1.0F;
|
||||
this.projectionMatrix.m23 = -1.0001999F;
|
||||
}
|
||||
|
||||
public void createBindFramebuffers(int width, int height)
|
||||
{
|
||||
this.mainFramebufferWidth = this.mainFramebuffer.framebufferTextureWidth;
|
||||
this.mainFramebufferHeight = this.mainFramebuffer.framebufferTextureHeight;
|
||||
this.resetProjectionMatrix();
|
||||
|
||||
for (Shader shader : this.listShaders)
|
||||
{
|
||||
shader.setProjectionMatrix(this.projectionMatrix);
|
||||
}
|
||||
|
||||
for (Framebuffer framebuffer : this.listFramebuffers)
|
||||
{
|
||||
framebuffer.createBindFramebuffer(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public void render(float partialTicks)
|
||||
{
|
||||
if (partialTicks < this.lastStamp)
|
||||
{
|
||||
this.time += 1.0F - this.lastStamp;
|
||||
this.time += partialTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.time += partialTicks - this.lastStamp;
|
||||
}
|
||||
|
||||
for (this.lastStamp = partialTicks; this.time > 20.0F; this.time -= 20.0F)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
for (Shader shader : this.listShaders)
|
||||
{
|
||||
shader.render(this.time / 20.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public final String getShaderGroupName()
|
||||
{
|
||||
return this.shaderGroupName;
|
||||
}
|
||||
|
||||
private Framebuffer getFramebuffer(String p_148017_1_)
|
||||
{
|
||||
if (p_148017_1_ == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return p_148017_1_.equals("minecraft:main") ? this.mainFramebuffer : (Framebuffer)this.mapFramebuffers.get(p_148017_1_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import java.io.IOException;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.util.JsonException;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderLinkHelper
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static ShaderLinkHelper staticShaderLinkHelper;
|
||||
|
||||
public static void setNewStaticShaderLinkHelper()
|
||||
{
|
||||
staticShaderLinkHelper = new ShaderLinkHelper();
|
||||
}
|
||||
|
||||
public static ShaderLinkHelper getStaticShaderLinkHelper()
|
||||
{
|
||||
return staticShaderLinkHelper;
|
||||
}
|
||||
|
||||
public void deleteShader(ShaderManager manager)
|
||||
{
|
||||
manager.getFragmentShaderLoader().deleteShader(manager);
|
||||
manager.getVertexShaderLoader().deleteShader(manager);
|
||||
OpenGlHelper.glDeleteProgram(manager.getProgram());
|
||||
}
|
||||
|
||||
public int createProgram() throws JsonException
|
||||
{
|
||||
int i = OpenGlHelper.glCreateProgram();
|
||||
|
||||
if (i <= 0)
|
||||
{
|
||||
throw new JsonException("Could not create shader program (returned program ID " + i + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public void linkProgram(ShaderManager manager) throws IOException
|
||||
{
|
||||
manager.getFragmentShaderLoader().attachShader(manager);
|
||||
manager.getVertexShaderLoader().attachShader(manager);
|
||||
OpenGlHelper.glLinkProgram(manager.getProgram());
|
||||
int i = OpenGlHelper.glGetProgrami(manager.getProgram(), OpenGlHelper.GL_LINK_STATUS);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
LOGGER.warn("Error encountered when linking program containing VS {} and FS {}. Log output:", manager.getVertexShaderLoader().getShaderFilename(), manager.getFragmentShaderLoader().getShaderFilename());
|
||||
LOGGER.warn(OpenGlHelper.glGetProgramInfoLog(manager.getProgram(), 32768));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.util.JsonException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderLoader
|
||||
{
|
||||
private final ShaderLoader.ShaderType shaderType;
|
||||
private final String shaderFilename;
|
||||
private final int shader;
|
||||
private int shaderAttachCount;
|
||||
|
||||
private ShaderLoader(ShaderLoader.ShaderType type, int shaderId, String filename)
|
||||
{
|
||||
this.shaderType = type;
|
||||
this.shader = shaderId;
|
||||
this.shaderFilename = filename;
|
||||
}
|
||||
|
||||
public void attachShader(ShaderManager manager)
|
||||
{
|
||||
++this.shaderAttachCount;
|
||||
OpenGlHelper.glAttachShader(manager.getProgram(), this.shader);
|
||||
}
|
||||
|
||||
public void deleteShader(ShaderManager manager)
|
||||
{
|
||||
--this.shaderAttachCount;
|
||||
|
||||
if (this.shaderAttachCount <= 0)
|
||||
{
|
||||
OpenGlHelper.glDeleteShader(this.shader);
|
||||
this.shaderType.getLoadedShaders().remove(this.shaderFilename);
|
||||
}
|
||||
}
|
||||
|
||||
public String getShaderFilename()
|
||||
{
|
||||
return this.shaderFilename;
|
||||
}
|
||||
|
||||
public static ShaderLoader loadShader(IResourceManager resourceManager, ShaderLoader.ShaderType type, String filename) throws IOException
|
||||
{
|
||||
ShaderLoader shaderloader = (ShaderLoader)type.getLoadedShaders().get(filename);
|
||||
|
||||
if (shaderloader == null)
|
||||
{
|
||||
String[] rl = ResourceLocation.splitObjectName(filename);
|
||||
ResourceLocation resourcelocation = new ResourceLocation(rl[0], "shaders/program/" + rl[1] + type.getShaderExtension());
|
||||
IResource iresource = resourceManager.getResource(resourcelocation);
|
||||
|
||||
try
|
||||
{
|
||||
byte[] abyte = IOUtils.toByteArray(new BufferedInputStream(iresource.getInputStream()));
|
||||
ByteBuffer bytebuffer = BufferUtils.createByteBuffer(abyte.length);
|
||||
bytebuffer.put(abyte);
|
||||
bytebuffer.position(0);
|
||||
int i = OpenGlHelper.glCreateShader(type.getShaderMode());
|
||||
OpenGlHelper.glShaderSource(i, bytebuffer);
|
||||
OpenGlHelper.glCompileShader(i);
|
||||
|
||||
if (OpenGlHelper.glGetShaderi(i, OpenGlHelper.GL_COMPILE_STATUS) == 0)
|
||||
{
|
||||
String s = StringUtils.trim(OpenGlHelper.glGetShaderInfoLog(i, 32768));
|
||||
JsonException jsonexception = new JsonException("Couldn't compile " + type.getShaderName() + " program: " + s);
|
||||
jsonexception.setFilenameAndFlush(resourcelocation.getResourcePath());
|
||||
throw jsonexception;
|
||||
}
|
||||
|
||||
shaderloader = new ShaderLoader(type, i, filename);
|
||||
type.getLoadedShaders().put(filename, shaderloader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
}
|
||||
}
|
||||
|
||||
return shaderloader;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum ShaderType
|
||||
{
|
||||
VERTEX("vertex", ".vsh", OpenGlHelper.GL_VERTEX_SHADER),
|
||||
FRAGMENT("fragment", ".fsh", OpenGlHelper.GL_FRAGMENT_SHADER);
|
||||
|
||||
private final String shaderName;
|
||||
private final String shaderExtension;
|
||||
private final int shaderMode;
|
||||
private final Map<String, ShaderLoader> loadedShaders = Maps.<String, ShaderLoader>newHashMap();
|
||||
|
||||
private ShaderType(String shaderNameIn, String shaderExtensionIn, int shaderModeIn)
|
||||
{
|
||||
this.shaderName = shaderNameIn;
|
||||
this.shaderExtension = shaderExtensionIn;
|
||||
this.shaderMode = shaderModeIn;
|
||||
}
|
||||
|
||||
public String getShaderName()
|
||||
{
|
||||
return this.shaderName;
|
||||
}
|
||||
|
||||
private String getShaderExtension()
|
||||
{
|
||||
return this.shaderExtension;
|
||||
}
|
||||
|
||||
private int getShaderMode()
|
||||
{
|
||||
return this.shaderMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a map of loaded shaders for the ShaderType.
|
||||
*/
|
||||
private Map<String, ShaderLoader> getLoadedShaders()
|
||||
{
|
||||
return this.loadedShaders;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.util.JsonBlendingMode;
|
||||
import net.minecraft.client.util.JsonException;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderManager
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final ShaderDefault DEFAULT_SHADER_UNIFORM = new ShaderDefault();
|
||||
private static ShaderManager staticShaderManager;
|
||||
private static int currentProgram = -1;
|
||||
private static boolean lastCull = true;
|
||||
/** maps sampler names to their texture */
|
||||
private final Map<String, Object> shaderSamplers = Maps.<String, Object>newHashMap();
|
||||
private final List<String> samplerNames = Lists.<String>newArrayList();
|
||||
private final List<Integer> shaderSamplerLocations = Lists.<Integer>newArrayList();
|
||||
private final List<ShaderUniform> shaderUniforms = Lists.<ShaderUniform>newArrayList();
|
||||
private final List<Integer> shaderUniformLocations = Lists.<Integer>newArrayList();
|
||||
private final Map<String, ShaderUniform> mappedShaderUniforms = Maps.<String, ShaderUniform>newHashMap();
|
||||
private final int program;
|
||||
private final String programFilename;
|
||||
private final boolean useFaceCulling;
|
||||
private boolean isDirty;
|
||||
private final JsonBlendingMode blendingMode;
|
||||
private final List<Integer> attribLocations;
|
||||
private final List<String> attributes;
|
||||
private final ShaderLoader vertexShaderLoader;
|
||||
private final ShaderLoader fragmentShaderLoader;
|
||||
|
||||
public ShaderManager(IResourceManager resourceManager, String programName) throws JsonException, IOException
|
||||
{
|
||||
JsonParser jsonparser = new JsonParser();
|
||||
String[] rl = ResourceLocation.splitObjectName(programName);
|
||||
ResourceLocation resourcelocation = new ResourceLocation(rl[0], "shaders/program/" + rl[1] + ".json");
|
||||
this.programFilename = programName;
|
||||
IResource iresource = null;
|
||||
|
||||
try
|
||||
{
|
||||
iresource = resourceManager.getResource(resourcelocation);
|
||||
JsonObject jsonobject = jsonparser.parse(IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
String s = JsonUtils.getString(jsonobject, "vertex");
|
||||
String s1 = JsonUtils.getString(jsonobject, "fragment");
|
||||
JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "samplers", (JsonArray)null);
|
||||
|
||||
if (jsonarray != null)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (JsonElement jsonelement : jsonarray)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.parseSampler(jsonelement);
|
||||
}
|
||||
catch (Exception exception2)
|
||||
{
|
||||
JsonException jsonexception1 = JsonException.forException(exception2);
|
||||
jsonexception1.prependJsonKey("samplers[" + i + "]");
|
||||
throw jsonexception1;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
JsonArray jsonarray1 = JsonUtils.getJsonArray(jsonobject, "attributes", (JsonArray)null);
|
||||
|
||||
if (jsonarray1 != null)
|
||||
{
|
||||
int j = 0;
|
||||
this.attribLocations = Lists.<Integer>newArrayListWithCapacity(jsonarray1.size());
|
||||
this.attributes = Lists.<String>newArrayListWithCapacity(jsonarray1.size());
|
||||
|
||||
for (JsonElement jsonelement1 : jsonarray1)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.attributes.add(JsonUtils.getString(jsonelement1, "attribute"));
|
||||
}
|
||||
catch (Exception exception1)
|
||||
{
|
||||
JsonException jsonexception2 = JsonException.forException(exception1);
|
||||
jsonexception2.prependJsonKey("attributes[" + j + "]");
|
||||
throw jsonexception2;
|
||||
}
|
||||
|
||||
++j;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.attribLocations = null;
|
||||
this.attributes = null;
|
||||
}
|
||||
|
||||
JsonArray jsonarray2 = JsonUtils.getJsonArray(jsonobject, "uniforms", (JsonArray)null);
|
||||
|
||||
if (jsonarray2 != null)
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
for (JsonElement jsonelement2 : jsonarray2)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.parseUniform(jsonelement2);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
JsonException jsonexception3 = JsonException.forException(exception);
|
||||
jsonexception3.prependJsonKey("uniforms[" + k + "]");
|
||||
throw jsonexception3;
|
||||
}
|
||||
|
||||
++k;
|
||||
}
|
||||
}
|
||||
|
||||
this.blendingMode = JsonBlendingMode.parseBlendNode(JsonUtils.getJsonObject(jsonobject, "blend", (JsonObject)null));
|
||||
this.useFaceCulling = JsonUtils.getBoolean(jsonobject, "cull", true);
|
||||
this.vertexShaderLoader = ShaderLoader.loadShader(resourceManager, ShaderLoader.ShaderType.VERTEX, s);
|
||||
this.fragmentShaderLoader = ShaderLoader.loadShader(resourceManager, ShaderLoader.ShaderType.FRAGMENT, s1);
|
||||
this.program = ShaderLinkHelper.getStaticShaderLinkHelper().createProgram();
|
||||
ShaderLinkHelper.getStaticShaderLinkHelper().linkProgram(this);
|
||||
this.setupUniforms();
|
||||
|
||||
if (this.attributes != null)
|
||||
{
|
||||
for (String s2 : this.attributes)
|
||||
{
|
||||
int l = OpenGlHelper.glGetAttribLocation(this.program, s2);
|
||||
this.attribLocations.add(Integer.valueOf(l));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception3)
|
||||
{
|
||||
JsonException jsonexception = JsonException.forException(exception3);
|
||||
jsonexception.setFilenameAndFlush(resourcelocation.getResourcePath());
|
||||
throw jsonexception;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void deleteShader()
|
||||
{
|
||||
ShaderLinkHelper.getStaticShaderLinkHelper().deleteShader(this);
|
||||
}
|
||||
|
||||
public void endShader()
|
||||
{
|
||||
OpenGlHelper.glUseProgram(0);
|
||||
currentProgram = -1;
|
||||
staticShaderManager = null;
|
||||
lastCull = true;
|
||||
|
||||
for (int i = 0; i < this.shaderSamplerLocations.size(); ++i)
|
||||
{
|
||||
if (this.shaderSamplers.get(this.samplerNames.get(i)) != null)
|
||||
{
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit + i);
|
||||
GlStateManager.bindTexture(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void useShader()
|
||||
{
|
||||
this.isDirty = false;
|
||||
staticShaderManager = this;
|
||||
this.blendingMode.apply();
|
||||
|
||||
if (this.program != currentProgram)
|
||||
{
|
||||
OpenGlHelper.glUseProgram(this.program);
|
||||
currentProgram = this.program;
|
||||
}
|
||||
|
||||
if (this.useFaceCulling)
|
||||
{
|
||||
GlStateManager.enableCull();
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.disableCull();
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.shaderSamplerLocations.size(); ++i)
|
||||
{
|
||||
if (this.shaderSamplers.get(this.samplerNames.get(i)) != null)
|
||||
{
|
||||
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit + i);
|
||||
GlStateManager.enableTexture2D();
|
||||
Object object = this.shaderSamplers.get(this.samplerNames.get(i));
|
||||
int j = -1;
|
||||
|
||||
if (object instanceof Framebuffer)
|
||||
{
|
||||
j = ((Framebuffer)object).framebufferTexture;
|
||||
}
|
||||
else if (object instanceof ITextureObject)
|
||||
{
|
||||
j = ((ITextureObject)object).getGlTextureId();
|
||||
}
|
||||
else if (object instanceof Integer)
|
||||
{
|
||||
j = ((Integer)object).intValue();
|
||||
}
|
||||
|
||||
if (j != -1)
|
||||
{
|
||||
GlStateManager.bindTexture(j);
|
||||
OpenGlHelper.glUniform1i(OpenGlHelper.glGetUniformLocation(this.program, this.samplerNames.get(i)), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ShaderUniform shaderuniform : this.shaderUniforms)
|
||||
{
|
||||
shaderuniform.upload();
|
||||
}
|
||||
}
|
||||
|
||||
public void markDirty()
|
||||
{
|
||||
this.isDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a shader uniform for the name given. null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public ShaderUniform getShaderUniform(String name)
|
||||
{
|
||||
return this.mappedShaderUniforms.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a shader uniform for the name given. if not found, returns a default not-null value
|
||||
*/
|
||||
public ShaderUniform getShaderUniformOrDefault(String name)
|
||||
{
|
||||
ShaderUniform shaderuniform = this.getShaderUniform(name);
|
||||
return (ShaderUniform)(shaderuniform == null ? DEFAULT_SHADER_UNIFORM : shaderuniform);
|
||||
}
|
||||
|
||||
/**
|
||||
* goes through the parsed uniforms and samplers and connects them to their GL counterparts.
|
||||
*/
|
||||
private void setupUniforms()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; i < this.samplerNames.size(); ++j)
|
||||
{
|
||||
String s = this.samplerNames.get(i);
|
||||
int k = OpenGlHelper.glGetUniformLocation(this.program, s);
|
||||
|
||||
if (k == -1)
|
||||
{
|
||||
LOGGER.warn("Shader {}could not find sampler named {} in the specified shader program.", this.programFilename, s);
|
||||
this.shaderSamplers.remove(s);
|
||||
this.samplerNames.remove(j);
|
||||
--j;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.shaderSamplerLocations.add(Integer.valueOf(k));
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
for (ShaderUniform shaderuniform : this.shaderUniforms)
|
||||
{
|
||||
String s1 = shaderuniform.getShaderName();
|
||||
int l = OpenGlHelper.glGetUniformLocation(this.program, s1);
|
||||
|
||||
if (l == -1)
|
||||
{
|
||||
LOGGER.warn("Could not find uniform named {} in the specified shader program.", (Object)s1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.shaderUniformLocations.add(Integer.valueOf(l));
|
||||
shaderuniform.setUniformLocation(l);
|
||||
this.mappedShaderUniforms.put(s1, shaderuniform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSampler(JsonElement element) throws JsonException
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(element, "sampler");
|
||||
String s = JsonUtils.getString(jsonobject, "name");
|
||||
|
||||
if (!JsonUtils.isString(jsonobject, "file"))
|
||||
{
|
||||
this.shaderSamplers.put(s, (Object)null);
|
||||
this.samplerNames.add(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.samplerNames.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a shader sampler texture. if it already exists, replaces it.
|
||||
*/
|
||||
public void addSamplerTexture(String name, Object samplerTexture)
|
||||
{
|
||||
if (this.shaderSamplers.containsKey(name))
|
||||
{
|
||||
this.shaderSamplers.remove(name);
|
||||
}
|
||||
|
||||
this.shaderSamplers.put(name, samplerTexture);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
private void parseUniform(JsonElement element) throws JsonException
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(element, "uniform");
|
||||
String s = JsonUtils.getString(jsonobject, "name");
|
||||
int i = ShaderUniform.parseType(JsonUtils.getString(jsonobject, "type"));
|
||||
int j = JsonUtils.getInt(jsonobject, "count");
|
||||
float[] afloat = new float[Math.max(j, 16)];
|
||||
JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "values");
|
||||
|
||||
if (jsonarray.size() != j && jsonarray.size() > 1)
|
||||
{
|
||||
throw new JsonException("Invalid amount of values specified (expected " + j + ", found " + jsonarray.size() + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
for (JsonElement jsonelement : jsonarray)
|
||||
{
|
||||
try
|
||||
{
|
||||
afloat[k] = JsonUtils.getFloat(jsonelement, "value");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
JsonException jsonexception = JsonException.forException(exception);
|
||||
jsonexception.prependJsonKey("values[" + k + "]");
|
||||
throw jsonexception;
|
||||
}
|
||||
|
||||
++k;
|
||||
}
|
||||
|
||||
if (j > 1 && jsonarray.size() == 1)
|
||||
{
|
||||
while (k < j)
|
||||
{
|
||||
afloat[k] = afloat[0];
|
||||
++k;
|
||||
}
|
||||
}
|
||||
|
||||
int l = j > 1 && j <= 4 && i < 8 ? j - 1 : 0;
|
||||
ShaderUniform shaderuniform = new ShaderUniform(s, i + l, j, this);
|
||||
|
||||
if (i <= 3)
|
||||
{
|
||||
shaderuniform.set((int)afloat[0], (int)afloat[1], (int)afloat[2], (int)afloat[3]);
|
||||
}
|
||||
else if (i <= 7)
|
||||
{
|
||||
shaderuniform.setSafe(afloat[0], afloat[1], afloat[2], afloat[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
shaderuniform.set(afloat);
|
||||
}
|
||||
|
||||
this.shaderUniforms.add(shaderuniform);
|
||||
}
|
||||
}
|
||||
|
||||
public ShaderLoader getVertexShaderLoader()
|
||||
{
|
||||
return this.vertexShaderLoader;
|
||||
}
|
||||
|
||||
public ShaderLoader getFragmentShaderLoader()
|
||||
{
|
||||
return this.fragmentShaderLoader;
|
||||
}
|
||||
|
||||
public int getProgram()
|
||||
{
|
||||
return this.program;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ShaderUniform
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private int uniformLocation;
|
||||
private final int uniformCount;
|
||||
private final int uniformType;
|
||||
private final IntBuffer uniformIntBuffer;
|
||||
private final FloatBuffer uniformFloatBuffer;
|
||||
private final String shaderName;
|
||||
private boolean dirty;
|
||||
private final ShaderManager shaderManager;
|
||||
|
||||
public ShaderUniform(String name, int type, int count, ShaderManager manager)
|
||||
{
|
||||
this.shaderName = name;
|
||||
this.uniformCount = count;
|
||||
this.uniformType = type;
|
||||
this.shaderManager = manager;
|
||||
|
||||
if (type <= 3)
|
||||
{
|
||||
this.uniformIntBuffer = BufferUtils.createIntBuffer(count);
|
||||
this.uniformFloatBuffer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.uniformIntBuffer = null;
|
||||
this.uniformFloatBuffer = BufferUtils.createFloatBuffer(count);
|
||||
}
|
||||
|
||||
this.uniformLocation = -1;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
private void markDirty()
|
||||
{
|
||||
this.dirty = true;
|
||||
|
||||
if (this.shaderManager != null)
|
||||
{
|
||||
this.shaderManager.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseType(String typeName)
|
||||
{
|
||||
int i = -1;
|
||||
|
||||
if ("int".equals(typeName))
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
else if ("float".equals(typeName))
|
||||
{
|
||||
i = 4;
|
||||
}
|
||||
else if (typeName.startsWith("matrix"))
|
||||
{
|
||||
if (typeName.endsWith("2x2"))
|
||||
{
|
||||
i = 8;
|
||||
}
|
||||
else if (typeName.endsWith("3x3"))
|
||||
{
|
||||
i = 9;
|
||||
}
|
||||
else if (typeName.endsWith("4x4"))
|
||||
{
|
||||
i = 10;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public void setUniformLocation(int uniformLocationIn)
|
||||
{
|
||||
this.uniformLocation = uniformLocationIn;
|
||||
}
|
||||
|
||||
public String getShaderName()
|
||||
{
|
||||
return this.shaderName;
|
||||
}
|
||||
|
||||
public void set(float p_148090_1_)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(0, p_148090_1_);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(float p_148087_1_, float p_148087_2_)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(0, p_148087_1_);
|
||||
this.uniformFloatBuffer.put(1, p_148087_2_);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(float p_148095_1_, float p_148095_2_, float p_148095_3_)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(0, p_148095_1_);
|
||||
this.uniformFloatBuffer.put(1, p_148095_2_);
|
||||
this.uniformFloatBuffer.put(2, p_148095_3_);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(float p_148081_1_, float p_148081_2_, float p_148081_3_, float p_148081_4_)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(p_148081_1_);
|
||||
this.uniformFloatBuffer.put(p_148081_2_);
|
||||
this.uniformFloatBuffer.put(p_148081_3_);
|
||||
this.uniformFloatBuffer.put(p_148081_4_);
|
||||
this.uniformFloatBuffer.flip();
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void setSafe(float p_148092_1_, float p_148092_2_, float p_148092_3_, float p_148092_4_)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
|
||||
if (this.uniformType >= 4)
|
||||
{
|
||||
this.uniformFloatBuffer.put(0, p_148092_1_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 5)
|
||||
{
|
||||
this.uniformFloatBuffer.put(1, p_148092_2_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 6)
|
||||
{
|
||||
this.uniformFloatBuffer.put(2, p_148092_3_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 7)
|
||||
{
|
||||
this.uniformFloatBuffer.put(3, p_148092_4_);
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(int p_148083_1_, int p_148083_2_, int p_148083_3_, int p_148083_4_)
|
||||
{
|
||||
this.uniformIntBuffer.position(0);
|
||||
|
||||
if (this.uniformType >= 0)
|
||||
{
|
||||
this.uniformIntBuffer.put(0, p_148083_1_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 1)
|
||||
{
|
||||
this.uniformIntBuffer.put(1, p_148083_2_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 2)
|
||||
{
|
||||
this.uniformIntBuffer.put(2, p_148083_3_);
|
||||
}
|
||||
|
||||
if (this.uniformType >= 3)
|
||||
{
|
||||
this.uniformIntBuffer.put(3, p_148083_4_);
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(float[] p_148097_1_)
|
||||
{
|
||||
if (p_148097_1_.length < this.uniformCount)
|
||||
{
|
||||
LOGGER.warn("Uniform.set called with a too-small value array (expected {}, got {}). Ignoring.", Integer.valueOf(this.uniformCount), Integer.valueOf(p_148097_1_.length));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(p_148097_1_);
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
|
||||
{
|
||||
this.uniformFloatBuffer.position(0);
|
||||
this.uniformFloatBuffer.put(0, m00);
|
||||
this.uniformFloatBuffer.put(1, m01);
|
||||
this.uniformFloatBuffer.put(2, m02);
|
||||
this.uniformFloatBuffer.put(3, m03);
|
||||
this.uniformFloatBuffer.put(4, m10);
|
||||
this.uniformFloatBuffer.put(5, m11);
|
||||
this.uniformFloatBuffer.put(6, m12);
|
||||
this.uniformFloatBuffer.put(7, m13);
|
||||
this.uniformFloatBuffer.put(8, m20);
|
||||
this.uniformFloatBuffer.put(9, m21);
|
||||
this.uniformFloatBuffer.put(10, m22);
|
||||
this.uniformFloatBuffer.put(11, m23);
|
||||
this.uniformFloatBuffer.put(12, m30);
|
||||
this.uniformFloatBuffer.put(13, m31);
|
||||
this.uniformFloatBuffer.put(14, m32);
|
||||
this.uniformFloatBuffer.put(15, m33);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void set(Matrix4f matrix)
|
||||
{
|
||||
this.set(matrix.m00, matrix.m01, matrix.m02, matrix.m03, matrix.m10, matrix.m11, matrix.m12, matrix.m13, matrix.m20, matrix.m21, matrix.m22, matrix.m23, matrix.m30, matrix.m31, matrix.m32, matrix.m33);
|
||||
}
|
||||
|
||||
public void upload()
|
||||
{
|
||||
if (!this.dirty)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
this.dirty = false;
|
||||
|
||||
if (this.uniformType <= 3)
|
||||
{
|
||||
this.uploadInt();
|
||||
}
|
||||
else if (this.uniformType <= 7)
|
||||
{
|
||||
this.uploadFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.uniformType > 10)
|
||||
{
|
||||
LOGGER.warn("Uniform.upload called, but type value ({}) is not a valid type. Ignoring.", (int)this.uniformType);
|
||||
return;
|
||||
}
|
||||
|
||||
this.uploadFloatMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadInt()
|
||||
{
|
||||
switch (this.uniformType)
|
||||
{
|
||||
case 0:
|
||||
OpenGlHelper.glUniform1(this.uniformLocation, this.uniformIntBuffer);
|
||||
break;
|
||||
case 1:
|
||||
OpenGlHelper.glUniform2(this.uniformLocation, this.uniformIntBuffer);
|
||||
break;
|
||||
case 2:
|
||||
OpenGlHelper.glUniform3(this.uniformLocation, this.uniformIntBuffer);
|
||||
break;
|
||||
case 3:
|
||||
OpenGlHelper.glUniform4(this.uniformLocation, this.uniformIntBuffer);
|
||||
break;
|
||||
default:
|
||||
LOGGER.warn("Uniform.upload called, but count value ({}) is not in the range of 1 to 4. Ignoring.", (int)this.uniformCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadFloat()
|
||||
{
|
||||
switch (this.uniformType)
|
||||
{
|
||||
case 4:
|
||||
OpenGlHelper.glUniform1(this.uniformLocation, this.uniformFloatBuffer);
|
||||
break;
|
||||
case 5:
|
||||
OpenGlHelper.glUniform2(this.uniformLocation, this.uniformFloatBuffer);
|
||||
break;
|
||||
case 6:
|
||||
OpenGlHelper.glUniform3(this.uniformLocation, this.uniformFloatBuffer);
|
||||
break;
|
||||
case 7:
|
||||
OpenGlHelper.glUniform4(this.uniformLocation, this.uniformFloatBuffer);
|
||||
break;
|
||||
default:
|
||||
LOGGER.warn("Uniform.upload called, but count value ({}) is not in the range of 1 to 4. Ignoring.", (int)this.uniformCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadFloatMatrix()
|
||||
{
|
||||
switch (this.uniformType)
|
||||
{
|
||||
case 8:
|
||||
OpenGlHelper.glUniformMatrix2(this.uniformLocation, true, this.uniformFloatBuffer);
|
||||
break;
|
||||
case 9:
|
||||
OpenGlHelper.glUniformMatrix3(this.uniformLocation, true, this.uniformFloatBuffer);
|
||||
break;
|
||||
case 10:
|
||||
OpenGlHelper.glUniformMatrix4(this.uniformLocation, true, this.uniformFloatBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.client.shader;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in New Issue
Block a user