Repository navigation
Expand file tree
/
Copy pathgl_context.h
More file actions
157 lines (141 loc) · 5.37 KB
/
Copy pathgl_context.h
File metadata and controls
157 lines (141 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* @file gl_context.h
* @author Martin Pulec <martin.pulec@cesnet.cz>
*/
/*
* Copyright (c) 2012-2026 CESNET, zájmové sdružení právnických osob
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of CESNET nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GL_CONTEXT_H_
#define _GL_CONTEXT_H_
#if defined __APPLE__
#include <OpenGL/GL.h>
#else
#include <GL/glew.h>
#endif /* !defined __APPLE__ */
#ifdef __APPLE__
#include <Availability.h>
#endif
#ifdef __cplusplus
#include <cstdio> // for fprintf, stderr
#include <cstdlib> // for abort
#else
#include <stdbool.h>
#include <stdio.h> // for fprintf, stderr
#include <stdlib.h> // for abort
#endif
#include "host.h" // for handle_eror
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#if defined __APPLE__ && ! defined __MAC_10_8
#define glGenFramebuffers glGenFramebuffersEXT
#define glBindFramebuffer glBindFramebufferEXT
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
#define glFramebufferTexture2D glFramebufferTexture2DEXT
#define glDeleteFramebuffers glDeleteFramebuffersEXT
#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
#define glCheckFramebufferStatus glCheckFramebufferStatusEXT
#endif
struct gl_context {
unsigned legacy:1;
void *context;
int gl_major;
int gl_minor;
};
#define GL_CONTEXT_ANY 0x00
#define GL_CONTEXT_LEGACY 0x01
/**
* @param which GL_CONTEXT_ANY or GL_CONTEXT_LEGACY
*/
bool init_gl_context(struct gl_context *context, int which);
void gl_context_make_current(struct gl_context *context);
void destroy_gl_context(struct gl_context *context);
/**
* @param fatal whether abort on error, if false, exit just if
* user requires so (handle_error() callback)
*/
#define gl_check_error_impl(fatal) do { \
GLenum msg = glGetError(); \
int flag = 1; \
switch(msg){ \
case GL_NO_ERROR: \
flag = 0; \
break; \
case GL_INVALID_ENUM: \
(void) fprintf(stderr, "GL_INVALID_ENUM\n"); \
break; \
case GL_INVALID_VALUE: \
(void) fprintf(stderr, "GL_INVALID_VALUE\n"); \
break; \
case GL_INVALID_OPERATION: \
(void) fprintf(stderr, "GL_INVALID_OPERATION\n"); \
break; \
case GL_STACK_OVERFLOW: \
(void) fprintf(stderr, "GL_STACK_OVERFLOW\n"); \
break; \
case GL_STACK_UNDERFLOW: \
(void) fprintf(stderr, "GL_STACK_UNDERFLOW\n"); \
break; \
case GL_OUT_OF_MEMORY: \
(void) fprintf(stderr, "GL_OUT_OF_MEMORY\n"); \
break; \
case 1286: \
(void) fprintf(stderr, \
"INVALID_FRAMEBUFFER_OPERATION_EXT\n"); \
break; \
default: \
(void) fprintf( \
stderr, "wft mate? Unknown GL ERROR: %d\n", msg); \
break; \
} \
if(flag) { \
(void) fprintf(stderr, "\tat %s:%d: %s\n", __FILE__, \
__LINE__, __func__); \
if (fatal) { \
abort(); \
} else { \
handle_error(1); \
} \
} \
} while(0)
#define gl_check_error() gl_check_error_impl(1)
#define gl_check_error_nonfatal() gl_check_error_impl(0)
/**
* compiles and links specified program shaders
* @returns shader ID
* @retval 0 on error
*/
GLuint glsl_compile_link(const char *vprogram, const char *fprogram);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* _GL_CONTEXT_H_ */