[nostalgia/core/userland] Cleanup
This commit is contained in:
parent
f5ff700bf3
commit
fefe8bacc7
@ -30,10 +30,10 @@ constexpr auto BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
|||||||
constexpr auto BgVertexEboLength = 6;
|
constexpr auto BgVertexEboLength = 6;
|
||||||
|
|
||||||
struct Background {
|
struct Background {
|
||||||
VertexArray vao;
|
GLVertexArray vao;
|
||||||
Buffer vbo;
|
GLBuffer vbo;
|
||||||
Buffer ebo;
|
GLBuffer ebo;
|
||||||
Texture tex;
|
GLTexture tex;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
std::array<float, TileCount * BgVertexVboLength> bgVertices = {};
|
std::array<float, TileCount * BgVertexVboLength> bgVertices = {};
|
||||||
@ -41,7 +41,7 @@ struct Background {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GlImplData {
|
struct GlImplData {
|
||||||
Program bgShader;
|
GLProgram bgShader;
|
||||||
int64_t prevFpsCheckTime = 0;
|
int64_t prevFpsCheckTime = 0;
|
||||||
uint64_t draws = 0;
|
uint64_t draws = 0;
|
||||||
std::array<Background, 4> backgrounds;
|
std::array<Background, 4> backgrounds;
|
||||||
@ -119,16 +119,16 @@ static void initBackgroundBufferObjects(Context *ctx, Background *bg) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VertexArray genVertexArrayObject() noexcept {
|
static GLVertexArray genVertexArrayObject() noexcept {
|
||||||
GLuint vao = 0;
|
GLuint vao = 0;
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
return VertexArray(vao);
|
return GLVertexArray(vao);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buffer genBuffer() noexcept {
|
static GLBuffer genBuffer() noexcept {
|
||||||
GLuint buff = 0;
|
GLuint buff = 0;
|
||||||
glGenBuffers(1, &buff);
|
glGenBuffers(1, &buff);
|
||||||
return Buffer(buff);
|
return GLBuffer(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) noexcept {
|
static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) noexcept {
|
||||||
@ -151,10 +151,10 @@ static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg)
|
|||||||
ox::bit_cast<void*>(2 * sizeof(float)));
|
ox::bit_cast<void*>(2 * sizeof(float)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Texture loadTexture(GLsizei w, GLsizei h, void *pixels) noexcept {
|
static GLTexture loadTexture(GLsizei w, GLsizei h, void *pixels) noexcept {
|
||||||
GLuint texId = 0;
|
GLuint texId = 0;
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
Texture tex(texId);
|
GLTexture tex(texId);
|
||||||
tex.width = w;
|
tex.width = w;
|
||||||
tex.height = h;
|
tex.height = h;
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
@ -28,15 +28,15 @@ void deleteVertexArray(GLuint v) noexcept {
|
|||||||
glDeleteVertexArrays(1, &v);
|
glDeleteVertexArrays(1, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template struct GLobject<deleteBuffer>;
|
template struct GLObject<deleteBuffer>;
|
||||||
template struct GLobject<deleteTexture, TextureBase>;
|
template struct GLObject<deleteTexture, TextureBase>;
|
||||||
template struct GLobject<deleteVertexArray>;
|
template struct GLObject<deleteVertexArray>;
|
||||||
template struct GLobject<glDeleteProgram>;
|
template struct GLObject<glDeleteProgram>;
|
||||||
template struct GLobject<glDeleteShader>;
|
template struct GLObject<glDeleteShader>;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static ox::Result<Shader> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) noexcept {
|
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) noexcept {
|
||||||
Shader shader(glCreateShader(shaderType));
|
GLShader shader(glCreateShader(shaderType));
|
||||||
glShaderSource(shader, 1, &src, nullptr);
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
GLint status;
|
GLint status;
|
||||||
@ -51,10 +51,10 @@ static ox::Result<Shader> buildShader(GLuint shaderType, const GLchar *src, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Result<Program> buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept {
|
ox::Result<GLProgram> buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept {
|
||||||
oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad"));
|
oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad"));
|
||||||
oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad"));
|
oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad"));
|
||||||
Program prgm(glCreateProgram());
|
GLProgram prgm(glCreateProgram());
|
||||||
glAttachShader(prgm, vs);
|
glAttachShader(prgm, vs);
|
||||||
glAttachShader(prgm, fs);
|
glAttachShader(prgm, fs);
|
||||||
glLinkProgram(prgm);
|
glLinkProgram(prgm);
|
||||||
|
@ -47,26 +47,26 @@ struct TextureBase {
|
|||||||
|
|
||||||
|
|
||||||
template<auto del, typename Base = Empty>
|
template<auto del, typename Base = Empty>
|
||||||
struct GLobject: public Base {
|
struct GLObject: public Base {
|
||||||
|
|
||||||
GLuint id = 0;
|
GLuint id = 0;
|
||||||
|
|
||||||
constexpr GLobject() noexcept = default;
|
constexpr GLObject() noexcept = default;
|
||||||
|
|
||||||
explicit constexpr GLobject(GLuint id) noexcept {
|
explicit constexpr GLObject(GLuint id) noexcept {
|
||||||
this->id = id;
|
this->id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr GLobject(GLobject &&o) noexcept: Base(ox::move(o)) {
|
constexpr GLObject(GLObject &&o) noexcept: Base(ox::move(o)) {
|
||||||
id = o.id;
|
id = o.id;
|
||||||
o.id = 0;
|
o.id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~GLobject() {
|
~GLObject() {
|
||||||
del(id);
|
del(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLobject &operator=(GLobject &&o) noexcept {
|
GLObject &operator=(GLObject &&o) noexcept {
|
||||||
if (this != &o) {
|
if (this != &o) {
|
||||||
del(id);
|
del(id);
|
||||||
Base::operator=(ox::move(o));
|
Base::operator=(ox::move(o));
|
||||||
@ -96,19 +96,19 @@ void deleteBuffer(GLuint b) noexcept;
|
|||||||
void deleteTexture(GLuint t) noexcept;
|
void deleteTexture(GLuint t) noexcept;
|
||||||
void deleteVertexArray(GLuint v) noexcept;
|
void deleteVertexArray(GLuint v) noexcept;
|
||||||
|
|
||||||
extern template struct GLobject<deleteBuffer>;
|
extern template struct GLObject<deleteBuffer>;
|
||||||
extern template struct GLobject<deleteTexture, TextureBase>;
|
extern template struct GLObject<deleteTexture, TextureBase>;
|
||||||
extern template struct GLobject<deleteVertexArray>;
|
extern template struct GLObject<deleteVertexArray>;
|
||||||
extern template struct GLobject<glDeleteProgram>;
|
extern template struct GLObject<glDeleteProgram>;
|
||||||
extern template struct GLobject<glDeleteShader>;
|
extern template struct GLObject<glDeleteShader>;
|
||||||
|
|
||||||
using Buffer = GLobject<deleteBuffer>;
|
using GLBuffer = GLObject<deleteBuffer>;
|
||||||
using Shader = GLobject<glDeleteShader>;
|
using GLShader = GLObject<glDeleteShader>;
|
||||||
using Program = GLobject<glDeleteProgram>;
|
using GLProgram = GLObject<glDeleteProgram>;
|
||||||
using Texture = GLobject<deleteTexture, TextureBase>;
|
using GLTexture = GLObject<deleteTexture, TextureBase>;
|
||||||
using VertexArray = GLobject<deleteVertexArray>;
|
using GLVertexArray = GLObject<deleteVertexArray>;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Result<Program> buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept;
|
ox::Result<GLProgram> buildShaderProgram(const GLchar *vert, const GLchar *frag) noexcept;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user