Porting Irrlicht to WebOS

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

Porting Irrlicht to WebOS

Post by partnerinflight »

Hi gang:

So I've been working on porting Irrlicht to WebOS. It's an interesting beast -- they support OpenGL ES 1.1 and 2.0, and use SDL for their drawing surface creation and input. They say they've extended SDL with OpenGL ES 1.1 and 2.0 support.

Now, before I go any further, please keep in mind I did C++ about 8 years ago, and my background and this point is C#. I'm NOT an OpenGL guru, or even moderately proficient user. So please forgive me if I blabber out something really dumb.

That said, what I did was grab the OpenGL ES branch of Irrlicht, and configure it out to compile against SDL. (_IRR_COMPILE_WITH_SDL_DEVICE_). Although my first testcase is on windows, I've specifically disabled _IRR_COMPILE_WITH_WINDOWS_DEVICE -- SDL should be able to handle Windows as far as I understand.

I then had to make a few modifications to CIrrDeviceSDL, specifically in the createDriver function to support OpenGL ES, like so:

Code: Select all

	case video::EDT_OGLES1:
	#ifdef _IRR_COMPILE_WITH_OGLES1_
		{
			video::SExposedVideoData data;
			data.OpenGLWin32.HWnd=Info.window;
			VideoDriver = video::createOGLES1Driver(CreationParams, data, FileSystem);
		}
	#else
		os::Printer::log("No OpenGL-ES1 support compiled in.", ELL_ERROR);
	#endif
		break;
And also some Palm-specific initialization in the device's constructor, like so:

Code: Select all

#if defined(_IRR_COMPILE_WITH_OGLES1_)
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#endif
#if defined(_IRR_WINDOWS_) && defined(_IRR_COMPILE_WITH_OGLES1_) && defined(_IRR_COMPILE_WITH_PALM_DEVICE_)
	// Load the desktop OpenGL-ES emulation library
    _dgles_load_library(NULL, proc_loader);
