mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-20 04:19:40 +00:00
Initial commit from the source zip for version 2.3.18
This commit is contained in:
commit
dccbbdd63d
62 files changed
+12694
No files matched your search
@@ -0,0 +1,19 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
|
||||
public class DefaultTexture extends AbstractTexture {
|
||||
|
||||
public DefaultTexture()
|
||||
{
|
||||
loadTexture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadTexture(IResourceManager resourcemanager)
|
||||
{
|
||||
int[] aint = ShadersTex.createAIntImage(1,0xFFFFFFFF);
|
||||
ShadersTex.setupTexture(this.getMultiTexID(), aint, 1, 1, false, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
public class GuiShaders extends GuiScreen
|
||||
{
|
||||
/** This GUI's parent GUI. */
|
||||
protected GuiScreen parentGui;
|
||||
|
||||
private int updateTimer = -1;
|
||||
public boolean needReinit;
|
||||
|
||||
/*
|
||||
private class GuiListShaderpacks {
|
||||
int posX,posY,sizeX,sizeY;
|
||||
int viewPosY;
|
||||
int itemHeight = 20;
|
||||
int selection;
|
||||
ArrayList<String> listShaderpacks;
|
||||
public void draw() {
|
||||
Tessellator tess = Tessellator.instance;
|
||||
int listSize = listShaderpacks.size();
|
||||
int i,j;
|
||||
for (i=viewPosY/itemHeight, j=Math.min((viewPosY+sizeY)/itemHeight,listSize); i<j; ++i)
|
||||
{
|
||||
int itemY = posY-viewPosY+itemHeight*i;
|
||||
boolean selected = i==selection;
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA(0,0,selected?128:0,128);
|
||||
tess.addVertex(posX,itemY,0);
|
||||
tess.addVertex(posX,itemY+itemHeight,0);
|
||||
tess.addVertex(posX+sizeX,itemY+itemHeight,0);
|
||||
tess.addVertex(posX+sizeX,itemY,0);
|
||||
tess.draw();
|
||||
field_146289_q.drawString(listShaderpacks.get(i), posX, itemY, 0xFFFFFFFF, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
private GuiListShaderpacks guiListShaderpacks;
|
||||
*/
|
||||
|
||||
private GuiSlotShaders shaderList;
|
||||
|
||||
|
||||
/** This GUI's 'Done' button. */
|
||||
//private GuiSmallButton doneButton;
|
||||
|
||||
public GuiShaders(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
|
||||
{
|
||||
this.parentGui = par1GuiScreen;
|
||||
}
|
||||
|
||||
private static String toStringOnOff(boolean value)
|
||||
{
|
||||
return value? "On": "Off";
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui()
|
||||
{
|
||||
if (Shaders.shadersConfig==null) Shaders.loadConfig();
|
||||
List buttonList = this.buttonList;
|
||||
int width = this.width;
|
||||
int height = this.height;
|
||||
buttonList.add(new GuiButton(17, width *3 /4 -60, 30, 160, 18, "NormapMap: " +toStringOnOff(Shaders.configNormalMap)));
|
||||
buttonList.add(new GuiButton(18, width *3 /4 -60, 50, 160, 18, "SpecularMap: " +toStringOnOff(Shaders.configSpecularMap)));
|
||||
buttonList.add(new GuiButton(15, width *3 /4 -60, 70, 160, 18, "RenderResMul: "+String.format("%.04f",Shaders.configRenderResMul)));
|
||||
buttonList.add(new GuiButton(16, width *3 /4 -60, 90, 160, 18, "ShadowResMul: "+String.format("%.04f",Shaders.configShadowResMul)));
|
||||
buttonList.add(new GuiButton(10, width *3 /4 -60, 110, 160, 18, "HandDepth: " +String.format("%.04f",Shaders.configHandDepthMul)));
|
||||
buttonList.add(new GuiButton( 9, width *3 /4 -60, 130, 160, 18, "CloudShadow: " +toStringOnOff(Shaders.configCloudShadow)));
|
||||
//buttonList.add(new GuiButton(14, width *3 /4 -60, 150, 160, 18, "ShadowClipFrustrum: " +toStringOnOff(Shaders.configShadowClipFrustrum)));
|
||||
buttonList.add(new GuiButton( 4, width *3 /4 -60, 170, 160, 18, "tweakBlockDamage: "+toStringOnOff(Shaders.configTweakBlockDamage)));
|
||||
buttonList.add(new GuiButton(19, width *3 /4 -60, 190, 160, 18, "OldLighting: "+toStringOnOff(Shaders.configOldLighting)));
|
||||
//buttonList.add(new GuiButton(11, width *3 /4 -60, 210, 160, 18, "Tex Min: " +Shaders.texMinFilDesc[Shaders.configTexMinFilB]));
|
||||
//buttonList.add(new GuiButton(12, width *3 /4 -60, 230, 160, 18, "Tex_n Mag: " +Shaders.texMagFilDesc[Shaders.configTexMagFilN]));
|
||||
//buttonList.add(new GuiButton(13, width *3 /4 -60, 250, 160, 18, "Tex_s Mag: " +Shaders.texMagFilDesc[Shaders.configTexMagFilS]));
|
||||
buttonList.add(new GuiButton( 6, width *3 /4 -60, height - 25, 160, 20, "Done"));
|
||||
buttonList.add(new GuiButton( 5, width /4 -80, height - 25, 160, 20, "Open shaderpacks folder"));
|
||||
this.shaderList = new GuiSlotShaders(this);
|
||||
this.shaderList.registerScrollButtons(7, 8);//registerScrollButtons(7, 8);
|
||||
this.needReinit = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
/** actionPerformed
|
||||
* Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton)
|
||||
{
|
||||
if (par1GuiButton.enabled)//enabled
|
||||
{
|
||||
switch (par1GuiButton.id)//id
|
||||
{
|
||||
case 4: /* New block breaking */
|
||||
Shaders.configTweakBlockDamage = !Shaders.configTweakBlockDamage;
|
||||
//displayString
|
||||
par1GuiButton.displayString = "tweakBlockDamage: "+toStringOnOff(Shaders.configTweakBlockDamage);
|
||||
break;
|
||||
|
||||
case 9: /* Cloud shadow */
|
||||
Shaders.configCloudShadow = !Shaders.configCloudShadow;
|
||||
par1GuiButton.displayString = "CloudShadow: " +toStringOnOff(Shaders.configCloudShadow);
|
||||
break;
|
||||
|
||||
case 10: /* Hand Depth */
|
||||
{
|
||||
float val = Shaders.configHandDepthMul;
|
||||
float[] choices = { 0.0625f,0.125f,0.25f,0.5f,1.0f };
|
||||
int i;
|
||||
if (!isShiftKeyDown()) {//isShiftKeyDown
|
||||
for (i=0; i<choices.length && choices[i]<=val; ++i) {}
|
||||
if (i==choices.length) i=0;
|
||||
} else {
|
||||
for (i=choices.length-1; i>=0 && val<=choices[i]; --i) {}
|
||||
if (i<0) i=choices.length-1;
|
||||
}
|
||||
Shaders.configHandDepthMul = choices[i];
|
||||
par1GuiButton.displayString = "HandDepth: "+String.format("%.4f",Shaders.configHandDepthMul);
|
||||
break;
|
||||
}
|
||||
|
||||
case 15: /* Render Resolution Multiplier */
|
||||
{
|
||||
float val = Shaders.configRenderResMul;
|
||||
float[] choices = { 0.25f,0.3333333333f,0.5f,0.7071067812f,1.0f,1.414213562f,2.0f };
|
||||
int i;
|
||||
if (!isShiftKeyDown()) {
|
||||
for (i=0; i<choices.length && choices[i]<=val; ++i) {}
|
||||
if (i==choices.length) i=0;
|
||||
} else {
|
||||
for (i=choices.length-1; i>=0 && val<=choices[i]; --i) {}
|
||||
if (i<0) i=choices.length-1;
|
||||
}
|
||||
Shaders.configRenderResMul = choices[i];
|
||||
par1GuiButton.displayString = "RenderResMul: "+String.format("%.4f",Shaders.configRenderResMul);
|
||||
Shaders.scheduleResize();
|
||||
break;
|
||||
}
|
||||
|
||||
case 16: /* Shadow Resolution Multiplier */
|
||||
{
|
||||
float val = Shaders.configShadowResMul;
|
||||
float[] choices = { 0.25f,0.3333333333f,0.5f,0.7071067812f,1.0f,1.414213562f,2.0f,3.0f,4.0f };
|
||||
int i;
|
||||
if (!isShiftKeyDown()) {
|
||||
for (i=0; i<choices.length && choices[i]<=val; ++i) {}
|
||||
if (i==choices.length) i=0;
|
||||
} else {
|
||||
for (i=choices.length-1; i>=0 && val<=choices[i]; --i) {}
|
||||
if (i<0) i=choices.length-1;
|
||||
}
|
||||
Shaders.configShadowResMul = choices[i];
|
||||
par1GuiButton.displayString = "ShadowResMul: "+String.format("%.4f",Shaders.configShadowResMul);
|
||||
Shaders.scheduleResizeShadow();
|
||||
break;
|
||||
}
|
||||
|
||||
case 17: /* Normal Map */
|
||||
{
|
||||
Shaders.configNormalMap = !Shaders.configNormalMap;
|
||||
//displayString
|
||||
par1GuiButton.displayString = "NormapMap: " +toStringOnOff(Shaders.configNormalMap);
|
||||
mc.scheduleResourcesRefresh(); // schedule refresh texture
|
||||
break;
|
||||
}
|
||||
|
||||
case 18: /* Normal Map */
|
||||
{
|
||||
Shaders.configSpecularMap = !Shaders.configSpecularMap;
|
||||
//displayString
|
||||
par1GuiButton.displayString = "SpecularMap: " +toStringOnOff(Shaders.configSpecularMap);
|
||||
mc.scheduleResourcesRefresh(); // schedule refresh texture
|
||||
break;
|
||||
}
|
||||
|
||||
case 19: /* old Lighting */
|
||||
{
|
||||
Shaders.configOldLighting = !Shaders.configOldLighting;
|
||||
//displayString
|
||||
par1GuiButton.displayString = "OldLighting: " +toStringOnOff(Shaders.configOldLighting);
|
||||
Shaders.updateBlockLightLevel();
|
||||
mc.renderGlobal.loadRenderers();
|
||||
break;
|
||||
}
|
||||
|
||||
case 11: /* texture filter */
|
||||
{
|
||||
Shaders.configTexMinFilB = (Shaders.configTexMinFilB+1)%Shaders.texMinFilRange;
|
||||
Shaders.configTexMinFilN = Shaders.configTexMinFilS = Shaders.configTexMinFilB;
|
||||
par1GuiButton.displayString = "Tex Min: " +Shaders.texMinFilDesc[Shaders.configTexMinFilB];
|
||||
ShadersTex.updateTextureMinMagFilter();
|
||||
break;
|
||||
}
|
||||
|
||||
case 12: /* texture filter */
|
||||
{
|
||||
Shaders.configTexMagFilN = (Shaders.configTexMagFilN+1)%Shaders.texMagFilRange;
|
||||
par1GuiButton.displayString = "Tex_n Mag: " +Shaders.texMagFilDesc[Shaders.configTexMagFilN];
|
||||
ShadersTex.updateTextureMinMagFilter();
|
||||
break;
|
||||
}
|
||||
|
||||
case 13: /* texture filter */
|
||||
{
|
||||
Shaders.configTexMagFilS = (Shaders.configTexMagFilS+1)%Shaders.texMagFilRange;
|
||||
par1GuiButton.displayString = "Tex_s Mag: " +Shaders.texMagFilDesc[Shaders.configTexMagFilS];
|
||||
ShadersTex.updateTextureMinMagFilter();
|
||||
break;
|
||||
}
|
||||
|
||||
case 14: /* shadow frustum clipping */
|
||||
{
|
||||
Shaders.configShadowClipFrustrum = !Shaders.configShadowClipFrustrum;
|
||||
par1GuiButton.displayString = "ShadowClipFrustrum: " +toStringOnOff(Shaders.configShadowClipFrustrum);
|
||||
ShadersTex.updateTextureMinMagFilter();
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: /* Open shaderpacks folder */
|
||||
switch(net.minecraft.util.Util.getOSType())
|
||||
{
|
||||
case OSX:
|
||||
{
|
||||
try
|
||||
{
|
||||
Runtime.getRuntime().exec(new String[] {"/usr/bin/open", Shaders.shaderpacksdir.getAbsolutePath()});
|
||||
return;
|
||||
}
|
||||
catch (IOException var7)
|
||||
{
|
||||
var7.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WINDOWS:
|
||||
{
|
||||
String var2 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {Shaders.shaderpacksdir.getAbsolutePath()});
|
||||
|
||||
try
|
||||
{
|
||||
Runtime.getRuntime().exec(var2);
|
||||
return;
|
||||
}
|
||||
catch (IOException var6)
|
||||
{
|
||||
var6.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
boolean var8 = false;
|
||||
|
||||
try
|
||||
{
|
||||
Class var3 = Class.forName("java.awt.Desktop");
|
||||
Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
|
||||
var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {(new File(mc.mcDataDir, Shaders.shaderpacksdirname)).toURI()});
|
||||
}
|
||||
catch (Throwable var5)
|
||||
{
|
||||
var5.printStackTrace();
|
||||
var8 = true;
|
||||
}
|
||||
|
||||
if (var8)
|
||||
{
|
||||
System.out.println("Opening via system class!");
|
||||
Sys.openURL("file://" + Shaders.shaderpacksdir.getAbsolutePath());
|
||||
}
|
||||
break;
|
||||
|
||||
case 6: /* Done */
|
||||
File confshader = new File(Shaders.shadersdir,"current.cfg");
|
||||
try
|
||||
{
|
||||
Shaders.storeConfig();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
if (needReinit)
|
||||
{
|
||||
needReinit = false;
|
||||
Shaders.loadShaderPack();
|
||||
Shaders.uninit();
|
||||
this.mc.renderGlobal.loadRenderers();
|
||||
}
|
||||
this.mc.displayGuiScreen(this.parentGui);//displayGuiScreen
|
||||
break;
|
||||
|
||||
default:
|
||||
this.shaderList.actionPerformed(par1GuiButton);//actionPerformed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3)
|
||||
{
|
||||
drawDefaultBackground(); // background
|
||||
this.shaderList.drawScreen(par1, par2, par3);//drawScreen
|
||||
|
||||
if (this.updateTimer <= 0)
|
||||
{
|
||||
this.shaderList.updateList();
|
||||
this.updateTimer += 20;
|
||||
}
|
||||
|
||||
this.drawCenteredString(this.fontRendererObj, "Shaders " , this.width / 2, 16, 0xffffff);
|
||||
this.drawCenteredString(this.fontRendererObj, " v"+Shaders.versionString, this.width - 40, 10, 0x808080);
|
||||
//this.drawCenteredString(this.fontRenderer, "( Place zipped Shader files here. )", this.width / 4 + 10, this.height - 26, 0x808080);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
--this.updateTimer;
|
||||
}
|
||||
|
||||
public Minecraft getMc()
|
||||
{
|
||||
return this.mc;
|
||||
}
|
||||
|
||||
public void drawCenteredString(String par1, int par2, int par3, int par4)
|
||||
{
|
||||
this.drawCenteredString(this.fontRendererObj, par1, par2, par3, par4);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiSlot;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
class GuiSlotShaders extends GuiSlot
|
||||
{
|
||||
private ArrayList shaderslist;
|
||||
|
||||
final GuiShaders shadersGui;
|
||||
|
||||
public GuiSlotShaders(GuiShaders par1GuiShaders)
|
||||
{
|
||||
//super(par1GuiShaders.getMc(), par1GuiShaders.width / 2 + 20, par1GuiShaders.height, 40, par1GuiShaders.height - 70, 16);
|
||||
super(par1GuiShaders.getMc(), par1GuiShaders.width / 2 + 20, par1GuiShaders.height, 40, par1GuiShaders.height - 70, 16);
|
||||
this.shadersGui = par1GuiShaders;
|
||||
this.shaderslist = Shaders.listofShaders();
|
||||
}
|
||||
|
||||
public void updateList()
|
||||
{
|
||||
this.shaderslist = Shaders.listofShaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
/** getSize */
|
||||
protected int getSize() {
|
||||
return this.shaderslist.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
/** elementClicked */
|
||||
protected void elementClicked(int par1, boolean par2, int par3, int par4) {
|
||||
Shaders.setShaderPack((String)shaderslist.get(par1));
|
||||
shadersGui.needReinit = false;
|
||||
Shaders.loadShaderPack();
|
||||
Shaders.uninit();
|
||||
}
|
||||
|
||||
@Override
|
||||
/** isSelected */
|
||||
protected boolean isSelected(int par1) {
|
||||
return ((String)this.shaderslist.get(par1)).equals(Shaders.currentshadername);
|
||||
}
|
||||
|
||||
@Override
|
||||
/** getScrollBarX */
|
||||
protected int getScrollBarX() {
|
||||
return this.width - 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
/** getContentHeight */
|
||||
protected int getContentHeight() {
|
||||
return this.getSize() * 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
/** drawBackground */
|
||||
protected void drawBackground() {
|
||||
//this.shadersGui.drawDefaultBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
/** drawSlot */
|
||||
protected void drawSlot(int par1, int par2, int par3, int par4,
|
||||
Tessellator par5, int par6, int par7) {
|
||||
this.shadersGui.drawCenteredString((String)this.shaderslist.get(par1), this.shadersGui.width / 4 + 10, par3 + 1, 0xffffff);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nathanael Lane
|
||||
*/
|
||||
public class HFNoiseTexture {
|
||||
public int texID;
|
||||
public int textureUnit;
|
||||
|
||||
public HFNoiseTexture(int width, int height){
|
||||
texID = GL11.glGenTextures();
|
||||
textureUnit = 15;
|
||||
|
||||
byte[] image = genHFNoiseImage(width, height);
|
||||
ByteBuffer data = BufferUtils.createByteBuffer(image.length);
|
||||
data.put(image);
|
||||
data.flip();
|
||||
|
||||
//GL13.glActiveTexture(GL13.GL_TEXTURE0 + this.textureUnit);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0,
|
||||
GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, data);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
//GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
public int getID(){
|
||||
return texID;
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
GL11.glDeleteTextures(texID);
|
||||
texID = 0;
|
||||
}
|
||||
|
||||
|
||||
//from George Marsaglia's paper on XORshift PRNGs
|
||||
private int random(int seed){
|
||||
seed ^= (seed << 13);
|
||||
seed ^= (seed >> 17);
|
||||
seed ^= (seed << 5);
|
||||
return seed;
|
||||
}
|
||||
|
||||
private byte random(int x, int y, int z){
|
||||
int seed = (random(x) + random(y * 19)) * random(z * 23) - z;
|
||||
return (byte) (random(seed) % 128);
|
||||
}
|
||||
|
||||
/*
|
||||
* Just a random value for each pixel to get maximum frequency
|
||||
*/
|
||||
private byte[] genHFNoiseImage(int width, int height){
|
||||
|
||||
byte[] image = new byte[width * height * 3];
|
||||
int index = 0;
|
||||
|
||||
for(int y = 0; y < height; y++){
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int z = 1; z < 4; z++){
|
||||
image[index++] = random(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface IShaderPack {
|
||||
|
||||
void close();
|
||||
|
||||
InputStream getResourceAsStream(String resName);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MultiTexID {
|
||||
public int base;
|
||||
public int norm;
|
||||
public int spec;
|
||||
|
||||
public MultiTexID(int baseTex, int normTex, int specTex)
|
||||
{
|
||||
base = baseTex;
|
||||
norm = normTex;
|
||||
spec = specTex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ShaderPackDefault implements IShaderPack {
|
||||
|
||||
public ShaderPackDefault() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String resName) {
|
||||
return ShaderPackDefault.class.getResourceAsStream(resName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ShaderPackFolder implements IShaderPack {
|
||||
|
||||
protected File packFile;
|
||||
|
||||
public ShaderPackFolder(String name, File file)
|
||||
{
|
||||
packFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String resName)
|
||||
{
|
||||
try
|
||||
{
|
||||
File resFile = new File(packFile, resName.substring(1));
|
||||
if (resFile != null)
|
||||
{
|
||||
return new BufferedInputStream(new FileInputStream(resFile));
|
||||
}
|
||||
}
|
||||
catch (Exception excp)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ShaderPackNone implements IShaderPack {
|
||||
|
||||
public ShaderPackNone() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String resName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class ShaderPackZip implements IShaderPack {
|
||||
|
||||
protected File packFile;
|
||||
protected ZipFile packZipFile;
|
||||
|
||||
public ShaderPackZip(String name, File file)
|
||||
{
|
||||
packFile = file;
|
||||
packZipFile = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if(packZipFile != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
packZipFile.close();
|
||||
}
|
||||
catch (Exception excp)
|
||||
{
|
||||
}
|
||||
packZipFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String resName)
|
||||
{
|
||||
if (packZipFile == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
packZipFile = new ZipFile(packFile);
|
||||
}
|
||||
catch (Exception excp)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (packZipFile != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ZipEntry entry = packZipFile.getEntry(resName.substring(1));
|
||||
if (entry != null)
|
||||
{
|
||||
return packZipFile.getInputStream(entry);
|
||||
}
|
||||
}
|
||||
catch (Exception excp)
|
||||
{
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,105 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import shadersmodcore.transform.Names;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockIce;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.culling.Frustrum;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemCloth;
|
||||
|
||||
public class ShadersRender {
|
||||
|
||||
public static void setFrustrumPosition(Frustrum frustrum, double x, double y, double z)
|
||||
{
|
||||
frustrum.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
public static void clipRenderersByFrustrum(RenderGlobal renderGlobal, Frustrum frustrum, float par2)
|
||||
{
|
||||
Shaders.checkGLError("pre clip");
|
||||
if (!Shaders.isShadowPass) {
|
||||
WorldRenderer[] worldRenderers = renderGlobal.worldRenderers;
|
||||
for (int i = 0; i < worldRenderers.length; ++i)
|
||||
{
|
||||
if (!worldRenderers[i].skipAllRenderPasses())
|
||||
{
|
||||
worldRenderers[i].updateInFrustum(frustrum);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WorldRenderer[] worldRenderers = renderGlobal.worldRenderers;
|
||||
for (int i = 0; i < worldRenderers.length; ++i)
|
||||
{
|
||||
if (!worldRenderers[i].skipAllRenderPasses())
|
||||
{
|
||||
worldRenderers[i].isInFrustum = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderHand0(EntityRenderer er, float par1, int par2) {
|
||||
if (!Shaders.isShadowPass)
|
||||
{
|
||||
Item item = (Shaders.itemToRender!=null)? Shaders.itemToRender.getItem(): null;
|
||||
Block block = (item instanceof ItemBlock)? ((ItemBlock)item).field_150939_a: null;
|
||||
// ItemCloth is for semitransparent block : stained glass, wool
|
||||
if (!(item instanceof ItemBlock) && !(block instanceof BlockIce))
|
||||
{
|
||||
Shaders.readCenterDepth();
|
||||
Shaders.beginHand();
|
||||
er.renderHand(par1, par2);
|
||||
Shaders.endHand();
|
||||
Shaders.isHandRendered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderHand1(EntityRenderer er, float par1, int par2) {
|
||||
if (!Shaders.isShadowPass)
|
||||
{
|
||||
if (!Shaders.isHandRendered) {
|
||||
Shaders.readCenterDepth();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
Shaders.beginHand();
|
||||
er.renderHand(par1, par2);
|
||||
Shaders.endHand();
|
||||
Shaders.isHandRendered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderItemFP(ItemRenderer itemRenderer, float par1) {
|
||||
// clear depth buffer locally
|
||||
GL11.glDepthFunc(GL11.GL_GEQUAL);
|
||||
GL11.glPushMatrix();
|
||||
IntBuffer drawBuffers = Shaders.activeDrawBuffers;
|
||||
Shaders.setDrawBuffers(Shaders.drawBuffersNone);
|
||||
itemRenderer.renderItemInFirstPerson(par1);
|
||||
Shaders.setDrawBuffers(drawBuffers);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
// really render item or hand
|
||||
itemRenderer.renderItemInFirstPerson(par1);
|
||||
}
|
||||
|
||||
public static void renderFPOverlay(EntityRenderer er, float par1, int par2) {
|
||||
Shaders.beginFPOverlay();
|
||||
er.renderHand(par1, par2);
|
||||
Shaders.endFPOverlay();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import static org.lwjgl.opengl.ARBVertexShader.glDisableVertexAttribArrayARB;
|
||||
import static org.lwjgl.opengl.ARBVertexShader.glEnableVertexAttribArrayARB;
|
||||
import static org.lwjgl.opengl.ARBVertexShader.glVertexAttribPointerARB;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.opengl.ARBVertexBufferObject;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import shadersmodcore.transform.SMCLog;
|
||||
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
public class ShadersTess {
|
||||
|
||||
public static final int vertexStride = 16;
|
||||
|
||||
public static int draw(Tessellator tess) {
|
||||
if (!tess.isDrawing)
|
||||
{
|
||||
throw new IllegalStateException("Not tesselating!");
|
||||
}
|
||||
else
|
||||
{
|
||||
tess.isDrawing = false;
|
||||
if (tess.drawMode == GL11.GL_QUADS && tess.vertexCount % 4 != 0) {
|
||||
SMCLog.warning("%s", "bad vertexCount");
|
||||
}
|
||||
int voffset = 0;
|
||||
int realDrawMode = tess.drawMode;
|
||||
while (voffset < tess.vertexCount)
|
||||
{
|
||||
int vcount;
|
||||
vcount = Math.min(tess.vertexCount - voffset, tess.byteBuffer.capacity() / (vertexStride*4));
|
||||
if (realDrawMode == GL11.GL_QUADS)
|
||||
vcount = vcount /4 *4;
|
||||
tess.floatBuffer.clear();
|
||||
tess.shortBuffer.clear();
|
||||
tess.intBuffer.clear();
|
||||
tess.intBuffer.put(tess.rawBuffer, voffset * vertexStride, vcount * vertexStride);
|
||||
tess.byteBuffer.position(0);
|
||||
tess.byteBuffer.limit(vcount * (vertexStride * 4));
|
||||
voffset += vcount;
|
||||
|
||||
if (tess.hasTexture)
|
||||
{
|
||||
tess.floatBuffer.position(3);
|
||||
GL11.glTexCoordPointer(2, (vertexStride * 4), tess.floatBuffer);
|
||||
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if (tess.hasBrightness)
|
||||
{
|
||||
OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
tess.shortBuffer.position(6*2);
|
||||
GL11.glTexCoordPointer(2, (vertexStride * 4), tess.shortBuffer);
|
||||
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
}
|
||||
if (tess.hasColor)
|
||||
{
|
||||
tess.byteBuffer.position(5*4);
|
||||
GL11.glColorPointer(4, true, (vertexStride * 4), tess.byteBuffer);
|
||||
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
|
||||
}
|
||||
if (tess.hasNormals)
|
||||
{
|
||||
tess.floatBuffer.position(9);
|
||||
GL11.glNormalPointer((vertexStride * 4), tess.floatBuffer);
|
||||
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
|
||||
}
|
||||
tess.floatBuffer.position(0);
|
||||
GL11.glVertexPointer(3, (vertexStride * 4), tess.floatBuffer);
|
||||
ShadersTess.preDrawArray(tess);
|
||||
|
||||
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
GL11.glDrawArrays(realDrawMode, 0, vcount);
|
||||
}
|
||||
// end loop
|
||||
|
||||
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
ShadersTess.postDrawArray(tess);
|
||||
if (tess.hasTexture)
|
||||
{
|
||||
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if (tess.hasBrightness)
|
||||
{
|
||||
OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
}
|
||||
if (tess.hasColor)
|
||||
{
|
||||
GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
|
||||
}
|
||||
if (tess.hasNormals)
|
||||
{
|
||||
GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
int n = tess.rawBufferIndex * 4;
|
||||
tess.reset();
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
public static void preDrawArray(Tessellator tess)
|
||||
{
|
||||
//Shaders.checkGLError("preDrawArray");
|
||||
if (Shaders.useMultiTexCoord3Attrib && tess.hasTexture)
|
||||
{
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glTexCoordPointer(2, (vertexStride * 4), (FloatBuffer)tess.floatBuffer.position(12));
|
||||
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
if (Shaders.useMidTexCoordAttrib && tess.hasTexture)
|
||||
{
|
||||
glVertexAttribPointerARB(Shaders.midTexCoordAttrib, 2, false, vertexStride*4, (FloatBuffer)tess.floatBuffer.position(12));
|
||||
glEnableVertexAttribArrayARB(Shaders.midTexCoordAttrib);
|
||||
}
|
||||
if (Shaders.useEntityAttrib)
|
||||
{
|
||||
glVertexAttribPointerARB(Shaders.entityAttrib, 3, false, false, vertexStride*4, (ShortBuffer)tess.shortBuffer.position(7*2));
|
||||
glEnableVertexAttribArrayARB(Shaders.entityAttrib);
|
||||
}
|
||||
//Shaders.checkGLError("preDrawArray");
|
||||
}
|
||||
public static void preDrawArrayVBO(Tessellator tess)
|
||||
{
|
||||
//Shaders.checkGLError("preDrawArray");
|
||||
if (Shaders.useMultiTexCoord3Attrib && tess.hasTexture)
|
||||
{
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, (vertexStride * 4), 12*4L);
|
||||
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
if (Shaders.useMidTexCoordAttrib && tess.hasTexture)
|
||||
{
|
||||
glVertexAttribPointerARB(Shaders.midTexCoordAttrib, 2, GL11.GL_FLOAT, false, vertexStride*4, 12*4L);
|
||||
glEnableVertexAttribArrayARB(Shaders.midTexCoordAttrib);
|
||||
}
|
||||
if (Shaders.useEntityAttrib)
|
||||
{
|
||||
glVertexAttribPointerARB(Shaders.entityAttrib, 3, GL11.GL_SHORT, false, vertexStride*4, 7*4L);
|
||||
glEnableVertexAttribArrayARB(Shaders.entityAttrib);
|
||||
}
|
||||
//Shaders.checkGLError("preDrawArray");
|
||||
}
|
||||
|
||||
public static void postDrawArray(Tessellator tess)
|
||||
{
|
||||
//Shaders.checkGLError("postDrawArray");
|
||||
if (Shaders.useEntityAttrib)
|
||||
{
|
||||
glDisableVertexAttribArrayARB(Shaders.entityAttrib);
|
||||
}
|
||||
if (Shaders.useMidTexCoordAttrib && tess.hasTexture)
|
||||
{
|
||||
glDisableVertexAttribArrayARB(Shaders.midTexCoordAttrib);
|
||||
}
|
||||
if (Shaders.useMultiTexCoord3Attrib && tess.hasTexture)
|
||||
{
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
//Shaders.checkGLError("postDrawArray");
|
||||
}
|
||||
|
||||
public static void addVertex(Tessellator tess, double parx, double pary, double parz) {
|
||||
int[] rawBuffer = tess.rawBuffer;
|
||||
int rbi = tess.rawBufferIndex;
|
||||
float fx = (float) (parx + tess.xOffset);
|
||||
float fy = (float) (pary + tess.yOffset);
|
||||
float fz = (float) (parz + tess.zOffset);
|
||||
// Check if buffer is nearly full
|
||||
if (rbi >= tess.bufferSize - vertexStride*4)
|
||||
{
|
||||
if (tess.bufferSize >= 0x1000000) {
|
||||
// Max size reached. Just draw.
|
||||
if (tess.addedVertices % 4 == 0)
|
||||
{
|
||||
tess.draw();
|
||||
tess.isDrawing = true;
|
||||
}
|
||||
} else if (tess.bufferSize > 0) {
|
||||
// Expand
|
||||
tess.bufferSize *= 2;
|
||||
tess.rawBuffer = rawBuffer = Arrays.copyOf(tess.rawBuffer, tess.bufferSize);
|
||||
System.out.format("Expand tesselator buffer %d\n",tess.bufferSize);
|
||||
} else {
|
||||
// Initialize
|
||||
tess.bufferSize = 0x10000;
|
||||
tess.rawBuffer = rawBuffer = new int[tess.bufferSize];
|
||||
}
|
||||
}
|
||||
|
||||
// shaders mod calculate normal and mid UV
|
||||
if (tess.drawMode == 7)
|
||||
{
|
||||
int i = tess.addedVertices % 4;
|
||||
float[] vertexPos = tess.vertexPos;
|
||||
vertexPos[i*4+0] = fx;
|
||||
vertexPos[i*4+1] = fy;
|
||||
vertexPos[i*4+2] = fz;
|
||||
if (i==3)
|
||||
{
|
||||
// calculate normal
|
||||
float x1 = vertexPos[ 8+0] - vertexPos[ +0];
|
||||
float y1 = vertexPos[ 8+1] - vertexPos[ +1];
|
||||
float z1 = vertexPos[ 8+2] - vertexPos[ +2];
|
||||
float x2 = vertexPos[12+0] - vertexPos[ 4+0];
|
||||
float y2 = vertexPos[12+1] - vertexPos[ 4+1];
|
||||
float z2 = vertexPos[12+2] - vertexPos[ 4+2];
|
||||
float vnx = y1*z2-y2*z1;
|
||||
float vny = z1*x2-z2*x1;
|
||||
float vnz = x1*y2-x2*y1;
|
||||
float lensq = vnx*vnx+vny*vny+vnz*vnz;
|
||||
float mult = (lensq!=0.0)? (float)(1f/Math.sqrt(lensq)): 1f;
|
||||
rawBuffer[rbi+( 9-vertexStride*3)] =
|
||||
rawBuffer[rbi+( 9-vertexStride*2)] =
|
||||
rawBuffer[rbi+( 9-vertexStride*1)] = Float.floatToRawIntBits(tess.normalX = vnx*mult);
|
||||
rawBuffer[rbi+(10-vertexStride*3)] =
|
||||
rawBuffer[rbi+(10-vertexStride*2)] =
|
||||
rawBuffer[rbi+(10-vertexStride*1)] = Float.floatToRawIntBits(tess.normalY = vny*mult);
|
||||
rawBuffer[rbi+(11-vertexStride*3)] =
|
||||
rawBuffer[rbi+(11-vertexStride*2)] =
|
||||
rawBuffer[rbi+(11-vertexStride*1)] = Float.floatToRawIntBits(tess.normalZ = vnz*mult);
|
||||
tess.hasNormals = true;
|
||||
// mid UV
|
||||
tess.midTextureU = (
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(3-vertexStride*3)])+
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(3-vertexStride*2)])+
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(3-vertexStride*1)])+
|
||||
(float)tess.textureU )/4;
|
||||
tess.midTextureV = (
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(4-vertexStride*3)])+
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(4-vertexStride*2)])+
|
||||
Float.intBitsToFloat(rawBuffer[rbi+(4-vertexStride*1)])+
|
||||
(float)tess.textureV )/4;
|
||||
rawBuffer[rbi+(12-vertexStride*3)] =
|
||||
rawBuffer[rbi+(12-vertexStride*2)] =
|
||||
rawBuffer[rbi+(12-vertexStride*1)] = Float.floatToRawIntBits(tess.midTextureU);
|
||||
rawBuffer[rbi+(13-vertexStride*3)] =
|
||||
rawBuffer[rbi+(13-vertexStride*2)] =
|
||||
rawBuffer[rbi+(13-vertexStride*1)] = Float.floatToRawIntBits(tess.midTextureV);
|
||||
}
|
||||
}
|
||||
// end normal and mid UV calculation
|
||||
|
||||
++tess.addedVertices;
|
||||
rawBuffer[rbi + 0] = Float.floatToRawIntBits((float)fx);
|
||||
rawBuffer[rbi + 1] = Float.floatToRawIntBits((float)fy);
|
||||
rawBuffer[rbi + 2] = Float.floatToRawIntBits((float)fz);
|
||||
rawBuffer[rbi + 3] = Float.floatToRawIntBits((float)tess.textureU);
|
||||
rawBuffer[rbi + 4] = Float.floatToRawIntBits((float)tess.textureV);
|
||||
rawBuffer[rbi + 5] = tess.color;
|
||||
rawBuffer[rbi + 6] = tess.brightness;
|
||||
rawBuffer[rbi + 7] = Shaders.getEntityData();
|
||||
rawBuffer[rbi + 8] = Shaders.getEntityData2();
|
||||
rawBuffer[rbi + 9] = Float.floatToRawIntBits((float)tess.normalX);
|
||||
rawBuffer[rbi +10] = Float.floatToRawIntBits((float)tess.normalY);
|
||||
rawBuffer[rbi +11] = Float.floatToRawIntBits((float)tess.normalZ);
|
||||
rawBuffer[rbi +12] = Float.floatToRawIntBits((float)tess.midTextureU);
|
||||
rawBuffer[rbi +13] = Float.floatToRawIntBits((float)tess.midTextureV);
|
||||
|
||||
tess.rawBufferIndex = rbi += vertexStride;
|
||||
++tess.vertexCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,969 @@
|
||||
package shadersmodcore.client;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.renderer.texture.LayeredTexture;
|
||||
import net.minecraft.client.renderer.texture.Stitcher;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.ARBTextureStorage;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL14;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL30.*;
|
||||
|
||||
public class ShadersTex {
|
||||
public static final int initialBufferSize = 1048576;
|
||||
public static ByteBuffer byteBuffer = BufferUtils.createByteBuffer(initialBufferSize*4);
|
||||
public static IntBuffer intBuffer = byteBuffer.asIntBuffer();
|
||||
public static int[] intArray = new int[initialBufferSize];
|
||||
public static final int defBaseTexColor = 0x00000000;
|
||||
public static final int defNormTexColor = 0xFF7F7FFF;
|
||||
public static final int defSpecTexColor = 0x00000000;
|
||||
public static Map<Integer,MultiTexID> multiTexMap = new HashMap();
|
||||
public static TextureMap updatingTextureMap = null;
|
||||
public static TextureAtlasSprite updatingSprite = null;
|
||||
public static MultiTexID updatingTex = null;
|
||||
public static MultiTexID boundTex = null;
|
||||
public static int updatingPage = 0;
|
||||
public static String iconName = null;
|
||||
|
||||
public static IntBuffer getIntBuffer(int size)
|
||||
{
|
||||
if (intBuffer.capacity() < size)
|
||||
{
|
||||
int bufferSize = roundUpPOT(size);
|
||||
byteBuffer = BufferUtils.createByteBuffer(bufferSize*4);
|
||||
intBuffer = byteBuffer.asIntBuffer();
|
||||
}
|
||||
return intBuffer;
|
||||
}
|
||||
|
||||
public static int[] getIntArray(int size)
|
||||
{
|
||||
if (intArray.length < size)
|
||||
{
|
||||
intArray = null;
|
||||
intArray = new int[roundUpPOT(size)];
|
||||
}
|
||||
return intArray;
|
||||
}
|
||||
|
||||
public static int roundUpPOT(int x)
|
||||
{
|
||||
int i = x-1;
|
||||
i |= (i>>1);
|
||||
i |= (i>>2);
|
||||
i |= (i>>4);
|
||||
i |= (i>>8);
|
||||
i |= (i>>16);
|
||||
return i+1;
|
||||
}
|
||||
|
||||
public static IntBuffer fillIntBuffer(int size, int value)
|
||||
{
|
||||
int[] aint = getIntArray(size);
|
||||
IntBuffer intBuf = getIntBuffer(size);
|
||||
Arrays.fill(intArray, 0, size, value);
|
||||
intBuffer.put(intArray, 0, size);
|
||||
return intBuffer;
|
||||
}
|
||||
|
||||
public static int[] createAIntImage(int size)
|
||||
{
|
||||
int[] aint = new int[size*3];
|
||||
Arrays.fill(aint, 0, size, defBaseTexColor);
|
||||
Arrays.fill(aint, size, size*2, defNormTexColor);
|
||||
Arrays.fill(aint, size*2, size*3, defSpecTexColor);
|
||||
return aint;
|
||||
}
|
||||
|
||||
public static int[] createAIntImage(int size, int color)
|
||||
{
|
||||
int[] aint = new int[size*3];
|
||||
Arrays.fill(aint, 0, size, color);
|
||||
Arrays.fill(aint, size, size*2, defNormTexColor);
|
||||
Arrays.fill(aint, size*2, size*3, defSpecTexColor);
|
||||
return aint;
|
||||
}
|
||||
|
||||
public static MultiTexID getMultiTexID(AbstractTexture tex)
|
||||
{
|
||||
MultiTexID multiTex = tex.multiTex;
|
||||
if (multiTex==null)
|
||||
{
|
||||
int baseTex = tex.getGlTextureId();
|
||||
multiTex = multiTexMap.get(Integer.valueOf(baseTex));
|
||||
if (multiTex == null)
|
||||
{
|
||||
multiTex = new MultiTexID(baseTex, GL11.glGenTextures(), GL11.glGenTextures());
|
||||
multiTexMap.put(baseTex, multiTex);
|
||||
}
|
||||
tex.multiTex = multiTex;
|
||||
}
|
||||
return multiTex;
|
||||
}
|
||||
|
||||
public static void deleteTextures(AbstractTexture atex)
|
||||
{
|
||||
int texid = atex.glTextureId;
|
||||
if (texid != -1)
|
||||
{
|
||||
GL11.glDeleteTextures(texid);
|
||||
atex.glTextureId = -1;
|
||||
}
|
||||
MultiTexID multiTex = atex.multiTex;
|
||||
if (multiTex != null)
|
||||
{
|
||||
atex.multiTex = null;
|
||||
multiTexMap.remove(Integer.valueOf(multiTex.base));
|
||||
GL11.glDeleteTextures(multiTex.norm);
|
||||
GL11.glDeleteTextures(multiTex.spec);
|
||||
if (multiTex.base != texid)
|
||||
{
|
||||
System.err.println("Error : MultiTexID.base mismatch.");
|
||||
GL11.glDeleteTextures(multiTex.base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove MultiTexID object reference and delete textures */
|
||||
public static int deleteMultiTex(ITextureObject tex)
|
||||
{
|
||||
if (tex instanceof AbstractTexture) {
|
||||
deleteTextures((AbstractTexture)tex);
|
||||
} else {
|
||||
GL11.glDeleteTextures(tex.getGlTextureId());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void bindNSTextures(int normTex, int specTex)
|
||||
{
|
||||
//Shaders.checkGLError("pre bindNSTextures");
|
||||
if (Shaders.isRenderingWorld && Shaders.activeTexUnit == GL13.GL_TEXTURE0)
|
||||
{
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, normTex);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, specTex);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
//Shaders.checkGLError("bindNSTextures");
|
||||
}
|
||||
|
||||
public static void bindNSTextures(MultiTexID multiTex)
|
||||
{
|
||||
bindNSTextures(multiTex.norm, multiTex.spec);
|
||||
}
|
||||
|
||||
public static void bindTextures(int baseTex, int normTex, int specTex)
|
||||
{
|
||||
//Shaders.checkGLError("pre bindTextures");
|
||||
if (Shaders.isRenderingWorld && Shaders.activeTexUnit == GL13.GL_TEXTURE0)
|
||||
{
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, normTex);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, specTex);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, baseTex);
|
||||
//Shaders.checkGLError("bindTextures");
|
||||
}
|
||||
|
||||
public static void bindTextures(MultiTexID multiTex)
|
||||
{
|
||||
boundTex = multiTex;
|
||||
if (Shaders.isRenderingWorld && Shaders.activeTexUnit == GL13.GL_TEXTURE0)
|
||||
{
|
||||
if (Shaders.configNormalMap) {
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
}
|
||||
if (Shaders.configSpecularMap) {
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
}
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
}
|
||||
|
||||
public static void bindTexture(ITextureObject tex)
|
||||
{
|
||||
if (tex instanceof TextureMap) {
|
||||
Shaders.atlasSizeX = ((TextureMap)tex).atlasWidth;
|
||||
Shaders.atlasSizeY = ((TextureMap)tex).atlasHeight;
|
||||
} else {
|
||||
Shaders.atlasSizeX = 0;
|
||||
Shaders.atlasSizeY = 0;
|
||||
}
|
||||
bindTextures(tex.getMultiTexID());
|
||||
}
|
||||
|
||||
/** not used */
|
||||
public static void bindTextures(int baseTex)
|
||||
{
|
||||
MultiTexID multiTex = multiTexMap.get(Integer.valueOf(baseTex));
|
||||
bindTextures(multiTex);
|
||||
}
|
||||
|
||||
public static void allocTexStorage(int width, int height, int maxLevel)
|
||||
{
|
||||
Shaders.checkGLError("pre allocTexStorage");
|
||||
int level;
|
||||
for (level=0; (width>>level)>0 && (height>>level)>0 /*&& level<=maxLevel*/; ++level) {
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA, (width>>level), (height>>level), 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)null);
|
||||
}
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, level-1);
|
||||
Shaders.checkGLError("allocTexStorage");
|
||||
//clear unused level otherwise glTexSubImage2D will crash on AMD when reallocation texture of different size.
|
||||
//for ( ; level < 16 ; ++level) {
|
||||
// GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA, 0, 0, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)null);
|
||||
//}
|
||||
GL11.glGetError(); // It usually returns error 0x0501 Invalid value for width 0 height 0. Ignore it.
|
||||
}
|
||||
|
||||
// for Dynamic Texture
|
||||
public static void initDynamicTexture(int texID, int width, int height, DynamicTexture tex)
|
||||
{
|
||||
MultiTexID multiTex = tex.getMultiTexID();
|
||||
int[] aint = tex.getTextureData();
|
||||
int size = width * height;
|
||||
Arrays.fill(aint, size, size*2, defNormTexColor);
|
||||
Arrays.fill(aint, size*2, size*3, defSpecTexColor);
|
||||
// base texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
allocTexStorage(width,height,0);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
// norm texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
allocTexStorage(width,height,0);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
// spec texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
allocTexStorage(width,height,0);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
// base texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
}
|
||||
|
||||
public static ITextureObject createDefaultTexture()
|
||||
{
|
||||
DynamicTexture tex = new DynamicTexture(1,1);
|
||||
tex.getTextureData()[0] = 0xffffffff;
|
||||
tex.updateDynamicTexture();
|
||||
return tex;
|
||||
}
|
||||
|
||||
// for TextureMap
|
||||
public static void allocateTextureMap(int texID, int mipmapLevels, int width, int height, float anisotropy, Stitcher stitcher, TextureMap tex)
|
||||
{
|
||||
System.out.println("allocateTextureMap "+tex.getTextureType()+" "+mipmapLevels+" "+width+" "+height+" "+anisotropy+" ");
|
||||
updatingTextureMap = tex;
|
||||
tex.atlasWidth = width;
|
||||
tex.atlasHeight = height;
|
||||
MultiTexID multiTex = getMultiTexID(tex);
|
||||
updatingTex = multiTex;
|
||||
TextureUtil.allocateTextureImpl(multiTex.base, mipmapLevels, width, height, anisotropy);
|
||||
if (Shaders.configNormalMap )
|
||||
TextureUtil.allocateTextureImpl(multiTex.norm, mipmapLevels, width, height, anisotropy);
|
||||
if (Shaders.configSpecularMap)
|
||||
TextureUtil.allocateTextureImpl(multiTex.spec, mipmapLevels, width, height, anisotropy);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
|
||||
}
|
||||
|
||||
public static TextureAtlasSprite setSprite(TextureAtlasSprite tas)
|
||||
{
|
||||
return updatingSprite = tas;
|
||||
}
|
||||
|
||||
public static String setIconName(String name)
|
||||
{
|
||||
return iconName = name;
|
||||
}
|
||||
|
||||
public static void uploadTexSubForLoadAtlas(int[][] data, int width, int height, int xoffset, int yoffset, boolean linear, boolean clamp)
|
||||
{
|
||||
TextureUtil.uploadTextureMipmap(data, width, height, xoffset, yoffset, linear, clamp);
|
||||
boolean border = updatingSprite.useAnisotropicFiltering;
|
||||
int[][] aaint;
|
||||
//
|
||||
if (Shaders.configNormalMap ) {
|
||||
aaint = readImageAndMipmaps(iconName+"_n", width, height, data.length, border, defNormTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.norm);
|
||||
TextureUtil.uploadTextureMipmap(aaint, width, height, xoffset, yoffset, linear, clamp);
|
||||
}
|
||||
//
|
||||
if (Shaders.configSpecularMap) {
|
||||
aaint = readImageAndMipmaps(iconName+"_s", width, height, data.length, border, defSpecTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.spec);
|
||||
TextureUtil.uploadTextureMipmap(aaint, width, height, xoffset, yoffset, linear, clamp);
|
||||
}
|
||||
//
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.base);
|
||||
}
|
||||
|
||||
public static int[][] readImageAndMipmaps(String name, int width, int height, int numLevels, boolean border, int defColor)
|
||||
{
|
||||
int[][] aaint = new int[numLevels][];
|
||||
int[] aint;
|
||||
aaint[0] = aint = new int[width*height];
|
||||
boolean goodImage = false;
|
||||
BufferedImage image = readImage(updatingTextureMap.completeResourceLocation(new ResourceLocation(name), 0));
|
||||
if (image != null) {
|
||||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
if (imageWidth + (border? 16: 0) == width)
|
||||
{
|
||||
goodImage = true;
|
||||
image.getRGB(0, 0, imageWidth, imageWidth, aint, 0, imageWidth);
|
||||
if (border)
|
||||
TextureUtil.prepareAnisotropicData(aint, imageWidth, imageWidth, 8);
|
||||
}
|
||||
}
|
||||
if (!goodImage) {
|
||||
Arrays.fill(aint, defColor);
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.spec);
|
||||
aaint = genMipmapsSimple(aaint.length-1, width, aaint);
|
||||
return aaint;
|
||||
}
|
||||
|
||||
public static BufferedImage readImage(ResourceLocation resLoc)
|
||||
{
|
||||
BufferedImage image = null;
|
||||
InputStream istr = null;
|
||||
try {
|
||||
istr = resManager.getResource(resLoc).getInputStream();
|
||||
image = ImageIO.read(istr);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
if (istr != null) {
|
||||
try {
|
||||
istr.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
istr = null;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public static int[][] genMipmapsSimple(int maxLevel, int width, int[][]data)
|
||||
{
|
||||
int level;
|
||||
for (level=1; level<=maxLevel; ++level)
|
||||
{
|
||||
if (data[level]==null)
|
||||
{
|
||||
int cw = width>>level;
|
||||
int pw = cw*2;
|
||||
int[] aintp = data[level-1];
|
||||
int[] aintc = data[level] = new int[cw*cw];
|
||||
int x,y;
|
||||
for (y=0; y<cw; ++y) {
|
||||
for (x=0; x<cw; ++x) {
|
||||
int ppos = y*2*pw+x*2;
|
||||
aintc[y*cw+x] = blend4Simple(aintp[ppos],aintp[ppos+1],aintp[ppos+pw],aintp[ppos+pw+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void uploadTexSub(int[][] data, int width, int height, int xoffset, int yoffset, boolean linear, boolean clamp)
|
||||
{
|
||||
TextureUtil.uploadTextureMipmap(data, width, height, xoffset, yoffset, linear, clamp);
|
||||
}
|
||||
|
||||
public static int blend4Alpha(int c0, int c1, int c2, int c3)
|
||||
{
|
||||
int a0 = (c0 >>> 24) & 255;
|
||||
int a1 = (c1 >>> 24) & 255;
|
||||
int a2 = (c2 >>> 24) & 255;
|
||||
int a3 = (c3 >>> 24) & 255;
|
||||
int as = a0+a1+a2+a3;
|
||||
int an = (as+2)/4;
|
||||
//int an = Math.min(Math.min(Math.min(a0,a1),a2),a3);
|
||||
int dv;
|
||||
if (as != 0) {
|
||||
dv = as;
|
||||
} else {
|
||||
dv=4; a3=a2=a1=a0=1;
|
||||
}
|
||||
int frac = (dv+1)/2;
|
||||
//return (((Math.min(Math.min(Math.min(a0,a1),a2),a3)/ 4) << 24) |
|
||||
int color = (an << 24) |
|
||||
(((((c0>>>16)&255)*a0 + ((c1>>>16)&255)*a1 + ((c2>>>16)&255)*a2 + ((c3>>>16)&255)*a3 + frac)/dv) << 16) |
|
||||
(((((c0>>> 8)&255)*a0 + ((c1>>> 8)&255)*a1 + ((c2>>> 8)&255)*a2 + ((c3>>> 8)&255)*a3 + frac)/dv) << 8) |
|
||||
(((((c0>>> 0)&255)*a0 + ((c1>>> 0)&255)*a1 + ((c2>>> 0)&255)*a2 + ((c3>>> 0)&255)*a3 + frac)/dv) << 0) ;
|
||||
return color;
|
||||
}
|
||||
|
||||
public static int blend4Simple(int c0, int c1, int c2, int c3)
|
||||
{
|
||||
int color =
|
||||
(((((c0>>>24)&255) + ((c1>>>24)&255) + ((c2>>>24)&255) + ((c3>>>24)&255) + 2)/4) << 24) |
|
||||
(((((c0>>>16)&255) + ((c1>>>16)&255) + ((c2>>>16)&255) + ((c3>>>16)&255) + 2)/4) << 16) |
|
||||
(((((c0>>> 8)&255) + ((c1>>> 8)&255) + ((c2>>> 8)&255) + ((c3>>> 8)&255) + 2)/4) << 8) |
|
||||
(((((c0>>> 0)&255) + ((c1>>> 0)&255) + ((c2>>> 0)&255) + ((c3>>> 0)&255) + 2)/4) << 0) ;
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
public static void genMipmapAlpha(int[] aint, int offset, int width, int height)
|
||||
{
|
||||
int minwh = Math.min(width, height);
|
||||
int level;
|
||||
int w1, w2, h1, h2, o1, o2;
|
||||
w1 = w2 = width;
|
||||
h1 = h2 = height;
|
||||
o1 = o2 = offset;
|
||||
// generate mipmap from big to small
|
||||
o2 = offset; w2 = width; h2 = height;
|
||||
o1 = 0; w1 = 0; h1 = 0;
|
||||
for (level=0; w2>1 && h2>1; ++level,w2=w1,h2=h1,o2=o1) {
|
||||
o1 = o2 + w2*h2;
|
||||
w1 = w2/2; h1 = h2/2;
|
||||
for (int y=0; y<h1; ++y)
|
||||
{
|
||||
int p1 = o1+y*w1;
|
||||
int p2 = o2+y*2*w2;
|
||||
for (int x=0; x<w1; ++x)
|
||||
{
|
||||
aint[p1+x] = blend4Alpha(
|
||||
aint[p2 +(x*2 )],
|
||||
aint[p2 +(x*2+1)],
|
||||
aint[p2+w2+(x*2 )],
|
||||
aint[p2+w2+(x*2+1)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// fix black pixels from small to big
|
||||
while (level>0)
|
||||
{
|
||||
--level;
|
||||
w2 = width>>level;
|
||||
h2 = height>>level;
|
||||
o2 = o1 - w2*h2;
|
||||
int p2 = o2;
|
||||
for (int y=0; y<h2; ++y)
|
||||
{
|
||||
for (int x=0; x<w2; ++x)
|
||||
{
|
||||
//p2 = o2 + y*w2 + x;
|
||||
if (aint[p2] == 0) {
|
||||
aint[p2] = aint[o1 +(y/2)*w1 +(x/2)] & 0x00ffffff;
|
||||
}
|
||||
++p2;
|
||||
}
|
||||
}
|
||||
o1 = o2;
|
||||
w1 = w2;
|
||||
h1 = h2;
|
||||
}
|
||||
}
|
||||
|
||||
public static void genMipmapSimple(int[] aint, int offset, int width, int height)
|
||||
{
|
||||
int minwh = Math.min(width, height);
|
||||
int level;
|
||||
int w1, w2, h1, h2, o1, o2;
|
||||
w1 = w2 = width;
|
||||
h1 = h2 = height;
|
||||
o1 = o2 = offset;
|
||||
// generate mipmap from big to small
|
||||
o2 = offset; w2 = width; h2 = height;
|
||||
o1 = 0; w1 = 0; h1 = 0;
|
||||
for (level=0; w2>1 && h2>1; ++level,w2=w1,h2=h1,o2=o1) {
|
||||
o1 = o2 + w2*h2;
|
||||
w1 = w2/2; h1 = h2/2;
|
||||
for (int y=0; y<h1; ++y)
|
||||
{
|
||||
int p1 = o1+y*w1;
|
||||
int p2 = o2+y*2*w2;
|
||||
for (int x=0; x<w1; ++x)
|
||||
{
|
||||
aint[p1+x] = blend4Simple(
|
||||
aint[p2 +(x*2 )],
|
||||
aint[p2 +(x*2+1)],
|
||||
aint[p2+w2+(x*2 )],
|
||||
aint[p2+w2+(x*2+1)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// fix black pixels from small to big
|
||||
while (level>0)
|
||||
{
|
||||
--level;
|
||||
w2 = width>>level;
|
||||
h2 = height>>level;
|
||||
o2 = o1 - w2*h2;
|
||||
int p2 = o2;
|
||||
for (int y=0; y<h2; ++y)
|
||||
{
|
||||
for (int x=0; x<w2; ++x)
|
||||
{
|
||||
//p2 = o2 + y*w2 + x;
|
||||
if (aint[p2] == 0) {
|
||||
aint[p2] = aint[o1 +(y/2)*w1 +(x/2)] & 0x00ffffff;
|
||||
}
|
||||
++p2;
|
||||
}
|
||||
}
|
||||
o1 = o2;
|
||||
w1 = w2;
|
||||
h1 = h2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSemiTransparent(int[] aint, int width, int height)
|
||||
{
|
||||
int size = width*height;
|
||||
// grass side texture ?;
|
||||
if (aint[0] >>> 24 == 255 && aint[size-1] == 0)
|
||||
return true;
|
||||
for (int i=0; i<size; ++i)
|
||||
{
|
||||
int alpha = aint[i] >>> 24;
|
||||
if (alpha!=0 && alpha!=255)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void updateSubImage1(int[] src, int width, int height, int posX, int posY, int page, int color)
|
||||
{
|
||||
int size = width * height;
|
||||
IntBuffer intBuf = getIntBuffer(size);
|
||||
int[] aint = getIntArray((size*4+2)/3);
|
||||
if (src.length >= size*(page+1))
|
||||
{
|
||||
System.arraycopy(src, size*page, aint, 0, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Arrays.fill(aint, color);
|
||||
}
|
||||
//
|
||||
// if (page == 0)
|
||||
genMipmapAlpha(aint,0,width,height);
|
||||
// else
|
||||
// genMipmapSimple(aint,0,width,height);
|
||||
//
|
||||
for (int level=0, offset=0, lw=width, lh=height, px=posX, py=posY;
|
||||
lw>0 && lh>0;
|
||||
++level)
|
||||
{
|
||||
int lsize = lw*lh;
|
||||
intBuf.clear();
|
||||
intBuf.put(aint, offset, lsize).position(0).limit(lsize);
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, px, py, lw, lh, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
offset += lsize; lw/=2; lh/=2; px/=2; py/=2;
|
||||
}
|
||||
intBuf.clear();
|
||||
}
|
||||
|
||||
public static void updateSubTex1(int[] src, int width, int height, int posX, int posY)
|
||||
{
|
||||
int level;
|
||||
int cw;
|
||||
int ch;
|
||||
int cx;
|
||||
int cy;
|
||||
for (level = 0, cw=width, ch=height, cx=posX, cy=posY;
|
||||
cw>0 && ch>0;
|
||||
++level, cw/=2, ch/=2, cx/=2, cy/=2)
|
||||
{
|
||||
GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, level, cx, cy, 0, 0, cw, ch);
|
||||
}
|
||||
}
|
||||
|
||||
/* updateSubImage for single Texture with mipmap */
|
||||
public static void updateSubImage1(int[][] src, int width, int height, int posX, int posY, int page, int color)
|
||||
{
|
||||
int size = width * height;
|
||||
IntBuffer intBuf = getIntBuffer(size);
|
||||
int numLevel = src.length;
|
||||
for (int level=0, //offset=0,
|
||||
lw=width, lh=height, px=posX, py=posY;
|
||||
lw>0 && lh>0 && level<numLevel;
|
||||
++level)
|
||||
{
|
||||
int lsize = lw*lh;
|
||||
intBuf.clear();
|
||||
intBuf.put(src[level], 0/*offset*/, lsize).position(0).limit(lsize);
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, px, py, lw, lh, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
//offset += lsize;
|
||||
lw/=2; lh/=2; px/=2; py/=2;
|
||||
}
|
||||
intBuf.clear();
|
||||
}
|
||||
|
||||
public static void setupTextureMipmap(TextureMap tex)
|
||||
{
|
||||
/*
|
||||
MultiTexID multiTex = tex.getMultiTexID();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
*/
|
||||
}
|
||||
|
||||
public static void updateDynamicTexture(int texID, int[] src, int width, int height, DynamicTexture tex)
|
||||
{
|
||||
MultiTexID multiTex = tex.getMultiTexID();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
updateSubImage1(src, width, height, 0, 0, 1, defNormTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
updateSubImage1(src, width, height, 0, 0, 2, defSpecTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
updateSubImage1(src, width, height, 0, 0, 0, defBaseTexColor);
|
||||
}
|
||||
|
||||
public static void updateSubImage(int[] src, int width, int height, int posX, int posY, boolean linear, boolean clamp)
|
||||
{
|
||||
if (updatingTex != null)
|
||||
{
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.norm);
|
||||
updateSubImage1(src, width, height, posX, posY, 1, defNormTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.spec);
|
||||
updateSubImage1(src, width, height, posX, posY, 2, defSpecTexColor);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, updatingTex.base);
|
||||
}
|
||||
updateSubImage1(src, width, height, posX, posY, 0, defBaseTexColor);
|
||||
}
|
||||
|
||||
// not used
|
||||
public static void updateAnimationTextureMap(TextureMap tex, List tasList)
|
||||
{
|
||||
Iterator<TextureAtlasSprite> iterator;
|
||||
MultiTexID multiTex = tex.getMultiTexID();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
for (iterator = tasList.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
TextureAtlasSprite tas = iterator.next();
|
||||
tas.updateAnimation();
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
for (iterator = tasList.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
TextureAtlasSprite tas = iterator.next();
|
||||
tas.updateAnimation();
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
for (iterator = tasList.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
TextureAtlasSprite tas = iterator.next();
|
||||
tas.updateAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupTexture(MultiTexID multiTex, int[] src, int width, int height, boolean linear, boolean clamp)
|
||||
{
|
||||
int mmfilter = linear? GL11.GL_LINEAR: GL11.GL_NEAREST;
|
||||
int wraptype = clamp? GL11.GL_CLAMP: GL11.GL_REPEAT;
|
||||
int size = width * height;
|
||||
IntBuffer intBuf = getIntBuffer(size);
|
||||
//
|
||||
intBuf.clear();
|
||||
intBuf.put(src, 0, size).position(0).limit(size);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wraptype);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wraptype);
|
||||
//
|
||||
intBuf.put(src, size, size).position(0).limit(size);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wraptype);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wraptype);
|
||||
//
|
||||
intBuf.put(src, size*2, size).position(0).limit(size);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, mmfilter);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wraptype);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wraptype);
|
||||
//
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
}
|
||||
|
||||
/* currently not used */
|
||||
public static void updateSubImage(MultiTexID multiTex, int[] src, int width, int height, int posX, int posY, boolean linear, boolean clamp)
|
||||
{
|
||||
int size = width * height;
|
||||
IntBuffer intBuf = getIntBuffer(size);
|
||||
//
|
||||
intBuf.clear();
|
||||
intBuf.put(src, 0, size);
|
||||
intBuf.position(0).limit(size);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, posX, posY, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
if (src.length == size*3)
|
||||
{
|
||||
intBuf.clear();
|
||||
intBuf.put(src, size, size).position(0);
|
||||
intBuf.position(0).limit(size);
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, posX, posY, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
if (src.length == size*3)
|
||||
{
|
||||
intBuf.clear();
|
||||
intBuf.put(src, size*2, size);
|
||||
intBuf.position(0).limit(size);
|
||||
}
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, posX, posY, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuf);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
|
||||
public static ResourceLocation getNSMapLocation(ResourceLocation location, String mapName)
|
||||
{
|
||||
String basename = location.getResourcePath();
|
||||
String[] basenameParts = basename.split(".png");
|
||||
String basenameNoFileType = basenameParts[0];
|
||||
return new ResourceLocation(location.getResourceDomain(),basenameNoFileType+"_"+mapName+".png");
|
||||
}
|
||||
|
||||
public static void loadNSMap(IResourceManager manager, ResourceLocation location, int width, int height, int[] aint)
|
||||
{
|
||||
if (Shaders.configNormalMap)
|
||||
ShadersTex.loadNSMap1(manager, getNSMapLocation(location,"n"), width, height, aint, width*height , defNormTexColor);
|
||||
if (Shaders.configSpecularMap)
|
||||
ShadersTex.loadNSMap1(manager, getNSMapLocation(location,"s"), width, height, aint, width*height*2, defSpecTexColor);
|
||||
}
|
||||
|
||||
public static void loadNSMap1(IResourceManager manager, ResourceLocation location, int width, int height, int[] aint, int offset, int defaultColor)
|
||||
{
|
||||
boolean good = false;
|
||||
try
|
||||
{
|
||||
IResource res = manager.getResource(location);
|
||||
BufferedImage bufferedimage = ImageIO.read(res.getInputStream());
|
||||
if (bufferedimage.getWidth()==width && bufferedimage.getHeight()==height)
|
||||
{
|
||||
bufferedimage.getRGB(0, 0, width, height, aint, offset, width);
|
||||
good = true;
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
}
|
||||
if (!good)
|
||||
{
|
||||
java.util.Arrays.fill(aint,offset,offset+width*height,defaultColor);
|
||||
}
|
||||
}
|
||||
|
||||
/** init and upload from BufferedImage */
|
||||
/* Replacement for TextureUtil.func_110989_a call in SimpleTexture.func_110551_a.
|
||||
Keep par0...par5 the same as func_110989_a for easy patching.
|
||||
More parameters added for reading N-S-Map. */
|
||||
public static int loadSimpleTexture(int textureID,
|
||||
BufferedImage bufferedimage, boolean linear, boolean clamp,
|
||||
IResourceManager resourceManager, ResourceLocation location, MultiTexID multiTex)
|
||||
{
|
||||
int width = bufferedimage.getWidth();
|
||||
int height = bufferedimage.getHeight();
|
||||
int size = width*height;
|
||||
int[] aint = getIntArray(size*3);
|
||||
bufferedimage.getRGB(0, 0, width, height, aint, 0, width);
|
||||
loadNSMap(resourceManager, location, width, height, aint);
|
||||
setupTexture(multiTex, aint, width, height, linear, clamp);
|
||||
return textureID;
|
||||
}
|
||||
|
||||
public static void mergeImage(int[] aint, int dstoff, int srcoff, int size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static int blendColor(int color1, int color2, int factor1)
|
||||
{
|
||||
int factor2 = 255-factor1;
|
||||
return
|
||||
(( (((color1>>>24)&255)*factor1 + ((color2>>>24)&255)*factor2) /255 ) << 24) |
|
||||
(( (((color1>>>16)&255)*factor1 + ((color2>>>16)&255)*factor2) /255 ) << 16) |
|
||||
(( (((color1>>> 8)&255)*factor1 + ((color2>>> 8)&255)*factor2) /255 ) << 8) |
|
||||
(( (((color1>>> 0)&255)*factor1 + ((color2>>> 0)&255)*factor2) /255 ) << 0);
|
||||
}
|
||||
|
||||
public static void loadLayeredTexture(LayeredTexture tex, IResourceManager manager, List list)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int size = 0;
|
||||
int[] image = null;
|
||||
Iterator<String> iterator;
|
||||
for (iterator = list.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
String s = iterator.next();
|
||||
if (s != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation(s);
|
||||
InputStream inputstream = manager.getResource(location).getInputStream();
|
||||
BufferedImage bufimg = ImageIO.read(inputstream);
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
width = bufimg.getWidth();
|
||||
height = bufimg.getHeight();
|
||||
size = width*height;
|
||||
image = createAIntImage(size,0x00000000);
|
||||
}
|
||||
int[] aint = getIntArray(size * 3);
|
||||
bufimg.getRGB(0, 0, width, height, aint, 0, width);
|
||||
loadNSMap(manager, location, width, height, aint);
|
||||
// merge
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
int alpha = (aint[i] >>> 24) & 255;
|
||||
image[size*0+i] = blendColor(aint[size*0+i], image[size*0+i], alpha);
|
||||
image[size*1+i] = blendColor(aint[size*1+i], image[size*1+i], alpha);
|
||||
image[size*2+i] = blendColor(aint[size*2+i], image[size*2+i], alpha);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// init and upload
|
||||
setupTexture(tex.getMultiTexID(), image, width, height, false, false);
|
||||
}
|
||||
|
||||
/* update block texture filter +/- items texture */
|
||||
static void updateTextureMinMagFilter()
|
||||
{
|
||||
TextureManager texman = Minecraft.getMinecraft().getTextureManager();
|
||||
ITextureObject texObj = texman.getTexture(TextureMap.locationBlocksTexture);
|
||||
if (texObj != null)
|
||||
{
|
||||
MultiTexID multiTex = texObj.getMultiTexID();
|
||||
// base texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.base);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, Shaders.texMinFilValue[Shaders.configTexMinFilB]);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, Shaders.texMagFilValue[Shaders.configTexMagFilB]);
|
||||
// norm texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.norm);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, Shaders.texMinFilValue[Shaders.configTexMinFilN]);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, Shaders.texMagFilValue[Shaders.configTexMagFilN]);
|
||||
|
||||
// spec texture
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, multiTex.spec);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, Shaders.texMinFilValue[Shaders.configTexMinFilS]);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, Shaders.texMagFilValue[Shaders.configTexMagFilS]);
|
||||
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static IResourceManager resManager = null;
|
||||
static ResourceLocation resLocation = null;
|
||||
static int imageSize = 0;
|
||||
|
||||
public static IResource loadResource(IResourceManager manager, ResourceLocation location) throws IOException
|
||||
{
|
||||
resManager = manager;
|
||||
resLocation = location;
|
||||
return manager.getResource(location);
|
||||
}
|
||||
|
||||
public static int[] loadAtlasSprite(BufferedImage bufferedimage, int startX, int startY, int w, int h, int[] aint, int offset, int scansize)
|
||||
{
|
||||
imageSize = w*h;
|
||||
bufferedimage.getRGB(startX, startY, w, h, aint, offset, scansize);
|
||||
loadNSMap(resManager, resLocation, w, h, aint);
|
||||
return aint;
|
||||
}
|
||||
|
||||
public static int[] extractFrame(int[] src, int width, int height, int frameIndex)
|
||||
{
|
||||
int srcSize = imageSize;
|
||||
int frameSize = width * height;
|
||||
int[] dst = new int[frameSize * 3];
|
||||
int srcPos = frameSize * frameIndex;
|
||||
int dstPos = 0;
|
||||
System.arraycopy(src, srcPos, dst, dstPos, frameSize);
|
||||
srcPos += srcSize; dstPos += frameSize;
|
||||
System.arraycopy(src, srcPos, dst, dstPos, frameSize);
|
||||
srcPos += srcSize; dstPos += frameSize;
|
||||
System.arraycopy(src, srcPos, dst, dstPos, frameSize);
|
||||
return dst;
|
||||
}
|
||||
|
||||
public static void fixTransparentColor(TextureAtlasSprite tas, int[] aint) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user