Navigation Menu

Skip to content

Commit

Permalink
GL|Cleanup: Using helper macros for definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 8, 2012
1 parent ecd7ca8 commit ee25e35
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
7 changes: 5 additions & 2 deletions doomsday/engine/portable/include/gl_defer.h
Expand Up @@ -72,8 +72,11 @@ void GL_ReleaseReservedNames(void);
*/
void GL_DeferTextureUpload(const struct texturecontent_s* content);

void GL_Defer_e(void (GL_CALL *ptr)(GLenum), GLenum param);
// Deferring functions for various function signatures.
#define LIBDENG_GL_DEFER1(form, x) void GL_Defer_##form(void (GL_CALL *ptr)(x), x)
#define LIBDENG_GL_DEFER2(form, x, y) void GL_Defer_##form(void (GL_CALL* ptr)(x, y), x, y)

void GL_Defer_uintArray(void (GL_CALL *ptr)(GLsizei, const GLuint*), GLsizei s, const GLuint* v);
LIBDENG_GL_DEFER1(e, GLenum e);
LIBDENG_GL_DEFER2(uintArray, GLsizei count, const GLuint* values);

#endif /* LIBDENG_GL_DEFERRED_H */
7 changes: 6 additions & 1 deletion doomsday/engine/portable/include/gl_deferredapi.h
Expand Up @@ -26,9 +26,14 @@
#ifndef LIBDENG_DEFERRED_GL_API_H
#define LIBDENG_DEFERRED_GL_API_H

/**
* @def LIBDENG_DISABLE_DEFERRED_GL_API
* Disables the automatic rerouting of GL API calls to the deferring queue.
* Put this in the beginning of a source file, before all #includes.
*/
#ifndef LIBDENG_DISABLE_DEFERRED_GL_API

#include "sys_opengl.h"
#include "sys_opengl.h" // ensure native OpenGL has been included

#define glEnable(x) Deferred_glEnable(x)
#define glDisable(x) Deferred_glDisable(x)
Expand Down
28 changes: 14 additions & 14 deletions doomsday/engine/portable/src/gl_defer.c
Expand Up @@ -40,10 +40,10 @@ typedef enum {

DTT_UPLOAD_TEXTURECONTENT = DEFERREDTASK_TYPES_FIRST,

DTT_FUNC_PTR_BEGIN,
DTT_FUNC_PTR_1E = DTT_FUNC_PTR_BEGIN,
DTT_FUNC_PTR_UINT_ARRAY,
DTT_FUNC_PTR_END,
DTT_FUNC_PTR_BEGIN,
DTT_FUNC_PTR_E = DTT_FUNC_PTR_BEGIN,
DTT_FUNC_PTR_UINT_ARRAY,
DTT_FUNC_PTR_END,

DEFERREDTASK_TYPES_COUNT
} deferredtask_type_t;
Expand All @@ -58,7 +58,7 @@ typedef struct deferredtask_s {

typedef struct apifunc_s {
union {
void (GL_CALL *ptr_1e)(GLenum);
void (GL_CALL *ptr_e)(GLenum);
void (GL_CALL *ptr_uintArray)(GLsizei, const GLuint*);
} func;
union {
Expand Down Expand Up @@ -151,20 +151,20 @@ static void destroyTask(deferredtask_t* d)
free(d);
}

void GL_Defer1e(void (GL_CALL *ptr)(GLenum), GLenum param)
LIBDENG_GL_DEFER1(e, GLenum e)
{
apifunc_t* api = malloc(sizeof(apifunc_t));
api->func.ptr_1e = ptr;
api->param.e = param;
api->func.ptr_e = ptr;
api->param.e = e;

#ifdef _DEBUG
fprintf(stderr, "GL_Defer1e: ptr=%p param=%i\n", ptr, param);
fprintf(stderr, "GL_Defer1e: ptr=%p enum=%i\n", ptr, e);
#endif

enqueueTask(DTT_FUNC_PTR_1E, api);
enqueueTask(DTT_FUNC_PTR_E, api);
}

void GL_Defer_uintArray(void (GL_CALL *ptr)(GLsizei, const GLuint*), GLsizei s, const GLuint* v)
LIBDENG_GL_DEFER2(uintArray, GLsizei s, const GLuint* v)
{
apifunc_t* api = malloc(sizeof(apifunc_t));
api->func.ptr_uintArray = ptr;
Expand Down Expand Up @@ -323,11 +323,11 @@ static void processTask(deferredtask_t* task)
GL_UploadTextureContent(task->data);
break;

case DTT_FUNC_PTR_1E:
case DTT_FUNC_PTR_E:
#ifdef _DEBUG
fprintf(stderr, "processDeferred: ptr=%p param=%i\n", api->func.ptr_1e, api->param.e);
fprintf(stderr, "processDeferred: ptr=%p param=%i\n", api->func.ptr_e, api->param.e);
#endif
api->func.ptr_1e(api->param.e);
api->func.ptr_e(api->param.e);
break;

case DTT_FUNC_PTR_UINT_ARRAY:
Expand Down

0 comments on commit ee25e35

Please sign in to comment.