Demos (cmake): New stab at callbacks prototypes.
Jose Fonseca
jrfonseca at kemper.freedesktop.org
Tue Nov 9 14:21:42 UTC 2010
Module: Demos
Branch: cmake
Commit: 1ce986aae13bc51615b94648502ddadb1f78074a
URL: http://cgit.freedesktop.org/mesa/demos/commit/?id=1ce986aae13bc51615b94648502ddadb1f78074a
Author: José Fonseca <jfonseca at vmware.com>
Date: Tue Nov 9 14:21:31 2010 +0000
New stab at callbacks prototypes.
Neither APIENTRY, GLAPIENTRY, or CALLBACK are guaranteed to be defined
everywhere. Standardize on GLAPIENTRY and define it on a central location.
Also don't use function pointer casts when setting the callbacks -- they
just defeat C type checking, and hide fatal ABI incompatibilities, and gcc
on Linux doesn't generate any warnings without the casts.
---
CMakeLists.txt | 5 ++++-
src/demos/tessdemo.c | 44 +++++++++++++++++---------------------------
src/redbook/quadric.c | 10 ++--------
src/redbook/surfpoints.c | 14 +++++---------
src/redbook/tess.c | 42 ++++++++++++++----------------------------
src/redbook/tesswind.c | 28 +++++++++-------------------
src/redbook/trim.c | 10 ++--------
src/samples/nurb.c | 11 ++---------
src/samples/quad.c | 11 ++---------
src/tests/shader_api.c | 6 +-----
10 files changed, 58 insertions(+), 123 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1426ce1..386c8e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,12 +31,15 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
add_definitions (--include windows.h)
endif (MSVC)
+ # MSVC & MinGW only define & use APIENTRY
+ add_definitions (-DGLAPIENTRY=__stdcall)
+
link_libraries (winmm)
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if (MSVC)
# Silence several MSVC pedantic warnings
- add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS)
+ add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
add_definitions (-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
add_definitions (-wd4244) # conversion' conversion from 'type1' to 'type2', possible loss of data
endif (MSVC)
diff --git a/src/demos/tessdemo.c b/src/demos/tessdemo.c
index f2dcee7..d5b84f5 100644
--- a/src/demos/tessdemo.c
+++ b/src/demos/tessdemo.c
@@ -13,14 +13,6 @@
#define MAX_CONTOURS 32
#define MAX_TRIANGLES 256
-#ifndef GLCALLBACK
-#ifdef CALLBACK
-#define GLCALLBACK CALLBACK
-#else
-#define GLCALLBACK
-#endif
-#endif
-
#ifdef GLU_VERSION_1_2
typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries;
@@ -50,7 +42,7 @@ static struct {
-static void GLCALLBACK error_callback( GLenum err )
+static void GLAPIENTRY error_callback( GLenum err )
{
int len, i;
char const *str;
@@ -66,14 +58,14 @@ static void GLCALLBACK error_callback( GLenum err )
}
}
-static void GLCALLBACK begin_callback( GLenum mode )
+static void GLAPIENTRY begin_callback( GLenum mode )
{
/* Allow multiple triangles to be output inside the begin/end pair. */
triangle_cnt = 0;
triangles[triangle_cnt].no = 0;
}
-static void GLCALLBACK edge_callback( GLenum flag )
+static void GLAPIENTRY edge_callback( GLenum flag )
{
/* Persist the edge flag across triangles. */
if ( flag == GL_TRUE ) {
@@ -87,7 +79,7 @@ static void GLCALLBACK edge_callback( GLenum flag )
}
}
-static void GLCALLBACK end_callback(void)
+static void GLAPIENTRY end_callback(void)
{
GLuint i;
@@ -121,7 +113,7 @@ static void GLCALLBACK end_callback(void)
glEnd();
}
-static void GLCALLBACK vertex_callback( void *data )
+static void GLAPIENTRY vertex_callback( void *data )
{
GLsizei no;
GLfloat *p;
@@ -143,9 +135,9 @@ static void GLCALLBACK vertex_callback( void *data )
}
}
-static void GLCALLBACK combine_callback( GLdouble coords[3],
- GLdouble *vertex_data[4],
- GLfloat weight[4], void **data )
+static void GLAPIENTRY combine_callback( GLdouble coords[3],
+ GLdouble *vertex_data[4],
+ GLfloat weight[4], void **data )
{
GLfloat *vertex;
@@ -164,8 +156,6 @@ static void set_screen_wh( GLsizei w, GLsizei h )
height = h;
}
-typedef void (GLAPIENTRY *callback_t)(void);
-
static void tesse( void )
{
GLUtesselator *tobj;
@@ -178,11 +168,11 @@ static void tesse( void )
if ( tobj != NULL ) {
gluTessNormal( tobj, 0.0, 0.0, 1.0 );
- gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) glBegin );
- gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) glVertex2fv );
- gluTessCallback( tobj, GLU_TESS_END, (callback_t) glEnd );
- gluTessCallback( tobj, GLU_TESS_ERROR, (callback_t) error_callback );
- gluTessCallback( tobj, GLU_TESS_COMBINE, (callback_t) combine_callback );
+ gluTessCallback( tobj, GLU_TESS_BEGIN, glBegin );
+ gluTessCallback( tobj, GLU_TESS_VERTEX, glVertex2fv );
+ gluTessCallback( tobj, GLU_TESS_END, glEnd );
+ gluTessCallback( tobj, GLU_TESS_ERROR, error_callback );
+ gluTessCallback( tobj, GLU_TESS_COMBINE, combine_callback );
glNewList( list_start, GL_COMPILE );
gluBeginPolygon( tobj );
@@ -202,10 +192,10 @@ static void tesse( void )
gluEndPolygon( tobj );
glEndList();
- gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) begin_callback );
- gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) vertex_callback );
- gluTessCallback( tobj, GLU_TESS_END, (callback_t) end_callback );
- gluTessCallback( tobj, GLU_TESS_EDGE_FLAG, (callback_t) edge_callback );
+ gluTessCallback( tobj, GLU_TESS_BEGIN, begin_callback );
+ gluTessCallback( tobj, GLU_TESS_VERTEX, vertex_callback );
+ gluTessCallback( tobj, GLU_TESS_END, end_callback );
+ gluTessCallback( tobj, GLU_TESS_EDGE_FLAG, edge_callback );
glNewList( list_start + 1, GL_COMPILE );
gluBeginPolygon( tobj );
diff --git a/src/redbook/quadric.c b/src/redbook/quadric.c
index 1cbd395..bb92904 100644
--- a/src/redbook/quadric.c
+++ b/src/redbook/quadric.c
@@ -47,14 +47,9 @@
#include <stdio.h>
#include <stdlib.h>
-/* Win32 calling conventions. */
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
GLuint startList;
-static void CALLBACK errorCallback(GLenum errorCode)
+static void GLAPIENTRY errorCallback(GLenum errorCode)
{
const GLubyte *estring;
@@ -90,8 +85,7 @@ static void init(void)
*/
startList = glGenLists(4);
qobj = gluNewQuadric();
- gluQuadricCallback(qobj, GLU_ERROR,
- (GLvoid (CALLBACK*) ()) errorCallback);
+ gluQuadricCallback(qobj, GLU_ERROR, errorCallback);
gluQuadricDrawStyle(qobj, GLU_FILL); /* smooth shaded */
gluQuadricNormals(qobj, GLU_SMOOTH);
diff --git a/src/redbook/surfpoints.c b/src/redbook/surfpoints.c
index 094f0da..b44518f 100644
--- a/src/redbook/surfpoints.c
+++ b/src/redbook/surfpoints.c
@@ -60,10 +60,6 @@
#ifdef GLU_VERSION_1_3
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
GLfloat ctlpoints[4][4][3];
int showPoints = 0;
@@ -89,7 +85,7 @@ static void init_surface(void)
}
}
-static void CALLBACK nurbsError(GLenum errorCode)
+static void GLAPIENTRY nurbsError(GLenum errorCode)
{
const GLubyte *estring;
@@ -98,7 +94,7 @@ static void CALLBACK nurbsError(GLenum errorCode)
exit (0);
}
-static void CALLBACK beginCallback(GLenum whichType)
+static void GLAPIENTRY beginCallback(GLenum whichType)
{
glBegin (whichType); /* resubmit rendering directive */
printf ("glBegin(");
@@ -135,20 +131,20 @@ static void CALLBACK beginCallback(GLenum whichType)
}
}
-static void CALLBACK endCallback()
+static void GLAPIENTRY endCallback()
{
glEnd(); /* resubmit rendering directive */
printf ("glEnd()\n");
}
-static void CALLBACK vertexCallback(GLfloat *vertex)
+static void GLAPIENTRY vertexCallback(GLfloat *vertex)
{
glVertex3fv(vertex); /* resubmit rendering directive */
printf ("glVertex3f (%5.3f, %5.3f, %5.3f)\n",
vertex[0], vertex[1], vertex[2]);
}
-static void CALLBACK normalCallback(GLfloat *normal)
+static void GLAPIENTRY normalCallback(GLfloat *normal)
{
glNormal3fv(normal); /* resubmit rendering directive */
printf ("glNormal3f (%5.3f, %5.3f, %5.3f)\n",
diff --git a/src/redbook/tess.c b/src/redbook/tess.c
index 0bf8a8e..8b907d0 100644
--- a/src/redbook/tess.c
+++ b/src/redbook/tess.c
@@ -54,11 +54,6 @@
#ifdef GLU_VERSION_1_2
-/* Win32 calling conventions. */
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
GLuint startList;
static void display (void) {
@@ -69,12 +64,12 @@ static void display (void) {
glFlush();
}
-static void CALLBACK beginCallback(GLenum which)
+static void GLAPIENTRY beginCallback(GLenum which)
{
glBegin(which);
}
-static void CALLBACK errorCallback(GLenum errorCode)
+static void GLAPIENTRY errorCallback(GLenum errorCode)
{
const GLubyte *estring;
@@ -83,12 +78,12 @@ static void CALLBACK errorCallback(GLenum errorCode)
exit(0);
}
-static void CALLBACK endCallback(void)
+static void GLAPIENTRY endCallback(void)
{
glEnd();
}
-static void CALLBACK vertexCallback(GLvoid *vertex)
+static void GLAPIENTRY vertexCallback(GLvoid *vertex)
{
const GLdouble *pointer;
@@ -102,7 +97,7 @@ static void CALLBACK vertexCallback(GLvoid *vertex)
* but weight[4] may be used to average color, normal, or texture
* coordinate data. In this program, color is weighted.
*/
-static void CALLBACK combineCallback(GLdouble coords[3],
+static void GLAPIENTRY combineCallback(GLdouble coords[3],
GLdouble *vertex_data[4],
GLfloat weight[4], GLdouble **dataOut )
{
@@ -143,14 +138,10 @@ static void init (void)
startList = glGenLists(2);
tobj = gluNewTess();
- gluTessCallback(tobj, GLU_TESS_VERTEX,
- (GLvoid (CALLBACK*) ()) &glVertex3dv);
- gluTessCallback(tobj, GLU_TESS_BEGIN,
- (GLvoid (CALLBACK*) ()) &beginCallback);
- gluTessCallback(tobj, GLU_TESS_END,
- (GLvoid (CALLBACK*) ()) &endCallback);
- gluTessCallback(tobj, GLU_TESS_ERROR,
- (GLvoid (CALLBACK*) ()) &errorCallback);
+ gluTessCallback(tobj, GLU_TESS_VERTEX, &glVertex3dv);
+ gluTessCallback(tobj, GLU_TESS_BEGIN, &beginCallback);
+ gluTessCallback(tobj, GLU_TESS_END, &endCallback);
+ gluTessCallback(tobj, GLU_TESS_ERROR, &errorCallback);
/* rectangle with triangular hole inside */
glNewList(startList, GL_COMPILE);
@@ -170,16 +161,11 @@ static void init (void)
gluTessEndPolygon(tobj);
glEndList();
- gluTessCallback(tobj, GLU_TESS_VERTEX,
- (GLvoid (CALLBACK*) ()) &vertexCallback);
- gluTessCallback(tobj, GLU_TESS_BEGIN,
- (GLvoid (CALLBACK*) ()) &beginCallback);
- gluTessCallback(tobj, GLU_TESS_END,
- (GLvoid (CALLBACK*) ()) &endCallback);
- gluTessCallback(tobj, GLU_TESS_ERROR,
- (GLvoid (CALLBACK*) ()) &errorCallback);
- gluTessCallback(tobj, GLU_TESS_COMBINE,
- (GLvoid (CALLBACK*) ()) &combineCallback);
+ gluTessCallback(tobj, GLU_TESS_VERTEX, &vertexCallback);
+ gluTessCallback(tobj, GLU_TESS_BEGIN, &beginCallback);
+ gluTessCallback(tobj, GLU_TESS_END, &endCallback);
+ gluTessCallback(tobj, GLU_TESS_ERROR, &errorCallback);
+ gluTessCallback(tobj, GLU_TESS_COMBINE, &combineCallback);
/* smooth shaded, self-intersecting star */
glNewList(startList + 1, GL_COMPILE);
diff --git a/src/redbook/tesswind.c b/src/redbook/tesswind.c
index 4729880..e701b38 100644
--- a/src/redbook/tesswind.c
+++ b/src/redbook/tesswind.c
@@ -48,11 +48,6 @@
#ifdef GLU_VERSION_1_2
-/* Win32 calling conventions. */
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
GLdouble currentWinding = GLU_TESS_WINDING_ODD;
int currentShape = 0;
GLUtesselator *tobj;
@@ -168,12 +163,12 @@ static void display (void) {
glFlush();
}
-static void CALLBACK beginCallback(GLenum which)
+static void GLAPIENTRY beginCallback(GLenum which)
{
glBegin(which);
}
-static void CALLBACK errorCallback(GLenum errorCode)
+static void GLAPIENTRY errorCallback(GLenum errorCode)
{
const GLubyte *estring;
@@ -182,7 +177,7 @@ static void CALLBACK errorCallback(GLenum errorCode)
exit(0);
}
-static void CALLBACK endCallback(void)
+static void GLAPIENTRY endCallback(void)
{
glEnd();
}
@@ -193,7 +188,7 @@ static void CALLBACK endCallback(void)
* coordinate data.
*/
/* ARGSUSED */
-static void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4],
+static void GLAPIENTRY combineCallback(GLdouble coords[3], GLdouble *data[4],
GLfloat weight[4], GLdouble **dataOut )
{
GLdouble *vertex;
@@ -211,16 +206,11 @@ static void init(void)
glShadeModel(GL_FLAT);
tobj = gluNewTess();
- gluTessCallback(tobj, GLU_TESS_VERTEX,
- (GLvoid (CALLBACK*) ()) &glVertex3dv);
- gluTessCallback(tobj, GLU_TESS_BEGIN,
- (GLvoid (CALLBACK*) ()) &beginCallback);
- gluTessCallback(tobj, GLU_TESS_END,
- (GLvoid (CALLBACK*) ()) &endCallback);
- gluTessCallback(tobj, GLU_TESS_ERROR,
- (GLvoid (CALLBACK*) ()) &errorCallback);
- gluTessCallback(tobj, GLU_TESS_COMBINE,
- (GLvoid (CALLBACK*) ()) &combineCallback);
+ gluTessCallback(tobj, GLU_TESS_VERTEX, &glVertex3dv);
+ gluTessCallback(tobj, GLU_TESS_BEGIN, &beginCallback);
+ gluTessCallback(tobj, GLU_TESS_END, &endCallback);
+ gluTessCallback(tobj, GLU_TESS_ERROR, &errorCallback);
+ gluTessCallback(tobj, GLU_TESS_COMBINE, &combineCallback);
list = glGenLists(4);
makeNewLists();
diff --git a/src/redbook/trim.c b/src/redbook/trim.c
index 216f62a..4d45d31 100644
--- a/src/redbook/trim.c
+++ b/src/redbook/trim.c
@@ -46,11 +46,6 @@
#include <stdio.h>
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
-
GLfloat ctlpoints[4][4][3];
GLUnurbsObj *theNurb;
@@ -75,7 +70,7 @@ static void init_surface(void)
}
}
-static void nurbsError(GLenum errorCode)
+static void GLAPIENTRY nurbsError(GLenum errorCode)
{
const GLubyte *estring;
@@ -108,8 +103,7 @@ static void init(void)
theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
- gluNurbsCallback(theNurb, GLU_ERROR,
- (GLvoid (CALLBACK*) ()) nurbsError);
+ gluNurbsCallback(theNurb, GLU_ERROR, nurbsError);
}
static void display(void)
diff --git a/src/samples/nurb.c b/src/samples/nurb.c
index dc89912..0bd6986 100644
--- a/src/samples/nurb.c
+++ b/src/samples/nurb.c
@@ -29,11 +29,6 @@
#include <GL/glut.h>
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
-
#define INREAL float
#define S_NUMPOINTS 13
@@ -207,7 +202,7 @@ Point ctlpoints[S_NUMPOINTS][T_NUMPOINTS] = {
GLUnurbsObj *theNurbs;
-static void CALLBACK ErrorCallback(GLenum which)
+static void GLAPIENTRY ErrorCallback(GLenum which)
{
if (which != expectedError) {
@@ -216,13 +211,11 @@ static void CALLBACK ErrorCallback(GLenum which)
}
}
-typedef void (GLAPIENTRY *callback_t)();
-
static void Init(void)
{
theNurbs = gluNewNurbsRenderer();
- gluNurbsCallback(theNurbs, GLU_ERROR, (callback_t) ErrorCallback);
+ gluNurbsCallback(theNurbs, GLU_ERROR, ErrorCallback);
gluNurbsProperty(theNurbs, GLU_SAMPLING_TOLERANCE, 15.0);
gluNurbsProperty(theNurbs, GLU_DISPLAY_MODE, GLU_OUTLINE_PATCH);
diff --git a/src/samples/quad.c b/src/samples/quad.c
index 193850a..b88c312 100644
--- a/src/samples/quad.c
+++ b/src/samples/quad.c
@@ -28,11 +28,6 @@
#include <GL/glut.h>
-#ifndef CALLBACK
-#define CALLBACK
-#endif
-
-
#define PI 3.141592654
#define BLACK 0
#define GRAY 128
@@ -96,14 +91,12 @@ GLubyte brickImage[4*brickImageWidth*brickImageHeight] = {
char *texFileName = 0;
-static void CALLBACK ErrorHandler(GLenum which)
+static void GLAPIENTRY ErrorHandler(GLenum which)
{
fprintf(stderr, "Quad Error: %s\n", (char *) gluErrorString(which));
}
-typedef void (GLAPIENTRY *callback_t)();
-
static void Init(void)
{
static GLint colorIndexes[3] = {0, 200, 255};
@@ -165,7 +158,7 @@ static void Init(void)
}
quadObj = gluNewQuadric();
- gluQuadricCallback(quadObj, GLU_ERROR, (callback_t) ErrorHandler);
+ gluQuadricCallback(quadObj, GLU_ERROR, ErrorHandler);
radius1 = 10;
radius2 = 5;
diff --git a/src/tests/shader_api.c b/src/tests/shader_api.c
index fa0a992..9d22379 100644
--- a/src/tests/shader_api.c
+++ b/src/tests/shader_api.c
@@ -8,10 +8,6 @@
#include <GL/glew.h>
#include <GL/glut.h>
-#ifndef APIENTRY
-#define APIENTRY
-#endif
-
static void assert_test(const char *file, int line, int cond, const char *msg)
{
if (!cond)
@@ -46,7 +42,7 @@ static void assert_error_test(const char *file, int line, GLenum expect)
#define assert_error(err) assert_error_test(__FILE__, __LINE__, (err))
-static void check_status(GLuint id, GLenum pname, void (APIENTRY *query)(GLuint, GLenum, GLint *))
+static void check_status(GLuint id, GLenum pname, void (GLAPIENTRY *query)(GLuint, GLenum, GLint *))
{
GLint status;
More information about the mesa-commit
mailing list