[RFE] LWJGL 3.0

Started by spasi, November 08, 2012, 13:23:54

Previous topic - Next topic

spasi

LWJGL 2 doesn't support color-index mode either. It doesn't have any color-index function, but does have COLOR_INDEX & COLOR_INDEXES. I removed those from LWJGL 3, since they're pointless.

TheBoneJarmer

I'm not sure if this is lwjgl-related, but I had some serious trouble just now with GLFW. This is my code:

lesson1/Game.java
package lesson1;

import org.lwjgl.Sys;
import org.lwjgl.opengl.*;
import org.lwjgl.system.glfw.*;
 
import java.nio.ByteBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.glfw.GLFW.*;

public class Game {
	
	public void run() {
		Window.create(800,600,false);
								
		while (!Window.isClosed()) {
			//Window.clear();
			
			Window.update();
		}
		
		Window.destroy();
	}
}


lesson1/Window.java
package lesson1;

import org.lwjgl.Sys;
import org.lwjgl.opengl.*;
import org.lwjgl.system.glfw.*;
 
import java.nio.ByteBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.glfw.GLFW.*;

public class Window {
	
	//Variables
	private static long window;
	public static String title = "";
	
	//Getters
	public static boolean isClosed() { if (glfwWindowShouldClose(window) == 0) return false; else return true; }
	
	//Setters
	public static void setSize(int width,int height) { glfwSetWindowSize(window, width, height); }
	public static void setPosition(int x,int y) { glfwSetWindowPos(window,x,y); }
	
	//General functions
	public static void create(int width,int height, boolean fullscreen) {		
		if (glfwInit() == GL_FALSE) {
			System.err.println("[Window] Unable to initialize Window");
			System.exit(1);
		}
		
		if (!fullscreen) {
			window = glfwCreateWindow(width,height,"",NULL,NULL);
		} else {
			window = glfwCreateWindow(width,height,"",glfwGetPrimaryMonitor(),NULL);
		}
		
		if (window == GL_FALSE) {
			System.err.println("[Window] Unable to create window");
			System.exit(1);
		}
				
		glfwMakeContextCurrent(window);
		glfwSwapInterval(1);
		GLContext.createFromCurrent();
		
		Keyboard.init(window);
	}
	public static void close() {
		glfwSetWindowShouldClose(window, 1);
	}
	public static void clear() {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(1,1,1,0);
	}
	public static void update() {
		glfwSetWindowTitle(window,title);
		
		glfwSwapBuffers(window);
		glfwPollEvents();
	}
	public static void destroy() {
		glfwDestroyWindow(window);
		glfwTerminate();
	}
	public static void minimize() {
		glfwIconifyWindow(window);
	}
	public static void restore() {
		glfwRestoreWindow(window);
	}
	public static void hide() {
		glfwHideWindow(window);
	}
	public static void show() {
		glfwShowWindow(window);
	}
}


Program.java
import lesson1.Game;

public class Program {
	public static void main (String[] args) {
		Game game = new Game();
		game.run();
	}
}


I am running Ubuntu 14.04 LTS 64 bit. I compile this using the terminal. What happens is that my entire system crashes when I click the resize button. I was forced to reboot in order to get control again. However, if I uncomment the Window.clear() void everything works fine.

kappa

Quote from: spasi on November 15, 2014, 16:02:04
LWJGL 2 doesn't support color-index mode either. It doesn't have any color-index function, but does have COLOR_INDEX & COLOR_INDEXES. I removed those from LWJGL 3, since they're pointless.
Ah ok, only noticed this as its used in LWJGL2's GLU package and wasn't there when I was wrapping the API.

Anyway finished a first rough version of the wrapper for LWJGL2. It can run unmodified versions (except for package names) of LWJGL2's Gears and Space Invaders demo's. Only implemented the bare minimum require API so far.

Early source code here

1) For some reason not getting any sound on Linux 64bit (OpenSuse 13.1) although there is sound on both Win32 and OSX.

