gl_resource_manager: separate OGLShader and OGLProgram
This commit is contained in:
parent
d2ee40dc45
commit
48869c768f
|
@ -377,7 +377,7 @@ private:
|
||||||
OGLVertexArray attributeless_vao;
|
OGLVertexArray attributeless_vao;
|
||||||
OGLBuffer d24s8_abgr_buffer;
|
OGLBuffer d24s8_abgr_buffer;
|
||||||
GLsizeiptr d24s8_abgr_buffer_size;
|
GLsizeiptr d24s8_abgr_buffer_size;
|
||||||
OGLShader d24s8_abgr_shader;
|
OGLProgram d24s8_abgr_shader;
|
||||||
GLint d24s8_abgr_tbo_size_u_id;
|
GLint d24s8_abgr_tbo_size_u_id;
|
||||||
GLint d24s8_abgr_viewport_u_id;
|
GLint d24s8_abgr_viewport_u_id;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
|
@ -96,11 +97,53 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
void Create(const char* source, GLenum type) {
|
||||||
void Create(const char* vert_shader, const char* frag_shader) {
|
|
||||||
if (handle != 0)
|
if (handle != 0)
|
||||||
return;
|
return;
|
||||||
handle = GLShader::LoadProgram(vert_shader, frag_shader);
|
if (source == nullptr)
|
||||||
|
return;
|
||||||
|
handle = GLShader::LoadShader(source, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Release() {
|
||||||
|
if (handle == 0)
|
||||||
|
return;
|
||||||
|
glDeleteShader(handle);
|
||||||
|
handle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint handle = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class OGLProgram : private NonCopyable {
|
||||||
|
public:
|
||||||
|
OGLProgram() = default;
|
||||||
|
|
||||||
|
OGLProgram(OGLProgram&& o) : handle(std::exchange(o.handle, 0)) {}
|
||||||
|
|
||||||
|
~OGLProgram() {
|
||||||
|
Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
OGLProgram& operator=(OGLProgram&& o) {
|
||||||
|
Release();
|
||||||
|
handle = std::exchange(o.handle, 0);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new program from given shader objects
|
||||||
|
void Create(bool separable_program, const std::vector<GLuint>& shaders) {
|
||||||
|
if (handle != 0)
|
||||||
|
return;
|
||||||
|
handle = GLShader::LoadProgram(separable_program, shaders);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new program from given shader soruce code
|
||||||
|
void Create(const char* vert_shader, const char* frag_shader) {
|
||||||
|
OGLShader vert, frag;
|
||||||
|
vert.Create(vert_shader, GL_VERTEX_SHADER);
|
||||||
|
frag.Create(frag_shader, GL_FRAGMENT_SHADER);
|
||||||
|
Create(false, {vert.handle, frag.handle});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
|
|
|
@ -73,7 +73,7 @@ private:
|
||||||
// OpenGL object IDs
|
// OpenGL object IDs
|
||||||
OGLVertexArray vertex_array;
|
OGLVertexArray vertex_array;
|
||||||
OGLBuffer vertex_buffer;
|
OGLBuffer vertex_buffer;
|
||||||
OGLShader shader;
|
OGLProgram shader;
|
||||||
|
|
||||||
/// Display information for top and bottom screens respectively
|
/// Display information for top and bottom screens respectively
|
||||||
std::array<ScreenInfo, 2> screen_infos;
|
std::array<ScreenInfo, 2> screen_infos;
|
||||||
|
|
Reference in New Issue