mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-17 22:25:37 +00:00
Common: Use std::string_view for GL::Program
This commit is contained in:
parent
2b17cfd365
commit
60281eb67e
|
@ -17,12 +17,12 @@ Program::~Program()
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Program::CompileShader(GLenum type, const char* source)
|
GLuint Program::CompileShader(GLenum type, const std::string_view source)
|
||||||
{
|
{
|
||||||
GLuint id = glCreateShader(type);
|
GLuint id = glCreateShader(type);
|
||||||
|
|
||||||
std::array<const GLchar*, 1> sources = {{source}};
|
std::array<const GLchar*, 1> sources = {{source.data()}};
|
||||||
std::array<GLint, 1> source_lengths = {{static_cast<GLint>(std::strlen(source))}};
|
std::array<GLint, 1> source_lengths = {{static_cast<GLint>(source.size())}};
|
||||||
glShaderSource(id, static_cast<GLsizei>(sources.size()), sources.data(), source_lengths.data());
|
glShaderSource(id, static_cast<GLsizei>(sources.size()), sources.data(), source_lengths.data());
|
||||||
glCompileShader(id);
|
glCompileShader(id);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ void Program::ResetLastProgram()
|
||||||
s_last_program_id = 0;
|
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);
|
GLuint vertex_shader_id = CompileShader(GL_VERTEX_SHADER, vertex_shader);
|
||||||
if (vertex_shader_id == 0)
|
if (vertex_shader_id == 0)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "glad.h"
|
#include "glad.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace GL {
|
namespace GL {
|
||||||
|
@ -10,12 +11,12 @@ public:
|
||||||
Program();
|
Program();
|
||||||
~Program();
|
~Program();
|
||||||
|
|
||||||
static GLuint CompileShader(GLenum type, const char* source);
|
static GLuint CompileShader(GLenum type, const std::string_view source);
|
||||||
static void ResetLastProgram();
|
static void ResetLastProgram();
|
||||||
|
|
||||||
bool IsVaild() const { return m_program_id != 0; }
|
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 BindAttribute(GLuint index, const char* name);
|
||||||
void BindDefaultAttributes();
|
void BindDefaultAttributes();
|
||||||
|
|
|
@ -286,7 +286,7 @@ bool GPU_HW_OpenGL::CompilePrograms()
|
||||||
const std::string vs = GenerateScreenQuadVertexShader();
|
const std::string vs = GenerateScreenQuadVertexShader();
|
||||||
const std::string fs =
|
const std::string fs =
|
||||||
GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit), ConvertToBoolUnchecked(interlaced));
|
GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit), ConvertToBoolUnchecked(interlaced));
|
||||||
if (!prog.Compile(vs.c_str(), fs.c_str()))
|
if (!prog.Compile(vs, fs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
prog.BindFragData(0, "o_col0");
|
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 bool textured = texture_mode != TextureMode::Disabled;
|
||||||
const std::string vs = GenerateVertexShader(textured);
|
const std::string vs = GenerateVertexShader(textured);
|
||||||
const std::string fs = GenerateFragmentShader(render_mode, texture_mode, dithering);
|
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;
|
return false;
|
||||||
|
|
||||||
prog.BindAttribute(0, "a_pos");
|
prog.BindAttribute(0, "a_pos");
|
||||||
|
|
Loading…
Reference in a new issue