From 77d621e3041b770f3a5d9fb6c030c9fe882788a7 Mon Sep 17 00:00:00 2001 From: beuc Date: Sat, 21 Apr 2012 16:45:46 +0000 Subject: [PATCH] fg_gl2: Use GLES2 functions directly git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1253 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/fg_gl2.c | 16 +++++++++------- freeglut/freeglut/src/fg_gl2.h | 30 +++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/freeglut/freeglut/src/fg_gl2.c b/freeglut/freeglut/src/fg_gl2.c index 9e31502..b2f1822 100644 --- a/freeglut/freeglut/src/fg_gl2.c +++ b/freeglut/freeglut/src/fg_gl2.c @@ -38,17 +38,19 @@ void FGAPIENTRY glutSetVertexAttribNormal(GLint attrib) { } void fgInitGL2() { +#ifndef GL_ES_VERSION_2_0 fgState.HasOpenGL20 = 0; // TODO: Mesa returns a valid stub function, rather than NULL, // when we request a non-existent function #define CHECK(func, a) if ((a) == NULL) { fgWarning("fgInitGL2: " func " is NULL"); return; } - CHECK("fghGenBuffers", fghGenBuffers = (FGH_PFNGLGENBUFFERSPROC) glutGetProcAddress ("glGenBuffers")); - CHECK("fghDeleteBuffers", fghDeleteBuffers = (FGH_PFNGLDELETEBUFFERSPROC) glutGetProcAddress ("glDeleteBuffers")); - CHECK("fghBindBuffer", fghBindBuffer = (FGH_PFNGLBINDBUFFERPROC) glutGetProcAddress ("glBindBuffer")); - CHECK("fghBufferData", fghBufferData = (FGH_PFNGLBUFFERDATAPROC) glutGetProcAddress ("glBufferData")); - CHECK("fghVertexAttribPointer", fghVertexAttribPointer = (FGH_PFNGLVERTEXATTRIBPOINTERPROC) glutGetProcAddress ("glVertexAttribPointer")); - CHECK("fghEnableVertexAttribArray", fghEnableVertexAttribArray = (FGH_PFNGLENABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress ("glEnableVertexAttribArray")); - CHECK("fghDisableVertexAttribArray", fghDisableVertexAttribArray = (FGH_PFNGLDISABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress ("glDisableVertexAttribArray")); + CHECK("fghGenBuffers", fghGenBuffers = (FGH_PFNGLGENBUFFERSPROC)glutGetProcAddress("glGenBuffers")); + CHECK("fghDeleteBuffers", fghDeleteBuffers = (FGH_PFNGLDELETEBUFFERSPROC)glutGetProcAddress("glDeleteBuffers")); + CHECK("fghBindBuffer", fghBindBuffer = (FGH_PFNGLBINDBUFFERPROC)glutGetProcAddress("glBindBuffer")); + CHECK("fghBufferData", fghBufferData = (FGH_PFNGLBUFFERDATAPROC)glutGetProcAddress("glBufferData")); + CHECK("fghVertexAttribPointer", fghVertexAttribPointer = (FGH_PFNGLVERTEXATTRIBPOINTERPROC)glutGetProcAddress("glVertexAttribPointer")); + CHECK("fghEnableVertexAttribArray", fghEnableVertexAttribArray = (FGH_PFNGLENABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glEnableVertexAttribArray")); + CHECK("fghDisableVertexAttribArray", fghDisableVertexAttribArray = (FGH_PFNGLDISABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glDisableVertexAttribArray")); #undef CHECK +#endif fgState.HasOpenGL20 = 1; } diff --git a/freeglut/freeglut/src/fg_gl2.h b/freeglut/freeglut/src/fg_gl2.h index 54076d7..d32f012 100644 --- a/freeglut/freeglut/src/fg_gl2.h +++ b/freeglut/freeglut/src/fg_gl2.h @@ -26,9 +26,31 @@ #ifndef FG_GL2_H #define FG_GL2_H -#ifndef APIENTRY -# define APIENTRY -#endif +#include +#include "fg_internal.h" + +#ifdef GL_ES_VERSION_2_0 +/* Use existing functions on GLES 2.0 */ + +#define FGH_ARRAY_BUFFER GL_ARRAY_BUFFER +#define FGH_STATIC_DRAW GL_STATIC_DRAW +#define FGH_ELEMENT_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER + +#define fghGenBuffers glGenBuffers +#define fghDeleteBuffers glDeleteBuffers +#define fghBindBuffer glBindBuffer +#define fghBufferData glBufferData +#define fghEnableVertexAttribArray glEnableVertexAttribArray +#define fghDisableVertexAttribArray glDisableVertexAttribArray +#define fghVertexAttribPointer glVertexAttribPointer + +#else +/* Load functions dynamically, they are not defined in e.g. win32's + OpenGL headers */ + +# ifndef APIENTRY +# define APIENTRY +# endif /* extension #defines, types and entries, avoiding a dependency on additional libraries like GLEW or the GL/glext.h header */ @@ -53,4 +75,6 @@ FGH_PFNGLENABLEVERTEXATTRIBARRAYPROC fghEnableVertexAttribArray; FGH_PFNGLDISABLEVERTEXATTRIBARRAYPROC fghDisableVertexAttribArray; FGH_PFNGLVERTEXATTRIBPOINTERPROC fghVertexAttribPointer; +# endif + #endif