Commit 7ab034295c052784a82cdacd190841d70c101ca2

Authored by Mumfrey
1 parent a2baddb7

adding FrameBufferListener

debug/obfuscation.properties
... ... @@ -14,4 +14,6 @@ field_148759_a=underlyingIntegerMap
14 14 #field_148748_b=
15 15 field_147559_m=mapSpecialRenderers
16 16 field_145855_i=nameToClassMap
17   -field_145853_j=classToNameMap
18 17 \ No newline at end of file
  18 +field_145853_j=classToNameMap
  19 +func_147615_c=framebufferRender
  20 +func_147612_c=bindFramebufferTexture
19 21 \ No newline at end of file
... ...
java/client/com/mumfrey/liteloader/FrameBufferListener.java 0 → 100644
  1 +package com.mumfrey.liteloader;
  2 +
  3 +import net.minecraft.client.shader.Framebuffer;
  4 +
  5 +/**
  6 + * Interface for mods which want to interact with Minecraft's main Frame Buffer Object
  7 + *
  8 + * @author Adam Mummery-Smith
  9 + */
  10 +public interface FrameBufferListener extends LiteMod
  11 +{
  12 + /**
  13 + * Called before the FBO is rendered. Useful if you want to interact with the FBO before it is drawn to the screen
  14 + */
  15 + public abstract void preRenderFBO(Framebuffer fbo);
  16 +
  17 + /**
  18 + * Called immediately before the FBO is rendered to the screen, after the appropriate GL modes and matrix transforms
  19 + * have been set but before the FBO is actually rendered into the main output buffer.
  20 + *
  21 + * @param fbo FBO instance
  22 + * @param width FBO width
  23 + * @param height FBO height
  24 + */
  25 + public abstract void onRenderFBO(Framebuffer fbo, int width, int height);
  26 +
  27 + /**
  28 + * Called after the FBO is rendered whilst still inside the FBO transform
  29 + */
  30 + public abstract void postRenderFBO(Framebuffer fbo);
  31 +}
... ...
java/client/com/mumfrey/liteloader/client/CallbackProxyClient.java
... ... @@ -2,6 +2,8 @@ package com.mumfrey.liteloader.client;
2 2  
3 3 import net.minecraft.client.Minecraft;
4 4 import net.minecraft.client.entity.EntityClientPlayerMP;
  5 +import net.minecraft.client.renderer.OpenGlHelper;
  6 +import net.minecraft.client.shader.Framebuffer;
5 7 import net.minecraft.entity.player.EntityPlayerMP;
6 8 import net.minecraft.network.INetHandler;
7 9 import net.minecraft.network.NetworkManager;
... ... @@ -39,6 +41,10 @@ public class CallbackProxyClient
39 41 private static boolean clock = false;
40 42  
41 43 private static ClientEvents events;
  44 +
  45 + private static boolean fboEnabled;
  46 +
  47 + private static boolean renderingFBO;