#elif defined(_IRR_WINDOWS_)
after the SDL_Init call. (the dgles library emulation is directly from Palm's sample code to enable running OpenGL ES on Windows.)

So that's all hopefully peachy. The problem I am running into happens a little later, inside COGLESTexture.cpp:40:

Code: Select all

	glGenTextures(1, &TextureName);
This line causes the program to simply exit. I don't get it. There's no exception thrown (I've been debugging with WinDBG and VS) -- there's an actual call to exit(). Anyone have any ideas?

My gut feeling is there's something wrong with the way I'm linking to the dgles library. (I'm using Palm's PDK version of the library.) I've ran their sample code that targets dgles2.0, and that appears to work fine; I haven't yet found samples that target 1.1, but I'm assuming they've tested this as well.

Any hints? Anything I should dig into? Any source files I can upload? ;)

Thanks!
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

glGenTextures solved... next problem.

Post by partnerinflight »

Ok I think I figured this one out. Two things I had to change:

1. Load the dgles emulation library AFTER creating the Screen.

2. When calling SDL_SetVideoMode, set the bpp parameter to 0 instead of 16.

Why this works though, I don't really understand. Anyone care to explain?

Next issue. The screen, when it finally comes up, is blank white. I'm assuming this has to do with color format I'm using for my texture?
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

Past the blank white screen... next issue

Post by partnerinflight »

Ok, I figured out the issue with the blank white screen -- I had to call SDL_GL_SwapBuffers(). That makes the outline of the model show up (I'm using HelloWorld as my testcase) but none of the textures.

Additionally I'm getting an access violation in glDeleteTextures when trying to close the app.

Help... :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

SwapBuffers should be called as part of the device or driver. Could be missing, though, as the SDL device (and also others) haven't been updated for ogl-es. This will follow once I merge this branch down to trunk.
Make sure that you know about all restrictions this library comes along with. Could be indeed a failure to set up the proper texture formats. In some cases this can be fixed by setting the texture creation flags properly. But I'd say that this only needs some more tweaking in the configuration of the underlying libs.
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

progress update

Post by partnerinflight »

Hurray! I've got the textures showing up. The trick was disabling all of the OES framebuffer calls. (with those in, the screen shows up black for some reason... I don't know enough opengl to understand why). The calls in question were:

Code: Select all

glGenFramebuffersOES(1, &ViewFramebuffer);
	glGenRenderbuffersOES(1, &ViewRenderbuffer);
	glBindRenderbufferOES(GL_RENDERBUFFER_OES, ViewRenderbuffer);

	#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
	ExposedData.OGLESIPhone.AppDelegate = Device.DeviceM;
	(*Device.displayInit)(&Device, &ExposedData.OGLESIPhone.Context, &ExposedData.OGLESIPhone.View);
	#endif

	GLint backingWidth;
	GLint backingHeight;
	glGetRenderbufferParameterivOES(
		GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
	glGetRenderbufferParameterivOES(
		GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
	
	glGenRenderbuffersOES(1, &ViewDepthRenderbuffer);
	glBindRenderbufferOES(GL_RENDERBUFFER_OES, ViewDepthRenderbuffer);
	glRenderbufferStorageOES(
		GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);

	glBindFramebufferOES(GL_FRAMEBUFFER_OES, ViewFramebuffer);
	glFramebufferRenderbufferOES(
		GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, ViewRenderbuffer);
	glFramebufferRenderbufferOES(
		GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, ViewDepthRenderbuffer);
(this if from COGLESDriver.cpp.)

Now I just have a problem where closing the app causes an access violation in COGLESExtensionHandler.h:366 -- at the glActiveTexture(texture) call. Callstack is:

Code: Select all


>	Irrlicht.dll!irr::video::COGLES1ExtensionHandler::extGlActiveTexture(unsigned int texture)  Line 366 + 0xc bytes	C++
 	Irrlicht.dll!irr::video::COGLES1Driver::setTransform(irr::video::E_TRANSFORMATION_STATE state, const irr::core::CMatrix4<float> & mat)  Line 470	C++
 	Irrlicht.dll!irr::video::COGLES1Driver::setMaterial(const irr::video::SMaterial & material)  Line 1512 + 0x29 bytes	C++
 	Irrlicht.dll!irr::scene::CSceneManager::removeAll()  Line 1920 + 0x24 bytes	C++
 	Irrlicht.dll!irr::scene::CSceneManager::~CSceneManager()  Line 333	C++
 	Irrlicht.dll!irr::scene::CSceneManager::`vbase destructor'()  + 0x1c bytes	C++
 	Irrlicht.dll!irr::scene::CSceneManager::`scalar deleting destructor'()  + 0x1c bytes	C++
 	Irrlicht.dll!irr::IReferenceCounted::drop()  Line 124 + 0x22 bytes	C++
 	Irrlicht.dll!irr::CIrrDeviceStub::~CIrrDeviceStub()  Line 63	C++
 	Irrlicht.dll!irr::CIrrDeviceSDL::~CIrrDeviceSDL()  Line 161 + 0x38 bytes	C++
 	Irrlicht.dll!irr::CIrrDeviceSDL::`vbase destructor'()  + 0x16 bytes	C++
 	Irrlicht.dll!irr::CIrrDeviceSDL::`scalar deleting destructor'()  + 0x16 bytes	C++
 	01.HelloWorld_vc9.exe!irr::IReferenceCounted::drop()  Line 124 + 0x34 bytes	C++
 	01.HelloWorld_vc9.exe!main()  Line 231	C++
 	01.HelloWorld_vc9.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes	C
 	01.HelloWorld_vc9.exe!mainCRTStartup()  Line 371	C
Anyone have an idea of what that could be? (I know it's probably a ridiculous question to ask without an actual debugging session... I'm hoping it's something obvious I'm missing, or maybe someone can point me to where to drill in for debugging...)

P.S. patch uploaded at https://sourceforge.net/tracker/?func=d ... tid=540678
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

Ping...

Post by partnerinflight »

So anyone have any idea of what might be going on with the extGlActiveTexture crash?
partnerinflight
Posts: 8
Joined: Thu Jun 24, 2010 5:04 pm

Post by partnerinflight »

Ok, after a little more digging, I figured out the issue.

CIrrDeviceSDL's destructor calls SDL_Quit before its base destructor removes all of the OpenGL objects created. I'm not sure about other platforms, but on Palm OpenGLES is initialized and destroyed through SDL... so when we call SDL_Quit, any further OpenGLES calls will do strange and horrible things.

I'm going to fix this by creating an explicit Destroy command on the base CIrrDeviceStub class, and calling that from the derived class. (I'll set some bool or somethin to leave the existing code working).

Sound like a good approach?
Post Reply