Common: Use std::string_view for GL::Program

This commit is contained in:
Connor McLaughlin 2019-11-02 23:42:21 +10:00
parent 2b17cfd365
commit 60281eb67e
3 changed files with 9 additions and 8 deletions

View File

@ -17,12 +17,12 @@ Program::~Program()
Destroy();
}
GLuint Program::CompileShader(GLenum type, const char* source)
GLuint Program::CompileShader(GLenum type, const std::string_view source)
{
GLuint id = glCreateShader(type);
std::array<const GLchar*, 1> sources = {{source}};
std::array<GLint, 1> source_lengths = {{static_cast<GLint>(std::strlen(source))}};
std::array<const GLchar*, 1> sources = {{source.data()}};
std::array<GLint, 1> source_lengths = {{static_cast<GLint>(source.size())}};
glShaderSource(id, static_cast<GLsizei>(sources.size()), sources.data(), source_lengths.data());
glCompileShader(id);
@ -69,7 +69,7 @@ void Program::ResetLastProgram()
s_last_program_id = 0;
}
bool Program::Compile(const char* vertex_shader, const char* fragment_shader)
bool Program::Compile(const std::string_view vertex_shader, const std::string_view fragment_shader)
{
GLuint vertex_shader_id = CompileShader(GL_VERTEX_SHADER, vertex_shader);
if (vertex_shader_id == 0)

View File

@ -1,6 +1,7 @@
#pragma once
#include "glad.h"
#include "types.h"
#include <string_view>
#include <vector>
namespace GL {
@ -10,12 +11,12 @@ public:
Program();
~Program();
static GLuint CompileShader(GLenum type, const char* source);
static GLuint CompileShader(GLenum type, const std::string_view source);
static void ResetLastProgram();
bool IsVaild() const { return m_program_id != 0; }
bool Compile(const char* vertex_shader, const char* fragment_shader);
bool Compile(const std::string_view vertex_shader, const std::string_view fragment_shader);
void BindAttribute(GLuint index, const char* name);
void BindDefaultAttributes();

View File

@ -286,7 +286,7 @@ bool GPU_HW_OpenGL::CompilePrograms()
const std::string vs = GenerateScreenQuadVertexShader();
const std::string fs =
GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit), ConvertToBoolUnchecked(interlaced));
if (!prog.Compile(vs.c_str(), fs.c_str()))
if (!prog.Compile(vs, fs))
return false;
prog.BindFragData(0, "o_col0");
@ -309,7 +309,7 @@ bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, HWBatchRenderMode render_m
const bool textured = texture_mode != TextureMode::Disabled;
const std::string vs = GenerateVertexShader(textured);
const std::string fs = GenerateFragmentShader(render_mode, texture_mode, dithering);
if (!prog.Compile(vs.c_str(), fs.c_str()))
if (!prog.Compile(vs, fs))
return false;
prog.BindAttribute(0, "a_pos");