shithub: tinygl

Download patch

ref: d27050d3cd1cfafd32a05029e04c91454f607a2c
parent: 36d0422a66ec59a4f61f91a7bb56855fb97017a6
author: David <gek@katherine>
date: Sun Feb 21 12:29:03 EST 2021

Optimized display lists

--- a/src/list.c
+++ b/src/list.c
@@ -8,13 +8,13 @@
 #include "opinfo.h"
 };
 */
-static void (*op_table_func[])(GLContext*, GLParam*) = {
+void (*op_table_func[])(GLContext*, GLParam*) = {
 #define ADD_OP(a, b, c) glop##a,
 
 #include "opinfo.h"
 };
 
-static GLint op_table_size[] = {
+GLint op_table_size[] = {
 #define ADD_OP(a, b, c) b + 1,
 
 #include "opinfo.h"
@@ -148,7 +148,7 @@
 	}
 	c->current_op_buffer_index = index;
 }
-
+/*
 void gl_add_op(GLParam* p) {
 	GLContext* c = gl_get_context();
 #include "error_check.h"
@@ -166,7 +166,7 @@
 		//		gl_print_op(stderr, p);
 	}
 }
-
+*/
 /* this opcode is never called directly */
 void glopEndList(GLContext* c, GLParam* p) { assert(0); }
 
@@ -188,7 +188,7 @@
 	p = l->first_op_buffer->ops;
 
 	while (1) {
-		#include "error_check.h"
+#include "error_check.h"
 		op = p[0].op;
 		if (op == OP_EndList)
 			break;
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -315,7 +315,27 @@
 
 extern GLContext* gl_ctx;
 
-void gl_add_op(GLParam* p);
+//void gl_add_op(GLParam* p);
+extern void (*op_table_func[])(GLContext*, GLParam*);
+extern GLint op_table_size[];
+extern void gl_compile_op(GLContext* c, GLParam* p);
+static inline void gl_add_op(GLParam* p) {
+	GLContext* c = gl_ctx;
+#include "error_check.h"
+	GLint op;
+	op = p[0].op;
+	if (c->exec_flag) {
+		op_table_func[op](c, p);
+#include "error_check.h"
+	}
+	if (c->compile_flag) {
+		gl_compile_op(c, p);
+#include "error_check.h"
+	}
+	if (c->print_flag) {
+		//		gl_print_op(stderr, p);
+	}
+}
 
 /* clip.c */
 void gl_transform_to_viewport(GLContext* c, GLVertex* v);