Game Development Reference
In-Depth Information
This system call loads a function given by function_name from the library and stores it in a
pointer that can be used to call the function dynamically (on the fly). Finally, nanoGL_Init
calls CreateGlEsInterface to create the OpenGL ES interface .
CreateGlEsInterface loops through two data structures, as shown in Listing 6-2. The first is
a set of function pointers defined in the structure GlESInterface . This structure contains a
function pointer for every API call in OpenGL ES. The second data structure is a set of API
entries defined in gl_entries.in . For every function pointer in GlESInterface there must be
an equivalent API entry in gl_entries.in in the same order. The order is absolutely crucial,
because if it does not match, then horrible things will happen at runtime.
At the end of the loop, the GlESInterface will point to all the OpenGL ES functions defined
in the API. This allows NanoGL to work as a filter for OpenGL. Thus, whenever the Quake
engine does a GL API call ( glBegin , for example), NanoGL will filter the call through its
interface, perform its magic, and send the result to the underlying OpenGL ES backend,
effectively solving the immediate mode drawing dilemma.
Listing 6-2. Data Structures Used to Initialize the NanoGL Interface
/*
// gl_entries.in
GL_ENTRY(int,eglChooseConfig,int dpy, const int *attrib_list,
int *configs, int config_size, int *num_config)
GL_ENTRY(int,eglCopyBuffers,int dpy, int surface, void* target)
GL_ENTRY(int,eglCreateContext,int dpy, int config,
int share_list, const int *attrib_list)
// GL
GL_ENTRY(void,glActiveTexture,unsigned int texture)
GL_ENTRY(void,glAlphaFunc,unsigned int func, float ref)
GL_ENTRY(void,glAlphaFuncx,unsigned int func, int ref)
GL_ENTRY(void,glBindTexture,unsigned int target, unsigned int texture)
// More GL functions here
*/
// glesinterface.h
struct GlESInterface
{
// entries must match gl_entries.in
int (*eglChooseConfig) (int dpy, const int *attrib_list, int *configs
, int config_size, int *num_config);
int (*eglCopyBuffers) (int dpy, int surface, void* target);
int (*eglCreateContext) (int dpy, int config, int share_list, const int *attrib_list);
void (*glActiveTexture) (unsigned int texture);
void (*glAlphaFunc) (unsigned int func, float ref);
void (*glAlphaFuncx) (unsigned int func, int ref);
void (*glBindTexture) (unsigned int target, unsigned int texture);
// More functions here
}
 
Search WWH ::




Custom Search