File size: 3,774 Bytes
111ba01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.

#pragma once

//------------------------------------------------------------------------
// Windows-specific headers and types.
//------------------------------------------------------------------------

#ifdef _WIN32
#define NOMINMAX
#include <windows.h> // Required by gl.h in Windows.
#define GLAPIENTRY APIENTRY

struct GLContext
{
    HDC     hdc;
    HGLRC   hglrc;
    int     extInitialized;
};

#endif // _WIN32

//------------------------------------------------------------------------
// Linux-specific headers and types.
//------------------------------------------------------------------------

#ifdef __linux__
#define EGL_NO_X11 // X11/Xlib.h has "#define Status int" which breaks Tensorflow. Avoid it.
#define MESA_EGL_NO_X11_HEADERS
#include <EGL/egl.h>
#include <EGL/eglext.h>
#define GLAPIENTRY

struct GLContext
{
    EGLDisplay  display;
    EGLContext  context;
    int         extInitialized;
};

#endif // __linux__

//------------------------------------------------------------------------
// OpenGL, CUDA interop, GL extensions.
//------------------------------------------------------------------------
#define GL_GLEXT_LEGACY
#include <GL/gl.h>
#include <cuda_gl_interop.h>

// Constants.
#ifndef GL_VERSION_1_2
#define GL_CLAMP_TO_EDGE                 0x812F
#define GL_TEXTURE_3D                    0x806F
#endif
#ifndef GL_VERSION_1_5
#define GL_ARRAY_BUFFER                  0x8892
#define GL_DYNAMIC_DRAW                  0x88E8
#define GL_ELEMENT_ARRAY_BUFFER          0x8893
#endif
#ifndef GL_VERSION_2_0
#define GL_FRAGMENT_SHADER               0x8B30
#define GL_INFO_LOG_LENGTH               0x8B84
#define GL_LINK_STATUS                   0x8B82
#define GL_VERTEX_SHADER                 0x8B31
#endif
#ifndef GL_VERSION_3_0
#define GL_MAJOR_VERSION                 0x821B
#define GL_MINOR_VERSION                 0x821C
#define GL_RGBA32F                       0x8814
#define GL_TEXTURE_2D_ARRAY              0x8C1A
#endif
#ifndef GL_VERSION_3_2
#define GL_GEOMETRY_SHADER               0x8DD9
#endif
#ifndef GL_ARB_framebuffer_object
#define GL_COLOR_ATTACHMENT0             0x8CE0
#define GL_COLOR_ATTACHMENT1             0x8CE1
#define GL_DEPTH_STENCIL                 0x84F9
#define GL_DEPTH_STENCIL_ATTACHMENT      0x821A
#define GL_DEPTH24_STENCIL8              0x88F0
#define GL_FRAMEBUFFER                   0x8D40
#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
#define GL_UNSIGNED_INT_24_8             0x84FA
#endif
#ifndef GL_ARB_imaging
#define GL_TABLE_TOO_LARGE               0x8031
#endif
#ifndef GL_KHR_robustness
#define GL_CONTEXT_LOST                  0x0507
#endif

// Declare function pointers to OpenGL extension functions.
#define GLUTIL_EXT(return_type, name, ...) extern return_type (GLAPIENTRY* name)(__VA_ARGS__);
#include "glutil_extlist.h"
#undef GLUTIL_EXT

//------------------------------------------------------------------------
// Common functions.
//------------------------------------------------------------------------

void        setGLContext            (GLContext& glctx);
void        releaseGLContext        (void);
GLContext   createGLContext         (int cudaDeviceIdx);
void        destroyGLContext        (GLContext& glctx);
const char* getGLErrorString        (GLenum err);

//------------------------------------------------------------------------