Requesting help and permission to use code

Discussion and questions about programming with Ultibo.
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Requesting help and permission to use code

Postby JPNotADragon » Tue May 08, 2018 11:20 am

Hi!

I'm exploring the possibility the make the Castle Game Engine (https://castle-engine.io/index.php) work on the Raspberry Pi without the X server. While looking for ways to integrate the Broadcom libraries, I came across the Ultibo project, and found first the dispmanx unit.

I tried to add that unit to the game engine, but naturally, that was only the top of a rather big dependency tree. While adding the first of those dependencies, I noticed that while dispmanx.pas itself had {$ifdef ultibo}..{$endif} guards around Ultibo-specific code, the dependencies apparently don't, and my knowledge about the RPi is woefully insufficient to decide what to cut out and/or replace, and with what.

I'm in danger of getting overwhelmed here, so I'm asking for both permission to use, and help on how to adapt, your VC-related units. The overall idea is to make the game engine run under Raspbian (without X - it should already work under X), and later with Ultibo itself - just because it would be so cool to have an OS-less version of the game engine :-). That second part should actually have become easy by the time the first part is working.

Thanks in advance for any help you can give me.
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Requesting help and permission to use code

Postby Ultibo » Tue May 08, 2018 12:40 pm

Hi JPNotADragon!

JPNotADragon wrote:I'm in danger of getting overwhelmed here, so I'm asking for both permission to use, and help on how to adapt, your VC-related units. The overall idea is to make the game engine run under Raspbian (without X - it should already work under X), and later with Ultibo itself - just because it would be so cool to have an OS-less version of the game engine :-). That second part should actually have become easy by the time the first part is working.

It would indeed be cool to have a game engine that runs without an OS, and while we are missing a couple of the things you need we have most of them already.

Back to your questions, as far as I can see Castle uses the same license as Ultibo so there should not be any issues with using relevant bits of code to help with your goal.

We (by necessity) understand pretty well how the VC4 interfaces work now and a lot of the details about what connects to what so we can probably answer some questions for you. I'm not sure the best way to go about it but maybe if you can tell us what you are looking for we can start from there, at a guess you probably want to get OpenGL (or more correctly GL ES) going first of all because Castle seems to depend on that.

I'm not sure if that is exactly what you had in mind, if not we can talk about other ideas and see where it goes.
Ultibo.org | Make something amazing
https://ultibo.org
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Tue May 08, 2018 2:03 pm

Thank you very much for your fast and encouraging response! Let me see if I can clearly formulate what I need at this point.

The first step is to implement the so called window "backend", which basically consists of obtaining a display surface and making it available to the game engin (which indeed can use either OpenGL - preferred - or OpenGL ES for rendering - with some restrictions at this time).

In C, I had already succeeded in displaying a red square without X by following instructions found in the eBook "Raspberry Pi GPU Audio Video Programming" by Jan Newmarch. So, my initial approach was to try and convert the Raspi C headers to Pascal files (.pas and .inc). I discovered that h2pas is not up to that task, tried to use the Ultibo files instead, and ran into problems with the dependencies branching out too wide and far.

Maybe this is enough for you to point me in right direction ? I'm looking for a way to get the absolute minimum at this time to get started.
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Tue May 08, 2018 5:55 pm

Perhaps a good question to ask would be: when integrating the VC4 libraries, particularly when converting the headers, what are the places where Ultibo deviated from strict 1:1 conversion, and why ?
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Requesting help and permission to use code

Postby Ultibo » Wed May 09, 2018 1:01 am

JPNotADragon wrote:Perhaps a good question to ask would be: when integrating the VC4 libraries, particularly when converting the headers, what are the places where Ultibo deviated from strict 1:1 conversion, and why ?

Let me answer that part first, the Ultibo version of the VC4 libraries are currently static only because we don't yet support loading dynamic libraries. That means that in each of the headers we made changes to allow for statically loading the libraries rather than the more conventional dynamic loading.

The bigger part of the difference in the Ultibo implementation is because we don't have Linux to rely on for services so everything is implemented in Ultibo including the magical and mysterious (well it used to be anyway) VCHIQ driver that provides the actual communication between the OpenGL, EGL and DispmanX libraries and the GPU which does the real work.

You will see that our units include a VC4 unit that has no equivalent on other platforms, this unit does all the work of initializing the interface to the GPU and starting the VCHIQ protocol which under Raspbian happens in a kernel driver somewhere.

