Last active
August 29, 2015 14:00
-
-
Save RainWarrior/11198518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ../Tessellator.orig 2014-04-23 03:53:04.774228361 +0400 | |
+++ ../Tessellator.new 2014-04-23 03:51:58.706227799 +0400 | |
@@ -10,8 +10,10 @@ | |
import java.util.Arrays; | |
import java.util.PriorityQueue; | |
import net.minecraft.client.shader.TesselatorVertexState; | |
+import net.minecraft.client.Minecraft; | |
import net.minecraft.client.util.QuadComparator; | |
import org.lwjgl.opengl.GL11; | |
+import org.lwjgl.opengl.GL20; | |
@SideOnly(Side.CLIENT) | |
public class Tessellator | |
@@ -103,6 +105,43 @@ | |
instance.defaultTexture = true; | |
} | |
+ private int fragmentShader = -1; | |
+ private int shaderProgram; | |
+ private int defaultTexSampler; | |
+ private int lightmapTexSampler; | |
+ | |
+ //private String shaderCode = "void main() {\ngl_FragColor = gl_Color;\n}\n"; | |
+ private String shaderCode = "uniform sampler2D defaultTex;\nuniform sampler2D lightmapTex;\nvoid main() {\ngl_FragColor = texture2D(defaultTex, gl_TexCoord[0].st) * texture2D(lightmapTex, gl_TexCoord[1].st) * gl_Color;\n}\n"; | |
+ | |
+ private void loadShader() | |
+ { | |
+ fragmentShader = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); | |
+ GL20.glShaderSource(fragmentShader, shaderCode); | |
+ GL20.glCompileShader(fragmentShader); | |
+ if(GL20.glGetShaderi(fragmentShader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) | |
+ { | |
+ GL20.glDeleteShader(fragmentShader); | |
+ int maxLength = GL20.glGetShaderi(fragmentShader, GL20.GL_INFO_LOG_LENGTH); | |
+ String log = GL20.glGetShaderInfoLog(fragmentShader, maxLength); | |
+ throw new RuntimeException("Could not compile shader: " + log); | |
+ } | |
+ shaderProgram = GL20.glCreateProgram(); | |
+ GL20.glAttachShader(shaderProgram, fragmentShader); | |
+ GL20.glLinkProgram(shaderProgram); | |
+ if(GL20.glGetProgrami(shaderProgram, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) | |
+ { | |
+ GL20.glDeleteProgram(shaderProgram); | |
+ GL20.glDeleteShader(fragmentShader); | |
+ int maxLength = GL20.glGetProgrami(shaderProgram, GL20.GL_INFO_LOG_LENGTH); | |
+ String log = GL20.glGetProgramInfoLog(shaderProgram, maxLength); | |
+ throw new RuntimeException("Could not link program: " + log); | |
+ } | |
+ //GL20.glDetachShader(shaderProgram, fragmentShader); | |
+ | |
+ defaultTexSampler = GL20.glGetUniformLocation(shaderProgram, "defaultTex"); | |
+ lightmapTexSampler = GL20.glGetUniformLocation(shaderProgram, "lightmapTex"); | |
+ } | |
+ | |
/** | |
* Draws the data set up in this tessellator and resets the state to prepare for new drawing. | |
*/ | |
@@ -135,6 +174,16 @@ | |
if (this.hasBrightness) | |
{ | |
+ if(this.fragmentShader == -1) | |
+ { | |
+ this.loadShader(); | |
+ } | |
+ //if(Minecraft.getMinecraft().gameSettings.showDebugInfo) | |
+ { | |
+ GL20.glUseProgram(shaderProgram); | |
+ GL20.glUniform1i(defaultTexSampler, 0); | |
+ GL20.glUniform1i(lightmapTexSampler, 1); | |
+ } | |
OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit); | |
this.shortBuffer.position(14); | |
GL11.glTexCoordPointer(2, 32, this.shortBuffer); | |
@@ -169,6 +218,10 @@ | |
if (this.hasBrightness) | |
{ | |
+ //if(Minecraft.getMinecraft().gameSettings.showDebugInfo) | |
+ { | |
+ GL20.glUseProgram(0); | |
+ } | |
OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit); | |
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); | |
OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment