Added the option of creating legacy OpenGL contexts
This commit is contained in:
parent
859a23cdc9
commit
8edb79c69b
|
@ -3,11 +3,15 @@ package cz.tefek.pluto.engine.buffer;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import cz.tefek.pluto.io.asl.resource.ResourceAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class to handle primitive native buffers.
|
* A utility class to handle primitive native buffers.
|
||||||
|
@ -110,9 +114,83 @@ public final class BufferHelper
|
||||||
*/
|
*/
|
||||||
public static ByteBuffer readToFlippedByteBuffer(String path) throws IOException
|
public static ByteBuffer readToFlippedByteBuffer(String path) throws IOException
|
||||||
{
|
{
|
||||||
try (var fis = new FileInputStream(path))
|
try (var fc = FileChannel.open(Path.of(path)))
|
||||||
{
|
{
|
||||||
var ba = IOUtils.toByteArray(fis);
|
var size = fc.size();
|
||||||
|
|
||||||
|
if (size > Integer.MAX_VALUE)
|
||||||
|
{
|
||||||
|
throw new IOException("File ' + pah + ' is too big to be read into a ByteBuffer!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer buf = BufferUtils.createByteBuffer((int) size);
|
||||||
|
fc.read(buf);
|
||||||
|
buf.flip();
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a file denoted by the specified {@link Path} and fills the input
|
||||||
|
* {@link ByteBuffer} with the read bytes.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* <em>Make sure the buffer can hold the entire file.</em>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param path The file's path.
|
||||||
|
* @param buf The input buffer to be filled with data.
|
||||||
|
*
|
||||||
|
* @return The input {@link ByteBuffer}.
|
||||||
|
* @throws IOException Upon standard I/O errors.
|
||||||
|
*
|
||||||
|
* @author 493msi
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
public static ByteBuffer readToByteBuffer(Path path, ByteBuffer buf) throws IOException
|
||||||
|
{
|
||||||
|
try (var fc = FileChannel.open(path))
|
||||||
|
{
|
||||||
|
fc.read(buf);
|
||||||
|
buf.flip();
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ResourceAddress} version of
|
||||||
|
* {@link BufferHelper#readToByteBuffer(Path path, ByteBuffer buf)}.
|
||||||
|
*
|
||||||
|
* @param addr The file's {@link ResourceAddress}.
|
||||||
|
* @param buf The input buffer to be filled with data.
|
||||||
|
*
|
||||||
|
* @return The input {@link ByteBuffer}.
|
||||||
|
* @throws IOException Upon standard I/O errors.
|
||||||
|
*
|
||||||
|
* @author 493msi
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
public static ByteBuffer readToByteBuffer(ResourceAddress addr, ByteBuffer buf) throws IOException
|
||||||
|
{
|
||||||
|
return readToByteBuffer(addr.toNIOPath(), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a file denoted by the specified {@link ResourceAddress} and returns
|
||||||
|
* a {@link ByteBuffer} containing the read bytes.
|
||||||
|
*
|
||||||
|
* @param path The file's path.
|
||||||
|
* @return A {@link ByteBuffer} containing the file's contents.
|
||||||
|
* @throws IOException Upon standard I/O errors.
|
||||||
|
*
|
||||||
|
* @author 493msi
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
public static ByteBuffer readToFlippedByteBuffer(ResourceAddress path) throws IOException
|
||||||
|
{
|
||||||
|
try (var is = Files.newInputStream(path.toNIOPath()))
|
||||||
|
{
|
||||||
|
var ba = IOUtils.toByteArray(is);
|
||||||
return flippedByteBuffer(ba);
|
return flippedByteBuffer(ba);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class Display
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
boolean debugMode;
|
boolean debugMode;
|
||||||
|
boolean coreProfile = true;
|
||||||
|
|
||||||
private boolean wasResized;
|
private boolean wasResized;
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ public class Display
|
||||||
|
|
||||||
public void createOpenGLCapabilities()
|
public void createOpenGLCapabilities()
|
||||||
{
|
{
|
||||||
var glCapabilities = GL.createCapabilities(true);
|
var glCapabilities = GL.createCapabilities(this.coreProfile);
|
||||||
|
|
||||||
GLDebugInfo.printDebugInfo(glCapabilities);
|
GLDebugInfo.printDebugInfo(glCapabilities);
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,26 @@ public class DisplayBuilder
|
||||||
|
|
||||||
public DisplayBuilder hintOpenGLVersion(int major, int minor)
|
public DisplayBuilder hintOpenGLVersion(int major, int minor)
|
||||||
{
|
{
|
||||||
|
GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_OPENGL_API);
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, major);
|
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, major);
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, minor);
|
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, minor);
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
|
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
|
||||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
|
this.display.coreProfile = true;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayBuilder hintOpenGLVersionLegacy(int major, int minor)
|
||||||
|
{
|
||||||
|
GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_OPENGL_API);
|
||||||
|
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_ANY_PROFILE);
|
||||||
|
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, major);
|
||||||
|
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, minor);
|
||||||
|
|
||||||
|
this.display.coreProfile = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ import org.joml.Matrix3x2f;
|
||||||
public class ViewMatrix
|
public class ViewMatrix
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a 2D
|
* Create a 2D view matrix.
|
||||||
*
|
*
|
||||||
* @param x The X camera translation
|
* @param x The X camera translation
|
||||||
* @param y The Y camera translation
|
* @param y The Y camera translation
|
||||||
* @param zoom The zoom
|
* @param zoom The zoom
|
||||||
*
|
*
|
||||||
* @return the view matrix
|
* @return the view matrix
|
||||||
|
|
Loading…
Reference in New Issue