1 /* libfsgl - utility and wrapper functions for OpenGL
2  * Copyright (C) 2011 Frode Solheim <frode-code@fengestad.no>
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or (at
7  * your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #ifndef LIBFSGL_OPENGL_H
20 #define LIBFSGL_OPENGL_H
21 
22 #if defined(USE_GLES) && !defined(FAKE_GLES)
23 #include <GLES/gl.h>
24 #define GL_BGRA 0x80e1
25 #elif defined(WITH_GLEW)
26 #include <GL/glew.h>
27 #elif defined(WITH_GLAD)
28 #include <glad/glad.h>
29 #elif defined(USE_SDL2)
30 #include <SDL_opengl.h>
31 #elif defined(USE_SDL)
32 #include <SDL_opengl.h>
33 #else
34 #include <GL/gl.h>
35 #endif
36 
37 #ifndef APIENTRY
38     #define APIENTRY
39 #endif
40 #ifndef APIENTRYP
41     #define APIENTRYP APIENTRY *
42 #endif
43 
44 void fs_gl_finish();
45 void fs_gl_texturing(int enable);
46 void fs_gl_bind_texture(int texture);
47 void fs_gl_unpack_row_length(int length);
48 
49 void fs_gl_blending(int enable);
50 void fs_gl_color4fv(float *c);
51 void fs_gl_color4f(float r, float g, float b, float a);
52 
53 void fs_gl_ortho(void);
54 void fs_gl_ortho_hd(void);
55 void fs_gl_ortho_render(void);
56 void fs_gl_perspective();
57 void fs_gl_viewport(int x, int y, int w, int h);
58 
59 void fs_gl_reset_client_state();
60 
61 #define FS_GL_CONTEXT_CREATE 1
62 #define FS_GL_CONTEXT_DESTROY 2
63 
64 typedef void (*fs_gl_context_notify_function)(int notification, void *data);
65 
66 void fs_gl_send_context_notification(int notification);
67 
68 void fs_gl_add_context_notification(fs_gl_context_notify_function function,
69         void *data);
70 void fs_gl_remove_context_notification(fs_gl_context_notify_function function,
71         void *data);
72 
73 //#define FS_DEBUG_OPENGL
74 
75 #ifdef FS_DEBUG_OPENGL
76 #define CHECK_GL_ERROR() { \
77     int error = glGetError(); \
78     while (error) { \
79         printf("GL ERROR %d (%s %s:%d)\n", error, __FUNCTION__, __FILE__, \
80                 __LINE__); \
81         error = glGetError(); \
82     } \
83 }
84 #else
85 #define CHECK_GL_ERROR()
86 #endif
87 
88 #ifdef FSUAE
89 
90 typedef GLsync (APIENTRYP FS_PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags);
91 typedef GLenum (APIENTRYP FS_PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
92 typedef void (APIENTRYP FS_PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
93 
94 typedef void (APIENTRYP FS_PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences);
95 typedef void (APIENTRYP FS_PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences);
96 typedef void (APIENTRYP FS_PFNGLSETFENCEAPPLEPROC) (GLuint fence);
97 typedef GLboolean (APIENTRYP FS_PFNGLISFENCEAPPLEPROC) (GLuint fence);
98 typedef GLboolean (APIENTRYP FS_PFNGLTESTFENCEAPPLEPROC) (GLuint fence);
99 typedef void (APIENTRYP FS_PFNGLFINISHFENCEAPPLEPROC) (GLuint fence);
100 typedef GLboolean (APIENTRYP FS_PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name);
101 typedef void (APIENTRYP FS_PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name);
102 
103 typedef void (APIENTRYP FS_PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
104 typedef void (APIENTRYP FS_PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
105 typedef GLboolean (APIENTRYP FS_PFNGLISFENCENVPROC) (GLuint fence);
106 typedef GLboolean (APIENTRYP FS_PFNGLTESTFENCENVPROC) (GLuint fence);
107 typedef void (APIENTRYP FS_PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
108 typedef void (APIENTRYP FS_PFNGLFINISHFENCENVPROC) (GLuint fence);
109 typedef void (APIENTRYP FS_PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
110 
111 #endif
112 
113 #endif /* LIBFSGL_OPENGL_H_ */
114