2) Had to use a different package name (org.lwjglx.*) to avoid conflicting with the LWJGL3 classes that have the same names, guess this could be worked around by either using some classloader voodoo or building a custom version of LWJGL3 which has different package names, this could then allow unmodified LWJGL2 apps to run on LWJGL3.

3) As for deployment, natives for Win32/Win64 and Linux32/64 have the same names, would make life a lot easier if they had different names (like LWJGL2 e.g. lwjgl64.dll, etc) as then you can put them all in one folder to make deployment easier, easier to identify which natives are what, and allowing the same "-Djava.library.path" path to be set once and it'll work for all platforms.

spasi

Quote from: TheBoneJarmer on November 15, 2014, 18:54:40
I'm not sure if this is lwjgl-related, but I had some serious trouble just now with GLFW. This is my code:

...

I am running Ubuntu 14.04 LTS 64 bit. I compile this using the terminal. What happens is that my entire system crashes when I click the resize button. I was forced to reboot in order to get control again. However, if I uncomment the Window.clear() void everything works fine.

I was able to reproduce this. It happens every time, without resizing the window. Using Window.clear() makes no difference, it's actually a bit better with it. I'm on OpenSuse 13.1, it doesn't crash, but the whole OS slows down to a crawl.

The fix is to not use glfwSetWindowTitle in the render loop. Linux does not do vsync (glfwSwapInterval(1)) in windowed mode, which means that your simple loop is called thousands of times per second. I don't think it's an LWJGL or GLFW issue, X simply cannot handle that many window title updates.

spasi

Quote from: kappa on November 15, 2014, 19:00:05
Anyway finished a first rough version of the wrapper for LWJGL2. It can run unmodified versions (except for package names) of LWJGL2's Gears and Space Invaders demo's. Only implemented the bare minimum require API so far.

Early source code here

Nice, good job!

Quote from: kappa on November 15, 2014, 19:00:051) For some reason not getting any sound on Linux 64bit (OpenSuse 13.1) although there is sound on both Win32 and OSX.

I'm on OpenSuse 13.1 too and OpenAL works fine. What's the output of org.lwjgl.demo.openal.ALCDemo on your machine?

Quote from: kappa on November 15, 2014, 19:00:052) Had to use a different package name (org.lwjglx.*) to avoid conflicting with the LWJGL3 classes that have the same names, guess this could be worked around by either using some classloader voodoo or building a custom version of LWJGL3 which has different package names, this could then allow unmodified LWJGL2 apps to run on LWJGL3.

There might be other options, if we really want to do this.

Quote from: kappa on November 15, 2014, 19:00:053) As for deployment, natives for Win32/Win64 and Linux32/64 have the same names, would make life a lot easier if they had different names (like LWJGL2 e.g. lwjgl64.dll, etc) as then you can put them all in one folder to make deployment easier, easier to identify which natives are what, and allowing the same "-Djava.library.path" path to be set once and it'll work for all platforms.

This makes the library initialization and build scripts unnecessarily complex, but you've got a point about deployment. I'll see what I can do.

kappa

Quote from: spasi on November 15, 2014, 19:52:13
I'm on OpenSuse 13.1 too and OpenAL works fine. What's the output of org.lwjgl.demo.openal.ALCDemo on your machine?

Also tried with ALCDemo, get the following output but don't hear anything
QuoteOpenALC10: true
OpenALC11: true
caps.ALC_EXT_EFX = true
0: No Output
Default device: OpenAL Soft
Waiting 5 seconds for sound to complete

