diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..cc08adb --- /dev/null +++ b/.classpath @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a51af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/.project b/.project new file mode 100644 index 0000000..bea62df --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + Minecraft-Classic-Browser + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..e479558 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home= +jvm.arguments= +offline.mode=false +override.workspace.settings=false +show.console.view=false +show.executions.view=false diff --git a/bin/main/net/PeytonPlayz585/glemu/FixedFunctionShader.class b/bin/main/net/PeytonPlayz585/glemu/FixedFunctionShader.class new file mode 100644 index 0000000..04f1583 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/FixedFunctionShader.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/GLObjectMap.class b/bin/main/net/PeytonPlayz585/glemu/GLObjectMap.class new file mode 100644 index 0000000..0084e78 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/GLObjectMap.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Matrix.class b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix.class new file mode 100644 index 0000000..154c13f Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Matrix2f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix2f.class new file mode 100644 index 0000000..573d7c5 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix2f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Matrix3f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix3f.class new file mode 100644 index 0000000..140cd4f Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix3f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Matrix4f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix4f.class new file mode 100644 index 0000000..74724f7 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Matrix4f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Quaternion.class b/bin/main/net/PeytonPlayz585/glemu/vector/Quaternion.class new file mode 100644 index 0000000..a3cfe6e Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Quaternion.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector.class b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector.class new file mode 100644 index 0000000..c364911 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector2f.class b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector2f.class new file mode 100644 index 0000000..ad0cffd Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector2f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector3f.class b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector3f.class new file mode 100644 index 0000000..aba01b9 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector3f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector4f.class b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector4f.class new file mode 100644 index 0000000..148b035 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/ReadableVector4f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Vector.class b/bin/main/net/PeytonPlayz585/glemu/vector/Vector.class new file mode 100644 index 0000000..e2129c7 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Vector.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Vector2f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Vector2f.class new file mode 100644 index 0000000..2389b9d Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Vector2f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Vector3f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Vector3f.class new file mode 100644 index 0000000..83804e0 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Vector3f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/Vector4f.class b/bin/main/net/PeytonPlayz585/glemu/vector/Vector4f.class new file mode 100644 index 0000000..9290840 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/Vector4f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector2f.class b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector2f.class new file mode 100644 index 0000000..49d201e Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector2f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector3f.class b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector3f.class new file mode 100644 index 0000000..100ce27 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector3f.class differ diff --git a/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector4f.class b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector4f.class new file mode 100644 index 0000000..30fbb49 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/glemu/vector/WritableVector4f.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferArrayGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferArrayGL.class new file mode 100644 index 0000000..438a58a Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferArrayGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferGL.class new file mode 100644 index 0000000..695c9e4 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$BufferGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$FramebufferGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$FramebufferGL.class new file mode 100644 index 0000000..65ff25c Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$FramebufferGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ProgramGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ProgramGL.class new file mode 100644 index 0000000..a610420 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ProgramGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$QueryGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$QueryGL.class new file mode 100644 index 0000000..0878694 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$QueryGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$RenderbufferGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$RenderbufferGL.class new file mode 100644 index 0000000..d64c503 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$RenderbufferGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ShaderGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ShaderGL.class new file mode 100644 index 0000000..2303bc9 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$ShaderGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$TextureGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$TextureGL.class new file mode 100644 index 0000000..b2f8403 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$TextureGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$UniformGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$UniformGL.class new file mode 100644 index 0000000..c845630 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL$UniformGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGL.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL.class new file mode 100644 index 0000000..35f7e93 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGL.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$1.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$1.class new file mode 100644 index 0000000..4592e46 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$1.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$2.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$2.class new file mode 100644 index 0000000..837d5a4 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils$2.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils.class b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils.class new file mode 100644 index 0000000..7de265a Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/LWJGLUtils.class differ diff --git a/bin/main/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.class b/bin/main/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.class new file mode 100644 index 0000000..f513905 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.class differ diff --git a/bin/main/net/PeytonPlayz585/main/MinecraftMain$1.class b/bin/main/net/PeytonPlayz585/main/MinecraftMain$1.class new file mode 100644 index 0000000..b26d303 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/main/MinecraftMain$1.class differ diff --git a/bin/main/net/PeytonPlayz585/main/MinecraftMain.class b/bin/main/net/PeytonPlayz585/main/MinecraftMain.class new file mode 100644 index 0000000..317fdcf Binary files /dev/null and b/bin/main/net/PeytonPlayz585/main/MinecraftMain.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/Base64.class b/bin/main/net/PeytonPlayz585/minecraft/Base64.class new file mode 100644 index 0000000..452aaaf Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/Base64.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$CodecPolicy.class b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$CodecPolicy.class new file mode 100644 index 0000000..1374f35 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$CodecPolicy.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$Context.class b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$Context.class new file mode 100644 index 0000000..62f96f5 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec$Context.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec.class b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec.class new file mode 100644 index 0000000..73b1f73 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/BaseNCodec.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/GLAllocation.class b/bin/main/net/PeytonPlayz585/minecraft/GLAllocation.class new file mode 100644 index 0000000..2a7ba9a Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/GLAllocation.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/GeneralDigest.class b/bin/main/net/PeytonPlayz585/minecraft/GeneralDigest.class new file mode 100644 index 0000000..0917c11 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/GeneralDigest.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/GlStateManager$DisplayList.class b/bin/main/net/PeytonPlayz585/minecraft/GlStateManager$DisplayList.class new file mode 100644 index 0000000..9f93854 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/GlStateManager$DisplayList.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/GlStateManager.class b/bin/main/net/PeytonPlayz585/minecraft/GlStateManager.class new file mode 100644 index 0000000..3d17c2f Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/GlStateManager.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/MinecraftClient.class b/bin/main/net/PeytonPlayz585/minecraft/MinecraftClient.class new file mode 100644 index 0000000..c177612 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/MinecraftClient.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/MinecraftImage.class b/bin/main/net/PeytonPlayz585/minecraft/MinecraftImage.class new file mode 100644 index 0000000..2f8da73 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/MinecraftImage.class differ diff --git a/bin/main/net/PeytonPlayz585/minecraft/SHA1Digest.class b/bin/main/net/PeytonPlayz585/minecraft/SHA1Digest.class new file mode 100644 index 0000000..e4768c6 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/minecraft/SHA1Digest.class differ diff --git a/bin/main/net/PeytonPlayz585/teavm/WebGL2RenderingContext.class b/bin/main/net/PeytonPlayz585/teavm/WebGL2RenderingContext.class new file mode 100644 index 0000000..b59c8de Binary files /dev/null and b/bin/main/net/PeytonPlayz585/teavm/WebGL2RenderingContext.class differ diff --git a/bin/main/net/PeytonPlayz585/teavm/WebGLQuery.class b/bin/main/net/PeytonPlayz585/teavm/WebGLQuery.class new file mode 100644 index 0000000..d4da3ca Binary files /dev/null and b/bin/main/net/PeytonPlayz585/teavm/WebGLQuery.class differ diff --git a/bin/main/net/PeytonPlayz585/teavm/WebGLVertexArray.class b/bin/main/net/PeytonPlayz585/teavm/WebGLVertexArray.class new file mode 100644 index 0000000..7633776 Binary files /dev/null and b/bin/main/net/PeytonPlayz585/teavm/WebGLVertexArray.class differ diff --git a/bin/main/org/lwjgl/opengl/GL11.class b/bin/main/org/lwjgl/opengl/GL11.class new file mode 100644 index 0000000..d0df5e3 Binary files /dev/null and b/bin/main/org/lwjgl/opengl/GL11.class differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..39c47c2 --- /dev/null +++ b/build.gradle @@ -0,0 +1,84 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath 'io.github.zebalu:teavm-gradle-plugin:1.0.0' + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'io.github.zebalu.teavm-gradle-plugin' + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +sourceSets { + main { + java { + srcDir 'src/main/java' + } + } +} + +repositories { + mavenCentral() +} + +dependencies { + /** we use 0.6.1 due to performance issues on 7.0.0 */ + implementation 'org.teavm:teavm-platform:0.6.1' + implementation('org.teavm:teavm-classlib:0.6.1') { + exclude group: 'com.google.code.gson', module: 'gson' + } +} + +teavm { + + compileScopes = null; + minifying = true; + maxTopLevelNames = 10000; + properties = null; + debugInformationGenerated = false; + sourceMapsGenerated = true; + sourceFilesCopied = false; + incremental = false; + transformers = null; + + /** Where to save the result */ + targetDirectory = file("js"); + + /** The directory to monitor to decide if compile is up-to-date or not */ + sourceDirectory = file("src"); + + /** How to name the result file. */ + targetFileName = "app.js"; + + /** Which class holds your public static void main(Strin[] args) method */ + mainClass = 'net.PeytonPlayz585.main.MinecraftMain'; + + /** This will be the name of your main method after compilation. */ + entryPointName = 'main'; + + classesToPreserve = null; + stopOnErrors = false; + optimizationLevel = "ADVANCED"; //org.teavm.vm.TeaVMOptimizationLevel.SIMPLE; + fastGlobalAnalysis = false; + targetType = "JAVASCRIPT"; //org.teavm.tooling.TeaVMTargetType.JAVASCRIPT; + cacheDirectory = null; + wasmVersion = "V_0x1"; //org.teavm.backend.wasm.render.WasmBinaryVersion.V_0x1; + minHeapSize = 4; + maxHeapSize = 128; + outOfProcess = false; + processMemory = 512; + longjmpSupported = true; + heapDump = false; + + /** Add name of configurations here where to look for jarfiles. */ + includeJarsFrom = []; + + /** By default teavmc taskd epends on javaCompile task, unless this varaibale is true. */ + skipJavaCompile = false; +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..cc4fdc2 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6ce793f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..9b215f0 --- /dev/null +++ b/js/app.js @@ -0,0 +1,624 @@ +"use strict"; +var main;(function(){ +var $rt_seed=2463534242;function $rt_nextId(){var x=$rt_seed;x^=x<<13;x^=x>>17;x^=x<<5;$rt_seed=x;return x;}function $rt_compare(a,b){return a>b?1:a0){var i=0;do {data[i]=null;i=i+1|0;}while(i=0;i=i -1|0){if(dimensions[i]===0){first=i;break;}}if(first>0){for(i=0;i=0?packages[prefixIndex]:"";packages[j] +=prefix+data[i++]+".";}$rt_packageData=packages;}function $rt_metadata(data){var packages=$rt_packageData;var i=0;while(i=0){m.name=packages[packageIndex]+m.name;}}m.binaryName="L"+m.name+";";var superclass=data[i++];m.superclass=superclass!==0?superclass:null;m.supertypes=data[i++];if(m.superclass){m.supertypes.push(m.superclass);cls.prototype +=Object.create(m.superclass.prototype);}else {cls.prototype={};}var flags=data[i++];m.enum=(flags&8)!==0;m.flags=flags;m.primitive=false;m.item=null;cls.prototype.constructor=cls;cls.classObject=null;m.accessLevel=data[i++];var clinit=data[i++];cls.$clinit=clinit!==0?clinit:function(){};var virtualMethods=data[i++];if(virtualMethods!==0){for(var j=0;j0){clsName+="[]";}return clsName;}function Long(lo,hi){this.lo=lo|0;this.hi=hi|0;}Long.prototype.__teavm_class__=function(){return "long";};Long.prototype.toString +=function(){var result=[];var n=this;var positive=Long_isPositive(n);if(!positive){n=Long_neg(n);}var radix=new Long(10,0);do {var divRem=Long_divRem(n,radix);result.push(String.fromCharCode(48+divRem[1].lo));n=divRem[0];}while(n.lo!==0||n.hi!==0);result=(result.reverse()).join('');return positive?result:"-"+result;};Long.prototype.valueOf=function(){return Long_toNumber(this);};var Long_ZERO=new Long(0,0);var Long_MAX_NORMAL=1<<18;function Long_fromInt(val){return val>=0?new Long(val,0):new Long(val, -1);}function Long_fromNumber(val) +{if(val>=0){return new Long(val|0,val/0x100000000|0);}else {return Long_neg(new Long( -val|0, -val/0x100000000|0));}}function Long_toNumber(val){var lo=val.lo;var hi=val.hi;if(lo<0){lo+=0x100000000;}return 0x100000000*hi+lo;}var $rt_imul=Math.imul||function(a,b){var ah=a>>>16&0xFFFF;var al=a&0xFFFF;var bh=b>>>16&0xFFFF;var bl=b&0xFFFF;return al*bl+(ah*bl+al*bh<<16>>>0)|0;};var $rt_udiv=function(a,b){if(a<0){a+=0x100000000;}if(b<0){b+=0x100000000;}return a/b|0;};var $rt_umod=function(a,b){if(a<0){a+=0x100000000;}if +(b<0){b+=0x100000000;}return a%b|0;};function $rt_setCloneMethod(target, f){target.dE=f;} +function $rt_cls(cls){return Fi(cls);} +function $rt_str(str) {if (str === null) {return null;}var characters = $rt_createCharArray(str.length);var charsBuffer = characters.data;for (var i = 0; i < str.length; i = (i + 1) | 0) {charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;}return H5(characters);} +function $rt_ustr(str) {if (str === null) {return null;}var data = str.t.data;var result = "";for (var i = 0; i < data.length; i = (i + 1) | 0) {result += String.fromCharCode(data[i]);}return result;} +function $rt_objcls() { return C; } +function $rt_nullCheck(val) {if (val === null) {$rt_throw(Ir());}return val;} +function $rt_intern(str) {return str;}function $rt_getThread(){return null;} +function $rt_setThread(t){} +function $rt_createException(message){return Is(message);} +function $rt_createStackElement(className,methodName,fileName,lineNumber){return null;} +function $rt_setStack(e,stack){} +var A=Object.create(null); +var D=$rt_throw;var C6=$rt_compare;var It=$rt_nullCheck;var Bt=$rt_cls;var Bu=$rt_createArray;var H$=$rt_isInstance;var GH=$rt_nativeThread;var G7=$rt_suspending;var If=$rt_resuming;var H8=$rt_invalidPointer;var B=$rt_s;var S=$rt_eraseClinit;var Dm=$rt_imul;var U=$rt_wrapException; +function C(){this.$id$=0;} +function B1(a){return Fi(a.constructor);} +function HF(a){var b,c,d,e,f,g,h,i;b=F(F(N(),D6(B1(a))),B(0));c=EB(a);if(!c)d=B(1);else{if(!c)e=32;else{f=0;e=c>>>16;if(e)f=16;else e=c;g=e>>>8;if(!g)g=e;else f=f|8;e=g>>>4;if(!e)e=g;else f=f|4;g=e>>>2;if(!g)g=e;else f=f|2;if(g>>>1)f=f|1;e=(32-f|0)-1|0;}g=(((32-e|0)+4|0)-1|0)/4|0;h=$rt_createCharArray(g);i=h.data;e=(g-1|0)*4|0;g=0;while(e>=0){f=g+1|0;i[g]=CL(c>>>e&15,16);e=e-4|0;g=f;}d=H5(h);}return M(F(b,d));} +function EB(a){var b,c;b=a;if(!b.$id$){c=$rt_nextId();b.$id$=c;}return a.$id$;} +function HT(a){var b,c,d;if(!H$(a,BT)&&a.constructor.$meta.item===null){b=new CV;H(b);D(b);}b=GX(a);c=b;d=$rt_nextId();c.$id$=d;return b;} +function V(){C.call(this);} +var Iu=null;var Iv=null;var Iw=null;var Ix=null;var Iy=null;var Iz=null;var IA=null;var IB=null;var IC=null;var ID=null;var IE=null;var IF=0;var IG=0;function Ft(b){var c,d,e,f,g,$p,$z;$p=0;if(If()){var $T=GH();$p=$T.l();g=$T.l();f=$T.l();e=$T.l();d=$T.l();c=$T.l();b=$T.l();}_:while(true){switch($p){case 0:FQ();Fj();EF();Eu();E$();En();Gp();Fk();Eo();E7();FI();EC();EA();Ey();FT();F2();ER();c=window.classicConfig;if(c===null)d=null;else{d=Bu(Br,c.length);b=d.data;e=0;f=b.length;while(e=0&&b=c)break a;e=b[d];a.b7=(31*a.b7|0)+e|0;d=d+1|0;}}}return a.b7;} +function E0(a){var b,c,d,e,f,g,h,i,j,k;if(CF(a))return a;b=$rt_createIntArray(a.t.data.length).data;c=0;d=0;while(d=e)break a;g=d[f];B5(b,B(6));Ga(b,g);f=f+1|0;}}}if(a.bY!==null&&a.bY!==a){B5(b,B(7));D5(a.bY,b);}} +function Bq(){BP.call(this);} +function BS(){Bq.call(this);} +function FF(){BS.call(this);} +function Ct(){var a=this;C.call(a);a.j=null;a.z=0;} +function Fd(a,b,c){return FV(a,a.z,b,c);} +function FV(a,b,c,d){var e,f,g,h,i,j,k;e=1;if(c<0){e=0;c= -c;}a:{if(cc){k=h;break b;}i=i+1|0;if(k>j)break;h=k;}}if(!e)i=i+1|0;Bd(a,b,b+i|0);if(e)e=b;else{f=a.j.data;e=b+1|0;f[b]=45;}while(true){if(k<=0)break a;f=a.j.data;b=e+1|0;f[e]=CL(c/k|0,d);c=c%k|0;k=k/d|0;e=b;}}}return a;} +function E8(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o;d=C6(c,0.0);if(!d){Bd(a,b,b+3|0);e=a.j.data;d=b+1|0;e[b]=48;e=a.j.data;b=d+1|0;e[d]=46;a.j.data[b]=48;return a;}if(!d){Bd(a,b,b+4|0);e=a.j.data;d=b+1|0;e[b]=45;e=a.j.data;b=d+1|0;e[d]=48;e=a.j.data;d=b+1|0;e[b]=46;a.j.data[d]=48;return a;}if(isNaN(c)?1:0){Bd(a,b,b+3|0);e=a.j.data;d=b+1|0;e[b]=78;e=a.j.data;b=d+1|0;e[d]=97;a.j.data[b]=78;return a;}if(!isFinite(c)?1:0){if(d>0){Bd(a,b,b+8|0);d=b;}else{Bd(a,b,b+9|0);e=a.j.data;d=b+1|0;e[b]=45;}e=a.j.data;b=d+1|0;e[d] +=73;e=a.j.data;d=b+1|0;e[b]=110;e=a.j.data;b=d+1|0;e[d]=102;e=a.j.data;d=b+1|0;e[b]=105;e=a.j.data;b=d+1|0;e[d]=110;e=a.j.data;d=b+1|0;e[b]=105;e=a.j.data;b=d+1|0;e[d]=116;a.j.data[b]=121;return a;}f=IL;EW(c,f);d=f.cF;g=f.c7;h=f.du;i=1;j=1;if(h){h=1;j=2;}k=9;l=G5(d);if(l>0)k=k-l|0;if(g<7&&g>=(-3)){if(g>=0){i=g+1|0;k=BA(k,i+1|0);g=0;}else if(g<0){d=d/IM.data[ -g]|0;k=k-g|0;g=0;}}if(g){j=j+2|0;if(!(g>(-10)&&g<10))j=j+1|0;if(g<0)j=j+1|0;}if(g&&k==i)k=k+1|0;Bd(a,b,b+(j+k|0)|0);if(!h)h=b;else{e=a.j.data;h=b+1|0;e[b] +=45;}m=100000000;n=0;while(n=0)d=b;else{g= -g;e=a.j.data;d=b+1|0;e[b]=45;}if(g<10)l=d;else{e=a.j.data;l=d+1|0;e[d]=(48+(g/10|0)|0)&65535;}a.j.data[l]=(48+(g%10|0)|0)&65535;}return a;} +function G5(b){var c,d,e;if(!(b%1000000000|0))return 9;c=0;d=1;if(!(b%100000000|0)){c=8;d=100000000;}e=d*10000|0;if(b%e|0)e=d;else c=c|4;d=e*100|0;if(b%d|0)d=e;else c=c|2;if(!(b%(d*10|0)|0))c=c|1;return c;} +function Bd(a,b,c){var d,e;d=a.z-b|0;D$(a,(a.z+c|0)-b|0);e=d-1|0;while(e>=0){a.j.data[c+e|0]=a.j.data[b+e|0];e=e+(-1)|0;}a.z=a.z+(c-b|0)|0;} +function Cy(){} +function EE(){Ct.call(this);} +function N(){var a=new EE();HE(a);return a;} +function HE(a){a.j=$rt_createCharArray(16);} +function F(a,b){CM(a,a.z,b);return a;} +function J(a,b){Fd(a,b,10);return a;} +function Hn(a,b){C5(a,a.z,b);return a;} +function EG(a,b){Dq(a,a.z,b);return a;} +function ES(a,b){DY(a,a.z,b);return a;} +function C5(a,b,c){E8(a,b,c);return a;} +function DY(a,b,c){CM(a,b,c===null?B(8):c.dq());return a;} +function Dq(a,b,c){Bd(a,b,b+1|0);a.j.data[b]=c;return a;} +function CM(a,b,c){var d,e,f;if(b>=0&&b<=a.z){a:{if(c===null)c=B(8);else if(CF(c))break a;D$(a,a.z+R(c)|0);d=a.z-1|0;while(d>=b){a.j.data[d+R(c)|0]=a.j.data[d];d=d+(-1)|0;}a.z=a.z+R(c)|0;d=0;while(dc){f=new O;G(f,B(9));D(f);}while(b=1073741823?2147483647:BA(b,BA(a.j.data.length*2|0,5));a.j=Dr(a.j,b);}} +function G1(a,b,c){return DY(a,b,c);} +function GI(a,b,c){return Dq(a,b,c);} +function Ho(a,b,c){return C5(a,b,c);} +function HX(a,b,c){return CM(a,b,c);} +function BR(){C.call(this);} +function C0(){BR.call(this);} +var IN=null;function EF(){IN=Bt($rt_intcls());} +function BI(){BS.call(this);} +function IO(a){var b=new BI();Dp(b,a);return b;} +function Dp(a,b){G(a,b);} +function Fs(){BI.call(this);} +function IP(a){var b=new Fs();HH(b,a);return b;} +function HH(a,b){Dp(a,b);} +function Fa(){BI.call(this);} +function IQ(a){var b=new Fa();HQ(b,a);return b;} +function HQ(a,b){Dp(a,b);} +function Bc(){BP.call(this);} +function IR(){var a=new Bc();H(a);return a;} +function H(a){a.cf=1;a.co=1;} +function P(){Bc.call(this);} +function Is(a){var b=new P();Hx(b,a);return b;} +function Hx(a,b){G(a,b);} +function Be(){} +function Bv(){} +function Ed(){} +function DO(){} +function DG(){} +function Dl(){} +function DU(){} +function DR(){} +function DX(){} +function Fc(){C.call(this);} +function GF(a,b,c){a.fz($rt_str(b),Cw(c,"handleEvent"));} +function GR(a,b,c){a.fc($rt_str(b),Cw(c,"handleEvent"));} +function Hl(a,b){return a.gQ(b);} +function Hs(a,b,c,d){a.fN($rt_str(b),Cw(c,"handleEvent"),d?1:0);} +function Hu(a,b){return !!a.fK(b);} +function HM(a){return a.gH();} +function GU(a,b,c,d){a.g6($rt_str(b),Cw(c,"handleEvent"),d?1:0);} +function Gy(){C.call(this);} +function EO(){C.call(this);} +function W(){C.call(this);} +var IH=null;var IS=0;var IT=null;var IU=null;var IV=null;var IW=null;var IX=null;var IY=0;var IZ=0;var I0=null;function H_(){H_=S(W);HB();} +function HB(){IH=null;IS=0;IT=$rt_createIntArray(4);IU=new Uint8Array(new ArrayBuffer(4194304));IV=new Float32Array(4);IW=new Float32Array(9);IX=new Float32Array(16);IY=(-1);IZ=0;I0=new Int32Array(new ArrayBuffer(2100000));} +function CI(){W.call(this);} +function Gg(){CI.call(this);} +function D3(){C.call(this);} +var I1=null;function Gd(b){var c,d,e,f,g,h,i,j,k,l,m,n;c=b.data;d=new CX;e=c.length;d.de=b;d.bU=0;d.ex=0;d.c2=0+e|0;f=Ia(d);c=$rt_createByteArray(8);Cq(f,c);g=new Br;Eb(B(10));h=Fn(I2,E0(B(10)));if(h===null){d=new DK;H(d);d.eD=B(10);D(d);}i=EL(h,FZ(c,0,c.data.length));if(F0(i)&&!i.p&&i.N==i.cc)g.t=F5(i);else{g.t=$rt_createCharArray(L(i));Gb(i,g.t);}if(!Bo(B(11),g)){d=new Q;G(d,B(12));D(d);}B9(f);i=new C7;f=new Di;j=new D7;j.K=GP();j.cs=0;k=Gw(j,15,0);if(k){d=new C_;G(d,M(F(F(J(N(),k),B(5)),j.o)));D(d);}Ei(f, +d);f.cn=0;f.bK=0;f.di=1;f.dA=0;f.d9=$rt_createByteArray(1);f.d_=$rt_createByteArray(512);f.M=j;f.bG=$rt_createByteArray(512);f.di=1;f.dA=1;EV(i,f);j=new C$;j.V=$rt_createByteArray(4);j.bc=0;j.y=$rt_createIntArray(80);C3(j);while(true){f=B9(i);if(!Bo(B(13),f)){if(Em(i)<=0&&Bo(B(14),f))return;d=new Q;G(d,B(12));D(d);}g=B9(i);l=$rt_createByteArray(20);m=$rt_createByteArray(20);Cq(i,l);k=El(i);n=$rt_createByteArray(k);Cq(i,n);if(Fu(I1,g))continue;a:{Fq(j,n,0,k);Fw(j,m,0);if(l===m)k=1;else{if(l!==null&&m!==null) +{b=l.data;c=m.data;k=b.length;if(k==c.length){e=0;while(e>10&1023)&65535;} +function Do(b){return (56320|b&1023)&65535;} +function Ef(b){return (String.fromCharCode(b)).toUpperCase().charCodeAt(0);} +function CL(b,c){if(c>=2&&c<=36&&b>24;c=c+1|0;}Ge(a.dg,B(17));}} +function G2(a){Gv(a);} +function D0(){} +function Cn(){} +function BN(){C.call(this);} +function CX(){var a=this;BN.call(a);a.de=null;a.bU=0;a.ex=0;a.c2=0;} +function HI(a,b,c,d){var e,f,g,h,i;e=Ba(d,a.c2-a.bU|0);f=0;while(f=0&&c<=(b.data.length-d|0)){while(d>0){f=a.bj.bX(b,c,d);if(f<0){e=new BM;H(e);D(e);}c=c+f|0;d=d-f|0;}return;}e=new O;H(e);D(e);} +function El(a){var b;if(Dg(a,4)<0){b=new BM;H(b);D(b);}return (a.ba.data[0]&255)<<24|(a.ba.data[1]&255)<<16|(a.ba.data[2]&255)<<8|a.ba.data[3]&255;} +function Gh(a){var b;if(Dg(a,2)<0){b=new BM;H(b);D(b);}return ((a.ba.data[0]&255)<<8|a.ba.data[1]&255)&65535;} +function B9(a){return E9(a,Gh(a));} +function E9(a,b){var c,d;c=$rt_createByteArray(b);d=$rt_createCharArray(b);Gt(a,c,0,b);return HD(c,d,0,b);} +function HD(b,c,d,e){var f,g,h,i,j,k,l,m,n,o;f=0;g=0;a:{while(f=e){m=new BC;G(m,B(18));D(m);}k=j+1|0;j=h[d+j|0];if((j&192)!=128){m=new BC;G(m,B(19));D(m);}n=g+1|0;i[g]=((l&31)<<6|j&63)&65535;g=n;j=k;}else{if((l&240)!=224){m=new BC;G(m,B(19));D(m);}f=j+1|0;if(f>=e){m=new BC;G(m,B(19));D(m);}n=h[d+j|0];j=f+1|0;o=h[d+f|0];if((n&192)!=128)break a;if((o&192)!=128)break a;f=g+1|0;i[g]=((l&15)<<12|(n&63)<<6|o&63) +&65535;g=f;}f=j;}return HN(c,0,g);}m=new BC;G(m,B(19));D(m);} +function Ck(){var a=this;C.call(a);a.dP=null;a.d7=null;} +function Eb(b){var c,d;if(CF(b))D(E4(b));if(!Gu(By(b,0)))D(E4(b));c=1;while(c=48&&b<=57)&&!(b>=97&&b<=122)&&b<65&&b>90?0:1;} +function EL(a,b){var c,d,$$je;a:{try{b=F8(Ff(Fe(Ev(a),I6),I6),b);}catch($$e){$$je=U($$e);if($$je instanceof BB){c=$$je;break a;}else{throw $$e;}}return b;}d=new DD;d.cf=1;d.co=1;d.c1=B(20);d.bY=c;D(d);} +function Di(){var a=this;BL.call(a);a.M=null;a.bG=null;a.cn=0;a.bK=0;a.di=0;a.dA=0;a.d9=null;a.d_=null;} +function Hj(a,b,c,d){var e,f,g;if(a.cn){e=new Q;G(e,B(21));D(e);}if(b===null){e=new BD;H(e);D(e);}if(c>=0&&d>=0&&d<=(b.data.length-c|0)){if(!d)return 0;if(a.bK)return (-1);f=0;EP(a.M,b,c,d);a:{while(!a.bK){if(!a.M.f)Fm(a);b:{g=E2(a.M,0);f=f+(a.M.b2-c|0)|0;c=a.M.b2;switch(g){case -3:e=new Q;G(e,a.M.o);D(e);case 1:case 2:break;default:break b;}a.bK=1;if(g==2)return (-1);}if(!a.M.R)break a;}}return f;}e=new O;H(e);D(e);} +function H2(a){var b;if(!a.cn){if(!a.bK)return 1;return 0;}b=new Q;G(b,B(21));D(b);} +function Fm(a){var b,c;if(a.cn){b=new Q;G(b,B(21));D(b);}a:{c=a.bj.bX(a.bG,0,a.bG.data.length);if(c==(-1)){if(a.M.Z.x)break a;if(EZ(a.M))break a;a.bG.data[0]=0;c=1;}Gl(a.M,a.bG,0,c,1);return;}if(Long_ne(a.M.Z.b4,Long_fromInt(-1))){b=new Q;G(b,B(22));D(b);}b=new BM;G(b,B(23));D(b);} +function CP(){var a=this;C.call(a);a.V=null;a.bc=0;a.bt=Long_ZERO;} +function B7(a,b){var c,d;c=a.V.data;d=a.bc;a.bc=d+1|0;c[d]=b;if(a.bc==a.V.data.length){CT(a,a.V,0);a.bc=0;}a.bt=Long_add(a.bt,Long_fromInt(1));} +function Fq(a,b,c,d){a:{while(a.bc){if(d<=0)break a;B7(a,b.data[c]);c=c+1|0;d=d+(-1)|0;}}while(d>a.V.data.length){CT(a,b,c);c=c+a.V.data.length|0;d=d-a.V.data.length|0;a.bt=Long_add(a.bt,Long_fromInt(a.V.data.length));}while(d>0){B7(a,b.data[c]);c=c+1|0;d=d+(-1)|0;}} +function F4(a){var b;b=Long_shl(a.bt,3);B7(a,(-128));while(a.bc){B7(a,0);}EK(a,b);CN(a);} +function C$(){var a=this;CP.call(a);a.bO=0;a.bP=0;a.bQ=0;a.bR=0;a.bS=0;a.y=null;a.bx=0;} +function CT(a,b,c){var d,e;d=b.data;b=a.y.data;e=a.bx;a.bx=e+1|0;b[e]=(d[c]&255)<<24|(d[c+1|0]&255)<<16|(d[c+2|0]&255)<<8|d[c+3|0]&255;if(a.bx==16)CN(a);} +function BH(a,b,c,d){c=c.data;c[d]=b>>>24<<24>>24;c[d+1|0]=b>>>16<<24>>24;c[d+2|0]=b>>>8<<24>>24;c[d+3|0]=b<<24>>24;} +function EK(a,b){if(a.bx>14)CN(a);a.y.data[14]=b.hi;a.y.data[15]=Long_and(b,Long_fromInt(-1)).lo;} +function Fw(a,b,c){F4(a);BH(a,a.bO,b,c);BH(a,a.bP,b,c+4|0);BH(a,a.bQ,b,c+8|0);BH(a,a.bR,b,c+12|0);BH(a,a.bS,b,c+16|0);C3(a);return 20;} +function C3(a){var b;a.bt=Long_ZERO;a.bc=0;b=0;while(b>>(32-c|0);} +function CN(a){var b,c,d,e,f,g,h,i,j;b=16;while(b<=79){a.y.data[b]=Bi(a,a.y.data[b-3|0]^a.y.data[b-8|0]^a.y.data[b-14|0]^a.y.data[b-16|0],1);b=b+1|0;}c=a.bO;d=a.bP;e=a.bQ;f=a.bR;g=a.bS;h=0;while(h<=19){i=(((Bi(a,c,5)+(d&e|(d^(-1))&f)|0)+g|0)+a.y.data[h]|0)+1518500249|0;b=Bi(a,d,30);h=h+1|0;g=f;f=e;e=b;d=c;c=i;}j=20;while(j<=39){i=(((Bi(a,c,5)+DL(a,d,e,f)|0)+g|0)+a.y.data[j]|0)+1859775393|0;b=Bi(a,d,30);j=j+1|0;g=f;f=e;e=b;d=c;c=i;}h=40;while(h<=59){i=(((Bi(a,c,5)+(d&e|d&f|e&f)|0)+g|0)+a.y.data[h]|0)+(-1894007588) +|0;b=Bi(a,d,30);h=h+1|0;g=f;f=e;e=b;d=c;c=i;}j=60;while(j<=79){i=(((Bi(a,c,5)+DL(a,d,e,f)|0)+g|0)+a.y.data[j]|0)+(-899497514)|0;b=Bi(a,d,30);j=j+1|0;g=f;f=e;e=b;d=c;c=i;}a.bO=a.bO+c|0;a.bP=a.bP+d|0;a.bQ=a.bQ+e|0;a.bR=a.bR+f|0;a.bS=a.bS+g|0;a.bx=0;b=0;while(b!=a.y.data.length){a.y.data[b]=0;b=b+1|0;}} +function Fv(){C.call(this);} +function Dr(b,c){var d,e,f,g;b=b.data;d=$rt_createCharArray(c);e=d.data;f=Ba(c,b.length);g=0;while(g=1073741824)return 1073741824;if(!b)return 16;c=b-1|0;b=c|c>>1;b=b|b>>2;b=b|b>>4;b=b|b>>8;return (b|b>>16)+1|0;} +function DV(a){a.cQ=a.J.data.length*a.dF|0;} +function Fu(a,b){return Dc(a,b)===null?0:1;} +function Fn(a,b){var c;c=Dc(a,b);if(c===null)return null;return c.b9;} +function Dc(a,b){var c,d;if(b===null)c=Ec(a);else{d=Dt(b);c=Dd(a,b,d&(a.J.data.length-1|0),d);}return c;} +function Dd(a,b,c,d){var e,f;e=a.J.data[c];while(e!==null){if(e.cC==d){f=e.c4;if(b!==f&&!Bo(b,f)?0:1)break;}e=e.bZ;}return e;} +function Ec(a){var b;b=a.J.data[0];while(b!==null&&b.c4!==null){b=b.bZ;}return b;} +function G$(a,b,c){return Cr(a,b,c);} +function Cr(a,b,c){var d,e,f,g;if(b===null){d=Ec(a);if(d===null){a.ck=a.ck+1|0;d=DS(a,null,0,0);e=a.bM+1|0;a.bM=e;if(e>a.cQ)D4(a);}}else{e=Dt(b);f=e&(a.J.data.length-1|0);d=Dd(a,b,f,e);if(d===null){a.ck=a.ck+1|0;d=DS(a,b,f,e);e=a.bM+1|0;a.bM=e;if(e>a.cQ)D4(a);}}g=d.b9;d.b9=c;return g;} +function DS(a,b,c,d){var e,f;e=new BE;f=null;e.c4=b;e.b9=f;e.cC=d;e.bZ=a.J.data[c];a.J.data[c]=e;return e;} +function E_(a,b){var c,d,e,f,g,h,i;c=FM(!b?1:b<<1);d=Bu(BE,c);e=d.data;f=0;c=c-1|0;while(f0&&e){f=$rt_createByteArray(a.f+d|0);Z(a.q,a.b,f,0,a.f);Z(b,c,f,a.f,d);a.q=f;a.b=0;a.f=a.f+d|0;}else{a.q=b;a.b=c;a.f=d;}} +function D7(){Cj.call(this);this.cs=0;} +function Gw(a,b,c){var d;a.cs=0;d=new CE;d.b4=Long_fromInt(-1);d.X=(-1);d.cz=$rt_createByteArray(4);d.r=null;d.I=null;d.d=a;a.Z=d;d=a.Z;if(c)b= -b;return Er(d,b);} +function E2(a,b){var c;if(a.Z===null)return (-2);c=FC(a.Z,b);if(c==1)a.cs=1;return c;} +function EZ(a){return a.Z.m!=12?0:1;} +function Gn(){Ck.call(this);} +function Hv(){var a=new Gn();HA(a);return a;} +function HA(a){var b,c,d,e;b=Bu(Br,0);c=b.data;Eb(B(10));d=c.length;e=0;while(e=b.c9){b.eb=a;b.cK=c.dE();b.ef=2.0;b.c9=4.0;return b;}f=new X;G(f,B(25));D(f);} +function BJ(){var a=this;C.call(a);a.cc=0;a.p=0;a.N=0;a.bN=0;} +function I8(a){var b=new BJ();C4(b,a);return b;} +function C4(a,b){a.bN=(-1);a.cc=b;a.N=b;} +function GJ(a){return a.cc;} +function Hp(a){return a.p;} +function Bf(a,b){var c;if(b>=0&&b<=a.N){a.p=b;if(b=a.N?0:1;} +function CJ(){var a=this;BJ.call(a);a.cR=0;a.cL=null;a.eF=null;} +function FZ(b,c,d){var e,f,g;e=b.data;f=new Dx;g=e.length;d=c+d|0;C4(f,g);f.eF=I9;f.cR=0;f.cL=b;f.p=c;f.N=d;f.dS=0;f.cE=0;return f;} +function Gq(a,b,c,d){var e,f,g,h,i,j,k;if(c>=0){e=b.data;f=e.length;if(cf){h=new O;G(h,M(J(F(J(F(N(),B(29)),g),B(30)),f)));D(h);}if(L(a)=0){f=b.data;g=f.length;if(cg){e=new O;G(e,M(J(F(J(F(N(),B(35)),h),B(30)),g)));D(e);}if(d<0){e=new O;G(e,M(F(J(F(N(),B(31)),d),B(32))));D(e);}h=a.p+a.cR|0;i=0;while(i=0)return HG(0,b,$rt_createCharArray(b),0,b,0);c=new X;G(c,M(J(F(N(),B(36)),b)));D(c);} +function Gc(b,c,d){return HG(0,b.data.length,b,c,c+d|0,0);} +function Dh(a,b,c,d){var e,f,g,h,i,j,k;if(c>=0){e=b.data;f=e.length;if(cf){h=new O;G(h,M(J(F(J(F(N(),B(37)),g),B(30)),f)));D(h);}if(L(a)=0){f=b.data;g=f.length;if(cg){e=new O;G(e,M(J(F(J(F(N(),B(38)),h),B(30)),g)));D(e);}if(d<0){e=new O;G(e,M(F(J(F(N(),B(31)),d),B(32))));D(e);}h=a.p;i=0;while(i=0&&cR(b)){f=new O;G(f,M(J(F(J(F(N(),B(38)),d),B(39)),R(b))));D(f);}if(c>d){b=new O;G(b,M(J(F(J(F(N(),B(40)),c),B(41)),d)));D(b);}g=a.p;while(c=0&&e>=0&&f>=0&&(c+f|0)<=F3(b)&&(e+f|0)<=F3(d)){a:{b:{if(b!==d){g=CZ(B1(b));h=CZ(B1(d));if(g!==null&&h!==null){if(g===h)break b;if(!BY(g)&&!BY(h)){i=b;j=0;k=c;while(j>4)+1|0;if(b<48)b=b&15;}if(b>=8&&b<=15){if(a.S!==null&&a.cV!=b){D1(a.S);a.S=null;}a.cV=b;c=new BX;d=a.d;b=1<>4)+8|0)>a.cV){a.m=13;a.d.o +=B(51);continue i;}a.d.K=GP();if(h&32){a.m=2;break d;}a.m=7;continue i;}break m;}try{d=Bl(a,4,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null)a.r.dN=a.i;if(a.A&512)BQ(a,4,a.i);a.m=17;}try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null){a.r.er=a.i.lo&255;a.r.dl=a.i.lo>>8&255;}if(a.A&512)BQ(a,2,a.i);a.m=18;}if(a.A&1024){try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;} +else{throw $$e;}}if(a.r!==null)a.r.bL=$rt_createByteArray(a.i.lo&65535);if(a.A&512)BQ(a,2,a.i);}else if(a.r!==null)a.r.bL=null;a.m=19;}if(a.A&1024)x:{try{d=Ex(a,d,c);if(a.r===null)break x;f=Cg(a.I);i=f.data;a.I=null;b=i.length;if(b!=a.r.bL.data.length){a.d.o=B(52);a.m=13;continue i;}Z(f,0,a.r.bL,0,b);break x;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}}else if(a.r!==null)a.r.bL=null;a.m=20;}y:{if(a.A&2048){z:{try{d=D9(a,d,c);if(a.r===null)break z;a.r.dd=Cg(a.I);break z;} +catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break h;}else{throw $$e;}}}try{a.I=null;break y;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break h;}else{throw $$e;}}}else if(a.r!==null)a.r.dd=null;}a.m=21;}ba:{if(a.A&4096){bb:{try{d=D9(a,d,c);if(a.r===null)break bb;a.r.dm=Cg(a.I);break bb;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break g;}else{throw $$e;}}}try{a.I=null;break ba;}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;break g;}else{throw $$e;}}}else if(a.r!==null)a.r.dm= +null;}a.m=22;}if(a.A&512){try{d=Bl(a,2,d,c);}catch($$e){$$je=U($$e);if($$je instanceof Y){e=$$je;return e.P;}else{throw $$e;}}if(a.r!==null)a.r.eG=Long_and(a.i,Long_fromInt(65535)).lo;if(Long_ne(a.i,Long_and(a.d.K.cY(),Long_fromInt(65535)))){a.m=13;a.d.o=B(53);a.bI=5;continue;}}a.d.K=Hb();a.m=7;}return d;}return e.P;}return e.P;}a.m=12;}return 1;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));f=a.d.q.data;e=a.d;d=e.b;e.b=d+1|0;a.i=Long_and(Long_fromInt((f[d]&255)<<24),new Long(4278190080, 0));a.m +=3;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;d=e.b;e.b=d+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[d]&255)<<16),Long_fromInt(16711680)));a.m=4;d=c;}if(!a.d.f)return d;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e=a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt((f[b]&255)<<8),Long_fromInt(65280)));a.m=5;}if(!a.d.f)return c;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));g=a.i;f=a.d.q.data;e= +a.d;b=e.b;e.b=b+1|0;a.i=Long_add(g,Long_and(Long_fromInt(f[b]),Long_fromInt(255)));a.d.K.dy(a.i);a.m=6;return 2;}if(b==4&&a.m==14)return 0;return (-2);} +function Bl(a,b,c,d){var e,f,g,h;if(a.X==(-1)){a.X=b;a.i=Long_ZERO;}while(true){if(a.X<=0){if(b==2)a.i=Long_and(a.i,Long_fromInt(65535));else if(b==4)a.i=Long_and(a.i,new Long(4294967295, 0));a.X=(-1);return c;}if(!a.d.f)break;e=a.d;e.f=e.f-1|0;e=a.d;e.e=Long_add(e.e,Long_fromInt(1));f=a.i;g=a.d.q.data;e=a.d;h=e.b;e.b=h+1|0;a.i=Long_or(f,Long_fromInt((g[h]&255)<<((b-a.X|0)*8|0)));a.X=a.X-1|0;c=d;}D(FY(a,c));} +function D9(a,b,c){var d,e;if(a.I===null)a.I=GY();while(true){if(!a.d.f)D(FY(a,b));d=a.d;d.f=d.f-1|0;d=a.d;d.e=Long_add(d.e,Long_fromInt(1));e=a.d.q.data[a.d.b];if(e)Dv(a.I,a.d.q,a.d.b,1);a.d.K.bn(a.d.q,a.d.b,1);d=a.d;d.b=d.b+1|0;if(!e)break;b=c;}return c;} +function Ex(a,b,c){var d;if(a.I===null)a.I=GY();while(Long_gt(a.i,Long_ZERO)){if(!a.d.f)D(FY(a,b));d=a.d;d.f=d.f-1|0;d=a.d;d.e=Long_add(d.e,Long_fromInt(1));Dv(a.I,a.d.q,a.d.b,1);a.d.K.bn(a.d.q,a.d.b,1);d=a.d;d.b=d.b+1|0;a.i=Long_sub(a.i,Long_fromInt(1));b=c;}return b;} +function BQ(a,b,c){var d;d=0;while(d>24;c=Long_shr(c,8);d=d+1|0;}a.d.K.bn(a.cz,0,b);} +function Fk(){var b,c;b=$rt_createByteArray(4);c=b.data;c[0]=0;c[1]=0;c[2]=(-1);c[3]=(-1);I_=b;} +function DT(){} +function Bp(){C.call(this);} +function EY(a,b,c,d){var e,f,g;e=0;while(ec)c=b;return c;} +function BX(){var a=this;C.call(a);a.v=0;a.bV=0;a.bJ=0;a.L=0;a.G=null;a.cp=null;a.bF=null;a.bC=null;a.bB=null;a.cx=null;a.cy=null;a.cG=null;a.cJ=null;a.bT=null;a.b$=0;a.l=0;a.k=0;a.bb=null;a.u=null;a.s=0;a.n=0;a.h=0;a.ca=0;a.cv=null;a.a=null;} +var Ja=null;var Jb=null;function B4(a){a.v=0;a.l=0;a.k=0;a.h=0;a.n=0;if(a.ca)a.a.K.cl();} +function FX(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;c=a.a.b;d=a.a.f;e=a.k;f=a.l;g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;a:{b:{c:{d:{e:while(true){f:{g:{h:{i:{j:{switch(a.v){case 2:break f;case 9:a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));case 0:break j;case 1:break;case 3:while(f<14){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<29)break d;k=k>>5&31;if(k>29)break d;k:{k=(258+l|0)+k|0;if(!(a.G!==null&&a.G.data.length>=k))a.G=$rt_createIntArray(k);else{l=0;while(true){if(l>=k)break k;a.G.data[l]=0;l=l+1|0;}}}e=e>>>14;f=f+(-14)|0;a.L=0;a.v=4;break i;case 4:break i;case 5:break h;case 6:break g;case 7:break b;case 8:break a;default:a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-2));}while(f<32){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b +|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<>>16&65535;l=e&65535;if(k!=l){a.v=9;a.a.o=B(54);a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.bV=l;f=0;a.v=a.bV?2:!a.b$?0:7;e=f;continue e;}while(f<3){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<>>1){case 0:k=e>>>3;l=f+(-3)|0;n=l&7;e=k>>>n;f=l-n|0;a.v=1;break l;case 1:FR(a.bC,a.bB,a.cx,a.cy,a.a);DN(a.bT,a.bC.data[0],a.bB.data[0],a.cx.data[0],0,a.cy.data[0],0);e=e>>>3;f=f+(-3)|0;a.v=6;break l;case 2:e=e>>>3;f=f+(-3)|0;a.v=3;break l;case 3:b=e>>>3;k=f+(-3)|0;a.v=9;a.a.o=B(55);a.k=b;a.l=k;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));default:}}continue e;}while(a.L<(4+(a.bJ>>>10)|0)){while(f<3){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c +-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}b=0;d=d+(-1)|0;j=a.a.q.data;k=c+1|0;e=e|(j[c]&255)<>>3;f=f+(-3)|0;}while(a.L<19){o=a.G.data;j=Jb.data;k=a.L;a.L=k+1|0;o[j[k]]=0;}a.cp.data[0]=7;k=GC(a.cv,a.G,a.cp,a.bF,a.bb,a.a);if(k){if(k==(-3)){a.G=null;a.v=9;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,k);}a.L=0;a.v=5;}while(true){k=a.bJ;if(a.L>=((258+(k&31)|0)+(k>>5&31)|0))break;k=a.cp.data[0];while +(f>>k;f=f-k|0;j=a.G.data;k=a.L;a.L=k+1|0;j[k]=n;}else{p=C6(n,18);q=!p?7:n-14|0;p=p?3:11;while(f<(k+q|0)){if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a, +b);}b=0;d=d+(-1)|0;j=a.a.q.data;n=c+1|0;e=e|(j[c]&255)<>>k;k=f-k|0;p=p+(n&Ja.data[q])|0;e=n>>>q;f=k-q|0;h=a.L;q=a.bJ;if((h+p|0)>((258+(q&31)|0)+(q>>5&31)|0))break c;if(!l&&h<1)break c;k=l?0:a.G.data[h-1|0];while(true){j=a.G.data;l=h+1|0;j[h]=k;p=p+(-1)|0;if(!p)break;h=l;}a.L=l;}}a.bF.data[0]=(-1);a.bC.data[0]=9;a.bB.data[0]=6;k=a.bJ;k=Fb(a.cv,257+(k&31)|0,1+(k>>5&31)|0,a.G,a.bC,a.bB,a.cG,a.cJ,a.bb,a.a);if(k){if(k==(-3)){a.G=null;a.v=9;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c +-a.a.b|0));a.a.b=c;a.h=g;return I(a,k);}DN(a.bT,a.bC.data[0],a.bB.data[0],a.bb,a.cG.data[0],a.bb,a.cJ.data[0]);a.v=6;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;b=FE(a.bT,b);if(b!=1)break e;b=0;EX(a.bT,a.a);c=a.a.b;d=a.a.f;e=a.k;f=a.l;g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;if(a.b$){a.v=7;break b;}a.v=0;continue e;}if(!d){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}if(!h){if(g==a.s&&a.n){g=0;h=g>=a.n?a.s-g|0:(a.n-g|0)-1 +|0;}if(!h){a.h=g;b=I(a,b);g=a.h;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;if(g==a.s&&a.n){g=0;h=g>=a.n?a.s-g|0:(a.n-g|0)-1|0;}if(!h){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}}}b=0;k=a.bV;if(k>d)k=d;if(k>h)k=h;Z(a.a.q,c,a.u,g,k);c=c+k|0;d=d-k|0;g=g+k|0;h=h-k|0;k=a.bV-k|0;a.bV=k;if(k)continue;a.v=!a.b$?0:7;}return I(a,b);}a.v=9;a.a.o=B(56);a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.G=null;a.v=9;a.a.o=B(57);a.k +=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,(-3));}a.h=g;b=I(a,b);g=a.h;if(a.n!=a.h){a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,b);}a.v=8;}a.k=e;a.l=f;a.a.f=d;i=a.a;i.e=Long_add(i.e,Long_fromInt(c-a.a.b|0));a.a.b=c;a.h=g;return I(a,1);} +function D1(a){B4(a);a.u=null;a.bb=null;} +function I(a,b){var c,d,e,f,g;c=a.a.b2;d=a.n;e=(d>a.h?a.s:a.h)-d|0;if(e>a.a.R)e=a.a.R;if(e&&b==(-5))b=0;f=a.a;f.R=f.R-e|0;f=a.a;f.bD=Long_add(f.bD,Long_fromInt(e));if(a.ca&&e>0)a.a.K.bn(a.u,d,e);Z(a.u,d,a.a.cr,c,e);c=c+e|0;g=d+e|0;if(g==a.s){if(a.h==a.s)a.h=0;d=a.h-0|0;if(d>a.a.R)d=a.a.R;if(d&&b==(-5))b=0;f=a.a;f.R=f.R-d|0;f=a.a;f.bD=Long_add(f.bD,Long_fromInt(d));if(a.ca&&d>0)a.a.K.bn(a.u,0,d);Z(a.u,0,a.a.cr,c,d);c=c+d|0;g=0+d|0;}a.a.b2=c;a.n=g;return b;} +function Eo(){var b,c;b=$rt_createIntArray(17);c=b.data;c[0]=0;c[1]=1;c[2]=3;c[3]=7;c[4]=15;c[5]=31;c[6]=63;c[7]=127;c[8]=255;c[9]=511;c[10]=1023;c[11]=2047;c[12]=4095;c[13]=8191;c[14]=16383;c[15]=32767;c[16]=65535;Ja=b;b=$rt_createIntArray(19);c=b.data;c[0]=16;c[1]=17;c[2]=18;c[3]=0;c[4]=8;c[5]=7;c[6]=9;c[7]=6;c[8]=10;c[9]=5;c[10]=11;c[11]=4;c[12]=12;c[13]=3;c[14]=13;c[15]=2;c[16]=14;c[17]=1;c[18]=15;Jb=b;} +function Bj(){var a=this;C.call(a);a.bf=null;a.be=null;a.C=null;a.H=null;a.bl=null;a.T=null;} +var Jc=null;var Jd=null;var Je=null;var Jf=null;var Jg=null;var Jh=null;function Ca(a,b,c,d,e,f,g,h,i,j,k,l){var m,n,o,p,q,r,s,t,u,v,w,x,y,z,ba,bb,bc,bd,be;m=0;n=d;while(true){o=b.data;p=a.C.data;q=o[c+m|0];p[q]=p[q]+1|0;m=m+1|0;n=n+(-1)|0;if(!n)break;}if(a.C.data[0]==d){b=h.data;f=i.data;b[0]=(-1);f[0]=0;return 0;}i=i.data;r=i[0];s=1;a:{while(true){if(s>15)break a;if(a.C.data[s])break;s=s+1|0;}}if(rt)r=t;i[0]=r;u=1<=t){v=u-a.C.data[t]|0;if(v<0)return (-3);b=a.C.data;b[t]=b[t]+v|0;b=a.T.data;u=0;b[1]=u;m=1;w=2;x=t;while(true){x=x+(-1)|0;if(!x)break;i=a.T.data;u=u+a.C.data[m]|0;i[w]=u;w=w+1|0;m=m+1|0;}m=0;w=0;while(true){x=o[c+w|0];if(x){i=l.data;b=a.T.data;q=b[x];b[x]=q+1|0;i[q]=m;}w=w+1|0;m=m+1|0;if(m>=d)break;}u=a.T.data[t];b=a.T.data;m=0;b[0]=m;w=0;y=(-1);z= -r;a.bl.data[0]=0;ba=0;bb=0;c:while(true){if(s>t)return v&&t!=1?(-5):0;bc=a.C.data[s];while(true){bd=bc+(-1)|0;if(!bc)break;n=bd+1|0;while(true){be= +z+r|0;if(s<=be)break;y=y+1|0;x=t-be|0;if(x>r)x=r;d:{bc=s-be|0;c=1<n){q=c-n|0;if(bc=x)break;d=q<<1;b=a.C.data;c=c+1|0;if(d<=b[c])break d;q=d-a.C.data[c]|0;}}}}b=k.data;bb=1<1440)break c;i=a.bl.data;ba=b[0];i[y]=ba;b[0]=b[0]+bb|0;if(!y){h.data[0]=ba;z=be;continue;}a.T.data[y]=m;a.H.data[0]=bc<<24>>24;a.H.data[1]=r<<24>>24;c=m>>>(be-r|0);i=a.H.data;b=a.bl.data;q=y-1|0;i[2]=(ba-b[q]|0)-c|0;Z(a.H,0,j,(a.bl.data[q]+c|0)*3|0,3);z=be;}b=a.H.data;x=s-z| +0;b[1]=x<<24>>24;if(w>=u)a.H.data[0]=192;else{p=l.data;if(p[w]>=e){i=g.data;o=f.data;a.H.data[0]=((i[p[w]-e|0]+16|0)+64|0)<<24>>24;b=a.H.data;d=w+1|0;b[2]=o[p[w]-e|0];w=d;}else{b=a.H;b.data[0]=(p[w]>=256?96:0)<<24>>24;b=a.H.data;d=w+1|0;b[2]=p[w];w=d;}}q=1<>>z;while(c>>1;}m=m^c;x=(1<257))return 0;if(c==(-3))j.o=B(60);else if(c==(-5)){j.o=B(61);c=(-3);}else if(c!=(-4)){j.o=B(62);c=(-3);}return c;}if(k==(-3))j.o=B(63);else if(k!=(-4)){j.o=B(64);k=(-3);}return k;} +function FR(b,c,d,e,f){e=e.data;d=d.data;c=c.data;b.data[0]=9;c[0]=5;d[0]=Jc;e[0]=Jd;return 0;} +function CB(a,b){var c;if(a.bf===null){a.bf=$rt_createIntArray(1);a.be=$rt_createIntArray(b);a.C=$rt_createIntArray(16);a.H=$rt_createIntArray(3);a.bl=$rt_createIntArray(15);a.T=$rt_createIntArray(16);}if(a.be.data.length>24;a.cH=c<<24>>24;a.c8=d;a.cI=e;a.cD=f;a.cO=g;a.E=null;} +function FE(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o;c=a.g.b;d=a.g.f;e=a.c.k;f=a.c.l;g=a.c.h;h=g>=a.c.n?a.c.s-g|0:(a.c.n-g|0)-1|0;a:{b:while(true){c:{d:{e:{f:{g:{switch(a.D){case 0:break f;case 2:i=a.cj;while(f>i;f=f-i|0;a.bw=a.cH;a.E=a.cD;a.bm=a.cO;a.D=3;break g;case 4:i=a.cj;while(f>i;f=f-i|0;a.D=5;break c;case 6:break d;case 7:if(f>7){f=f+(-8)|0;d=d+1|0;c=c+(-1)|0;}a.c.h=g;b=I(a.c,b);g=a.c.h;if(a.c.n!=a.c.h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}a.D=8;break a;case 9:a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b +|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));case 1:break e;case 3:break;case 5:break c;case 8:break a;default:a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-2));}}l=a.bw;while(f>k[i];f=f-a.E.data[i]|0;l=a.E.data[m];if(l&16){a.cj +=l&15;a.b_=a.E.data[m+2|0];a.D=4;continue b;}if(l&64){a.D=9;a.g.o=B(65);a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));}a.bw=l;a.bm=(m/3|0)+a.E.data[m+2|0]|0;continue b;}if(h>=258&&d>=10){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;b=F$(a,a.cZ,a.cH,a.c8,a.cI,a.cD,a.cO,a.c,a.g);c=a.g.b;d=a.g.f;e=a.c.k;f=a.c.l;g=a.c.h;h=g>=a.c.n?a.c.s-g|0:(a.c.n-g|0)-1|0;if(b){a.D=b!=1?9:7;continue b;}}a.bw=a.cZ;a.E=a.c8;a.bm +=a.cI;a.D=1;}l=a.bw;while(f>>k[i];f=f-a.E.data[i]|0;n=a.E.data[m];if(!n){a.dp=a.E.data[m+2|0];a.D=6;continue b;}if(n&16){a.cj=n&15;a.bs=a.E.data[m+2|0];a.D=2;continue b;}if(!(n&64)){a.bw=n;a.bm=(m/3|0)+a.E.data[m+2|0]|0;continue b;}if(!(n&32)){a.D=9;a.g.o=B(66);a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,(-3));}a.D= +7;continue b;}if(h)i=g;else{if(g!=a.c.s)i=g;else if(!a.c.n)i=g;else{i=0;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;}if(!h){a.c.h=i;b=I(a.c,b);i=a.c.h;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;if(i==a.c.s&&a.c.n){i=0;h=i>=a.c.n?a.c.s-i|0:(a.c.n-i|0)-1|0;}if(!h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=i;return I(a.c,b);}}}b=0;k=a.c.u.data;g=i+1|0;k[i]=a.dp<<24>>24;h=h+(-1)|0;a.D=0;continue b;}i=g-a.b_|0;while(i<0){i=i+a.c.s|0;}while(a.bs){if(h)l=g;else{if(g!=a.c.s)l=g;else if +(!a.c.n)l=g;else{l=0;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;}if(!h){a.c.h=l;b=I(a.c,b);l=a.c.h;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;if(l==a.c.s&&a.c.n){l=0;h=l>=a.c.n?a.c.s-l|0:(a.c.n-l|0)-1|0;}if(!h){a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=l;return I(a.c,b);}}}o=a.c.u.data;g=l+1|0;k=a.c.u.data;m=i+1|0;o[l]=k[i];h=h+(-1)|0;i=m==a.c.s?0:m;a.bs=a.bs-1|0;}a.D=0;}a.c.k=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,b);}a.c.k +=e;a.c.l=f;a.g.f=d;j=a.g;j.e=Long_add(j.e,Long_fromInt(c-a.g.b|0));a.g.b=c;a.c.h=g;return I(a.c,1);} +function EX(a,b){return;} +function F$(a,b,c,d,e,f,g,h,i){var j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;j=i.b;k=i.f;l=h.k;m=h.l;n=h.h;o=n>=h.n?h.s-n|0:(h.n-n|0)-1|0;p=Ji.data[b];q=Ji.data[c];while(true){if(m<20){k=k+(-1)|0;r=i.q.data;b=j+1|0;l=l|(r[j]&255)<>s[b];m=m-s[b]|0;r=h.u.data;c=n+1|0;r[n]=s[u+2|0]<<24>>24;o=o+(-1)|0;}else{while(true){b=u+1|0;l=l>>s[b];m=m-s[b]|0;if(c&16){b=c&15;v=s[u+2|0]+(l&Ji.data[b])|0;w=l>>b;m=m-b|0;while(m<15){k=k+(-1)|0;r=i.q.data;b= +j+1|0;w=w|(r[j]&255)<>r[l];m=m-r[l]|0;if(c&16)break;if(c&64){i.o=B(65);b=i.f-k|0;c=m>>3;if(c>b;m=m-b|0;o=o-v|0;if(n>=x){w=n-x|0;b=n-w|0;if(b>0&&2>b){s +=h.u.data;b=n+1|0;r=h.u.data;c=w+1|0;s[n]=r[w];s=h.u.data;n=b+1|0;r=h.u.data;w=c+1|0;s[b]=r[c];v=v+(-2)|0;}else{Z(h.u,w,h.u,n,2);n=n+2|0;w=w+2|0;v=v+(-2)|0;}}else{w=n-x|0;while(true){w=w+h.s|0;if(w>=0)break;}b=h.s-w|0;if(v>b){v=v-b|0;c=n-w|0;if(c>0&&b>c){c=n;while(true){s=h.u.data;n=c+1|0;r=h.u.data;x=w+1|0;s[c]=r[w];b=b+(-1)|0;if(!b)break;c=n;w=x;}}else{Z(h.u,w,h.u,n,b);n=n+b|0;}w=0;}}b=n-w|0;if(b>0&&v>b){while(true){s=h.u.data;c=n+1|0;r=h.u.data;b=w+1|0;s[n]=r[w];v=v+(-1)|0;if(!v)break;n=c;w=b;}break a;}Z(h.u, +w,h.u,n,v);c=n+v|0;break a;}if(c&64){if(c&32){v=i.f-k|0;b=m>>3;if(b>3;if(b>s[b];m=m-s[b]|0;r=h.u.data;c=n+1|0;r[n]=s[u+2|0]<<24>>24;o=o+(-1)|0;}}if(o<258)break;if(k<10)break;n +=c;}v=i.f-k|0;b=m>>3;if(bg&&Bg(b)){j=f;while(j=g?Jl:Jk;break a;}k=Ba(L(c),i.length);m=new D8;m.c_=b;m.dc=c;l=FS(a,d,f,g,h,0,k,m);f=m.cT;if(l===null&&0==m.ch)l=Jl;Gs(c,h,0,m.ch);if(l!==null)break;}}Bf(b,b.p-(g-f|0)|0);return l;} +function Dj(){CA.call(this);} +function FS(a,b,c,d,e,f,g,h){var i,j,k,l,m,n,o,p,q;i=null;a:{b:{c:{while(c=g)break a;j=b.data;k=c+1|0;l=j[c]&255;if(!(l&128)){j=e.data;m=f+1|0;j[f]=l&65535;}else if((l&224)==192){if(k>=d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}n=k+1|0;k=j[k];if(!Bw(a,k)){c=n+(-2)|0;i=Bh(1);break a;}j=e.data;m=f+1|0;j[f]=((l&31)<<6|k&63)&65535;k=n;}else if((l&240)==224){if((k+2|0)>d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}c=k+1|0;m=j[k];k=c+1|0;o=j[c];if(!Bw(a,m))break b;if(!Bw(a,o))break b;p=((l&15)<<12|(m&63) +<<6|o&63)&65535;if(DJ(p)){c=k+(-3)|0;i=Bh(3);break a;}j=e.data;m=f+1|0;j[f]=p;}else{if((l&248)!=240){c=k+(-1)|0;i=Bh(1);break a;}if((k+3|0)>d){c=k+(-1)|0;if(Cl(h))break a;i=Jl;break a;}if((f+2|0)>g){c=k+(-1)|0;if(FO(h,2))break a;i=Jk;break a;}c=k+1|0;m=j[k];n=c+1|0;o=j[c];k=n+1|0;n=j[n];if(!Bw(a,m))break c;if(!Bw(a,o))break c;if(!Bw(a,n))break c;j=e.data;q=(l&7)<<18|(m&63)<<12|(o&63)<<6|n&63;c=f+1|0;j[f]=Ee(q);m=c+1|0;j[c]=Do(q);}c=k;f=m;}break a;}c=k+(-3)|0;i=Bh(1);break a;}c=k+(-3)|0;i=Bh(1);}h.cT=c;h.ch= +f;return i;} +function Bw(a,b){return (b&192)!=128?0:1;} +function Y(){var a=this;Bc.call(a);a.P=0;a.ea=null;} +function FY(a,b){var c=new Y();HZ(c,a,b);return c;} +function HZ(a,b,c){a.ea=b;H(a);a.P=c;} +function Gz(){var a=this;C.call(a);a.d$=0;a.dK=0;a.dN=Long_ZERO;a.er=0;a.dl=0;a.bL=null;a.dd=null;a.dm=null;a.eG=0;a.ec=Long_ZERO;a.dQ=0;a.ee=Long_ZERO;} +function Ii(){var a=new Gz();Ht(a);return a;} +function Ht(a){a.d$=0;a.dK=0;a.dl=255;a.dQ=0;a.ee=Long_ZERO;} +function Da(){C.call(this);this.bA=0;} +var Jm=null;function Hb(){var a=new Da();FH(a);return a;} +function FH(a){a.bA=0;} +function HV(a,b,c,d){var e,f,g,h;e=a.bA^(-1);while(true){d=d+(-1)|0;if(d<0)break;f=b.data;g=Jm.data;h=c+1|0;e=g[(e^f[c])&255]^e>>>8;c=h;}a.bA=e^(-1);} +function Hw(a){a.bA=0;} +function GQ(a,b){a.bA=Long_and(b,new Long(4294967295, 0)).lo;} +function GS(a){return Long_and(Long_fromInt(a.bA),new Long(4294967295, 0));} +function Ey(){var b,c,d;Jm=null;Jm=$rt_createIntArray(256);b=0;while(b<256){c=8;d=b;while(true){c=c+(-1)|0;if(c<0)break;if(!(d&1)){d=d>>>1;continue;}d=(-306674912)^d>>>1;}Jm.data[b]=d;b=b+1|0;}} +function CQ(){B_.call(this);} +function Fx(a,b,c){var d,e,f,g,h,i,j,k,l,m;d=$rt_createCharArray(Ba(L(b),512));e=d.data;f=0;g=0;h=$rt_createByteArray(Ba(L(c),512));i=h.data;a:{while(true){if((f+32|0)>g&&Bg(b)){j=f;while(j=g?Jl:Jk;break a;}k=Ba(L(c),i.length);m=new Du;m.df=b;m.dv=c;l=Gj(a,d,f,g,h,0,k,m);f=m.cu;if(l===null&&0==m.ce)l=Jl;Dz(c,h,0,m.ce);if(l!==null)break;}}Bf(b,b.p-(g-f|0)|0);return l;} +function Eh(){CQ.call(this);} +function Gj(a,b,c,d,e,f,g,h){var i,j,k,l,m,n;i=null;a:{while(c=g){j=c;break a;}k=b.data;j=c+1|0;l=k[c];if(l<128){k=e.data;m=f+1|0;k[f]=l<<24>>24;}else if(l<2048){if((f+2|0)>g){j=j+(-1)|0;if(Cd(h,2))break a;i=Jk;break a;}k=e.data;c=f+1|0;k[f]=(192|l>>6)<<24>>24;m=c+1|0;k[c]=(128|l&63)<<24>>24;}else if(!DJ(l)){if((f+3|0)>g){j=j+(-1)|0;if(Cd(h,3))break a;i=Jk;break a;}k=e.data;n=f+1|0;k[f]=(224|l>>12)<<24>>24;c=n+1|0;k[n]=(128|l>>6&63)<<24>>24;m=c+1|0;k[c]=(128|l&63)<<24>>24;}else{if(!Cs(l)){i=Bh(1);break a;}if +(j>=d){if(Ez(h))break a;i=Jl;break a;}c=j+1|0;j=k[j];if(!Co(j)){j=c+(-2)|0;i=Bh(1);break a;}if((f+4|0)>g){j=c+(-2)|0;if(Cd(h,4))break a;i=Jk;break a;}k=e.data;n=Ds(l,j);j=f+1|0;k[f]=(240|n>>18)<<24>>24;f=j+1|0;k[j]=(128|n>>12&63)<<24>>24;j=f+1|0;k[f]=(128|n>>6&63)<<24>>24;m=j+1|0;k[j]=(128|n&63)<<24>>24;j=c;}c=j;f=m;}j=c;}h.cu=j;h.ce=f;return i;} +function F_(){var a=this;Bp.call(a);a.bh=null;a.ci=0;} +function GY(){var a=new F_();HS(a);return a;} +function HS(a){a.bh=$rt_createByteArray(32);} +function Dv(a,b,c,d){var e,f,g,h,i;e=a.ci+d|0;if(a.bh.data.length>23&255;if(!e&&!f){c.cF=0;c.c7=0;return;}g=0;if(f)e=e|8388608;else{e=e<<1;while(Long_eq(Long_and(Long_fromInt(e),Long_fromInt(8388608)),Long_ZERO)){e=e<<1;f=f+(-1)|0;g=g+1|0;}}h=Ju.data;i=0;j=h.length;if(i>j){c=new X;H(c);D(c);}j=j-1|0;a:{while(true){k=(i+j|0)/2|0;l=h[k];if(l==f)break;if(f>=l){i=k+1|0;if(i>j){k= -k-2|0;break a;}}else{j=k-1|0;if(j=1000000000){k=k+1|0;m=9+(f-Ju.data[k]|0)|0;i=Long_shru(Long_mul(n,Long_fromInt(Jt.data[k])),32-m|0).lo;}f=(31-m|0)-g|0;j=f>=0?Jt.data[k]>>>f:Jt.data[k]<< -f;l=(j+1|0)>>1;o=j>>1;if(e==4194304)o=o>>2;p=10;while(p<=o){p=p*10|0;}if((i%p|0)>=(o/2|0))p=p/10|0;q=10;while(q<=l){q=q*10|0;}if((q-(i%q|0)|0)>(l/2|0))q=q/10|0;e=C6(p,q);e=e>0?Dm(i/p|0,p):e<0?Dm(i/q|0,q)+q|0:Dm((i+(q/2|0)|0)/q|0,q);if(e +>=1000000000){k=k+1|0;e=e/10|0;}else if(e<100000000){k=k+(-1)|0;e=e*10|0;}c.cF=e;c.c7=k-50|0;} +function ER(){var b,c,d,e,f,g,h,i;Jt=$rt_createIntArray(100);Ju=$rt_createIntArray(100);b=2000000000;c=127;d=0;e=b;while(d<50){f=Jt.data;g=d+50|0;f[g]=$rt_udiv(e,20);Ju.data[g]=c;g=$rt_udiv(e,10);h=$rt_umod(g,10);while(g<=b&&!(g&(-2147483648))){g=g<<1;c=c+1|0;h=h<<1;}e=g+(h/10|0)|0;d=d+1|0;}c=127;d=0;while(d<50){i=0;h=b;while(h>214748364){h=h>>1;i=i+1|0;c=c+(-1)|0;}h=h*10|0;b=i<=0?h:Long_add(Long_fromInt(h),Long_shr(Long_mul(Long_fromInt(b&((1<0){str+=", ";}str+=this.data[i].toString();}str+="]";return str;};$rt_setCloneMethod($rt_array.prototype,function(){var dataCopy;if('slice' in this.data){dataCopy=this.data.slice();}else {dataCopy=new this.data.constructor(this.data.length);for +(var i=0;i"," end","invalid file hash for ","","yee","End of stream reached","Malformed UTF-8 sequence","Should never been thrown","Stream closed","footer is not found","Unexpected end of ZLIB input stream", +"�","Replacement preconditions do not hold","New position "," is outside of range [0;","]","The last byte in dst "," is outside of array of size ","Length "," must be non-negative","Offset ",")","The last byte in src ","Capacity is negative: ","The last char in dst ","The last char in src "," is outside of string of size ","Start "," must be before end ","BIG_ENDIAN","LITTLE_ENDIAN","Either src or dest is null","need dictionary","unknown compression method","unknown header flags set","incorrect data check", +"incorrect length check","incorrect header check","invalid window size","bad extra field length","header crc mismatch","invalid stored block lengths","invalid block type","too many length or distance symbols","invalid bit length repeat","oversubscribed dynamic bit lengths tree","incomplete dynamic bit lengths tree","oversubscribed distance tree","incomplete distance tree","empty distance tree with lengths","oversubscribed literal/length tree","incomplete literal/length tree","invalid distance code","invalid literal/length code", +"IGNORE","REPLACE","REPORT","newAction must be non-null","Action must be non-null","Malformed input of length ","Unmappable characters of length "]); +Br.prototype.toString=function(){return $rt_ustr(this);}; +Br.prototype.valueOf=Br.prototype.toString;C.prototype.toString=function(){return $rt_ustr(HF(this));}; +C.prototype.__teavm_class__=function(){return $dbg_class(this);}; +function Long_eq(a,b){return a.hi===b.hi&&a.lo===b.lo;}function Long_ne(a,b){return a.hi!==b.hi||a.lo!==b.lo;}function Long_gt(a,b){if(a.hib.hi){return true;}var x=a.lo>>>1;var y=b.lo>>>1;if(x!==y){return x>y;}return (a.lo&1)>(b.lo&1);}function Long_ge(a,b){if(a.hib.hi){return true;}var x=a.lo>>>1;var y=b.lo>>>1;if(x!==y){return x>=y;}return (a.lo&1)>=(b.lo&1);}function Long_lt(a,b){if(a.hi>b.hi){return false;}if(a.hi>> +1;var y=b.lo>>>1;if(x!==y){return xb.hi){return false;}if(a.hi>>1;var y=b.lo>>>1;if(x!==y){return x<=y;}return (a.lo&1)<=(b.lo&1);}function Long_add(a,b){if(a.hi===a.lo>>31&&b.hi===b.lo>>31){return Long_fromNumber(a.lo+b.lo);}else if(Math.abs(a.hi)>>16;var a_hilo=a.hi&0xFFFF;var a_hihi +=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=a_lolo+b_lolo|0;var lohi=a_lohi+b_lohi+(lolo>>16)|0;var hilo=a_hilo+b_hilo+(lohi>>16)|0;var hihi=a_hihi+b_hihi+(hilo>>16)|0;return new Long(lolo&0xFFFF|(lohi&0xFFFF)<<16,hilo&0xFFFF|(hihi&0xFFFF)<<16);}function Long_inc(a){var lo=a.lo+1|0;var hi=a.hi;if(lo===0){hi=hi+1|0;}return new Long(lo,hi);}function Long_dec(a){var lo=a.lo -1|0;var hi=a.hi;if(lo=== -1){hi=hi -1|0;}return new Long(lo,hi);}function Long_neg(a) +{return Long_inc(new Long(a.lo^0xFFFFFFFF,a.hi^0xFFFFFFFF));}function Long_sub(a,b){if(a.hi===a.lo>>31&&b.hi===b.lo>>31){return Long_fromNumber(a.lo -b.lo);}var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=a_lolo -b_lolo|0;var lohi=a_lohi -b_lohi+(lolo>>16)|0;var hilo=a_hilo -b_hilo+(lohi>>16)|0;var hihi=a_hihi -b_hihi+(hilo>>16)|0;return new Long(lolo&0xFFFF|(lohi&0xFFFF)<< +16,hilo&0xFFFF|(hihi&0xFFFF)<<16);}function Long_compare(a,b){var r=a.hi -b.hi;if(r!==0){return r;}r=(a.lo>>>1) -(b.lo>>>1);if(r!==0){return r;}return (a.lo&1) -(b.lo&1);}function Long_isPositive(a){return (a.hi&0x80000000)===0;}function Long_isNegative(a){return (a.hi&0x80000000)!==0;}function Long_mul(a,b){var positive=Long_isNegative(a)===Long_isNegative(b);if(Long_isNegative(a)){a=Long_neg(a);}if(Long_isNegative(b)){b=Long_neg(b);}var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi +=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;var lolo=0;var lohi=0;var hilo=0;var hihi=0;lolo=a_lolo*b_lolo|0;lohi=lolo>>>16;lohi=(lohi&0xFFFF)+a_lohi*b_lolo|0;hilo=hilo+(lohi>>>16)|0;lohi=(lohi&0xFFFF)+a_lolo*b_lohi|0;hilo=hilo+(lohi>>>16)|0;hihi=hilo>>>16;hilo=(hilo&0xFFFF)+a_hilo*b_lolo|0;hihi=hihi+(hilo>>>16)|0;hilo=(hilo&0xFFFF)+a_lohi*b_lohi|0;hihi=hihi+(hilo>>>16)|0;hilo=(hilo&0xFFFF)+a_lolo*b_hilo|0;hihi=hihi+(hilo>>>16)|0;hihi=hihi+a_hihi*b_lolo ++a_hilo*b_lohi+a_lohi*b_hilo+a_lolo*b_hihi|0;var result=new Long(lolo&0xFFFF|lohi<<16,hilo&0xFFFF|hihi<<16);return positive?result:Long_neg(result);}function Long_div(a,b){if(Math.abs(a.hi)=0&&a.hi=0&&b.hi=0&&a.hi=0&&b.hi>>16|a.hi<<16);}function Long_shiftRight16(a) +{return new Long(a.lo>>>16|a.hi<<16,a.hi>>>16);}function Long_and(a,b){return new Long(a.lo&b.lo,a.hi&b.hi);}function Long_or(a,b){return new Long(a.lo|b.lo,a.hi|b.hi);}function Long_xor(a,b){return new Long(a.lo^b.lo,a.hi^b.hi);}function Long_shl(a,b){b&=63;if(b===0){return a;}else if(b<32){return new Long(a.lo<>>32 -b|a.hi<>>b|a.hi +<<32 -b,a.hi>>b);}else if(b===32){return new Long(a.hi,a.hi>>31);}else {return new Long(a.hi>>b -32,a.hi>>31);}}function Long_shru(a,b){b&=63;if(b===0){return a;}else if(b<32){return new Long(a.lo>>>b|a.hi<<32 -b,a.hi>>>b);}else if(b===32){return new Long(a.hi,0);}else {return new Long(a.hi>>>b -32,0);}}function LongInt(lo,hi,sup){this.lo=lo;this.hi=hi;this.sup=sup;}function LongInt_mul(a,b){var a_lolo=(a.lo&0xFFFF)*b|0;var a_lohi=(a.lo>>>16)*b|0;var a_hilo=(a.hi&0xFFFF)*b|0;var a_hihi=(a.hi>>>16)*b|0;var sup +=a.sup*b|0;a_lohi=a_lohi+(a_lolo>>>16)|0;a_hilo=a_hilo+(a_lohi>>>16)|0;a_hihi=a_hihi+(a_hilo>>>16)|0;sup=sup+(a_hihi>>>16)|0;a.lo=a_lolo&0xFFFF|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup&0xFFFF;}function LongInt_sub(a,b){var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;a_lolo=a_lolo -b_lolo|0;a_lohi=a_lohi -b_lohi+(a_lolo>>16)|0;a_hilo=a_hilo -b_hilo+(a_lohi>>16)|0;a_hihi=a_hihi - +b_hihi+(a_hilo>>16)|0;var sup=a.sup -b.sup+(a_hihi>>16)|0;a.lo=a_lolo&0xFFFF|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup;}function LongInt_add(a,b){var a_lolo=a.lo&0xFFFF;var a_lohi=a.lo>>>16;var a_hilo=a.hi&0xFFFF;var a_hihi=a.hi>>>16;var b_lolo=b.lo&0xFFFF;var b_lohi=b.lo>>>16;var b_hilo=b.hi&0xFFFF;var b_hihi=b.hi>>>16;a_lolo=a_lolo+b_lolo|0;a_lohi=a_lohi+b_lohi+(a_lolo>>16)|0;a_hilo=a_hilo+b_hilo+(a_lohi>>16)|0;a_hihi=a_hihi+b_hihi+(a_hilo>>16)|0;var sup=a.sup+b.sup+(a_hihi>>16)|0;a.lo=a_lolo&0xFFFF +|a_lohi<<16;a.hi=a_hilo&0xFFFF|a_hihi<<16;a.sup=sup;}function LongInt_inc(a){a.lo=a.lo+1|0;if(a.lo===0){a.hi=a.hi+1|0;if(a.hi===0){a.sup=a.sup+1&0xFFFF;}}}function LongInt_dec(a){a.lo=a.lo -1|0;if(a.lo=== -1){a.hi=a.hi -1|0;if(a.hi=== -1){a.sup=a.sup -1&0xFFFF;}}}function LongInt_ucompare(a,b){var r=a.sup -b.sup;if(r!==0){return r;}r=(a.hi>>>1) -(b.hi>>>1);if(r!==0){return r;}r=(a.hi&1) -(b.hi&1);if(r!==0){return r;}r=(a.lo>>>1) -(b.lo>>>1);if(r!==0){return r;}return (a.lo&1) -(b.lo&1);}function LongInt_numOfLeadingZeroBits(a) +{var n=0;var d=16;while(d>0){if(a>>>d!==0){a>>>=d;n=n+d|0;}d=d/2|0;}return 31 -n;}function LongInt_shl(a,b){if(b===0){return;}if(b<32){a.sup=(a.hi>>>32 -b|a.sup<>>32 -b|a.hi<>>64 -b|a.hi<>>b|a.hi<<32 -b;a.hi=a.hi>>>b|a.sup<<32 -b;a.sup>>>=b;}else if(b===64){a.lo=a.sup;a.hi=0;a.sup=0;}else if(b<64){a.lo=a.hi>>>b -32|a.sup<<64 -b;a.hi=a.sup>>>b -32;a.sup=0;}else {a.lo=a.sup>>>b -64;a.hi=0;a.sup=0;}}function LongInt_copy(a){return new LongInt(a.lo,a.hi,a.sup);}function LongInt_div(a,b){var bits=b.hi!==0?LongInt_numOfLeadingZeroBits(b.hi):LongInt_numOfLeadingZeroBits(b.lo)+32;var sz=1+(bits/16|0);var dividentBits=bits%16;LongInt_shl(b,bits);LongInt_shl(a,dividentBits);var q +=new LongInt(0,0,0);while(sz-->0){LongInt_shl(q,16);var digitA=(a.hi>>>16)+0x10000*a.sup;var digitB=b.hi>>>16;var digit=digitA/digitB|0;var t=LongInt_copy(b);LongInt_mul(t,digit);if(LongInt_ucompare(t,a)>=0){while(LongInt_ucompare(t,a)>0){LongInt_sub(t,b); --digit;}}else {while(true){var nextT=LongInt_copy(t);LongInt_add(nextT,b);if(LongInt_ucompare(nextT,a)>0){break;}t=nextT;++digit;}}LongInt_sub(a,t);q.lo|=digit;LongInt_shl(a,16);}LongInt_shr(a,bits+16);return q;}function TeaVMThread(runner){this.status=3;this.stack +=[];this.suspendCallback=null;this.runner=runner;this.attribute=null;this.completeCallback=null;}TeaVMThread.prototype.push=function(){for(var i=0;i + + + Main page + + + + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..d3e4b34 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html + */ + +rootProject.name = 'Minecraft-Classic-Browser' diff --git a/src/main/java/net/PeytonPlayz585/glemu/FixedFunctionShader.java b/src/main/java/net/PeytonPlayz585/glemu/FixedFunctionShader.java new file mode 100644 index 0000000..ad8563d --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/FixedFunctionShader.java @@ -0,0 +1,397 @@ +package net.PeytonPlayz585.glemu; + +import static net.PeytonPlayz585.minecraft.GlStateManager.*; + +import net.PeytonPlayz585.glemu.vector.*; + +public class FixedFunctionShader { + + private static final FixedFunctionShader[] instances = new FixedFunctionShader[128]; + + public static void refreshCoreGL() { + for (int i = 0; i < instances.length; ++i) { + if (instances[i] != null) { + _wglDeleteProgram(instances[i].globject); + instances[i] = null; + } + } + shaderSource = null; + } + + public static final int COLOR = 1; + public static final int NORMAL = 2; + public static final int TEXTURE0 = 4; + public static final int LIGHTING = 8; + public static final int FOG = 16; + public static final int ALPHATEST = 32; + public static final int UNIT0 = 64; + + public static FixedFunctionShader instance(int i) { + FixedFunctionShader s = instances[i]; + if (s == null) { + boolean CC_a_color = false; + boolean CC_a_normal = false; + boolean CC_a_texture0 = false; + boolean CC_lighting = false; + boolean CC_fog = false; + boolean CC_alphatest = false; + boolean CC_unit0 = false; + if ((i & COLOR) == COLOR) { + CC_a_color = true; + } + if ((i & NORMAL) == NORMAL) { + CC_a_normal = true; + } + if ((i & TEXTURE0) == TEXTURE0) { + CC_a_texture0 = true; + } + if ((i & LIGHTING) == LIGHTING) { + CC_lighting = true; + } + if ((i & FOG) == FOG) { + CC_fog = true; + } + if ((i & ALPHATEST) == ALPHATEST) { + CC_alphatest = true; + } + if ((i & UNIT0) == UNIT0) { + CC_unit0 = true; + } + s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_lighting, CC_fog, CC_alphatest, CC_unit0); + instances[i] = s; + } + return s; + } + + private static String shaderSource = null; + + private final boolean enable_color; + private final boolean enable_normal; + private final boolean enable_texture0; + private final boolean enable_lighting; + private final boolean enable_fog; + private final boolean enable_alphatest; + private final boolean enable_unit0; + private final ProgramGL globject; + + private UniformGL u_matrix_m = null; + private UniformGL u_matrix_p = null; + private UniformGL u_matrix_t = null; + + private UniformGL u_fogColor = null; + private UniformGL u_fogMode = null; + private UniformGL u_fogStart = null; + private UniformGL u_fogEnd = null; + private UniformGL u_fogDensity = null; + private UniformGL u_fogPremultiply = null; + + private UniformGL u_colorUniform = null; + private UniformGL u_normalUniform = null; + + private UniformGL u_alphaTestF = null; + + private UniformGL u_texCoordV0 = null; + + private UniformGL u_light0Pos = null; + private UniformGL u_light1Pos = null; + + private final int a_position; + private final int a_texture0; + private final int a_color; + private final int a_normal; + + private final int attributeIndexesToEnable; + + public final BufferArrayGL genericArray; + public final BufferGL genericBuffer; + public boolean bufferIsInitialized = false; + + private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0, + boolean CC_lighting, boolean CC_fog, boolean CC_alphatest, boolean CC_unit0) { + enable_color = CC_a_color; + enable_normal = CC_a_normal; + enable_texture0 = CC_a_texture0; + enable_lighting = CC_lighting; + enable_fog = CC_fog; + enable_alphatest = CC_alphatest; + enable_unit0 = CC_unit0; + + if (shaderSource == null) { + shaderSource = fileContents("/glsl/core.glsl"); + } + + String source = ""; + if (enable_color) + source += "\n#define CC_a_color\n"; + if (enable_normal) + source += "#define CC_a_normal\n"; + if (enable_texture0) + source += "#define CC_a_texture0\n"; + if (enable_lighting) + source += "#define CC_lighting\n"; + if (enable_fog) + source += "#define CC_fog\n"; + if (enable_alphatest) + source += "#define CC_alphatest\n"; + if (enable_unit0) + source += "#define CC_unit0\n"; + source += shaderSource; + + ShaderGL v = _wglCreateShader(_wGL_VERTEX_SHADER); + _wglShaderSource(v, _wgetShaderHeader() + "\n#define CC_VERT\n" + source); + _wglCompileShader(v); + + if (!_wglGetShaderCompiled(v)) { + System.err.println(("\n\n" + _wglGetShaderInfoLog(v)).replace("\n", "\n[/glsl/core.glsl][CC_VERT] ")); + throw new RuntimeException("broken shader file"); + } + + ShaderGL f = _wglCreateShader(_wGL_FRAGMENT_SHADER); + _wglShaderSource(f, _wgetShaderHeader() + "\n#define CC_FRAG\n" + source); + _wglCompileShader(f); + + if (!_wglGetShaderCompiled(f)) { + System.err.println(("\n\n" + _wglGetShaderInfoLog(f)).replace("\n", "\n[/glsl/core.glsl][CC_FRAG] ")); + throw new RuntimeException("broken shader file"); + } + + globject = _wglCreateProgram(); + _wglAttachShader(globject, v); + _wglAttachShader(globject, f); + + int i = 0; + a_position = i++; + _wglBindAttributeLocation(globject, a_position, "a_position"); + + if (enable_texture0) { + a_texture0 = i++; + _wglBindAttributeLocation(globject, a_texture0, "a_texture0"); + } else { + a_texture0 = -1; + } + if (enable_color) { + a_color = i++; + _wglBindAttributeLocation(globject, a_color, "a_color"); + } else { + a_color = -1; + } + if (enable_normal) { + a_normal = i++; + _wglBindAttributeLocation(globject, a_normal, "a_normal"); + } else { + a_normal = -1; + } + + attributeIndexesToEnable = i; + + _wglLinkProgram(globject); + + _wglDetachShader(globject, v); + _wglDetachShader(globject, f); + _wglDeleteShader(v); + _wglDeleteShader(f); + + if (!_wglGetProgramLinked(globject)) { + System.err.println(("\n\n" + _wglGetProgramInfoLog(globject)).replace("\n", "\n[LINKER] ")); + throw new RuntimeException("broken shader file"); + } + + _wglUseProgram(globject); + + u_matrix_m = _wglGetUniformLocation(globject, "matrix_m"); + u_matrix_p = _wglGetUniformLocation(globject, "matrix_p"); + u_matrix_t = _wglGetUniformLocation(globject, "matrix_t"); + + u_colorUniform = _wglGetUniformLocation(globject, "colorUniform"); + + if (enable_lighting) { + u_normalUniform = _wglGetUniformLocation(globject, "normalUniform"); + // u_invertNormals = _wglGetUniformLocation(globject, "invertNormals"); + u_light0Pos = _wglGetUniformLocation(globject, "light0Pos"); + u_light1Pos = _wglGetUniformLocation(globject, "light1Pos"); + } + + if (enable_fog) { + u_fogColor = _wglGetUniformLocation(globject, "fogColor"); + u_fogMode = _wglGetUniformLocation(globject, "fogMode"); + u_fogStart = _wglGetUniformLocation(globject, "fogStart"); + u_fogEnd = _wglGetUniformLocation(globject, "fogEnd"); + u_fogDensity = _wglGetUniformLocation(globject, "fogDensity"); + u_fogPremultiply = _wglGetUniformLocation(globject, "fogPremultiply"); + } + + if (enable_alphatest) { + u_alphaTestF = _wglGetUniformLocation(globject, "alphaTestF"); + } + + _wglUniform1i(_wglGetUniformLocation(globject, "tex0"), 0); + u_texCoordV0 = _wglGetUniformLocation(globject, "texCoordV0"); + + genericArray = _wglCreateVertexArray(); + genericBuffer = _wglCreateBuffer(); + _wglBindVertexArray(genericArray); + _wglBindBuffer(_wGL_ARRAY_BUFFER, genericBuffer); + setupArrayForProgram(); + + } + + public void setupArrayForProgram() { + _wglEnableVertexAttribArray(a_position); + _wglVertexAttribPointer(a_position, 3, _wGL_FLOAT, false, 28, 0); + if (enable_texture0) { + _wglEnableVertexAttribArray(a_texture0); + _wglVertexAttribPointer(a_texture0, 2, _wGL_FLOAT, false, 28, 12); + } + if (enable_color) { + _wglEnableVertexAttribArray(a_color); + _wglVertexAttribPointer(a_color, 4, _wGL_UNSIGNED_BYTE, true, 28, 20); + } + if (enable_normal) { + _wglEnableVertexAttribArray(a_normal); + _wglVertexAttribPointer(a_normal, 4, _wGL_UNSIGNED_BYTE, true, 28, 24); + } + } + + public void useProgram() { + _wglUseProgram(globject); + } + + public void unuseProgram() { + + } + + private float[] modelBuffer = new float[16]; + private float[] projectionBuffer = new float[16]; + private float[] textureBuffer = new float[16]; + + private Matrix4f modelMatrix = (Matrix4f) new Matrix4f().setZero(); + private Matrix4f projectionMatrix = (Matrix4f) new Matrix4f().setZero(); + private Matrix4f textureMatrix = (Matrix4f) new Matrix4f().setZero(); + private Vector4f light0Pos = new Vector4f(); + private Vector4f light1Pos = new Vector4f(); + + public void setModelMatrix(Matrix4f mat) { + if (!mat.equals(modelMatrix)) { + modelMatrix.load(mat).store(modelBuffer); + _wglUniformMat4fv(u_matrix_m, modelBuffer); + } + } + + public void setProjectionMatrix(Matrix4f mat) { + if (!mat.equals(projectionMatrix)) { + projectionMatrix.load(mat).store(projectionBuffer); + _wglUniformMat4fv(u_matrix_p, projectionBuffer); + } + } + + public void setTextureMatrix(Matrix4f mat) { + if (!mat.equals(textureMatrix)) { + textureMatrix.load(mat).store(textureBuffer); + _wglUniformMat4fv(u_matrix_t, textureBuffer); + } + } + + public void setLightPositions(Vector4f pos0, Vector4f pos1) { + if (!pos0.equals(light0Pos) || !pos1.equals(light1Pos)) { + light0Pos.set(pos0); + light1Pos.set(pos1); + _wglUniform3f(u_light0Pos, light0Pos.x, light0Pos.y, light0Pos.z); + _wglUniform3f(u_light1Pos, light1Pos.x, light1Pos.y, light1Pos.z); + } + } + + private int fogMode = 0; + + public void setFogMode(int mode) { + if (fogMode != mode) { + fogMode = mode; + _wglUniform1i(u_fogMode, mode % 2); + _wglUniform1f(u_fogPremultiply, mode / 2); + } + } + + private float fogColorR = 0.0f; + private float fogColorG = 0.0f; + private float fogColorB = 0.0f; + private float fogColorA = 0.0f; + + public void setFogColor(float r, float g, float b, float a) { + if (fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) { + fogColorR = r; + fogColorG = g; + fogColorB = b; + fogColorA = a; + _wglUniform4f(u_fogColor, fogColorR, fogColorG, fogColorB, fogColorA); + } + } + + private float fogStart = 0.0f; + private float fogEnd = 0.0f; + + public void setFogStartEnd(float s, float e) { + if (fogStart != s || fogEnd != e) { + fogStart = s; + fogEnd = e; + _wglUniform1f(u_fogStart, fogStart); + _wglUniform1f(u_fogEnd, fogEnd); + } + } + + private float fogDensity = 0.0f; + + public void setFogDensity(float d) { + if (fogDensity != d) { + fogDensity = d; + _wglUniform1f(u_fogDensity, fogDensity); + } + } + + private float alphaTestValue = 0.0f; + + public void setAlphaTest(float limit) { + if (alphaTestValue != limit) { + alphaTestValue = limit; + _wglUniform1f(u_alphaTestF, alphaTestValue); + } + } + + private float tex0x = 0.0f; + private float tex0y = 0.0f; + + public void setTex0Coords(float x, float y) { + if (tex0x != x || tex0y != y) { + tex0x = x; + tex0y = y; + _wglUniform2f(u_texCoordV0, tex0x, tex0y); + } + } + + private float colorUniformR = 0.0f; + private float colorUniformG = 0.0f; + private float colorUniformB = 0.0f; + private float colorUniformA = 0.0f; + + public void setColor(float r, float g, float b, float a) { + if (colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) { + colorUniformR = r; + colorUniformG = g; + colorUniformB = b; + colorUniformA = a; + _wglUniform4f(u_colorUniform, colorUniformR, colorUniformG, colorUniformB, colorUniformA); + } + } + + private float normalUniformX = 0.0f; + private float normalUniformY = 0.0f; + private float normalUniformZ = 0.0f; + + public void setNormal(float x, float y, float z) { + if (normalUniformX != x || normalUniformY != y || normalUniformZ != z) { + normalUniformX = x; + normalUniformY = y; + normalUniformZ = z; + _wglUniform3f(u_normalUniform, normalUniformX, normalUniformY, normalUniformZ); + } + } + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/GLObjectMap.java b/src/main/java/net/PeytonPlayz585/glemu/GLObjectMap.java new file mode 100644 index 0000000..409d52a --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/GLObjectMap.java @@ -0,0 +1,55 @@ +package net.PeytonPlayz585.glemu; + +public class GLObjectMap { + private Object[] values; + private int size; + private int insertIndex; + public int allocatedObjects; + + public GLObjectMap(int initialSize) { + this.values = new Object[initialSize]; + this.size = initialSize; + this.insertIndex = 0; + this.allocatedObjects = 0; + } + + public int register(T obj) { + int start = insertIndex; + do { + ++insertIndex; + if (insertIndex >= size) { + insertIndex = 0; + } + if (insertIndex == start) { + resize(); + return register(obj); + } + } while (values[insertIndex] != null); + values[insertIndex] = obj; + ++allocatedObjects; + return insertIndex; + } + + public T free(int obj) { + if (obj >= size || obj < 0) + return null; + Object ret = values[obj]; + values[obj] = null; + --allocatedObjects; + return (T) ret; + } + + public T get(int obj) { + if (obj >= size || obj < 0) + return null; + return (T) values[obj]; + } + + private void resize() { + int oldSize = size; + size += size / 2; + Object[] oldValues = values; + values = new Object[size]; + System.arraycopy(oldValues, 0, values, 0, oldSize); + } +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix.java new file mode 100644 index 0000000..d3e962d --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Base class for matrices. When a matrix is constructed it will be the identity + * matrix unless otherwise stated. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ +public abstract class Matrix implements Serializable { + + /** + * Constructor for Matrix. + */ + protected Matrix() { + super(); + } + + /** + * Set this matrix to be the identity matrix. + * + * @return this + */ + public abstract Matrix setIdentity(); + + /** + * Invert this matrix + * + * @return this + */ + public abstract Matrix invert(); + + /** + * Load from a float buffer. The buffer stores the matrix in column major + * (OpenGL) order. + * + * @param buf A float buffer to read from + * @return this + */ + public abstract Matrix load(FloatBuffer buf); + + /** + * Load from a float buffer. The buffer stores the matrix in row major + * (mathematical) order. + * + * @param buf A float buffer to read from + * @return this + */ + public abstract Matrix loadTranspose(FloatBuffer buf); + + /** + * Negate this matrix + * + * @return this + */ + public abstract Matrix negate(); + + /** + * Store this matrix in a float buffer. The matrix is stored in column major + * (openGL) order. + * + * @param buf The buffer to store this matrix in + * @return this + */ + public abstract Matrix store(FloatBuffer buf); + + /** + * Store this matrix in a float buffer. The matrix is stored in row major + * (maths) order. + * + * @param buf The buffer to store this matrix in + * @return this + */ + public abstract Matrix storeTranspose(FloatBuffer buf); + + /** + * Transpose this matrix + * + * @return this + */ + public abstract Matrix transpose(); + + /** + * Set this matrix to 0. + * + * @return this + */ + public abstract Matrix setZero(); + + /** + * @return the determinant of the matrix + */ + public abstract float determinant(); + +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix2f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix2f.java new file mode 100644 index 0000000..e48997e --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix2f.java @@ -0,0 +1,418 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Holds a 2x2 matrix + * + * @author cix_foo + * @version $Revision$ $Id$ + */ + +public class Matrix2f extends Matrix implements Serializable { + + private static final long serialVersionUID = 1L; + + public float m00, m01, m10, m11; + + /** + * Constructor for Matrix2f. The matrix is initialised to the identity. + */ + public Matrix2f() { + setIdentity(); + } + + /** + * Constructor + */ + public Matrix2f(Matrix2f src) { + load(src); + } + + /** + * Load from another matrix + * + * @param src The source matrix + * @return this + */ + public Matrix2f load(Matrix2f src) { + return load(src, this); + } + + /** + * Copy the source matrix to the destination matrix. + * + * @param src The source matrix + * @param dest The destination matrix, or null if a new one should be created. + * @return The copied matrix + */ + public static Matrix2f load(Matrix2f src, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + dest.m00 = src.m00; + dest.m01 = src.m01; + dest.m10 = src.m10; + dest.m11 = src.m11; + + return dest; + } + + /** + * Load from a float buffer. The buffer stores the matrix in column major + * (OpenGL) order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix load(FloatBuffer buf) { + + m00 = buf.get(); + m01 = buf.get(); + m10 = buf.get(); + m11 = buf.get(); + + return this; + } + + /** + * Load from a float buffer. The buffer stores the matrix in row major + * (mathematical) order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix loadTranspose(FloatBuffer buf) { + + m00 = buf.get(); + m10 = buf.get(); + m01 = buf.get(); + m11 = buf.get(); + + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in column major + * (openGL) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix store(FloatBuffer buf) { + buf.put(m00); + buf.put(m01); + buf.put(m10); + buf.put(m11); + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in row major + * (maths) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix storeTranspose(FloatBuffer buf) { + buf.put(m00); + buf.put(m10); + buf.put(m01); + buf.put(m11); + return this; + } + + /** + * Add two matrices together and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + dest.m00 = left.m00 + right.m00; + dest.m01 = left.m01 + right.m01; + dest.m10 = left.m10 + right.m10; + dest.m11 = left.m11 + right.m11; + + return dest; + } + + /** + * Subtract the right matrix from the left and place the result in a third + * matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + dest.m00 = left.m00 - right.m00; + dest.m01 = left.m01 - right.m01; + dest.m10 = left.m10 - right.m10; + dest.m11 = left.m11 - right.m11; + + return dest; + } + + /** + * Multiply the right matrix by the left and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + float m00 = left.m00 * right.m00 + left.m10 * right.m01; + float m01 = left.m01 * right.m00 + left.m11 * right.m01; + float m10 = left.m00 * right.m10 + left.m10 * right.m11; + float m11 = left.m01 * right.m10 + left.m11 * right.m11; + + dest.m00 = m00; + dest.m01 = m01; + dest.m10 = m10; + dest.m11 = m11; + + return dest; + } + + /** + * Transform a Vector by a matrix and return the result in a destination vector. + * + * @param left The left matrix + * @param right The right vector + * @param dest The destination vector, or null if a new one is to be created + * @return the destination vector + */ + public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) { + if (dest == null) + dest = new Vector2f(); + + float x = left.m00 * right.x + left.m10 * right.y; + float y = left.m01 * right.x + left.m11 * right.y; + + dest.x = x; + dest.y = y; + + return dest; + } + + /** + * Transpose this matrix + * + * @return this + */ + public Matrix transpose() { + return transpose(this); + } + + /** + * Transpose this matrix and place the result in another matrix. + * + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public Matrix2f transpose(Matrix2f dest) { + return transpose(this, dest); + } + + /** + * Transpose the source matrix and place the result in the destination matrix. + * + * @param src The source matrix or null if a new matrix is to be created + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix2f transpose(Matrix2f src, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + float m01 = src.m10; + float m10 = src.m01; + + dest.m01 = m01; + dest.m10 = m10; + + return dest; + } + + /** + * Invert this matrix + * + * @return this if successful, null otherwise + */ + public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and place the result in the destination matrix. + * + * @param src The source matrix to be inverted + * @param dest The destination matrix or null if a new matrix is to be created + * @return The inverted matrix, or null if source can't be reverted. + */ + public static Matrix2f invert(Matrix2f src, Matrix2f dest) { + /* + * inv(A) = 1/det(A) * adj(A); + */ + + float determinant = src.determinant(); + if (determinant != 0) { + if (dest == null) + dest = new Matrix2f(); + float determinant_inv = 1f / determinant; + float t00 = src.m11 * determinant_inv; + float t01 = -src.m01 * determinant_inv; + float t11 = src.m00 * determinant_inv; + float t10 = -src.m10 * determinant_inv; + + dest.m00 = t00; + dest.m01 = t01; + dest.m10 = t10; + dest.m11 = t11; + return dest; + } else + return null; + } + + /** + * Returns a string representation of this matrix + */ + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append(m00).append(' ').append(m10).append(' ').append('\n'); + buf.append(m01).append(' ').append(m11).append(' ').append('\n'); + return buf.toString(); + } + + /** + * Negate this matrix + * + * @return this + */ + public Matrix negate() { + return negate(this); + } + + /** + * Negate this matrix and stash the result in another matrix. + * + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public Matrix2f negate(Matrix2f dest) { + return negate(this, dest); + } + + /** + * Negate the source matrix and stash the result in the destination matrix. + * + * @param src The source matrix to be negated + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public static Matrix2f negate(Matrix2f src, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); + + dest.m00 = -src.m00; + dest.m01 = -src.m01; + dest.m10 = -src.m10; + dest.m11 = -src.m11; + + return dest; + } + + /** + * Set this matrix to be the identity matrix. + * + * @return this + */ + public Matrix setIdentity() { + return setIdentity(this); + } + + /** + * Set the source matrix to be the identity matrix. + * + * @param src The matrix to set to the identity. + * @return The source matrix + */ + public static Matrix2f setIdentity(Matrix2f src) { + src.m00 = 1.0f; + src.m01 = 0.0f; + src.m10 = 0.0f; + src.m11 = 1.0f; + return src; + } + + /** + * Set this matrix to 0. + * + * @return this + */ + public Matrix setZero() { + return setZero(this); + } + + public static Matrix2f setZero(Matrix2f src) { + src.m00 = 0.0f; + src.m01 = 0.0f; + src.m10 = 0.0f; + src.m11 = 0.0f; + return src; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Matrix#determinant() + */ + public float determinant() { + return m00 * m11 - m01 * m10; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix3f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix3f.java new file mode 100644 index 0000000..06ccf59 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix3f.java @@ -0,0 +1,529 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Holds a 3x3 matrix. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ + +public class Matrix3f extends Matrix implements Serializable { + + private static final long serialVersionUID = 1L; + + public float m00, m01, m02, m10, m11, m12, m20, m21, m22; + + /** + * Constructor for Matrix3f. Matrix is initialised to the identity. + */ + public Matrix3f() { + super(); + setIdentity(); + } + + /** + * Load from another matrix + * + * @param src The source matrix + * @return this + */ + public Matrix3f load(Matrix3f src) { + return load(src, this); + } + + /** + * Copy source matrix to destination matrix + * + * @param src The source matrix + * @param dest The destination matrix, or null of a new matrix is to be created + * @return The copied matrix + */ + public static Matrix3f load(Matrix3f src, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + + dest.m00 = src.m00; + dest.m10 = src.m10; + dest.m20 = src.m20; + dest.m01 = src.m01; + dest.m11 = src.m11; + dest.m21 = src.m21; + dest.m02 = src.m02; + dest.m12 = src.m12; + dest.m22 = src.m22; + + return dest; + } + + /** + * Load from a float buffer. The buffer stores the matrix in column major + * (OpenGL) order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix load(FloatBuffer buf) { + + m00 = buf.get(); + m01 = buf.get(); + m02 = buf.get(); + m10 = buf.get(); + m11 = buf.get(); + m12 = buf.get(); + m20 = buf.get(); + m21 = buf.get(); + m22 = buf.get(); + + return this; + } + + /** + * Load from a float buffer. The buffer stores the matrix in row major (maths) + * order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix loadTranspose(FloatBuffer buf) { + + m00 = buf.get(); + m10 = buf.get(); + m20 = buf.get(); + m01 = buf.get(); + m11 = buf.get(); + m21 = buf.get(); + m02 = buf.get(); + m12 = buf.get(); + m22 = buf.get(); + + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in column major + * (openGL) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix store(FloatBuffer buf) { + buf.put(m00); + buf.put(m01); + buf.put(m02); + buf.put(m10); + buf.put(m11); + buf.put(m12); + buf.put(m20); + buf.put(m21); + buf.put(m22); + return this; + } + + public Matrix store(float[] buf) { + buf[0] = m00; + buf[1] = m01; + buf[2] = m02; + buf[3] = m10; + buf[4] = m11; + buf[5] = m12; + buf[6] = m20; + buf[7] = m21; + buf[8] = m22; + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in row major + * (maths) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix storeTranspose(FloatBuffer buf) { + buf.put(m00); + buf.put(m10); + buf.put(m20); + buf.put(m01); + buf.put(m11); + buf.put(m21); + buf.put(m02); + buf.put(m12); + buf.put(m22); + return this; + } + + /** + * Add two matrices together and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + + dest.m00 = left.m00 + right.m00; + dest.m01 = left.m01 + right.m01; + dest.m02 = left.m02 + right.m02; + dest.m10 = left.m10 + right.m10; + dest.m11 = left.m11 + right.m11; + dest.m12 = left.m12 + right.m12; + dest.m20 = left.m20 + right.m20; + dest.m21 = left.m21 + right.m21; + dest.m22 = left.m22 + right.m22; + + return dest; + } + + /** + * Subtract the right matrix from the left and place the result in a third + * matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + + dest.m00 = left.m00 - right.m00; + dest.m01 = left.m01 - right.m01; + dest.m02 = left.m02 - right.m02; + dest.m10 = left.m10 - right.m10; + dest.m11 = left.m11 - right.m11; + dest.m12 = left.m12 - right.m12; + dest.m20 = left.m20 - right.m20; + dest.m21 = left.m21 - right.m21; + dest.m22 = left.m22 - right.m22; + + return dest; + } + + /** + * Multiply the right matrix by the left and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + + float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02; + float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02; + float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02; + float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12; + float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12; + float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12; + float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22; + float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22; + float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + + return dest; + } + + /** + * Transform a Vector by a matrix and return the result in a destination vector. + * + * @param left The left matrix + * @param right The right vector + * @param dest The destination vector, or null if a new one is to be created + * @return the destination vector + */ + public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) { + if (dest == null) + dest = new Vector3f(); + + float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z; + float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z; + float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z; + + dest.x = x; + dest.y = y; + dest.z = z; + + return dest; + } + + /** + * Transpose this matrix + * + * @return this + */ + public Matrix transpose() { + return transpose(this, this); + } + + /** + * Transpose this matrix and place the result in another matrix + * + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public Matrix3f transpose(Matrix3f dest) { + return transpose(this, dest); + } + + /** + * Transpose the source matrix and place the result into the destination matrix + * + * @param src The source matrix to be transposed + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix3f transpose(Matrix3f src, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + return dest; + } + + /** + * @return the determinant of the matrix + */ + public float determinant() { + float f = m00 * (m11 * m22 - m12 * m21) + m01 * (m12 * m20 - m10 * m22) + m02 * (m10 * m21 - m11 * m20); + return f; + } + + /** + * Returns a string representation of this matrix + */ + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append('\n'); + buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append('\n'); + buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append('\n'); + return buf.toString(); + } + + /** + * Invert this matrix + * + * @return this if successful, null otherwise + */ + public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and put the result into the destination matrix + * + * @param src The source matrix to be inverted + * @param dest The destination matrix, or null if a new one is to be created + * @return The inverted matrix if successful, null otherwise + */ + public static Matrix3f invert(Matrix3f src, Matrix3f dest) { + float determinant = src.determinant(); + + if (determinant != 0) { + if (dest == null) + dest = new Matrix3f(); + /* + * do it the ordinary way + * + * inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix) + * + * m00 m01 m02 m10 m11 m12 m20 m21 m22 + */ + float determinant_inv = 1f / determinant; + + // get the conjugate matrix + float t00 = src.m11 * src.m22 - src.m12 * src.m21; + float t01 = -src.m10 * src.m22 + src.m12 * src.m20; + float t02 = src.m10 * src.m21 - src.m11 * src.m20; + float t10 = -src.m01 * src.m22 + src.m02 * src.m21; + float t11 = src.m00 * src.m22 - src.m02 * src.m20; + float t12 = -src.m00 * src.m21 + src.m01 * src.m20; + float t20 = src.m01 * src.m12 - src.m02 * src.m11; + float t21 = -src.m00 * src.m12 + src.m02 * src.m10; + float t22 = src.m00 * src.m11 - src.m01 * src.m10; + + dest.m00 = t00 * determinant_inv; + dest.m11 = t11 * determinant_inv; + dest.m22 = t22 * determinant_inv; + dest.m01 = t10 * determinant_inv; + dest.m10 = t01 * determinant_inv; + dest.m20 = t02 * determinant_inv; + dest.m02 = t20 * determinant_inv; + dest.m12 = t21 * determinant_inv; + dest.m21 = t12 * determinant_inv; + return dest; + } else + return null; + } + + /** + * Negate this matrix + * + * @return this + */ + public Matrix negate() { + return negate(this); + } + + /** + * Negate this matrix and place the result in a destination matrix. + * + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public Matrix3f negate(Matrix3f dest) { + return negate(this, dest); + } + + /** + * Negate the source matrix and place the result in the destination matrix. + * + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public static Matrix3f negate(Matrix3f src, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); + + dest.m00 = -src.m00; + dest.m01 = -src.m02; + dest.m02 = -src.m01; + dest.m10 = -src.m10; + dest.m11 = -src.m12; + dest.m12 = -src.m11; + dest.m20 = -src.m20; + dest.m21 = -src.m22; + dest.m22 = -src.m21; + return dest; + } + + /** + * Set this matrix to be the identity matrix. + * + * @return this + */ + public Matrix setIdentity() { + return setIdentity(this); + } + + /** + * Set the matrix to be the identity matrix. + * + * @param m The matrix to be set to the identity + * @return m + */ + public static Matrix3f setIdentity(Matrix3f m) { + m.m00 = 1.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m10 = 0.0f; + m.m11 = 1.0f; + m.m12 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 1.0f; + return m; + } + + /** + * Set this matrix to 0. + * + * @return this + */ + public Matrix setZero() { + return setZero(this); + } + + /** + * Set the matrix matrix to 0. + * + * @param m The matrix to be set to 0 + * @return m + */ + public static Matrix3f setZero(Matrix3f m) { + m.m00 = 0.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m10 = 0.0f; + m.m11 = 0.0f; + m.m12 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 0.0f; + return m; + } + + public boolean equals(Object m) { + return (m instanceof Matrix3f) && equal(this, (Matrix3f) m); + } + + public static boolean equal(Matrix3f a, Matrix3f b) { + return a.m00 == b.m00 && a.m01 == b.m01 && a.m02 == b.m02 && a.m10 == b.m10 && a.m11 == b.m11 && a.m12 == b.m12 + && a.m20 == b.m20 && a.m21 == b.m21 && a.m22 == b.m22; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix4f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix4f.java new file mode 100644 index 0000000..cdca438 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Matrix4f.java @@ -0,0 +1,902 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * Holds a 4x4 float matrix. + * + * @author foo + */ +public class Matrix4f extends Matrix implements Serializable { + private static final long serialVersionUID = 1L; + + public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33; + + /** + * Construct a new matrix, initialized to the identity. + */ + public Matrix4f() { + super(); + setIdentity(); + } + + public Matrix4f(final Matrix4f src) { + super(); + load(src); + } + + /** + * Returns a string representation of this matrix + */ + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append(m30).append('\n'); + buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append(m31).append('\n'); + buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append(m32).append('\n'); + buf.append(m03).append(' ').append(m13).append(' ').append(m23).append(' ').append(m33).append('\n'); + return buf.toString(); + } + + /** + * Set this matrix to be the identity matrix. + * + * @return this + */ + public Matrix setIdentity() { + return setIdentity(this); + } + + /** + * Set the given matrix to be the identity matrix. + * + * @param m The matrix to set to the identity + * @return m + */ + public static Matrix4f setIdentity(Matrix4f m) { + m.m00 = 1.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m03 = 0.0f; + m.m10 = 0.0f; + m.m11 = 1.0f; + m.m12 = 0.0f; + m.m13 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 1.0f; + m.m23 = 0.0f; + m.m30 = 0.0f; + m.m31 = 0.0f; + m.m32 = 0.0f; + m.m33 = 1.0f; + + return m; + } + + /** + * Set this matrix to 0. + * + * @return this + */ + public Matrix setZero() { + return setZero(this); + } + + /** + * Set the given matrix to 0. + * + * @param m The matrix to set to 0 + * @return m + */ + public static Matrix4f setZero(Matrix4f m) { + m.m00 = 0.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m03 = 0.0f; + m.m10 = 0.0f; + m.m11 = 0.0f; + m.m12 = 0.0f; + m.m13 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 0.0f; + m.m23 = 0.0f; + m.m30 = 0.0f; + m.m31 = 0.0f; + m.m32 = 0.0f; + m.m33 = 0.0f; + + return m; + } + + /** + * Load from another matrix4f + * + * @param src The source matrix + * @return this + */ + public Matrix4f load(Matrix4f src) { + return load(src, this); + } + + /** + * Copy the source matrix to the destination matrix + * + * @param src The source matrix + * @param dest The destination matrix, or null of a new one is to be created + * @return The copied matrix + */ + public static Matrix4f load(Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + dest.m00 = src.m00; + dest.m01 = src.m01; + dest.m02 = src.m02; + dest.m03 = src.m03; + dest.m10 = src.m10; + dest.m11 = src.m11; + dest.m12 = src.m12; + dest.m13 = src.m13; + dest.m20 = src.m20; + dest.m21 = src.m21; + dest.m22 = src.m22; + dest.m23 = src.m23; + dest.m30 = src.m30; + dest.m31 = src.m31; + dest.m32 = src.m32; + dest.m33 = src.m33; + + return dest; + } + + /** + * Load from a float buffer. The buffer stores the matrix in column major + * (OpenGL) order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix load(FloatBuffer buf) { + + m00 = buf.get(); + m01 = buf.get(); + m02 = buf.get(); + m03 = buf.get(); + m10 = buf.get(); + m11 = buf.get(); + m12 = buf.get(); + m13 = buf.get(); + m20 = buf.get(); + m21 = buf.get(); + m22 = buf.get(); + m23 = buf.get(); + m30 = buf.get(); + m31 = buf.get(); + m32 = buf.get(); + m33 = buf.get(); + + return this; + } + + /** + * Load from a float buffer. The buffer stores the matrix in row major (maths) + * order. + * + * @param buf A float buffer to read from + * @return this + */ + public Matrix loadTranspose(FloatBuffer buf) { + + m00 = buf.get(); + m10 = buf.get(); + m20 = buf.get(); + m30 = buf.get(); + m01 = buf.get(); + m11 = buf.get(); + m21 = buf.get(); + m31 = buf.get(); + m02 = buf.get(); + m12 = buf.get(); + m22 = buf.get(); + m32 = buf.get(); + m03 = buf.get(); + m13 = buf.get(); + m23 = buf.get(); + m33 = buf.get(); + + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in column major + * (openGL) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix store(FloatBuffer buf) { + buf.put(m00); + buf.put(m01); + buf.put(m02); + buf.put(m03); + buf.put(m10); + buf.put(m11); + buf.put(m12); + buf.put(m13); + buf.put(m20); + buf.put(m21); + buf.put(m22); + buf.put(m23); + buf.put(m30); + buf.put(m31); + buf.put(m32); + buf.put(m33); + return this; + } + + public Matrix store(float[] buf) { + buf[0] = m00; + buf[1] = m01; + buf[2] = m02; + buf[3] = m03; + buf[4] = m10; + buf[5] = m11; + buf[6] = m12; + buf[7] = m13; + buf[8] = m20; + buf[9] = m21; + buf[10] = m22; + buf[11] = m23; + buf[12] = m30; + buf[13] = m31; + buf[14] = m32; + buf[15] = m33; + return this; + } + + /** + * Store this matrix in a float buffer. The matrix is stored in row major + * (maths) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix storeTranspose(FloatBuffer buf) { + buf.put(m00); + buf.put(m10); + buf.put(m20); + buf.put(m30); + buf.put(m01); + buf.put(m11); + buf.put(m21); + buf.put(m31); + buf.put(m02); + buf.put(m12); + buf.put(m22); + buf.put(m32); + buf.put(m03); + buf.put(m13); + buf.put(m23); + buf.put(m33); + return this; + } + + /** + * Store the rotation portion of this matrix in a float buffer. The matrix is + * stored in column major (openGL) order. + * + * @param buf The buffer to store this matrix in + */ + public Matrix store3f(FloatBuffer buf) { + buf.put(m00); + buf.put(m01); + buf.put(m02); + buf.put(m10); + buf.put(m11); + buf.put(m12); + buf.put(m20); + buf.put(m21); + buf.put(m22); + return this; + } + + /** + * Add two matrices together and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + dest.m00 = left.m00 + right.m00; + dest.m01 = left.m01 + right.m01; + dest.m02 = left.m02 + right.m02; + dest.m03 = left.m03 + right.m03; + dest.m10 = left.m10 + right.m10; + dest.m11 = left.m11 + right.m11; + dest.m12 = left.m12 + right.m12; + dest.m13 = left.m13 + right.m13; + dest.m20 = left.m20 + right.m20; + dest.m21 = left.m21 + right.m21; + dest.m22 = left.m22 + right.m22; + dest.m23 = left.m23 + right.m23; + dest.m30 = left.m30 + right.m30; + dest.m31 = left.m31 + right.m31; + dest.m32 = left.m32 + right.m32; + dest.m33 = left.m33 + right.m33; + + return dest; + } + + /** + * Subtract the right matrix from the left and place the result in a third + * matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + dest.m00 = left.m00 - right.m00; + dest.m01 = left.m01 - right.m01; + dest.m02 = left.m02 - right.m02; + dest.m03 = left.m03 - right.m03; + dest.m10 = left.m10 - right.m10; + dest.m11 = left.m11 - right.m11; + dest.m12 = left.m12 - right.m12; + dest.m13 = left.m13 - right.m13; + dest.m20 = left.m20 - right.m20; + dest.m21 = left.m21 - right.m21; + dest.m22 = left.m22 - right.m22; + dest.m23 = left.m23 - right.m23; + dest.m30 = left.m30 - right.m30; + dest.m31 = left.m31 - right.m31; + dest.m32 = left.m32 - right.m32; + dest.m33 = left.m33 - right.m33; + + return dest; + } + + /** + * Multiply the right matrix by the left and place the result in a third matrix. + * + * @param left The left source matrix + * @param right The right source matrix + * @param dest The destination matrix, or null if a new one is to be created + * @return the destination matrix + */ + public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03; + float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03; + float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03; + float m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03; + float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13; + float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13; + float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13; + float m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13; + float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23; + float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23; + float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23; + float m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23; + float m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33; + float m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33; + float m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33; + float m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m03 = m03; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m13 = m13; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + dest.m23 = m23; + dest.m30 = m30; + dest.m31 = m31; + dest.m32 = m32; + dest.m33 = m33; + + return dest; + } + + /** + * Transform a Vector by a matrix and return the result in a destination vector. + * + * @param left The left matrix + * @param right The right vector + * @param dest The destination vector, or null if a new one is to be created + * @return the destination vector + */ + public static Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) { + if (dest == null) + dest = new Vector4f(); + + float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w; + float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w; + float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w; + float w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w; + + dest.x = x; + dest.y = y; + dest.z = z; + dest.w = w; + + return dest; + } + + /** + * Transpose this matrix + * + * @return this + */ + public Matrix transpose() { + return transpose(this); + } + + /** + * Translate this matrix + * + * @param vec The vector to translate by + * @return this + */ + public Matrix4f translate(Vector2f vec) { + return translate(vec, this); + } + + /** + * Translate this matrix + * + * @param vec The vector to translate by + * @return this + */ + public Matrix4f translate(Vector3f vec) { + return translate(vec, this); + } + + /** + * Scales this matrix + * + * @param vec The vector to scale by + * @return this + */ + public Matrix4f scale(Vector3f vec) { + return scale(vec, this, this); + } + + /** + * Scales the source matrix and put the result in the destination matrix + * + * @param vec The vector to scale by + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The scaled matrix + */ + public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + dest.m00 = src.m00 * vec.x; + dest.m01 = src.m01 * vec.x; + dest.m02 = src.m02 * vec.x; + dest.m03 = src.m03 * vec.x; + dest.m10 = src.m10 * vec.y; + dest.m11 = src.m11 * vec.y; + dest.m12 = src.m12 * vec.y; + dest.m13 = src.m13 * vec.y; + dest.m20 = src.m20 * vec.z; + dest.m21 = src.m21 * vec.z; + dest.m22 = src.m22 * vec.z; + dest.m23 = src.m23 * vec.z; + return dest; + } + + /** + * Rotates the matrix around the given axis the specified angle + * + * @param angle the angle, in radians. + * @param axis The vector representing the rotation axis. Must be normalized. + * @return this + */ + public Matrix4f rotate(float angle, Vector3f axis) { + return rotate(angle, axis, this); + } + + /** + * Rotates the matrix around the given axis the specified angle + * + * @param angle the angle, in radians. + * @param axis The vector representing the rotation axis. Must be normalized. + * @param dest The matrix to put the result, or null if a new matrix is to be + * created + * @return The rotated matrix + */ + public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { + return rotate(angle, axis, this, dest); + } + + /** + * Rotates the source matrix around the given axis the specified angle and put + * the result in the destination matrix. + * + * @param angle the angle, in radians. + * @param axis The vector representing the rotation axis. Must be normalized. + * @param src The matrix to rotate + * @param dest The matrix to put the result, or null if a new matrix is to be + * created + * @return The rotated matrix + */ + public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + float c = (float) Math.cos(angle); + float s = (float) Math.sin(angle); + float oneminusc = 1.0f - c; + float xy = axis.x * axis.y; + float yz = axis.y * axis.z; + float xz = axis.x * axis.z; + float xs = axis.x * s; + float ys = axis.y * s; + float zs = axis.z * s; + + float f00 = axis.x * axis.x * oneminusc + c; + float f01 = xy * oneminusc + zs; + float f02 = xz * oneminusc - ys; + // n[3] not used + float f10 = xy * oneminusc - zs; + float f11 = axis.y * axis.y * oneminusc + c; + float f12 = yz * oneminusc + xs; + // n[7] not used + float f20 = xz * oneminusc + ys; + float f21 = yz * oneminusc - xs; + float f22 = axis.z * axis.z * oneminusc + c; + + float t00 = src.m00 * f00 + src.m10 * f01 + src.m20 * f02; + float t01 = src.m01 * f00 + src.m11 * f01 + src.m21 * f02; + float t02 = src.m02 * f00 + src.m12 * f01 + src.m22 * f02; + float t03 = src.m03 * f00 + src.m13 * f01 + src.m23 * f02; + float t10 = src.m00 * f10 + src.m10 * f11 + src.m20 * f12; + float t11 = src.m01 * f10 + src.m11 * f11 + src.m21 * f12; + float t12 = src.m02 * f10 + src.m12 * f11 + src.m22 * f12; + float t13 = src.m03 * f10 + src.m13 * f11 + src.m23 * f12; + dest.m20 = src.m00 * f20 + src.m10 * f21 + src.m20 * f22; + dest.m21 = src.m01 * f20 + src.m11 * f21 + src.m21 * f22; + dest.m22 = src.m02 * f20 + src.m12 * f21 + src.m22 * f22; + dest.m23 = src.m03 * f20 + src.m13 * f21 + src.m23 * f22; + dest.m00 = t00; + dest.m01 = t01; + dest.m02 = t02; + dest.m03 = t03; + dest.m10 = t10; + dest.m11 = t11; + dest.m12 = t12; + dest.m13 = t13; + return dest; + } + + /** + * Translate this matrix and stash the result in another matrix + * + * @param vec The vector to translate by + * @param dest The destination matrix or null if a new matrix is to be created + * @return the translated matrix + */ + public Matrix4f translate(Vector3f vec, Matrix4f dest) { + return translate(vec, this, dest); + } + + /** + * Translate the source matrix and stash the result in the destination matrix + * + * @param vec The vector to translate by + * @param src The source matrix + * @param dest The destination matrix or null if a new matrix is to be created + * @return The translated matrix + */ + public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z; + dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z; + dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z; + dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z; + + return dest; + } + + /** + * Translate this matrix and stash the result in another matrix + * + * @param vec The vector to translate by + * @param dest The destination matrix or null if a new matrix is to be created + * @return the translated matrix + */ + public Matrix4f translate(Vector2f vec, Matrix4f dest) { + return translate(vec, this, dest); + } + + /** + * Translate the source matrix and stash the result in the destination matrix + * + * @param vec The vector to translate by + * @param src The source matrix + * @param dest The destination matrix or null if a new matrix is to be created + * @return The translated matrix + */ + public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + dest.m30 += src.m00 * vec.x + src.m10 * vec.y; + dest.m31 += src.m01 * vec.x + src.m11 * vec.y; + dest.m32 += src.m02 * vec.x + src.m12 * vec.y; + dest.m33 += src.m03 * vec.x + src.m13 * vec.y; + + return dest; + } + + /** + * Transpose this matrix and place the result in another matrix + * + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public Matrix4f transpose(Matrix4f dest) { + return transpose(this, dest); + } + + /** + * Transpose the source matrix and place the result in the destination matrix + * + * @param src The source matrix + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix4f transpose(Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m03 = src.m30; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m13 = src.m31; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; + float m23 = src.m32; + float m30 = src.m03; + float m31 = src.m13; + float m32 = src.m23; + float m33 = src.m33; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m03 = m03; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m13 = m13; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + dest.m23 = m23; + dest.m30 = m30; + dest.m31 = m31; + dest.m32 = m32; + dest.m33 = m33; + + return dest; + } + + /** + * @return the determinant of the matrix + */ + public float determinant() { + float f = m00 * ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32) - m13 * m22 * m31 - m11 * m23 * m32 + - m12 * m21 * m33); + f -= m01 * ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32) - m13 * m22 * m30 - m10 * m23 * m32 + - m12 * m20 * m33); + f += m02 * ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31) - m13 * m21 * m30 - m10 * m23 * m31 + - m11 * m20 * m33); + f -= m03 * ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31) - m12 * m21 * m30 - m10 * m22 * m31 + - m11 * m20 * m32); + return f; + } + + /** + * Calculate the determinant of a 3x3 matrix + * + * @return result + */ + + private static float determinant3x3(float t00, float t01, float t02, float t10, float t11, float t12, float t20, + float t21, float t22) { + return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + t02 * (t10 * t21 - t11 * t20); + } + + /** + * Invert this matrix + * + * @return this if successful, null otherwise + */ + public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and put the result in the destination + * + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The inverted matrix if successful, null otherwise + */ + public static Matrix4f invert(Matrix4f src, Matrix4f dest) { + float determinant = src.determinant(); + + if (determinant != 0) { + /* + * m00 m01 m02 m03 m10 m11 m12 m13 m20 m21 m22 m23 m30 m31 m32 m33 + */ + if (dest == null) + dest = new Matrix4f(); + float determinant_inv = 1f / determinant; + + // first row + float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); + float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, + src.m33); + float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); + float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, + src.m32); + // second row + float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, + src.m33); + float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); + float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, + src.m33); + float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); + // third row + float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33); + float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, + src.m33); + float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33); + float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, + src.m32); + // fourth row + float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, + src.m23); + float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23); + float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, + src.m23); + float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22); + + // transpose and divide by the determinant + dest.m00 = t00 * determinant_inv; + dest.m11 = t11 * determinant_inv; + dest.m22 = t22 * determinant_inv; + dest.m33 = t33 * determinant_inv; + dest.m01 = t10 * determinant_inv; + dest.m10 = t01 * determinant_inv; + dest.m20 = t02 * determinant_inv; + dest.m02 = t20 * determinant_inv; + dest.m12 = t21 * determinant_inv; + dest.m21 = t12 * determinant_inv; + dest.m03 = t30 * determinant_inv; + dest.m30 = t03 * determinant_inv; + dest.m13 = t31 * determinant_inv; + dest.m31 = t13 * determinant_inv; + dest.m32 = t23 * determinant_inv; + dest.m23 = t32 * determinant_inv; + return dest; + } else + return null; + } + + /** + * Negate this matrix + * + * @return this + */ + public Matrix negate() { + return negate(this); + } + + /** + * Negate this matrix and place the result in a destination matrix. + * + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public Matrix4f negate(Matrix4f dest) { + return negate(this, dest); + } + + /** + * Negate this matrix and place the result in a destination matrix. + * + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The negated matrix + */ + public static Matrix4f negate(Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + + dest.m00 = -src.m00; + dest.m01 = -src.m01; + dest.m02 = -src.m02; + dest.m03 = -src.m03; + dest.m10 = -src.m10; + dest.m11 = -src.m11; + dest.m12 = -src.m12; + dest.m13 = -src.m13; + dest.m20 = -src.m20; + dest.m21 = -src.m21; + dest.m22 = -src.m22; + dest.m23 = -src.m23; + dest.m30 = -src.m30; + dest.m31 = -src.m31; + dest.m32 = -src.m32; + dest.m33 = -src.m33; + + return dest; + } + + public boolean equals(Object m) { + return (m instanceof Matrix4f) && equal(this, (Matrix4f) m); + } + + public static boolean equal(Matrix4f a, Matrix4f b) { + return a.m00 == b.m00 && a.m01 == b.m01 && a.m02 == b.m02 && a.m03 == b.m03 && a.m10 == b.m10 && a.m11 == b.m11 + && a.m12 == b.m12 && a.m13 == b.m13 && a.m20 == b.m20 && a.m21 == b.m21 && a.m22 == b.m22 + && a.m23 == b.m23 && a.m30 == b.m30 && a.m31 == b.m31 && a.m32 == b.m32 && a.m33 == b.m33; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Quaternion.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Quaternion.java new file mode 100644 index 0000000..663448f --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Quaternion.java @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * + * Quaternions for LWJGL! + * + * @author fbi + * @version $Revision$ + * $Id$ + */ + +import java.nio.FloatBuffer; + +public class Quaternion extends Vector implements ReadableVector4f { + private static final long serialVersionUID = 1L; + + public float x, y, z, w; + + /** + * C'tor. The quaternion will be initialized to the identity. + */ + public Quaternion() { + super(); + setIdentity(); + } + + /** + * C'tor + * + * @param src + */ + public Quaternion(ReadableVector4f src) { + set(src); + } + + /** + * C'tor + * + */ + public Quaternion(float x, float y, float z, float w) { + set(x, y, z, w); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector2f#set(float, float) + */ + public void set(float x, float y) { + this.x = x; + this.y = y; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float) + */ + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float) + */ + public void set(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + /** + * Load from another Vector4f + * + * @param src The source vector + * @return this + */ + public Quaternion set(ReadableVector4f src) { + x = src.getX(); + y = src.getY(); + z = src.getZ(); + w = src.getW(); + return this; + } + + /** + * Set this quaternion to the multiplication identity. + * + * @return this + */ + public Quaternion setIdentity() { + return setIdentity(this); + } + + /** + * Set the given quaternion to the multiplication identity. + * + * @param q The quaternion + * @return q + */ + public static Quaternion setIdentity(Quaternion q) { + q.x = 0; + q.y = 0; + q.z = 0; + q.w = 1; + return q; + } + + /** + * @return the length squared of the quaternion + */ + public float lengthSquared() { + return x * x + y * y + z * z + w * w; + } + + /** + * Normalise the source quaternion and place the result in another quaternion. + * + * @param src The source quaternion + * @param dest The destination quaternion, or null if a new quaternion is to be + * created + * @return The normalised quaternion + */ + public static Quaternion normalise(Quaternion src, Quaternion dest) { + float inv_l = 1f / src.length(); + + if (dest == null) + dest = new Quaternion(); + + dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l); + + return dest; + } + + /** + * Normalise this quaternion and place the result in another quaternion. + * + * @param dest The destination quaternion, or null if a new quaternion is to be + * created + * @return the normalised quaternion + */ + public Quaternion normalise(Quaternion dest) { + return normalise(this, dest); + } + + /** + * The dot product of two quaternions + * + * @param left The LHS quat + * @param right The RHS quat + * @return left dot right + */ + public static float dot(Quaternion left, Quaternion right) { + return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; + } + + /** + * Calculate the conjugate of this quaternion and put it into the given one + * + * @param dest The quaternion which should be set to the conjugate of this + * quaternion + */ + public Quaternion negate(Quaternion dest) { + return negate(this, dest); + } + + /** + * Calculate the conjugate of this quaternion and put it into the given one + * + * @param src The source quaternion + * @param dest The quaternion which should be set to the conjugate of this + * quaternion + */ + public static Quaternion negate(Quaternion src, Quaternion dest) { + if (dest == null) + dest = new Quaternion(); + + dest.x = -src.x; + dest.y = -src.y; + dest.z = -src.z; + dest.w = src.w; + + return dest; + } + + /** + * Calculate the conjugate of this quaternion + */ + public Vector negate() { + return negate(this, this); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.Vector#load(java.nio.FloatBuffer) + */ + public Vector load(FloatBuffer buf) { + x = buf.get(); + y = buf.get(); + z = buf.get(); + w = buf.get(); + return this; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#scale(float) + */ + public Vector scale(float scale) { + return scale(scale, this, this); + } + + /** + * Scale the source quaternion by scale and put the result in the destination + * + * @param scale The amount to scale by + * @param src The source quaternion + * @param dest The destination quaternion, or null if a new quaternion is to be + * created + * @return The scaled quaternion + */ + public static Quaternion scale(float scale, Quaternion src, Quaternion dest) { + if (dest == null) + dest = new Quaternion(); + dest.x = src.x * scale; + dest.y = src.y * scale; + dest.z = src.z * scale; + dest.w = src.w * scale; + return dest; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer) + */ + public Vector store(FloatBuffer buf) { + buf.put(x); + buf.put(y); + buf.put(z); + buf.put(w); + + return this; + } + + /** + * @return x + */ + public final float getX() { + return x; + } + + /** + * @return y + */ + public final float getY() { + return y; + } + + /** + * Set X + * + * @param x + */ + public final void setX(float x) { + this.x = x; + } + + /** + * Set Y + * + * @param y + */ + public final void setY(float y) { + this.y = y; + } + + /** + * Set Z + * + * @param z + */ + public void setZ(float z) { + this.z = z; + } + + /* + * (Overrides) + * + * @see org.lwjgl.vector.ReadableVector3f#getZ() + */ + public float getZ() { + return z; + } + + /** + * Set W + * + * @param w + */ + public void setW(float w) { + this.w = w; + } + + /* + * (Overrides) + * + * @see org.lwjgl.vector.ReadableVector3f#getW() + */ + public float getW() { + return w; + } + + public String toString() { + return "Quaternion: " + x + " " + y + " " + z + " " + w; + } + + /** + * Sets the value of this quaternion to the quaternion product of quaternions + * left and right (this = left * right). Note that this is safe for aliasing + * (e.g. this can be left or right). + * + * @param left the first quaternion + * @param right the second quaternion + */ + public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest) { + if (dest == null) + dest = new Quaternion(); + dest.set(left.x * right.w + left.w * right.x + left.y * right.z - left.z * right.y, + left.y * right.w + left.w * right.y + left.z * right.x - left.x * right.z, + left.z * right.w + left.w * right.z + left.x * right.y - left.y * right.x, + left.w * right.w - left.x * right.x - left.y * right.y - left.z * right.z); + return dest; + } + + /** + * + * Multiplies quaternion left by the inverse of quaternion right and places the + * value into this quaternion. The value of both argument quaternions is + * preservered (this = left * right^-1). + * + * @param left the left quaternion + * @param right the right quaternion + */ + public static Quaternion mulInverse(Quaternion left, Quaternion right, Quaternion dest) { + float n = right.lengthSquared(); + // zero-div may occur. + n = (n == 0.0 ? n : 1 / n); + // store on stack once for aliasing-safty + if (dest == null) + dest = new Quaternion(); + dest.set((left.x * right.w - left.w * right.x - left.y * right.z + left.z * right.y) * n, + (left.y * right.w - left.w * right.y - left.z * right.x + left.x * right.z) * n, + (left.z * right.w - left.w * right.z - left.x * right.y + left.y * right.x) * n, + (left.w * right.w + left.x * right.x + left.y * right.y + left.z * right.z) * n); + + return dest; + } + + /** + * Sets the value of this quaternion to the equivalent rotation of the + * Axis-Angle argument. + * + * @param a1 the axis-angle: (x,y,z) is the axis and w is the angle + */ + public final void setFromAxisAngle(Vector4f a1) { + x = a1.x; + y = a1.y; + z = a1.z; + float n = (float) Math.sqrt(x * x + y * y + z * z); + // zero-div may occur. + float s = (float) (Math.sin(0.5 * a1.w) / n); + x *= s; + y *= s; + z *= s; + w = (float) Math.cos(0.5 * a1.w); + } + + /** + * Sets the value of this quaternion using the rotational component of the + * passed matrix. + * + * @param m The matrix + * @return this + */ + public final Quaternion setFromMatrix(Matrix4f m) { + return setFromMatrix(m, this); + } + + /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m The source matrix + * @param q The destination quaternion, or null if a new quaternion is to be + * created + * @return q + */ + public static Quaternion setFromMatrix(Matrix4f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22); + } + + /** + * Sets the value of this quaternion using the rotational component of the + * passed matrix. + * + * @param m The source matrix + */ + public final Quaternion setFromMatrix(Matrix3f m) { + return setFromMatrix(m, this); + } + + /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m The source matrix + * @param q The destination quaternion, or null if a new quaternion is to be + * created + * @return q + */ + public static Quaternion setFromMatrix(Matrix3f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22); + } + + /** + * Private method to perform the matrix-to-quaternion conversion + */ + private Quaternion setFromMat(float m00, float m01, float m02, float m10, float m11, float m12, float m20, + float m21, float m22) { + + float s; + float tr = m00 + m11 + m22; + if (tr >= 0.0) { + s = (float) Math.sqrt(tr + 1.0); + w = s * 0.5f; + s = 0.5f / s; + x = (m21 - m12) * s; + y = (m02 - m20) * s; + z = (m10 - m01) * s; + } else { + float max = Math.max(Math.max(m00, m11), m22); + if (max == m00) { + s = (float) Math.sqrt(m00 - (m11 + m22) + 1.0); + x = s * 0.5f; + s = 0.5f / s; + y = (m01 + m10) * s; + z = (m20 + m02) * s; + w = (m21 - m12) * s; + } else if (max == m11) { + s = (float) Math.sqrt(m11 - (m22 + m00) + 1.0); + y = s * 0.5f; + s = 0.5f / s; + z = (m12 + m21) * s; + x = (m01 + m10) * s; + w = (m02 - m20) * s; + } else { + s = (float) Math.sqrt(m22 - (m00 + m11) + 1.0); + z = s * 0.5f; + s = 0.5f / s; + x = (m20 + m02) * s; + y = (m12 + m21) * s; + w = (m10 - m01) * s; + } + } + return this; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector.java b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector.java new file mode 100644 index 0000000..e72d312 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.nio.FloatBuffer; + +/** + * @author foo + */ +public interface ReadableVector { + /** + * @return the length of the vector + */ + float length(); + + /** + * @return the length squared of the vector + */ + float lengthSquared(); + + /** + * Store this vector in a FloatBuffer + * + * @param buf The buffer to store it in, at the current position + * @return this + */ + Vector store(FloatBuffer buf); +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector2f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector2f.java new file mode 100644 index 0000000..f857c6f --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector2f.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * @author foo + */ +public interface ReadableVector2f extends ReadableVector { + /** + * @return x + */ + float getX(); + + /** + * @return y + */ + float getY(); +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector3f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector3f.java new file mode 100644 index 0000000..6eae2ec --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector3f.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * @author foo + */ +public interface ReadableVector3f extends ReadableVector2f { + /** + * @return z + */ + float getZ(); +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector4f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector4f.java new file mode 100644 index 0000000..feedc20 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/ReadableVector4f.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * @author foo + */ +public interface ReadableVector4f extends ReadableVector3f { + + /** + * @return w + */ + float getW(); + +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Vector.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector.java new file mode 100644 index 0000000..61dfb43 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Base class for vectors. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ +public abstract class Vector implements Serializable, ReadableVector { + + /** + * Constructor for Vector. + */ + protected Vector() { + super(); + } + + /** + * @return the length of the vector + */ + public final float length() { + return (float) Math.sqrt(lengthSquared()); + } + + /** + * @return the length squared of the vector + */ + public abstract float lengthSquared(); + + /** + * Load this vector from a FloatBuffer + * + * @param buf The buffer to load it from, at the current position + * @return this + */ + public abstract Vector load(FloatBuffer buf); + + /** + * Negate a vector + * + * @return this + */ + public abstract Vector negate(); + + /** + * Normalise this vector + * + * @return this + */ + public final Vector normalise() { + float len = length(); + if (len != 0.0f) { + float l = 1.0f / len; + return scale(l); + } else + throw new IllegalStateException("Zero length vector"); + } + + /** + * Store this vector in a FloatBuffer + * + * @param buf The buffer to store it in, at the current position + * @return this + */ + public abstract Vector store(FloatBuffer buf); + + /** + * Scale this vector + * + * @param scale The scale factor + * @return this + */ + public abstract Vector scale(float scale); + +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Vector2f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector2f.java new file mode 100644 index 0000000..4201c7a --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector2f.java @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Holds a 2-tuple vector. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ + +public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f { + + private static final long serialVersionUID = 1L; + + public float x, y; + + /** + * Constructor for Vector2f. + */ + public Vector2f() { + super(); + } + + /** + * Constructor. + */ + public Vector2f(ReadableVector2f src) { + set(src); + } + + /** + * Constructor. + */ + public Vector2f(float x, float y) { + set(x, y); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector2f#set(float, float) + */ + public void set(float x, float y) { + this.x = x; + this.y = y; + } + + /** + * Load from another Vector2f + * + * @param src The source vector + * @return this + */ + public Vector2f set(ReadableVector2f src) { + x = src.getX(); + y = src.getY(); + return this; + } + + /** + * @return the length squared of the vector + */ + public float lengthSquared() { + return x * x + y * y; + } + + /** + * Translate a vector + * + * @param x The translation in x + * @param y the translation in y + * @return this + */ + public Vector2f translate(float x, float y) { + this.x += x; + this.y += y; + return this; + } + + /** + * Negate a vector + * + * @return this + */ + public Vector negate() { + x = -x; + y = -y; + return this; + } + + /** + * Negate a vector and place the result in a destination vector. + * + * @param dest The destination vector or null if a new vector is to be created + * @return the negated vector + */ + public Vector2f negate(Vector2f dest) { + if (dest == null) + dest = new Vector2f(); + dest.x = -x; + dest.y = -y; + return dest; + } + + /** + * Normalise this vector and place the result in another vector. + * + * @param dest The destination vector, or null if a new vector is to be created + * @return the normalised vector + */ + public Vector2f normalise(Vector2f dest) { + float l = length(); + + if (dest == null) + dest = new Vector2f(x / l, y / l); + else + dest.set(x / l, y / l); + + return dest; + } + + /** + * The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y + + * v1.z * v2.z + * + * @param left The LHS vector + * @param right The RHS vector + * @return left dot right + */ + public static float dot(Vector2f left, Vector2f right) { + return left.x * right.x + left.y * right.y; + } + + /** + * Calculate the angle between two vectors, in radians + * + * @param a A vector + * @param b The other vector + * @return the angle between the two vectors, in radians + */ + public static float angle(Vector2f a, Vector2f b) { + float dls = dot(a, b) / (a.length() * b.length()); + if (dls < -1f) + dls = -1f; + else if (dls > 1.0f) + dls = 1.0f; + return (float) Math.acos(dls); + } + + /** + * Add a vector to another vector and place the result in a destination vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return the sum of left and right in dest + */ + public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) { + if (dest == null) + return new Vector2f(left.x + right.x, left.y + right.y); + else { + dest.set(left.x + right.x, left.y + right.y); + return dest; + } + } + + /** + * Subtract a vector from another vector and place the result in a destination + * vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return left minus right in dest + */ + public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) { + if (dest == null) + return new Vector2f(left.x - right.x, left.y - right.y); + else { + dest.set(left.x - right.x, left.y - right.y); + return dest; + } + } + + /** + * Store this vector in a FloatBuffer + * + * @param buf The buffer to store it in, at the current position + * @return this + */ + public Vector store(FloatBuffer buf) { + buf.put(x); + buf.put(y); + return this; + } + + /** + * Load this vector from a FloatBuffer + * + * @param buf The buffer to load it from, at the current position + * @return this + */ + public Vector load(FloatBuffer buf) { + x = buf.get(); + y = buf.get(); + return this; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#scale(float) + */ + public Vector scale(float scale) { + + x *= scale; + y *= scale; + + return this; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuilder sb = new StringBuilder(64); + + sb.append("Vector2f["); + sb.append(x); + sb.append(", "); + sb.append(y); + sb.append(']'); + return sb.toString(); + } + + /** + * @return x + */ + public final float getX() { + return x; + } + + /** + * @return y + */ + public final float getY() { + return y; + } + + /** + * Set X + * + * @param x + */ + public final void setX(float x) { + this.x = x; + } + + /** + * Set Y + * + * @param y + */ + public final void setY(float y) { + this.y = y; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Vector2f other = (Vector2f) obj; + + if (x == other.x && y == other.y) + return true; + + return false; + } + +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Vector3f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector3f.java new file mode 100644 index 0000000..282170f --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector3f.java @@ -0,0 +1,376 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Holds a 3-tuple vector. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ + +public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f { + + private static final long serialVersionUID = 1L; + + public float x, y, z; + + /** + * Constructor for Vector3f. + */ + public Vector3f() { + super(); + } + + /** + * Constructor + */ + public Vector3f(ReadableVector3f src) { + set(src); + } + + /** + * Constructor + */ + public Vector3f(float x, float y, float z) { + set(x, y, z); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector2f#set(float, float) + */ + public void set(float x, float y) { + this.x = x; + this.y = y; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float) + */ + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Load from another Vector3f + * + * @param src The source vector + * @return this + */ + public Vector3f set(ReadableVector3f src) { + x = src.getX(); + y = src.getY(); + z = src.getZ(); + return this; + } + + /** + * @return the length squared of the vector + */ + public float lengthSquared() { + return x * x + y * y + z * z; + } + + /** + * Translate a vector + * + * @param x The translation in x + * @param y the translation in y + * @return this + */ + public Vector3f translate(float x, float y, float z) { + this.x += x; + this.y += y; + this.z += z; + return this; + } + + /** + * Add a vector to another vector and place the result in a destination vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return the sum of left and right in dest + */ + public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) { + if (dest == null) + return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z); + else { + dest.set(left.x + right.x, left.y + right.y, left.z + right.z); + return dest; + } + } + + /** + * Subtract a vector from another vector and place the result in a destination + * vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return left minus right in dest + */ + public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) { + if (dest == null) + return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z); + else { + dest.set(left.x - right.x, left.y - right.y, left.z - right.z); + return dest; + } + } + + /** + * The cross product of two vectors. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination result, or null if a new vector is to be created + * @return left cross right + */ + public static Vector3f cross(Vector3f left, Vector3f right, Vector3f dest) { + + if (dest == null) + dest = new Vector3f(); + + dest.set(left.y * right.z - left.z * right.y, right.x * left.z - right.z * left.x, + left.x * right.y - left.y * right.x); + + return dest; + } + + /** + * Negate a vector + * + * @return this + */ + public Vector negate() { + x = -x; + y = -y; + z = -z; + return this; + } + + /** + * Negate a vector and place the result in a destination vector. + * + * @param dest The destination vector or null if a new vector is to be created + * @return the negated vector + */ + public Vector3f negate(Vector3f dest) { + if (dest == null) + dest = new Vector3f(); + dest.x = -x; + dest.y = -y; + dest.z = -z; + return dest; + } + + /** + * Normalise this vector and place the result in another vector. + * + * @param dest The destination vector, or null if a new vector is to be created + * @return the normalised vector + */ + public Vector3f normalise(Vector3f dest) { + float l = length(); + + if (dest == null) + dest = new Vector3f(x / l, y / l, z / l); + else + dest.set(x / l, y / l, z / l); + + return dest; + } + + /** + * The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y + + * v1.z * v2.z + * + * @param left The LHS vector + * @param right The RHS vector + * @return left dot right + */ + public static float dot(Vector3f left, Vector3f right) { + return left.x * right.x + left.y * right.y + left.z * right.z; + } + + /** + * Calculate the angle between two vectors, in radians + * + * @param a A vector + * @param b The other vector + * @return the angle between the two vectors, in radians + */ + public static float angle(Vector3f a, Vector3f b) { + float dls = dot(a, b) / (a.length() * b.length()); + if (dls < -1f) + dls = -1f; + else if (dls > 1.0f) + dls = 1.0f; + return (float) Math.acos(dls); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#load(FloatBuffer) + */ + public Vector load(FloatBuffer buf) { + x = buf.get(); + y = buf.get(); + z = buf.get(); + return this; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#scale(float) + */ + public Vector scale(float scale) { + + x *= scale; + y *= scale; + z *= scale; + + return this; + + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#store(FloatBuffer) + */ + public Vector store(FloatBuffer buf) { + + buf.put(x); + buf.put(y); + buf.put(z); + + return this; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuilder sb = new StringBuilder(64); + + sb.append("Vector3f["); + sb.append(x); + sb.append(", "); + sb.append(y); + sb.append(", "); + sb.append(z); + sb.append(']'); + return sb.toString(); + } + + /** + * @return x + */ + public final float getX() { + return x; + } + + /** + * @return y + */ + public final float getY() { + return y; + } + + /** + * Set X + * + * @param x + */ + public final void setX(float x) { + this.x = x; + } + + /** + * Set Y + * + * @param y + */ + public final void setY(float y) { + this.y = y; + } + + /** + * Set Z + * + * @param z + */ + public void setZ(float z) { + this.z = z; + } + + /* + * (Overrides) + * + * @see org.lwjgl.vector.ReadableVector3f#getZ() + */ + public float getZ() { + return z; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Vector3f other = (Vector3f) obj; + + if (x == other.x && y == other.y && z == other.z) + return true; + + return false; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/Vector4f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector4f.java new file mode 100644 index 0000000..7582396 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/Vector4f.java @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +import java.io.Serializable; +import java.nio.FloatBuffer; + +/** + * + * Holds a 4-tuple vector. + * + * @author cix_foo + * @version $Revision$ $Id$ + */ + +public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f { + + private static final long serialVersionUID = 1L; + + public float x, y, z, w; + + /** + * Constructor for Vector4f. + */ + public Vector4f() { + super(); + } + + /** + * Constructor + */ + public Vector4f(ReadableVector4f src) { + set(src); + } + + /** + * Constructor + */ + public Vector4f(float x, float y, float z, float w) { + set(x, y, z, w); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector2f#set(float, float) + */ + public void set(float x, float y) { + this.x = x; + this.y = y; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float) + */ + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float) + */ + public void set(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + /** + * Load from another Vector4f + * + * @param src The source vector + * @return this + */ + public Vector4f set(ReadableVector4f src) { + x = src.getX(); + y = src.getY(); + z = src.getZ(); + w = src.getW(); + return this; + } + + /** + * @return the length squared of the vector + */ + public float lengthSquared() { + return x * x + y * y + z * z + w * w; + } + + /** + * Translate a vector + * + * @param x The translation in x + * @param y the translation in y + * @return this + */ + public Vector4f translate(float x, float y, float z, float w) { + this.x += x; + this.y += y; + this.z += z; + this.w += w; + return this; + } + + /** + * Add a vector to another vector and place the result in a destination vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return the sum of left and right in dest + */ + public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) { + if (dest == null) + return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); + else { + dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); + return dest; + } + } + + /** + * Subtract a vector from another vector and place the result in a destination + * vector. + * + * @param left The LHS vector + * @param right The RHS vector + * @param dest The destination vector, or null if a new vector is to be created + * @return left minus right in dest + */ + public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) { + if (dest == null) + return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); + else { + dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); + return dest; + } + } + + /** + * Negate a vector + * + * @return this + */ + public Vector negate() { + x = -x; + y = -y; + z = -z; + w = -w; + return this; + } + + /** + * Negate a vector and place the result in a destination vector. + * + * @param dest The destination vector or null if a new vector is to be created + * @return the negated vector + */ + public Vector4f negate(Vector4f dest) { + if (dest == null) + dest = new Vector4f(); + dest.x = -x; + dest.y = -y; + dest.z = -z; + dest.w = -w; + return dest; + } + + /** + * Normalise this vector and place the result in another vector. + * + * @param dest The destination vector, or null if a new vector is to be created + * @return the normalised vector + */ + public Vector4f normalise(Vector4f dest) { + float l = length(); + + if (dest == null) + dest = new Vector4f(x / l, y / l, z / l, w / l); + else + dest.set(x / l, y / l, z / l, w / l); + + return dest; + } + + /** + * The dot product of two vectors is calculated as v1.x * v2.x + v1.y * v2.y + + * v1.z * v2.z + v1.w * v2.w + * + * @param left The LHS vector + * @param right The RHS vector + * @return left dot right + */ + public static float dot(Vector4f left, Vector4f right) { + return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; + } + + /** + * Calculate the angle between two vectors, in radians + * + * @param a A vector + * @param b The other vector + * @return the angle between the two vectors, in radians + */ + public static float angle(Vector4f a, Vector4f b) { + float dls = dot(a, b) / (a.length() * b.length()); + if (dls < -1f) + dls = -1f; + else if (dls > 1.0f) + dls = 1.0f; + return (float) Math.acos(dls); + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#load(FloatBuffer) + */ + public Vector load(FloatBuffer buf) { + x = buf.get(); + y = buf.get(); + z = buf.get(); + w = buf.get(); + return this; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#scale(float) + */ + public Vector scale(float scale) { + x *= scale; + y *= scale; + z *= scale; + w *= scale; + return this; + } + + /* + * (non-Javadoc) + * + * @see org.lwjgl.vector.Vector#store(FloatBuffer) + */ + public Vector store(FloatBuffer buf) { + + buf.put(x); + buf.put(y); + buf.put(z); + buf.put(w); + + return this; + } + + public String toString() { + return "Vector4f: " + x + " " + y + " " + z + " " + w; + } + + /** + * @return x + */ + public final float getX() { + return x; + } + + /** + * @return y + */ + public final float getY() { + return y; + } + + /** + * Set X + * + * @param x + */ + public final void setX(float x) { + this.x = x; + } + + /** + * Set Y + * + * @param y + */ + public final void setY(float y) { + this.y = y; + } + + /** + * Set Z + * + * @param z + */ + public void setZ(float z) { + this.z = z; + } + + /* + * (Overrides) + * + * @see org.lwjgl.vector.ReadableVector3f#getZ() + */ + public float getZ() { + return z; + } + + /** + * Set W + * + * @param w + */ + public void setW(float w) { + this.w = w; + } + + /* + * (Overrides) + * + * @see org.lwjgl.vector.ReadableVector3f#getZ() + */ + public float getW() { + return w; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Vector4f other = (Vector4f) obj; + + if (x == other.x && y == other.y && z == other.z && w == other.w) + return true; + + return false; + } +} diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector2f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector2f.java new file mode 100644 index 0000000..faa6c71 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector2f.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * Writable interface to Vector2fs + * + * @author $author$ + * @version $revision$ $Id$ + */ +public interface WritableVector2f { + + /** + * Set the X value + * + * @param x + */ + void setX(float x); + + /** + * Set the Y value + * + * @param y + */ + void setY(float y); + + /** + * Set the X,Y values + * + * @param x + * @param y + */ + void set(float x, float y); + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector3f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector3f.java new file mode 100644 index 0000000..6c6e004 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector3f.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * Writable interface to Vector3fs + * + * @author $author$ + * @version $revision$ $Id$ + */ +public interface WritableVector3f extends WritableVector2f { + + /** + * Set the Z value + * + * @param z + */ + void setZ(float z); + + /** + * Set the X,Y,Z values + * + * @param x + * @param y + * @param z + */ + void set(float x, float y, float z); + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector4f.java b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector4f.java new file mode 100644 index 0000000..9870654 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/glemu/vector/WritableVector4f.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2008 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.PeytonPlayz585.glemu.vector; + +/** + * Writable interface to Vector4fs + * + * @author $author$ + * @version $revision$ $Id$ + */ +public interface WritableVector4f extends WritableVector3f { + + /** + * Set the W value + * + * @param w + */ + void setW(float w); + + /** + * Set the X,Y,Z,W values + * + * @param x + * @param y + * @param z + * @param w + */ + void set(float x, float y, float z, float w); + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/lwjgl/LWJGL.java b/src/main/java/net/PeytonPlayz585/lwjgl/LWJGL.java new file mode 100644 index 0000000..bed46a6 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/lwjgl/LWJGL.java @@ -0,0 +1,586 @@ +package net.PeytonPlayz585.lwjgl; + +import static net.PeytonPlayz585.teavm.WebGL2RenderingContext.*; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.charset.Charset; + +import org.teavm.jso.JSBody; +import org.teavm.jso.JSObject; +import org.teavm.jso.typedarrays.ArrayBuffer; +import org.teavm.jso.typedarrays.Float32Array; +import org.teavm.jso.typedarrays.Int32Array; +import org.teavm.jso.typedarrays.Uint8Array; +import org.teavm.jso.webgl.WebGLBuffer; +import org.teavm.jso.webgl.WebGLFramebuffer; +import org.teavm.jso.webgl.WebGLProgram; +import org.teavm.jso.webgl.WebGLRenderbuffer; +import org.teavm.jso.webgl.WebGLShader; +import org.teavm.jso.webgl.WebGLTexture; +import org.teavm.jso.webgl.WebGLUniformLocation; + +import net.PeytonPlayz585.main.MinecraftMain; +import net.PeytonPlayz585.minecraft.GlStateManager; +import net.PeytonPlayz585.minecraft.MinecraftClient; +import net.PeytonPlayz585.teavm.WebGL2RenderingContext; +import net.PeytonPlayz585.teavm.WebGLQuery; +import net.PeytonPlayz585.teavm.WebGLVertexArray; + +public class LWJGL { +static WebGL2RenderingContext webgl = null; + + public static final void initWebGL(WebGL2RenderingContext wgl2rc) { + webgl = wgl2rc; + } + + public static final String _wgetShaderHeader() { + return "#version 300 es"; + } + + public static final class TextureGL { + protected final WebGLTexture obj; + public int w = -1; + public int h = -1; + public boolean nearest = true; + public boolean anisotropic = false; + protected TextureGL(WebGLTexture obj) { + this.obj = obj; + } + } + public static final class BufferGL { + protected final WebGLBuffer obj; + protected BufferGL(WebGLBuffer obj) { + this.obj = obj; + } + } + public static final class ShaderGL { + protected final WebGLShader obj; + protected ShaderGL(WebGLShader obj) { + this.obj = obj; + } + } + private static int progId = 0; + public static final class ProgramGL { + protected final WebGLProgram obj; + protected final int hashcode; + protected ProgramGL(WebGLProgram obj) { + this.obj = obj; + this.hashcode = ++progId; + } + } + public static final class UniformGL { + protected final WebGLUniformLocation obj; + protected UniformGL(WebGLUniformLocation obj) { + this.obj = obj; + } + } + public static final class BufferArrayGL { + protected final WebGLVertexArray obj; + public boolean isQuadBufferBound; + protected BufferArrayGL(WebGLVertexArray obj) { + this.obj = obj; + this.isQuadBufferBound = false; + } + } + public static final class FramebufferGL { + protected final WebGLFramebuffer obj; + protected FramebufferGL(WebGLFramebuffer obj) { + this.obj = obj; + } + } + public static final class RenderbufferGL { + protected final WebGLRenderbuffer obj; + protected RenderbufferGL(WebGLRenderbuffer obj) { + this.obj = obj; + } + } + public static final class QueryGL { + protected final WebGLQuery obj; + protected QueryGL(WebGLQuery obj) { + this.obj = obj; + } + } + + public static final void _wglEnable(int p1) { + webgl.enable(p1); + } + public static final void _wglClearDepth(float p1) { + webgl.clearDepth(p1); + } + public static final void _wglDepthFunc(int p1) { + webgl.depthFunc(p1); + } + public static final void _wglCullFace(int p1) { + webgl.cullFace(p1); + } + private static int[] viewportCache = new int[4]; + public static final void _wglViewport(int p1, int p2, int p3, int p4) { + viewportCache[0] = p1; viewportCache[1] = p2; + viewportCache[2] = p3; viewportCache[3] = p4; + webgl.viewport(p1, p2, p3, p4); + } + public static final void _wglClear(int p1) { + webgl.clear(p1); + } + public static final void _wglClearColor(float p1, float p2, float p3, float p4) { + webgl.clearColor(p1, p2, p3, p4); + } + public static final void _wglDisable(int p1) { + webgl.disable(p1); + } + public static final int _wglGetError() { + return webgl.getError(); + } + public static final void _wglFlush() { + //webgl.flush(); + } + private static Uint8Array uploadBuffer = Uint8Array.create(ArrayBuffer.create(4 * 1024 * 1024)); + public static final void _wglTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) { + if(p9 == null) { + webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, null); + }else { + int len = p9.remaining(); + Uint8Array uploadBuffer1 = uploadBuffer; + for(int i = 0; i < len; ++i) { + uploadBuffer1.set(i, (short) ((int)p9.get() & 0xff)); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len); + webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data); + } + } + public static final void _wglBlendFunc(int p1, int p2) { + webgl.blendFunc(p1, p2); + } + public static final void _wglDepthMask(boolean p1) { + webgl.depthMask(p1); + } + public static final void _wglColorMask(boolean p1, boolean p2, boolean p3, boolean p4) { + webgl.colorMask(p1, p2, p3, p4); + } + public static final void _wglBindTexture(int p1, TextureGL p2) { + webgl.bindTexture(p1, p2 == null ? null : p2.obj); + } + public static final void _wglCopyTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { + webgl.copyTexSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8); + } + public static final void _wglTexParameteri(int p1, int p2, int p3) { + webgl.texParameteri(p1, p2, p3); + } + public static final void _wglTexParameterf(int p1, int p2, float p3) { + webgl.texParameterf(p1, p2, p3); + } + public static final void _wglTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, IntBuffer p9) { + int len = p9.remaining(); + Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer()); + for(int i = 0; i < len; ++i) { + deevis.set(i, p9.get()); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4); + webgl.texImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data); + } + public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, IntBuffer p9) { + int len = p9.remaining(); + Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer()); + for(int i = 0; i < len; ++i) { + deevis.set(i, p9.get()); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4); + webgl.texSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data); + } + public static final void _wglDeleteTextures(TextureGL p1) { + webgl.deleteTexture(p1.obj); + } + public static final void _wglDrawArrays(int p1, int p2, int p3) { + webgl.drawArrays(p1, p2, p3); + } + public static final void _wglDrawElements(int p1, int p2, int p3, int p4) { + webgl.drawElements(p1, p2, p3, p4); + } + public static final TextureGL _wglGenTextures() { + return new TextureGL(webgl.createTexture()); + } + public static final void _wglTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, ByteBuffer p9) { + int len = p9.remaining(); + for(int i = 0; i < len; ++i) { + uploadBuffer.set(i, (short) ((int)p9.get() & 0xff)); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len); + webgl.texSubImage2D(p1, p2, p3, p4, p5, p6, p7, p8, data); + } + public static final void _wglActiveTexture(int p1) { + webgl.activeTexture(p1); + } + public static final ProgramGL _wglCreateProgram() { + return new ProgramGL(webgl.createProgram()); + } + public static final ShaderGL _wglCreateShader(int p1) { + return new ShaderGL(webgl.createShader(p1)); + } + public static final void _wglAttachShader(ProgramGL p1, ShaderGL p2) { + webgl.attachShader(p1.obj, p2.obj); + } + public static final void _wglDetachShader(ProgramGL p1, ShaderGL p2) { + webgl.detachShader(p1.obj, p2.obj); + } + public static final void _wglCompileShader(ShaderGL p1) { + webgl.compileShader(p1.obj); + } + public static final void _wglLinkProgram(ProgramGL p1) { + webgl.linkProgram(p1.obj); + } + public static final void _wglShaderSource(ShaderGL p1, String p2) { + webgl.shaderSource(p1.obj, p2); + } + public static final String _wglGetShaderInfoLog(ShaderGL p1) { + return webgl.getShaderInfoLog(p1.obj); + } + public static final String _wglGetProgramInfoLog(ProgramGL p1) { + return webgl.getProgramInfoLog(p1.obj); + } + public static final boolean _wglGetShaderCompiled(ShaderGL p1) { + return webgl.getShaderParameteri(p1.obj, COMPILE_STATUS) == 1; + } + public static final boolean _wglGetProgramLinked(ProgramGL p1) { + return webgl.getProgramParameteri(p1.obj, LINK_STATUS) == 1; + } + public static final void _wglDeleteShader(ShaderGL p1) { + webgl.deleteShader(p1.obj); + } + public static final void _wglDeleteProgram(ProgramGL p1) { + webgl.deleteProgram(p1.obj); + } + public static final BufferGL _wglCreateBuffer() { + return new BufferGL(webgl.createBuffer()); + } + public static final void _wglDeleteBuffer(BufferGL p1) { + webgl.deleteBuffer(p1.obj); + } + public static final void _wglBindBuffer(int p1, BufferGL p2) { + webgl.bindBuffer(p1, p2 == null ? null : p2.obj); + } + public static final void _wglBufferData0(int p1, IntBuffer p2, int p3) { + int len = p2.remaining(); + Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer()); + for(int i = 0; i < len; ++i) { + deevis.set(i, p2.get()); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4); + webgl.bufferData(p1, data, p3); + } + public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) { + int len = p3.remaining(); + Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer()); + for(int i = 0; i < len; ++i) { + deevis.set(i, p3.get()); + } + Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4); + webgl.bufferSubData(p1, p2, data); + } + public static final void _wglBufferData(int p1, Object p2, int p3) { + webgl.bufferData(p1, (Int32Array)p2, p3); + } + public static final void _wglBufferSubData(int p1, int p2, Object p3) { + webgl.bufferSubData(p1, p2, (Int32Array)p3); + } + public static final void _wglBindAttribLocation(ProgramGL p1, int p2, String p3) { + webgl.bindAttribLocation(p1.obj, p2, p3); + } + public static final void _wglEnableVertexAttribArray(int p1) { + webgl.enableVertexAttribArray(p1); + } + public static final void _wglDisableVertexAttribArray(int p1) { + webgl.disableVertexAttribArray(p1); + } + public static final UniformGL _wglGetUniformLocation(ProgramGL p1, String p2) { + WebGLUniformLocation u = webgl.getUniformLocation(p1.obj, p2); + return u == null ? null : new UniformGL(u); + } + public static final void _wglBindAttributeLocation(ProgramGL p1, int p2, String p3) { + webgl.bindAttribLocation(p1.obj, p2, p3); + } + public static final void _wglUniform1f(UniformGL p1, float p2) { + if(p1 != null) webgl.uniform1f(p1.obj, p2); + } + public static final void _wglUniform2f(UniformGL p1, float p2, float p3) { + if(p1 != null) webgl.uniform2f(p1.obj, p2, p3); + } + public static final void _wglUniform3f(UniformGL p1, float p2, float p3, float p4) { + if(p1 != null) webgl.uniform3f(p1.obj, p2, p3, p4); + } + public static final void _wglUniform4f(UniformGL p1, float p2, float p3, float p4, float p5) { + if(p1 != null) webgl.uniform4f(p1.obj, p2, p3, p4, p5); + } + public static final void _wglUniform1i(UniformGL p1, int p2) { + if(p1 != null) webgl.uniform1i(p1.obj, p2); + } + public static final void _wglUniform2i(UniformGL p1, int p2, int p3) { + if(p1 != null) webgl.uniform2i(p1.obj, p2, p3); + } + public static final void _wglUniform3i(UniformGL p1, int p2, int p3, int p4) { + if(p1 != null) webgl.uniform3i(p1.obj, p2, p3, p4); + } + public static final void _wglUniform4i(UniformGL p1, int p2, int p3, int p4, int p5) { + if(p1 != null) webgl.uniform4i(p1.obj, p2, p3, p4, p5); + } + private static Float32Array mat2 = Float32Array.create(4); + private static Float32Array mat3 = Float32Array.create(9); + private static Float32Array mat4 = Float32Array.create(16); + public static final void _wglUniformMat2fv(UniformGL p1, float[] mat) { + mat2.set(mat); + if(p1 != null) webgl.uniformMatrix2fv(p1.obj, false, mat2); + } + public static final void _wglUniformMat3fv(UniformGL p1, float[] mat) { + mat3.set(mat); + if(p1 != null) webgl.uniformMatrix3fv(p1.obj, false, mat3); + } + public static final void _wglUniformMat4fv(UniformGL p1, float[] mat) { + mat4.set(mat); + if(p1 != null) webgl.uniformMatrix4fv(p1.obj, false, mat4); + } + private static int currentProgram = -1; + public static final void _wglUseProgram(ProgramGL p1) { + if(p1 != null && currentProgram != p1.hashcode) { + currentProgram = p1.hashcode; + webgl.useProgram(p1.obj); + } + } + public static final void _wglGetParameter(int p1, int size, int[] ret) { + if(p1 == _wGL_VIEWPORT) { + ret[0] = viewportCache[0]; + ret[1] = viewportCache[1]; + ret[2] = viewportCache[2]; + ret[3] = viewportCache[3]; + } + } + public static final void _wglPolygonOffset(float p1, float p2) { + webgl.polygonOffset(p1, p2); + } + public static final void _wglVertexAttribPointer(int p1, int p2, int p3, boolean p4, int p5, int p6) { + webgl.vertexAttribPointer(p1, p2, p3, p4, p5, p6); + } + public static final void _wglBindFramebuffer(int p1, FramebufferGL p2) { + webgl.bindFramebuffer(p1, p2 == null ? null : p2.obj); + } + public static final FramebufferGL _wglCreateFramebuffer() { + return new FramebufferGL(webgl.createFramebuffer()); + } + public static final void _wglDeleteFramebuffer(FramebufferGL p1) { + webgl.deleteFramebuffer(p1.obj); + } + public static final void _wglFramebufferTexture2D(int p1, TextureGL p2) { + webgl.framebufferTexture2D(FRAMEBUFFER, p1, TEXTURE_2D, p2 == null ? null : p2.obj, 0); + } + public static final QueryGL _wglCreateQuery() { + return new QueryGL(webgl.createQuery()); + } + public static final void _wglBeginQuery(int p1, QueryGL p2) { + webgl.beginQuery(p1, p2.obj); + } + public static final void _wglEndQuery(int p1) { + webgl.endQuery(p1); + } + public static final void _wglDeleteQuery(QueryGL p1) { + webgl.deleteQuery(p1.obj); + } + public static final int _wglGetQueryObjecti(QueryGL p1, int p2) { + return webgl.getQueryParameter(p1.obj, p2); + } + public static final BufferArrayGL _wglCreateVertexArray() { + return new BufferArrayGL(webgl.createVertexArray()); + } + public static final void _wglDeleteVertexArray(BufferArrayGL p1) { + webgl.deleteVertexArray(p1.obj); + } + public static final void _wglBindVertexArray(BufferArrayGL p1) { + webgl.bindVertexArray(p1 == null ? null : p1.obj); + } + public static final void _wglDrawBuffer(int p1) { + webgl.drawBuffers(new int[] { p1 }); + } + public static final RenderbufferGL _wglCreateRenderBuffer() { + return new RenderbufferGL(webgl.createRenderbuffer()); + } + public static final void _wglBindRenderbuffer(RenderbufferGL p1) { + webgl.bindRenderbuffer(RENDERBUFFER, p1 == null ? null : p1.obj); + } + public static final void _wglRenderbufferStorage(int p1, int p2, int p3) { + webgl.renderbufferStorage(RENDERBUFFER, p1, p2, p3); + } + public static final void _wglFramebufferRenderbuffer(int p1, RenderbufferGL p2) { + webgl.framebufferRenderbuffer(FRAMEBUFFER, p1, RENDERBUFFER, p2 == null ? null : p2.obj); + } + public static final void _wglDeleteRenderbuffer(RenderbufferGL p1) { + webgl.deleteRenderbuffer(p1.obj); + } + public static final void _wglRenderbufferStorageMultisample(int p1, int p2, int p3, int p4) { + webgl.renderbufferStorageMultisample(RENDERBUFFER, p1, p2, p3, p4); + } + public static final void _wglBlitFramebuffer(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) { + webgl.blitFramebuffer(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); + } + public static final int _wglGetAttribLocation(ProgramGL p1, String p2) { + return webgl.getAttribLocation(p1.obj, p2); + } + + @JSBody(params = { "ctx", "p" }, script = "return ctx.getTexParameter(0x0DE1, p) | 0;") + private static final native int __wglGetTexParameteri(WebGL2RenderingContext ctx, int p); + public static final int _wglGetTexParameteri(int p1) { + return __wglGetTexParameteri(webgl, p1); + } + @JSBody(params = { "ctx", "p" }, script = "return (0.0 + ctx.getTexParameter(0x0DE1, p));") + private static final native float __wglGetTexParameterf(WebGL2RenderingContext ctx, int p); + public static final float _wglGetTexParameterf(int p1) { + return __wglGetTexParameterf(webgl, p1); + } + + public static final int _wArrayByteLength(Object obj) { + return ((Int32Array)obj).getByteLength(); + } + + public static final Object _wCreateLowLevelIntBuffer(int len) { + return Int32Array.create(len); + } + + private static int appendbufferindex = 0; + private static Int32Array appendbuffer = Int32Array.create(ArrayBuffer.create(525000*4)); + + public static final void _wAppendLowLevelBuffer(Object arr) { + Int32Array a = ((Int32Array)arr); + if(appendbufferindex + a.getLength() < appendbuffer.getLength()) { + appendbuffer.set(a, appendbufferindex); + appendbufferindex += a.getLength(); + } + } + + public static final Object _wGetLowLevelBuffersAppended() { + Int32Array ret = Int32Array.create(appendbuffer.getBuffer(), 0, appendbufferindex); + appendbufferindex = 0; + return ret; + } + + @JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();") + private static native int commitContext(JSObject obj); + + public static final void updateDisplay() { + commitContext(webgl); + MinecraftMain.canvasContext.drawImage(MinecraftMain.canvasBack, 0d, 0d, MinecraftMain.canvas.getWidth(), MinecraftMain.canvas.getHeight()); + + int ww = MinecraftMain.canvas.getClientWidth(); + int hh = MinecraftMain.canvas.getClientHeight(); + if(ww != MinecraftMain.width || hh != MinecraftMain.height) { + MinecraftMain.width = ww; + MinecraftMain.height = hh; + MinecraftMain.canvasBack.setWidth(ww); + MinecraftMain.canvasBack.setHeight(hh); + } + + try { + Thread.sleep(1l); + } catch (InterruptedException e) { + ; + } + } + + public static final byte[] loadResourceBytes(String path) { + return MinecraftClient.getResource(path); + } + + public static final String fileContents(String path) { + byte[] contents = loadResourceBytes(path); + if(contents == null) { + return null; + }else { + return new String(contents, Charset.forName("UTF-8")); + } + } + + public static final int _wGL_TEXTURE_2D = TEXTURE_2D; + public static final int _wGL_DEPTH_TEST = DEPTH_TEST; + public static final int _wGL_LEQUAL = LEQUAL; + public static final int _wGL_GEQUAL = GEQUAL; + public static final int _wGL_GREATER = GREATER; + public static final int _wGL_LESS = LESS; + public static final int _wGL_BACK = BACK; + public static final int _wGL_FRONT = FRONT; + public static final int _wGL_FRONT_AND_BACK = FRONT_AND_BACK; + public static final int _wGL_COLOR_BUFFER_BIT = COLOR_BUFFER_BIT; + public static final int _wGL_DEPTH_BUFFER_BIT = DEPTH_BUFFER_BIT; + public static final int _wGL_BLEND = BLEND; + public static final int _wGL_RGBA = RGBA; + public static final int _wGL_RGB = RGB; + public static final int _wGL_RGB8 = RGB8; + public static final int _wGL_RGBA8 = RGBA8; + public static final int _wGL_UNSIGNED_BYTE = UNSIGNED_BYTE; + public static final int _wGL_UNSIGNED_SHORT = UNSIGNED_SHORT; + public static final int _wGL_SRC_ALPHA = SRC_ALPHA; + public static final int _wGL_ONE_MINUS_SRC_ALPHA = ONE_MINUS_SRC_ALPHA; + public static final int _wGL_ONE_MINUS_DST_COLOR = ONE_MINUS_DST_COLOR; + public static final int _wGL_ONE_MINUS_SRC_COLOR = ONE_MINUS_SRC_COLOR; + public static final int _wGL_ZERO = ZERO; + public static final int _wGL_CULL_FACE = CULL_FACE; + public static final int _wGL_TEXTURE_MIN_FILTER = TEXTURE_MIN_FILTER; + public static final int _wGL_TEXTURE_MAG_FILTER = TEXTURE_MAG_FILTER; + public static final int _wGL_LINEAR = LINEAR; + public static final int _wGL_EQUAL = EQUAL; + public static final int _wGL_SRC_COLOR = SRC_COLOR; + public static final int _wGL_ONE = ONE; + public static final int _wGL_NEAREST = NEAREST; + public static final int _wGL_CLAMP = CLAMP_TO_EDGE; + public static final int _wGL_TEXTURE_WRAP_S = TEXTURE_WRAP_S; + public static final int _wGL_TEXTURE_WRAP_T = TEXTURE_WRAP_T; + public static final int _wGL_REPEAT = REPEAT; + public static final int _wGL_DST_COLOR = DST_COLOR; + public static final int _wGL_DST_ALPHA = DST_ALPHA; + public static final int _wGL_FLOAT = FLOAT; + public static final int _wGL_SHORT = SHORT; + public static final int _wGL_TRIANGLES = TRIANGLES; + public static final int _wGL_TRIANGLE_STRIP = TRIANGLE_STRIP; + public static final int _wGL_TRIANGLE_FAN = TRIANGLE_FAN; + public static final int _wGL_LINE_STRIP = LINE_STRIP; + public static final int _wGL_LINES = LINES; + public static final int _wGL_PACK_ALIGNMENT = PACK_ALIGNMENT; + public static final int _wGL_UNPACK_ALIGNMENT = UNPACK_ALIGNMENT; + public static final int _wGL_TEXTURE0 = TEXTURE0; + public static final int _wGL_TEXTURE1 = TEXTURE1; + public static final int _wGL_TEXTURE2 = TEXTURE2; + public static final int _wGL_TEXTURE3 = TEXTURE3; + public static final int _wGL_VIEWPORT = VIEWPORT; + public static final int _wGL_VERTEX_SHADER = VERTEX_SHADER; + public static final int _wGL_FRAGMENT_SHADER = FRAGMENT_SHADER; + public static final int _wGL_ARRAY_BUFFER = ARRAY_BUFFER; + public static final int _wGL_ELEMENT_ARRAY_BUFFER = ELEMENT_ARRAY_BUFFER; + public static final int _wGL_STATIC_DRAW = STATIC_DRAW; + public static final int _wGL_DYNAMIC_DRAW = DYNAMIC_DRAW; + public static final int _wGL_INVALID_ENUM = INVALID_ENUM; + public static final int _wGL_INVALID_VALUE= INVALID_VALUE; + public static final int _wGL_INVALID_OPERATION = INVALID_OPERATION; + public static final int _wGL_OUT_OF_MEMORY = OUT_OF_MEMORY; + public static final int _wGL_CONTEXT_LOST_WEBGL = CONTEXT_LOST_WEBGL; + public static final int _wGL_FRAMEBUFFER_COMPLETE = FRAMEBUFFER_COMPLETE; + public static final int _wGL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + public static final int _wGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; + public static final int _wGL_COLOR_ATTACHMENT0 = COLOR_ATTACHMENT0; + public static final int _wGL_DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL_ATTACHMENT; + public static final int _wGL_DEPTH_STENCIL = DEPTH_STENCIL; + public static final int _wGL_NEAREST_MIPMAP_LINEAR = NEAREST_MIPMAP_LINEAR; + public static final int _wGL_LINEAR_MIPMAP_LINEAR = LINEAR_MIPMAP_LINEAR; + public static final int _wGL_LINEAR_MIPMAP_NEAREST = LINEAR_MIPMAP_NEAREST; + public static final int _wGL_NEAREST_MIPMAP_NEAREST = NEAREST_MIPMAP_NEAREST; + public static final int _wGL_TEXTURE_MAX_LEVEL = TEXTURE_MAX_LEVEL; + public static final int _wGL_UNSIGNED_INT_24_8 = UNSIGNED_INT_24_8; + public static final int _wGL_UNSIGNED_INT = UNSIGNED_INT; + public static final int _wGL_ANY_SAMPLES_PASSED = ANY_SAMPLES_PASSED; + public static final int _wGL_QUERY_RESULT = QUERY_RESULT; + public static final int _wGL_QUERY_RESULT_AVAILABLE = QUERY_RESULT_AVAILABLE; + public static final int _wGL_TEXTURE_MAX_ANISOTROPY = TEXTURE_MAX_ANISOTROPY_EXT; + public static final int _wGL_DEPTH24_STENCIL8 = DEPTH24_STENCIL8; + public static final int _wGL_DEPTH_COMPONENT32F = DEPTH_COMPONENT32F; + public static final int _wGL_DEPTH_ATTACHMENT = DEPTH_ATTACHMENT; + public static final int _wGL_MULTISAMPLE = -1; + public static final int _wGL_LINE_SMOOTH = -1; + public static final int _wGL_READ_FRAMEBUFFER = READ_FRAMEBUFFER; + public static final int _wGL_DRAW_FRAMEBUFFER = DRAW_FRAMEBUFFER; + public static final int _wGL_FRAMEBUFFER = FRAMEBUFFER; + public static final int _wGL_POLYGON_OFFSET_FILL = POLYGON_OFFSET_FILL; +} diff --git a/src/main/java/net/PeytonPlayz585/lwjgl/LWJGLUtils.java b/src/main/java/net/PeytonPlayz585/lwjgl/LWJGLUtils.java new file mode 100644 index 0000000..11e8ba0 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/lwjgl/LWJGLUtils.java @@ -0,0 +1,82 @@ +package net.PeytonPlayz585.lwjgl; + +import org.lwjgl.opengl.GL11; +import org.teavm.interop.Async; +import org.teavm.interop.AsyncCallback; +import org.teavm.jso.canvas.CanvasRenderingContext2D; +import org.teavm.jso.canvas.ImageData; +import org.teavm.jso.dom.events.Event; +import org.teavm.jso.dom.events.EventListener; +import org.teavm.jso.dom.html.HTMLCanvasElement; +import org.teavm.jso.dom.html.HTMLImageElement; +import org.teavm.jso.typedarrays.ArrayBuffer; +import org.teavm.jso.typedarrays.Uint8Array; +import org.teavm.jso.typedarrays.Uint8ClampedArray; + +import net.PeytonPlayz585.main.MinecraftMain; +import net.PeytonPlayz585.minecraft.MinecraftImage; + +public class LWJGLUtils extends GL11 { + + public LWJGLUtils() { + + } + + public static final MinecraftImage loadPNG(byte[] data) { + ArrayBuffer arr = ArrayBuffer.create(data.length); + Uint8Array.create(arr).set(data); + return loadPNG0(arr); + } + + @Async + private static native MinecraftImage loadPNG0(ArrayBuffer data); + + private static void loadPNG0(ArrayBuffer data, final AsyncCallback ret) { + final HTMLImageElement toLoad = (HTMLImageElement) MinecraftMain.doc.createElement("img"); + toLoad.addEventListener("load", new EventListener() { + @Override + public void handleEvent(Event evt) { + if(MinecraftMain.imageLoadCanvas == null) { + MinecraftMain.imageLoadCanvas = (HTMLCanvasElement) MinecraftMain.doc.createElement("canvas"); + } + if(MinecraftMain.imageLoadCanvas.getWidth() < toLoad.getWidth()) { + MinecraftMain.imageLoadCanvas.setWidth(toLoad.getWidth()); + } + if(MinecraftMain.imageLoadCanvas.getHeight() < toLoad.getHeight()) { + MinecraftMain.imageLoadCanvas.setHeight(toLoad.getHeight()); + } + if(MinecraftMain.imageLoadContext == null) { + MinecraftMain.imageLoadContext = (CanvasRenderingContext2D) MinecraftMain.imageLoadCanvas.getContext("2d"); + } + MinecraftMain.imageLoadContext.clearRect(0, 0, toLoad.getWidth(), toLoad.getHeight()); + MinecraftMain.imageLoadContext.drawImage(toLoad, 0, 0, toLoad.getWidth(), toLoad.getHeight()); + ImageData pxlsDat = MinecraftMain.imageLoadContext.getImageData(0, 0, toLoad.getWidth(), toLoad.getHeight()); + Uint8ClampedArray pxls = pxlsDat.getData(); + int totalPixels = pxlsDat.getWidth() * pxlsDat.getHeight(); + MinecraftMain.freeDataURL(toLoad.getSrc()); + if(pxls.getByteLength() < totalPixels * 4) { + ret.complete(null); + return; + } + int[] pixels = new int[totalPixels]; + for(int i = 0; i < pixels.length; ++i) { + pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24); + } + ret.complete(new MinecraftImage(pixels, pxlsDat.getWidth(), pxlsDat.getHeight(), true)); + } + }); + toLoad.addEventListener("error", new EventListener() { + @Override + public void handleEvent(Event evt) { + MinecraftMain.freeDataURL(toLoad.getSrc()); + ret.complete(null); + } + }); + String src = MinecraftMain.getDataURL(data, "image/png"); + if(src == null) { + ret.complete(null); + }else { + toLoad.setSrc(src); + } + } +} diff --git a/src/main/java/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.java b/src/main/java/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.java new file mode 100644 index 0000000..d90b6b4 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/lwjgl/RealOpenGLEnums.java @@ -0,0 +1,2417 @@ +package net.PeytonPlayz585.lwjgl; + +public class RealOpenGLEnums { + + // Field descriptor #544 I + public static final int GL_ACCUM = 256; + + // Field descriptor #544 I + public static final int GL_LOAD = 257; + + // Field descriptor #544 I + public static final int GL_RETURN = 258; + + // Field descriptor #544 I + public static final int GL_MULT = 259; + + // Field descriptor #544 I + public static final int GL_ADD = 260; + + // Field descriptor #544 I + public static final int GL_NEVER = 512; + + // Field descriptor #544 I + public static final int GL_LESS = 513; + + // Field descriptor #544 I + public static final int GL_EQUAL = 514; + + // Field descriptor #544 I + public static final int GL_LEQUAL = 515; + + // Field descriptor #544 I + public static final int GL_GREATER = 516; + + // Field descriptor #544 I + public static final int GL_NOTEQUAL = 517; + + // Field descriptor #544 I + public static final int GL_GEQUAL = 518; + + // Field descriptor #544 I + public static final int GL_ALWAYS = 519; + + // Field descriptor #544 I + public static final int GL_CURRENT_BIT = 1; + + // Field descriptor #544 I + public static final int GL_POINT_BIT = 2; + + // Field descriptor #544 I + public static final int GL_LINE_BIT = 4; + + // Field descriptor #544 I + public static final int GL_POLYGON_BIT = 8; + + // Field descriptor #544 I + public static final int GL_POLYGON_STIPPLE_BIT = 16; + + // Field descriptor #544 I + public static final int GL_PIXEL_MODE_BIT = 32; + + // Field descriptor #544 I + public static final int GL_LIGHTING_BIT = 64; + + // Field descriptor #544 I + public static final int GL_FOG_BIT = 128; + + // Field descriptor #544 I + public static final int GL_DEPTH_BUFFER_BIT = 256; + + // Field descriptor #544 I + public static final int GL_ACCUM_BUFFER_BIT = 512; + + // Field descriptor #544 I + public static final int GL_STENCIL_BUFFER_BIT = 1024; + + // Field descriptor #544 I + public static final int GL_VIEWPORT_BIT = 2048; + + // Field descriptor #544 I + public static final int GL_TRANSFORM_BIT = 4096; + + // Field descriptor #544 I + public static final int GL_ENABLE_BIT = 8192; + + // Field descriptor #544 I + public static final int GL_COLOR_BUFFER_BIT = 16384; + + // Field descriptor #544 I + public static final int GL_HINT_BIT = 32768; + + // Field descriptor #544 I + public static final int GL_EVAL_BIT = 65536; + + // Field descriptor #544 I + public static final int GL_LIST_BIT = 131072; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BIT = 262144; + + // Field descriptor #544 I + public static final int GL_SCISSOR_BIT = 524288; + + // Field descriptor #544 I + public static final int GL_ALL_ATTRIB_BITS = 1048575; + + // Field descriptor #544 I + public static final int GL_POINTS = 0; + + // Field descriptor #544 I + public static final int GL_LINES = 1; + + // Field descriptor #544 I + public static final int GL_LINE_LOOP = 2; + + // Field descriptor #544 I + public static final int GL_LINE_STRIP = 3; + + // Field descriptor #544 I + public static final int GL_TRIANGLES = 4; + + // Field descriptor #544 I + public static final int GL_TRIANGLE_STRIP = 5; + + // Field descriptor #544 I + public static final int GL_TRIANGLE_FAN = 6; + + // Field descriptor #544 I + public static final int GL_QUADS = 7; + + // Field descriptor #544 I + public static final int GL_QUAD_STRIP = 8; + + // Field descriptor #544 I + public static final int GL_POLYGON = 9; + + // Field descriptor #544 I + public static final int GL_ZERO = 0; + + // Field descriptor #544 I + public static final int GL_ONE = 1; + + // Field descriptor #544 I + public static final int GL_SRC_COLOR = 768; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_SRC_COLOR = 769; + + // Field descriptor #544 I + public static final int GL_SRC_ALPHA = 770; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_SRC_ALPHA = 771; + + // Field descriptor #544 I + public static final int GL_DST_ALPHA = 772; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_DST_ALPHA = 773; + + // Field descriptor #544 I + public static final int GL_DST_COLOR = 774; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_DST_COLOR = 775; + + // Field descriptor #544 I + public static final int GL_SRC_ALPHA_SATURATE = 776; + + // Field descriptor #544 I + public static final int GL_CONSTANT_COLOR = 32769; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_CONSTANT_COLOR = 32770; + + // Field descriptor #544 I + public static final int GL_CONSTANT_ALPHA = 32771; + + // Field descriptor #544 I + public static final int GL_ONE_MINUS_CONSTANT_ALPHA = 32772; + + // Field descriptor #544 I + public static final int GL_TRUE = 1; + + // Field descriptor #544 I + public static final int GL_FALSE = 0; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE0 = 12288; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE1 = 12289; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE2 = 12290; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE3 = 12291; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE4 = 12292; + + // Field descriptor #544 I + public static final int GL_CLIP_PLANE5 = 12293; + + // Field descriptor #544 I + public static final int GL_BYTE = 5120; + + // Field descriptor #544 I + public static final int GL_UNSIGNED_BYTE = 5121; + + // Field descriptor #544 I + public static final int GL_SHORT = 5122; + + // Field descriptor #544 I + public static final int GL_UNSIGNED_SHORT = 5123; + + // Field descriptor #544 I + public static final int GL_INT = 5124; + + // Field descriptor #544 I + public static final int GL_UNSIGNED_INT = 5125; + + // Field descriptor #544 I + public static final int GL_FLOAT = 5126; + + // Field descriptor #544 I + public static final int GL_2_BYTES = 5127; + + // Field descriptor #544 I + public static final int GL_3_BYTES = 5128; + + // Field descriptor #544 I + public static final int GL_4_BYTES = 5129; + + // Field descriptor #544 I + public static final int GL_DOUBLE = 5130; + + // Field descriptor #544 I + public static final int GL_NONE = 0; + + // Field descriptor #544 I + public static final int GL_FRONT_LEFT = 1024; + + // Field descriptor #544 I + public static final int GL_FRONT_RIGHT = 1025; + + // Field descriptor #544 I + public static final int GL_BACK_LEFT = 1026; + + // Field descriptor #544 I + public static final int GL_BACK_RIGHT = 1027; + + // Field descriptor #544 I + public static final int GL_FRONT = 1028; + + // Field descriptor #544 I + public static final int GL_BACK = 1029; + + // Field descriptor #544 I + public static final int GL_LEFT = 1030; + + // Field descriptor #544 I + public static final int GL_RIGHT = 1031; + + // Field descriptor #544 I + public static final int GL_FRONT_AND_BACK = 1032; + + // Field descriptor #544 I + public static final int GL_AUX0 = 1033; + + // Field descriptor #544 I + public static final int GL_AUX1 = 1034; + + // Field descriptor #544 I + public static final int GL_AUX2 = 1035; + + // Field descriptor #544 I + public static final int GL_AUX3 = 1036; + + // Field descriptor #544 I + public static final int GL_NO_ERROR = 0; + + // Field descriptor #544 I + public static final int GL_INVALID_ENUM = 1280; + + // Field descriptor #544 I + public static final int GL_INVALID_VALUE = 1281; + + // Field descriptor #544 I + public static final int GL_INVALID_OPERATION = 1282; + + // Field descriptor #544 I + public static final int GL_STACK_OVERFLOW = 1283; + + // Field descriptor #544 I + public static final int GL_STACK_UNDERFLOW = 1284; + + // Field descriptor #544 I + public static final int GL_OUT_OF_MEMORY = 1285; + + // Field descriptor #544 I + public static final int GL_2D = 1536; + + // Field descriptor #544 I + public static final int GL_3D = 1537; + + // Field descriptor #544 I + public static final int GL_3D_COLOR = 1538; + + // Field descriptor #544 I + public static final int GL_3D_COLOR_TEXTURE = 1539; + + // Field descriptor #544 I + public static final int GL_4D_COLOR_TEXTURE = 1540; + + // Field descriptor #544 I + public static final int GL_PASS_THROUGH_TOKEN = 1792; + + // Field descriptor #544 I + public static final int GL_POINT_TOKEN = 1793; + + // Field descriptor #544 I + public static final int GL_LINE_TOKEN = 1794; + + // Field descriptor #544 I + public static final int GL_POLYGON_TOKEN = 1795; + + // Field descriptor #544 I + public static final int GL_BITMAP_TOKEN = 1796; + + // Field descriptor #544 I + public static final int GL_DRAW_PIXEL_TOKEN = 1797; + + // Field descriptor #544 I + public static final int GL_COPY_PIXEL_TOKEN = 1798; + + // Field descriptor #544 I + public static final int GL_LINE_RESET_TOKEN = 1799; + + // Field descriptor #544 I + public static final int GL_EXP = 2048; + + // Field descriptor #544 I + public static final int GL_EXP2 = 2049; + + // Field descriptor #544 I + public static final int GL_CW = 2304; + + // Field descriptor #544 I + public static final int GL_CCW = 2305; + + // Field descriptor #544 I + public static final int GL_COEFF = 2560; + + // Field descriptor #544 I + public static final int GL_ORDER = 2561; + + // Field descriptor #544 I + public static final int GL_DOMAIN = 2562; + + // Field descriptor #544 I + public static final int GL_CURRENT_COLOR = 2816; + + // Field descriptor #544 I + public static final int GL_CURRENT_INDEX = 2817; + + // Field descriptor #544 I + public static final int GL_CURRENT_NORMAL = 2818; + + // Field descriptor #544 I + public static final int GL_CURRENT_TEXTURE_COORDS = 2819; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_COLOR = 2820; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_INDEX = 2821; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_TEXTURE_COORDS = 2822; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_POSITION = 2823; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_POSITION_VALID = 2824; + + // Field descriptor #544 I + public static final int GL_CURRENT_RASTER_DISTANCE = 2825; + + // Field descriptor #544 I + public static final int GL_POINT_SMOOTH = 2832; + + // Field descriptor #544 I + public static final int GL_POINT_SIZE = 2833; + + // Field descriptor #544 I + public static final int GL_POINT_SIZE_RANGE = 2834; + + // Field descriptor #544 I + public static final int GL_POINT_SIZE_GRANULARITY = 2835; + + // Field descriptor #544 I + public static final int GL_LINE_SMOOTH = 2848; + + // Field descriptor #544 I + public static final int GL_LINE_WIDTH = 2849; + + // Field descriptor #544 I + public static final int GL_LINE_WIDTH_RANGE = 2850; + + // Field descriptor #544 I + public static final int GL_LINE_WIDTH_GRANULARITY = 2851; + + // Field descriptor #544 I + public static final int GL_LINE_STIPPLE = 2852; + + // Field descriptor #544 I + public static final int GL_LINE_STIPPLE_PATTERN = 2853; + + // Field descriptor #544 I + public static final int GL_LINE_STIPPLE_REPEAT = 2854; + + // Field descriptor #544 I + public static final int GL_LIST_MODE = 2864; + + // Field descriptor #544 I + public static final int GL_MAX_LIST_NESTING = 2865; + + // Field descriptor #544 I + public static final int GL_LIST_BASE = 2866; + + // Field descriptor #544 I + public static final int GL_LIST_INDEX = 2867; + + // Field descriptor #544 I + public static final int GL_POLYGON_MODE = 2880; + + // Field descriptor #544 I + public static final int GL_POLYGON_SMOOTH = 2881; + + // Field descriptor #544 I + public static final int GL_POLYGON_STIPPLE = 2882; + + // Field descriptor #544 I + public static final int GL_EDGE_FLAG = 2883; + + // Field descriptor #544 I + public static final int GL_CULL_FACE = 2884; + + // Field descriptor #544 I + public static final int GL_CULL_FACE_MODE = 2885; + + // Field descriptor #544 I + public static final int GL_FRONT_FACE = 2886; + + // Field descriptor #544 I + public static final int GL_LIGHTING = 2896; + + // Field descriptor #544 I + public static final int GL_LIGHT_MODEL_LOCAL_VIEWER = 2897; + + // Field descriptor #544 I + public static final int GL_LIGHT_MODEL_TWO_SIDE = 2898; + + // Field descriptor #544 I + public static final int GL_LIGHT_MODEL_AMBIENT = 2899; + + // Field descriptor #544 I + public static final int GL_SHADE_MODEL = 2900; + + // Field descriptor #544 I + public static final int GL_COLOR_MATERIAL_FACE = 2901; + + // Field descriptor #544 I + public static final int GL_COLOR_MATERIAL_PARAMETER = 2902; + + // Field descriptor #544 I + public static final int GL_COLOR_MATERIAL = 2903; + + // Field descriptor #544 I + public static final int GL_FOG = 2912; + + // Field descriptor #544 I + public static final int GL_FOG_INDEX = 2913; + + // Field descriptor #544 I + public static final int GL_FOG_DENSITY = 2914; + + // Field descriptor #544 I + public static final int GL_FOG_START = 2915; + + // Field descriptor #544 I + public static final int GL_FOG_END = 2916; + + // Field descriptor #544 I + public static final int GL_FOG_MODE = 2917; + + // Field descriptor #544 I + public static final int GL_FOG_COLOR = 2918; + + // Field descriptor #544 I + public static final int GL_DEPTH_RANGE = 2928; + + // Field descriptor #544 I + public static final int GL_DEPTH_TEST = 2929; + + // Field descriptor #544 I + public static final int GL_DEPTH_WRITEMASK = 2930; + + // Field descriptor #544 I + public static final int GL_DEPTH_CLEAR_VALUE = 2931; + + // Field descriptor #544 I + public static final int GL_DEPTH_FUNC = 2932; + + // Field descriptor #544 I + public static final int GL_ACCUM_CLEAR_VALUE = 2944; + + // Field descriptor #544 I + public static final int GL_STENCIL_TEST = 2960; + + // Field descriptor #544 I + public static final int GL_STENCIL_CLEAR_VALUE = 2961; + + // Field descriptor #544 I + public static final int GL_STENCIL_FUNC = 2962; + + // Field descriptor #544 I + public static final int GL_STENCIL_VALUE_MASK = 2963; + + // Field descriptor #544 I + public static final int GL_STENCIL_FAIL = 2964; + + // Field descriptor #544 I + public static final int GL_STENCIL_PASS_DEPTH_FAIL = 2965; + + // Field descriptor #544 I + public static final int GL_STENCIL_PASS_DEPTH_PASS = 2966; + + // Field descriptor #544 I + public static final int GL_STENCIL_REF = 2967; + + // Field descriptor #544 I + public static final int GL_STENCIL_WRITEMASK = 2968; + + // Field descriptor #544 I + public static final int GL_MATRIX_MODE = 2976; + + // Field descriptor #544 I + public static final int GL_NORMALIZE = 2977; + + // Field descriptor #544 I + public static final int GL_VIEWPORT = 2978; + + // Field descriptor #544 I + public static final int GL_MODELVIEW_STACK_DEPTH = 2979; + + // Field descriptor #544 I + public static final int GL_PROJECTION_STACK_DEPTH = 2980; + + // Field descriptor #544 I + public static final int GL_TEXTURE_STACK_DEPTH = 2981; + + // Field descriptor #544 I + public static final int GL_MODELVIEW_MATRIX = 2982; + + // Field descriptor #544 I + public static final int GL_PROJECTION_MATRIX = 2983; + + // Field descriptor #544 I + public static final int GL_TEXTURE_MATRIX = 2984; + + // Field descriptor #544 I + public static final int GL_ATTRIB_STACK_DEPTH = 2992; + + // Field descriptor #544 I + public static final int GL_CLIENT_ATTRIB_STACK_DEPTH = 2993; + + // Field descriptor #544 I + public static final int GL_ALPHA_TEST = 3008; + + // Field descriptor #544 I + public static final int GL_ALPHA_TEST_FUNC = 3009; + + // Field descriptor #544 I + public static final int GL_ALPHA_TEST_REF = 3010; + + // Field descriptor #544 I + public static final int GL_DITHER = 3024; + + // Field descriptor #544 I + public static final int GL_BLEND_DST = 3040; + + // Field descriptor #544 I + public static final int GL_BLEND_SRC = 3041; + + // Field descriptor #544 I + public static final int GL_BLEND = 3042; + + // Field descriptor #544 I + public static final int GL_LOGIC_OP_MODE = 3056; + + // Field descriptor #544 I + public static final int GL_INDEX_LOGIC_OP = 3057; + + // Field descriptor #544 I + public static final int GL_COLOR_LOGIC_OP = 3058; + + // Field descriptor #544 I + public static final int GL_AUX_BUFFERS = 3072; + + // Field descriptor #544 I + public static final int GL_DRAW_BUFFER = 3073; + + // Field descriptor #544 I + public static final int GL_READ_BUFFER = 3074; + + // Field descriptor #544 I + public static final int GL_SCISSOR_BOX = 3088; + + // Field descriptor #544 I + public static final int GL_SCISSOR_TEST = 3089; + + // Field descriptor #544 I + public static final int GL_INDEX_CLEAR_VALUE = 3104; + + // Field descriptor #544 I + public static final int GL_INDEX_WRITEMASK = 3105; + + // Field descriptor #544 I + public static final int GL_COLOR_CLEAR_VALUE = 3106; + + // Field descriptor #544 I + public static final int GL_COLOR_WRITEMASK = 3107; + + // Field descriptor #544 I + public static final int GL_INDEX_MODE = 3120; + + // Field descriptor #544 I + public static final int GL_RGBA_MODE = 3121; + + // Field descriptor #544 I + public static final int GL_DOUBLEBUFFER = 3122; + + // Field descriptor #544 I + public static final int GL_STEREO = 3123; + + // Field descriptor #544 I + public static final int GL_RENDER_MODE = 3136; + + // Field descriptor #544 I + public static final int GL_PERSPECTIVE_CORRECTION_HINT = 3152; + + // Field descriptor #544 I + public static final int GL_POINT_SMOOTH_HINT = 3153; + + // Field descriptor #544 I + public static final int GL_LINE_SMOOTH_HINT = 3154; + + // Field descriptor #544 I + public static final int GL_POLYGON_SMOOTH_HINT = 3155; + + // Field descriptor #544 I + public static final int GL_FOG_HINT = 3156; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GEN_S = 3168; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GEN_T = 3169; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GEN_R = 3170; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GEN_Q = 3171; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_I = 3184; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_S_TO_S = 3185; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_R = 3186; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_G = 3187; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_B = 3188; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_A = 3189; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_R_TO_R = 3190; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_G_TO_G = 3191; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_B_TO_B = 3192; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_A_TO_A = 3193; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_I_SIZE = 3248; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_S_TO_S_SIZE = 3249; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_R_SIZE = 3250; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_G_SIZE = 3251; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_B_SIZE = 3252; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_I_TO_A_SIZE = 3253; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_R_TO_R_SIZE = 3254; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_G_TO_G_SIZE = 3255; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_B_TO_B_SIZE = 3256; + + // Field descriptor #544 I + public static final int GL_PIXEL_MAP_A_TO_A_SIZE = 3257; + + // Field descriptor #544 I + public static final int GL_UNPACK_SWAP_BYTES = 3312; + + // Field descriptor #544 I + public static final int GL_UNPACK_LSB_FIRST = 3313; + + // Field descriptor #544 I + public static final int GL_UNPACK_ROW_LENGTH = 3314; + + // Field descriptor #544 I + public static final int GL_UNPACK_SKIP_ROWS = 3315; + + // Field descriptor #544 I + public static final int GL_UNPACK_SKIP_PIXELS = 3316; + + // Field descriptor #544 I + public static final int GL_UNPACK_ALIGNMENT = 3317; + + // Field descriptor #544 I + public static final int GL_PACK_SWAP_BYTES = 3328; + + // Field descriptor #544 I + public static final int GL_PACK_LSB_FIRST = 3329; + + // Field descriptor #544 I + public static final int GL_PACK_ROW_LENGTH = 3330; + + // Field descriptor #544 I + public static final int GL_PACK_SKIP_ROWS = 3331; + + // Field descriptor #544 I + public static final int GL_PACK_SKIP_PIXELS = 3332; + + // Field descriptor #544 I + public static final int GL_PACK_ALIGNMENT = 3333; + + // Field descriptor #544 I + public static final int GL_MAP_COLOR = 3344; + + // Field descriptor #544 I + public static final int GL_MAP_STENCIL = 3345; + + // Field descriptor #544 I + public static final int GL_INDEX_SHIFT = 3346; + + // Field descriptor #544 I + public static final int GL_INDEX_OFFSET = 3347; + + // Field descriptor #544 I + public static final int GL_RED_SCALE = 3348; + + // Field descriptor #544 I + public static final int GL_RED_BIAS = 3349; + + // Field descriptor #544 I + public static final int GL_ZOOM_X = 3350; + + // Field descriptor #544 I + public static final int GL_ZOOM_Y = 3351; + + // Field descriptor #544 I + public static final int GL_GREEN_SCALE = 3352; + + // Field descriptor #544 I + public static final int GL_GREEN_BIAS = 3353; + + // Field descriptor #544 I + public static final int GL_BLUE_SCALE = 3354; + + // Field descriptor #544 I + public static final int GL_BLUE_BIAS = 3355; + + // Field descriptor #544 I + public static final int GL_ALPHA_SCALE = 3356; + + // Field descriptor #544 I + public static final int GL_ALPHA_BIAS = 3357; + + // Field descriptor #544 I + public static final int GL_DEPTH_SCALE = 3358; + + // Field descriptor #544 I + public static final int GL_DEPTH_BIAS = 3359; + + // Field descriptor #544 I + public static final int GL_MAX_EVAL_ORDER = 3376; + + // Field descriptor #544 I + public static final int GL_MAX_LIGHTS = 3377; + + // Field descriptor #544 I + public static final int GL_MAX_CLIP_PLANES = 3378; + + // Field descriptor #544 I + public static final int GL_MAX_TEXTURE_SIZE = 3379; + + // Field descriptor #544 I + public static final int GL_MAX_PIXEL_MAP_TABLE = 3380; + + // Field descriptor #544 I + public static final int GL_MAX_ATTRIB_STACK_DEPTH = 3381; + + // Field descriptor #544 I + public static final int GL_MAX_MODELVIEW_STACK_DEPTH = 3382; + + // Field descriptor #544 I + public static final int GL_MAX_NAME_STACK_DEPTH = 3383; + + // Field descriptor #544 I + public static final int GL_MAX_PROJECTION_STACK_DEPTH = 3384; + + // Field descriptor #544 I + public static final int GL_MAX_TEXTURE_STACK_DEPTH = 3385; + + // Field descriptor #544 I + public static final int GL_MAX_VIEWPORT_DIMS = 3386; + + // Field descriptor #544 I + public static final int GL_MAX_CLIENT_ATTRIB_STACK_DEPTH = 3387; + + // Field descriptor #544 I + public static final int GL_SUBPIXEL_BITS = 3408; + + // Field descriptor #544 I + public static final int GL_INDEX_BITS = 3409; + + // Field descriptor #544 I + public static final int GL_RED_BITS = 3410; + + // Field descriptor #544 I + public static final int GL_GREEN_BITS = 3411; + + // Field descriptor #544 I + public static final int GL_BLUE_BITS = 3412; + + // Field descriptor #544 I + public static final int GL_ALPHA_BITS = 3413; + + // Field descriptor #544 I + public static final int GL_DEPTH_BITS = 3414; + + // Field descriptor #544 I + public static final int GL_STENCIL_BITS = 3415; + + // Field descriptor #544 I + public static final int GL_ACCUM_RED_BITS = 3416; + + // Field descriptor #544 I + public static final int GL_ACCUM_GREEN_BITS = 3417; + + // Field descriptor #544 I + public static final int GL_ACCUM_BLUE_BITS = 3418; + + // Field descriptor #544 I + public static final int GL_ACCUM_ALPHA_BITS = 3419; + + // Field descriptor #544 I + public static final int GL_NAME_STACK_DEPTH = 3440; + + // Field descriptor #544 I + public static final int GL_AUTO_NORMAL = 3456; + + // Field descriptor #544 I + public static final int GL_MAP1_COLOR_4 = 3472; + + // Field descriptor #544 I + public static final int GL_MAP1_INDEX = 3473; + + // Field descriptor #544 I + public static final int GL_MAP1_NORMAL = 3474; + + // Field descriptor #544 I + public static final int GL_MAP1_TEXTURE_COORD_1 = 3475; + + // Field descriptor #544 I + public static final int GL_MAP1_TEXTURE_COORD_2 = 3476; + + // Field descriptor #544 I + public static final int GL_MAP1_TEXTURE_COORD_3 = 3477; + + // Field descriptor #544 I + public static final int GL_MAP1_TEXTURE_COORD_4 = 3478; + + // Field descriptor #544 I + public static final int GL_MAP1_VERTEX_3 = 3479; + + // Field descriptor #544 I + public static final int GL_MAP1_VERTEX_4 = 3480; + + // Field descriptor #544 I + public static final int GL_MAP2_COLOR_4 = 3504; + + // Field descriptor #544 I + public static final int GL_MAP2_INDEX = 3505; + + // Field descriptor #544 I + public static final int GL_MAP2_NORMAL = 3506; + + // Field descriptor #544 I + public static final int GL_MAP2_TEXTURE_COORD_1 = 3507; + + // Field descriptor #544 I + public static final int GL_MAP2_TEXTURE_COORD_2 = 3508; + + // Field descriptor #544 I + public static final int GL_MAP2_TEXTURE_COORD_3 = 3509; + + // Field descriptor #544 I + public static final int GL_MAP2_TEXTURE_COORD_4 = 3510; + + // Field descriptor #544 I + public static final int GL_MAP2_VERTEX_3 = 3511; + + // Field descriptor #544 I + public static final int GL_MAP2_VERTEX_4 = 3512; + + // Field descriptor #544 I + public static final int GL_MAP1_GRID_DOMAIN = 3536; + + // Field descriptor #544 I + public static final int GL_MAP1_GRID_SEGMENTS = 3537; + + // Field descriptor #544 I + public static final int GL_MAP2_GRID_DOMAIN = 3538; + + // Field descriptor #544 I + public static final int GL_MAP2_GRID_SEGMENTS = 3539; + + // Field descriptor #544 I + public static final int GL_TEXTURE_1D = 3552; + + // Field descriptor #544 I + public static final int GL_TEXTURE_2D = 3553; + + // Field descriptor #544 I + public static final int GL_FEEDBACK_BUFFER_POINTER = 3568; + + // Field descriptor #544 I + public static final int GL_FEEDBACK_BUFFER_SIZE = 3569; + + // Field descriptor #544 I + public static final int GL_FEEDBACK_BUFFER_TYPE = 3570; + + // Field descriptor #544 I + public static final int GL_SELECTION_BUFFER_POINTER = 3571; + + // Field descriptor #544 I + public static final int GL_SELECTION_BUFFER_SIZE = 3572; + + // Field descriptor #544 I + public static final int GL_TEXTURE_WIDTH = 4096; + + // Field descriptor #544 I + public static final int GL_TEXTURE_HEIGHT = 4097; + + // Field descriptor #544 I + public static final int GL_TEXTURE_INTERNAL_FORMAT = 4099; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BORDER_COLOR = 4100; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BORDER = 4101; + + // Field descriptor #544 I + public static final int GL_DONT_CARE = 4352; + + // Field descriptor #544 I + public static final int GL_FASTEST = 4353; + + // Field descriptor #544 I + public static final int GL_NICEST = 4354; + + // Field descriptor #544 I + public static final int GL_LIGHT0 = 16384; + + // Field descriptor #544 I + public static final int GL_LIGHT1 = 16385; + + // Field descriptor #544 I + public static final int GL_LIGHT2 = 16386; + + // Field descriptor #544 I + public static final int GL_LIGHT3 = 16387; + + // Field descriptor #544 I + public static final int GL_LIGHT4 = 16388; + + // Field descriptor #544 I + public static final int GL_LIGHT5 = 16389; + + // Field descriptor #544 I + public static final int GL_LIGHT6 = 16390; + + // Field descriptor #544 I + public static final int GL_LIGHT7 = 16391; + + // Field descriptor #544 I + public static final int GL_AMBIENT = 4608; + + // Field descriptor #544 I + public static final int GL_DIFFUSE = 4609; + + // Field descriptor #544 I + public static final int GL_SPECULAR = 4610; + + // Field descriptor #544 I + public static final int GL_POSITION = 4611; + + // Field descriptor #544 I + public static final int GL_SPOT_DIRECTION = 4612; + + // Field descriptor #544 I + public static final int GL_SPOT_EXPONENT = 4613; + + // Field descriptor #544 I + public static final int GL_SPOT_CUTOFF = 4614; + + // Field descriptor #544 I + public static final int GL_CONSTANT_ATTENUATION = 4615; + + // Field descriptor #544 I + public static final int GL_LINEAR_ATTENUATION = 4616; + + // Field descriptor #544 I + public static final int GL_QUADRATIC_ATTENUATION = 4617; + + // Field descriptor #544 I + public static final int GL_COMPILE = 4864; + + // Field descriptor #544 I + public static final int GL_COMPILE_AND_EXECUTE = 4865; + + // Field descriptor #544 I + public static final int GL_CLEAR = 5376; + + // Field descriptor #544 I + public static final int GL_AND = 5377; + + // Field descriptor #544 I + public static final int GL_AND_REVERSE = 5378; + + // Field descriptor #544 I + public static final int GL_COPY = 5379; + + // Field descriptor #544 I + public static final int GL_AND_INVERTED = 5380; + + // Field descriptor #544 I + public static final int GL_NOOP = 5381; + + // Field descriptor #544 I + public static final int GL_XOR = 5382; + + // Field descriptor #544 I + public static final int GL_OR = 5383; + + // Field descriptor #544 I + public static final int GL_NOR = 5384; + + // Field descriptor #544 I + public static final int GL_EQUIV = 5385; + + // Field descriptor #544 I + public static final int GL_INVERT = 5386; + + // Field descriptor #544 I + public static final int GL_OR_REVERSE = 5387; + + // Field descriptor #544 I + public static final int GL_COPY_INVERTED = 5388; + + // Field descriptor #544 I + public static final int GL_OR_INVERTED = 5389; + + // Field descriptor #544 I + public static final int GL_NAND = 5390; + + // Field descriptor #544 I + public static final int GL_SET = 5391; + + // Field descriptor #544 I + public static final int GL_EMISSION = 5632; + + // Field descriptor #544 I + public static final int GL_SHININESS = 5633; + + // Field descriptor #544 I + public static final int GL_AMBIENT_AND_DIFFUSE = 5634; + + // Field descriptor #544 I + public static final int GL_COLOR_INDEXES = 5635; + + // Field descriptor #544 I + public static final int GL_MODELVIEW = 5888; + + // Field descriptor #544 I + public static final int GL_PROJECTION = 5889; + + // Field descriptor #544 I + public static final int GL_TEXTURE = 5890; + + // Field descriptor #544 I + public static final int GL_COLOR = 6144; + + // Field descriptor #544 I + public static final int GL_DEPTH = 6145; + + // Field descriptor #544 I + public static final int GL_STENCIL = 6146; + + // Field descriptor #544 I + public static final int GL_COLOR_INDEX = 6400; + + // Field descriptor #544 I + public static final int GL_STENCIL_INDEX = 6401; + + // Field descriptor #544 I + public static final int GL_DEPTH_COMPONENT = 6402; + + // Field descriptor #544 I + public static final int GL_RED = 6403; + + // Field descriptor #544 I + public static final int GL_GREEN = 6404; + + // Field descriptor #544 I + public static final int GL_BLUE = 6405; + + // Field descriptor #544 I + public static final int GL_ALPHA = 6406; + + // Field descriptor #544 I + public static final int GL_RGB = 6407; + + // Field descriptor #544 I + public static final int GL_RGBA = 6408; + + // Field descriptor #544 I + public static final int GL_LUMINANCE = 6409; + + // Field descriptor #544 I + public static final int GL_LUMINANCE_ALPHA = 6410; + + // Field descriptor #544 I + public static final int GL_BITMAP = 6656; + + // Field descriptor #544 I + public static final int GL_POINT = 6912; + + // Field descriptor #544 I + public static final int GL_LINE = 6913; + + // Field descriptor #544 I + public static final int GL_FILL = 6914; + + // Field descriptor #544 I + public static final int GL_RENDER = 7168; + + // Field descriptor #544 I + public static final int GL_FEEDBACK = 7169; + + // Field descriptor #544 I + public static final int GL_SELECT = 7170; + + // Field descriptor #544 I + public static final int GL_FLAT = 7424; + + // Field descriptor #544 I + public static final int GL_SMOOTH = 7425; + + // Field descriptor #544 I + public static final int GL_KEEP = 7680; + + // Field descriptor #544 I + public static final int GL_REPLACE = 7681; + + // Field descriptor #544 I + public static final int GL_INCR = 7682; + + // Field descriptor #544 I + public static final int GL_DECR = 7683; + + // Field descriptor #544 I + public static final int GL_VENDOR = 7936; + + // Field descriptor #544 I + public static final int GL_RENDERER = 7937; + + // Field descriptor #544 I + public static final int GL_VERSION = 7938; + + // Field descriptor #544 I + public static final int GL_EXTENSIONS = 7939; + + // Field descriptor #544 I + public static final int GL_S = 8192; + + // Field descriptor #544 I + public static final int GL_T = 8193; + + // Field descriptor #544 I + public static final int GL_R = 8194; + + // Field descriptor #544 I + public static final int GL_Q = 8195; + + // Field descriptor #544 I + public static final int GL_MODULATE = 8448; + + // Field descriptor #544 I + public static final int GL_DECAL = 8449; + + // Field descriptor #544 I + public static final int GL_TEXTURE_ENV_MODE = 8704; + + // Field descriptor #544 I + public static final int GL_TEXTURE_ENV_COLOR = 8705; + + // Field descriptor #544 I + public static final int GL_TEXTURE_ENV = 8960; + + // Field descriptor #544 I + public static final int GL_EYE_LINEAR = 9216; + + // Field descriptor #544 I + public static final int GL_OBJECT_LINEAR = 9217; + + // Field descriptor #544 I + public static final int GL_SPHERE_MAP = 9218; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GEN_MODE = 9472; + + // Field descriptor #544 I + public static final int GL_OBJECT_PLANE = 9473; + + // Field descriptor #544 I + public static final int GL_EYE_PLANE = 9474; + + // Field descriptor #544 I + public static final int GL_NEAREST = 9728; + + // Field descriptor #544 I + public static final int GL_LINEAR = 9729; + + // Field descriptor #544 I + public static final int GL_NEAREST_MIPMAP_NEAREST = 9984; + + // Field descriptor #544 I + public static final int GL_LINEAR_MIPMAP_NEAREST = 9985; + + // Field descriptor #544 I + public static final int GL_NEAREST_MIPMAP_LINEAR = 9986; + + // Field descriptor #544 I + public static final int GL_LINEAR_MIPMAP_LINEAR = 9987; + + // Field descriptor #544 I + public static final int GL_TEXTURE_MAG_FILTER = 10240; + + // Field descriptor #544 I + public static final int GL_TEXTURE_MIN_FILTER = 10241; + + // Field descriptor #544 I + public static final int GL_TEXTURE_WRAP_S = 10242; + + // Field descriptor #544 I + public static final int GL_TEXTURE_WRAP_T = 10243; + + // Field descriptor #544 I + public static final int GL_CLAMP = 10496; + + // Field descriptor #544 I + public static final int GL_REPEAT = 10497; + + // Field descriptor #544 I + public static final int GL_CLIENT_PIXEL_STORE_BIT = 1; + + // Field descriptor #544 I + public static final int GL_CLIENT_VERTEX_ARRAY_BIT = 2; + + // Field descriptor #544 I + public static final int GL_ALL_CLIENT_ATTRIB_BITS = -1; + + // Field descriptor #544 I + public static final int GL_POLYGON_OFFSET_FACTOR = 32824; + + // Field descriptor #544 I + public static final int GL_POLYGON_OFFSET_UNITS = 10752; + + // Field descriptor #544 I + public static final int GL_POLYGON_OFFSET_POINT = 10753; + + // Field descriptor #544 I + public static final int GL_POLYGON_OFFSET_LINE = 10754; + + // Field descriptor #544 I + public static final int GL_POLYGON_OFFSET_FILL = 32823; + + // Field descriptor #544 I + public static final int GL_ALPHA4 = 32827; + + // Field descriptor #544 I + public static final int GL_ALPHA8 = 32828; + + // Field descriptor #544 I + public static final int GL_ALPHA12 = 32829; + + // Field descriptor #544 I + public static final int GL_ALPHA16 = 32830; + + // Field descriptor #544 I + public static final int GL_LUMINANCE4 = 32831; + + // Field descriptor #544 I + public static final int GL_LUMINANCE8 = 32832; + + // Field descriptor #544 I + public static final int GL_LUMINANCE12 = 32833; + + // Field descriptor #544 I + public static final int GL_LUMINANCE16 = 32834; + + // Field descriptor #544 I + public static final int GL_LUMINANCE4_ALPHA4 = 32835; + + // Field descriptor #544 I + public static final int GL_LUMINANCE6_ALPHA2 = 32836; + + // Field descriptor #544 I + public static final int GL_LUMINANCE8_ALPHA8 = 32837; + + // Field descriptor #544 I + public static final int GL_LUMINANCE12_ALPHA4 = 32838; + + // Field descriptor #544 I + public static final int GL_LUMINANCE12_ALPHA12 = 32839; + + // Field descriptor #544 I + public static final int GL_LUMINANCE16_ALPHA16 = 32840; + + // Field descriptor #544 I + public static final int GL_INTENSITY = 32841; + + // Field descriptor #544 I + public static final int GL_INTENSITY4 = 32842; + + // Field descriptor #544 I + public static final int GL_INTENSITY8 = 32843; + + // Field descriptor #544 I + public static final int GL_INTENSITY12 = 32844; + + // Field descriptor #544 I + public static final int GL_INTENSITY16 = 32845; + + // Field descriptor #544 I + public static final int GL_R3_G3_B2 = 10768; + + // Field descriptor #544 I + public static final int GL_RGB4 = 32847; + + // Field descriptor #544 I + public static final int GL_RGB5 = 32848; + + // Field descriptor #544 I + public static final int GL_RGB8 = 32849; + + // Field descriptor #544 I + public static final int GL_RGB10 = 32850; + + // Field descriptor #544 I + public static final int GL_RGB12 = 32851; + + // Field descriptor #544 I + public static final int GL_RGB16 = 32852; + + // Field descriptor #544 I + public static final int GL_RGBA2 = 32853; + + // Field descriptor #544 I + public static final int GL_RGBA4 = 32854; + + // Field descriptor #544 I + public static final int GL_RGB5_A1 = 32855; + + // Field descriptor #544 I + public static final int GL_RGBA8 = 32856; + + // Field descriptor #544 I + public static final int GL_RGB10_A2 = 32857; + + // Field descriptor #544 I + public static final int GL_RGBA12 = 32858; + + // Field descriptor #544 I + public static final int GL_RGBA16 = 32859; + + // Field descriptor #544 I + public static final int GL_TEXTURE_RED_SIZE = 32860; + + // Field descriptor #544 I + public static final int GL_TEXTURE_GREEN_SIZE = 32861; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BLUE_SIZE = 32862; + + // Field descriptor #544 I + public static final int GL_TEXTURE_ALPHA_SIZE = 32863; + + // Field descriptor #544 I + public static final int GL_TEXTURE_LUMINANCE_SIZE = 32864; + + // Field descriptor #544 I + public static final int GL_TEXTURE_INTENSITY_SIZE = 32865; + + // Field descriptor #544 I + public static final int GL_PROXY_TEXTURE_1D = 32867; + + // Field descriptor #544 I + public static final int GL_PROXY_TEXTURE_2D = 32868; + + // Field descriptor #544 I + public static final int GL_TEXTURE_PRIORITY = 32870; + + // Field descriptor #544 I + public static final int GL_TEXTURE_RESIDENT = 32871; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BINDING_1D = 32872; + + // Field descriptor #544 I + public static final int GL_TEXTURE_BINDING_2D = 32873; + + // Field descriptor #544 I + public static final int GL_VERTEX_ARRAY = 32884; + + // Field descriptor #544 I + public static final int GL_NORMAL_ARRAY = 32885; + + // Field descriptor #544 I + public static final int GL_COLOR_ARRAY = 32886; + + // Field descriptor #544 I + public static final int GL_INDEX_ARRAY = 32887; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COORD_ARRAY = 32888; + + // Field descriptor #544 I + public static final int GL_EDGE_FLAG_ARRAY = 32889; + + // Field descriptor #544 I + public static final int GL_VERTEX_ARRAY_SIZE = 32890; + + // Field descriptor #544 I + public static final int GL_VERTEX_ARRAY_TYPE = 32891; + + // Field descriptor #544 I + public static final int GL_VERTEX_ARRAY_STRIDE = 32892; + + // Field descriptor #544 I + public static final int GL_NORMAL_ARRAY_TYPE = 32894; + + // Field descriptor #544 I + public static final int GL_NORMAL_ARRAY_STRIDE = 32895; + + // Field descriptor #544 I + public static final int GL_COLOR_ARRAY_SIZE = 32897; + + // Field descriptor #544 I + public static final int GL_COLOR_ARRAY_TYPE = 32898; + + // Field descriptor #544 I + public static final int GL_COLOR_ARRAY_STRIDE = 32899; + + // Field descriptor #544 I + public static final int GL_INDEX_ARRAY_TYPE = 32901; + + // Field descriptor #544 I + public static final int GL_INDEX_ARRAY_STRIDE = 32902; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COORD_ARRAY_SIZE = 32904; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COORD_ARRAY_TYPE = 32905; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COORD_ARRAY_STRIDE = 32906; + + // Field descriptor #544 I + public static final int GL_EDGE_FLAG_ARRAY_STRIDE = 32908; + + // Field descriptor #544 I + public static final int GL_VERTEX_ARRAY_POINTER = 32910; + + // Field descriptor #544 I + public static final int GL_NORMAL_ARRAY_POINTER = 32911; + + // Field descriptor #544 I + public static final int GL_COLOR_ARRAY_POINTER = 32912; + + // Field descriptor #544 I + public static final int GL_INDEX_ARRAY_POINTER = 32913; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COORD_ARRAY_POINTER = 32914; + + // Field descriptor #544 I + public static final int GL_EDGE_FLAG_ARRAY_POINTER = 32915; + + // Field descriptor #544 I + public static final int GL_V2F = 10784; + + // Field descriptor #544 I + public static final int GL_V3F = 10785; + + // Field descriptor #544 I + public static final int GL_C4UB_V2F = 10786; + + // Field descriptor #544 I + public static final int GL_C4UB_V3F = 10787; + + // Field descriptor #544 I + public static final int GL_C3F_V3F = 10788; + + // Field descriptor #544 I + public static final int GL_N3F_V3F = 10789; + + // Field descriptor #544 I + public static final int GL_C4F_N3F_V3F = 10790; + + // Field descriptor #544 I + public static final int GL_T2F_V3F = 10791; + + // Field descriptor #544 I + public static final int GL_T4F_V4F = 10792; + + // Field descriptor #544 I + public static final int GL_T2F_C4UB_V3F = 10793; + + // Field descriptor #544 I + public static final int GL_T2F_C3F_V3F = 10794; + + // Field descriptor #544 I + public static final int GL_T2F_N3F_V3F = 10795; + + // Field descriptor #544 I + public static final int GL_T2F_C4F_N3F_V3F = 10796; + + // Field descriptor #544 I + public static final int GL_T4F_C4F_N3F_V4F = 10797; + + // Field descriptor #544 I + public static final int GL_LOGIC_OP = 3057; + + // Field descriptor #544 I + public static final int GL_TEXTURE_COMPONENTS = 4099; + + // Field descriptor #45 I + public static final int GL_TEXTURE_BINDING_3D = 32874; + + // Field descriptor #45 I + public static final int GL_PACK_SKIP_IMAGES = 32875; + + // Field descriptor #45 I + public static final int GL_PACK_IMAGE_HEIGHT = 32876; + + // Field descriptor #45 I + public static final int GL_UNPACK_SKIP_IMAGES = 32877; + + // Field descriptor #45 I + public static final int GL_UNPACK_IMAGE_HEIGHT = 32878; + + // Field descriptor #45 I + public static final int GL_TEXTURE_3D = 32879; + + // Field descriptor #45 I + public static final int GL_PROXY_TEXTURE_3D = 32880; + + // Field descriptor #45 I + public static final int GL_TEXTURE_DEPTH = 32881; + + // Field descriptor #45 I + public static final int GL_TEXTURE_WRAP_R = 32882; + + // Field descriptor #45 I + public static final int GL_MAX_3D_TEXTURE_SIZE = 32883; + + // Field descriptor #45 I + public static final int GL_BGR = 32992; + + // Field descriptor #45 I + public static final int GL_BGRA = 32993; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_BYTE_3_3_2 = 32818; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_BYTE_2_3_3_REV = 33634; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_5_6_5 = 33635; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_5_6_5_REV = 33636; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_4_4_4_4 = 32819; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_4_4_4_4_REV = 33637; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 32820; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_SHORT_1_5_5_5_REV = 33638; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_INT_8_8_8_8 = 32821; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_INT_8_8_8_8_REV = 33639; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_INT_10_10_10_2 = 32822; + + // Field descriptor #45 I + public static final int GL_UNSIGNED_INT_2_10_10_10_REV = 33640; + + // Field descriptor #45 I + public static final int GL_RESCALE_NORMAL = 32826; + + // Field descriptor #45 I + public static final int GL_LIGHT_MODEL_COLOR_CONTROL = 33272; + + // Field descriptor #45 I + public static final int GL_SINGLE_COLOR = 33273; + + // Field descriptor #45 I + public static final int GL_SEPARATE_SPECULAR_COLOR = 33274; + + // Field descriptor #45 I + public static final int GL_CLAMP_TO_EDGE = 33071; + + // Field descriptor #45 I + public static final int GL_TEXTURE_MIN_LOD = 33082; + + // Field descriptor #45 I + public static final int GL_TEXTURE_MAX_LOD = 33083; + + // Field descriptor #45 I + public static final int GL_TEXTURE_BASE_LEVEL = 33084; + + // Field descriptor #45 I + public static final int GL_TEXTURE_MAX_LEVEL = 33085; + + // Field descriptor #45 I + public static final int GL_MAX_ELEMENTS_VERTICES = 33000; + + // Field descriptor #45 I + public static final int GL_MAX_ELEMENTS_INDICES = 33001; + + // Field descriptor #45 I + public static final int GL_ALIASED_POINT_SIZE_RANGE = 33901; + + // Field descriptor #45 I + public static final int GL_ALIASED_LINE_WIDTH_RANGE = 33902; + + // Field descriptor #45 I + public static final int GL_SMOOTH_POINT_SIZE_RANGE = 2834; + + // Field descriptor #45 I + public static final int GL_SMOOTH_POINT_SIZE_GRANULARITY = 2835; + + // Field descriptor #45 I + public static final int GL_SMOOTH_LINE_WIDTH_RANGE = 2850; + + // Field descriptor #45 I + public static final int GL_SMOOTH_LINE_WIDTH_GRANULARITY = 2851; + + // Field descriptor #76 I + public static final int GL_TEXTURE0 = 33984; + + // Field descriptor #76 I + public static final int GL_TEXTURE1 = 33985; + + // Field descriptor #76 I + public static final int GL_TEXTURE2 = 33986; + + // Field descriptor #76 I + public static final int GL_TEXTURE3 = 33987; + + // Field descriptor #76 I + public static final int GL_TEXTURE4 = 33988; + + // Field descriptor #76 I + public static final int GL_TEXTURE5 = 33989; + + // Field descriptor #76 I + public static final int GL_TEXTURE6 = 33990; + + // Field descriptor #76 I + public static final int GL_TEXTURE7 = 33991; + + // Field descriptor #76 I + public static final int GL_TEXTURE8 = 33992; + + // Field descriptor #76 I + public static final int GL_TEXTURE9 = 33993; + + // Field descriptor #76 I + public static final int GL_TEXTURE10 = 33994; + + // Field descriptor #76 I + public static final int GL_TEXTURE11 = 33995; + + // Field descriptor #76 I + public static final int GL_TEXTURE12 = 33996; + + // Field descriptor #76 I + public static final int GL_TEXTURE13 = 33997; + + // Field descriptor #76 I + public static final int GL_TEXTURE14 = 33998; + + // Field descriptor #76 I + public static final int GL_TEXTURE15 = 33999; + + // Field descriptor #76 I + public static final int GL_TEXTURE16 = 34000; + + // Field descriptor #76 I + public static final int GL_TEXTURE17 = 34001; + + // Field descriptor #76 I + public static final int GL_TEXTURE18 = 34002; + + // Field descriptor #76 I + public static final int GL_TEXTURE19 = 34003; + + // Field descriptor #76 I + public static final int GL_TEXTURE20 = 34004; + + // Field descriptor #76 I + public static final int GL_TEXTURE21 = 34005; + + // Field descriptor #76 I + public static final int GL_TEXTURE22 = 34006; + + // Field descriptor #76 I + public static final int GL_TEXTURE23 = 34007; + + // Field descriptor #76 I + public static final int GL_TEXTURE24 = 34008; + + // Field descriptor #76 I + public static final int GL_TEXTURE25 = 34009; + + // Field descriptor #76 I + public static final int GL_TEXTURE26 = 34010; + + // Field descriptor #76 I + public static final int GL_TEXTURE27 = 34011; + + // Field descriptor #76 I + public static final int GL_TEXTURE28 = 34012; + + // Field descriptor #76 I + public static final int GL_TEXTURE29 = 34013; + + // Field descriptor #76 I + public static final int GL_TEXTURE30 = 34014; + + // Field descriptor #76 I + public static final int GL_TEXTURE31 = 34015; + + // Field descriptor #76 I + public static final int GL_ACTIVE_TEXTURE = 34016; + + // Field descriptor #76 I + public static final int GL_CLIENT_ACTIVE_TEXTURE = 34017; + + // Field descriptor #76 I + public static final int GL_MAX_TEXTURE_UNITS = 34018; + + // Field descriptor #76 I + public static final int GL_NORMAL_MAP = 34065; + + // Field descriptor #76 I + public static final int GL_REFLECTION_MAP = 34066; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP = 34067; + + // Field descriptor #76 I + public static final int GL_TEXTURE_BINDING_CUBE_MAP = 34068; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 34069; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 34070; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 34071; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 34072; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 34073; + + // Field descriptor #76 I + public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 34074; + + // Field descriptor #76 I + public static final int GL_PROXY_TEXTURE_CUBE_MAP = 34075; + + // Field descriptor #76 I + public static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 34076; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_ALPHA = 34025; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_LUMINANCE = 34026; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_LUMINANCE_ALPHA = 34027; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_INTENSITY = 34028; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_RGB = 34029; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_RGBA = 34030; + + // Field descriptor #76 I + public static final int GL_TEXTURE_COMPRESSION_HINT = 34031; + + // Field descriptor #76 I + public static final int GL_TEXTURE_COMPRESSED_IMAGE_SIZE = 34464; + + // Field descriptor #76 I + public static final int GL_TEXTURE_COMPRESSED = 34465; + + // Field descriptor #76 I + public static final int GL_NUM_COMPRESSED_TEXTURE_FORMATS = 34466; + + // Field descriptor #76 I + public static final int GL_COMPRESSED_TEXTURE_FORMATS = 34467; + + // Field descriptor #76 I + public static final int GL_MULTISAMPLE = 32925; + + // Field descriptor #76 I + public static final int GL_SAMPLE_ALPHA_TO_COVERAGE = 32926; + + // Field descriptor #76 I + public static final int GL_SAMPLE_ALPHA_TO_ONE = 32927; + + // Field descriptor #76 I + public static final int GL_SAMPLE_COVERAGE = 32928; + + // Field descriptor #76 I + public static final int GL_SAMPLE_BUFFERS = 32936; + + // Field descriptor #76 I + public static final int GL_SAMPLES = 32937; + + // Field descriptor #76 I + public static final int GL_SAMPLE_COVERAGE_VALUE = 32938; + + // Field descriptor #76 I + public static final int GL_SAMPLE_COVERAGE_INVERT = 32939; + + // Field descriptor #76 I + public static final int GL_MULTISAMPLE_BIT = 536870912; + + // Field descriptor #76 I + public static final int GL_TRANSPOSE_MODELVIEW_MATRIX = 34019; + + // Field descriptor #76 I + public static final int GL_TRANSPOSE_PROJECTION_MATRIX = 34020; + + // Field descriptor #76 I + public static final int GL_TRANSPOSE_TEXTURE_MATRIX = 34021; + + // Field descriptor #76 I + public static final int GL_TRANSPOSE_COLOR_MATRIX = 34022; + + // Field descriptor #76 I + public static final int GL_COMBINE = 34160; + + // Field descriptor #76 I + public static final int GL_COMBINE_RGB = 34161; + + // Field descriptor #76 I + public static final int GL_COMBINE_ALPHA = 34162; + + // Field descriptor #76 I + public static final int GL_SOURCE0_RGB = 34176; + + // Field descriptor #76 I + public static final int GL_SOURCE1_RGB = 34177; + + // Field descriptor #76 I + public static final int GL_SOURCE2_RGB = 34178; + + // Field descriptor #76 I + public static final int GL_SOURCE0_ALPHA = 34184; + + // Field descriptor #76 I + public static final int GL_SOURCE1_ALPHA = 34185; + + // Field descriptor #76 I + public static final int GL_SOURCE2_ALPHA = 34186; + + // Field descriptor #76 I + public static final int GL_OPERAND0_RGB = 34192; + + // Field descriptor #76 I + public static final int GL_OPERAND1_RGB = 34193; + + // Field descriptor #76 I + public static final int GL_OPERAND2_RGB = 34194; + + // Field descriptor #76 I + public static final int GL_OPERAND0_ALPHA = 34200; + + // Field descriptor #76 I + public static final int GL_OPERAND1_ALPHA = 34201; + + // Field descriptor #76 I + public static final int GL_OPERAND2_ALPHA = 34202; + + // Field descriptor #76 I + public static final int GL_RGB_SCALE = 34163; + + // Field descriptor #76 I + public static final int GL_ADD_SIGNED = 34164; + + // Field descriptor #76 I + public static final int GL_INTERPOLATE = 34165; + + // Field descriptor #76 I + public static final int GL_SUBTRACT = 34023; + + // Field descriptor #76 I + public static final int GL_CONSTANT = 34166; + + // Field descriptor #76 I + public static final int GL_PRIMARY_COLOR = 34167; + + // Field descriptor #76 I + public static final int GL_PREVIOUS = 34168; + + // Field descriptor #76 I + public static final int GL_DOT3_RGB = 34478; + + // Field descriptor #76 I + public static final int GL_DOT3_RGBA = 34479; + + // Field descriptor #76 I + public static final int GL_CLAMP_TO_BORDER = 33069; + + // Field descriptor #71 I + public static final int GL_ARRAY_BUFFER = 34962; + + // Field descriptor #71 I + public static final int GL_ELEMENT_ARRAY_BUFFER = 34963; + + // Field descriptor #71 I + public static final int GL_ARRAY_BUFFER_BINDING = 34964; + + // Field descriptor #71 I + public static final int GL_ELEMENT_ARRAY_BUFFER_BINDING = 34965; + + // Field descriptor #71 I + public static final int GL_VERTEX_ARRAY_BUFFER_BINDING = 34966; + + // Field descriptor #71 I + public static final int GL_NORMAL_ARRAY_BUFFER_BINDING = 34967; + + // Field descriptor #71 I + public static final int GL_COLOR_ARRAY_BUFFER_BINDING = 34968; + + // Field descriptor #71 I + public static final int GL_INDEX_ARRAY_BUFFER_BINDING = 34969; + + // Field descriptor #71 I + public static final int GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING = 34970; + + // Field descriptor #71 I + public static final int GL_EDGE_FLAG_ARRAY_BUFFER_BINDING = 34971; + + // Field descriptor #71 I + public static final int GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING = 34972; + + // Field descriptor #71 I + public static final int GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING = 34973; + + // Field descriptor #71 I + public static final int GL_WEIGHT_ARRAY_BUFFER_BINDING = 34974; + + // Field descriptor #71 I + public static final int GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 34975; + + // Field descriptor #71 I + public static final int GL_STREAM_DRAW = 35040; + + // Field descriptor #71 I + public static final int GL_STREAM_READ = 35041; + + // Field descriptor #71 I + public static final int GL_STREAM_COPY = 35042; + + // Field descriptor #71 I + public static final int GL_STATIC_DRAW = 35044; + + // Field descriptor #71 I + public static final int GL_STATIC_READ = 35045; + + // Field descriptor #71 I + public static final int GL_STATIC_COPY = 35046; + + // Field descriptor #71 I + public static final int GL_DYNAMIC_DRAW = 35048; + + // Field descriptor #71 I + public static final int GL_DYNAMIC_READ = 35049; + + // Field descriptor #71 I + public static final int GL_DYNAMIC_COPY = 35050; + + // Field descriptor #71 I + public static final int GL_READ_ONLY = 35000; + + // Field descriptor #71 I + public static final int GL_WRITE_ONLY = 35001; + + // Field descriptor #71 I + public static final int GL_READ_WRITE = 35002; + + // Field descriptor #71 I + public static final int GL_BUFFER_SIZE = 34660; + + // Field descriptor #71 I + public static final int GL_BUFFER_USAGE = 34661; + + // Field descriptor #71 I + public static final int GL_BUFFER_ACCESS = 35003; + + // Field descriptor #71 I + public static final int GL_BUFFER_MAPPED = 35004; + + // Field descriptor #71 I + public static final int GL_BUFFER_MAP_POINTER = 35005; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_SRC = 33872; + + // Field descriptor #71 I + public static final int GL_FOG_COORD = 33873; + + // Field descriptor #71 I + public static final int GL_CURRENT_FOG_COORD = 33875; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_ARRAY_TYPE = 33876; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_ARRAY_STRIDE = 33877; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_ARRAY_POINTER = 33878; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_ARRAY = 33879; + + // Field descriptor #71 I + public static final int GL_FOG_COORD_ARRAY_BUFFER_BINDING = 34973; + + // Field descriptor #71 I + public static final int GL_SRC0_RGB = 34176; + + // Field descriptor #71 I + public static final int GL_SRC1_RGB = 34177; + + // Field descriptor #71 I + public static final int GL_SRC2_RGB = 34178; + + // Field descriptor #71 I + public static final int GL_SRC0_ALPHA = 34184; + + // Field descriptor #71 I + public static final int GL_SRC1_ALPHA = 34185; + + // Field descriptor #71 I + public static final int GL_SRC2_ALPHA = 34186; + + // Field descriptor #71 I + public static final int GL_SAMPLES_PASSED = 35092; + + // Field descriptor #71 I + public static final int GL_QUERY_COUNTER_BITS = 34916; + + // Field descriptor #71 I + public static final int GL_CURRENT_QUERY = 34917; + + // Field descriptor #71 I + public static final int GL_QUERY_RESULT = 34918; + + // Field descriptor #71 I + public static final int GL_QUERY_RESULT_AVAILABLE = 34919; + + // Field descriptor #194 I + public static final int GL_SHADING_LANGUAGE_VERSION = 35724; + + // Field descriptor #194 I + public static final int GL_CURRENT_PROGRAM = 35725; + + // Field descriptor #194 I + public static final int GL_SHADER_TYPE = 35663; + + // Field descriptor #194 I + public static final int GL_DELETE_STATUS = 35712; + + // Field descriptor #194 I + public static final int GL_COMPILE_STATUS = 35713; + + // Field descriptor #194 I + public static final int GL_LINK_STATUS = 35714; + + // Field descriptor #194 I + public static final int GL_VALIDATE_STATUS = 35715; + + // Field descriptor #194 I + public static final int GL_INFO_LOG_LENGTH = 35716; + + // Field descriptor #194 I + public static final int GL_ATTACHED_SHADERS = 35717; + + // Field descriptor #194 I + public static final int GL_ACTIVE_UNIFORMS = 35718; + + // Field descriptor #194 I + public static final int GL_ACTIVE_UNIFORM_MAX_LENGTH = 35719; + + // Field descriptor #194 I + public static final int GL_ACTIVE_ATTRIBUTES = 35721; + + // Field descriptor #194 I + public static final int GL_ACTIVE_ATTRIBUTE_MAX_LENGTH = 35722; + + // Field descriptor #194 I + public static final int GL_SHADER_SOURCE_LENGTH = 35720; + + // Field descriptor #194 I + public static final int GL_SHADER_OBJECT = 35656; + + // Field descriptor #194 I + public static final int GL_FLOAT_VEC2 = 35664; + + // Field descriptor #194 I + public static final int GL_FLOAT_VEC3 = 35665; + + // Field descriptor #194 I + public static final int GL_FLOAT_VEC4 = 35666; + + // Field descriptor #194 I + public static final int GL_INT_VEC2 = 35667; + + // Field descriptor #194 I + public static final int GL_INT_VEC3 = 35668; + + // Field descriptor #194 I + public static final int GL_INT_VEC4 = 35669; + + // Field descriptor #194 I + public static final int GL_BOOL = 35670; + + // Field descriptor #194 I + public static final int GL_BOOL_VEC2 = 35671; + + // Field descriptor #194 I + public static final int GL_BOOL_VEC3 = 35672; + + // Field descriptor #194 I + public static final int GL_BOOL_VEC4 = 35673; + + // Field descriptor #194 I + public static final int GL_FLOAT_MAT2 = 35674; + + // Field descriptor #194 I + public static final int GL_FLOAT_MAT3 = 35675; + + // Field descriptor #194 I + public static final int GL_FLOAT_MAT4 = 35676; + + // Field descriptor #194 I + public static final int GL_SAMPLER_1D = 35677; + + // Field descriptor #194 I + public static final int GL_SAMPLER_2D = 35678; + + // Field descriptor #194 I + public static final int GL_SAMPLER_3D = 35679; + + // Field descriptor #194 I + public static final int GL_SAMPLER_CUBE = 35680; + + // Field descriptor #194 I + public static final int GL_SAMPLER_1D_SHADOW = 35681; + + // Field descriptor #194 I + public static final int GL_SAMPLER_2D_SHADOW = 35682; + + // Field descriptor #194 I + public static final int GL_VERTEX_SHADER = 35633; + + // Field descriptor #194 I + public static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS = 35658; + + // Field descriptor #194 I + public static final int GL_MAX_VARYING_FLOATS = 35659; + + // Field descriptor #194 I + public static final int GL_MAX_VERTEX_ATTRIBS = 34921; + + // Field descriptor #194 I + public static final int GL_MAX_TEXTURE_IMAGE_UNITS = 34930; + + // Field descriptor #194 I + public static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 35660; + + // Field descriptor #194 I + public static final int GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = 35661; + + // Field descriptor #194 I + public static final int GL_MAX_TEXTURE_COORDS = 34929; + + // Field descriptor #194 I + public static final int GL_VERTEX_PROGRAM_POINT_SIZE = 34370; + + // Field descriptor #194 I + public static final int GL_VERTEX_PROGRAM_TWO_SIDE = 34371; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_ENABLED = 34338; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_SIZE = 34339; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_STRIDE = 34340; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_TYPE = 34341; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_NORMALIZED = 34922; + + // Field descriptor #194 I + public static final int GL_CURRENT_VERTEX_ATTRIB = 34342; + + // Field descriptor #194 I + public static final int GL_VERTEX_ATTRIB_ARRAY_POINTER = 34373; + + // Field descriptor #194 I + public static final int GL_FRAGMENT_SHADER = 35632; + + // Field descriptor #194 I + public static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 35657; + + // Field descriptor #194 I + public static final int GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 35723; + + // Field descriptor #194 I + public static final int GL_MAX_DRAW_BUFFERS = 34852; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER0 = 34853; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER1 = 34854; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER2 = 34855; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER3 = 34856; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER4 = 34857; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER5 = 34858; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER6 = 34859; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER7 = 34860; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER8 = 34861; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER9 = 34862; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER10 = 34863; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER11 = 34864; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER12 = 34865; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER13 = 34866; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER14 = 34867; + + // Field descriptor #194 I + public static final int GL_DRAW_BUFFER15 = 34868; + + // Field descriptor #194 I + public static final int GL_POINT_SPRITE = 34913; + + // Field descriptor #194 I + public static final int GL_COORD_REPLACE = 34914; + + // Field descriptor #194 I + public static final int GL_POINT_SPRITE_COORD_ORIGIN = 36000; + + // Field descriptor #194 I + public static final int GL_LOWER_LEFT = 36001; + + // Field descriptor #194 I + public static final int GL_UPPER_LEFT = 36002; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_FUNC = 34816; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_FAIL = 34817; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_PASS_DEPTH_FAIL = 34818; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_PASS_DEPTH_PASS = 34819; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_REF = 36003; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_VALUE_MASK = 36004; + + // Field descriptor #194 I + public static final int GL_STENCIL_BACK_WRITEMASK = 36005; + + // Field descriptor #194 I + public static final int GL_BLEND_EQUATION_RGB = 32777; + + // Field descriptor #194 I + public static final int GL_BLEND_EQUATION_ALPHA = 34877; + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/main/MinecraftMain.java b/src/main/java/net/PeytonPlayz585/main/MinecraftMain.java new file mode 100644 index 0000000..48d1f0b --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/main/MinecraftMain.java @@ -0,0 +1,140 @@ +package net.PeytonPlayz585.main; + +import java.io.IOException; + +import org.lwjgl.opengl.GL11; +import org.teavm.interop.Async; +import org.teavm.interop.AsyncCallback; +import org.teavm.jso.JSBody; +import org.teavm.jso.JSObject; +import org.teavm.jso.ajax.ReadyStateChangeHandler; +import org.teavm.jso.ajax.XMLHttpRequest; +import org.teavm.jso.browser.Window; +import org.teavm.jso.canvas.CanvasRenderingContext2D; +import org.teavm.jso.dom.html.HTMLCanvasElement; +import org.teavm.jso.dom.html.HTMLDocument; +import org.teavm.jso.dom.html.HTMLElement; +import org.teavm.jso.typedarrays.ArrayBuffer; +import org.teavm.jso.typedarrays.Uint8Array; +import org.teavm.jso.webgl.WebGLRenderingContext; + +import net.PeytonPlayz585.minecraft.MinecraftClient; +import net.PeytonPlayz585.teavm.WebGL2RenderingContext; + +public class MinecraftMain { + + public static Window win = null; + public static HTMLCanvasElement canvas = null; + public static HTMLElement rootElement = null; + public static WebGL2RenderingContext webgl = null; + public static HTMLElement parent = null; + public static HTMLDocument doc = null; + public static CanvasRenderingContext2D canvasContext = null; + public static HTMLCanvasElement canvasBack = null; + public static HTMLCanvasElement imageLoadCanvas = null; + public static CanvasRenderingContext2D imageLoadContext = null; + private static byte[] loadedPackage = null; + + public static int width = 0; + public static int height = 0; + + public static void main(String args[]) { + String[] element = getClassicConfig(); + initContext(rootElement = Window.current().getDocument().getElementById(element[0]), element[1]); + } + + public final static void initContext(HTMLElement rootElement, String assetsURI) { + parent = rootElement; + String s = parent.getAttribute("style"); + parent.setAttribute("style", (s == null ? "" : s)+"overflow-x:hidden;overflow-y:hidden;"); + win = Window.current(); + doc = win.getDocument(); + canvas = (HTMLCanvasElement)doc.createElement("canvas"); + width = rootElement.getClientWidth(); + height = rootElement.getClientHeight(); + canvas.setWidth(width); + canvas.setHeight(height); + canvasContext = (CanvasRenderingContext2D) canvas.getContext("2d"); + canvas.setAttribute("id", "minecraftClassicBrowser"); + rootElement.appendChild(canvas); + canvasBack = (HTMLCanvasElement)doc.createElement("canvas"); + canvasBack.setWidth(width); + canvasBack.setHeight(height); + webgl = (WebGL2RenderingContext) canvasBack.getContext("webgl2"); + if(webgl == null) { + throw new RuntimeException("WebGL 2.0 is not supported in your browser, please get a new one!"); + } + setCurrentContext(webgl); + GL11.initWebGL(webgl); + + webgl.getExtension("EXT_texture_filter_anisotropic"); + + downloadAssetPack(assetsURI); + + try { + MinecraftClient.install(loadedPackage); + } catch (IOException e) { + e.printStackTrace(); + } + + //Start Game Function + + } + + @Async + public static native String downloadAssetPack(String assetPackageURI); + + private static void downloadAssetPack(String assetPackageURI, final AsyncCallback cb) { + final XMLHttpRequest request = XMLHttpRequest.create(); + request.setResponseType("arraybuffer"); + request.open("GET", assetPackageURI, true); + request.setOnReadyStateChange(new ReadyStateChangeHandler() { + @Override + public void stateChanged() { + if(request.getReadyState() == XMLHttpRequest.DONE) { + Uint8Array bl = Uint8Array.create((ArrayBuffer)request.getResponse()); + loadedPackage = new byte[bl.getByteLength()]; + for(int i = 0; i < loadedPackage.length; ++i) { + loadedPackage[i] = (byte) bl.get(i); + } + cb.complete("yee"); + } + } + }); + request.send(); + } + + public static final int getCanvasWidth() { + int w = parent.getClientWidth(); + if(w != width) { + canvas.setWidth(w); + canvasBack.setWidth(w); + width = w; + } + return w; + } + public static final int getCanvasHeight() { + int h = parent.getClientHeight(); + if(h != height) { + canvas.setHeight(h); + canvasBack.setHeight(h); + height = h; + } + return h; + } + + @JSBody(params = { "obj" }, script = "window.currentContext = obj;") + private static native int setCurrentContext(JSObject obj); + + @JSBody(params = { }, script = "return window.classicConfig;") + public static native String[] getClassicConfig(); + + @JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();") + public static native int commitContext(JSObject obj); + + @JSBody(params = { "url" }, script = "URL.revokeObjectURL(url);") + public static native void freeDataURL(String url); + + @JSBody(params = { "buf", "mime" }, script = "return URL.createObjectURL(new Blob([buf], {type: mime}));") + public static native String getDataURL(ArrayBuffer buf, String mime); +} diff --git a/src/main/java/net/PeytonPlayz585/minecraft/Base64.java b/src/main/java/net/PeytonPlayz585/minecraft/Base64.java new file mode 100644 index 0000000..ab0b0ec --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/Base64.java @@ -0,0 +1,857 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.PeytonPlayz585.minecraft; + +import java.math.BigInteger; +import java.nio.charset.Charset; + +/** + * Provides Base64 encoding and decoding as defined by + * RFC 2045. + * + *

+ * This class implements section 6.8. Base64 + * Content-Transfer-Encoding from RFC 2045 Multipurpose Internet + * Mail Extensions (MIME) Part One: Format of Internet Message Bodies by + * Freed and Borenstein. + *

+ *

+ * The class can be parameterized in the following manner with various + * constructors: + *

+ *
    + *
  • URL-safe mode: Default off.
  • + *
  • Line length: Default 76. Line length that aren't multiples of 4 will + * still essentially end up being multiples of 4 in the encoded data. + *
  • Line separator: Default is CRLF ("\r\n")
  • + *
+ *

+ * The URL-safe parameter is only applied to encode operations. Decoding + * seamlessly handles both modes. + *

+ *

+ * Since this class operates directly on byte streams, and not character + * streams, it is hard-coded to only encode/decode character encodings which are + * compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, + * etc). + *

+ *

+ * This class is thread-safe. + *

+ * + * @see RFC 2045 + * @since 1.0 + */ +public class Base64 extends BaseNCodec { + + /** + * BASE32 characters are 6 bits in length. They are formed by taking a block of + * 3 octets to form a 24-bit string, which is converted into 4 BASE64 + * characters. + */ + private static final int BITS_PER_ENCODED_BYTE = 6; + private static final int BYTES_PER_UNENCODED_BLOCK = 3; + private static final int BYTES_PER_ENCODED_BLOCK = 4; + + /** + * This array is a lookup table that translates 6-bit positive integer index + * values into their "Base64 Alphabet" equivalents as specified in Table 1 of + * RFC 2045. + * + * Thanks to "commons" project in ws.apache.org for this code. + * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ + */ + private static final byte[] STANDARD_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; + + /** + * This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed + * to - and _ to make the encoded Base64 results more URL-SAFE. This table is + * only used when the Base64's mode is set to URL-SAFE. + */ + private static final byte[] URL_SAFE_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' }; + + /** + * This array is a lookup table that translates Unicode characters drawn from + * the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit + * positive integer equivalents. Characters that are not in the Base64 alphabet + * but fall within the bounds of the array are translated to -1. + * + * Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This + * means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The + * encoder, on the other hand, needs to know ahead of time what to emit). + * + * Thanks to "commons" project in ws.apache.org for this code. + * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ + */ + private static final byte[] DECODE_TABLE = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, // 20-2f + - / + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 30-3f 0-9 + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40-4f A-O + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, // 50-5f P-Z _ + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60-6f a-o + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 // 70-7a p-z + }; + + /** + * Base64 uses 6-bit fields. + */ + /** Mask used to extract 6 bits, used when encoding */ + private static final int MASK_6BITS = 0x3f; + /** Mask used to extract 4 bits, used when decoding final trailing character. */ + private static final int MASK_4BITS = 0xf; + /** Mask used to extract 2 bits, used when decoding final trailing character. */ + private static final int MASK_2BITS = 0x3; + + // The static final fields above are used for the original static byte[] methods + // on Base64. + // The private member fields below are used with the new streaming approach, + // which requires + // some state be preserved between calls of encode() and decode(). + + /** + * Decodes Base64 data into octets. + *

+ * Note: this method seamlessly handles data encoded in URL-safe or + * normal mode. + *

+ * + * @param base64Data Byte array containing Base64 data + * @return Array containing decoded data. + */ + public static byte[] decodeBase64(final byte[] base64Data) { + return new Base64().decode(base64Data); + } + + /** + * Decodes a Base64 String into octets. + *

+ * Note: this method seamlessly handles data encoded in URL-safe or + * normal mode. + *

+ * + * @param base64String String containing Base64 data + * @return Array containing decoded data. + * @since 1.4 + */ + public static byte[] decodeBase64(final String base64String) { + return new Base64().decode(base64String); + } + + // Implementation of integer encoding used for crypto + /** + * Decodes a byte64-encoded integer according to crypto standards such as W3C's + * XML-Signature. + * + * @param pArray a byte array containing base64 character data + * @return A BigInteger + * @since 1.4 + */ + public static BigInteger decodeInteger(final byte[] pArray) { + return new BigInteger(1, decodeBase64(pArray)); + } + + /** + * Encodes binary data using the base64 algorithm but does not chunk the output. + * + * @param binaryData binary data to encode + * @return byte[] containing Base64 characters in their UTF-8 representation. + */ + public static byte[] encodeBase64(final byte[] binaryData) { + return encodeBase64(binaryData, false); + } + + /** + * Encodes binary data using the base64 algorithm, optionally chunking the + * output into 76 character blocks. + * + * @param binaryData Array containing binary data to encode. + * @param isChunked if {@code true} this encoder will chunk the base64 output + * into 76 character blocks + * @return Base64-encoded data. + * @throws IllegalArgumentException Thrown when the input array needs an output + * array bigger than {@link Integer#MAX_VALUE} + */ + public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked) { + return encodeBase64(binaryData, isChunked, false); + } + + /** + * Encodes binary data using the base64 algorithm, optionally chunking the + * output into 76 character blocks. + * + * @param binaryData Array containing binary data to encode. + * @param isChunked if {@code true} this encoder will chunk the base64 output + * into 76 character blocks + * @param urlSafe if {@code true} this encoder will emit - and _ instead of + * the usual + and / characters. Note: no padding is added + * when encoding using the URL-safe alphabet. + * @return Base64-encoded data. + * @throws IllegalArgumentException Thrown when the input array needs an output + * array bigger than {@link Integer#MAX_VALUE} + * @since 1.4 + */ + public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe) { + return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE); + } + + /** + * Encodes binary data using the base64 algorithm, optionally chunking the + * output into 76 character blocks. + * + * @param binaryData Array containing binary data to encode. + * @param isChunked if {@code true} this encoder will chunk the base64 + * output into 76 character blocks + * @param urlSafe if {@code true} this encoder will emit - and _ instead + * of the usual + and / characters. Note: no padding is + * added when encoding using the URL-safe alphabet. + * @param maxResultSize The maximum result size to accept. + * @return Base64-encoded data. + * @throws IllegalArgumentException Thrown when the input array needs an output + * array bigger than maxResultSize + * @since 1.4 + */ + public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, + final int maxResultSize) { + if (binaryData == null || binaryData.length == 0) { + return binaryData; + } + + // Create this so can use the super-class method + // Also ensures that the same roundings are performed by the ctor and the code + final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe); + final long len = b64.getEncodedLength(binaryData); + if (len > maxResultSize) { + throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + + ") than the specified maximum size of " + maxResultSize); + } + + return b64.encode(binaryData); + } + + /** + * Encodes binary data using the base64 algorithm and chunks the encoded output + * into 76 character blocks + * + * @param binaryData binary data to encode + * @return Base64 characters chunked in 76 character blocks + */ + public static byte[] encodeBase64Chunked(final byte[] binaryData) { + return encodeBase64(binaryData, true); + } + + /** + * Encodes binary data using the base64 algorithm but does not chunk the output. + * + * NOTE: We changed the behavior of this method from multi-line chunking + * (commons-codec-1.4) to single-line non-chunking (commons-codec-1.5). + * + * @param binaryData binary data to encode + * @return String containing Base64 characters. + * @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not). + */ + public static String encodeBase64String(final byte[] binaryData) { + return new String(encodeBase64(binaryData, false), Charset.forName("UTF-8")); + } + + /** + * Encodes binary data using a URL-safe variation of the base64 algorithm but + * does not chunk the output. The url-safe variation emits - and _ instead of + + * and / characters. Note: no padding is added. + * + * @param binaryData binary data to encode + * @return byte[] containing Base64 characters in their UTF-8 representation. + * @since 1.4 + */ + public static byte[] encodeBase64URLSafe(final byte[] binaryData) { + return encodeBase64(binaryData, false, true); + } + + /** + * Encodes binary data using a URL-safe variation of the base64 algorithm but + * does not chunk the output. The url-safe variation emits - and _ instead of + + * and / characters. Note: no padding is added. + * + * @param binaryData binary data to encode + * @return String containing Base64 characters + * @since 1.4 + */ + public static String encodeBase64URLSafeString(final byte[] binaryData) { + return new String(encodeBase64(binaryData, false, true), Charset.forName("UTF-8")); + } + + /** + * Encodes to a byte64-encoded integer according to crypto standards such as + * W3C's XML-Signature. + * + * @param bigInteger a BigInteger + * @return A byte array containing base64 character data + * @throws NullPointerException if null is passed in + * @since 1.4 + */ + public static byte[] encodeInteger(final BigInteger bigInteger) { + return encodeBase64(toIntegerBytes(bigInteger), false); + } + + /** + * Tests a given byte array to see if it contains only valid characters within + * the Base64 alphabet. Currently the method treats whitespace as valid. + * + * @param arrayOctet byte array to test + * @return {@code true} if all bytes are valid characters in the Base64 alphabet + * or if the byte array is empty; {@code false}, otherwise + * @deprecated 1.5 Use {@link #isBase64(byte[])}, will be removed in 2.0. + */ + @Deprecated + public static boolean isArrayByteBase64(final byte[] arrayOctet) { + return isBase64(arrayOctet); + } + + /** + * Returns whether or not the {@code octet} is in the base 64 alphabet. + * + * @param octet The value to test + * @return {@code true} if the value is defined in the the base 64 alphabet, + * {@code false} otherwise. + * @since 1.4 + */ + public static boolean isBase64(final byte octet) { + return octet == PAD_DEFAULT || (octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1); + } + + /** + * Tests a given byte array to see if it contains only valid characters within + * the Base64 alphabet. Currently the method treats whitespace as valid. + * + * @param arrayOctet byte array to test + * @return {@code true} if all bytes are valid characters in the Base64 alphabet + * or if the byte array is empty; {@code false}, otherwise + * @since 1.5 + */ + public static boolean isBase64(final byte[] arrayOctet) { + for (int i = 0; i < arrayOctet.length; i++) { + if (!isBase64(arrayOctet[i]) && !isWhiteSpace(arrayOctet[i])) { + return false; + } + } + return true; + } + + /** + * Tests a given String to see if it contains only valid characters within the + * Base64 alphabet. Currently the method treats whitespace as valid. + * + * @param base64 String to test + * @return {@code true} if all characters in the String are valid characters in + * the Base64 alphabet or if the String is empty; {@code false}, + * otherwise + * @since 1.5 + */ + public static boolean isBase64(final String base64) { + return isBase64(base64.getBytes(Charset.forName("UTF-8"))); + } + + /** + * Returns a byte-array representation of a {@code BigInteger} without sign bit. + * + * @param bigInt {@code BigInteger} to be converted + * @return a byte array representation of the BigInteger parameter + */ + static byte[] toIntegerBytes(final BigInteger bigInt) { + int bitlen = bigInt.bitLength(); + // round bitlen + bitlen = ((bitlen + 7) >> 3) << 3; + final byte[] bigBytes = bigInt.toByteArray(); + + if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) { + return bigBytes; + } + // set up params for copying everything but sign bit + int startSrc = 0; + int len = bigBytes.length; + + // if bigInt is exactly byte-aligned, just skip signbit in copy + if ((bigInt.bitLength() % 8) == 0) { + startSrc = 1; + len--; + } + final int startDst = bitlen / 8 - len; // to pad w/ nulls as per spec + final byte[] resizedBytes = new byte[bitlen / 8]; + System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len); + return resizedBytes; + } + + /** + * Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE + * above remains static because it is able to decode both STANDARD and URL_SAFE + * streams, but the encodeTable must be a member variable so we can switch + * between the two modes. + */ + private final byte[] encodeTable; + + // Only one decode table currently; keep for consistency with Base32 code + private final byte[] decodeTable = DECODE_TABLE; + + /** + * Line separator for encoding. Not used when decoding. Only used if lineLength + * > 0. + */ + private final byte[] lineSeparator; + + /** + * Convenience variable to help us determine when our buffer is going to run out + * of room and needs resizing. {@code decodeSize = 3 + lineSeparator.length;} + */ + private final int decodeSize; + + /** + * Convenience variable to help us determine when our buffer is going to run out + * of room and needs resizing. {@code encodeSize = 4 + lineSeparator.length;} + */ + private final int encodeSize; + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in + * URL-unsafe mode. + *

+ * When encoding the line length is 0 (no chunking), and the encoding table is + * STANDARD_ENCODE_TABLE. + *

+ * + *

+ * When decoding all variants are supported. + *

+ */ + public Base64() { + this(0); + } + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in the + * given URL-safe mode. + *

+ * When encoding the line length is 76, the line separator is CRLF, and the + * encoding table is STANDARD_ENCODE_TABLE. + *

+ * + *

+ * When decoding all variants are supported. + *

+ * + * @param urlSafe if {@code true}, URL-safe encoding is used. In most cases this + * should be set to {@code false}. + * @since 1.4 + */ + public Base64(final boolean urlSafe) { + this(MIME_CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); + } + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in + * URL-unsafe mode. + *

+ * When encoding the line length is given in the constructor, the line separator + * is CRLF, and the encoding table is STANDARD_ENCODE_TABLE. + *

+ *

+ * Line lengths that aren't multiples of 4 will still essentially end up being + * multiples of 4 in the encoded data. + *

+ *

+ * When decoding all variants are supported. + *

+ * + * @param lineLength Each line of encoded data will be at most of the given + * length (rounded down to nearest multiple of 4). If + * lineLength <= 0, then the output will not be divided + * into lines (chunks). Ignored when decoding. + * @since 1.4 + */ + public Base64(final int lineLength) { + this(lineLength, CHUNK_SEPARATOR); + } + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in + * URL-unsafe mode. + *

+ * When encoding the line length and line separator are given in the + * constructor, and the encoding table is STANDARD_ENCODE_TABLE. + *

+ *

+ * Line lengths that aren't multiples of 4 will still essentially end up being + * multiples of 4 in the encoded data. + *

+ *

+ * When decoding all variants are supported. + *

+ * + * @param lineLength Each line of encoded data will be at most of the given + * length (rounded down to nearest multiple of 4). If + * lineLength <= 0, then the output will not be divided + * into lines (chunks). Ignored when decoding. + * @param lineSeparator Each line of encoded data will end with this sequence of + * bytes. + * @throws IllegalArgumentException Thrown when the provided lineSeparator + * included some base64 characters. + * @since 1.4 + */ + public Base64(final int lineLength, final byte[] lineSeparator) { + this(lineLength, lineSeparator, false); + } + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in + * URL-unsafe mode. + *

+ * When encoding the line length and line separator are given in the + * constructor, and the encoding table is STANDARD_ENCODE_TABLE. + *

+ *

+ * Line lengths that aren't multiples of 4 will still essentially end up being + * multiples of 4 in the encoded data. + *

+ *

+ * When decoding all variants are supported. + *

+ * + * @param lineLength Each line of encoded data will be at most of the given + * length (rounded down to nearest multiple of 4). If + * lineLength <= 0, then the output will not be divided + * into lines (chunks). Ignored when decoding. + * @param lineSeparator Each line of encoded data will end with this sequence of + * bytes. + * @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_' + * respectively. urlSafe is only applied to encode + * operations. Decoding seamlessly handles both modes. + * Note: no padding is added when using the URL-safe + * alphabet. + * @throws IllegalArgumentException Thrown when the {@code lineSeparator} + * contains Base64 characters. + * @since 1.4 + */ + public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe) { + this(lineLength, lineSeparator, urlSafe, CodecPolicy.LENIANT); + } + + /** + * Creates a Base64 codec used for decoding (all modes) and encoding in + * URL-unsafe mode. + *

+ * When encoding the line length and line separator are given in the + * constructor, and the encoding table is STANDARD_ENCODE_TABLE. + *

+ *

+ * Line lengths that aren't multiples of 4 will still essentially end up being + * multiples of 4 in the encoded data. + *

+ *

+ * When decoding all variants are supported. + *

+ * + * @param lineLength Each line of encoded data will be at most of the given + * length (rounded down to nearest multiple of 4). If + * lineLength <= 0, then the output will not be divided + * into lines (chunks). Ignored when decoding. + * @param lineSeparator Each line of encoded data will end with this sequence + * of bytes. + * @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_' + * respectively. urlSafe is only applied to encode + * operations. Decoding seamlessly handles both modes. + * Note: no padding is added when using the URL-safe + * alphabet. + * @param decodingPolicy The decoding policy. + * @throws IllegalArgumentException Thrown when the {@code lineSeparator} + * contains Base64 characters. + * @since 1.15 + */ + public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe, + final CodecPolicy decodingPolicy) { + super(BYTES_PER_UNENCODED_BLOCK, BYTES_PER_ENCODED_BLOCK, lineLength, + lineSeparator == null ? 0 : lineSeparator.length, PAD_DEFAULT, decodingPolicy); + // TODO could be simplified if there is no requirement to reject invalid line + // sep when length <=0 + // @see test case Base64Test.testConstructors() + if (lineSeparator != null) { + if (containsAlphabetOrPad(lineSeparator)) { + final String sep = new String(lineSeparator, Charset.forName("UTF-8")); + throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]"); + } + if (lineLength > 0) { // null line-sep forces no chunking rather than throwing IAE + this.encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length; + this.lineSeparator = new byte[lineSeparator.length]; + System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length); + } else { + this.encodeSize = BYTES_PER_ENCODED_BLOCK; + this.lineSeparator = null; + } + } else { + this.encodeSize = BYTES_PER_ENCODED_BLOCK; + this.lineSeparator = null; + } + this.decodeSize = this.encodeSize - 1; + this.encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE; + } + + // Implementation of the Encoder Interface + + /** + *

+ * Decodes all of the provided data, starting at inPos, for inAvail bytes. + * Should be called at least twice: once with the data to decode, and once with + * inAvail set to "-1" to alert decoder that EOF has been reached. The "-1" call + * is not necessary when decoding, but it doesn't hurt, either. + *

+ *

+ * Ignores all non-base64 characters. This is how chunked (e.g. 76 character) + * data is handled, since CR and LF are silently ignored, but has implications + * for other bytes, too. This method subscribes to the garbage-in, garbage-out + * philosophy: it will not check the provided data for validity. + *

+ *

+ * Thanks to "commons" project in ws.apache.org for the bitwise operations, and + * general approach. + * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ + *

+ * + * @param in byte[] array of ascii data to base64 decode. + * @param inPos Position to start reading data from. + * @param inAvail Amount of bytes available from input for decoding. + * @param context the context to be used + */ + @Override + void decode(final byte[] in, int inPos, final int inAvail, final Context context) { + if (context.eof) { + return; + } + if (inAvail < 0) { + context.eof = true; + } + for (int i = 0; i < inAvail; i++) { + final byte[] buffer = ensureBufferSize(decodeSize, context); + final byte b = in[inPos++]; + if (b == pad) { + // We're done. + context.eof = true; + break; + } + if (b >= 0 && b < DECODE_TABLE.length) { + final int result = DECODE_TABLE[b]; + if (result >= 0) { + context.modulus = (context.modulus + 1) % BYTES_PER_ENCODED_BLOCK; + context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result; + if (context.modulus == 0) { + buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS); + buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS); + buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS); + } + } + } + } + + // Two forms of EOF as far as base64 decoder is concerned: actual + // EOF (-1) and first time '=' character is encountered in stream. + // This approach makes the '=' padding characters completely optional. + if (context.eof && context.modulus != 0) { + final byte[] buffer = ensureBufferSize(decodeSize, context); + + // We have some spare bits remaining + // Output all whole multiples of 8 bits and ignore the rest + switch (context.modulus) { +// case 0 : // impossible, as excluded above + case 1: // 6 bits - either ignore entirely, or raise an exception + validateTrailingCharacter(); + break; + case 2: // 12 bits = 8 + 4 + validateCharacter(MASK_4BITS, context); + context.ibitWorkArea = context.ibitWorkArea >> 4; // dump the extra 4 bits + buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS); + break; + case 3: // 18 bits = 8 + 8 + 2 + validateCharacter(MASK_2BITS, context); + context.ibitWorkArea = context.ibitWorkArea >> 2; // dump 2 bits + buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS); + buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS); + break; + default: + throw new IllegalStateException("Impossible modulus " + context.modulus); + } + } + } + + /** + *

+ * Encodes all of the provided data, starting at inPos, for inAvail bytes. Must + * be called at least twice: once with the data to encode, and once with inAvail + * set to "-1" to alert encoder that EOF has been reached, to flush last + * remaining bytes (if not multiple of 3). + *

+ *

+ * Note: no padding is added when encoding using the URL-safe alphabet. + *

+ *

+ * Thanks to "commons" project in ws.apache.org for the bitwise operations, and + * general approach. + * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ + *

+ * + * @param in byte[] array of binary data to base64 encode. + * @param inPos Position to start reading data from. + * @param inAvail Amount of bytes available from input for encoding. + * @param context the context to be used + */ + @Override + void encode(final byte[] in, int inPos, final int inAvail, final Context context) { + if (context.eof) { + return; + } + // inAvail < 0 is how we're informed of EOF in the underlying data we're + // encoding. + if (inAvail < 0) { + context.eof = true; + if (0 == context.modulus && lineLength == 0) { + return; // no leftovers to process and not using chunking + } + final byte[] buffer = ensureBufferSize(encodeSize, context); + final int savedPos = context.pos; + switch (context.modulus) { // 0-2 + case 0: // nothing to do here + break; + case 1: // 8 bits = 6 + 2 + // top 6 bits: + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS]; + // remaining 2: + buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS]; + // URL-SAFE skips the padding to further reduce size. + if (encodeTable == STANDARD_ENCODE_TABLE) { + buffer[context.pos++] = pad; + buffer[context.pos++] = pad; + } + break; + + case 2: // 16 bits = 6 + 6 + 4 + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 10) & MASK_6BITS]; + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 4) & MASK_6BITS]; + buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 2) & MASK_6BITS]; + // URL-SAFE skips the padding to further reduce size. + if (encodeTable == STANDARD_ENCODE_TABLE) { + buffer[context.pos++] = pad; + } + break; + default: + throw new IllegalStateException("Impossible modulus " + context.modulus); + } + context.currentLinePos += context.pos - savedPos; // keep track of current line position + // if currentPos == 0 we are at the start of a line, so don't add CRLF + if (lineLength > 0 && context.currentLinePos > 0) { + System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length); + context.pos += lineSeparator.length; + } + } else { + for (int i = 0; i < inAvail; i++) { + final byte[] buffer = ensureBufferSize(encodeSize, context); + context.modulus = (context.modulus + 1) % BYTES_PER_UNENCODED_BLOCK; + int b = in[inPos++]; + if (b < 0) { + b += 256; + } + context.ibitWorkArea = (context.ibitWorkArea << 8) + b; // BITS_PER_BYTE + if (0 == context.modulus) { // 3 bytes = 24 bits = 4 * 6 bits to extract + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 18) & MASK_6BITS]; + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 12) & MASK_6BITS]; + buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 6) & MASK_6BITS]; + buffer[context.pos++] = encodeTable[context.ibitWorkArea & MASK_6BITS]; + context.currentLinePos += BYTES_PER_ENCODED_BLOCK; + if (lineLength > 0 && lineLength <= context.currentLinePos) { + System.arraycopy(lineSeparator, 0, buffer, context.pos, lineSeparator.length); + context.pos += lineSeparator.length; + context.currentLinePos = 0; + } + } + } + } + } + + /** + * Returns whether or not the {@code octet} is in the Base64 alphabet. + * + * @param octet The value to test + * @return {@code true} if the value is defined in the the Base64 alphabet + * {@code false} otherwise. + */ + @Override + protected boolean isInAlphabet(final byte octet) { + return octet >= 0 && octet < decodeTable.length && decodeTable[octet] != -1; + } + + /** + * Returns our current encode mode. True if we're URL-SAFE, false otherwise. + * + * @return true if we're in URL-SAFE mode, false otherwise. + * @since 1.4 + */ + public boolean isUrlSafe() { + return this.encodeTable == URL_SAFE_ENCODE_TABLE; + } + + /** + * Validates whether decoding the final trailing character is possible in the + * context of the set of possible base 64 values. + * + *

+ * The character is valid if the lower bits within the provided mask are zero. + * This is used to test the final trailing base-64 digit is zero in the bits + * that will be discarded. + * + * @param emptyBitsMask The mask of the lower bits that should be empty + * @param context the context to be used + * + * @throws IllegalArgumentException if the bits being checked contain any + * non-zero value + */ + private void validateCharacter(final int emptyBitsMask, final Context context) { + if (isStrictDecoding() && (context.ibitWorkArea & emptyBitsMask) != 0) { + throw new IllegalArgumentException( + "Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. " + + "Expected the discarded bits from the character to be zero."); + } + } + + /** + * Validates whether decoding allows an entire final trailing character that + * cannot be used for a complete byte. + * + * @throws IllegalArgumentException if strict decoding is enabled + */ + private void validateTrailingCharacter() { + if (isStrictDecoding()) { + throw new IllegalArgumentException( + "Strict decoding: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible encoding. " + + "Decoding requires at least two trailing 6-bit characters to create bytes."); + } + } + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/BaseNCodec.java b/src/main/java/net/PeytonPlayz585/minecraft/BaseNCodec.java new file mode 100644 index 0000000..8fbeceb --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/BaseNCodec.java @@ -0,0 +1,692 @@ +package net.PeytonPlayz585.minecraft; + +import java.nio.charset.Charset; +import java.util.Arrays; + +public abstract class BaseNCodec { + + static enum CodecPolicy { + STRICT, LENIANT; + } + + /** + * Holds thread context so classes can be thread-safe. + * + * This class is not itself thread-safe; each thread must allocate its own copy. + * + * @since 1.7 + */ + static class Context { + + /** + * Place holder for the bytes we're dealing with for our based logic. Bitwise + * operations store and extract the encoding or decoding from this variable. + */ + int ibitWorkArea; + + /** + * Place holder for the bytes we're dealing with for our based logic. Bitwise + * operations store and extract the encoding or decoding from this variable. + */ + long lbitWorkArea; + + /** + * Buffer for streaming. + */ + byte[] buffer; + + /** + * Position where next character should be written in the buffer. + */ + int pos; + + /** + * Position where next character should be read from the buffer. + */ + int readPos; + + /** + * Boolean flag to indicate the EOF has been reached. Once EOF has been reached, + * this object becomes useless, and must be thrown away. + */ + boolean eof; + + /** + * Variable tracks how many characters have been written to the current line. + * Only used when encoding. We use it to make sure each encoded line never goes + * beyond lineLength (if lineLength > 0). + */ + int currentLinePos; + + /** + * Writes to the buffer only occur after every 3/5 reads when encoding, and + * every 4/8 reads when decoding. This variable helps track that. + */ + int modulus; + + Context() { + } + + /** + * Returns a String useful for debugging (especially within a debugger.) + * + * @return a String useful for debugging. + */ + @SuppressWarnings("boxing") // OK to ignore boxing here + @Override + public String toString() { + return String.format( + "%s[buffer=%s, currentLinePos=%s, eof=%s, ibitWorkArea=%s, lbitWorkArea=%s, " + + "modulus=%s, pos=%s, readPos=%s]", + this.getClass().getSimpleName(), Arrays.toString(buffer), currentLinePos, eof, ibitWorkArea, + lbitWorkArea, modulus, pos, readPos); + } + } + + /** + * EOF + * + * @since 1.7 + */ + static final int EOF = -1; + + /** + * MIME chunk size per RFC 2045 section 6.8. + * + *

+ * The {@value} character limit does not count the trailing CRLF, but counts all + * other characters, including any equal signs. + *

+ * + * @see RFC 2045 section 6.8 + */ + public static final int MIME_CHUNK_SIZE = 76; + + /** + * PEM chunk size per RFC 1421 section 4.3.2.4. + * + *

+ * The {@value} character limit does not count the trailing CRLF, but counts all + * other characters, including any equal signs. + *

+ * + * @see RFC 1421 section + * 4.3.2.4 + */ + public static final int PEM_CHUNK_SIZE = 64; + + private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2; + + /** + * Defines the default buffer size - currently {@value} - must be large enough + * for at least one encoded block+separator + */ + private static final int DEFAULT_BUFFER_SIZE = 8192; + + /** + * The maximum size buffer to allocate. + * + *

+ * This is set to the same size used in the JDK {@code java.util.ArrayList}: + *

+ *
Some VMs reserve some header words in an array. Attempts to + * allocate larger arrays may result in OutOfMemoryError: Requested array size + * exceeds VM limit.
+ */ + private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; + + /** Mask used to extract 8 bits, used in decoding bytes */ + protected static final int MASK_8BITS = 0xff; + + /** + * Byte used to pad output. + */ + protected static final byte PAD_DEFAULT = '='; // Allow static access to default + + /** + * Chunk separator per RFC 2045 section 2.1. + * + * @see RFC 2045 section 2.1 + */ + static final byte[] CHUNK_SEPARATOR = { '\r', '\n' }; + + /** + * Compares two {@code int} values numerically treating the values as unsigned. + * Taken from JDK 1.8. + * + *

+ * TODO: Replace with JDK 1.8 Integer::compareUnsigned(int, int). + *

+ * + * @param x the first {@code int} to compare + * @param y the second {@code int} to compare + * @return the value {@code 0} if {@code x == y}; a value less than {@code 0} if + * {@code x < y} as unsigned values; and a value greater than {@code 0} + * if {@code x > y} as unsigned values + */ + private static int compareUnsigned(final int xx, final int yy) { + int x = xx + Integer.MIN_VALUE; + int y = yy + Integer.MIN_VALUE; + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + + /** + * Create a positive capacity at least as large the minimum required capacity. + * If the minimum capacity is negative then this throws an OutOfMemoryError as + * no array can be allocated. + * + * @param minCapacity the minimum capacity + * @return the capacity + * @throws OutOfMemoryError if the {@code minCapacity} is negative + */ + private static int createPositiveCapacity(final int minCapacity) { + if (minCapacity < 0) { + // overflow + throw new OutOfMemoryError("Unable to allocate array size: " + (minCapacity & 0xffffffffL)); + } + // This is called when we require buffer expansion to a very big array. + // Use the conservative maximum buffer size if possible, otherwise the biggest + // required. + // + // Note: In this situation JDK 1.8 java.util.ArrayList returns + // Integer.MAX_VALUE. + // This excludes some VMs that can exceed MAX_BUFFER_SIZE but not allocate a + // full + // Integer.MAX_VALUE length array. + // The result is that we may have to allocate an array of this size more than + // once if + // the capacity must be expanded again. + return (minCapacity > MAX_BUFFER_SIZE) ? minCapacity : MAX_BUFFER_SIZE; + } + + /** + * Gets a copy of the chunk separator per RFC 2045 section 2.1. + * + * @return the chunk separator + * @see RFC 2045 section 2.1 + * @since 1.15 + */ + public static byte[] getChunkSeparator() { + return CHUNK_SEPARATOR.clone(); + } + + /** + * Checks if a byte value is whitespace or not. Whitespace is taken to mean: + * space, tab, CR, LF + * + * @param byteToCheck the byte to check + * @return true if byte is whitespace, false otherwise + */ + protected static boolean isWhiteSpace(final byte byteToCheck) { + switch (byteToCheck) { + case ' ': + case '\n': + case '\r': + case '\t': + return true; + default: + return false; + } + } + + /** + * Increases our buffer by the {@link #DEFAULT_BUFFER_RESIZE_FACTOR}. + * + * @param context the context to be used + * @param minCapacity the minimum required capacity + * @return the resized byte[] buffer + * @throws OutOfMemoryError if the {@code minCapacity} is negative + */ + private static byte[] resizeBuffer(final Context context, final int minCapacity) { + // Overflow-conscious code treats the min and new capacity as unsigned. + final int oldCapacity = context.buffer.length; + int newCapacity = oldCapacity * DEFAULT_BUFFER_RESIZE_FACTOR; + if (compareUnsigned(newCapacity, minCapacity) < 0) { + newCapacity = minCapacity; + } + if (compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) { + newCapacity = createPositiveCapacity(minCapacity); + } + + final byte[] b = new byte[newCapacity]; + System.arraycopy(context.buffer, 0, b, 0, context.buffer.length); + context.buffer = b; + return b; + } + + /** + * @deprecated Use {@link #pad}. Will be removed in 2.0. + */ + @Deprecated + protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later + + protected final byte pad; // instance variable just in case it needs to vary later + + /** + * Number of bytes in each full block of unencoded data, e.g. 4 for Base64 and 5 + * for Base32 + */ + private final int unencodedBlockSize; + + /** + * Number of bytes in each full block of encoded data, e.g. 3 for Base64 and 8 + * for Base32 + */ + private final int encodedBlockSize; + + /** + * Chunksize for encoding. Not used when decoding. A value of zero or less + * implies no chunking of the encoded data. Rounded down to nearest multiple of + * encodedBlockSize. + */ + protected final int lineLength; + + /** + * Size of chunk separator. Not used unless {@link #lineLength} > 0. + */ + private final int chunkSeparatorLength; + + /** + * Defines the decoding behavior when the input bytes contain leftover trailing + * bits that cannot be created by a valid encoding. These can be bits that are + * unused from the final character or entire characters. The default mode is + * lenient decoding. Set this to {@code true} to enable strict decoding. + *
    + *
  • Lenient: Any trailing bits are composed into 8-bit bytes where possible. + * The remainder are discarded. + *
  • Strict: The decoding will raise an {@link IllegalArgumentException} if + * trailing bits are not part of a valid encoding. Any unused bits from the + * final character must be zero. Impossible counts of entire final characters + * are not allowed. + *
+ * + *

+ * When strict decoding is enabled it is expected that the decoded bytes will be + * re-encoded to a byte array that matches the original, i.e. no changes occur + * on the final character. This requires that the input bytes use the same + * padding and alphabet as the encoder. + */ + private final CodecPolicy decodingPolicy; + + /** + * Note {@code lineLength} is rounded down to the nearest multiple of the + * encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is + * disabled. + * + * @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3) + * @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4) + * @param lineLength if > 0, use chunking with a length + * {@code lineLength} + * @param chunkSeparatorLength the chunk separator length, if relevant + */ + protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, + final int chunkSeparatorLength) { + this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, PAD_DEFAULT); + } + + /** + * Note {@code lineLength} is rounded down to the nearest multiple of the + * encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is + * disabled. + * + * @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3) + * @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4) + * @param lineLength if > 0, use chunking with a length + * {@code lineLength} + * @param chunkSeparatorLength the chunk separator length, if relevant + * @param pad byte used as padding byte. + */ + protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, + final int chunkSeparatorLength, final byte pad) { + this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, pad, CodecPolicy.LENIANT); + } + + /** + * Note {@code lineLength} is rounded down to the nearest multiple of the + * encoded block size. If {@code chunkSeparatorLength} is zero, then chunking is + * disabled. + * + * @param unencodedBlockSize the size of an unencoded block (e.g. Base64 = 3) + * @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4) + * @param lineLength if > 0, use chunking with a length + * {@code lineLength} + * @param chunkSeparatorLength the chunk separator length, if relevant + * @param pad byte used as padding byte. + * @param decodingPolicy Decoding policy. + * @since 1.15 + */ + protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, + final int chunkSeparatorLength, final byte pad, final CodecPolicy decodingPolicy) { + this.unencodedBlockSize = unencodedBlockSize; + this.encodedBlockSize = encodedBlockSize; + final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0; + this.lineLength = useChunking ? (lineLength / encodedBlockSize) * encodedBlockSize : 0; + this.chunkSeparatorLength = chunkSeparatorLength; + this.pad = pad; + this.decodingPolicy = decodingPolicy; + } + + /** + * Returns the amount of buffered data available for reading. + * + * @param context the context to be used + * @return The amount of buffered data available for reading. + */ + int available(final Context context) { // package protected for access from I/O streams + return context.buffer != null ? context.pos - context.readPos : 0; + } + + /** + * Tests a given byte array to see if it contains any characters within the + * alphabet or PAD. + * + * Intended for use in checking line-ending arrays + * + * @param arrayOctet byte array to test + * @return {@code true} if any byte is a valid character in the alphabet or PAD; + * {@code false} otherwise + */ + protected boolean containsAlphabetOrPad(final byte[] arrayOctet) { + if (arrayOctet == null) { + return false; + } + for (final byte element : arrayOctet) { + if (pad == element || isInAlphabet(element)) { + return true; + } + } + return false; + } + + /** + * Decodes a byte[] containing characters in the Base-N alphabet. + * + * @param pArray A byte array containing Base-N character data + * @return a byte array containing binary data + */ + public byte[] decode(final byte[] pArray) { + if (pArray == null || pArray.length == 0) { + return pArray; + } + final Context context = new Context(); + decode(pArray, 0, pArray.length, context); + decode(pArray, 0, EOF, context); // Notify decoder of EOF. + final byte[] result = new byte[context.pos]; + readResults(result, 0, result.length, context); + return result; + } + + // package protected for access from I/O streams + abstract void decode(byte[] pArray, int i, int length, Context context); + + /** + * Decodes an Object using the Base-N algorithm. This method is provided in + * order to satisfy the requirements of the Decoder interface, and will throw a + * DecoderException if the supplied object is not of type byte[] or String. + * + * @param obj Object to decode + * @return An object (of type byte[]) containing the binary data which + * corresponds to the byte[] or String supplied. + * @throws DecoderException if the parameter supplied is not of type byte[] + */ + public Object decode(final Object obj) { + if (obj instanceof byte[]) { + return decode((byte[]) obj); + } else if (obj instanceof String) { + return decode((String) obj); + } else { + return null; + } + } + + /** + * Decodes a String containing characters in the Base-N alphabet. + * + * @param pArray A String containing Base-N character data + * @return a byte array containing binary data + */ + public byte[] decode(final String pArray) { + return decode(pArray.getBytes(Charset.forName("UTF-8"))); + } + + /** + * Encodes a byte[] containing binary data, into a byte[] containing characters + * in the alphabet. + * + * @param pArray a byte array containing binary data + * @return A byte array containing only the base N alphabetic character data + */ + public byte[] encode(final byte[] pArray) { + if (pArray == null || pArray.length == 0) { + return pArray; + } + return encode(pArray, 0, pArray.length); + } + + /** + * Encodes a byte[] containing binary data, into a byte[] containing characters + * in the alphabet. + * + * @param pArray a byte array containing binary data + * @param offset initial offset of the subarray. + * @param length length of the subarray. + * @return A byte array containing only the base N alphabetic character data + * @since 1.11 + */ + public byte[] encode(final byte[] pArray, final int offset, final int length) { + if (pArray == null || pArray.length == 0) { + return pArray; + } + final Context context = new Context(); + encode(pArray, offset, length, context); + encode(pArray, offset, EOF, context); // Notify encoder of EOF. + final byte[] buf = new byte[context.pos - context.readPos]; + readResults(buf, 0, buf.length, context); + return buf; + } + + // package protected for access from I/O streams + abstract void encode(byte[] pArray, int i, int length, Context context); + + /** + * Encodes an Object using the Base-N algorithm. This method is provided in + * order to satisfy the requirements of the Encoder interface, and will throw an + * EncoderException if the supplied object is not of type byte[]. + * + * @param obj Object to encode + * @return An object (of type byte[]) containing the Base-N encoded data which + * corresponds to the byte[] supplied. + * @throws EncoderException if the parameter supplied is not of type byte[] + */ + public Object encode(final Object obj) { + return encode((byte[]) obj); + } + + /** + * Encodes a byte[] containing binary data, into a String containing characters + * in the appropriate alphabet. Uses UTF8 encoding. + * + * @param pArray a byte array containing binary data + * @return String containing only character data in the appropriate alphabet. + * @since 1.5 This is a duplicate of {@link #encodeToString(byte[])}; it was + * merged during refactoring. + */ + public String encodeAsString(final byte[] pArray) { + return new String(encode(pArray), Charset.forName("UTF-8")); + } + + /** + * Encodes a byte[] containing binary data, into a String containing characters + * in the Base-N alphabet. Uses UTF8 encoding. + * + * @param pArray a byte array containing binary data + * @return A String containing only Base-N character data + */ + public String encodeToString(final byte[] pArray) { + return new String(encode(pArray), Charset.forName("UTF-8")); + } + + /** + * Ensure that the buffer has room for {@code size} bytes + * + * @param size minimum spare space required + * @param context the context to be used + * @return the buffer + */ + protected byte[] ensureBufferSize(final int size, final Context context) { + if (context.buffer == null) { + context.buffer = new byte[Math.max(size, getDefaultBufferSize())]; + context.pos = 0; + context.readPos = 0; + + // Overflow-conscious: + // x + y > z == x + y - z > 0 + } else if (context.pos + size - context.buffer.length > 0) { + return resizeBuffer(context, context.pos + size); + } + return context.buffer; + } + + /** + * Returns the decoding behavior policy. + * + *

+ * The default is lenient. If the decoding policy is strict, then decoding will + * raise an {@link IllegalArgumentException} if trailing bits are not part of a + * valid encoding. Decoding will compose trailing bits into 8-bit bytes and + * discard the remainder. + *

+ * + * @return true if using strict decoding + * @since 1.15 + */ + public CodecPolicy getCodecPolicy() { + return decodingPolicy; + } + + /** + * Get the default buffer size. Can be overridden. + * + * @return the default buffer size. + */ + protected int getDefaultBufferSize() { + return DEFAULT_BUFFER_SIZE; + } + + /** + * Calculates the amount of space needed to encode the supplied array. + * + * @param pArray byte[] array which will later be encoded + * + * @return amount of space needed to encoded the supplied array. Returns a long + * since a max-len array will require > Integer.MAX_VALUE + */ + public long getEncodedLength(final byte[] pArray) { + // Calculate non-chunked size - rounded up to allow for padding + // cast to long is needed to avoid possibility of overflow + long len = ((pArray.length + unencodedBlockSize - 1) / unencodedBlockSize) * (long) encodedBlockSize; + if (lineLength > 0) { // We're using chunking + // Round up to nearest multiple + len += ((len + lineLength - 1) / lineLength) * chunkSeparatorLength; + } + return len; + } + + /** + * Returns true if this object has buffered data for reading. + * + * @param context the context to be used + * @return true if there is data still available for reading. + */ + boolean hasData(final Context context) { // package protected for access from I/O streams + return context.buffer != null; + } + + /** + * Returns whether or not the {@code octet} is in the current alphabet. Does not + * allow whitespace or pad. + * + * @param value The value to test + * + * @return {@code true} if the value is defined in the current alphabet, + * {@code false} otherwise. + */ + protected abstract boolean isInAlphabet(byte value); + + /** + * Tests a given byte array to see if it contains only valid characters within + * the alphabet. The method optionally treats whitespace and pad as valid. + * + * @param arrayOctet byte array to test + * @param allowWSPad if {@code true}, then whitespace and PAD are also allowed + * + * @return {@code true} if all bytes are valid characters in the alphabet or if + * the byte array is empty; {@code false}, otherwise + */ + public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) { + for (final byte octet : arrayOctet) { + if (!isInAlphabet(octet) && (!allowWSPad || (octet != pad) && !isWhiteSpace(octet))) { + return false; + } + } + return true; + } + + /** + * Tests a given String to see if it contains only valid characters within the + * alphabet. The method treats whitespace and PAD as valid. + * + * @param basen String to test + * @return {@code true} if all characters in the String are valid characters in + * the alphabet or if the String is empty; {@code false}, otherwise + * @see #isInAlphabet(byte[], boolean) + */ + public boolean isInAlphabet(final String basen) { + return isInAlphabet(basen.getBytes(Charset.forName("UTF-8")), true); + } + + /** + * Returns true if decoding behavior is strict. Decoding will raise an + * {@link IllegalArgumentException} if trailing bits are not part of a valid + * encoding. + * + *

+ * The default is false for lenient decoding. Decoding will compose trailing + * bits into 8-bit bytes and discard the remainder. + *

+ * + * @return true if using strict decoding + * @since 1.15 + */ + public boolean isStrictDecoding() { + return decodingPolicy == CodecPolicy.STRICT; + } + + /** + * Extracts buffered data into the provided byte[] array, starting at position + * bPos, up to a maximum of bAvail bytes. Returns how many bytes were actually + * extracted. + *

+ * Package protected for access from I/O streams. + * + * @param b byte[] array to extract the buffered data into. + * @param bPos position in byte[] array to start extraction at. + * @param bAvail amount of bytes we're allowed to extract. We may extract fewer + * (if fewer are available). + * @param context the context to be used + * @return The number of bytes successfully extracted into the provided byte[] + * array. + */ + int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { + if (context.buffer != null) { + final int len = Math.min(available(context), bAvail); + System.arraycopy(context.buffer, context.readPos, b, bPos, len); + context.readPos += len; + if (context.readPos >= context.pos) { + context.buffer = null; // so hasData() will return false, and this method can return -1 + } + return len; + } + return context.eof ? EOF : 0; + } +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/GLAllocation.java b/src/main/java/net/PeytonPlayz585/minecraft/GLAllocation.java new file mode 100644 index 0000000..a8975da --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/GLAllocation.java @@ -0,0 +1,58 @@ +package net.PeytonPlayz585.minecraft; + +import java.nio.*; +import java.util.ArrayList; +import java.util.List; + +public class GLAllocation { + + public GLAllocation() { + } + + public static synchronized int generateDisplayLists(int i) { + int j = GlStateManager.glGenLists(i); + displayLists.add(Integer.valueOf(j)); + displayLists.add(Integer.valueOf(i)); + return j; + } + + public static synchronized void generateTextureNames(IntBuffer intbuffer) { + + for (int i = intbuffer.position(); i < intbuffer.limit(); i++) { + int tx = GlStateManager.glGenTextures(); + intbuffer.put(i, tx); + textureNames.add(Integer.valueOf(tx)); + } + + } + + public static synchronized void deleteTexturesAndDisplayLists() { + for (int i = 0; i < displayLists.size(); i += 2) { + GlStateManager.glDeleteLists(((Integer) displayLists.get(i)).intValue(), + ((Integer) displayLists.get(i + 1)).intValue()); + } + + for (int j = 0; j < textureNames.size(); j++) { + GlStateManager.glDeleteTextures(((Integer) textureNames.get(j)).intValue()); + } + + displayLists.clear(); + textureNames.clear(); + } + + public static ByteBuffer createDirectByteBuffer(int par0) { + return ByteBuffer.wrap(new byte[par0]).order(ByteOrder.nativeOrder()); + } + + public static IntBuffer createDirectIntBuffer(int par0) { + return IntBuffer.wrap(new int[par0]); + } + + public static FloatBuffer createDirectFloatBuffer(int par0) { + return FloatBuffer.wrap(new float[par0]); + } + + private static List displayLists = new ArrayList(); + private static List textureNames = new ArrayList(); + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/GeneralDigest.java b/src/main/java/net/PeytonPlayz585/minecraft/GeneralDigest.java new file mode 100644 index 0000000..c7054e1 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/GeneralDigest.java @@ -0,0 +1,108 @@ +package net.PeytonPlayz585.minecraft; + +/** + * base implementation of MD4 family style digest as outlined in "Handbook of + * Applied Cryptography", pages 344 - 347. + */ +public abstract class GeneralDigest { + private byte[] xBuf; + private int xBufOff; + + private long byteCount; + + /** + * Standard constructor + */ + protected GeneralDigest() { + xBuf = new byte[4]; + xBufOff = 0; + } + + /** + * Copy constructor. We are using copy constructors in place of the + * Object.clone() interface as this interface is not supported by J2ME. + */ + protected GeneralDigest(GeneralDigest t) { + xBuf = new byte[t.xBuf.length]; + System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length); + + xBufOff = t.xBufOff; + byteCount = t.byteCount; + } + + public void update(byte in) { + xBuf[xBufOff++] = in; + + if (xBufOff == xBuf.length) { + processWord(xBuf, 0); + xBufOff = 0; + } + + byteCount++; + } + + public void update(byte[] in, int inOff, int len) { + // + // fill the current word + // + while ((xBufOff != 0) && (len > 0)) { + update(in[inOff]); + + inOff++; + len--; + } + + // + // process whole words. + // + while (len > xBuf.length) { + processWord(in, inOff); + + inOff += xBuf.length; + len -= xBuf.length; + byteCount += xBuf.length; + } + + // + // load in the remainder. + // + while (len > 0) { + update(in[inOff]); + + inOff++; + len--; + } + } + + public void finish() { + long bitLength = (byteCount << 3); + + // + // add the pad bytes. + // + update((byte) 128); + + while (xBufOff != 0) { + update((byte) 0); + } + + processLength(bitLength); + + processBlock(); + } + + public void reset() { + byteCount = 0; + + xBufOff = 0; + for (int i = 0; i < xBuf.length; i++) { + xBuf[i] = 0; + } + } + + protected abstract void processWord(byte[] in, int inOff); + + protected abstract void processLength(long bitLength); + + protected abstract void processBlock(); +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/GlStateManager.java b/src/main/java/net/PeytonPlayz585/minecraft/GlStateManager.java new file mode 100644 index 0000000..9edb2bb --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/GlStateManager.java @@ -0,0 +1,1220 @@ +package net.PeytonPlayz585.minecraft; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.HashMap; + +import net.PeytonPlayz585.glemu.FixedFunctionShader; +import net.PeytonPlayz585.glemu.GLObjectMap; +import net.PeytonPlayz585.glemu.vector.*; +import net.PeytonPlayz585.lwjgl.LWJGL; +import net.PeytonPlayz585.lwjgl.RealOpenGLEnums; + +public class GlStateManager extends LWJGL { + + public static final int GL_ZERO = RealOpenGLEnums.GL_ZERO; + public static final int GL_ONE = RealOpenGLEnums.GL_ONE; + public static final int GL_TEXTURE_2D = RealOpenGLEnums.GL_TEXTURE_2D; + public static final int GL_SMOOTH = RealOpenGLEnums.GL_SMOOTH; + public static final int GL_DEPTH_TEST = RealOpenGLEnums.GL_DEPTH_TEST; + public static final int GL_LEQUAL = RealOpenGLEnums.GL_LEQUAL; + public static final int GL_ALPHA_TEST = RealOpenGLEnums.GL_ALPHA_TEST; + public static final int GL_GREATER = RealOpenGLEnums.GL_GREATER; + public static final int GL_BACK = RealOpenGLEnums.GL_BACK; + public static final int GL_PROJECTION = RealOpenGLEnums.GL_PROJECTION; + public static final int GL_MODELVIEW = RealOpenGLEnums.GL_MODELVIEW; + public static final int GL_COLOR_BUFFER_BIT = RealOpenGLEnums.GL_COLOR_BUFFER_BIT; + public static final int GL_DEPTH_BUFFER_BIT = RealOpenGLEnums.GL_DEPTH_BUFFER_BIT; + public static final int GL_LIGHTING = RealOpenGLEnums.GL_LIGHTING; + public static final int GL_FOG = RealOpenGLEnums.GL_FOG; + public static final int GL_COLOR_MATERIAL = RealOpenGLEnums.GL_COLOR_MATERIAL; + public static final int GL_BLEND = RealOpenGLEnums.GL_BLEND; + public static final int GL_RGBA = RealOpenGLEnums.GL_RGBA; + public static final int GL_UNSIGNED_BYTE = RealOpenGLEnums.GL_UNSIGNED_BYTE; + public static final int GL_TEXTURE_WIDTH = RealOpenGLEnums.GL_TEXTURE_WIDTH; + public static final int GL_LIGHT0 = RealOpenGLEnums.GL_LIGHT0; + public static final int GL_LIGHT1 = RealOpenGLEnums.GL_LIGHT1; + public static final int GL_POSITION = RealOpenGLEnums.GL_POSITION; + public static final int GL_DIFFUSE = RealOpenGLEnums.GL_DIFFUSE; + public static final int GL_SPECULAR = RealOpenGLEnums.GL_SPECULAR; + public static final int GL_AMBIENT = RealOpenGLEnums.GL_AMBIENT; + public static final int GL_FLAT = RealOpenGLEnums.GL_FLAT; + public static final int GL_LIGHT_MODEL_AMBIENT = RealOpenGLEnums.GL_LIGHT_MODEL_AMBIENT; + public static final int GL_FRONT_AND_BACK = RealOpenGLEnums.GL_FRONT_AND_BACK; + public static final int GL_AMBIENT_AND_DIFFUSE = RealOpenGLEnums.GL_AMBIENT_AND_DIFFUSE; + public static final int GL_MODELVIEW_MATRIX = RealOpenGLEnums.GL_MODELVIEW_MATRIX; + public static final int GL_PROJECTION_MATRIX = RealOpenGLEnums.GL_PROJECTION_MATRIX; + public static final int GL_VIEWPORT = RealOpenGLEnums.GL_VIEWPORT; + public static final int GL_RESCALE_NORMAL = RealOpenGLEnums.GL_RESCALE_NORMAL; + public static final int GL_SRC_ALPHA = RealOpenGLEnums.GL_SRC_ALPHA; + public static final int GL_ONE_MINUS_SRC_ALPHA = RealOpenGLEnums.GL_ONE_MINUS_SRC_ALPHA; + public static final int GL_ONE_MINUS_DST_COLOR = RealOpenGLEnums.GL_ONE_MINUS_DST_COLOR; + public static final int GL_ONE_MINUS_SRC_COLOR = RealOpenGLEnums.GL_ONE_MINUS_SRC_COLOR; + public static final int GL_CULL_FACE = RealOpenGLEnums.GL_CULL_FACE; + public static final int GL_TEXTURE_MIN_FILTER = RealOpenGLEnums.GL_TEXTURE_MIN_FILTER; + public static final int GL_TEXTURE_MAG_FILTER = RealOpenGLEnums.GL_TEXTURE_MAG_FILTER; + public static final int GL_LINEAR = RealOpenGLEnums.GL_LINEAR; + public static final int GL_COLOR_LOGIC_OP = RealOpenGLEnums.GL_COLOR_LOGIC_OP; + public static final int GL_OR_REVERSE = RealOpenGLEnums.GL_OR_REVERSE; + public static final int GL_EQUAL = RealOpenGLEnums.GL_EQUAL; + public static final int GL_SRC_COLOR = RealOpenGLEnums.GL_SRC_COLOR; + public static final int GL_TEXTURE = RealOpenGLEnums.GL_TEXTURE; + public static final int GL_FRONT = RealOpenGLEnums.GL_FRONT; + public static final int GL_COMPILE = RealOpenGLEnums.GL_COMPILE; + public static final int GL_S = RealOpenGLEnums.GL_S; + public static final int GL_T = RealOpenGLEnums.GL_T; + public static final int GL_R = RealOpenGLEnums.GL_R; + public static final int GL_Q = RealOpenGLEnums.GL_Q; + public static final int GL_TEXTURE_GEN_S = RealOpenGLEnums.GL_TEXTURE_GEN_S; + public static final int GL_TEXTURE_GEN_T = RealOpenGLEnums.GL_TEXTURE_GEN_T; + public static final int GL_TEXTURE_GEN_R = RealOpenGLEnums.GL_TEXTURE_GEN_R; + public static final int GL_TEXTURE_GEN_Q = RealOpenGLEnums.GL_TEXTURE_GEN_Q; + public static final int GL_TEXTURE_GEN_MODE = RealOpenGLEnums.GL_TEXTURE_GEN_MODE; + public static final int GL_OBJECT_PLANE = RealOpenGLEnums.GL_OBJECT_PLANE; + public static final int GL_EYE_PLANE = RealOpenGLEnums.GL_EYE_PLANE; + public static final int GL_OBJECT_LINEAR = RealOpenGLEnums.GL_OBJECT_LINEAR; + public static final int GL_EYE_LINEAR = RealOpenGLEnums.GL_EYE_LINEAR; + public static final int GL_NEAREST = RealOpenGLEnums.GL_NEAREST; + public static final int GL_CLAMP = RealOpenGLEnums.GL_CLAMP_TO_EDGE; + public static final int GL_TEXTURE_WRAP_S = RealOpenGLEnums.GL_TEXTURE_WRAP_S; + public static final int GL_TEXTURE_WRAP_T = RealOpenGLEnums.GL_TEXTURE_WRAP_T; + public static final int GL_REPEAT = RealOpenGLEnums.GL_REPEAT; + public static final int GL_BGRA = RealOpenGLEnums.GL_BGRA; + public static final int GL_UNSIGNED_INT_8_8_8_8_REV = RealOpenGLEnums.GL_UNSIGNED_INT_8_8_8_8_REV; + public static final int GL_DST_COLOR = RealOpenGLEnums.GL_DST_COLOR; + public static final int GL_CONSTANT_COLOR = RealOpenGLEnums.GL_CONSTANT_COLOR; + public static final int GL_ONE_MINUS_CONSTANT_COLOR = RealOpenGLEnums.GL_ONE_MINUS_CONSTANT_COLOR; + public static final int GL_CONSTANT_ALPHA = RealOpenGLEnums.GL_CONSTANT_ALPHA; + public static final int GL_ONE_MINUS_CONSTANT_ALPHA = RealOpenGLEnums.GL_ONE_MINUS_CONSTANT_ALPHA; + public static final int GL_POLYGON_OFFSET_FILL = RealOpenGLEnums.GL_POLYGON_OFFSET_FILL; + public static final int GL_NORMALIZE = RealOpenGLEnums.GL_NORMALIZE; + public static final int GL_DST_ALPHA = RealOpenGLEnums.GL_DST_ALPHA; + public static final int GL_FLOAT = RealOpenGLEnums.GL_FLOAT; + public static final int GL_TEXTURE_COORD_ARRAY = RealOpenGLEnums.GL_TEXTURE_COORD_ARRAY; + public static final int GL_SHORT = RealOpenGLEnums.GL_SHORT; + public static final int GL_COLOR_ARRAY = RealOpenGLEnums.GL_COLOR_ARRAY; + public static final int GL_VERTEX_ARRAY = RealOpenGLEnums.GL_VERTEX_ARRAY; + public static final int GL_TRIANGLES = RealOpenGLEnums.GL_TRIANGLES; + public static final int GL_NORMAL_ARRAY = RealOpenGLEnums.GL_NORMAL_ARRAY; + public static final int GL_TEXTURE_3D = RealOpenGLEnums.GL_TEXTURE_3D; + public static final int GL_FOG_MODE = RealOpenGLEnums.GL_FOG_MODE; + public static final int GL_EXP = RealOpenGLEnums.GL_EXP; + public static final int GL_FOG_DENSITY = RealOpenGLEnums.GL_FOG_DENSITY; + public static final int GL_FOG_START = RealOpenGLEnums.GL_FOG_START; + public static final int GL_FOG_END = RealOpenGLEnums.GL_FOG_END; + public static final int GL_FOG_COLOR = RealOpenGLEnums.GL_FOG_COLOR; + public static final int GL_TRIANGLE_STRIP = RealOpenGLEnums.GL_TRIANGLE_STRIP; + public static final int GL_PACK_ALIGNMENT = RealOpenGLEnums.GL_PACK_ALIGNMENT; + public static final int GL_UNPACK_ALIGNMENT = RealOpenGLEnums.GL_UNPACK_ALIGNMENT; + public static final int GL_QUADS = RealOpenGLEnums.GL_QUADS; + public static final int GL_TEXTURE0 = RealOpenGLEnums.GL_TEXTURE0; + public static final int GL_TEXTURE1 = RealOpenGLEnums.GL_TEXTURE1; + public static final int GL_TEXTURE2 = RealOpenGLEnums.GL_TEXTURE2; + public static final int GL_TEXTURE3 = RealOpenGLEnums.GL_TEXTURE3; + public static final int GL_INVALID_ENUM = RealOpenGLEnums.GL_INVALID_ENUM; + public static final int GL_INVALID_VALUE = RealOpenGLEnums.GL_INVALID_VALUE; + public static final int GL_INVALID_OPERATION = RealOpenGLEnums.GL_INVALID_OPERATION; + public static final int GL_OUT_OF_MEMORY = RealOpenGLEnums.GL_OUT_OF_MEMORY; + public static final int GL_CONTEXT_LOST_WEBGL = -100; + public static final int GL_TRIANGLE_FAN = RealOpenGLEnums.GL_TRIANGLE_FAN; + public static final int GL_LINE_STRIP = RealOpenGLEnums.GL_LINE_STRIP; + public static final int EAG_SWAP_RB = -101; + public static final int GL_LINES = RealOpenGLEnums.GL_LINES; + public static final int GL_NEAREST_MIPMAP_LINEAR = RealOpenGLEnums.GL_NEAREST_MIPMAP_LINEAR; + public static final int GL_TEXTURE_MAX_ANISOTROPY = -103; + public static final int GL_TEXTURE_MAX_LEVEL = RealOpenGLEnums.GL_TEXTURE_MAX_LEVEL; + public static final int GL_LINEAR_MIPMAP_LINEAR = RealOpenGLEnums.GL_LINEAR_MIPMAP_LINEAR; + public static final int GL_LINEAR_MIPMAP_NEAREST = RealOpenGLEnums.GL_LINEAR_MIPMAP_NEAREST; + public static final int GL_NEAREST_MIPMAP_NEAREST = RealOpenGLEnums.GL_NEAREST_MIPMAP_NEAREST; + + private static final GLObjectMap texObjects = new GLObjectMap(256); + + private static boolean enableTexture2D = false; + private static boolean enableLighting = false; + private static boolean enableAlphaTest = false; + private static float alphaThresh = 0.1f; + + private static boolean isCompilingDisplayList = false; + private static DisplayList compilingDisplayList = null; + + private static boolean enableColorArray = false; + private static boolean enableNormalArray = false; + private static boolean enableTex0Array = false; + + private static float colorR = 1.0f; + private static float colorG = 1.0f; + private static float colorB = 1.0f; + private static float colorA = 1.0f; + + private static float normalX = 1.0f; + private static float normalY = 0.0f; + private static float normalZ = 0.0f; + + private static float tex0X = 0; + private static float tex0Y = 0; + + private static boolean enableColorMaterial = false; + + private static float fogColorR = 1.0f; + private static float fogColorG = 1.0f; + private static float fogColorB = 1.0f; + private static float fogColorA = 1.0f; + private static int fogMode = 1; + private static boolean fogEnabled = false; + private static boolean fogPremultiply = false; + private static float fogStart = 1.0f; + private static float fogEnd = 1.0f; + private static float fogDensity = 1.0f; + + private static int bytesUploaded = 0; + private static int vertexDrawn = 0; + private static int triangleDrawn = 0; + + private static int matrixMode = GL_MODELVIEW; + + static Matrix4f[] matModelV = new Matrix4f[32]; + static int matModelPointer = 0; + + static Matrix4f[] matProjV = new Matrix4f[6]; + static int matProjPointer = 0; + + static Matrix4f[] matTexV = new Matrix4f[16]; + static int matTexPointer = 0; + + static { + for (int i = 0; i < matModelV.length; ++i) { + matModelV[i] = new Matrix4f(); + } + for (int i = 0; i < matProjV.length; ++i) { + matProjV[i] = new Matrix4f(); + } + for (int i = 0; i < matTexV.length; ++i) { + matTexV[i] = new Matrix4f(); + } + } + + public static void glClearStack() { + matModelV[0].load(matModelV[matModelPointer]); + matModelPointer = 0; + matProjV[0].load(matProjV[matProjPointer]); + matProjPointer = 0; + matTexV[0].load(matTexV[matTexPointer]); + matTexPointer = 0; + } + + private static BufferGL quadsToTrianglesBuffer = null; + private static BufferArrayGL currentArray = null; + + private static class DisplayList { + private final int id; + private BufferArrayGL glarray; + private BufferGL glbuffer; + private int shaderMode; + private int listLength; + + private DisplayList(int id) { + this.id = id; + this.glarray = null; + this.glbuffer = null; + this.shaderMode = -1; + this.listLength = 0; + } + } + + private static final HashMap displayLists = new HashMap(); + private static final HashMap displayListsInitialized = new HashMap(); + + public static final int getDisplayListCount() { + return displayListsInitialized.size(); + } + + public static final void glEnable(int p1) { + switch (p1) { + case GL_DEPTH_TEST: + _wglEnable(_wGL_DEPTH_TEST); + break; + case GL_CULL_FACE: + _wglEnable(_wGL_CULL_FACE); + break; + case GL_BLEND: + _wglEnable(_wGL_BLEND); + break; + case GL_RESCALE_NORMAL: + break; + case GL_TEXTURE_2D: + enableTexture2D = true; + break; + case GL_LIGHTING: + enableLighting = true; + break; + case GL_ALPHA_TEST: + enableAlphaTest = true; + break; + case GL_FOG: + fogEnabled = true; + break; + case GL_COLOR_MATERIAL: + enableColorMaterial = true; + break; + case GL_POLYGON_OFFSET_FILL: + _wglEnable(_wGL_POLYGON_OFFSET_FILL); + default: + break; + } + } + + public static final void glShadeModel(int p1) { + + } + + public static final void glClearDepth(float p1) { + _wglClearDepth(-p1); + } + + public static final void glDepthFunc(int p1) { + int f = _wGL_GEQUAL; + switch (p1) { + case GL_GREATER: + f = _wGL_LESS; + break; + case GL_LEQUAL: + f = _wGL_GEQUAL; + break; + case GL_EQUAL: + f = _wGL_EQUAL; + default: + break; + } + _wglDepthFunc(f); + } + + public static final void glAlphaFunc(int p1, float p2) { + alphaThresh = p2; + } + + public static final void glCullFace(int p1) { + _wglCullFace(p1); + } + + public static final void glMatrixMode(int p1) { + matrixMode = p1; + } + + private static final Matrix4f getMatrix() { + switch (matrixMode) { + case GL_MODELVIEW: + default: + return matModelV[matModelPointer]; + case GL_PROJECTION: + return matProjV[matProjPointer]; + case GL_TEXTURE: + return matTexV[matTexPointer]; + } + } + + public static final void glLoadIdentity() { + getMatrix().setIdentity(); + } + + public static final void glViewport(int p1, int p2, int p3, int p4) { + _wglViewport(p1, p2, p3, p4); + } + + public static final void glClear(int p1) { + _wglClear(p1); + } + + public static final void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) { + Matrix4f res = getMatrix(); + res.m00 = 2.0f / (right - left); + res.m01 = 0.0f; + res.m02 = 0.0f; + res.m03 = 0.0f; + res.m10 = 0.0f; + res.m11 = 2.0f / (top - bottom); + res.m12 = 0.0f; + res.m13 = 0.0f; + res.m20 = 0.0f; + res.m21 = 0.0f; + res.m22 = 2.0f / (zFar - zNear); + res.m23 = 0.0f; + res.m30 = -(right + left) / (right - left); + res.m31 = -(top + bottom) / (top - bottom); + res.m32 = (zFar + zNear) / (zFar - zNear); + res.m33 = 1.0f; + } + + private static final Vector3f deevis = new Vector3f(); + + public static final void glTranslatef(float p1, float p2, float p3) { + deevis.set(p1, p2, p3); + getMatrix().translate(deevis); + if (isCompilingDisplayList) { + throw new IllegalArgumentException("matrix is not supported while recording display list use tessellator class instead"); + } + } + + public static final void glClearColor(float p1, float p2, float p3, float p4) { + _wglClearColor(p1, p2, p3, p4); + } + + public static final void glDisable(int p1) { + switch (p1) { + case GL_DEPTH_TEST: + _wglDisable(_wGL_DEPTH_TEST); + break; + case GL_CULL_FACE: + _wglDisable(_wGL_CULL_FACE); + break; + case GL_BLEND: + _wglDisable(_wGL_BLEND); + break; + case GL_RESCALE_NORMAL: + break; + case GL_TEXTURE_2D: + enableTexture2D = false; + break; + case GL_LIGHTING: + enableLighting = false; + break; + case GL_ALPHA_TEST: + enableAlphaTest = false; + break; + case GL_FOG: + fogEnabled = false; + break; + case GL_COLOR_MATERIAL: + enableColorMaterial = false; + break; + case GL_POLYGON_OFFSET_FILL: + _wglDisable(_wGL_POLYGON_OFFSET_FILL); + default: + break; + } + } + + public static final void glColor4f(float p1, float p2, float p3, float p4) { + colorR = p1; + colorG = p2; + colorB = p3; + colorA = p4; + } + + public static final int glGetError() { + int err = _wglGetError(); + if (err == _wGL_CONTEXT_LOST_WEBGL) + return GL_CONTEXT_LOST_WEBGL; + return err; + } + + public static final void glFlush() { + _wglFlush(); + } + + public static final void glLineWidth(float p1) { + + } + + public static final void glTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + ByteBuffer p9) { + _wglTexImage2D(_wGL_TEXTURE_2D, p2, _wGL_RGBA8, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9); + } + + public static final void glLight(int p1, int p2, FloatBuffer p3) { + + } + + public static final void glLightModel(int p1, FloatBuffer p2) { + + } + + private static Vector4f lightPos0vec0 = new Vector4f(); + private static Vector4f lightPos1vec0 = new Vector4f(); + private static Vector4f lightPos0vec = new Vector4f(); + private static Vector4f lightPos1vec = new Vector4f(); + + public static final void copyModelToLightMatrix() { + lightPos0vec0.set(lightPos0vec); + lightPos1vec0.set(lightPos1vec); + lightPos0vec.set(0.2f, 1.0f, -0.7f, 0.0f); + lightPos0vec.normalise(); + lightPos1vec.set(-0.2f, 1.0f, 0.7f, 0.0f); + lightPos1vec.normalise(); + Matrix4f.transform(matModelV[matModelPointer], lightPos0vec, lightPos0vec).normalise(); + Matrix4f.transform(matModelV[matModelPointer], lightPos1vec, lightPos1vec).normalise(); + } + + public static final void flipLightMatrix() { + lightPos0vec.x = -lightPos0vec.x; + lightPos1vec.x = -lightPos1vec.x; + lightPos0vec.y = -lightPos0vec.y; + lightPos1vec.y = -lightPos1vec.y; + lightPos0vec.z = -lightPos0vec.z; + lightPos1vec.z = -lightPos1vec.z; + } + + public static final void revertLightMatrix() { + lightPos0vec.set(lightPos0vec0); + lightPos1vec.set(lightPos1vec0); + } + + public static final void glPushMatrix() { + switch (matrixMode) { + case GL_MODELVIEW: + default: + if (matModelPointer < matModelV.length - 1) { + ++matModelPointer; + matModelV[matModelPointer].load(matModelV[matModelPointer - 1]); + } else { + System.err.println("modelview matrix stack overflow"); + } + break; + case GL_PROJECTION: + if (matProjPointer < matProjV.length - 1) { + ++matProjPointer; + matProjV[matProjPointer].load(matProjV[matProjPointer - 1]); + } else { + System.err.println("projection matrix stack overflow"); + } + break; + case GL_TEXTURE: + if (matTexPointer < matTexV.length - 1) { + ++matTexPointer; + matTexV[matTexPointer].load(matTexV[matTexPointer - 1]); + } else { + System.err.println("texture matrix stack overflow"); + } + break; + } + } + + private static final float toRad = 0.0174532925f; + + public static final void glRotatef(float p1, float p2, float p3, float p4) { + deevis.set(p2, p3, p4); + getMatrix().rotate(p1 * toRad, deevis); + if (isCompilingDisplayList) { + throw new IllegalArgumentException("matrix is not supported while recording display list use tessellator class instead"); + } + } + + public static final void glPopMatrix() { + switch (matrixMode) { + case GL_MODELVIEW: + default: + if (matModelPointer > 0) { + --matModelPointer; + } else { + System.err.println("modelview matrix stack underflow"); + } + break; + case GL_PROJECTION: + if (matProjPointer > 0) { + --matProjPointer; + } else { + System.err.println("projection matrix stack underflow"); + } + break; + case GL_TEXTURE: + if (matTexPointer > 0) { + --matTexPointer; + } else { + System.err.println("texture matrix stack underflow"); + } + break; + } + } + + public static final void glColorMaterial(int p1, int p2) { + + } + + public static final void glGetFloat(int p1, FloatBuffer p2) { + switch (p1) { + case GL_MODELVIEW_MATRIX: + default: + matModelV[matModelPointer].store(p2); + break; + case GL_PROJECTION_MATRIX: + matProjV[matProjPointer].store(p2); + break; + } + } + + public static final void glGetInteger(int p1, int[] p2) { + if (p1 == GL_VIEWPORT) { + _wglGetParameter(_wGL_VIEWPORT, 4, p2); + } + } + + public static final void glScalef(float p1, float p2, float p3) { + deevis.set(p1, p2, p3); + getMatrix().scale(deevis); + if (isCompilingDisplayList) { + throw new IllegalArgumentException("matrix is not supported while recording display list use tessellator class instead"); + } + } + + public static final void glBlendFunc(int p1, int p2) { + fogPremultiply = (p1 == GL_ONE && p2 == GL_ONE_MINUS_SRC_ALPHA); + _wglBlendFunc(p1, p2); + } + + public static final void glDepthMask(boolean p1) { + _wglDepthMask(p1); + } + + public static final void glColorMask(boolean p1, boolean p2, boolean p3, boolean p4) { + _wglColorMask(p1, p2, p3, p4); + } + + public static final void glBindTexture(int p1, int p2) { + TextureGL t = texObjects.get(p2); + _wglBindTexture(_wGL_TEXTURE_2D, t); + } + + public static final void glCopyTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { + _wglCopyTexSubImage2D(_wGL_TEXTURE_2D, p2, p3, p4, p5, p6, p7, p8); + } + + public static final void glTexParameteri(int p1, int p2, int p3) { + if(p3 == RealOpenGLEnums.GL_CLAMP_TO_EDGE || p3 == 10496) { + p3 = _wGL_CLAMP; + } + _wglTexParameteri(p1, p2, p3); + } + + public static final void glTexParameterf(int p1, int p2, float p3) { + int pp1 = 0; + switch (p1) { + default: + case GL_TEXTURE_2D: + pp1 = _wGL_TEXTURE_2D; + break; + // case GL_TEXTURE_3D: pp1 = _wGL_TEXTURE_3D; break; + } + int pp2 = 0; + switch (p2) { + default: + case GL_TEXTURE_MAX_ANISOTROPY: + pp2 = _wGL_TEXTURE_MAX_ANISOTROPY; + break; + } + _wglTexParameterf(pp1, pp2, p3); + } + + public static final void glLogicOp(int p1) { + + } + + public static final void glNormal3f(float p1, float p2, float p3) { + float len = (float) Math.sqrt(p1 * p1 + p2 * p2 + p3 * p3); + normalX = p1 / len; + normalY = p2 / len; + normalZ = p3 / len; + } + + public static final int glGenLists(int p1) { + int base = displayListId + 1; + for (int i = 0; i < p1; i++) { + int id = ++displayListId; + displayLists.put(id, new DisplayList(id)); + } + return base; + } + + public static final void _wglBindVertexArray0(BufferArrayGL p1) { + currentArray = p1; + _wglBindVertexArray(p1); + } + + private static int displayListId = 0; + + public static final void glCallList(int p1) { + if (!isCompilingDisplayList) { + DisplayList d = displayListsInitialized.get(p1); + if (d != null && d.listLength > 0) { + bindTheShader(d.shaderMode | getShaderModeFlag1()); + _wglBindVertexArray0(d.glarray); + _wglDrawQuadArrays(0, d.listLength); + shader.unuseProgram(); + vertexDrawn += d.listLength * 6 / 4; + triangleDrawn += d.listLength / 2; + } + } + } + + public static final void glNewList(int p1, int p2) { + if (!isCompilingDisplayList) { + compilingDisplayList = displayLists.get(p1); + if (compilingDisplayList != null) { + compilingDisplayList.shaderMode = -1; + compilingDisplayList.listLength = 0; + isCompilingDisplayList = true; + } + } + } + + public static final void glEndList() { + if (isCompilingDisplayList) { + isCompilingDisplayList = false; + Object upload = _wGetLowLevelBuffersAppended(); + int l = _wArrayByteLength(upload); + if (l > 0) { + if (compilingDisplayList.glbuffer == null) { + displayListsInitialized.put(compilingDisplayList.id, compilingDisplayList); + compilingDisplayList.glarray = _wglCreateVertexArray(); + compilingDisplayList.glbuffer = _wglCreateBuffer(); + FixedFunctionShader f = FixedFunctionShader.instance(compilingDisplayList.shaderMode); + _wglBindVertexArray0(compilingDisplayList.glarray); + _wglBindBuffer(_wGL_ARRAY_BUFFER, compilingDisplayList.glbuffer); + f.setupArrayForProgram(); + } + _wglBindBuffer(_wGL_ARRAY_BUFFER, compilingDisplayList.glbuffer); + _wglBufferData(_wGL_ARRAY_BUFFER, upload, _wGL_STATIC_DRAW); + bytesUploaded += l; + } + } + } + + public static final void glColor3f(float p1, float p2, float p3) { + colorR = p1; + colorG = p2; + colorB = p3; + colorA = 1.0f; + } + + public static final void glTexImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + IntBuffer p9) { + /* + * int pp2 = 0; switch(p3) { default: case GL_RGBA: pp2 = _wGL_RGBA; break; case + * GL_BGRA: pp2 = _wGL_BGRA; break; } int pp3 = 0; switch(p7) { default: case + * GL_RGBA: pp3 = _wGL_RGBA; break; case GL_BGRA: pp3 = _wGL_BGRA; break; } + */ + bytesUploaded += p9.remaining() * 4; + _wglTexImage2D(_wGL_TEXTURE_2D, p2, _wGL_RGBA8, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9); + } + + public static final void glTexImage2D_2(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + IntBuffer p9) { + bytesUploaded += p9.remaining() * 4; + _wglTexImage2D(_wGL_TEXTURE_2D, p2, _wGL_RGB8, p4, p5, p6, _wGL_RGB, _wGL_UNSIGNED_BYTE, p9); + } + + public static final void glTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + IntBuffer p9) { + int pp1 = 0; + switch (p1) { + default: + case GL_TEXTURE_2D: + pp1 = _wGL_TEXTURE_2D; + break; + // case GL_TEXTURE_3D: pp1 = _wGL_TEXTURE_3D; break; + } + /* + * int pp3 = 0; switch(p7) { default: case GL_RGBA: pp3 = _wGL_RGBA; break; case + * GL_BGRA: pp3 = _wGL_BGRA; break; } + */ + bytesUploaded += p9.remaining() * 4; + _wglTexSubImage2D(pp1, p2, p3, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9); + } + + public static final void glDeleteTextures(int p1) { + _wglDeleteTextures(texObjects.free(p1)); + } + + public static final void glPolygonOffset(float p1, float p2) { + _wglPolygonOffset(p1, p2); + } + + public static final void glCallLists(IntBuffer p1) { + while (p1.hasRemaining()) { + glCallList(p1.get()); + } + } + + public static final void glEnableVertexAttrib(int p1) { + switch (p1) { + case GL_COLOR_ARRAY: + enableColorArray = true; + break; + case GL_NORMAL_ARRAY: + enableNormalArray = true; + break; + case GL_TEXTURE_COORD_ARRAY: + enableTex0Array = true; + break; + default: + break; + } + } + + public static final void glDisableVertexAttrib(int p1) { + switch (p1) { + case GL_COLOR_ARRAY: + enableColorArray = false; + break; + case GL_NORMAL_ARRAY: + enableNormalArray = false; + break; + case GL_TEXTURE_COORD_ARRAY: + enableTex0Array = false; + break; + default: + break; + } + } + + private static final int getShaderModeFlag0() { + int mode = 0; + mode = (mode | (enableColorArray ? FixedFunctionShader.COLOR : 0)); + mode = (mode | (enableNormalArray ? FixedFunctionShader.NORMAL : 0)); + mode = (mode | (enableTex0Array ? FixedFunctionShader.TEXTURE0 : 0)); + return mode; + } + + private static final int getShaderModeFlag1() { + int mode = 0; + mode = (mode | ((enableColorMaterial && enableLighting) ? FixedFunctionShader.LIGHTING : 0)); + mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0)); + mode = (mode | (enableAlphaTest ? FixedFunctionShader.ALPHATEST : 0)); + mode = (mode | (enableTexture2D ? FixedFunctionShader.UNIT0 : 0)); + return mode; + } + + private static final int getShaderModeFlag() { + int mode = 0; + mode = (mode | (enableColorArray ? FixedFunctionShader.COLOR : 0)); + mode = (mode | (enableNormalArray ? FixedFunctionShader.NORMAL : 0)); + mode = (mode | (enableTex0Array ? FixedFunctionShader.TEXTURE0 : 0)); + mode = (mode | ((enableColorMaterial && enableLighting) ? FixedFunctionShader.LIGHTING : 0)); + mode = (mode | (fogEnabled ? FixedFunctionShader.FOG : 0)); + mode = (mode | (enableAlphaTest ? FixedFunctionShader.ALPHATEST : 0)); + mode = (mode | (enableTexture2D ? FixedFunctionShader.UNIT0 : 0)); + return mode; + } + + private static FixedFunctionShader shader = null; + + private static final void bindTheShader() { + bindTheShader(getShaderModeFlag()); + } + + private static final void bindTheShader(int mode) { + FixedFunctionShader s = shader = FixedFunctionShader.instance(mode); + s.useProgram(); + if (enableAlphaTest) { + s.setAlphaTest(alphaThresh); + } + s.setColor(colorR, colorG, colorB, colorA); + if (fogEnabled) { + s.setFogMode((fogPremultiply ? 2 : 0) + fogMode); + s.setFogColor(fogColorR, fogColorG, fogColorB, fogColorA); + s.setFogDensity(fogDensity); + s.setFogStartEnd(fogStart, fogEnd); + } + s.setModelMatrix(matModelV[matModelPointer]); + s.setProjectionMatrix(matProjV[matProjPointer]); + s.setTextureMatrix(matTexV[matTexPointer]); + if (enableColorMaterial && enableLighting) { + s.setNormal(normalX, normalY, normalZ); + s.setLightPositions(lightPos0vec, lightPos1vec); + } + s.setTex0Coords(tex0X, tex0Y); + } + + private static Object blankUploadArray = _wCreateLowLevelIntBuffer(525000); + + public static final void glDrawArrays(int p1, int p2, int p3, Object buffer) { + if (isCompilingDisplayList) { + if (p1 == GL_QUADS) { + if (compilingDisplayList.shaderMode == -1) { + compilingDisplayList.shaderMode = getShaderModeFlag0(); + } else { + if (compilingDisplayList.shaderMode != getShaderModeFlag0()) { + System.err.println("vertex format inconsistent in display list"); + } + } + compilingDisplayList.listLength += p3; + _wAppendLowLevelBuffer(buffer); + } else { + System.err.println("only GL_QUADS supported in a display list"); + } + } else { + bytesUploaded += _wArrayByteLength(buffer); + vertexDrawn += p3; + + bindTheShader(); + + _wglBindVertexArray0(shader.genericArray); + _wglBindBuffer(_wGL_ARRAY_BUFFER, shader.genericBuffer); + if (!shader.bufferIsInitialized) { + shader.bufferIsInitialized = true; + _wglBufferData(_wGL_ARRAY_BUFFER, blankUploadArray, _wGL_DYNAMIC_DRAW); + } + _wglBufferSubData(_wGL_ARRAY_BUFFER, 0, buffer); + + if (p1 == GL_QUADS) { + _wglDrawQuadArrays(p2, p3); + triangleDrawn += p3 / 2; + } else { + int drawMode = 0; + switch (p1) { + default: + case GL_TRIANGLES: + drawMode = _wGL_TRIANGLES; + triangleDrawn += p3 / 3; + break; + case GL_TRIANGLE_STRIP: + drawMode = _wGL_TRIANGLE_STRIP; + triangleDrawn += p3 - 2; + break; + case GL_TRIANGLE_FAN: + drawMode = _wGL_TRIANGLE_FAN; + triangleDrawn += p3 - 2; + break; + case GL_LINE_STRIP: + drawMode = _wGL_LINE_STRIP; + triangleDrawn += p3 - 1; + break; + case GL_LINES: + drawMode = _wGL_LINES; + triangleDrawn += p3 / 2; + break; + } + _wglDrawArrays(drawMode, p2, p3); + } + + shader.unuseProgram(); + + } + } + + private static final void _wglDrawQuadArrays(int p2, int p3) { + if (quadsToTrianglesBuffer == null) { + IntBuffer upload = IntBuffer.wrap(new int[98400 / 2]); + for (int i = 0; i < 16384; ++i) { + int v1 = i * 4; + int v2 = i * 4 + 1; + int v3 = i * 4 + 2; + int v4 = i * 4 + 3; + upload.put(v1 | (v2 << 16)); + upload.put(v4 | (v2 << 16)); + upload.put(v3 | (v4 << 16)); + } + upload.flip(); + quadsToTrianglesBuffer = _wglCreateBuffer(); + _wglBindBuffer(_wGL_ELEMENT_ARRAY_BUFFER, quadsToTrianglesBuffer); + _wglBufferData0(_wGL_ELEMENT_ARRAY_BUFFER, upload, _wGL_STATIC_DRAW); + } + if (!currentArray.isQuadBufferBound) { + currentArray.isQuadBufferBound = true; + _wglBindBuffer(_wGL_ELEMENT_ARRAY_BUFFER, quadsToTrianglesBuffer); + } + _wglDrawElements(_wGL_TRIANGLES, p3 * 6 / 4, _wGL_UNSIGNED_SHORT, p2 * 6 / 4); + } + + private static BufferArrayGL occlusion_vao = null; + private static BufferGL occlusion_vbo = null; + private static ProgramGL occlusion_program = null; + private static UniformGL occlusion_matrix_m = null; + private static UniformGL occlusion_matrix_p = null; + + private static final void initializeOcclusionObjects() { + occlusion_vao = _wglCreateVertexArray(); + occlusion_vbo = _wglCreateBuffer(); + + IntBuffer upload = IntBuffer.wrap(new int[108]); + float[] verts = new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }; + for (int i = 0; i < verts.length; i++) { + upload.put(Float.floatToRawIntBits(verts[i])); + } + upload.flip(); + + _wglBindVertexArray(occlusion_vao); + _wglBindBuffer(_wGL_ARRAY_BUFFER, occlusion_vbo); + _wglBufferData0(_wGL_ARRAY_BUFFER, upload, _wGL_STATIC_DRAW); + _wglEnableVertexAttribArray(0); + _wglVertexAttribPointer(0, 3, _wGL_FLOAT, false, 12, 0); + + ShaderGL vert = _wglCreateShader(_wGL_VERTEX_SHADER); + ShaderGL frag = _wglCreateShader(_wGL_FRAGMENT_SHADER); + + String src = fileContents("/glsl/occl.glsl"); + _wglShaderSource(vert, _wgetShaderHeader() + "\n#define CC_VERT\n" + src); + _wglShaderSource(frag, _wgetShaderHeader() + "\n#define CC_FRAG\n" + src); + + _wglCompileShader(vert); + if (!_wglGetShaderCompiled(vert)) + System.err.println(("\n" + _wglGetShaderInfoLog(vert)).replace("\n", "\n[/glsl/occl.glsl][VERT] ") + "\n"); + + _wglCompileShader(frag); + if (!_wglGetShaderCompiled(frag)) + System.err.println(("\n" + _wglGetShaderInfoLog(frag)).replace("\n", "\n[/glsl/occl.glsl][FRAG] ") + "\n"); + + occlusion_program = _wglCreateProgram(); + + _wglAttachShader(occlusion_program, vert); + _wglAttachShader(occlusion_program, frag); + _wglLinkProgram(occlusion_program); + _wglDetachShader(occlusion_program, vert); + _wglDetachShader(occlusion_program, frag); + _wglDeleteShader(vert); + _wglDeleteShader(frag); + + if (!_wglGetProgramLinked(occlusion_program)) + System.err.println( + ("\n\n" + _wglGetProgramInfoLog(occlusion_program)).replace("\n", "\n[/glsl/occl.glsl][LINKER] ")); + + _wglUseProgram(occlusion_program); + occlusion_matrix_m = _wglGetUniformLocation(occlusion_program, "matrix_m"); + occlusion_matrix_p = _wglGetUniformLocation(occlusion_program, "matrix_p"); + + } + + private static final GLObjectMap queryObjs = new GLObjectMap(256); + + public static final int glCreateQuery() { + return queryObjs.register(_wglCreateQuery()); + } + + public static final void glBeginQuery(int obj) { + _wglBeginQuery(_wGL_ANY_SAMPLES_PASSED, queryObjs.get(obj)); + } + + public static final void glDeleteQuery(int obj) { + _wglDeleteQuery(queryObjs.free(obj)); + } + + private static final Matrix4f cachedOcclusionP = (Matrix4f) (new Matrix4f()).setZero(); + private static float[] occlusionModel = new float[16]; + private static float[] occlusionProj = new float[16]; + + public static final void glBindOcclusionBB() { + if (occlusion_vao == null) + initializeOcclusionObjects(); + _wglUseProgram(occlusion_program); + _wglBindVertexArray(occlusion_vao); + if (!cachedOcclusionP.equals(matProjV[matProjPointer])) { + cachedOcclusionP.load(matProjV[matProjPointer]); + cachedOcclusionP.store(occlusionProj); + _wglUniformMat4fv(occlusion_matrix_p, occlusionProj); + } + } + + public static final void glEndOcclusionBB() { + + } + + public static final void glDrawOcclusionBB(float posX, float posY, float posZ, float sizeX, float sizeY, + float sizeZ) { + glPushMatrix(); + glTranslatef(posX - sizeX * 0.01f, posY - sizeY * 0.01f, posZ - sizeZ * 0.01f); + glScalef(sizeX * 1.02f, sizeY * 1.02f, sizeZ * 1.02f); + matModelV[matModelPointer].store(occlusionModel); + _wglUniformMat4fv(occlusion_matrix_m, occlusionModel); + _wglDrawArrays(_wGL_TRIANGLES, 0, 36); + glPopMatrix(); + + } + + public static final void glEndQuery() { + _wglEndQuery(_wGL_ANY_SAMPLES_PASSED); + } + + public static final boolean glGetQueryResult(int obj) { + QueryGL q = queryObjs.get(obj); + return _wglGetQueryObjecti(q, _wGL_QUERY_RESULT) > 0; + } + + public static final boolean glGetQueryResultAvailable(int obj) { + QueryGL q = queryObjs.get(obj); + return _wglGetQueryObjecti(q, _wGL_QUERY_RESULT_AVAILABLE) > 0; + } + + public static final int glGenTextures() { + return texObjects.register(_wglGenTextures()); + } + + public static final void glTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + ByteBuffer p9) { + int pp1 = 0; + switch (p1) { + default: + case GL_TEXTURE_2D: + pp1 = _wGL_TEXTURE_2D; + break; + // case GL_TEXTURE_3D: pp1 = _wGL_TEXTURE_3D; break; + } + /* + * int pp3 = 0; switch(p7) { default: case GL_RGBA: pp3 = _wGL_RGBA; break; case + * GL_BGRA: pp3 = _wGL_BGRA; break; } + */ + bytesUploaded += p9.remaining(); + _wglTexSubImage2D(pp1, p2, p3, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9); + } + + public static final void glFogi(int p1, int p2) { + if (p1 == GL_FOG_MODE) { + switch (p2) { + default: + case GL_LINEAR: + fogMode = 1; + break; + case GL_EXP: + fogMode = 2; + break; + } + } + } + + public static final void glFogf(int p1, float p2) { + switch (p1) { + case GL_FOG_START: + fogStart = p2; + break; + case GL_FOG_END: + fogEnd = p2; + break; + case GL_FOG_DENSITY: + fogDensity = p2; + break; + default: + break; + } + } + + public static final void glFog(int p1, FloatBuffer p2) { + if (p1 == GL_FOG_COLOR) { + fogColorR = p2.get(); + fogColorG = p2.get(); + fogColorB = p2.get(); + fogColorA = p2.get(); + } + } + + public static final void glDeleteLists(int p1, int p2) { + for (int i = 0; i < p2; i++) { + DisplayList d = displayListsInitialized.remove(p1 + i); + if (d != null) { + _wglDeleteVertexArray(d.glarray); + _wglDeleteBuffer(d.glbuffer); + } + displayLists.remove(p1 + i); + } + } + + public static final void glMultiTexCoord2f(int p1, float p2, float p3) { + tex0X = p2; + tex0Y = p3; + } + + private static Matrix4f unprojA = new Matrix4f(); + private static Matrix4f unprojB = new Matrix4f(); + private static Vector4f unprojC = new Vector4f(); + + public static final void gluUnProject(float p1, float p2, float p3, FloatBuffer p4, FloatBuffer p5, int[] p6, + FloatBuffer p7) { + unprojA.load(p4); + unprojB.load(p5); + Matrix4f.mul(unprojA, unprojB, unprojB); + unprojB.invert(); + unprojC.set(((p1 - (float) p6[0]) / (float) p6[2]) * 2f - 1f, ((p2 - (float) p6[1]) / (float) p6[3]) * 2f - 1f, + p3, 1.0f); + Matrix4f.transform(unprojB, unprojC, unprojC); + p7.put(unprojC.x / unprojC.w); + p7.put(unprojC.y / unprojC.w); + p7.put(unprojC.z / unprojC.w); + } + + public static final void gluPerspective(float fovy, float aspect, float zNear, float zFar) { + Matrix4f res = getMatrix(); + float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f); + res.m00 = cotangent / aspect; + res.m01 = 0.0f; + res.m02 = 0.0f; + res.m03 = 0.0f; + res.m10 = 0.0f; + res.m11 = cotangent; + res.m12 = 0.0f; + res.m13 = 0.0f; + res.m20 = 0.0f; + res.m21 = 0.0f; + res.m22 = (zFar + zNear) / (zFar - zNear); + res.m23 = -1.0f; + res.m30 = 0.0f; + res.m31 = 0.0f; + res.m32 = 2.0f * zFar * zNear / (zFar - zNear); + res.m33 = 0.0f; + } + + public static final void gluPerspectiveFlat(float fovy, float aspect, float zNear, float zFar) { + Matrix4f res = getMatrix(); + float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f); + res.m00 = cotangent / aspect; + res.m01 = 0.0f; + res.m02 = 0.0f; + res.m03 = 0.0f; + res.m10 = 0.0f; + res.m11 = cotangent; + res.m12 = 0.0f; + res.m13 = 0.0f; + res.m20 = 0.0f; + res.m21 = 0.0f; + res.m22 = ((zFar + zNear) / (zFar - zNear)) * 0.001f; + res.m23 = -1.0f; + res.m30 = 0.0f; + res.m31 = 0.0f; + res.m32 = 2.0f * zFar * zNear / (zFar - zNear); + res.m33 = 0.0f; + } + + public static final String gluErrorString(int p1) { + switch (p1) { + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM"; + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE"; + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION"; + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY"; + case GL_CONTEXT_LOST_WEBGL: + return "CONTEXT_LOST_WEBGL"; + default: + return "Unknown Error"; + } + } + + private static long lastBandwidthReset = 0l; + private static int lastBandwidth = 0; + + public static final int getBitsPerSecond() { + if (System.currentTimeMillis() - lastBandwidthReset > 1000) { + lastBandwidthReset = System.currentTimeMillis(); + lastBandwidth = bytesUploaded * 8; + bytesUploaded = 0; + } + return lastBandwidth; + } + + public static final int getVertexesPerSecond() { + int ret = vertexDrawn; + vertexDrawn = 0; + return ret; + } + + public static final int getTrianglesPerSecond() { + int ret = triangleDrawn; + triangleDrawn = 0; + return ret; + } + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/MinecraftClient.java b/src/main/java/net/PeytonPlayz585/minecraft/MinecraftClient.java new file mode 100644 index 0000000..00337fe --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/MinecraftClient.java @@ -0,0 +1,54 @@ +package net.PeytonPlayz585.minecraft; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; + +import com.jcraft.jzlib.InflaterInputStream; + +public class MinecraftClient { + private static final HashMap filePool = new HashMap(); + + public static final void install(byte[] pkg) throws IOException { + ByteArrayInputStream in2 = new ByteArrayInputStream(pkg); + DataInputStream in = new DataInputStream(in2); + byte[] header = new byte[8]; + in.read(header); + if (!"EAGPKG!!".equals(new String(header, Charset.forName("UTF-8")))) + throw new IOException("invalid epk file"); + in.readUTF(); + in = new DataInputStream(new InflaterInputStream(in2)); + String s = null; + SHA1Digest dg = new SHA1Digest(); + while ("".equals(s = in.readUTF())) { + String path = in.readUTF(); + byte[] digest = new byte[20]; + byte[] digest2 = new byte[20]; + in.read(digest); + int len = in.readInt(); + byte[] file = new byte[len]; + in.read(file); + if (filePool.containsKey(path)) + continue; + dg.update(file, 0, len); + dg.doFinal(digest2, 0); + if (!Arrays.equals(digest, digest2)) + throw new IOException("invalid file hash for " + path); + filePool.put(path, file); + if (!"".equals(in.readUTF())) + throw new IOException("invalid epk file"); + } + if (in.available() > 0 || !" end".equals(s)) + throw new IOException("invalid epk file"); + } + + public static final byte[] getResource(String path) { + if (path.startsWith("/")) + path = path.substring(1); + return filePool.get(path); + } + +} diff --git a/src/main/java/net/PeytonPlayz585/minecraft/MinecraftImage.java b/src/main/java/net/PeytonPlayz585/minecraft/MinecraftImage.java new file mode 100644 index 0000000..88532c1 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/MinecraftImage.java @@ -0,0 +1,40 @@ +package net.PeytonPlayz585.minecraft; + +public class MinecraftImage { + + public final int[] data; + public final int w; + public final int h; + public final boolean alpha; + + public MinecraftImage(int pw, int ph, boolean palpha) { + this.w = pw; + this.h = ph; + this.alpha = palpha; + this.data = new int[pw * ph]; + } + + public MinecraftImage(int[] pdata, int pw, int ph, boolean palpha) { + if (pdata.length != pw * ph) { + throw new IllegalArgumentException("array size does not equal image size"); + } + this.w = pw; + this.h = ph; + this.alpha = palpha; + if (!palpha) { + for (int i = 0; i < pdata.length; ++i) { + pdata[i] = pdata[i] | 0xFF000000; + } + } + this.data = pdata; + } + + public MinecraftImage getSubImage(int x, int y, int pw, int ph) { + int[] img = new int[pw * ph]; + for (int i = 0; i < ph; ++i) { + System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw); + } + return new MinecraftImage(img, pw, ph, alpha); + } + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/minecraft/SHA1Digest.java b/src/main/java/net/PeytonPlayz585/minecraft/SHA1Digest.java new file mode 100644 index 0000000..c93990a --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/minecraft/SHA1Digest.java @@ -0,0 +1,213 @@ +package net.PeytonPlayz585.minecraft; + +/** + * implementation of SHA-1 as outlined in "Handbook of Applied Cryptography", + * pages 346 - 349. + * + * It is interesting to ponder why the, apart from the extra IV, the other + * difference here from MD5 is the "endienness" of the word processing! + */ +public class SHA1Digest extends GeneralDigest { + private static final int DIGEST_LENGTH = 20; + + private int H1, H2, H3, H4, H5; + + private int[] X = new int[80]; + private int xOff; + + /** + * Standard constructor + */ + public SHA1Digest() { + reset(); + } + + /** + * Copy constructor. This will copy the state of the provided message digest. + */ + public SHA1Digest(SHA1Digest t) { + super(t); + + H1 = t.H1; + H2 = t.H2; + H3 = t.H3; + H4 = t.H4; + H5 = t.H5; + + System.arraycopy(t.X, 0, X, 0, t.X.length); + xOff = t.xOff; + } + + public String getAlgorithmName() { + return "SHA-1"; + } + + public int getDigestSize() { + return DIGEST_LENGTH; + } + + protected void processWord(byte[] in, int inOff) { + X[xOff++] = ((in[inOff] & 0xff) << 24) | ((in[inOff + 1] & 0xff) << 16) | ((in[inOff + 2] & 0xff) << 8) + | ((in[inOff + 3] & 0xff)); + + if (xOff == 16) { + processBlock(); + } + } + + private void unpackWord(int word, byte[] out, int outOff) { + out[outOff] = (byte) (word >>> 24); + out[outOff + 1] = (byte) (word >>> 16); + out[outOff + 2] = (byte) (word >>> 8); + out[outOff + 3] = (byte) word; + } + + protected void processLength(long bitLength) { + if (xOff > 14) { + processBlock(); + } + + X[14] = (int) (bitLength >>> 32); + X[15] = (int) (bitLength & 0xffffffff); + } + + public int doFinal(byte[] out, int outOff) { + finish(); + + unpackWord(H1, out, outOff); + unpackWord(H2, out, outOff + 4); + unpackWord(H3, out, outOff + 8); + unpackWord(H4, out, outOff + 12); + unpackWord(H5, out, outOff + 16); + + reset(); + + return DIGEST_LENGTH; + } + + /** + * reset the chaining variables + */ + public void reset() { + super.reset(); + + H1 = 0x67452301; + H2 = 0xefcdab89; + H3 = 0x98badcfe; + H4 = 0x10325476; + H5 = 0xc3d2e1f0; + + xOff = 0; + for (int i = 0; i != X.length; i++) { + X[i] = 0; + } + } + + // + // Additive constants + // + private static final int Y1 = 0x5a827999; + private static final int Y2 = 0x6ed9eba1; + private static final int Y3 = 0x8f1bbcdc; + private static final int Y4 = 0xca62c1d6; + + private int f(int u, int v, int w) { + return ((u & v) | ((~u) & w)); + } + + private int h(int u, int v, int w) { + return (u ^ v ^ w); + } + + private int g(int u, int v, int w) { + return ((u & v) | (u & w) | (v & w)); + } + + private int rotateLeft(int x, int n) { + return (x << n) | (x >>> (32 - n)); + } + + protected void processBlock() { + // + // expand 16 word block into 80 word block. + // + for (int i = 16; i <= 79; i++) { + X[i] = rotateLeft((X[i - 3] ^ X[i - 8] ^ X[i - 14] ^ X[i - 16]), 1); + } + + // + // set up working variables. + // + int A = H1; + int B = H2; + int C = H3; + int D = H4; + int E = H5; + + // + // round 1 + // + for (int j = 0; j <= 19; j++) { + int t = rotateLeft(A, 5) + f(B, C, D) + E + X[j] + Y1; + + E = D; + D = C; + C = rotateLeft(B, 30); + B = A; + A = t; + } + + // + // round 2 + // + for (int j = 20; j <= 39; j++) { + int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y2; + + E = D; + D = C; + C = rotateLeft(B, 30); + B = A; + A = t; + } + + // + // round 3 + // + for (int j = 40; j <= 59; j++) { + int t = rotateLeft(A, 5) + g(B, C, D) + E + X[j] + Y3; + + E = D; + D = C; + C = rotateLeft(B, 30); + B = A; + A = t; + } + + // + // round 4 + // + for (int j = 60; j <= 79; j++) { + int t = rotateLeft(A, 5) + h(B, C, D) + E + X[j] + Y4; + + E = D; + D = C; + C = rotateLeft(B, 30); + B = A; + A = t; + } + + H1 += A; + H2 += B; + H3 += C; + H4 += D; + H5 += E; + + // + // reset the offset and clean out the word buffer. + // + xOff = 0; + for (int i = 0; i != X.length; i++) { + X[i] = 0; + } + } +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/teavm/WebGL2RenderingContext.java b/src/main/java/net/PeytonPlayz585/teavm/WebGL2RenderingContext.java new file mode 100644 index 0000000..26c0ace --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/teavm/WebGL2RenderingContext.java @@ -0,0 +1,42 @@ +package net.PeytonPlayz585.teavm; + +import org.teavm.jso.webgl.WebGLRenderingContext; + +public interface WebGL2RenderingContext extends WebGLRenderingContext { + + int TEXTURE_MAX_LEVEL = 0x0000813D; + int TEXTURE_MAX_ANISOTROPY_EXT = 0x000084FE; + int UNSIGNED_INT_24_8 = 0x000084FA; + int ANY_SAMPLES_PASSED = 0x00008D6A; + int QUERY_RESULT = 0x00008866; + int QUERY_RESULT_AVAILABLE = 0x00008867; + int DEPTH24_STENCIL8 = 0x000088F0; + int DEPTH_COMPONENT32F = 0x00008CAC; + int READ_FRAMEBUFFER = 0x00008CA8; + int DRAW_FRAMEBUFFER = 0x00008CA9; + int RGB8 = 0x00008051; + int RGBA8 = 0x00008058; + + WebGLQuery createQuery(); + + void beginQuery(int p1, WebGLQuery obj); + + void endQuery(int p1); + + void deleteQuery(WebGLQuery obj); + + int getQueryParameter(WebGLQuery obj, int p2); + + WebGLVertexArray createVertexArray(); + + void deleteVertexArray(WebGLVertexArray obj); + + void bindVertexArray(WebGLVertexArray obj); + + void renderbufferStorageMultisample(int p1, int p2, int p3, int p4, int p5); + + void blitFramebuffer(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10); + + void drawBuffers(int[] p1); + +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/teavm/WebGLQuery.java b/src/main/java/net/PeytonPlayz585/teavm/WebGLQuery.java new file mode 100644 index 0000000..035b43c --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/teavm/WebGLQuery.java @@ -0,0 +1,6 @@ +package net.PeytonPlayz585.teavm; + +import org.teavm.jso.JSObject; + +public interface WebGLQuery extends JSObject { +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/teavm/WebGLVertexArray.java b/src/main/java/net/PeytonPlayz585/teavm/WebGLVertexArray.java new file mode 100644 index 0000000..6ddffda --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/teavm/WebGLVertexArray.java @@ -0,0 +1,6 @@ +package net.PeytonPlayz585.teavm; + +import org.teavm.jso.JSObject; + +public interface WebGLVertexArray extends JSObject { +} \ No newline at end of file diff --git a/src/main/java/org/lwjgl/opengl/GL11.java b/src/main/java/org/lwjgl/opengl/GL11.java new file mode 100644 index 0000000..507ea3a --- /dev/null +++ b/src/main/java/org/lwjgl/opengl/GL11.java @@ -0,0 +1,7 @@ +package org.lwjgl.opengl; + +import net.PeytonPlayz585.minecraft.GlStateManager; + +public class GL11 extends GlStateManager { + +} \ No newline at end of file