diff options
| author | Léo Lam <leo@leolam.fr> | 2021-01-28 01:33:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-28 01:33:46 +0100 |
| commit | 9ca24ae8e0da53d09e402d18055f102440af7098 (patch) | |
| tree | c1afad8f3611bf1cd49383100f21a635462269c1 /Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp | |
| parent | 4740c2a882fc13fe93adae74139caadc0917c100 (diff) | |
| parent | 500a694ca870f9f5a8ea196f4099a0e7de09fe50 (diff) | |
Merge pull request #9092 from shuffle2/vshack
msbuild: Merge "Core" libs into single DolphinLib
Diffstat (limited to 'Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp b/Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp new file mode 100644 index 0000000000..9e88767afc --- /dev/null +++ b/Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp @@ -0,0 +1,78 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include <cstring> + +#include "Common/GL/GLUtil.h" + +#include "VideoBackends/OGL/OGLBoundingBox.h" +#include "VideoBackends/OGL/OGLRender.h" + +#include "VideoCommon/DriverDetails.h" +#include "VideoCommon/VideoConfig.h" + +static GLuint s_bbox_buffer_id; + +namespace OGL +{ +void BoundingBox::Init() +{ + if (!g_ActiveConfig.backend_info.bSupportsBBox) + return; + + int initial_values[4] = {0, 0, 0, 0}; + glGenBuffers(1, &s_bbox_buffer_id); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_bbox_buffer_id); + glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * sizeof(s32), initial_values, GL_DYNAMIC_DRAW); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, s_bbox_buffer_id); +} + +void BoundingBox::Shutdown() +{ + if (!g_ActiveConfig.backend_info.bSupportsBBox) + return; + + glDeleteBuffers(1, &s_bbox_buffer_id); +} + +void BoundingBox::Set(int index, int value) +{ + if (!g_ActiveConfig.backend_info.bSupportsBBox) + return; + + glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_bbox_buffer_id); + glBufferSubData(GL_SHADER_STORAGE_BUFFER, index * sizeof(int), sizeof(int), &value); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); +} + +int BoundingBox::Get(int index) +{ + if (!g_ActiveConfig.backend_info.bSupportsBBox) + return 0; + + int data = 0; + glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_bbox_buffer_id); + if (!DriverDetails::HasBug(DriverDetails::BUG_SLOW_GETBUFFERSUBDATA) && + !static_cast<Renderer*>(g_renderer.get())->IsGLES()) + { + // Using glMapBufferRange to read back the contents of the SSBO is extremely slow + // on nVidia drivers. This is more noticeable at higher internal resolutions. + // Using glGetBufferSubData instead does not seem to exhibit this slowdown. + glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, index * sizeof(int), sizeof(int), &data); + } + else + { + // Using glMapBufferRange is faster on AMD cards by a measurable margin. + void* ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, index * sizeof(int), sizeof(int), + GL_MAP_READ_BIT); + if (ptr) + { + memcpy(&data, ptr, sizeof(int)); + glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); + } + } + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + return data; +} +}; // namespace OGL |
