[nostalgia/core/userland] Move Vertex arrays and Buffers to GLobject
This commit is contained in:
parent
8d19f99fac
commit
cc23947d27
@ -118,11 +118,11 @@ static void initBackgroundBufferObjects(Context *ctx, Background *bg) noexcept {
|
||||
|
||||
static void initBackgroundBufferset(Context *ctx, GLuint shader, Background *bg) {
|
||||
// vao
|
||||
glGenVertexArrays(1, &bg->vao);
|
||||
glGenVertexArrays(1, &bg->vao.id);
|
||||
glBindVertexArray(bg->vao);
|
||||
// vbo & ebo
|
||||
glGenBuffers(1, &bg->vbo);
|
||||
glGenBuffers(1, &bg->ebo);
|
||||
glGenBuffers(1, &bg->vbo.id);
|
||||
glGenBuffers(1, &bg->ebo.id);
|
||||
initBackgroundBufferObjects(ctx, bg);
|
||||
sendVbo(*bg);
|
||||
sendEbo(*bg);
|
||||
@ -200,9 +200,6 @@ ox::Error init(Context *ctx) {
|
||||
|
||||
ox::Error shutdown(Context *ctx) {
|
||||
const auto id = ctx->rendererData<GlImplData>();
|
||||
for (auto &bg : id->backgrounds) {
|
||||
destroy(bg);
|
||||
}
|
||||
ctx->setRendererData(nullptr);
|
||||
delete id;
|
||||
return OxError(0);
|
||||
|
@ -15,13 +15,23 @@
|
||||
|
||||
namespace nostalgia::core::renderer {
|
||||
|
||||
void deleteTexture(GLuint t) {
|
||||
void deleteBuffer(GLuint b) noexcept {
|
||||
glDeleteBuffers(1, &b);
|
||||
}
|
||||
|
||||
void deleteTexture(GLuint t) noexcept {
|
||||
glDeleteTextures(1, &t);
|
||||
}
|
||||
|
||||
void deleteVertexArray(GLuint v) noexcept {
|
||||
glDeleteVertexArrays(1, &v);
|
||||
}
|
||||
|
||||
template struct GLobject<deleteBuffer>;
|
||||
template struct GLobject<deleteTexture, TextureBase>;
|
||||
template struct GLobject<deleteVertexArray>;
|
||||
template struct GLobject<glDeleteProgram>;
|
||||
template struct GLobject<glDeleteShader>;
|
||||
template struct GLobject<deleteTexture, TextureBase>;
|
||||
|
||||
[[nodiscard]]
|
||||
static ox::Result<Shader> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) {
|
||||
@ -50,10 +60,4 @@ ox::Result<Program> buildShaderProgram(const GLchar *vert, const GLchar *frag) {
|
||||
return ox::move(prgm);
|
||||
}
|
||||
|
||||
void destroy(const Bufferset &bufferset) {
|
||||
glDeleteVertexArrays(1, &bufferset.vao);
|
||||
glDeleteBuffers(1, &bufferset.ebo);
|
||||
glDeleteBuffers(1, &bufferset.vbo);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -90,19 +90,26 @@ struct GLobject: public Base {
|
||||
|
||||
};
|
||||
|
||||
void deleteTexture(GLuint t);
|
||||
void deleteBuffer(GLuint b) noexcept;
|
||||
void deleteTexture(GLuint t) noexcept;
|
||||
void deleteVertexArray(GLuint v) noexcept;
|
||||
|
||||
extern template struct GLobject<deleteBuffer>;
|
||||
extern template struct GLobject<deleteTexture, TextureBase>;
|
||||
extern template struct GLobject<deleteVertexArray>;
|
||||
extern template struct GLobject<glDeleteProgram>;
|
||||
extern template struct GLobject<glDeleteShader>;
|
||||
extern template struct GLobject<deleteTexture, TextureBase>;
|
||||
|
||||
using Buffer = GLobject<deleteBuffer>;
|
||||
using Shader = GLobject<glDeleteShader>;
|
||||
using Program = GLobject<glDeleteProgram>;
|
||||
using Texture = GLobject<deleteTexture, TextureBase>;
|
||||
using VertexArray = GLobject<deleteVertexArray>;
|
||||
|
||||
struct Bufferset {
|
||||
GLuint vao = 0;
|
||||
GLuint vbo = 0;
|
||||
GLuint ebo = 0;
|
||||
VertexArray vao;
|
||||
Buffer vbo;
|
||||
Buffer ebo;
|
||||
Texture tex;
|
||||
GLsizei eboElements = 0;
|
||||
};
|
||||
@ -110,6 +117,4 @@ struct Bufferset {
|
||||
[[nodiscard]]
|
||||
ox::Result<Program> buildShaderProgram(const GLchar *vert, const GLchar *frag);
|
||||
|
||||
void destroy(const Bufferset &bufferset);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user