summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/BoundingBox.cpp
diff options
context:
space:
mode:
authorPringo <Pringo@users.noreply.github.com>2014-11-24 21:54:15 -0800
committerPringo <Pringo@users.noreply.github.com>2014-11-24 21:54:15 -0800
commit670d94967a64b6a3e99127caf5511b07825f21cb (patch)
treee83e2909a2db5dbe8387a40f3839d27abf588c0c /Source/Core/VideoBackends/OGL/BoundingBox.cpp
parent5a89ba20d75b17b1aeec090544934b95bdb0ec74 (diff)
parent245ff601b7033f4122b48d837171c21baa9ac306 (diff)
Merge pull request #1 from dolphin-emu/master
update
Diffstat (limited to 'Source/Core/VideoBackends/OGL/BoundingBox.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/BoundingBox.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/BoundingBox.cpp b/Source/Core/VideoBackends/OGL/BoundingBox.cpp
new file mode 100644
index 0000000000..91fedb2a2d
--- /dev/null
+++ b/Source/Core/VideoBackends/OGL/BoundingBox.cpp
@@ -0,0 +1,54 @@
+// Copyright 2014 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "VideoBackends/OGL/BoundingBox.h"
+#include "VideoBackends/OGL/GLUtil.h"
+
+#include "VideoCommon/VideoConfig.h"
+
+static GLuint s_bbox_buffer_id;
+
+namespace OGL
+{
+
+void BoundingBox::Init()
+{
+ if (g_ActiveConfig.backend_info.bSupportsBBox)
+ {
+ 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, 3, s_bbox_buffer_id);
+ }
+}
+
+void BoundingBox::Shutdown()
+{
+ if (g_ActiveConfig.backend_info.bSupportsBBox)
+ glDeleteBuffers(1, &s_bbox_buffer_id);
+}
+
+void BoundingBox::Set(int index, int value)
+{
+ 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)
+{
+ int data = 0;
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_bbox_buffer_id);
+ void* ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, index * sizeof(int), sizeof(int), GL_MAP_READ_BIT);
+ if (ptr)
+ {
+ data = *(int*)ptr;
+ glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
+ }
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
+ return data;
+}
+
+};