Game Development Community

bloody AGL.h

by Paul Scott · in Torque Game Engine · 09/17/2002 (12:22 pm) · 2 replies

I'm trying to piece together some debug rendering mode support on macs. I've got the Interior render modes working. I've run into a problem with the wireframe mode support.

I'm doing the same thing that the windows code does: swap out the gl* routines for a custom routine. In wireframe mode, the buffer must be cleared each frame. The windows code switches the swapbuffers func for one that clears, then swaps buffers.
On macs, the swapbuffer func is aglSwapBuffers.
In order to alias it to a function pointer, we must refer to it in platformGL.h, and so we must include AGL.h in platformGL.h...

The compiler is throwing an error back when it gets to something that AGL.h includes: OpenTransport.h.
looks like one of the structs in opentransport overrides the new() operator.

The platformMacCarb.cc file says:
#include "platform/types.h"
#if defined(TORQUE_OS_MAC_OSX)
// AAAAAAAAARGGGH.
// OSX Frameworks version of AGL.h includes CoreServices, which hits the
// OpenTransport-has-a-new-but-platform.h-#defs-new-to-something-nonstandard
// issue, so we need to pre-include OT here...
#include <OpenTransport.h>
#endif

#include "PlatformMacCarb/platformMacCarb.h"
#include "PlatformMacCarb/platformGL.h"
#include "dgl/dgl.h"
#include "console/console.h"

#include <AGL.h>

--

on further investigation, it appears that platform.h is to blame, for redefining new. Would some engine veteran please explain why we are redefining new?
Seems like a strange thing to do...

#1
09/18/2002 (1:22 am)
Paul,

Not sure about your problem here but it's not really uncommon for applications to override the 'new' operator for memory management purposes.

This is in-fact why Torque overrides it. I've not messed with it but that portion of code can be disabled by defining 'TORQUE_DISABLE_MEMORY_MANAGER'.

I've not tried this so use it at your own disgression. ;)

- Melv.
#2
09/18/2002 (2:17 am)
Got a couple of solutions.

I've noticed that the specific func I'm trying to hijack, aglSwapBuffers, is only called once, from one file. Soo... switch that call out for a call to a function pointer, which has been assigned to a wrapper around the original func. Then we can swap that function pointer back & forth to anything we please.

I've also noticed that the main fix for the AGL thing is to pre include opentransport.h, before platfom.h. But this is not always possible, if platform.h is included by something else first. So if I include it *inside* platform.h, or better yet inside types.h which is the first thing included by plaform.h, we automatically get the benefits.

in types.h line 18:
#if defined(TORQUE_OS_MAC_OSX)
#include <OpenTransport.h>
#endif

I am getting SO tired of clean builds. But every time I change such central headers, clean builds are needed.

no errors with either of these approaches so far... waiting to see.