onox/orka

Add keyboard support to KTX viewer tool

onox opened this issue · 12 comments

onox commented

Support changing the selected mipmap level. To render a higher mipmap level, call Texture.Set_Lowest_Mipmap_Level.

  • Add keyboard shortcuts
  • Support loading previous or next texture in directory of current texture
  • Flip view direction when toggling between internal/external view for cubemaps (in order to always stay pointed at the same face of the cubemap)

Keyboard support depends on #25.

Do you have a test KTX file I can use to test this tool? I pulled a couple from the Khronos test files but they all failed with a STORAGE_ERROR. I can provide the stack trace if needed.

onox commented

Could you post the stack trace? Which files exactly did raise the Storage_Error? Note that KTX2 is not supported yet.

Link to specifications:

Repositories with .ktx files:

Assert_Failure error raised in orka-ktx.adb line 86 for many files in scenes/

onox commented

It seems that many .ktx files in Vulkan-Samples-Assets in scenes/ folder have an incorrect glTypeSize. The textures are compressed (glType = 0) and therefore glTypeSize must be 1, but in the files it is 0. I'll modify the assertions to allow 0 | 1 if the texture is compressed. That should fix the Assert_Failure in orka-ktx.adb.

Fixed in #63.

onox commented

@Rodeo-McCabe Btw, you can create screenshots in your app by calling Orka.Resources.Textures.KTX.Write_Texture. This will save a Texture object to a .ktx file. If you use a Texture_Cube_Map texture, you could create a 360 deg screenshot 😄

Ok here is the output from orka-ktx rgb-reference.ktx:

Error: raised STORAGE_ERROR : s-intman.adb:136 explicit raise
Call stack traceback locations:
0x7fc167f2d4b4 0x7fc167b4b95e 0x7fc16826bdb7 0x5643db62d34f 0x5643db61ef97 0x7fc167975000 0x5643db61f00c 0xfffffffffffffffe

This is from the most recent master branch. I rebuilt and reinstalled Orka, rebuilt the examples, and rebuilt the tools before running.

onox commented

I can view that file perfectly. It's 128 x 128 with SRGB8 (3x Unsigned_Byte). Did you compile and install GLFW 3.3?

I didn't compile GLFW from source, since Manjaro provides a package:

$ pacman -Qs glfw
local/glfw-wayland 3.3.2-1
    A free, open source, portable framework for graphical application development (wayland)

I realize I was actually trying to run in an X session, which I think is not supported. Running in a Wayland session also produces an error:

$ ./orka-ktx rbg-reference.ktx
[00:00:00.066358 ERROR] [WINDOW_SYSTEM:OTHER] GLFW PLATFORM_ERROR: Wayland: Focusing a window requires user interaction
Error: raised STORAGE_ERROR : s-intman.adb:136 explicit raise
Call stack traceback locations:
0x7f5fc061b4b4 0x7f5fc023995e 0x7f5fc0954db7 0x560230c7b34f 0x560230c6cf97 0x7f5fc0063000 0x560230c6d00c 0xfffffffffffffffe

^C

Note that I have to manually end the process with Ctrl-C, which I thought was strange. Also note the error from GLFW "Focusing a window requires user interaction". I am using Sway, a tiling window manager, so I wonder if this could be affecting it?

onox commented

This is very strange. I use Sway as well (with no Xwayland). The error about focusing is harmless and happens because the windows created by GLFW are focused by default.

The reason you have to do Ctrl-C is probably because either the workers and/or resource loader tasks are still running.

Could you try to add some Ada.Text_IO.Put_Line calls in various places in src/tools/orka_ktx.adb?

Does the error happen with other .ktx files? Can you succesfully run orka-info and the examples?

I just tried with a couple other .ktx files, and had the same error. Everything else ran fine except example 10, which had an overflow check error, and examples 12 and 14, in which the space bar did not work. I can open separate issues for these.

Worth noting is that most of the examples ran fine in an X session. I only just installed Sway to troubleshoot this issue, and the only way I could get Sway to work was removing the proprietary Nvidia drivers. I now have only Nouveau and Mesa for graphics drivers. I think Sway doesn't support Nvidia, could this be the problem?

I will continue to investigate with print statements and update if I find something.

onox commented

examples 12 and 14, in which the space bar did not work. I can open separate issues for these.

The space bar is temporarily broken until I add back keyboard handling in #25.

I now have only Nouveau and Mesa for graphics drivers. I think Sway doesn't support Nvidia, could this be the problem?

Sway doesn't support the proprietary drivers from Nvidia, but the Nouveau drivers should be fine for Sway.

After stepping through with a debugger, the problem lies in Orka.Cameras.Rotate_Around_Cameras.Create_Camera A segfault occurs at this call.

In orka_ktx.adb, line 146:

Current_Camera : constant Camera_Ptr
              := new Camera'Class'(Camera'Class
                   (Rotate_Around_Cameras.Create_Camera (Window.Pointer_Input, Lens, FB_D)));

The Package'Class'(...) and Package'Class(...) notation I've never seen before. Note the extra '. What is this notation called? I don't really understand what's happening here.

onox commented

It's actually Type'Class(...) because of the use statement above it.

Type'Class (...) is a type conversion, while Type'Class'(...) is a type qualification (a hint to the compiler how to interpret some data when there is ambiguity). With the new keyword in front of it, it should create a new object on the heap. However, I've seen before with the jobs system that the compiler doesn't properly create it when it's a class-wide type.

In a VM (Arch Linux), orka-ktx runs fine, but one of the examples doesn't (number 12). I get a segfault near Create_Camera as well. But other examples run fine again. I only managed to work around it by completely disabling the camera code in that example. I think the Cameras and Loops packages have to be rewritten basically.

Anyway, to fix the ktx tool, remove Orka.Loops (removing everything that uses Loops) and do this instead:

while not Window.Should_Close loop
   Window.Process_Input;
--   Camera.Update (0.01666);  --  (to update a camera without Orka.Loops)

   FB_D.Clear;

   --  TODO Add the original loop code here

   Window.Swap_Buffers;
end loop;