add GL/Shader

This commit is contained in:
2022-10-12 10:25:19 +09:00
parent 7ee770e67d
commit 4e83f7b5e9
2 changed files with 141 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ class Obj final {
Obj() = delete;
template <typename... Args>
Obj(const std::shared_ptr<nf7::Context>& ctx, GLuint id, Args&&... args) noexcept :
ctx_(ctx), id_(id? id: T::Gen()), meta_(std::forward<Args>(args)...) {
ctx_(ctx), meta_(std::forward<Args>(args)...), id_(id? id: meta_.Gen()) {
}
~Obj() noexcept {
ctx_->env().ExecGL(ctx_, [id = id_]() { T::Delete(id); });
@@ -39,8 +39,8 @@ class Obj final {
private:
std::shared_ptr<nf7::Context> ctx_;
GLuint id_;
T meta_;
const GLuint id_;
};
@@ -90,4 +90,23 @@ struct Obj_TextureMeta final {
using Texture = Obj<Obj_TextureMeta>;
using TextureFactory = AsyncFactory<nf7::Mutex::Resource<std::shared_ptr<Texture>>>;
struct Obj_ShaderMeta final {
public:
Obj_ShaderMeta() = delete;
Obj_ShaderMeta(GLenum t) noexcept : type(t) {
}
const GLenum type;
GLuint Gen() noexcept {
return glCreateShader(type);
}
static void Delete(GLuint id) noexcept {
glDeleteShader(id);
}
};
using Shader = Obj<Obj_ShaderMeta>;
using ShaderFactory = AsyncFactory<nf7::Mutex::Resource<std::shared_ptr<Shader>>>;
} // namespace nf7::gl