42 48  
43 49 public static void handleLoginSuccessPacket(INetHandler netHandler, S02PacketLoginSuccess packet)
44 50 {
... ... @@ -261,9 +267,40 @@ public class CallbackProxyClient
261 267 {
262 268 CallbackProxyClient.events.onSendChatMessage(e, message);
263 269 }
  270 +
  271 + public static void onResize(EventInfo<Minecraft> e)
  272 + {
  273 + CallbackProxyClient.events.onResize(e.getSource());
  274 + }
  275 +
  276 + public static void preRenderFBO(EventInfo<Minecraft> e)
  277 + {
  278 + CallbackProxyClient.fboEnabled = OpenGlHelper.isFramebufferEnabled();
  279 +
  280 + if (CallbackProxyClient.fboEnabled)
  281 + {
  282 + CallbackProxyClient.renderingFBO = true;
  283 + CallbackProxyClient.events.preRenderFBO(e.getSource().getFramebuffer());
  284 + }
  285 + }
  286 +
  287 + public static void postRenderFBO(EventInfo<Minecraft> e)
  288 + {
  289 + CallbackProxyClient.renderingFBO = false;
264 290  
265   - public static void onResize(EventInfo<Minecraft> e)
266   - {
267   - CallbackProxyClient.events.onResize(e.getSource());
268   - }
  291 + if (CallbackProxyClient.fboEnabled)
  292 + {
  293 + CallbackProxyClient.events.postRenderFBO(e.getSource().getFramebuffer());
  294 + }
  295 + }
  296 +
  297 + public static void renderFBO(EventInfo<Framebuffer> e, int width, int height)
  298 + {
  299 + if (CallbackProxyClient.renderingFBO)
  300 + {
  301 + CallbackProxyClient.events.onRenderFBO(e.getSource(), width, height);
  302 + }
  303 +
  304 + CallbackProxyClient.renderingFBO = false;
  305 + }
269 306 }
... ...
java/client/com/mumfrey/liteloader/client/ClientEvents.java
... ... @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
6 6 import net.minecraft.client.entity.EntityClientPlayerMP;
7 7 import net.minecraft.client.gui.GuiNewChat;
8 8 import net.minecraft.client.gui.ScaledResolution;
  9 +import net.minecraft.client.shader.Framebuffer;
9 10 import net.minecraft.network.INetHandler;
10 11 import net.minecraft.network.login.INetHandlerLoginClient;
11 12 import net.minecraft.network.login.server.S02PacketLoginSuccess;
... ... @@ -159,6 +160,11 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
159 160 * List of mods which monitor changes in the viewport
160 161 */
161 162 private LinkedList<ViewportListener> viewportListeners = new LinkedList<ViewportListener>();
  163 +
  164 + /**
  165 + * List of mods which interact with the main minecraft FBO
  166 + */
  167 + private LinkedList<FrameBufferListener> frameBufferListeners = new LinkedList<FrameBufferListener>();
162 168  
163 169 /**
164 170 * Hash code of the current world. We don't store the world reference here because we don't want
... ... @@ -212,6 +218,7 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
212 218 delegate.registerInterface(OutboundChatListener.class);
213 219 delegate.registerInterface(OutboundChatFilter.class);
214 220 delegate.registerInterface(ViewportListener.class);
  221 + delegate.registerInterface(FrameBufferListener.class);
215 222 }
216 223  
217 224 /**
... ... @@ -437,6 +444,17 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
437 444 this.viewportListeners.add(viewportListener);
438 445 }
439 446 }
  447 +
  448 + /**
  449 + * @param frameBufferListener
  450 + */
  451 + public void addFrameBufferListener(FrameBufferListener frameBufferListener)
  452 + {
  453 + if (!this.frameBufferListeners.contains(frameBufferListener))
  454 + {
  455 + this.frameBufferListeners.add(frameBufferListener);
  456 + }
  457 + }