JPNotADragon wrote:The first step is to implement the so called window "backend", which basically consists of obtaining a display surface and making it available to the game engin (which indeed can use either OpenGL - preferred - or OpenGL ES for rendering - with some restrictions at this time).

In C, I had already succeeded in displaying a red square without X by following instructions found in the eBook "Raspberry Pi GPU Audio Video Programming" by Jan Newmarch. So, my initial approach was to try and convert the Raspi C headers to Pascal files (.pas and .inc). I discovered that h2pas is not up to that task, tried to use the Ultibo files instead, and ran into problems with the dependencies branching out too wide and far.

To get the first steps working in Raspbian using FPC/Lazarus should be straightforward enough and once you have that it will be a lot clearer how to make use of the other functionality.

I don't know if Castle uses OpenGL ES 1.1 or 2.0 but the Pi supports both, these are the links for the Ultibo ports of the GLES11 and GLES2 units, as above these have been modified from the standard ones included with FPC to support static linking and to include (where needed) the VC4 unit and some other Ultibo specifics.

OpenGL ES depends on EGL to provide the drawing interface, the Ultibo port of that can be found here and if you leave out the Ultibo specific elements it should work under Raspbian as well.

In order to get anything to work with OpenGL on the Pi there is some mandatory setup steps that need to occur, you've already seen some of that if you followed the DispmanX example to draw a square on the screen. Ultibo includes two pure pascal OpenGL ES examples (one for 1.1 and one for 2.0) which show the setup process and again if you leave out the Ultibo specifics it should readily translate to FPC on Raspbian.

The OpenGL ES 1.1 example is here and the 2.0 example is here, you can look at both to see the minor differences in the setup process, both of these examples show the classic rotating 3D cube.

If you look at the GLESUnit you will see the GLESInit function which does most of the setup, in fact you should recognize some items from your DispmanX example in C.

The only other mandatory element of the setup process is the call to BCMHostInit (bcm_host_init) which must happen before anything else, you can find the declarations for that call (and several other BCM host functions) in the VC4 unit, those few functions will be about all you need from VC4 so you can simply extract them to your own code.

I hope that helps, see what you can follow and how far you get then come back and ask any other questions that you have.
Ultibo.org | Make something amazing
https://ultibo.org
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Wed May 09, 2018 8:34 am

Ultibo wrote:Let me answer that part first, the Ultibo version of the VC4 libraries are currently static only because we don't yet support loading dynamic libraries. That means that in each of the headers we made changes to allow for statically loading the libraries rather than the more conventional dynamic loading.


I hadn't really noticed that - I'm unfortunately a bit new to freepascal as well (worked with Delphi years ago). I'm actually rather surprised that Ultibo, not being an OS, intends to support dynamic loading at all.

Ultibo wrote:You will see that our units include a VC4 unit that has no equivalent on other platforms, this unit does all the work of initializing the interface to the GPU and starting the VCHIQ protocol which under Raspbian happens in a kernel driver somewhere.


Does that mean that I can remove that unit and all its dependencies that aren't imported by any other unit?

Ultibo wrote:To get the first steps working in Raspbian using FPC/Lazarus should be straightforward enough and once you have that it will be a lot clearer how to make use of the other functionality.


That sounds like a really good idea. I may have been trying to skip one or more steps here.

Ultibo wrote:I don't know if Castle uses OpenGL ES 1.1 or 2.0 but the Pi supports both, these are the links for the Ultibo ports of the GLES11 and GLES2 units, as above these have been modified from the standard ones included with FPC to support static linking and to include (where needed) the VC4 unit and some other Ultibo specifics.


We will probably be able to use the original versions. We'll just have to be careful to use the right versions (yours) when the time comes to make CGE work as part of Ultibo.

Ultibo wrote:OpenGL ES depends on EGL to provide the drawing interface, the Ultibo port of that can be found here and if you leave out the Ultibo specific elements it should work under Raspbian as well.


Excellent, that will be a great help.

Ultibo wrote:In order to get anything to work with OpenGL on the Pi there is some mandatory setup steps that need to occur, you've already seen some of that if you followed the DispmanX example to draw a square on the screen. Ultibo includes two pure pascal OpenGL ES examples (one for 1.1 and one for 2.0) which show the setup process and again if you leave out the Ultibo specifics it should readily translate to FPC on Raspbian.

