1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2010-2017. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 
21 #include "erl_driver.h"
22 
23 /* Wrap everything from glext.h so we are not dependent on the user version of it */
24 
25 #ifndef _WIN32
26 # include <dlfcn.h>
27 #endif
28 
29 #ifdef _WIN32
30 #include <windows.h>
31 #include <gl/gl.h>
32 #include <gl/glu.h>
33 #elif defined(HAVE_GL_GL_H)
34 #include <GL/gl.h>
35 # include <GL/glu.h>
36 #elif defined(HAVE_OPENGL_GL_H)
37 #include <OpenGL/gl.h>
38 #include <OpenGL/glu.h>
39 #endif
40 
41 #ifndef APIENTRY
42 #define APIENTRY
43 #endif
44 
45 #ifndef CALLBACK
46 # define CALLBACK
47 #endif
48 
49 #ifdef _WIN32
50 # ifndef _GLUfuncptr
51 //  Visual studio CPP ++ compiler
52 #  define _GLUfuncptr void (_stdcall *)()
53 # endif
54 #endif
55 
56 #ifdef _GLUfuncptr
57 # define GLUfuncptr _GLUfuncptr
58 #elif defined(TESS_CB_TIGER_STYLE)
59 # define GLUfuncptr GLvoid (*)(...)
60 #else
61 # define GLUfuncptr GLvoid (*)()
62 #endif
63 
64 /* Some new GL types (eliminates the need for glext.h) */
65 
66 #ifndef HAVE_GLINTPTR
67 #ifndef HAVE_GLINTPTRARB
68 # include <stddef.h>
69 /* GL types for handling large vertex buffer objects */
70 typedef ptrdiff_t GLintptrARB;
71 typedef ptrdiff_t GLsizeiptrARB;
72 #endif  /* HAVE_GLINTPTRARB */
73 typedef GLintptrARB   GLintptr;
74 typedef GLsizeiptrARB GLsizeiptr;
75 #endif  /* HAVE_GLINTPTR */
76 
77 #ifndef HAVE_GLCHAR
78 # ifndef HAVE_GLCHARARB
79 /* GL types for handling shader object handles and characters */
80 typedef char GLcharARB;		     /* native character */
81 typedef unsigned int GLhandleARB;    /* shader object handle */
82 #endif  /* HAVE_GLCHARARB */
83 typedef GLcharARB GLchar;
84 #endif
85 
86 #ifndef HAVE_GLHALFARB
87 /* GL types for "half" precision (s10e5) float data in host memory */
88 typedef unsigned short GLhalfARB;
89 #endif
90 
91 /* Define int32_t, int64_t, and uint64_t types for UST/MSC */
92 /* (as used in the GLX_OML_sync_control extension). */
93 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
94 #include <inttypes.h>
95 #elif defined(__sun__)
96 #include <inttypes.h>
97 #if defined(__STDC__)
98 #if defined(__arch64__)
99 typedef long int int64_t;
100 typedef unsigned long int uint64_t;
101 #else
102 typedef long long int int64_t;
103 typedef unsigned long long int uint64_t;
104 #endif /* __arch64__ */
105 #endif /* __STDC__ */
106 #elif defined( __VMS )
107 #include <inttypes.h>
108 #elif defined(__SCO__) || defined(__USLC__)
109 #include <stdint.h>
110 #elif defined(__UNIXOS2__) || defined(__SOL64__)
111 typedef long int int32_t;
112 typedef long long int int64_t;
113 typedef unsigned long long int uint64_t;
114 #elif defined(WIN32) && defined(_MSC_VER)
115 typedef __int32 int32_t;
116 typedef __int64 int64_t;
117 typedef unsigned __int64 uint64_t;
118 #elif defined(WIN32) && defined(__GNUC__)
119 #include <stdint.h>
120 #else
121 #include <inttypes.h>     /* Fallback option */
122 #endif
123 
124 #ifndef HAVE_GLINT64EXT
125 typedef int64_t GLint64EXT;
126 typedef uint64_t GLuint64EXT;
127 #endif
128 
129 #ifndef GL_ARB_sync
130 typedef int64_t GLint64;
131 typedef uint64_t GLuint64;
132 typedef struct __GLsync *GLsync;
133 #endif
134 
135 /* External Api */
136 
137 #ifdef _WIN32
138 extern "C" __declspec(dllexport) int  egl_init_opengl(void *);
139 extern "C" __declspec(dllexport) void egl_dispatch(int, char *, ErlDrvPort, ErlDrvTermData, char **, int *);
140 #else
141 extern "C" int egl_init_opengl(void *);
142 extern "C" void egl_dispatch(int, char *, ErlDrvPort, ErlDrvTermData, char **, int *);
143 #endif
144 
145 /* internal */
146 int erl_tess_impl(char* buff, ErlDrvPort port, ErlDrvTermData caller);
147 void gl_error();
148 extern int gl_error_op;
149 extern ErlDrvTermData gl_active;
150 
151