shithub: tinygl

Download patch

ref: 10691f9c4e802193b17cfb0a1bab84e37855667c
parent: 9dda1aa6621c073a9ac165b6c989c654bcb4b444
author: MHS <gek@katherine>
date: Sat Apr 10 15:14:51 EDT 2021

Automatic commit.

--- a/config.mk
+++ b/config.mk
@@ -1,7 +1,7 @@
 #####################################################################
 # C compiler
 
-CC= gcc
+CC= clang
 #uncomment the following line for compiling the lib using tinyc.
 #note that the demos will fail to build with tinyc, but you can 
 #-link- to tinygl built with tinyc using gcc.
@@ -10,7 +10,7 @@
 #CFLAGS= -Wall -w -O3 -g -std=c99 -march=native -DNDEBUG
 
 #extract the maximum possible performance from gcc.
-CFLAGS= -Wall -Warray-bounds=2 -O3 -std=c99 -mtune=native -DNDEBUG -g -fopenmp
+CFLAGS= -Wall -Warray-bounds=2 -O3 -std=gnu99 -mtune=native -DNDEBUG -g -fopenmp
 #uncomment the following line for compiling the lib with tinyc
 #keep these flags for compiling with gcc if you are linking with tinygl compiled with tcc.
 #CFLAGS= -Wall -O3 -std=gnu99 -DNDEBUG -g
--- a/include-demo/tobjparse.h
+++ b/include-demo/tobjparse.h
@@ -145,7 +145,7 @@
 
 #define TOBJ_PUSH(type, vec, n, val){vec = realloc(vec, sizeof(type) * (n+1)); vec[n++] = val;}
 		while(fgets(line, 2047, f)){
-			vec3 val;
+			vec3 val = {0};
 			facedef frick0 = {0};
 			facedef frick1 = {0};
 			facedef frick2 = {0};
--- a/src/get.c
+++ b/src/get.c
@@ -173,8 +173,8 @@
 //NOTE: You should never be prevented from retrieving values from the GL state, even in GL_OUT_OF_MEMORY
 
 void glGetIntegerv(GLint pname, GLint* params) {
-	GLContext* c = gl_get_context();
-	GLint i = 0;
+	GLint i;GLContext* c = gl_get_context();
+	i = 0;
 	switch (pname) {
 	case GL_MAX_BUFFERS:
 		*params = MAX_BUFFERS;
@@ -581,9 +581,9 @@
 
 
 void glGetFloatv(GLint pname, GLfloat* v) {
-	GLint i;
-	GLint mnr = 0; /* just a trick to return the correct matrix */
-	GLContext* c = gl_get_context();
+	GLint i, mnr; GLContext* c;
+	mnr = 0; /* just a trick to return the correct matrix */
+	c = gl_get_context();
 	switch (pname) {
 		case GL_BLUE_SCALE:
 		case GL_RED_SCALE:
--- a/src/init.c
+++ b/src/init.c
@@ -104,22 +104,22 @@
 	tf2 = 1.0/sqrt(10000);
 	if(TGL_FLOAT_ERR(t,tf2) > 0.05) return 1;
 #endif
-	{	//MEMCPY COMPATIBILITY TEST
-		GLuint buf1[10];
-		GLuint buf2[10];
-		for(int i = 0; i < 10; i++) buf1[i] = (1023<<i) + i + i%-1;
-		for(int i = 0; i < 10; i++) buf2[i] = (14<<i) + i + i%-4;
+	{GLint i;
+		GLuint buf1[10];GLuint buf2[10];
+		for(i = 0; i < 10; i++) buf1[i] = (1023<<i) + i + i%-1;
+		for(i = 0; i < 10; i++) buf2[i] = (14<<i) + i + i%-4;
 		memcpy(buf1,buf2,10*4);
-		for(int i = 0; i < 10; i++) if(buf2[i] != buf1[i]) return 1;
+		for(i = 0; i < 10; i++) if(buf2[i] != buf1[i]) return 1;
 	}
 	if(sizeof(void*) < 4) return 1;
 	//ZALLOC TEST
-	for(int i = 0; i < 10; i++){
+	{GLint i, j;
+	for(i = 0; i < 10; i++){
 		GLubyte* data = gl_zalloc(1024); //A kilobyte.
 		if(!data) return 1;
-		for(int i = 0; i <1024; i++) if(data[i] != 0) return 1;
+		for(j = 0; j <1024; j++) if(data[j] != 0) return 1;
 		gl_free(data);
-	}
+	}}
 	return 0;
 }
 #endif
@@ -126,18 +126,16 @@
 
 
 void glInit(void* zbuffer1) {
-	ZBuffer* zbuffer = (ZBuffer*)zbuffer1;
 	GLContext* c;
 	GLViewport* v;
 	GLint i;
+	ZBuffer* zbuffer = (ZBuffer*)zbuffer1;
 #if TGL_FEATURE_TINYGL_RUNTIME_COMPAT_TEST == 1
 	if(TinyGLRuntimeCompatibilityTest()) gl_fatal_error("TINYGL_FAILED_RUNTIME_COMPAT_TEST");
 #endif
-	//c = gl_zalloc(sizeof(GLContext));
 	gl_ctx = empty_gl_ctx;
 	c = &gl_ctx;
 	if(!c) gl_fatal_error("TINYGL_CANNOT_INIT_OOM");
-	//gl_ctx = c;
 	
 	c->zb = zbuffer;
 #if TGL_FEATURE_ERROR_CHECK == 1
@@ -144,9 +142,9 @@
 	c->error_flag = GL_NO_ERROR;
 #endif
 	/* allocate GLVertex array */
-	//c->vertex_max = POLYGON_MAX_VERTEX;
-	//c->vertex = gl_malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));
-	//if(!c->vertex) gl_fatal_error("TINYGL_CANNOT_INIT_OOM");
+	/*c->vertex_max = POLYGON_MAX_VERTEX;*/
+	/*c->vertex = gl_malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));*/
+	/*if(!c->vertex) gl_fatal_error("TINYGL_CANNOT_INIT_OOM");*/
 	/* viewport */
 	v = &c->viewport;
 	v->xmin = 0;
@@ -153,7 +151,6 @@
 	v->ymin = 0;
 	v->xsize = zbuffer->xsize;
 	v->ysize = zbuffer->ysize;
-	//v->updated = 1;
 	gl_eval_viewport(c);
 	/* buffer stuff GL 1.1 */
 	c->drawbuffer = GL_FRONT;
@@ -163,11 +160,11 @@
 	/* ztext */
 	c->textsize = 1;
 	/* buffer */
-	c->boundarraybuffer = 0; //no bound buffer
-	c->boundvertexbuffer = 0; //no bound buffer
-	c->boundcolorbuffer = 0; //no bound buffer
-	c->boundnormalbuffer = 0; //no bound buffer
-	c->boundtexcoordbuffer = 0; //no bound buffer
+	c->boundarraybuffer = 0; 
+	c->boundvertexbuffer = 0;
+	c->boundcolorbuffer = 0; 
+	c->boundnormalbuffer = 0; 
+	c->boundtexcoordbuffer = 0; 
 	/* lists */
 
 	c->exec_flag = 1;
@@ -226,10 +223,6 @@
 	c->current_color.Y = 1.0;
 	c->current_color.Z = 1.0;
 	c->current_color.W = 0.0;
-	// Shouldn't ever be used.
-	// c->longcurrent_color[0] = 65280;
-	// c->longcurrent_color[1] = 65280;
-	// c->longcurrent_color[2] = 65280;
 
 	c->current_normal.X = 1.0;
 	c->current_normal.Y = 0.0;
@@ -335,18 +328,20 @@
 }
 
 void glClose(void) {
+	
+	GLuint i; 
 	GLContext* c = gl_get_context();
-	GLuint i;
 	for (i = 0; i < 3; i++) {
 		gl_free(c->matrix_stack[i]);
 	}
 	i = 0;
 #if TGL_FEATURE_SPECULAR_BUFFERS == 1
-	GLSpecBuf* n = NULL;
-	for (GLSpecBuf* b = c->specbuf_first; b != NULL; b = n) {
+	{GLSpecBuf*b,*n = NULL;
+	for(b = c->specbuf_first; b != NULL; b = n) {
 		n = b->next;
 		gl_free(b);
 		i++;
+	}
 	}
 #endif
 	endSharedState(c);
--- a/src/list.c
+++ b/src/list.c
@@ -48,8 +48,9 @@
 	c->shared_state.lists[list] = NULL;
 }
 void glDeleteLists(GLuint list, GLuint range) {
+	GLuint i;
 #include "error_check_no_context.h"
-	for (GLuint i = 0; i < list + range; i++)
+	for (i = 0; i < list + range; i++)
 		glDeleteList(list + i);
 }
 void glDeleteList(GLuint list) { 
@@ -58,9 +59,8 @@
 }
 
 static GLList* alloc_list( GLint list) {
+	GLList* l;GLParamBuffer* ob;
 	GLContext* c = gl_get_context();
-	GLList* l;
-	GLParamBuffer* ob;
 #define RETVAL NULL
 #include "error_check.h"
 	l = gl_zalloc(sizeof(GLList));
@@ -120,6 +120,7 @@
 void glCallLists(	GLsizei n,
 				 	GLenum type,
 				 	const GLuint* lists){
+	GLint i;
 	GLContext* c = gl_get_context();
 //A ridiculously expensive error check.
 /*
@@ -131,7 +132,7 @@
 #include "error_check.h"
 #endif
 */
-	for(GLint i = 0; i < n; i++)
+	for(i = 0; i < n; i++)
 		glCallList(c->listbase + lists[i]);
 }
 void gl_compile_op(GLParam* p) {
@@ -183,8 +184,7 @@
 
 void glopCallList(GLParam* p) {
 	//GLContext* c = gl_get_context();
-	GLList* l;
-	GLint list;
+	GLList* l;GLint list;
 #include "error_check_no_context.h"
 	list = p[1].ui;
 	l = find_list(list);
@@ -196,9 +196,9 @@
 #endif
 	p = l->first_op_buffer->ops;
 
-	while (1) {
+	while (1) {GLint op;
 #include "error_check.h"
-		GLint op = p[0].op;
+		op = p[0].op;
 		if (op == OP_EndList)
 			break;
 		if (op == OP_NextBuffer) {
@@ -276,9 +276,9 @@
 }
 
 GLuint glGenLists(GLint range) {
-	GLContext* c = gl_get_context();
 	GLint count, i, list;
 	GLList** lists;
+	GLContext* c = gl_get_context();
 #define RETVAL 0
 #include "error_check.h"
 	lists = c->shared_state.lists;
--- a/src/texture.c
+++ b/src/texture.c
@@ -5,8 +5,8 @@
 #include "zgl.h"
 
 static GLTexture* find_texture(GLint h) {
-	GLContext* c = gl_get_context();
 	GLTexture* t;
+	GLContext* c = gl_get_context();
 	t = c->shared_state.texture_hash_table[h & TEXTURE_HASH_TABLE_MASK];
 	while (t != NULL) {
 		if (t->handle == h)
@@ -19,11 +19,11 @@
 GLboolean glAreTexturesResident(	GLsizei n,
 								 	const GLuint * textures,
 								 	GLboolean * residences){
-//GLContext* c = gl_get_context();
 #define RETVAL GL_FALSE
+GLboolean retval = GL_TRUE; GLint i;
 #include "error_check_no_context.h"
-GLboolean retval = GL_TRUE;
-	for(GLint i = 0; i < n; i++)
+
+	for(i = 0; i < n; i++)
 		if(find_texture(textures[i]))
 			{residences[i] = GL_TRUE;}
 		else
@@ -48,7 +48,7 @@
 #define RETVAL NULL
 #include "error_check.h"
 #else
-	//assert(text >= 0 && level < MAX_TEXTURE_LEVELS);
+	/*assert(text >= 0 && level < MAX_TEXTURE_LEVELS);*/
 #endif
 	tex = find_texture(text);
 	if (!tex)
@@ -77,12 +77,6 @@
 	if (t->next != NULL)
 		t->next->prev = t->prev;
 
-//	for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
-//		im = &t->images[i];
-		//if (im->pixmap != NULL)
-		//	gl_free(im->pixmap);
-//	}
-
 	gl_free(t);
 }
 
@@ -141,12 +135,10 @@
 }
 
 void glDeleteTextures(GLint n, const GLuint* textures) {
+	GLint i;GLTexture* t;
 	GLContext* c = gl_get_context();
-	GLint i;
-	GLTexture* t;
 #include "error_check.h"
 	for (i = 0; i < n; i++) {
-
 		t = find_texture(textures[i]);
 		if (t != NULL && t != 0) {
 			if (t == c->current_texture) {
@@ -159,10 +151,10 @@
 }
 
 void glopBindTexture(GLParam* p) {
-	GLContext* c = gl_get_context();
 	GLint target = p[1].i;
 	GLint texture = p[2].i;
 	GLTexture* t;
+	GLContext* c = gl_get_context();
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if(!(target == GL_TEXTURE_2D && target > 0))
 #define ERROR_FLAG GL_INVALID_ENUM
@@ -214,22 +206,23 @@
 	gl_add_op(p);
 }
 void glopCopyTexImage2D(GLParam* p){
-	GLContext* c = gl_get_context();
+	GLImage* im; PIXEL* data;
 	GLint target = p[1].i;
 	GLint level = p[2].i;
-	//GLenum internalformat = p[3].i;
+	
 	GLint x = p[4].i;
 	GLint y = p[5].i;
 	GLsizei w = p[6].i;
 	GLsizei h = p[7].i;
-	y -= h; //Spec says LOWER left corner. So, let's change it to top left, for our purposes, eh?
+	GLContext* c = gl_get_context();
+	y -= h; 
 	GLint border = p[8].i;
-	//todo
+	
 	if(c->readbuffer != GL_FRONT ||
 		c->current_texture == NULL ||
 		target != GL_TEXTURE_2D ||
 		border != 0 ||
-		w != TGL_FEATURE_TEXTURE_DIM ||  //TODO Implement image interp
+		w != TGL_FEATURE_TEXTURE_DIM ||  /*TODO Implement image interp*/
 		h != TGL_FEATURE_TEXTURE_DIM
 	)
 	{
@@ -240,8 +233,8 @@
 		return;
 #endif
 	}
-	GLImage* im = &c->current_texture->images[level];
-	PIXEL* data = c->current_texture->images[level].pixmap;
+	im = &c->current_texture->images[level];
+	data = c->current_texture->images[level].pixmap;
 	im->xsize = TGL_FEATURE_TEXTURE_DIM;
 	im->ysize = TGL_FEATURE_TEXTURE_DIM;
 	//sample the buffer.
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -45,9 +45,9 @@
 
 
 void glopBegin(GLParam* p) {
-	GLContext* c = gl_get_context();
 	GLint type;
 	M4 tmp;
+	GLContext* c = gl_get_context();
 #if TGL_FEATURE_ERROR_CHECK == 1
 	if(c->in_begin != 0)
 #define ERROR_FLAG GL_INVALID_OPERATION
@@ -150,8 +150,7 @@
 }
 
 static inline void gl_vertex_transform(GLVertex* v) {
-	GLfloat* m;
-	GLContext* c = gl_get_context();
+	GLfloat* m;GLContext* c = gl_get_context();
 
 
 	if (c->lighting_enabled) 
--- a/src/zpostprocess.c
+++ b/src/zpostprocess.c
@@ -3,9 +3,10 @@
 #include "zgl.h"
 
 void glPostProcess(GLuint (*postprocess)(GLint x, GLint y, GLuint pixel, GLushort z)){
+	GLint i,j;
 	GLContext* c = gl_get_context();
 #pragma omp parallel for collapse(2)
-	for(GLint j = 0; j < c->zb->ysize; j++)
-	for(GLint i = 0; i < c->zb->xsize; i++)
+	for(j = 0; j < c->zb->ysize; j++)
+	for(i = 0; i < c->zb->xsize; i++)
 		c->zb->pbuf[i+j*(c->zb->xsize)] = postprocess(i,j,c->zb->pbuf[i+j*(c->zb->xsize)],c->zb->zbuf[i+j*(c->zb->xsize)]);
 }