440 458  
441 459 /**
442 460 * Late initialisation callback
... ... @@ -778,4 +796,22 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
778 796 for (JoinGameListener joinGameListener : this.joinGameListeners)
779 797 joinGameListener.onJoinGame(netHandler, loginPacket);
780 798 }
  799 +
  800 + void preRenderFBO(Framebuffer framebuffer)
  801 + {
  802 + for (FrameBufferListener frameBufferListener : this.frameBufferListeners)
  803 + frameBufferListener.preRenderFBO(framebuffer);
  804 + }
  805 +
  806 + void onRenderFBO(Framebuffer framebuffer, int width, int height)
  807 + {
  808 + for (FrameBufferListener frameBufferListener : this.frameBufferListeners)
  809 + frameBufferListener.onRenderFBO(framebuffer, width, height);
  810 + }
  811 +
  812 + void postRenderFBO(Framebuffer framebuffer)
  813 + {
  814 + for (FrameBufferListener frameBufferListener : this.frameBufferListeners)
  815 + frameBufferListener.postRenderFBO(framebuffer);
  816 + }
781 817 }
... ...
java/client/com/mumfrey/liteloader/client/transformers/LiteLoaderEventInjectionTransformer.java
... ... @@ -5,6 +5,7 @@ import com.mumfrey.liteloader.transformers.event.Event;
5 5 import com.mumfrey.liteloader.transformers.event.EventInjectionTransformer;
6 6 import com.mumfrey.liteloader.transformers.event.InjectionPoint;
7 7 import com.mumfrey.liteloader.transformers.event.MethodInfo;
  8 +import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke;
8 9 import com.mumfrey.liteloader.transformers.event.inject.MethodHead;
9 10  
10 11 public class LiteLoaderEventInjectionTransformer extends EventInjectionTransformer
... ... @@ -21,5 +22,18 @@ public class LiteLoaderEventInjectionTransformer extends EventInjectionTransform
21 22 Event updateFramebufferSize = Event.getOrCreate("updateFramebufferSize", false);
22 23 MethodInfo updateFramebufferSizeTarget = new MethodInfo(Obf.Minecraft, Obf.updateFramebufferSize, Void.TYPE);
23 24 this.addEvent(updateFramebufferSize, updateFramebufferSizeTarget, head).addListener(new MethodInfo(Obf.CallbackProxyClient, "onResize"));
  25 +
  26 + MethodInfo framebufferRender = new MethodInfo(Obf.FrameBuffer, Obf.framebufferRender, "(II)V");
  27 + BeforeInvoke beforeFramebufferRender = new BeforeInvoke(framebufferRender);
  28 +
  29 + Event preRenderFBO = Event.getOrCreate("preRenderFBO", false);
  30 + MethodInfo runGameLoop = new MethodInfo(Obf.Minecraft, Obf.runGameLoop, Void.TYPE);
  31 + this.addEvent(preRenderFBO, runGameLoop, beforeFramebufferRender).addListener(new MethodInfo(Obf.CallbackProxyClient, "preRenderFBO"));
  32 +
  33 + Event renderFBO = Event.getOrCreate("renderFBO", false);
  34 + this.addEvent(renderFBO, framebufferRender, new BeforeInvoke(new MethodInfo(Obf.FrameBuffer, Obf.bindFramebufferTexture, Void.TYPE))).addListener(new MethodInfo(Obf.CallbackProxyClient, "renderFBO"));
  35 +
  36 + Event postRenderFBO = Event.getOrCreate("postRenderFBO", false);
  37 + this.addEvent(postRenderFBO, runGameLoop, InjectionPoint.after(beforeFramebufferRender)).addListener(new MethodInfo(Obf.CallbackProxyClient, "postRenderFBO"));;
24 38 }
25 39 }
... ...
java/common/com/mumfrey/liteloader/core/runtime/Obf.java
... ... @@ -46,6 +46,7 @@ public class Obf
46 46 public static final Obf EntityClientPlayerMP = new Obf("net.minecraft.client.entity.EntityClientPlayerMP", "bjk" );
47 47 public static final Obf Blocks = new Obf("net.minecraft.init.Blocks", "ajn" );
48 48 public static final Obf Items = new Obf("net.minecraft.init.Items", "ade" );
  49 + public static final Obf FrameBuffer = new Obf("net.minecraft.client.shader.Framebuffer", "bmg" );
49 50  
50 51 // Fields
51 52 // -----------------------------------------------------------------------------------------
... ... @@ -82,6 +83,8 @@ public class Obf
82 83 public static final Obf startServerThread = new Obf("func_71256_s", "w" );
83 84 public static final Obf sendChatMessage = new Obf("func_71165_d", "a" );
84 85 public static final Obf updateFramebufferSize = new Obf("func_147119_ah", "an" );
  86 + public static final Obf framebufferRender = new Obf("func_147615_c", "c" );
  87 + public static final Obf bindFramebufferTexture = new Obf("func_147612_c", "c" );
85 88  
86 89 public static final int MCP = 0;
87 90 public static final int SRG = 1;
... ...