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();