Quote from: spasi on November 15, 2014, 19:52:13
Quote from: kappa on November 15, 2014, 19:00:052) Had to use a different package name (org.lwjglx.*) to avoid conflicting with the LWJGL3 classes that have the same names, guess this could be worked around by either using some classloader voodoo or building a custom version of LWJGL3 which has different package names, this could then allow unmodified LWJGL2 apps to run on LWJGL3.
There might be other options, if we really want to do this.
Yes don't wanna waste massive amounts of time on such a library because it'll eventually die once everyone switches to LWJGL3, but its not really much work (spent maybe an hour on the above and was a good learning experience for the LWJGL3 API), its just a matter of hooking up the corresponding Display calls to GLFW and the GL and AL stuff is pretty much the same (above already covers a good chunk of the LWJGL2 core). It doesn't need to cover the whole LWJGL2 API just the API's a target project is using. Could be nice for current LWJGL2 code bases (e.g. minecraft, puppygames, Spiral Knights, jME, etc) to trial LWJGL3 before deciding whether they want to commit to it or when LWJGL2 projects starts breaking on future platforms there could be quick fix library available. Anyway just curious, what other options did you have in mind?

spasi

Quote from: kappa on November 15, 2014, 20:15:06Also tried with ALCDemo, get the following output but don't hear anything
QuoteOpenALC10: true
OpenALC11: true
caps.ALC_EXT_EFX = true
0: No Output
Default device: OpenAL Soft
Waiting 5 seconds for sound to complete

Hmm. Could you please try the OpenAL binary from LWJGL 2? Does that work?

Quote from: kappa on November 15, 2014, 20:15:06Anyway just curious, what other options did you have in mind?

We could move LWJGL 3 classes, except bindings, to a new root: org.lwjgl3. It should simplify the emulation layer, but it's a bit inconvenient for new LWJGL 3 users and we'll have to publicly expose some package-private functionality.

kappa

Quote from: spasi on November 15, 2014, 20:19:54
Hmm. Could you please try the OpenAL binary from LWJGL 2? Does that work?
The OpenAL binary from LWJGL2 works nicely (renamed its libopenal64.so to libopenal.so), ALCDemo output is as follows:
QuoteOpenALC10: true
OpenALC11: true
caps.ALC_EXT_EFX = true
0: ALSA Default
1: HDA Intel, ALC888 Analog (CARD=Intel,DEV=0)
2: HDA Intel, ALC888 Digital (CARD=Intel,DEV=1)
3: HDA NVidia, HDMI 0 (CARD=NVidia,DEV=3)
4: HDA NVidia, HDMI 1 (CARD=NVidia,DEV=7)
5: HDA NVidia, HDMI 2 (CARD=NVidia,DEV=8)
6: HDA NVidia, HDMI 3 (CARD=NVidia,DEV=9)
Default device: OpenAL Soft
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead
Waiting 5 seconds for sound to complete

Quote from: spasi on November 15, 2014, 20:19:54
We could move LWJGL 3 classes, except bindings, to a new root: org.lwjgl3. It should simplify the emulation layer, but it's a bit inconvenient for new LWJGL 3 users and we'll have to publicly expose some package-private functionality.
Ah, better not to compromise any LWJGL3 niceness for such a library (since its not really that important), rather keep all the hackage and voodoo in the wrapper library.

spasi

Quote from: kappa on November 15, 2014, 20:32:50The OpenAL binary from LWJGL2 works nicely

I've stopped merging OpenAL Soft automatically from upstream. Seems a lot of unstable stuff are being pushed to the master branch. I have now reverted our nightly build to the 1.16 release (edit: nvm, I think I fixed it now), could you please try this binary?

kappa

Quote from: spasi on November 16, 2014, 12:21:14
Quote from: kappa on November 15, 2014, 20:32:50The OpenAL binary from LWJGL2 works nicely

I've stopped merging OpenAL Soft automatically from upstream. Seems a lot of unstable stuff are being pushed to the master branch. I have now reverted our nightly build to the 1.16 release (edit: nvm, I think I fixed it now), could you please try this binary?
Yup, can confirm that the binary above works fine.

spasi

