UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
gl_context.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2012-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _GL_CONTEXT_H_
39#define _GL_CONTEXT_H_
40
41#if defined __linux__ || defined _WIN32
42#include <GL/glew.h>
43#else
44#include <OpenGL/GL.h>
45#endif /* __linux__ */
46
47#ifdef __APPLE__
48#include <Availability.h>
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif // __cplusplus
54
55#if defined __APPLE__ && ! defined __MAC_10_8
56#define glGenFramebuffers glGenFramebuffersEXT
57#define glBindFramebuffer glBindFramebufferEXT
58#define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
59#define glFramebufferTexture2D glFramebufferTexture2DEXT
60#define glDeleteFramebuffers glDeleteFramebuffersEXT
61#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
62#define glCheckFramebufferStatus glCheckFramebufferStatusEXT
63#endif
64
65struct gl_context {
66 unsigned legacy:1;
67 void *context;
70};
71
72#define GL_CONTEXT_ANY 0x00
73#define GL_CONTEXT_LEGACY 0x01
74
78bool init_gl_context(struct gl_context *context, int which);
79void gl_context_make_current(struct gl_context *context);
80void destroy_gl_context(struct gl_context *context);
81
82#define gl_check_error() do { \
83 GLenum msg = glGetError(); \
84 int flag = 1; \
85 switch(msg){ \
86 case GL_NO_ERROR: \
87 flag = 0; \
88 break; \
89 case GL_INVALID_ENUM: \
90 fprintf(stderr, "GL_INVALID_ENUM\n"); \
91 break; \
92 case GL_INVALID_VALUE: \
93 fprintf(stderr, "GL_INVALID_VALUE\n"); \
94 break; \
95 case GL_INVALID_OPERATION: \
96 fprintf(stderr, "GL_INVALID_OPERATION\n"); \
97 break; \
98 case GL_STACK_OVERFLOW: \
99 fprintf(stderr, "GL_STACK_OVERFLOW\n"); \
100 break; \
101 case GL_STACK_UNDERFLOW: \
102 fprintf(stderr, "GL_STACK_UNDERFLOW\n"); \
103 break; \
104 case GL_OUT_OF_MEMORY: \
105 fprintf(stderr, "GL_OUT_OF_MEMORY\n"); \
106 break; \
107 case 1286: \
108 fprintf(stderr, "INVALID_FRAMEBUFFER_OPERATION_EXT\n"); \
109 break; \
110 default: \
111 fprintf(stderr, "wft mate? Unknown GL ERROR: %d\n", msg); \
112 break; \
113 } \
114 if(flag) { \
115 fprintf(stderr, "\tat %s:%d: %s\n", __FILE__, __LINE__, __func__); \
116 abort(); \
117 } \
118} while(0)
119
125GLuint glsl_compile_link(const char *vprogram, const char *fprogram);
126
127#ifdef __cplusplus
128}
129#endif // __cplusplus
130
131#endif /* _GL_CONTEXT_H_ */
132
bool init_gl_context(struct gl_context *context, int which)
initializes specified OpenGL context
Definition gl_context.c:69
void destroy_gl_context(struct gl_context *context)
Definition gl_context.c:223
void gl_context_make_current(struct gl_context *context)
Definition gl_context.c:236
GLuint glsl_compile_link(const char *vprogram, const char *fprogram)
Definition gl_context.c:147
void * context
Definition gl_context.h:67
unsigned legacy
Definition gl_context.h:66
static const char * vprogram
Definition swmix.c:468