-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathgraphicsplugin_opengl.cpp
More file actions
513 lines (432 loc) · 21.1 KB
/
graphicsplugin_opengl.cpp
File metadata and controls
513 lines (432 loc) · 21.1 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
// Copyright (c) 2017-2026 The Khronos Group Inc.
//
// SPDX-License-Identifier: Apache-2.0
#include "pch.h"
#include "common.h"
#include "geometry.h"
#include "graphicsplugin.h"
#include "graphics_plugin_impl_helpers.h"
#include "options.h"
#ifdef XR_USE_GRAPHICS_API_OPENGL
#include <common/gfxwrapper_opengl.h>
#include <common/xr_linear.h>
namespace {
static const char* VertexShaderGlsl = R"_(
#version 410
in vec3 VertexPos;
in vec3 VertexColor;
out vec3 PSVertexColor;
uniform mat4 ModelViewProjection;
void main() {
gl_Position = ModelViewProjection * vec4(VertexPos, 1.0);
PSVertexColor = VertexColor;
}
)_";
static const char* FragmentShaderGlsl = R"_(
#version 410
in vec3 PSVertexColor;
out vec4 FragColor;
void main() {
FragColor = vec4(PSVertexColor, 1);
}
)_";
std::string glResultString(GLenum err) {
switch (err) {
case GL_NO_ERROR:
return "GL_NO_ERROR";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
default:
return "<unknown " + std::to_string(err) + ">";
}
}
[[noreturn]] inline void ThrowGLResult(GLenum res, const char* originator = nullptr, const char* sourceLocation = nullptr) {
Throw("GL failure " + glResultString(res), originator, sourceLocation);
}
inline GLenum CheckThrowGLResult(GLenum res, const char* originator = nullptr, const char* sourceLocation = nullptr) {
if ((res) != GL_NO_ERROR) {
ThrowGLResult(res, originator, sourceLocation);
}
return res;
}
#define CHECK_GLCMD(cmd) CheckThrowGLResult(((cmd), glGetError()), #cmd, FILE_AND_LINE)
inline GLenum TexTarget(bool isArray, bool isMultisample) {
if (isArray && isMultisample) {
return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
} else if (isMultisample) {
return GL_TEXTURE_2D_MULTISAMPLE;
} else if (isArray) {
return GL_TEXTURE_2D_ARRAY;
} else {
return GL_TEXTURE_2D;
}
}
struct OpenGLGraphicsPlugin : public IGraphicsPlugin {
OpenGLGraphicsPlugin(const std::shared_ptr<Options>& options, const std::shared_ptr<IPlatformPlugin> /*unused*/&)
: m_clearColor(options->GetBackgroundClearColor()) {}
OpenGLGraphicsPlugin(const OpenGLGraphicsPlugin&) = delete;
OpenGLGraphicsPlugin& operator=(const OpenGLGraphicsPlugin&) = delete;
OpenGLGraphicsPlugin(OpenGLGraphicsPlugin&&) = delete;
OpenGLGraphicsPlugin& operator=(OpenGLGraphicsPlugin&&) = delete;
~OpenGLGraphicsPlugin() override {
if (m_swapchainFramebuffer != 0) {
glDeleteFramebuffers(1, &m_swapchainFramebuffer);
}
if (m_program != 0) {
glDeleteProgram(m_program);
}
if (m_vao != 0) {
glDeleteVertexArrays(1, &m_vao);
}
if (m_cubeVertexBuffer != 0) {
glDeleteBuffers(1, &m_cubeVertexBuffer);
}
if (m_cubeIndexBuffer != 0) {
glDeleteBuffers(1, &m_cubeIndexBuffer);
}
ksGpuWindow_Destroy(&window);
}
std::vector<std::string> GetInstanceExtensions() const override { return {XR_KHR_OPENGL_ENABLE_EXTENSION_NAME}; }
ksGpuWindow window{};
#if !defined(XR_USE_PLATFORM_MACOS)
void DebugMessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message) {
(void)source;
(void)type;
(void)id;
(void)severity;
Log::Write(Log::Level::Info, "GL Debug: " + std::string(message, 0, length));
}
#endif // !defined(XR_USE_PLATFORM_MACOS)
void InitializeDevice(XrInstance instance, XrSystemId systemId) override {
// Extension function must be loaded by name
PFN_xrGetOpenGLGraphicsRequirementsKHR pfnGetOpenGLGraphicsRequirementsKHR = nullptr;
CHECK_XRCMD(xrGetInstanceProcAddr(instance, "xrGetOpenGLGraphicsRequirementsKHR",
reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetOpenGLGraphicsRequirementsKHR)));
XrGraphicsRequirementsOpenGLKHR graphicsRequirements{XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR};
CHECK_XRCMD(pfnGetOpenGLGraphicsRequirementsKHR(instance, systemId, &graphicsRequirements));
// Initialize the gl extensions. Note we have to open a window.
ksDriverInstance driverInstance{};
ksGpuQueueInfo queueInfo{};
ksGpuSurfaceColorFormat colorFormat{KS_GPU_SURFACE_COLOR_FORMAT_B8G8R8A8};
ksGpuSurfaceDepthFormat depthFormat{KS_GPU_SURFACE_DEPTH_FORMAT_D24};
ksGpuSampleCount sampleCount{KS_GPU_SAMPLE_COUNT_1};
if (!ksGpuWindow_Create(&window, &driverInstance, &queueInfo, 0, colorFormat, depthFormat, sampleCount, 640, 480, false)) {
THROW("Unable to create GL context");
}
GLint major = 0;
GLint minor = 0;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
const XrVersion desiredApiVersion = XR_MAKE_VERSION(major, minor, 0);
if (graphicsRequirements.minApiVersionSupported > desiredApiVersion) {
THROW("Runtime does not support desired Graphics API and/or version");
}
#ifdef XR_USE_PLATFORM_WIN32
m_graphicsBinding.hDC = window.context.hDC;
m_graphicsBinding.hGLRC = window.context.hGLRC;
#elif defined(XR_USE_PLATFORM_XLIB)
m_graphicsBinding.xDisplay = window.context.xDisplay;
m_graphicsBinding.visualid = window.context.visualid;
m_graphicsBinding.glxFBConfig = window.context.glxFBConfig;
m_graphicsBinding.glxDrawable = window.context.glxDrawable;
m_graphicsBinding.glxContext = window.context.glxContext;
#elif defined(XR_USE_PLATFORM_XCB)
// TODO: Still missing the platform adapter, and some items to make this usable.
m_graphicsBinding.connection = window.connection;
// m_graphicsBinding.screenNumber = window.context.screenNumber;
// m_graphicsBinding.fbconfigid = window.context.fbconfigid;
m_graphicsBinding.visualid = window.context.visualid;
m_graphicsBinding.glxDrawable = window.context.glxDrawable;
// m_graphicsBinding.glxContext = window.context.glxContext;
#elif defined(XR_USE_PLATFORM_WAYLAND)
// TODO: Just need something other than NULL here for now (for validation). Eventually need
// to correctly put in a valid pointer to an wl_display
m_graphicsBinding.display = reinterpret_cast<wl_display*>(0xFFFFFFFF);
#elif defined(XR_USE_PLATFORM_MACOS)
#error OpenGL bindings for Mac have not been implemented
#else
#error Platform not supported
#endif
#if !defined(XR_USE_PLATFORM_MACOS)
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(
[](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message,
const void* userParam) {
((OpenGLGraphicsPlugin*)userParam)->DebugMessageCallback(source, type, id, severity, length, message);
},
this);
#endif // !defined(XR_USE_PLATFORM_MACOS)
InitializeResources();
}
void InitializeResources() {
glGenFramebuffers(1, &m_swapchainFramebuffer);
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &VertexShaderGlsl, nullptr);
glCompileShader(vertexShader);
CheckShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &FragmentShaderGlsl, nullptr);
glCompileShader(fragmentShader);
CheckShader(fragmentShader);
m_program = glCreateProgram();
glAttachShader(m_program, vertexShader);
glAttachShader(m_program, fragmentShader);
glLinkProgram(m_program);
CheckProgram(m_program);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
m_modelViewProjectionUniformLocation = glGetUniformLocation(m_program, "ModelViewProjection");
m_vertexAttribCoords = glGetAttribLocation(m_program, "VertexPos");
m_vertexAttribColor = glGetAttribLocation(m_program, "VertexColor");
glGenBuffers(1, &m_cubeVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_cubeVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Geometry::c_cubeVertices), Geometry::c_cubeVertices, GL_STATIC_DRAW);
glGenBuffers(1, &m_cubeIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_cubeIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Geometry::c_cubeIndices), Geometry::c_cubeIndices, GL_STATIC_DRAW);
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
glEnableVertexAttribArray(m_vertexAttribCoords);
glEnableVertexAttribArray(m_vertexAttribColor);
glBindBuffer(GL_ARRAY_BUFFER, m_cubeVertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_cubeIndexBuffer);
glVertexAttribPointer(m_vertexAttribCoords, 3, GL_FLOAT, GL_FALSE, sizeof(Geometry::Vertex), nullptr);
glVertexAttribPointer(m_vertexAttribColor, 3, GL_FLOAT, GL_FALSE, sizeof(Geometry::Vertex),
reinterpret_cast<const void*>(sizeof(XrVector3f)));
}
void CheckShader(GLuint shader) {
GLint r = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &r);
if (r == GL_FALSE) {
GLchar msg[4096] = {};
GLsizei length;
glGetShaderInfoLog(shader, sizeof(msg), &length, msg);
THROW(Fmt("Compile shader failed: %s", msg));
}
}
void CheckProgram(GLuint prog) {
GLint r = 0;
glGetProgramiv(prog, GL_LINK_STATUS, &r);
if (r == GL_FALSE) {
GLchar msg[4096] = {};
GLsizei length;
glGetProgramInfoLog(prog, sizeof(msg), &length, msg);
THROW(Fmt("Link program failed: %s", msg));
}
}
int64_t SelectColorSwapchainFormat(bool throwIfNotFound, span<const int64_t> imageFormatArray) const override {
// List of supported color swapchain formats, note sRGB formats skipped due to CTS bug.
// The order of this list does not effect the priority of selecting formats, the runtime list defines that.
return SelectSwapchainFormat( //
throwIfNotFound, imageFormatArray,
{
GL_RGB10_A2,
GL_RGBA16,
GL_RGBA16F,
GL_RGBA32F,
// The two below should only be used as a fallback, as they are linear color formats without enough bits for color
// depth, thus leading to banding.
GL_RGBA8,
GL_RGBA8_SNORM,
});
}
int64_t SelectDepthSwapchainFormat(bool throwIfNotFound, span<const int64_t> imageFormatArray) const override {
// List of supported depth swapchain formats.
return SelectSwapchainFormat( //
throwIfNotFound, imageFormatArray,
{
GL_DEPTH24_STENCIL8,
GL_DEPTH32F_STENCIL8,
GL_DEPTH_COMPONENT24,
GL_DEPTH_COMPONENT32F,
GL_DEPTH_COMPONENT16,
});
}
const XrBaseInStructure* GetGraphicsBinding() const override {
return reinterpret_cast<const XrBaseInStructure*>(&m_graphicsBinding);
}
struct OpenGLFallbackDepthTexture {
public:
OpenGLFallbackDepthTexture() = default;
~OpenGLFallbackDepthTexture() {
if (Allocated()) {
// As implementation as ::Reset(), but should not throw in destructor
glDeleteTextures(1, &m_texture);
}
m_texture = 0;
}
void Reset() {
if (Allocated()) {
CHECK_GLCMD(glDeleteTextures(1, &m_texture));
}
m_texture = 0;
}
bool Allocated() const { return m_texture != 0; }
void Allocate(GLuint width, GLuint height, uint32_t arraySize, uint32_t sampleCount) {
Reset();
const bool isArray = arraySize > 1;
const bool isMultisample = sampleCount > 1;
GLenum target = TexTarget(isArray, isMultisample);
CHECK_GLCMD(glGenTextures(1, &m_texture));
CHECK_GLCMD(glBindTexture(target, m_texture));
if (!isMultisample) {
CHECK_GLCMD(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
CHECK_GLCMD(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
CHECK_GLCMD(glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
CHECK_GLCMD(glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
if (isMultisample) {
if (isArray) {
CHECK_GLCMD(glTexImage3DMultisample(target, sampleCount, GL_DEPTH_COMPONENT32, width, height, arraySize, true));
} else {
CHECK_GLCMD(glTexImage2DMultisample(target, sampleCount, GL_DEPTH_COMPONENT32, width, height, true));
}
} else {
if (isArray) {
CHECK_GLCMD(glTexImage3D(target, 0, GL_DEPTH_COMPONENT32, width, height, arraySize, 0, GL_DEPTH_COMPONENT,
GL_FLOAT, nullptr));
} else {
CHECK_GLCMD(
glTexImage2D(target, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr));
}
}
m_image.image = m_texture;
}
const XrSwapchainImageOpenGLKHR& GetTexture() const { return m_image; }
private:
uint32_t m_texture{0};
XrSwapchainImageOpenGLKHR m_image{XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR, NULL, 0};
};
class OpenGLSwapchainImageData : public SwapchainImageDataBase<XrSwapchainImageOpenGLKHR> {
public:
OpenGLSwapchainImageData(uint32_t capacity, const XrSwapchainCreateInfo& createInfo)
: SwapchainImageDataBase(XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR, capacity, createInfo), m_internalDepthTextures(capacity) {}
OpenGLSwapchainImageData(uint32_t capacity, const XrSwapchainCreateInfo& createInfo, XrSwapchain depthSwapchain,
const XrSwapchainCreateInfo& depthCreateInfo)
: SwapchainImageDataBase(XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR, capacity, createInfo, depthSwapchain, depthCreateInfo),
m_internalDepthTextures(capacity) {}
protected:
const XrSwapchainImageOpenGLKHR& GetFallbackDepthSwapchainImage(uint32_t i) override {
if (!m_internalDepthTextures[i].Allocated()) {
m_internalDepthTextures[i].Allocate(this->Width(), this->Height(), this->ArraySize(), this->SampleCount());
}
return m_internalDepthTextures[i].GetTexture();
}
private:
std::vector<OpenGLFallbackDepthTexture> m_internalDepthTextures;
};
ISwapchainImageData* AllocateSwapchainImageData(size_t size, const XrSwapchainCreateInfo& swapchainCreateInfo) override {
auto typedResult = std::make_unique<OpenGLSwapchainImageData>(uint32_t(size), swapchainCreateInfo);
// Cast our derived type to the caller-expected type.
auto ret = static_cast<ISwapchainImageData*>(typedResult.get());
m_swapchainImageDataMap.Adopt(std::move(typedResult));
return ret;
}
inline ISwapchainImageData* AllocateSwapchainImageDataWithDepthSwapchain(
size_t size, const XrSwapchainCreateInfo& colorSwapchainCreateInfo, XrSwapchain depthSwapchain,
const XrSwapchainCreateInfo& depthSwapchainCreateInfo) override {
auto typedResult = std::make_unique<OpenGLSwapchainImageData>(uint32_t(size), colorSwapchainCreateInfo, depthSwapchain,
depthSwapchainCreateInfo);
// Cast our derived type to the caller-expected type.
auto ret = static_cast<ISwapchainImageData*>(typedResult.get());
m_swapchainImageDataMap.Adopt(std::move(typedResult));
return ret;
}
void RenderView(const XrCompositionLayerProjectionView& layerView, const XrSwapchainImageBaseHeader* swapchainImage,
int64_t colorSwapchainFormat, int64_t depthSwapchainFormat, const std::vector<Cube>& cubes) override {
CHECK(layerView.subImage.imageArrayIndex == 0); // Texture arrays not supported.
UNUSED_PARM(colorSwapchainFormat); // Not used in this function for now.
UNUSED_PARM(depthSwapchainFormat); // Not used in this function for now.
OpenGLSwapchainImageData* swapchainData;
uint32_t imageIndex;
std::tie(swapchainData, imageIndex) = m_swapchainImageDataMap.GetDataAndIndexFromBasePointer(swapchainImage);
glBindFramebuffer(GL_FRAMEBUFFER, m_swapchainFramebuffer);
const uint32_t colorTexture = reinterpret_cast<const XrSwapchainImageOpenGLKHR*>(swapchainImage)->image;
const GLuint depthTexture = swapchainData->GetDepthImageForColorIndex(imageIndex).image;
glViewport(static_cast<GLint>(layerView.subImage.imageRect.offset.x),
static_cast<GLint>(layerView.subImage.imageRect.offset.y),
static_cast<GLsizei>(layerView.subImage.imageRect.extent.width),
static_cast<GLsizei>(layerView.subImage.imageRect.extent.height));
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
// Clear swapchain and depth buffer.
glClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearColor[3]);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Set shaders and uniform variables.
glUseProgram(m_program);
const auto& pose = layerView.pose;
XrMatrix4x4f proj;
XrMatrix4x4f_CreateProjectionFov(&proj, GRAPHICS_OPENGL, layerView.fov, 0.05f, 100.0f);
XrMatrix4x4f toView;
XrMatrix4x4f_CreateFromRigidTransform(&toView, &pose);
XrMatrix4x4f view;
XrMatrix4x4f_InvertRigidBody(&view, &toView);
XrMatrix4x4f vp;
XrMatrix4x4f_Multiply(&vp, &proj, &view);
// Set cube primitive data.
glBindVertexArray(m_vao);
// Render each cube
for (const Cube& cube : cubes) {
// Compute the model-view-projection transform and set it..
XrMatrix4x4f model;
XrMatrix4x4f_CreateTranslationRotationScale(&model, &cube.Pose.position, &cube.Pose.orientation, &cube.Scale);
XrMatrix4x4f mvp;
XrMatrix4x4f_Multiply(&mvp, &vp, &model);
glUniformMatrix4fv(m_modelViewProjectionUniformLocation, 1, GL_FALSE, reinterpret_cast<const GLfloat*>(&mvp));
// Draw the cube.
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(ArraySize(Geometry::c_cubeIndices)), GL_UNSIGNED_SHORT, nullptr);
}
glBindVertexArray(0);
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
uint32_t GetSupportedSwapchainSampleCount(const XrViewConfigurationView&) override { return 1; }
void UpdateOptions(const std::shared_ptr<Options>& options) override { m_clearColor = options->GetBackgroundClearColor(); }
private:
#ifdef XR_USE_PLATFORM_WIN32
XrGraphicsBindingOpenGLWin32KHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR};
#elif defined(XR_USE_PLATFORM_XLIB)
XrGraphicsBindingOpenGLXlibKHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR};
#elif defined(XR_USE_PLATFORM_XCB)
XrGraphicsBindingOpenGLXcbKHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR};
#elif defined(XR_USE_PLATFORM_WAYLAND)
XrGraphicsBindingOpenGLWaylandKHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR};
#elif defined(XR_USE_PLATFORM_MACOS)
#error OpenGL bindings for Mac have not been implemented
#else
#error Platform not supported
#endif
SwapchainImageDataMap<OpenGLSwapchainImageData> m_swapchainImageDataMap;
GLuint m_swapchainFramebuffer{0};
GLuint m_program{0};
GLint m_modelViewProjectionUniformLocation{0};
GLint m_vertexAttribCoords{0};
GLint m_vertexAttribColor{0};
GLuint m_vao{0};
GLuint m_cubeVertexBuffer{0};
GLuint m_cubeIndexBuffer{0};
std::array<float, 4> m_clearColor;
};
} // namespace
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_OpenGL(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin) {
return std::make_shared<OpenGLGraphicsPlugin>(options, platformPlugin);
}
#endif