Quote from: kappa on November 15, 2014, 19:00:053) As for deployment, natives for Win32/Win64 and Linux32/64 have the same names, would make life a lot easier if they had different names (like LWJGL2 e.g. lwjgl64.dll, etc) as then you can put them all in one folder to make deployment easier, easier to identify which natives are what, and allowing the same "-Djava.library.path" path to be set once and it'll work for all platforms.

I implemented a new method of loading native libraries, which solves the above issue. With the current build structure, you can simply point java.library.path or org.lwjgl.librarypath to the /native folder and it will work on all OSes and architectures.

I did my best to extensively test this (I think I tried everything except OpenCL on Linux) but please try the latest nightly and let me know if you have any issues.

spasi

See the blog for a fresh progress update.

kappa

Continuing to play with the LWJGL2 compatibility layer, implemented some more bits and can now run LWJake2 on LWJGL3 almost without any modifications to its code.



Some thoughts and hurdles I ran into:

- Finally with LWJGL3 we have sane keyboard key names (thx to GLFW) some of the LWJGL2's key names were pretty horrid (still haven't figured out what some of the keys are and how to correspond them to the ones in GLFW).

- The characters keys return with GLFW is really well implemented and supports unicode (something the non-english users will really like).

- Really loving the callbacks in GLFW makes code a lot simpler in places.

- The AL class is different in LWJGL3 although the changes are not too dramatic and do allow more flexibility but not as simple anymore as LWGL2's AL.create() and require more code to initialise.

- Had to wrap EFX for LWJGL2 compatibility as its no longer in the EFX10 class but in one called EXTEfx other than that the EFX API calls are the same.

- The extensions ARBMultitexture, EXTPointParameters & EXTSharedTexturePalette are used extensively in LWJake2 but missing in LWJGL3, so created wrappers for them (for
ARBMultitexture pointed the calls to corresponding GL13 calls, for EXTPointParameters created a wrapper which points to ARBPointParameters which is the same, for
EXTSharedTexturePalette there was only reference to an int called GL_SHARED_TEXTURE_PALETTE_EXT=33275 so just added that).

- came across the missing GL11.GL_COLOR_INDEX again, which is used quiet a lot in LWJake2, so replaced with public static final int GL_COLOR_INDEX = 6400;

- I still need to implement full screen support in the LWJGL2 compatibility layer, will probably try next to get it working in a bigger project like LibGDX, jME, etc.

Other than the above, it was a pretty smooth transition to getting LWJake2 working.

spasi

Awesome, thanks for the info. Addressing a few points:

- AL needs work in general. I'll also see if we can structure EFX better. Not saying it's going to be compatible with LWJGL 2, will prefer the design that makes more sense.

- I'll add the missing extensions asap and please let me know if you need more.

- I really wonder what GL_COLOR_INDEX is used for... If we're talking about a valid use-case I'll add all the missing functionality.

kappa

Quote from: spasi on November 23, 2014, 19:37:57
- I really wonder what GL_COLOR_INDEX is used for... If we're talking about a valid use-case I'll add all the missing functionality.
TBH, not really sure what its used for, seems like its one of the format options supported by glTexImage2D.
It also part of the OpenGL specs, the OpenGL docs say
QuoteGL_COLOR_INDEX
Each element is a single value, a color index. The GL converts it to fixed point (with an unspecified number of zero bits to the right of the binary point), shifted left or right depending on the value and sign of GL_INDEX_SHIFT, and added to GL_INDEX_OFFSET (see glPixelTransfer). The resulting index is converted to a set of color components using the GL_PIXEL_MAP_I_TO_R, GL_PIXEL_MAP_I_TO_G, GL_PIXEL_MAP_I_TO_B, and GL_PIXEL_MAP_I_TO_A tables, and clamped to the range [0,1].

Doing a quick google search for GL11.GL_COLOR_INDEX shows that its used in quiet a few other projects including, JPCSP (java psp emulator), Eclipse GEF3d, Ardor3d, github says 270 repo's use it.