summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-05-24 23:32:01 -0400
committerGravatar Lioncash2019-05-24 23:50:10 -0400
commit5a4564bd8eae9c8fef6da70009536ce50b5752d5 (patch)
treee2c03d0a39175e2310d9a2289b7cf9274a8fa95a /src
parentMerge pull request #2513 from lioncash/string (diff)
downloadyuzu-5a4564bd8eae9c8fef6da70009536ce50b5752d5.tar.gz
yuzu-5a4564bd8eae9c8fef6da70009536ce50b5752d5.tar.xz
yuzu-5a4564bd8eae9c8fef6da70009536ce50b5752d5.zip
renderer_opengl/utils: Use a std::string_view with LabelGLObject()
Uses a std::string_view instead of a std::string, given the pointed to string isn't modified and is only used in a formatting operation. This is nice because a few usages directly supply a string literal to the function, allowing these usages to otherwise not heap allocate, unlike the std::string overloads. While we're at it, we can combine the address formatting into a single formatting call.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/utils.cpp16
-rw-r--r--src/video_core/renderer_opengl/utils.h4
2 files changed, 10 insertions, 10 deletions
diff --git a/src/video_core/renderer_opengl/utils.cpp b/src/video_core/renderer_opengl/utils.cpp
index 84a987371..f23fc9f9d 100644
--- a/src/video_core/renderer_opengl/utils.cpp
+++ b/src/video_core/renderer_opengl/utils.cpp
@@ -38,27 +38,27 @@ void BindBuffersRangePushBuffer::Bind() const {
38 sizes.data()); 38 sizes.data());
39} 39}
40 40
41void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string extra_info) { 41void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string_view extra_info) {
42 if (!GLAD_GL_KHR_debug) { 42 if (!GLAD_GL_KHR_debug) {
43 return; // We don't need to throw an error as this is just for debugging 43 // We don't need to throw an error as this is just for debugging
44 return;
44 } 45 }
45 const std::string nice_addr = fmt::format("0x{:016x}", addr);
46 std::string object_label;
47 46
47 std::string object_label;
48 if (extra_info.empty()) { 48 if (extra_info.empty()) {
49 switch (identifier) { 49 switch (identifier) {
50 case GL_TEXTURE: 50 case GL_TEXTURE:
51 object_label = "Texture@" + nice_addr; 51 object_label = fmt::format("Texture@0x{:016X}", addr);
52 break; 52 break;
53 case GL_PROGRAM: 53 case GL_PROGRAM:
54 object_label = "Shader@" + nice_addr; 54 object_label = fmt::format("Shader@0x{:016X}", addr);
55 break; 55 break;
56 default: 56 default:
57 object_label = fmt::format("Object(0x{:x})@{}", identifier, nice_addr); 57 object_label = fmt::format("Object(0x{:X})@0x{:016X}", identifier, addr);
58 break; 58 break;
59 } 59 }
60 } else { 60 } else {
61 object_label = extra_info + '@' + nice_addr; 61 object_label = fmt::format("{}@0x{:016X}", extra_info, addr);
62 } 62 }
63 glObjectLabel(identifier, handle, -1, static_cast<const GLchar*>(object_label.c_str())); 63 glObjectLabel(identifier, handle, -1, static_cast<const GLchar*>(object_label.c_str()));
64} 64}
diff --git a/src/video_core/renderer_opengl/utils.h b/src/video_core/renderer_opengl/utils.h
index aef45c9dc..b3e9fc499 100644
--- a/src/video_core/renderer_opengl/utils.h
+++ b/src/video_core/renderer_opengl/utils.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <string> 7#include <string_view>
8#include <vector> 8#include <vector>
9#include <glad/glad.h> 9#include <glad/glad.h>
10#include "common/common_types.h" 10#include "common/common_types.h"
@@ -30,6 +30,6 @@ private:
30 std::vector<GLsizeiptr> sizes; 30 std::vector<GLsizeiptr> sizes;
31}; 31};
32 32
33void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string extra_info = ""); 33void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string_view extra_info = {});
34 34
35} // namespace OpenGL \ No newline at end of file 35} // namespace OpenGL \ No newline at end of file