The OpenGL ES 1.1 example is here and the 2.0 example is here, you can look at both to see the minor differences in the setup process, both of these examples show the classic rotating 3D cube.

If you look at the GLESUnit you will see the GLESInit function which does most of the setup, in fact you should recognize some items from your DispmanX example in C.

The only other mandatory element of the setup process is the call to BCMHostInit (bcm_host_init) which must happen before anything else, you can find the declarations for that call (and several other BCM host functions) in the VC4 unit, those few functions will be about all you need from VC4 so you can simply extract them to your own code.


I'm beginning to feel more hopeful again :-)

Ultibo wrote:I hope that helps, see what you can follow and how far you get then come back and ask any other questions that you have.


Thank you so much! I look forward to getting back to work on this, possibly as early as tonight.

As for further questions: do you know the chat tool called Discord ? It was created for gamers, but it has proven very effective in the CGE project. You can post screenshots with ease, and you can post code by surrounding it with triple backticks (as in Markdown).
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Requesting help and permission to use code

Postby Ultibo » Wed May 09, 2018 11:15 am

JPNotADragon wrote:Does that mean that I can remove that unit and all its dependencies that aren't imported by any other unit?

Yes, you won't need the VC4 unit except for the BCMHost functions it defines.

JPNotADragon wrote:As for further questions: do you know the chat tool called Discord ?

May have heard of it, never used it though. We like to keep discussion that might be useful to others on the forum here so it is available later, however something else could work if there are occasional nitty gritty questions about porting etc. The fact we are in Australia might make timezones tricky, in that case email is also an option.
Ultibo.org | Make something amazing
https://ultibo.org
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Thu May 10, 2018 12:39 pm

Working on cannibalizing VC4.pas for my first test program... found a problem at line 595: the comment is not being closed. (EDIT: just reporting, not needing help on that particular "issue" :-) )
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Thu May 10, 2018 2:08 pm

I found the datatype cunsigned int the bcm_host section of VC4.pas. That type appears to be specific to your fork of the compiler, correct ? I have replaced it with NativeUInt for now.
JPNotADragon
Posts: 10
Joined: Tue May 08, 2018 11:05 am

Re: Requesting help and permission to use code

Postby JPNotADragon » Thu May 10, 2018 9:54 pm

I have experimentally reduced VC4.pas to a form that compiles, but I'm getting linker errors. It should be easy to remove those, and I'll try that tomorrow, but could you tell me a little about what they are, and why my linker can't find them ?

Code: Select all

/usr/bin/ld.bfd: cannot find -lilclient
/usr/bin/ld.bfd: cannot find -lmmal_omx
/usr/bin/ld.bfd: cannot find -lmmal_omxutil
/usr/bin/ld.bfd: cannot find -lreader_asf
/usr/bin/ld.bfd: cannot find -lreader_avi
/usr/bin/ld.bfd: cannot find -lreader_binary
/usr/bin/ld.bfd: cannot find -lreader_flv
/usr/bin/ld.bfd: cannot find -lreader_metadata_id3
/usr/bin/ld.bfd: cannot find -lreader_mkv
/usr/bin/ld.bfd: cannot find -lreader_mp4
/usr/bin/ld.bfd: cannot find -lreader_mpga
/usr/bin/ld.bfd: cannot find -lreader_ps
/usr/bin/ld.bfd: cannot find -lreader_qsynth
/usr/bin/ld.bfd: cannot find -lreader_raw_video
/usr/bin/ld.bfd: cannot find -lreader_rcv
/usr/bin/ld.bfd: cannot find -lreader_rtp
/usr/bin/ld.bfd: cannot find -lreader_rtsp
/usr/bin/ld.bfd: cannot find -lreader_rv9
/usr/bin/ld.bfd: cannot find -lreader_simple
/usr/bin/ld.bfd: cannot find -lreader_wav
/usr/bin/ld.bfd: cannot find -lwriter_asf
/usr/bin/ld.bfd: cannot find -lwriter_avi
/usr/bin/ld.bfd: cannot find -lwriter_binary
/usr/bin/ld.bfd: cannot find -lwriter_dummy
/usr/bin/ld.bfd: cannot find -lwriter_mp4
/usr/bin/ld.bfd: cannot find -lwriter_raw_video
/usr/bin/ld.bfd: cannot find -lwriter_simple
/usr/bin/ld.bfd: cannot find -lbrcmjpeg

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests