GapiDraw 3.5 dll for emulator
I'm currently implementing a .net wrapper for GapiDraw 3.5. It comes with some precompiled dlls for the arm and mips processor and such...but is there a dll for the emulator?
I don't personally own a device, so I need to do my testing on the emulator.
Hi,
We'll include an emulator DLL in the 3.51 update due out in February. If you want it before that just email me and I'll se what I can do.
Regards,
Johan
How are the progress on the .NET wrapper so far, Kiyote?
I'm interested in this because the current GapiDrawNet wrapper (by Mr X) is for version 3.01, which doesn't include the new HIRES support for VGA devices, and I haven't the slightest clue on where to start writing my own wrapper.
Slowly. There is approximately 1 metric buttload of API to convert and test. And sometimes I'm guessing as to how to markup some of the parameters.
I'm making sure that I don't look at that other fellows conversion, since I don't want any accusations of theft...which of course hampers my progress.

Alright, slow progress is better than no progress I guess

I can post my Interop once I'm done, if you want. I'm going to create wrapper classes as well, but once the Interop is done you could theoretically just start on your own.
Johan,
In GapiDraw.h, you have the line(193):
GDERR_FRAMETIMEOVERFLOW = ((HRESULT)0x486600f0)
Shouldn't that be 0x
C86600f0?
Just wondering about the inconsistency.

Johan,
One more question for now. I don't suppose you have a list somewhere of what functions can return what error codes, do you?
ie -
Method:
CGapiSurface_CreateSurfaceFromMem
Can Return:
GDERR_OUTOFMEMORY
GDERR_INVALIDPARAMS
GDERR_INVALIDBITMAP
Kiyote: The first digit in the error codes describes the critical level of the return code. 4 is not an error (more of a notification), where C is an error. Values less than 0x8000 0000 are not "errors", but warnings. This is from the Microsoft DirectX standard.
The online documentation lists all possible return values for each function (CGapiSurface_CreateSurfaceFromMem is a wrapper for CGapiSurface::CreateSurface)
Johan,
Thanks for clearing that up. I wasn't trying to find an error in the code or anything like that, I just wanted to be sure I was reading everything correctly.
Also, the dll that you sent me does not appear to have been compiled with the "flattened" API function calls. I dumped the headers and it appears that only C++ style function calls are embedded in the dll. Looking in the gd301.dll reveals all sorts of function calls that I would expect.
ie - ??0CGapiBitmapFont@@QAE@ABV0@@Z in the current DLL and _CGapiBitmapFont_Create@0 in the older DLL. (Well, the original call is in there too)
Do you know what happened to those routines? I have finally completed a partial set of wrapper objects and went to test and get nothing but "missing method exception".

Kiyote: You are correct. Sorry for the mistake. Please email me again and I'll send you the updated DLL and "GapiDrawNet.h" include file.
I sent you a PM with my email address. Thanks for your prompt attention to this matter. Your responsiveness is amazing.
Thank you.

I'll do the recompile tomorrow morning and send it to you.
It's great to know that someone is active in the making of this. Im really looking forward to a test build

Well, just so you know, my primary concern is making it work under the Compact Framework. I want to get all of the objects wrapped up and exposing the GapiDraw API as well as adding some helper functions of my own.
The least of my concerns right now is emulating the GapiApplication since my intended usage is a manual frame-flipping system, not a high action game.
Just warning you.

Since I know at least one person is waiting on this, I thought I'd make a bit of a mini-progress update.
The API conversion is complete. I have wrapped up CGapiDraw, CGapiDisplay and CGapiSurface. I have written a quick app to test and I have been able to create a display and draw some loaded images on it.
If you're interested in a sneak-peek, let me know and I'll send you the code. (With the understanding that it's very preliminary.) I cannot send you the emulator dll since those are from Johan and you will have to ask him directly.
Kiyote: You can distribute the DLL I sent you with your wrapper if you want to.
Thanks Johan. I'm trying very hard to not step on any toes here.
Johan,
I downloaded the new 3.5a package just to make sure, but I think there's a discrepancy somewhere inbetween the code and the documentation.
The documentation says:
No matter what format you choose from, the steps involved to create a font are always:
1. Create a CGapiBitmapFont object.
2. Call CGapiBitmapFont::CreateSurface and supply a valid font bitmap.
3. Call CGapiBitmapFont::CreateFont to calculate the font offsets and widths.
4. Draw some text with the font using CGapiSurface::DrawText.
Step 2 mentions calling CGapiBitmapFont::CreateSurface, but this method is not exported to the flat API. Is this a C++ class-only method? Or is it a method from another object and the CGapiBitmapFont reference is erroneous?
If I skip this step, I get a NotInitialized error return code.
CGapiBitmapFont::CreateSurface is subclassed from CGapiSurface::CreateSurface. CGapiBitmapFont is a subclass of CGapiSurface.
So you should call GapiSurfaceCreateSurface.
So, call CGapiSurface_CreateSurface and pass in the bitmap font handle to the method? I'm not quite sure what you mean here Johan.
Johan,
I suspect it's something the same for the CGapiRGBASurface blitting? The documentation shows two methods for AlphaBlt, one that takes two CGapiSurface objects, and one that takes one CGapiRGBASurface object...but the second doesn't appear to be expoosed to the flat API. Should I just call the regular Blt and BltFast and pass in the handle to the CGapiRGBASurface instead of a regular CGapiSurface?
It should be something like
CGapiSurface_CreateSurface( (CGapiSurface)myCGapiBitmapFont, ... )
A subclass is simply one way for one class to contain another. Inside each instance of a CGapiBitmapFont is a CGapiSurface. (If you use the VS.NET debugger you can expand objects in the Watch window to see the base class instance hidden inside.) What a cast like this does is return a reference to the inner object.
Assuming you have the wrappers constructed properly you shouldn't need to explicitly cast - on the C++ side of things it isn't necessary. From my days of writing J/Direct wrappers (Microsoft's Java-to-Win32 calling convention, which is pretty similar to P/Invoke) this sort of thing is sometimes tricky to figure out at the wrapper layer, but once you've gotten it right the consumer of your wrapper classes shouldn't notice.
Well, the challenge is that I'm working directly with IntPtr and nothing else. I can't "cast" to anything since I have to treat the handle to the object as a black box. My GapiBitmapFont object doesn't have a CreateSurface method because there is no corresponding CGapiBitmapFont_CreateSurface method in the flattened version of the API.
Hmmm. Yeah, that makes life trickier.
Since the base class is effectively a member of the derived class, and since the whole .NET-wrapper-over-native-structs approach is predicated on a fixed memory layout for the structures, you
should be able to do pointer math to turn a CGapiBitmapFont into a CGapiSurface - just write a dummy C++ app that computes the pointer delta; for any given build of GapiDraw this should be fixed. Then, in your .NET wrappers just add the delta to the IntPtr to convert from CGapiBitmapFont to CGapiSurface.
Of course, this is just theory - I haven't written this. When I was doing wrappers I had the luxury of being able to add native stubs in such cases so that the compiler did all of the hard thinking.

Kiyote: The easiest thing to do seems for me to just add the CreateSurface subclassed method to CGapiBitmapFont. I'll add the RGBA blit functions to the CGapiSurface<n> functions as well.
Thanks Johan. I look forward to 3.5b.

Johan, FYI: CGapiBitmapFont_CreateFont can return GDERR_NOTINITIALIZED. This isn't mentioned in the online documentation.
(Is my QA getting annoying yet?)
Ooh...ooh...feature request. CGapiBitmapFont. Can it expose the height of the font somehow? I'm not expecting an actual "measure" function, just something that returns the height of the surface used to create the font (less the kerning line)?
Out of curiosity, why does the system font not have a percent sign? (%) Space considerations?
Johan,
I'm having a little trouble when my application exits. Specifically, I'm getting access violations. So, I'm wondering if there is a particular order that any created objects should be destroyed?
ie - Is it valid to dispose of the display before you dispose of surface? Is it only required that my gapidraw object handle exist until all other objects are disposed?
Just trying to get the application to shut down cleanly.
I would recommend:
1. All surfaces and other objects
2. The display object
3. The GapiDraw object
Please take a look in GapiApplication.cpp to see the order.
Thanks for the tips Johan. I'll look in to it and see if I can get it cleaned up. I'm inching ever closer to that first Beta release of the wrapper!
Also, perchance do you have any answers to my other questions in this thread?

Hi,
The documentation shows two methods for AlphaBlt, one that takes two CGapiSurface objects, and one that takes one CGapiRGBASurface object...but the second doesn't appear to be expoosed to the flat API. Should I just call the regular Blt and BltFast and pass in the handle to the CGapiRGBASurface instead of a regular CGapiSurface?
Actually, these two functions ARE exposed!

But they are called:
CGapiSurface_AlphaBltFastRgba
CGapiSurface_AlphaBltRgba
I just named them differently to handle RGBA surfaces.
Johan, FYI: CGapiBitmapFont_CreateFont can return GDERR_NOTINITIALIZED. This isn't mentioned in the online documentation.
Ok, thanks. I've updated the documentation.
Ooh...ooh...feature request. CGapiBitmapFont. Can it expose the height of the font somehow? I'm not expecting an actual "measure" function, just something that returns the height of the surface used to create the font (less the kerning line)?
The easiest way to solve this is to add a GetBaseClass() method to CGapiBitmapFont (and CGapiDisplay) that returns a CGapiSurface pointer. That way you can call GetHeight(), CreateSurface() etc on the superclass without having to typecast etc. I'll fix this and send you a 3.5b pre-release.
Out of curiosity, why does the system font not have a percent sign? (%) Space considerations?
Good question.

I'll see if I can add it...
Johan,
I am so sorry, I have no idea how I missed those RGBA functions in the dll. I feel like such an idiot. I've stared at the file for so long I just see the same thing over and over, I guess. My apologies. I'm quite the idiot.

No worries. I really appreciate any feedback I get!
Johan,
I have integrated the changes you made to return the ancestor class of the various objects. I am currently testing the ability to load a font surface and then create a font from it.
When I try to load my image with GapiBitmapFont.CreateSurface it throws an InvalidBitmap error. However, when I use a regular GapiSurface object and load it, it loads without any problems. Does the GapiBitmapFont object *require* the surface to be in bitmap format or something like that?
The file is available if anyone cares to look at it and point out what I'm doing wrong.
http://www.kiyote.ca/external/gulim_8.png
Just an FYI to those that are interested...I have cracked the load from stream problem for the wrapper. (Seems easy until you realize I'm working on the compact framework!) The only downside is that it will consume 2x the amount of memory needed to load it temporarily.
Basically, it loads the data from the stream, then allocates an unmanaged block of memory and copies the data in to there. Then it passes that unmanaged pointer to the Gapi subsystem and disposes of the managed memory block. (I'm sure for many of you your eyes glazed over there.)
Anyhoo, I'm still working on integrating all of the changes for 3.5b in to the codebase and getting other objects up and running. It's still going ahead!
Okay, I think the problem I'm having with the font is a misunderstanding with the documentation. There appears to be really 3 different font methodologies.
1) Simple Bitmap - This just looks for the first blank space between characters and calls that the end of the character. Use GDCREATEFONT_SIMPLEBITMAP.
2) Tracking - As far as I can tell from the documentation, this will work like above, but then the characters become mono-spaced according to the lTracking parameter in the structure passed in. Use GDCREATEFONT_TRACKING.
3) Advanced - According to the documentation, the kerning will be worked out automatically for this mode by the use of a white line above the character. However, I have no idea how this mode is "activated".
If I add the GDCREATEFONT_SIMPLEBITMAP to my previous font problem, the font works, but everything appears with a white line over the top of it. Can anyone who knows how CGapiBitmapFont works give me a rundown on what I'm supposed to do?
Well, moving on from the font problem for now... I'm curious what the implications of GapiDisplay.SurfacesAreLost returning NOVIDEOHW are. Since the application opened just fine and everything seemed to be working until I got that result...what does it mean? My assumption is that this means there is no video hardware memory or something like that? i.e - Asking if surfaces are lost when there is no video memory to lose them from is a silly question to ask it?
[Edit: clarify my understanding]