ref: 5559b1d2498227919f2a5c728064dd53d0822fe9
parent: d07d0eee0119e1e4b793b5d6ee80ad5d32dc7702
author: David <gek@katherine>
date: Fri Feb 19 08:43:08 EST 2021
Major performance boost
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -5,7 +5,7 @@
header file. */
//Enables setting the error flags when there's an error, so you can check it with glGetError, should only be used in development builds.
-#define TGL_FEATURE_ERROR_CHECK 0
+#define TGL_FEATURE_ERROR_CHECK 1
//Strict out-of-memory checking. All OpenGL function calls are invalidated (ALL OF THEM) if a GL_OUT_OF_MEMORY error occurs.
//This slows down the renderer so we don't usually do it.
#define TGL_FEATURE_STRICT_OOM_CHECKS 0
--- a/src/clip.c
+++ b/src/clip.c
@@ -393,13 +393,30 @@
#ifdef PROFILE
{
GLint norm;
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if(!(
+ (p0->zp.x >= 0 && p0->zp.x < c->zb->xsize) &&
+ (p0->zp.y >= 0 && p0->zp.y < c->zb->ysize) &&
+ (p1->zp.x >= 0 && p1->zp.x < c->zb->xsize) &&
+
+ (p1->zp.y >= 0 && p1->zp.y < c->zb->ysize) &&
+ (p2->zp.x >= 0 && p2->zp.x < c->zb->xsize) &&
+ (p2->zp.y >= 0 && p2->zp.y < c->zb->ysize)
+ ))
+#define ERROR_FLAG GL_INVALID_VALUE
+#include "error_check.h"
+#else
+/*
assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
+
assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
-
+*/
+//Assume it's ok!
+#endif
norm = (p1->zp.x - p0->zp.x) * (p2->zp.y - p0->zp.y) - (p2->zp.x - p0->zp.x) * (p1->zp.y - p0->zp.y);
count_pixels += abs(norm) / 2;
count_triangles++;
--- a/src/error_check.h
+++ b/src/error_check.h
@@ -6,7 +6,7 @@
#if TGL_FEATURE_ERROR_CHECK == 1
//LEVEL 1 ERROR_CHECK
-#error should never execute.
+//#error should never execute.
#ifndef ERROR_FLAG
//LEVEL 2 ERROR_FLAG
--- a/src/error_check_no_context.h
+++ b/src/error_check_no_context.h
@@ -4,7 +4,7 @@
#if TGL_FEATURE_ERROR_CHECK == 1
GLContext* c = gl_get_context();
-#error should never execute
+//#error should never execute
#if TGL_FEATURE_STRICT_OOM_CHECKS == 1
if(c->error_flag == GL_OUT_OF_MEMORY)
return RETVAL;
--- a/src/light.c
+++ b/src/light.c
@@ -69,7 +69,12 @@
c->current_color.Y = v[1];
c->current_color.Z = v[2];
c->current_color.W = v[3];
- assert(0);
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+#else
+ //assert(0);
+#endif
}
}
@@ -88,8 +93,16 @@
GLLight* l;
GLint i;
- assert(light >= GL_LIGHT0 && light < GL_LIGHT0 + MAX_LIGHTS);
+ //assert(light >= GL_LIGHT0 && light < GL_LIGHT0 + MAX_LIGHTS);
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if(!(light >= GL_LIGHT0 && light < GL_LIGHT0 + MAX_LIGHTS))
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+ //assert(light >= GL_LIGHT0 && light < GL_LIGHT0 + MAX_LIGHTS);
+#endif
+
l = &c->lights[light - GL_LIGHT0];
for (i = 0; i < 4; i++)
@@ -131,7 +144,14 @@
break;
case GL_SPOT_CUTOFF: {
GLfloat a = v.v[0];
- assert(a == 180 || (a >= 0 && a <= 90));
+
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_VALUE
+#include "error_check.h"
+#else
+ //assert(a == 180 || (a >= 0 && a <= 90));
+#endif
+
l->spot_cutoff = a;
if (a != 180)
l->cos_spot_cutoff = cos(a * M_PI / 180.0);
@@ -146,7 +166,11 @@
l->attenuation[2] = v.v[0];
break;
default:
- assert(0);
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+#endif
+ return;
}
}
@@ -167,7 +191,11 @@
c->light_model_two_side = (GLint)v[0];
break;
default:
- tgl_warning("glopLightModel: illegal pname: 0x%x\n", pname);
+#if TGL_FEATURE_ERROR_CHECK == 1
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+#endif
+// tgl_warning("glopLightModel: illegal pname: 0x%x\n", pname);
// assert(0);
break;
}
--- a/src/list.c
+++ b/src/list.c
@@ -33,7 +33,7 @@
tgl_warning("\nAttempted to delete NULL list!!!!\n");
return;
}
- assert(l != NULL);
+ //assert(l != NULL);
/* free param buffer */
pb = l->first_op_buffer;
--- a/src/msghandling.c
+++ b/src/msghandling.c
@@ -2,7 +2,7 @@
#include "zgl.h"
#include <stdarg.h>
//#include <stdio.h>
-#define NDEBUG
+//#define NDEBUG
#ifdef NDEBUG
#define NO_DEBUG_OUTPUT
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -63,9 +63,13 @@
void glopBegin(GLContext* c, GLParam* p) {
GLint type;
M4 tmp;
-
- assert(c->in_begin == 0);
-
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if(c->in_begin != 0)
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+ //assert(c->in_begin == 0);
+#endif
type = p[1].i;
c->begin_type = type;
c->in_begin = 1;
@@ -183,7 +187,13 @@
GLVertex* v;
GLint n, i, cnt;
- assert(c->in_begin != 0);
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if(c->in_begin == 0)
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+ //assert(c->in_begin != 0);
+#endif
n = c->vertex_n;
cnt = c->vertex_cnt;
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -1,6 +1,5 @@
#ifndef _tgl_zgl_h_
#define _tgl_zgl_h_
-
#include "../include/GL/gl.h"
#include "../include/zbuffer.h"
#include "../include/zfeatures.h"
@@ -11,8 +10,8 @@
#ifndef M_PI
#define M_PI 3.14159265358979323
#endif
-#define DEBUG
-/* #define NDEBUG */
+//#define DEBUG
+#define NDEBUG
enum {