From a9bd975460c45c5781ba25ca9360bbe48bdfde88 Mon Sep 17 00:00:00 2001 From: Sylvain Beucler Date: Sat, 31 Mar 2012 20:21:16 +0000 Subject: [PATCH] Declare OpenGL 2.0 dynamically-loaded functions for internal use git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1220 7f0cb862-5218-0410-a997-914c9d46530a --- CMakeLists.txt | 2 ++ src/fg_gl2.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/fg_gl2.h | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/fg_init.c | 3 +++ src/fg_internal.h | 1 + 5 files changed, 113 insertions(+) create mode 100644 src/fg_gl2.c create mode 100644 src/fg_gl2.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b2b93..de00ec0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,8 @@ SET(FREEGLUT_SRCS src/fg_ext.c src/fg_font_data.c src/fg_gamemode.c + src/fg_gl2.c + src/fg_gl2.h src/fg_init.c src/fg_internal.h src/fg_input_devices.c diff --git a/src/fg_gl2.c b/src/fg_gl2.c new file mode 100644 index 0000000..47913f4 --- /dev/null +++ b/src/fg_gl2.c @@ -0,0 +1,58 @@ +/* + * fg_gl2.c + * + * Load OpenGL (ES) 2.0 functions used by fg_geometry + * + * Copyright (C) 2012 Sylvain Beucler + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "fg_internal.h" +#include "fg_gl2.h" + +typedef void (APIENTRY *PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef void (APIENTRY *PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRY *PFNGLBUFFERDATAPROC) (GLenum target, fghGLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRY *PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint* buffers); +typedef void (APIENTRY *PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRY *PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint); +typedef void (APIENTRY *PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); + +PFNGLGENBUFFERSPROC fghGenBuffers = NULL; +PFNGLDELETEBUFFERSPROC fghDeleteBuffers = NULL; +PFNGLBINDBUFFERPROC fghBindBuffer = NULL; +PFNGLBUFFERDATAPROC fghBufferData = NULL; +PFNGLENABLEVERTEXATTRIBARRAYPROC fghEnableVertexAttribArray = NULL; +PFNGLDISABLEVERTEXATTRIBARRAYPROC fghDisableVertexAttribArray = NULL; +PFNGLVERTEXATTRIBPOINTERPROC fghVertexAttribPointer = NULL; + +void fgInitGL2() { + fgState.HasOpenGL20 = 0; +#define CHECK(func, a) if ((a) == NULL) { fgWarning("fgInitGL2: " func " is NULL"); return; } + CHECK("fghGenBuffers", fghGenBuffers = (PFNGLGENBUFFERSPROC) glutGetProcAddress ("glGenBuffers")); + CHECK("fghDeleteBuffers", fghDeleteBuffers = (PFNGLDELETEBUFFERSPROC) glutGetProcAddress ("glDeleteBuffers")); + CHECK("fghBindBuffer", fghBindBuffer = (PFNGLBINDBUFFERPROC) glutGetProcAddress ("glBindBuffer")); + CHECK("fghBufferData", fghBufferData = (PFNGLBUFFERDATAPROC) glutGetProcAddress ("glBufferData")); + CHECK("fghVertexAttribPointer", fghVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) glutGetProcAddress ("glVertexAttribPointer")); + CHECK("fghEnableVertexAttribArray", fghEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress ("glEnableVertexAttribArray")); + CHECK("fghDisableVertexAttribArray", fghDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) glutGetProcAddress ("glDisnableVertexAttribArray")); +#undef CHECK + fgState.HasOpenGL20 = 1; +} diff --git a/src/fg_gl2.h b/src/fg_gl2.h new file mode 100644 index 0000000..788db43 --- /dev/null +++ b/src/fg_gl2.h @@ -0,0 +1,49 @@ +/* + * fg_gl2.c + * + * Load OpenGL (ES) 2.0 functions used by fg_geometry + * + * Copyright (C) 2012 Sylvain Beucler + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef FG_GL2_H +#define FG_GL2_H + +#ifndef APIENTRY +# define APIENTRY +#endif +typedef ptrdiff_t fghGLsizeiptr; +typedef void (APIENTRY *PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef void (APIENTRY *PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRY *PFNGLBUFFERDATAPROC) (GLenum target, fghGLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRY *PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint* buffers); +typedef void (APIENTRY *PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRY *PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint); +typedef void (APIENTRY *PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); + +PFNGLGENBUFFERSPROC fghGenBuffers; +PFNGLDELETEBUFFERSPROC fghDeleteBuffers; +PFNGLBINDBUFFERPROC fghBindBuffer; +PFNGLBUFFERDATAPROC fghBufferData; +PFNGLENABLEVERTEXATTRIBARRAYPROC fghEnableVertexAttribArray; +PFNGLDISABLEVERTEXATTRIBARRAYPROC fghDisableVertexAttribArray; +PFNGLVERTEXATTRIBPOINTERPROC fghVertexAttribPointer; + +#endif diff --git a/src/fg_init.c b/src/fg_init.c index d564e83..74c4649 100644 --- a/src/fg_init.c +++ b/src/fg_init.c @@ -90,6 +90,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */ 0, /* OpenGL context MinorVersion */ 0, /* OpenGL ContextFlags */ 0, /* OpenGL ContextProfile */ + 0, /* HasOpenGL20 */ NULL, /* ErrorFunc */ NULL /* WarningFunc */ }; @@ -380,6 +381,8 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) if( (mask & (XValue|YValue)) == (XValue|YValue) ) fgState.Position.Use = GL_TRUE; } + + fgInitGL2(); } /* diff --git a/src/fg_internal.h b/src/fg_internal.h index 2119d1a..c7dd53b 100644 --- a/src/fg_internal.h +++ b/src/fg_internal.h @@ -319,6 +319,7 @@ struct tagSFG_State int MajorVersion; /* Major OpenGL context version */ int MinorVersion; /* Minor OpenGL context version */ int ContextFlags; /* OpenGL context flags */ + int HasOpenGL20; /* fgInitGL2 could find all OpenGL 2.0 functions */ int ContextProfile; /* OpenGL context profile */ FGError ErrorFunc; /* User defined error handler */ FGWarning WarningFunc; /* User defined warning handler */ -- 1.7.10.4