1 /* San Angeles Observation OpenGL ES version example
2  * Copyright 2004-2005 Jetro Lauha
3  * All rights reserved.
4  * Web: http://iki.fi/jetro/
5  *
6  * This source is free software; you can redistribute it and/or
7  * modify it under the terms of EITHER:
8  *   (1) The GNU Lesser General Public License as published by the Free
9  *       Software Foundation; either version 2.1 of the License, or (at
10  *       your option) any later version. The text of the GNU Lesser
11  *       General Public License is included with this source in the
12  *       file LICENSE-LGPL.txt.
13  *   (2) The BSD-style license that is included with this source in
14  *       the file LICENSE-BSD.txt.
15  *
16  * This source is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
19  * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
20  *
21  * $Id: importgl.c,v 1.4 2005/02/08 18:42:55 tonic Exp $
22  * $Revision: 1.4 $
23  */
24 
25 #ifndef DISABLE_IMPORTGL
26 
27 #include <stdlib.h>
28 #include <dlfcn.h>
29 #include "waffle.h"
30 
31 #define IMPORTGL_NO_FNPTR_DEFS
32 #define IMPORTGL_API
33 #define IMPORTGL_FNPTRINIT = NULL
34 #include "importgl.h"
35 
36 
37 /* Imports function pointers to selected function calls in GLES DLL
38  * or shared object. The function pointers are stored as global symbols with
39  * equivalent function name but prefixed with "funcPtr_". Standard gl
40  * calls are redirected to the function pointers with preprocessor macros
41  * (see importgl.h).
42  */
importGLInit()43 int importGLInit()
44 {
45     int result = 1;
46 
47 #undef IMPORT_FUNC_GL
48 
49 #define IMPORT_FUNC_GL(funcName) do { \
50         void *procAddress = waffle_dl_sym(WAFFLE_DL_OPENGL_ES2, #funcName); \
51         if (procAddress == NULL) result = 0; \
52         FNPTR(funcName) = (funcType_##funcName)procAddress; } while (0)
53 
54     IMPORT_FUNC_GL(glAttachShader);
55     IMPORT_FUNC_GL(glBindBuffer);
56     IMPORT_FUNC_GL(glBlendFunc);
57     IMPORT_FUNC_GL(glBufferData);
58     IMPORT_FUNC_GL(glBufferSubData);
59     IMPORT_FUNC_GL(glClear);
60     IMPORT_FUNC_GL(glClearColor);
61     IMPORT_FUNC_GL(glCompileShader);
62     IMPORT_FUNC_GL(glCreateProgram);
63     IMPORT_FUNC_GL(glCreateShader);
64     IMPORT_FUNC_GL(glDeleteBuffers);
65     IMPORT_FUNC_GL(glDeleteProgram);
66     IMPORT_FUNC_GL(glDeleteShader);
67     IMPORT_FUNC_GL(glDisable);
68     IMPORT_FUNC_GL(glDisableVertexAttribArray);
69     IMPORT_FUNC_GL(glDrawArrays);
70     IMPORT_FUNC_GL(glEnable);
71     IMPORT_FUNC_GL(glEnableVertexAttribArray);
72     IMPORT_FUNC_GL(glGenBuffers);
73     IMPORT_FUNC_GL(glGetAttribLocation);
74     IMPORT_FUNC_GL(glGetError);
75     IMPORT_FUNC_GL(glGetShaderiv);
76     IMPORT_FUNC_GL(glGetShaderInfoLog);
77     IMPORT_FUNC_GL(glGetUniformLocation);
78     IMPORT_FUNC_GL(glLinkProgram);
79     IMPORT_FUNC_GL(glShaderSource);
80     IMPORT_FUNC_GL(glUniform1f);
81     IMPORT_FUNC_GL(glUniform3fv);
82     IMPORT_FUNC_GL(glUniform4fv);
83     IMPORT_FUNC_GL(glUniformMatrix3fv);
84     IMPORT_FUNC_GL(glUniformMatrix4fv);
85     IMPORT_FUNC_GL(glUseProgram);
86     IMPORT_FUNC_GL(glVertexAttribPointer);
87     IMPORT_FUNC_GL(glViewport);
88 
89     return result;
90 }
91 
92 #endif  // !DISABLE_IMPORTGL
93 
94