Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius committed Oct 22, 2021
1 parent d3b9f57 commit 8af0832
Show file tree
Hide file tree
Showing 92 changed files with 20,530 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions MCLWJGL3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
160 changes: 160 additions & 0 deletions src/de/verschwiegener/lwjgl3/BufferUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package de.verschwiegener.lwjgl3;

import org.lwjgl.PointerBuffer;

import java.nio.*;

public final class BufferUtils {

/**
* Construct a direct native-ordered bytebuffer with the specified size.
* @param size The size, in bytes
* @return a ByteBuffer
*/
public static ByteBuffer createByteBuffer(int size) {
return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
}

/**
* Construct a direct native-order shortbuffer with the specified number
* of elements.
* @param size The size, in shorts
* @return a ShortBuffer
*/
public static ShortBuffer createShortBuffer(int size) {
return createByteBuffer(size << 1).asShortBuffer();
}

/**
* Construct a direct native-order charbuffer with the specified number
* of elements.
* @param size The size, in chars
* @return an CharBuffer
*/
public static CharBuffer createCharBuffer(int size) {
return createByteBuffer(size << 1).asCharBuffer();
}

/**
* Construct a direct native-order intbuffer with the specified number
* of elements.
* @param size The size, in ints
* @return an IntBuffer
*/
public static IntBuffer createIntBuffer(int size) {
return createByteBuffer(size << 2).asIntBuffer();
}

/**
* Construct a direct native-order longbuffer with the specified number
* of elements.
* @param size The size, in longs
* @return an LongBuffer
*/
public static LongBuffer createLongBuffer(int size) {
return createByteBuffer(size << 3).asLongBuffer();
}

/**
* Construct a direct native-order floatbuffer with the specified number
* of elements.
* @param size The size, in floats
* @return a FloatBuffer
*/
public static FloatBuffer createFloatBuffer(int size) {
return createByteBuffer(size << 2).asFloatBuffer();
}

/**
* Construct a direct native-order doublebuffer with the specified number
* of elements.
* @param size The size, in floats
* @return a FloatBuffer
*/
public static DoubleBuffer createDoubleBuffer(int size) {
return createByteBuffer(size << 3).asDoubleBuffer();
}

/**
* Construct a PointerBuffer with the specified number
* of elements.
* @param size The size, in memory addresses
* @return a PointerBuffer
*/
public static PointerBuffer createPointerBuffer(int size) {
return PointerBuffer.allocateDirect(size);
}

/**
* @return n, where buffer_element_size=2^n.
*/
public static int getElementSizeExponent(Buffer buf) {
if (buf instanceof ByteBuffer)
return 0;
else if (buf instanceof ShortBuffer || buf instanceof CharBuffer)
return 1;
else if (buf instanceof FloatBuffer || buf instanceof IntBuffer)
return 2;
else if (buf instanceof LongBuffer || buf instanceof DoubleBuffer)
return 3;
else
throw new IllegalStateException("Unsupported buffer type: " + buf);
}

/**
* A helper function which is used to get the byte offset in an arbitrary buffer
* based on its position
* @return the position of the buffer, in BYTES
*/
public static int getOffset(Buffer buffer) {
return buffer.position() << getElementSizeExponent(buffer);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(ByteBuffer b) {
zeroBuffer0(b, b.position(), b.remaining());
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(ShortBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(CharBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(IntBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(FloatBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(LongBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}

/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(DoubleBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}

/** Fill buffer with zeros from position to remaining */
private static native void zeroBuffer0(Buffer b, long off, long size);

/**
* Returns the memory address of the specified buffer.
*
* @param buffer the buffer
*
* @return the memory address
*/
static native long getBufferAddress(Buffer buffer);

}
52 changes: 52 additions & 0 deletions src/de/verschwiegener/lwjgl3/LWJGLUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.verschwiegener.lwjgl3;


import org.lwjgl.opengl.GL;

import java.security.AccessController;
import java.security.PrivilegedAction;

import static org.lwjgl.opengl.ARBImaging.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL30.*;

public class LWJGLUtil {

public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug");

public static boolean getPrivilegedBoolean(final String property_name) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return Boolean.getBoolean(property_name);
}
});
}
public static String translateGLErrorString(int error_code) {
switch (error_code) {
case GL_NO_ERROR:
return "No error";
case GL_INVALID_ENUM:
return "Invalid enum";
case GL_INVALID_VALUE:
return "Invalid value";
case GL_INVALID_OPERATION:
return "Invalid operation";
case GL_STACK_OVERFLOW:
return "Stack overflow";
case GL_STACK_UNDERFLOW:
return "Stack underflow";
case GL_OUT_OF_MEMORY:
return "Out of memory";
case GL_TABLE_TOO_LARGE:
return "Table too large";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "Invalid framebuffer operation";
default:
return null;
}
}
public static void log(String log){
System.out.println(log);
}

}
39 changes: 39 additions & 0 deletions src/de/verschwiegener/lwjgl3/OpenGLException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.verschwiegener.lwjgl3;

public class OpenGLException extends Exception {

private static final long serialVersionUID = 1L;

/**
* Plain c'tor
*/
public OpenGLException() {
super();
}

/**
* Creates a new OpenGLException
*
* @param msg
* String identifier for exception
*/
public OpenGLException(String msg) {
super(msg);
}

/**
* @param message
* @param cause
*/
public OpenGLException(String message, Throwable cause) {
super(message, cause);
}

/**
* @param cause
*/
public OpenGLException(Throwable cause) {
super(cause);
}

}
53 changes: 53 additions & 0 deletions src/de/verschwiegener/lwjgl3/Sys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.verschwiegener.lwjgl3;

import org.lwjgl.Version;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.openal.AL;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;

public class Sys {

public static long getTime(){
return (long) GLFW.glfwGetTime();
}
public static long getTimerResolution() {
return GLFW.glfwGetTimerFrequency();
}
public static boolean openURL(String url) {
// Attempt to use Webstart if we have it available
try {
// Lookup the javax.jnlp.BasicService object
final Class<?> serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
Method lookupMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
public Method run() throws Exception {
return serviceManagerClass.getMethod("lookup", String.class);
}
});
Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"});
final Class<?> basicServiceClass = Class.forName("javax.jnlp.BasicService");
Method showDocumentMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
public Method run() throws Exception {
return basicServiceClass.getMethod("showDocument", URL.class);
}
});
try {
Boolean ret = (Boolean)showDocumentMethod.invoke(basicService, new URL(url));
return ret;
} catch (MalformedURLException e) {
e.printStackTrace(System.err);
return false;
}
} catch (Exception ue) {
ue.printStackTrace();
return false;
}
}
public static String getVersion() {
return "LWJGL3 Port by Juli15 Version 2.0 stable, based on LWJGL" + Version.getVersion();
}
}
Loading

0 comments on commit 8af0832

Please sign in to comment.