Major rework of the rendering core. Added support for custom render context
handling.
This commit is contained in:
parent
348a6fe03c
commit
dbb5a37449
3 changed files with 88 additions and 24 deletions
|
@ -41,25 +41,54 @@ public class ForgeHooksClient {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HashMap tessellators=new HashMap();
|
private static class TesKey implements Comparable<TesKey> {
|
||||||
static HashMap textures=new HashMap();
|
public TesKey(int t, int s) { tex=t; sub=s; }
|
||||||
|
public int compareTo(TesKey key) {
|
||||||
|
if(sub==key.sub) return tex-key.tex;
|
||||||
|
return sub-key.sub;
|
||||||
|
}
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return compareTo((TesKey)obj)==0;
|
||||||
|
}
|
||||||
|
public int hashCode() {
|
||||||
|
int c1=Integer.valueOf(tex).hashCode();
|
||||||
|
int c2=Integer.valueOf(sub).hashCode();
|
||||||
|
return c1+31*c2;
|
||||||
|
}
|
||||||
|
public int tex, sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HashMap<TesKey,Tessellator> tessellators=
|
||||||
|
new HashMap<TesKey,Tessellator>();
|
||||||
|
static HashMap<String,Integer> textures=new HashMap<String,Integer>();
|
||||||
static boolean inWorld=false;
|
static boolean inWorld=false;
|
||||||
static HashSet renderTextureTest=new HashSet();
|
static TreeSet<TesKey> renderTextures=new TreeSet<TesKey>();
|
||||||
static ArrayList<List> renderTextureList=new ArrayList();
|
|
||||||
static Tessellator defaultTessellator=null;
|
static Tessellator defaultTessellator=null;
|
||||||
|
static HashMap<TesKey,IRenderContextHandler> renderHandlers=new
|
||||||
|
HashMap<TesKey,IRenderContextHandler>();
|
||||||
|
|
||||||
|
protected static void registerRenderContextHandler(String tex, int sub,
|
||||||
|
IRenderContextHandler handler) {
|
||||||
|
Integer n;
|
||||||
|
n=textures.get(tex);
|
||||||
|
if(n==null) {
|
||||||
|
n=ModLoader.getMinecraftInstance().renderEngine
|
||||||
|
.getTexture(tex);
|
||||||
|
textures.put(tex,n);
|
||||||
|
}
|
||||||
|
renderHandlers.put(new TesKey(n,sub),handler);
|
||||||
|
}
|
||||||
|
|
||||||
protected static void bindTessellator(int tex, int sub) {
|
protected static void bindTessellator(int tex, int sub) {
|
||||||
List key=Arrays.asList(tex,sub);
|
TesKey key=new TesKey(tex,sub);
|
||||||
Tessellator t;
|
Tessellator t;
|
||||||
if(!tessellators.containsKey(key)) {
|
t=tessellators.get(key);
|
||||||
|
if(t==null) {
|
||||||
t=new Tessellator();
|
t=new Tessellator();
|
||||||
tessellators.put(key,t);
|
tessellators.put(key,t);
|
||||||
} else {
|
|
||||||
t=(Tessellator)tessellators.get(key);
|
|
||||||
}
|
}
|
||||||
if(inWorld && !renderTextureTest.contains(key)) {
|
if(inWorld && !renderTextures.contains(key)) {
|
||||||
renderTextureTest.add(key);
|
renderTextures.add(key);
|
||||||
renderTextureList.add(key);
|
|
||||||
t.startDrawingQuads();
|
t.startDrawingQuads();
|
||||||
t.setTranslationD(defaultTessellator.xOffset,
|
t.setTranslationD(defaultTessellator.xOffset,
|
||||||
defaultTessellator.yOffset,
|
defaultTessellator.yOffset,
|
||||||
|
@ -69,13 +98,12 @@ public class ForgeHooksClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void bindTexture(String name, int sub) {
|
protected static void bindTexture(String name, int sub) {
|
||||||
int n;
|
Integer n;
|
||||||
if(!textures.containsKey(name)) {
|
n=textures.get(name);
|
||||||
|
if(n==null) {
|
||||||
n=ModLoader.getMinecraftInstance().renderEngine
|
n=ModLoader.getMinecraftInstance().renderEngine
|
||||||
.getTexture(name);
|
.getTexture(name);
|
||||||
textures.put(name,n);
|
textures.put(name,n);
|
||||||
} else {
|
|
||||||
n=(Integer)textures.get(name);
|
|
||||||
}
|
}
|
||||||
if(!inWorld) {
|
if(!inWorld) {
|
||||||
if(Tessellator.instance.isDrawing) {
|
if(Tessellator.instance.isDrawing) {
|
||||||
|
@ -113,25 +141,31 @@ public class ForgeHooksClient {
|
||||||
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader
|
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader
|
||||||
.getMinecraftInstance().renderEngine
|
.getMinecraftInstance().renderEngine
|
||||||
.getTexture("/terrain.png"));
|
.getTexture("/terrain.png"));
|
||||||
renderTextureTest.clear();
|
renderTextures.clear();
|
||||||
renderTextureList.clear();
|
|
||||||
inWorld=true;
|
inWorld=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void afterRenderPass(int pass) {
|
public static void afterRenderPass(int pass) {
|
||||||
renderPass=-1;
|
renderPass=-1;
|
||||||
inWorld=false;
|
inWorld=false;
|
||||||
for(List l : renderTextureList) {
|
for(TesKey tk : renderTextures) {
|
||||||
// TODO: call appropriate client hooks
|
IRenderContextHandler irch=renderHandlers.get(tk);
|
||||||
Integer[] tn=(Integer[])l.toArray();
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D,tk.tex);
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D,tn[0]);
|
Tessellator t=tessellators.get(tk);
|
||||||
Tessellator t=(Tessellator)tessellators.get(l);
|
if(irch==null) {
|
||||||
t.draw();
|
t.draw();
|
||||||
|
} else {
|
||||||
|
Tessellator.instance=t;
|
||||||
|
irch.beforeRenderContext();
|
||||||
|
t.draw();
|
||||||
|
irch.afterRenderContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader
|
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, ModLoader
|
||||||
.getMinecraftInstance().renderEngine
|
.getMinecraftInstance().renderEngine
|
||||||
.getTexture("/terrain.png"));
|
.getTexture("/terrain.png"));
|
||||||
Tessellator.renderingWorldRenderer=false;
|
Tessellator.renderingWorldRenderer=false;
|
||||||
|
Tessellator.instance=defaultTessellator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void beforeBlockRender(Block block,
|
public static void beforeBlockRender(Block block,
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* This software is provided under the terms of the Minecraft Forge Public
|
||||||
|
* License v1.0.
|
||||||
|
*/
|
||||||
|
package net.minecraft.src.forge;
|
||||||
|
|
||||||
|
public interface IRenderContextHandler {
|
||||||
|
/** Run before the specified rendering context.
|
||||||
|
*/
|
||||||
|
public void beforeRenderContext();
|
||||||
|
|
||||||
|
/** Run after the specified rendering context.
|
||||||
|
*/
|
||||||
|
public void afterRenderContext();
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,20 @@ public class MinecraftForgeClient {
|
||||||
ForgeHooksClient.highlightHandlers.add(handler);
|
ForgeHooksClient.highlightHandlers.add(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Register a new render context handler. A render context is a block
|
||||||
|
* of rendering performed with similar OpenGL modes, for example,
|
||||||
|
* texture name.
|
||||||
|
* @param tex The name of the texture for this render context.
|
||||||
|
* @param sub The subid of this render context. 0 is the default pass
|
||||||
|
* for normal rendering, higher subids render later. All subids of 0
|
||||||
|
* will render before all subids of 1, etc.
|
||||||
|
* @param handler The handler to register.
|
||||||
|
*/
|
||||||
|
public static void registerRenderContextHandler(String tex, int sub,
|
||||||
|
IRenderContextHandler handler) {
|
||||||
|
ForgeHooksClient.registerRenderContextHandler(tex,sub,handler);
|
||||||
|
}
|
||||||
|
|
||||||
/** Bind a texture. This is used to bind a texture file when
|
/** Bind a texture. This is used to bind a texture file when
|
||||||
* performing your own rendering, rather than using ITextureProvider.
|
* performing your own rendering, rather than using ITextureProvider.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue