Commit 35d59a000819118ae93b849aa39458158c8f9a7e
1 parent
0a1da0c9
moving clipping plane functionality to convenience class so that mods can use it as well
Showing
7 changed files
with
202 additions
and
102 deletions
java/client/com/mumfrey/liteloader/client/gui/GuiLiteLoaderPanel.java
| @@ -2,7 +2,6 @@ package com.mumfrey.liteloader.client.gui; | @@ -2,7 +2,6 @@ package com.mumfrey.liteloader.client.gui; | ||
| 2 | 2 | ||
| 3 | import static org.lwjgl.opengl.GL11.*; | 3 | import static org.lwjgl.opengl.GL11.*; |
| 4 | 4 | ||
| 5 | -import java.nio.DoubleBuffer; | ||
| 6 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
| 7 | import java.util.List; | 6 | import java.util.List; |
| 8 | 7 | ||
| @@ -16,7 +15,6 @@ import net.minecraft.client.resources.I18n; | @@ -16,7 +15,6 @@ import net.minecraft.client.resources.I18n; | ||
| 16 | import net.minecraft.util.IIcon; | 15 | import net.minecraft.util.IIcon; |
| 17 | import net.minecraft.util.ResourceLocation; | 16 | import net.minecraft.util.ResourceLocation; |
| 18 | 17 | ||
| 19 | -import org.lwjgl.BufferUtils; | ||
| 20 | import org.lwjgl.input.Keyboard; | 18 | import org.lwjgl.input.Keyboard; |
| 21 | import org.lwjgl.input.Mouse; | 19 | import org.lwjgl.input.Mouse; |
| 22 | 20 | ||
| @@ -55,13 +53,6 @@ public class GuiLiteLoaderPanel extends GuiScreen | @@ -55,13 +53,6 @@ public class GuiLiteLoaderPanel extends GuiScreen | ||
| 55 | static final int PANEL_BOTTOM = 26; | 53 | static final int PANEL_BOTTOM = 26; |
| 56 | 54 | ||
| 57 | private static final double TWEEN_RATE = 0.08; | 55 | private static final double TWEEN_RATE = 0.08; |
| 58 | - | ||
| 59 | - /** | ||
| 60 | - * Used for clipping | ||
| 61 | - */ | ||
| 62 | - private static DoubleBuffer doubleBuffer = BufferUtils.createByteBuffer(64).asDoubleBuffer(); | ||
| 63 | - | ||
| 64 | - private static int clippingPlaneFlags = 0; | ||
| 65 | 56 | ||
| 66 | private static boolean displayErrorToolTip = true; | 57 | private static boolean displayErrorToolTip = true; |
| 67 | 58 | ||
| @@ -770,79 +761,4 @@ public class GuiLiteLoaderPanel extends GuiScreen | @@ -770,79 +761,4 @@ public class GuiLiteLoaderPanel extends GuiScreen | ||
| 770 | { | 761 | { |
| 771 | glDrawTexturedRect(x, y, icon.getIconWidth(), icon.getIconHeight(), icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV(), alpha); | 762 | glDrawTexturedRect(x, y, icon.getIconWidth(), icon.getIconHeight(), icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV(), alpha); |
| 772 | } | 763 | } |
| 773 | - | ||
| 774 | - /** | ||
| 775 | - * Enable OpenGL clipping planes (uses planes 2, 3, 4 and 5) | ||
| 776 | - * | ||
| 777 | - * @param xLeft Left edge clip or -1 to not use this plane | ||
| 778 | - * @param xRight Right edge clip or -1 to not use this plane | ||
| 779 | - * @param yTop Top edge clip or -1 to not use this plane | ||
| 780 | - * @param yBottom Bottom edge clip or -1 to not use this plane | ||
| 781 | - */ | ||
| 782 | - final static void glEnableClipping(int xLeft, int xRight, int yTop, int yBottom) | ||
| 783 | - { | ||
| 784 | - clippingPlaneFlags = 0; | ||
| 785 | - | ||
| 786 | - // Apply left edge clipping if specified | ||
| 787 | - if (xLeft != -1) | ||
| 788 | - { | ||
| 789 | - doubleBuffer.clear(); | ||
| 790 | - doubleBuffer.put(1).put(0).put(0).put(-xLeft).flip(); | ||
| 791 | - glClipPlane(GL_CLIP_PLANE2, doubleBuffer); | ||
| 792 | - glEnable(GL_CLIP_PLANE2); | ||
| 793 | - clippingPlaneFlags |= GL_CLIP_PLANE2; | ||
| 794 | - } | ||
| 795 | - | ||
| 796 | - // Apply right edge clipping if specified | ||
| 797 | - if (xRight != -1) | ||
| 798 | - { | ||
| 799 | - doubleBuffer.clear(); | ||
| 800 | - doubleBuffer.put(-1).put(0).put(0).put(xRight).flip(); | ||
| 801 | - glClipPlane(GL_CLIP_PLANE3, doubleBuffer); | ||
| 802 | - glEnable(GL_CLIP_PLANE3); | ||
| 803 | - clippingPlaneFlags |= GL_CLIP_PLANE3; | ||
| 804 | - } | ||
| 805 | - | ||
| 806 | - // Apply top edge clipping if specified | ||
| 807 | - if (yTop != -1) | ||
| 808 | - { | ||
| 809 | - doubleBuffer.clear(); | ||
| 810 | - doubleBuffer.put(0).put(1).put(0).put(-yTop).flip(); | ||
| 811 | - glClipPlane(GL_CLIP_PLANE4, doubleBuffer); | ||
| 812 | - glEnable(GL_CLIP_PLANE4); | ||
| 813 | - clippingPlaneFlags |= GL_CLIP_PLANE4; | ||
| 814 | - } | ||
| 815 | - | ||
| 816 | - // Apply bottom edge clipping if specified | ||
| 817 | - if (yBottom != -1) | ||
| 818 | - { | ||
| 819 | - doubleBuffer.clear(); | ||
| 820 | - doubleBuffer.put(0).put(-1).put(0).put(yBottom).flip(); | ||
| 821 | - glClipPlane(GL_CLIP_PLANE5, doubleBuffer); | ||
| 822 | - glEnable(GL_CLIP_PLANE5); | ||
| 823 | - clippingPlaneFlags |= GL_CLIP_PLANE5; | ||
| 824 | - } | ||
| 825 | - } | ||
| 826 | - | ||
| 827 | - /** | ||
| 828 | - * Enable clipping planes which were previously enabled | ||
| 829 | - */ | ||
| 830 | - final static void glEnableClipping() | ||
| 831 | - { | ||
| 832 | - if ((clippingPlaneFlags & GL_CLIP_PLANE2) == GL_CLIP_PLANE2) glEnable(GL_CLIP_PLANE2); | ||
| 833 | - if ((clippingPlaneFlags & GL_CLIP_PLANE3) == GL_CLIP_PLANE3) glEnable(GL_CLIP_PLANE3); | ||
| 834 | - if ((clippingPlaneFlags & GL_CLIP_PLANE4) == GL_CLIP_PLANE4) glEnable(GL_CLIP_PLANE4); | ||
| 835 | - if ((clippingPlaneFlags & GL_CLIP_PLANE5) == GL_CLIP_PLANE5) glEnable(GL_CLIP_PLANE5); | ||
| 836 | - } | ||
| 837 | - | ||
| 838 | - /** | ||
| 839 | - * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) | ||
| 840 | - */ | ||
| 841 | - final static void glDisableClipping() | ||
| 842 | - { | ||
| 843 | - glDisable(GL_CLIP_PLANE5); | ||
| 844 | - glDisable(GL_CLIP_PLANE4); | ||
| 845 | - glDisable(GL_CLIP_PLANE3); | ||
| 846 | - glDisable(GL_CLIP_PLANE2); | ||
| 847 | - } | ||
| 848 | } | 764 | } |
| 849 | \ No newline at end of file | 765 | \ No newline at end of file |
java/client/com/mumfrey/liteloader/client/gui/GuiModListEntry.java
| 1 | package com.mumfrey.liteloader.client.gui; | 1 | package com.mumfrey.liteloader.client.gui; |
| 2 | 2 | ||
| 3 | +import static com.mumfrey.liteloader.client.util.GLClippingPlanes.*; | ||
| 3 | import static org.lwjgl.opengl.GL11.*; | 4 | import static org.lwjgl.opengl.GL11.*; |
| 4 | 5 | ||
| 5 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
| @@ -273,9 +274,9 @@ public class GuiModListEntry extends Gui | @@ -273,9 +274,9 @@ public class GuiModListEntry extends Gui | ||
| 273 | String tooltipText = icon.getDisplayText(); | 274 | String tooltipText = icon.getDisplayText(); |
| 274 | if (tooltipText != null) | 275 | if (tooltipText != null) |
| 275 | { | 276 | { |
| 276 | - GuiLiteLoaderPanel.glDisableClipping(); | 277 | + glDisableClipping(); |
| 277 | GuiLiteLoaderPanel.drawTooltip(this.fontRenderer, tooltipText, mouseX, mouseY, 4096, 4096, GuiModListEntry.WHITE, GuiModListEntry.BLEND_HALF & GuiModListEntry.BLACK); | 278 | GuiLiteLoaderPanel.drawTooltip(this.fontRenderer, tooltipText, mouseX, mouseY, 4096, 4096, GuiModListEntry.WHITE, GuiModListEntry.BLEND_HALF & GuiModListEntry.BLACK); |
| 278 | - GuiLiteLoaderPanel.glEnableClipping(); | 279 | + glEnableClipping(); |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | if (icon instanceof IconClickable) this.mouseOverIcon = (IconClickable)icon; | 282 | if (icon instanceof IconClickable) this.mouseOverIcon = (IconClickable)icon; |
| @@ -323,7 +324,7 @@ public class GuiModListEntry extends Gui | @@ -323,7 +324,7 @@ public class GuiModListEntry extends Gui | ||
| 323 | 324 | ||
| 324 | this.mouseOverScrollBar = this.isMouseOver(mouseX, mouseY, xPosition + width - 5, yPos, 5, scrollHeight); | 325 | this.mouseOverScrollBar = this.isMouseOver(mouseX, mouseY, xPosition + width - 5, yPos, 5, scrollHeight); |
| 325 | 326 | ||
| 326 | - GuiLiteLoaderPanel.glEnableClipping(-1, -1, yPos, bottom - 3); | 327 | + glEnableClipping(-1, -1, yPos, bottom - 3); |
| 327 | this.fontRenderer.drawSplitString(this.description, xPosition + 5, yPos - this.scrollBar.getValue(), width - 11, GuiModListEntry.DESCRIPTION_COLOUR); | 328 | this.fontRenderer.drawSplitString(this.description, xPosition + 5, yPos - this.scrollBar.getValue(), width - 11, GuiModListEntry.DESCRIPTION_COLOUR); |
| 328 | } | 329 | } |
| 329 | 330 |
java/client/com/mumfrey/liteloader/client/gui/GuiPanel.java
| @@ -207,15 +207,4 @@ public abstract class GuiPanel extends Gui | @@ -207,15 +207,4 @@ public abstract class GuiPanel extends Gui | ||
| 207 | glAlphaFunc(GL_GREATER, 0.1F); | 207 | glAlphaFunc(GL_GREATER, 0.1F); |
| 208 | glDisable(GL_BLEND); | 208 | glDisable(GL_BLEND); |
| 209 | } | 209 | } |
| 210 | - | ||
| 211 | - | ||
| 212 | - protected static final void glEnableClipping(int xLeft, int xRight, int yTop, int yBottom) | ||
| 213 | - { | ||
| 214 | - GuiLiteLoaderPanel.glEnableClipping(xLeft, xRight, yTop, yBottom); | ||
| 215 | - } | ||
| 216 | - | ||
| 217 | - protected static final void glDisableClipping() | ||
| 218 | - { | ||
| 219 | - GuiLiteLoaderPanel.glDisableClipping(); | ||
| 220 | - } | ||
| 221 | } | 210 | } |
| 222 | \ No newline at end of file | 211 | \ No newline at end of file |
java/client/com/mumfrey/liteloader/client/gui/GuiPanelConfigContainer.java
| 1 | package com.mumfrey.liteloader.client.gui; | 1 | package com.mumfrey.liteloader.client.gui; |
| 2 | 2 | ||
| 3 | +import static com.mumfrey.liteloader.client.util.GLClippingPlanes.*; | ||
| 3 | import static org.lwjgl.opengl.GL11.*; | 4 | import static org.lwjgl.opengl.GL11.*; |
| 4 | import net.minecraft.client.Minecraft; | 5 | import net.minecraft.client.Minecraft; |
| 5 | import net.minecraft.client.gui.GuiButton; | 6 | import net.minecraft.client.gui.GuiButton; |
java/client/com/mumfrey/liteloader/client/gui/GuiPanelMods.java
| 1 | package com.mumfrey.liteloader.client.gui; | 1 | package com.mumfrey.liteloader.client.gui; |
| 2 | 2 | ||
| 3 | +import static com.mumfrey.liteloader.client.util.GLClippingPlanes.*; | ||
| 3 | import static org.lwjgl.opengl.GL11.*; | 4 | import static org.lwjgl.opengl.GL11.*; |
| 4 | 5 | ||
| 5 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
| @@ -7,6 +8,10 @@ import java.util.List; | @@ -7,6 +8,10 @@ import java.util.List; | ||
| 7 | import java.util.Map; | 8 | import java.util.Map; |
| 8 | import java.util.TreeMap; | 9 | import java.util.TreeMap; |
| 9 | 10 | ||
| 11 | +import net.minecraft.client.Minecraft; | ||
| 12 | +import net.minecraft.client.gui.GuiButton; | ||
| 13 | +import net.minecraft.client.resources.I18n; | ||
| 14 | + | ||
| 10 | import org.lwjgl.input.Keyboard; | 15 | import org.lwjgl.input.Keyboard; |
| 11 | 16 | ||
| 12 | import com.mumfrey.liteloader.LiteMod; | 17 | import com.mumfrey.liteloader.LiteMod; |
| @@ -19,10 +24,6 @@ import com.mumfrey.liteloader.launch.LoaderEnvironment; | @@ -19,10 +24,6 @@ import com.mumfrey.liteloader.launch.LoaderEnvironment; | ||
| 19 | import com.mumfrey.liteloader.modconfig.ConfigManager; | 24 | import com.mumfrey.liteloader.modconfig.ConfigManager; |
| 20 | import com.mumfrey.liteloader.modconfig.ConfigPanel; | 25 | import com.mumfrey.liteloader.modconfig.ConfigPanel; |
| 21 | 26 | ||
| 22 | -import net.minecraft.client.Minecraft; | ||
| 23 | -import net.minecraft.client.gui.GuiButton; | ||
| 24 | -import net.minecraft.client.resources.I18n; | ||
| 25 | - | ||
| 26 | /** | 27 | /** |
| 27 | * Mods panel | 28 | * Mods panel |
| 28 | * | 29 | * |
java/client/com/mumfrey/liteloader/client/gui/GuiScrollPanel.java
| 1 | package com.mumfrey.liteloader.client.gui; | 1 | package com.mumfrey.liteloader.client.gui; |
| 2 | 2 | ||
| 3 | +import static com.mumfrey.liteloader.client.util.GLClippingPlanes.*; | ||
| 3 | import static org.lwjgl.opengl.GL11.*; | 4 | import static org.lwjgl.opengl.GL11.*; |
| 4 | import net.minecraft.client.Minecraft; | 5 | import net.minecraft.client.Minecraft; |
| 5 | import net.minecraft.client.gui.GuiButton; | 6 | import net.minecraft.client.gui.GuiButton; |
java/client/com/mumfrey/liteloader/client/util/GLClippingPlanes.java
0 โ 100644
| 1 | +package com.mumfrey.liteloader.client.util; | ||
| 2 | + | ||
| 3 | +import static org.lwjgl.opengl.GL11.*; | ||
| 4 | + | ||
| 5 | +import java.nio.DoubleBuffer; | ||
| 6 | + | ||
| 7 | +import org.lwjgl.BufferUtils; | ||
| 8 | +import org.lwjgl.util.Rectangle; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * OpenGL clipping plane convenience functions. We prefer to clip rectangular GUI regions in Minecraft using | ||
| 12 | + * clipping rather than scissor because scissor is a nuisance to work with, primarily because it works in | ||
| 13 | + * "window" (OpenGL window) coordinates and doesn't respect the current transformation matrix. Using clipping | ||
| 14 | + * planes we can specify clipping edges in "Minecraft screen coordinates", can optionally clip on only one or | ||
| 15 | + * two axes, and also don't need to worry about the current transform. | ||
| 16 | + * | ||
| 17 | + * @author Adam Mummery-Smith | ||
| 18 | + */ | ||
| 19 | +public final class GLClippingPlanes | ||
| 20 | +{ | ||
| 21 | + public enum Plane | ||
| 22 | + { | ||
| 23 | + LEFT(GL_CLIP_PLANE0), | ||
| 24 | + RIGHT(GL_CLIP_PLANE1), | ||
| 25 | + TOP(GL_CLIP_PLANE2), | ||
| 26 | + BOTTOM(GL_CLIP_PLANE3); | ||
| 27 | + | ||
| 28 | + final int plane; | ||
| 29 | + final int sign; | ||
| 30 | + | ||
| 31 | + private Plane(int plane) | ||
| 32 | + { | ||
| 33 | + this.plane = plane; | ||
| 34 | + this.sign = (plane % 2 == 0) ? -1 : 1; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + private static final int STACK_DEPTH = 1; | ||
| 39 | + private static final int STACK_FRAME_SIZE = 128; | ||
| 40 | + | ||
| 41 | + private static DoubleBuffer doubleBuffer = BufferUtils.createByteBuffer(STACK_FRAME_SIZE * STACK_DEPTH).asDoubleBuffer(); | ||
| 42 | + | ||
| 43 | + private static int clippingPlaneFlags = 0; | ||
| 44 | + | ||
| 45 | + private static int totalClippingPlanes = glGetInteger(GL_MAX_CLIP_PLANES); | ||
| 46 | + | ||
| 47 | +// private static int frame = 0; | ||
| 48 | + | ||
| 49 | + static | ||
| 50 | + { | ||
| 51 | + for (int f = 0; f < STACK_DEPTH; f++) | ||
| 52 | + { | ||
| 53 | + // Clipping normals | ||
| 54 | + GLClippingPlanes.doubleBuffer.put(1).put(0).put(0).put(0); | ||
| 55 | + GLClippingPlanes.doubleBuffer.put(-1).put(0).put(0).put(0); | ||
| 56 | + GLClippingPlanes.doubleBuffer.put(0).put(1).put(0).put(0); | ||
| 57 | + GLClippingPlanes.doubleBuffer.put(0).put(-1).put(0).put(0); | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + private GLClippingPlanes() {} | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Get the total number of available clipping planes on the platform | ||
| 65 | + */ | ||
| 66 | + public static int glGetTotalClippingPlanes() | ||
| 67 | + { | ||
| 68 | + return GLClippingPlanes.totalClippingPlanes; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * Enable OpenGL clipping planes (uses planes 0, 1, 2 and 3) | ||
| 73 | + * | ||
| 74 | + * @param left Left edge clip or -1 to not use this plane | ||
| 75 | + * @param right Right edge clip or -1 to not use this plane | ||
| 76 | + * @param top Top edge clip or -1 to not use this plane | ||
| 77 | + * @param bottom Bottom edge clip or -1 to not use this plane | ||
| 78 | + */ | ||
| 79 | + public static void glEnableClipping(int left, int right, int top, int bottom) | ||
| 80 | + { | ||
| 81 | + GLClippingPlanes.clippingPlaneFlags = 0; | ||
| 82 | + | ||
| 83 | + glEnableClipping(GL_CLIP_PLANE0, left, -1); | ||
| 84 | + glEnableClipping(GL_CLIP_PLANE1, right, 1); | ||
| 85 | + glEnableClipping(GL_CLIP_PLANE2, top, -1); | ||
| 86 | + glEnableClipping(GL_CLIP_PLANE3, bottom, 1); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Enable OpenGL clipping planes (uses planes 0, 1, 2 and 3) | ||
| 91 | + * | ||
| 92 | + * @param rect Clipping rectangle | ||
| 93 | + */ | ||
| 94 | + public static void glEnableClipping(Rectangle rect) | ||
| 95 | + { | ||
| 96 | + GLClippingPlanes.clippingPlaneFlags = 0; | ||
| 97 | + | ||
| 98 | + glEnableClipping(GL_CLIP_PLANE0, rect.getX(), -1); | ||
| 99 | + glEnableClipping(GL_CLIP_PLANE1, rect.getX() + rect.getWidth(), 1); | ||
| 100 | + glEnableClipping(GL_CLIP_PLANE2, rect.getY(), -1); | ||
| 101 | + glEnableClipping(GL_CLIP_PLANE3, rect.getY() + rect.getHeight(), 1); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Enable horizontal clipping planes (left and right) (uses planes 0, 1) | ||
| 106 | + * | ||
| 107 | + * @param left Left edge clip or -1 to not use this plane | ||
| 108 | + * @param right Right edge clip or -1 to not use this plane | ||
| 109 | + */ | ||
| 110 | + public static void glEnableHorizontalClipping(int left, int right) | ||
| 111 | + { | ||
| 112 | + glEnableClipping(GL_CLIP_PLANE0, left, -1); | ||
| 113 | + glEnableClipping(GL_CLIP_PLANE1, right, 1); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * Enable vertical clipping planes (top and bottom) (uses planes 2, 3) | ||
| 118 | + * | ||
| 119 | + * @param top Top edge clip or -1 to not use this plane | ||
| 120 | + * @param bottom Bottom edge clip or -1 to not use this plane | ||
| 121 | + */ | ||
| 122 | + public static void glEnableVerticalClipping(int top, int bottom) | ||
| 123 | + { | ||
| 124 | + glEnableClipping(GL_CLIP_PLANE2, top, -1); | ||
| 125 | + glEnableClipping(GL_CLIP_PLANE3, bottom, 1); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * @param plane | ||
| 130 | + * @param value | ||
| 131 | + */ | ||
| 132 | + public static void glEnableClipping(int plane, int value) | ||
| 133 | + { | ||
| 134 | + if (plane < GL_CLIP_PLANE0 || plane >= (GL_CLIP_PLANE0 + GLClippingPlanes.totalClippingPlanes)) | ||
| 135 | + { | ||
| 136 | + throw new IllegalArgumentException("Invalid clipping plane enum specified GL_CLIP_PLANE" + (plane - GL_CLIP_PLANE0)); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + glEnableClipping(plane, value, (plane % 2 == 0) ? -1 : 1); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * @param plane | ||
| 144 | + * @param value | ||
| 145 | + */ | ||
| 146 | + public static void glEnableClipping(Plane plane, int value) | ||
| 147 | + { | ||
| 148 | + glEnableClipping(plane.plane, value, plane.sign); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + /** | ||
| 152 | + * Enable clipping on a particular axis | ||
| 153 | + * | ||
| 154 | + * @param plane Clipping plane to enable | ||
| 155 | + * @param value Clipping plane position | ||
| 156 | + * @param sign Sign of the position | ||
| 157 | + */ | ||
| 158 | + private static void glEnableClipping(int plane, int value, int sign) | ||
| 159 | + { | ||
| 160 | + if (value == -1) return; | ||
| 161 | + | ||
| 162 | + int offset = (plane - GL_CLIP_PLANE0) << 2; | ||
| 163 | + GLClippingPlanes.doubleBuffer.put(offset + 3, value * sign).position(offset); | ||
| 164 | + GLClippingPlanes.clippingPlaneFlags |= plane; | ||
| 165 | + | ||
| 166 | + glClipPlane(plane, GLClippingPlanes.doubleBuffer); | ||
| 167 | + glEnable(plane); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * Enable clipping planes which were previously enabled | ||
| 172 | + */ | ||
| 173 | + public static void glEnableClipping() | ||
| 174 | + { | ||
| 175 | + if ((GLClippingPlanes.clippingPlaneFlags & GL_CLIP_PLANE0) == GL_CLIP_PLANE0) glEnable(GL_CLIP_PLANE0); | ||
| 176 | + if ((GLClippingPlanes.clippingPlaneFlags & GL_CLIP_PLANE1) == GL_CLIP_PLANE1) glEnable(GL_CLIP_PLANE1); | ||
| 177 | + if ((GLClippingPlanes.clippingPlaneFlags & GL_CLIP_PLANE2) == GL_CLIP_PLANE2) glEnable(GL_CLIP_PLANE2); | ||
| 178 | + if ((GLClippingPlanes.clippingPlaneFlags & GL_CLIP_PLANE3) == GL_CLIP_PLANE3) glEnable(GL_CLIP_PLANE3); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) | ||
| 183 | + */ | ||
| 184 | + public static void glDisableClipping() | ||
| 185 | + { | ||
| 186 | + glDisable(GL_CLIP_PLANE3); | ||
| 187 | + glDisable(GL_CLIP_PLANE2); | ||
| 188 | + glDisable(GL_CLIP_PLANE1); | ||
| 189 | + glDisable(GL_CLIP_PLANE0); | ||
| 190 | + } | ||
| 191 | +} |