If you have a namespaced-class and a template class defined like this:

namespace Frog
    class A

template<class T>
class B

Now suppose you wish the template class B to have access to private and protected members and methods of class A. Normally you’d add the following line of code to the declaration of class A:

template<class T> friend class B;

However, in this case the compiler may object when a method in class B tries to access protected or private areas in class A. In this case, your compiler is probably thinking that your template friend class B is actually in the namespace Frog, even if class B is declared globally and before Frog::A is declared.

To fix this, simply tell the compiler that class B falls in the global namespace, like this:

template<class T> friend class ::B;

Notice I just added a double colon (::) before B’s name.

Tagged with:

OpenGL Frame Capture Tips

On April 10, 2012, in All Posts, Games, Graphics, by stu

In Xcode version 4.2 and above, there’s a very nice  feature to capture OpenGL rendering commands from your game as it runs on an iOS device. I use the OpenGL ES 2.0 API, but it works the same in ES 1.1. Here are some helpful tips that I’ve discovered. I bumbled through these issues myself, so these will hopefully save you some time.

  1. Only render the objects that you are debugging. In Xcode 4.2, capturing a frame consumes a TON of memory if you have a lot of objects. For example, my game renders about 50 objects, each with approximately 2000 vertices and this will consume gigabytes of memory. So unless you enjoy trying to end tasks while your Mac is completely unresponsive, hide all but the objects that you are investigating. On the Apple Developer Forums, I was told that this issue has been improved in Xcode 4.3.
  2. Group your commands. There’s a handy debug extension you can call to mark the start and end of a group of rendering commands. Rendering a single primitive like a triangle strip, even if it is one object, involves setting a lot of attributes and uniforms and possibly changing blend modes. You can group all these commands together in the debugger by first calling glPushGroupMarkerEXT(0,”Name”) before issuing the commands and then glPopGroupMarkerEXT() after. You can also group objects together in the same way to create a hierarchy in the tool’s interface.
  3. Label your resources. When you create a texture or vertex buffer, you can attach a friendly name to it so that it doesn’t appear as “Texture #28.”  This is done using the glLabelObjectEXT()function. Here’s how to do it for a texture:

    glLabelObjectEXT(GL_TEXTURE, texture.glid, 0, texture.name)

    where texture.glid is the GL texture identifier returned from glGenTextures() and texture.name is a null-terminated char string. One important tip here is that you can’t call this until you’ve actually created your texture using glTexImage2D(). Otherwise you’ll get an error returned.

Command Grouping

Resource Labels

Tagged with: