[fpc-pascal] Android porting ideas

Ryan Joseph ryan at thealchemistguild.com
Tue Feb 23 03:43:47 CET 2016


> On Feb 23, 2016, at 8:30 AM, Michalis Kamburelis <michalis.kambi at gmail.com> wrote:
> 
> It looks like the majority of the startup code is in castlewindow_android but I was expected to see an OpenGL context (surface view I think in Android). How do you render OpenGL then?
> 
> 
> castlewindow_android.inc does
> 
>   {$I castlewindow_egl.inc}
> 
> and the code that initializes OpenGLES context is inside castlewindow_egl.inc. It's using EGL library, https://www.khronos.org/registry/egl/ , specification blessed by Khronos, available on Android, able to initialize OpenGL ES context.
> 
> It can also be used to initialize OpenGL ES context on the desktops (which is useful to test OpenGL ES renderer on Linux, Windows etc.). That's why the code is not inside castlewindow_android.inc --- it's more generally useful.
> 

I see now! I’m using OpenGLES 1.x but I think I can use the EGL window functions you have translated in your OpenGLES 2 unit.

> So UNIX I/O “works” but you can’t read anything without the asset manager? That doesn’t really make sense but either way using the Asset manager in a stream like you did is just fine. I only need to read the contents of images and XML files anyways.
> 
> 
> UNIX I/O works for reading files. On disk (device internal memory, sdcard etc.).
> 
> It doesn't work to read stuff from the apk. Because the files you put inside apk ("assets" in Android terminology) are not available to you as normal files inside the Android application. You don't know where (and if, at all) they are unpackaged on the Android filesystem. You can only access them (read-only) using AssetManager.

Ok. I need to learn about the file system more then.

> 
> I was using ReadXMLFile to read the XML file but I assume this is just a helper function that wraps something lower level I could use in conjunction with the asset manager. Is that correct? Can’t find your code for this.
> 
> 
> See the URLReadXML implementation:
> 
> procedure URLReadXML(out Doc: TXMLDocument; const URL: String);
> var
>  Stream: TStream;
> begin
>  Doc := nil; // clean "out" param at start, just like ReadXMLFile
>  Stream := Download(URL, []);
>  try
>    ReadXMLFile(Doc, Stream);
>  finally FreeAndNil(Stream) end;
> end;
> 
> So it simply reads URL to a TStream, then uses overloaded ReadXMLFile version that reads XML from a stream:)
> So internally Android just uses the same C libraries we were using in Pascal? I guess that makes sense but I was thinking EVERYTHING on the system was now Java but that’s not the case I guess. The lesson here is that Android is built on Linux so we’re sharing more than I think.

This will probably make more sense when I learn about the asset manager more. I think I read there is a format like asset:// for file URL’s.

Thanks again!



Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list