ref: b9431f23d40a9d49f76db230668869664235c256
parent: 914605ce571e8d472976fa768eab3ae931e751d6
author: David <gek@katherine>
date: Fri Feb 19 20:42:22 EST 2021
Added the TinyGL Runtime Compatibility test, and improved the buildtime compat test system
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -730,11 +730,7 @@
extern char TGL_BUILDT_LshiftGLshort[ 1-2*(((GLshort)255<<8) != 65280)];
extern char TGL_BUILDT_RshiftGLshort[ 1-2*((GLshort)65280>>8 != -1)];
//Testing floating point
-#define TGL_BUILDT_T1_FLOAT ((GLfloat)-10.7)
-#define TGL_BUILDT_T1_HEX 0xC12B3333
-#define TGL_BUILDT_T2_FLOAT 23
-#define TGL_BUILDT_T2_HEX 0x41B80000
-#define TGL_BUILDT_UNION_CAST(i) ((union{GLuint l; GLfloat f; }){i})
+
//extern char TGL_BUILDT_FLOATT1[ 1-2*((TGL_BUILDT_UNION_CAST(TGL_BUILDT_T1_HEX)).f == TGL_BUILDT_T1_FLOAT)];
//extern char TGL_BUILDT_FLOATT2[ 1-2*((TGL_BUILDT_UNION_CAST(TGL_BUILDT_T2_FLOAT)).l == TGL_BUILDT_T2_HEX)];
#undef T
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -5,7 +5,7 @@
//Enables setting the error flags when there's an error, so you can check it with glGetError
//Disabling this has slight performance gains.
-#define TGL_FEATURE_ERROR_CHECK 1
+#define TGL_FEATURE_ERROR_CHECK 0
//Strict out-of-memory checking. All OpenGL function calls are invalidated (ALL OF THEM) if a GL_OUT_OF_MEMORY error occurs.
//The checks slow down the renderer so it is not recommended , but
//it's part of the GL spec and it was relatively easy to add so I added it.
@@ -82,6 +82,8 @@
//The fraction bits in the fixed point values used for S and T in interpolatiion.
#define ZB_POINT_S_FRAC_BITS 10
#define ZB_POINT_T_FRAC_BITS (ZB_POINT_S_FRAC_BITS + TGL_FEATURE_TEXTURE_POW2)
+
+#define TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST 1
#endif
/* _tgl_features_h_ */
--- a/src/get.c
+++ b/src/get.c
@@ -167,7 +167,9 @@
#if COMPILETIME_TINYGL_COMPAT_TEST == 1
"TGL_COMPILETIME_TINYGL_COMPAT_TEST "
#endif
-
+#if TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST == 1
+"TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST "
+#endif
"TGL_SOFTWARE_ACCELERATED";
const GLubyte* glGetString(GLenum name){
switch(name){
--- a/src/init.c
+++ b/src/init.c
@@ -63,12 +63,40 @@
gl_free(s->texture_hash_table);
}
+#if TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST == 1
+
+#define TGL_RUNT_UNION_CAST(i) ((union{GLuint l; GLfloat f;}){i})
+int TinyGLRuntimeCompatibilityTest(){
+ GLfloat t = -0;
+ GLint t2 = 1<<31;
+ if(TGL_RUNT_UNION_CAST(t2).f != -0)
+ return 1;
+ t2 = 3212836864;
+ t = -1;
+ if(TGL_RUNT_UNION_CAST(t2).f != t)
+ return 1;
+ if(((GLint)255<<8) != 65280) return 1;
+ if((GLint)65280>>8 != 255) return 1;
+ if( ((GLint)-1)>>14 != -1 ) return 1;
+ if(((GLuint)255<<8) != 65280) return 1;
+ if((GLuint)65280>>8 != 255) return 1;
+ if(((GLushort)255<<8) != 65280) return 1;
+ if((GLushort)65280>>8 != 255) return 1;
+ if(((GLshort)255<<8) != 65280) return 1;
+ if((GLshort)65280>>8 != -1) return 1;
+ return 0;
+}
+#endif
+
+
void glInit(void* zbuffer1) {
ZBuffer* zbuffer = (ZBuffer*)zbuffer1;
GLContext* c;
GLViewport* v;
GLint i;
-
+#if TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST == 1
+ if(TinyGLRuntimeCompatibilityTest()) gl_fatal_error("TINYGL_FAILED_RUNTIME_COMPAT_TEST");
+#endif
c = gl_zalloc(sizeof(GLContext));
if(!c) gl_fatal_error("TINYGL_CANNOT_INIT_OOM");
gl_ctx = c;
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -11,8 +11,9 @@
#define M_PI 3.14159265358979323
#endif
//#define DEBUG
+#ifndef NDEBUG
#define NDEBUG
-
+#endif
enum {
#define ADD_OP(a, b, c) OP_##a,