yuzu-emu
/
yuzu
Archived
1
0
Fork 0

gl_shader_util: Use std::string_view instead of star pointer

This allows us passing any type of string and hinting the length of the
string to the OpenGL driver.
This commit is contained in:
ReinUsesLisp 2020-08-23 21:23:54 -03:00
parent 9619964e8c
commit 0eaf7e1daa
5 changed files with 21 additions and 9 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <string_view>
#include <utility> #include <utility>
#include <glad/glad.h> #include <glad/glad.h>
#include "common/common_types.h" #include "common/common_types.h"
@ -82,11 +83,13 @@ void OGLSampler::Release() {
handle = 0; handle = 0;
} }
void OGLShader::Create(const char* source, GLenum type) { void OGLShader::Create(std::string_view source, GLenum type) {
if (handle != 0) if (handle != 0) {
return; return;
if (source == nullptr) }
if (source.empty()) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation); MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
handle = GLShader::LoadShader(source, type); handle = GLShader::LoadShader(source, type);

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <string_view>
#include <utility> #include <utility>
#include <glad/glad.h> #include <glad/glad.h>
#include "common/common_types.h" #include "common/common_types.h"
@ -127,7 +128,7 @@ public:
return *this; return *this;
} }
void Create(const char* source, GLenum type); void Create(std::string_view source, GLenum type);
void Release(); void Release();

View File

@ -22,6 +22,7 @@
#include "video_core/memory_manager.h" #include "video_core/memory_manager.h"
#include "video_core/renderer_opengl/gl_arb_decompiler.h" #include "video_core/renderer_opengl/gl_arb_decompiler.h"
#include "video_core/renderer_opengl/gl_rasterizer.h" #include "video_core/renderer_opengl/gl_rasterizer.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_cache.h" #include "video_core/renderer_opengl/gl_shader_cache.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_disk_cache.h" #include "video_core/renderer_opengl/gl_shader_disk_cache.h"

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <string_view>
#include <vector> #include <vector>
#include <glad/glad.h> #include <glad/glad.h>
#include "common/assert.h" #include "common/assert.h"
@ -11,7 +12,8 @@
namespace OpenGL::GLShader { namespace OpenGL::GLShader {
namespace { namespace {
const char* GetStageDebugName(GLenum type) {
std::string_view StageDebugName(GLenum type) {
switch (type) { switch (type) {
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
return "vertex"; return "vertex";
@ -25,12 +27,17 @@ const char* GetStageDebugName(GLenum type) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return "unknown"; return "unknown";
} }
} // Anonymous namespace } // Anonymous namespace
GLuint LoadShader(const char* source, GLenum type) { GLuint LoadShader(std::string_view source, GLenum type) {
const char* debug_type = GetStageDebugName(type); const std::string_view debug_type = StageDebugName(type);
const GLuint shader_id = glCreateShader(type); const GLuint shader_id = glCreateShader(type);
glShaderSource(shader_id, 1, &source, nullptr);
const GLchar* source_string = source.data();
const GLint source_length = static_cast<GLint>(source.size());
glShaderSource(shader_id, 1, &source_string, &source_length);
LOG_DEBUG(Render_OpenGL, "Compiling {} shader...", debug_type); LOG_DEBUG(Render_OpenGL, "Compiling {} shader...", debug_type);
glCompileShader(shader_id); glCompileShader(shader_id);

View File

@ -38,7 +38,7 @@ void LogShaderSource(T... shaders) {
* @param source String of the GLSL shader program * @param source String of the GLSL shader program
* @param type Type of the shader (GL_VERTEX_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER) * @param type Type of the shader (GL_VERTEX_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER)
*/ */
GLuint LoadShader(const char* source, GLenum type); GLuint LoadShader(std::string_view source, GLenum type);
/** /**
* Utility function to create and compile an OpenGL GLSL shader program (vertex + fragment shader) * Utility function to create and compile an OpenGL GLSL shader program (vertex + fragment shader)