Starting actual tests
This commit is contained in:
@@ -1,29 +1,35 @@
|
||||
package speiger.src.coreengine;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.stb.STBImage;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
|
||||
import speiger.src.coreengine.assets.parsers.NativeMemoryParser;
|
||||
import speiger.src.coreengine.math.misc.ColorSpaces;
|
||||
import speiger.src.coreengine.math.misc.ColorUtils;
|
||||
import speiger.src.coreengine.assets.AssetLocation;
|
||||
import speiger.src.coreengine.assets.AssetManager;
|
||||
import speiger.src.coreengine.assets.base.IAssetPackage;
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider;
|
||||
import speiger.src.coreengine.rendering.input.devices.FileDrop;
|
||||
import speiger.src.coreengine.rendering.input.devices.Joystick;
|
||||
import speiger.src.coreengine.rendering.input.devices.Keyboard;
|
||||
import speiger.src.coreengine.rendering.input.devices.Mouse;
|
||||
import speiger.src.coreengine.rendering.input.window.Window;
|
||||
import speiger.src.coreengine.rendering.input.window.WindowManager;
|
||||
import speiger.src.coreengine.rendering.shader.Shader;
|
||||
import speiger.src.coreengine.rendering.shader.SimpleShader;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.base.TextureUniform;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
import speiger.src.coreengine.utils.eventbus.EventBus;
|
||||
import speiger.src.coreengine.utils.helpers.IOUtils;
|
||||
|
||||
public class NewInputTest {
|
||||
|
||||
EventBus bus = new EventBus();
|
||||
WindowManager manager = new WindowManager();
|
||||
AssetManager assets = new AssetManager(List.of(IAssetPackage.of(IOUtils.getBaseLocation())));
|
||||
private Shader<TestShader> shaderTest = Shader.create(TestShader::new);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new NewInputTest().run();
|
||||
@@ -38,7 +44,9 @@ public class NewInputTest {
|
||||
FileDrop.INSTANCE.init(bus);
|
||||
manager.addDevices(Mouse.INSTANCE, Keyboard.INSTANCE, Joystick.INSTANCE, FileDrop.INSTANCE);
|
||||
Window window = manager.builder().title("Testing Engine").build();
|
||||
testInit();
|
||||
shaderTest.register();
|
||||
assets.addListener(GLStateTracker.instance().shaders);
|
||||
assets.reload(Runnable::run, Runnable::run);
|
||||
window.visible(true);
|
||||
while(!window.shouldClose()) {
|
||||
GLFW.glfwPollEvents();
|
||||
@@ -52,19 +60,10 @@ public class NewInputTest {
|
||||
manager.destroy();
|
||||
}
|
||||
|
||||
public void testInit() {
|
||||
try {
|
||||
int result = ImageIO.read(new File("test.png")).getRGB(0, 0);
|
||||
ByteBuffer buffer = NativeMemoryParser.INSTANCE.parseAsset(Paths.get("test.png"), T -> {});
|
||||
int[] width = new int[1];
|
||||
int[] height = new int[1];
|
||||
int[] fileChannels = new int[1];
|
||||
ByteBuffer stbBuffer = STBImage.stbi_load_from_memory(buffer, width, height, fileChannels, 4);
|
||||
int stbResult = stbBuffer.getInt();
|
||||
System.out.println("Java="+ColorUtils.toHex(result, true)+", STB="+ColorUtils.toHex(stbResult, true)+", STB_RGB="+ColorUtils.toHex(ColorSpaces.ABGR.toARGB(stbResult), true));
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
public static class TestShader extends SimpleShader {
|
||||
public TextureUniform texture = uniforms.addTexture("texture", 0);
|
||||
public TestShader(IAssetProvider provider) {
|
||||
super(provider, "testing_shader", AssetLocation.of("shader/testing/vertex.vs"), AssetLocation.of("shader/testing/fragment.fs"), "in_position", "in_tex", "in_color");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import speiger.src.coreengine.assets.base.IAssetProvider;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
|
||||
public class Shader<T extends ShaderProgram> implements Supplier<T> {
|
||||
boolean registered = false;
|
||||
T program;
|
||||
Function<IAssetProvider, T> provider;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class Shader<T extends ShaderProgram> implements Supplier<T> {
|
||||
|
||||
public static <T extends ShaderProgram> Shader<T> createAndRegister(Function<IAssetProvider, T> provider) {
|
||||
Shader<T> shader = new Shader<>(provider);
|
||||
GLStateTracker.instance().shaders.register(shader);
|
||||
shader.register();
|
||||
return shader;
|
||||
}
|
||||
|
||||
@@ -34,6 +35,12 @@ public class Shader<T extends ShaderProgram> implements Supplier<T> {
|
||||
program.validateProgram();
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if(registered) throw new IllegalStateException("Shader is already registered!");
|
||||
registered = true;
|
||||
GLStateTracker.instance().shaders.register(this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(program == null) return;
|
||||
program.remove();
|
||||
@@ -45,6 +52,7 @@ public class Shader<T extends ShaderProgram> implements Supplier<T> {
|
||||
GLStateTracker.instance().shaders.remove(this);
|
||||
}
|
||||
|
||||
public void bind() { program.bind(); }
|
||||
@Override
|
||||
public T get() { return program; }
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public class ShaderTracker implements ISimpleRealodableAsset, IManagedAsset {
|
||||
}
|
||||
|
||||
private void load(IAssetProvider provider, Shader<?> shader) {
|
||||
if(provider == null) return;
|
||||
shader.load(provider);
|
||||
shader.validate();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import speiger.src.coreengine.rendering.utils.values.ShaderType;
|
||||
public abstract class SimpleShader extends ShaderProgram {
|
||||
|
||||
public SimpleShader(IAssetProvider provider, String identifer, AssetLocation vertex, AssetLocation fragment, String...attributes) {
|
||||
//TODO id is never set?
|
||||
loadOrGenerateCache(identifer, provider.getLatestTime(vertex, fragment), id -> {
|
||||
int vId = loadShader(provider, vertex, ShaderType.VERTEX);
|
||||
if(vId == -1) return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ public class CullState extends GLState {
|
||||
GLCullType state;
|
||||
|
||||
public CullState(GLCullType defaultState) {
|
||||
super(GL11.GL_CULL_FACE);
|
||||
super(GL11.GL_CULL_FACE, false);
|
||||
defaultValue = state = defaultState;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TextureState implements IGLState {
|
||||
public TextureState bind(int unit, int texture) {
|
||||
if(textures[unit] != texture) {
|
||||
this.textures[unit] = texture;
|
||||
GL45.glBindTextureUnit(unit, texture);
|
||||
GL45.glBindTextureUnit(GL20.GL_TEXTURE0 + unit, texture);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ public class IOUtils
|
||||
public static Path getBaseLocation() {
|
||||
try {
|
||||
Path path = Paths.get(IOUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
if(path.toString().endsWith(".jar")) return path;
|
||||
if(!path.toString().endsWith(".jar")) return path;
|
||||
}
|
||||
catch(Exception e) {}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
return Paths.get(".");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#version 330
|
||||
|
||||
in vec4 pass_color;
|
||||
in vec2 pass_tex;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_color = pass_color * texture2D(texture, pass_tex);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_tex;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
|
||||
out vec4 pass_color;
|
||||
out vec2 pass_tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
pass_color = in_color;
|
||||
pass_tex = in_tex;
|
||||
}
|
||||
Reference in New Issue
Block a user