summaryrefslogtreecommitdiff
path: root/gl.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-11-03 18:22:44 -0400
committerpommicket <pommicket@gmail.com>2022-11-03 18:22:44 -0400
commit4d995edfdde5953bc5669c54b1194be40a3641f2 (patch)
treedf24530695859b1cf7b48ee2775f0b57a990edc4 /gl.c
parent1e49845629e93d4513b9388c524d7d1e0ac945f8 (diff)
better shader system
Diffstat (limited to 'gl.c')
-rw-r--r--gl.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gl.c b/gl.c
index ddb4ba4..c16d252 100644
--- a/gl.c
+++ b/gl.c
@@ -60,6 +60,33 @@
gl_for_each_proc(gl_declare_proc)
#undef gl_declare_proc
+GlRcSAB *gl_rc_sab_new(GLuint shader, GLuint array, GLuint buffer) {
+ GlRcSAB *s = calloc(1, sizeof *s);
+ s->ref_count = 1;
+ s->shader = shader;
+ s->array = array;
+ s->buffer = buffer;
+ return s;
+}
+
+void gl_rc_sab_incref(GlRcSAB *s) {
+ if (!s) return;
+ ++s->ref_count;
+}
+
+void gl_rc_sab_decref(GlRcSAB **ps) {
+ GlRcSAB *s = *ps;
+ if (!s) return;
+ if (--s->ref_count == 0) {
+ debug_println("Delete program %u", s->shader);
+ glDeleteProgram(s->shader);
+ glDeleteBuffers(1, &s->buffer);
+ glDeleteVertexArrays(1, &s->array);
+ free(s);
+ }
+ *ps = NULL;
+}
+
// set by main()
static int gl_version_major;
static int gl_version_minor;