Skip to content

LwjglCanvas using lwjgl-jawt #2153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 5, 2024

Conversation

JNightRider
Copy link
Contributor

Would this be an acceptable solution for now?

This solves the problem of integrating https://github.com/LWJGLX/lwjgl3-awt (#1868)

There is just one small detail, removing the canvas from its main component and integrating it again breaks it. This issue occurs on the lwjgl3-awt side (LWJGLX/lwjgl3-awt#40)

@DontingK
Copy link

extends LwjglContext ,LwjglWindow , Which one is better? LwjglWindow Mainly to initialize glfw window

@tonihele
Copy link
Contributor

tonihele commented Dec 1, 2023

This would solve #1192 and make #1868 obsolete.

I didn't test it. But code wise it looks good. Very simple (or rather low LoC count :) ).

synchronized (lock) {
canvas.deleteContext();
}
//// request the cleanup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in comments generally should not be. Is this something that is incomplete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be there, I forgot to delete it. Sorry for causing confusion...

@tonihele
Copy link
Contributor

I tried to test this but I couldn't get it running. I was always greeted with:
image
And the appsettings at least indicate I have renderer set accordingly

@JNightRider
Copy link
Contributor Author

JNightRider commented Dec 18, 2023

Did you check the dependencies?; You might be using lwjgl (on my Linux it throws a lot of errors)

Captura desde 2023-12-17 19-59-17

In the examples module I did not change anything (in the tests I did but I reverted the changes)

It looks like a version issue... if so, it's probably line 199 (working to locate the error).

@tonihele
Copy link
Contributor

It looks like a version issue... if so, it's probably line 199 (working to locate the error).

Yeah, if I just remove glData.profile = GLData.Profile.CORE;, then it works. But it is a little bit volatile then:

  • Closing the app causes NPE (at LwjglAWTGLCanvas.deleteContext)
  • Switching the canvas to another tab just results in a black canvas. I can't see the cube anymore

I'm talking about the jme3test.awt.TestCanvas.

@tonihele
Copy link
Contributor

To actually use the profiles you need to do as the error message I posted, but it of course refers to the library settings:

        glData.majorVersion = 3;
        glData.minorVersion = 2;
        glData.profile = GLData.Profile.CORE;

The above works but the canvas is just black and the test cube is not showing.

@tonihele
Copy link
Contributor

Core profile I didn't get to work. Compatibility profile works. Here is an example how I tested this then to conform to jME's rendered setting (although I'm not sure if this is required or not...). But note that these didn't fix any of the problems encountered:

private static final Map<String, Consumer<GLData>> RENDER_CONFIGS = new HashMap<>();

    static {
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL30, (data) -> {
            data.majorVersion = 3;
            data.minorVersion = 0;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL31, (data) -> {
            data.majorVersion = 3;
            data.minorVersion = 1;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL32, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 3;
            data.minorVersion = 2;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL33, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 3;
            data.minorVersion = 3;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL40, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 0;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL41, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 1;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL42, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 2;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL43, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 3;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL44, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 4;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
        RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL45, (data) -> {
            data.forwardCompatible = true;
            data.majorVersion = 4;
            data.minorVersion = 5;
            data.profile = GLData.Profile.COMPATIBILITY;
        });
    }
        RENDER_CONFIGS.computeIfAbsent(settings.getRenderer(), (t) -> {
            return (data) -> {
                data.majorVersion = 2;
                data.minorVersion = 0;
            };
        }).accept(glData);

@JNightRider
Copy link
Contributor Author

  • Switching the canvas to another tab just results in a black canvas. I can't see the cube anymore

As I mentioned before, removing the canvas from the parent component and adding it back (or to any other component) breaks it, which is a problem that lwjgl3-awt currently has; TestCanvas performs this same procedure (removing the canvas).

  • Closing the app causes NPE (at LwjglAWTGLCanvas.deleteContext)

This is an unexpected issue, thanks for reporting; Just out of curiosity, what operating system are you using (version)

@JNightRider
Copy link
Contributor Author

To actually use the profiles you need to do as the error message I posted, but it of course refers to the library settings:

        glData.majorVersion = 3;
        glData.minorVersion = 2;
        glData.profile = GLData.Profile.CORE;

The above works but the canvas is just black and the test cube is not showing.

Still trying to switch tabs?

@tonihele
Copy link
Contributor

This is an unexpected issue, thanks for reporting; Just out of curiosity, what operating system are you using (version)

Windows 10.

Still trying to switch tabs?

No, this was just in general. I was trying stuff out. As the CORE profile doesn't work at all for me.

@JNightRider
Copy link
Contributor Author

No, this was just in general. I was trying stuff out. As the CORE profile doesn't work at all for me.

When setting data.forwardCompatible = true to true, for some reason they don't work even though the lwjgl3-awt documentation recommends it... strange; For now this should work.

*Closing the app causes NPE (at LwjglAWTGLCanvas.deleteContext)

Now, it's pending... I'm testing on Windows 10 to fix it...

@JNightRider
Copy link
Contributor Author

At the moment I can run it on Windows-10 and there is no problem with Linux.

@JNightRider
Copy link
Contributor Author

JNightRider commented Dec 27, 2023

With this patch (if it can be considered), LwjglCanvas works with Linux without problems (100%)

  • Now you can delete and re-add the canvas without any problem.

Now I'm working on getting it to work with Windows, MacOS shouldn't be a problem.

@scenemax3d
Copy link
Contributor

With this patch (if it can be considered), LwjglCanvas works with Linux without problems (100%)

  • Now you can delete and re-add the canvas without any problem.

Now I'm working on getting it to work with Windows, MacOS shouldn't be a problem.

Hi,
What is the status of getting it to work with Windows / MacOS ?
Is there anything preventing us from merging it to v3.7.0?
Thanks :)

@JNightRider
Copy link
Contributor Author

JNightRider commented Jan 12, 2024

What is the status of getting it to work with Windows / MacOS ?

In the case of Windows it is currently pending. The option to remove and re-add the canvas is the only issue present.

Regarding MacOS; Removing and re-adding the canvas is no problem (it basically totally works; according to the lwjgl3-awt guys),

Is there anything preventing us from merging it to v3.7.0?

The Windows platform that still has the aforementioned problem.

@tonihele
Copy link
Contributor

Looks like #1868 just went in. I suppose that is ok, it should not cause any harm. But I'm in favor of overwriting the said PR with this. As this is hardware accelerated, a real solution to the problem.

@scenemax3d
Copy link
Contributor

Looks like #1868 just went in. I suppose that is ok, it should not cause any harm. But I'm in favor of overwriting the said PR with this. As this is hardware accelerated, a real solution to the problem.

Yes. there is a current pending issue with Windows. I will merge it as soon as it is resolved

@scenemax3d
Copy link
Contributor

Hi @JNightRide
You mentioned in the forum that more commits are planned for this PR.
What is your estimation for adding them?

@tonihele - if we decide to merge this PR, should we need to pay attention to some of your #1868 PR code or we can just merge this PR as-is without warring about the changes that you have made?

Thanks :)

@JNightRider
Copy link
Contributor Author

JNightRider commented Jan 30, 2024

What is your estimation for adding them?

To answer this question.

  • I should first mention that the "commits" I plan to release are bugfixes (JME3 side) and javadoc.
  • It is possible that it will be finished on February 4.

[ NOTE ]
This PR still has a conflict with Windows (the issue of removing and re-adding the canvas).

This current issue is on the lwjgl3-awt side, it can't be patched from JME3 (as far as I know), lwjgl3-awt may need to be modified to fix it (source code), I'm working on it; However, at the moment I do not have the time necessary to present a definitive solution.

Is JME3 willing to accept this "PR"? And in a future version (3.7.x), this issue may be fixed.

@scenemax3d
Copy link
Contributor

  • It is possible that it will be finished on February 4.
    Excellent! thank you.

Is JME3 willing to accept this "PR"? And in a future version (3.7.x), this issue may be fixed
I will get the core dev. advise and get back with answer

@tonihele
Copy link
Contributor

tonihele commented Feb 1, 2024

@tonihele - if we decide to merge this PR, should we need to pay attention to some of your #1868 PR code or we can just merge this PR as-is without warring about the changes that you have made?

This can and should override my PR. No need to worry about the stuff I made.

Merge conflicts just no need to be resolved accordingly.

Also notable that as of currently this PR will change jme-examples to run on LWJGL 3. I suppose this is fine as we should really start advocating it as default.

@@ -172,6 +172,10 @@ public void actionPerformed(ActionEvent e) {
currentPanel.remove(canvas);
app.stop(true);

try {
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test yes but looks like a hack of sorts. Better at least to comment why this is needed. Should consumer add this to their production code?

Copy link
Contributor Author

@JNightRider JNightRider Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should consumer add this to their production code?

It is an important part for lwjgl3-awt to work correctly (the consumer will have to implement it), in the pending commits I plan to document this part.

[ EDIT ]
It's better to have "LwjglCanvas" handle this internally (I'll put it on my list of things to fix).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to have "LwjglCanvas" handle this internally (I'll put it on my list of things to fix).

Definitely. Optimally users should not care whether they are running LWJGL 2 or 3. Identical code should work. Any shenanigans should be hidden from the user (exist in the library itself).

@@ -234,7 +238,7 @@ public static void createCanvas(String appClass){
}

public static void startApp(){
app.startCanvas();
/*app.startCanvas();*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in comments are bad. Also this test should still work on both LWJGL 2 and LWJGL 3. I think it is important that LwjglCanvas works the same. It should handle all disparities internally and not require any shenanigans from the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction in pending commits....

@riccardobl
Copy link
Member

riccardobl commented Feb 2, 2024

Thanks for your PR 💯

Anyone can test this with Wayland on linux? It seems it is using X11 apis, so i wonder if it will work as expected

@riccardobl
Copy link
Member

There is just one small detail, removing the canvas from its main component and integrating it again breaks it. This issue occurs on the lwjgl3-awt side (LWJGLX/lwjgl3-awt#40)

Can you add a test to reproduce this issue?

@tonihele
Copy link
Contributor

tonihele commented Feb 2, 2024

Can you add a test to reproduce this issue?

There is the https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/awt/TestCanvas.java general test. It has the context menu where this can be caused.

@JNightRider
Copy link
Contributor Author

With this, this PR now has the necessary documentation and reported bug fixes.

@JNightRider
Copy link
Contributor Author

Can you add a test to reproduce this issue?

It seems that this question has already been answered for you; Thank you @tonihele for your quick response.

@scenemax3d scenemax3d added this to the v3.7.0 milestone Feb 5, 2024
@scenemax3d scenemax3d merged commit 22bf58a into jMonkeyEngine:master Feb 5, 2024
@tonihele
Copy link
Contributor

tonihele commented Feb 6, 2024

Note that this PR changed the jME tests to run on LWJGL3. While this is fine and desirable. Our TestChooser is still written in Swing, and by using TestChooser people might run into errors...

@JNightRider JNightRider deleted the LwjglCanvas_lwjgl-jawt branch February 15, 2024 23:18
@stephengold stephengold mentioned this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants