shithub: tinygl

Download patch

ref: a34a256d427468ec74ead49d48647317cae0e0c0
parent: b833e3a78434e4956e434a9e86781b879c2d6f96
author: Cameron Cawley <ccawley2011@gmail.com>
date: Mon Sep 6 17:06:37 EDT 2021

Only use OpenMP when _OPENMP is defined

--- a/include-demo/3dMath.h
+++ b/include-demo/3dMath.h
@@ -320,7 +320,9 @@
 }
 static inline mat4 multm4( mat4 a,  mat4 b){
 	mat4 ret;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for(int i = 0; i < 4; i++)
 	for(int j = 0; j < 4; j++)
 		ret.d[i*4 + j] = dotv4( /*j is the ROW of the target, i is the COLUMN.*/
--- a/src/clip.c
+++ b/src/clip.c
@@ -113,7 +113,9 @@
 	q->pc.Y = p0->pc.Y + (p1->pc.Y - p0->pc.Y) * t;
 	q->pc.Z = p0->pc.Z + (p1->pc.Z - p0->pc.Z) * t;
 	q->pc.W = p0->pc.W + (p1->pc.W - p0->pc.W) * t;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for (i = 0; i < 3; i++)
 		q->color.v[i] = p0->color.v[i] + (p1->color.v[i] - p0->color.v[i]) * t;
 }
--- a/src/texture.c
+++ b/src/texture.c
@@ -232,7 +232,9 @@
 	im->ysize = TGL_FEATURE_TEXTURE_DIM;
 	/* TODO implement the scaling and stuff that the GL spec says it should have.*/
 #if TGL_FEATURE_MULTITHREADED_COPY_TEXIMAGE_2D == 1
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
 	for (j = 0; j < h; j++)
 		for (i = 0; i < w; i++) {
 			data[i + j * w] = c->zb->pbuf[((i + x) % (c->zb->xsize)) + ((j + y) % (c->zb->ysize)) * (c->zb->xsize)];
--- a/src/zbuffer.c
+++ b/src/zbuffer.c
@@ -117,7 +117,9 @@
 static void ZB_copyBuffer(ZBuffer* zb, void* buf, GLint linesize) {
 	GLint y, i;
 #if TGL_FEATURE_MULTITHREADED_ZB_COPYBUFFER == 1
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
 	for (y = 0; y < zb->ysize; y++) {
 		PIXEL* q;
 		GLubyte* p1;
--- a/src/zmath.c
+++ b/src/zmath.c
@@ -11,7 +11,9 @@
 void gl_M4_Id(M4* a) {
 	/*
 		GLint i, j;
+	#ifdef _OPENMP
 	#pragma omp simd collapse(2)
+	#endif
 		for (i = 0; i < 4; i++)
 			for (j = 0; j < 4; j++)
 				if (i == j)
@@ -53,7 +55,9 @@
 void gl_M4_Mul(M4* c, M4* a, M4* b) {
 	GLint i, j, k;
 	GLfloat s;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for (i = 0; i < 4; i++)
 		for (j = 0; j < 4; j++) {
 			s = 0.0;
@@ -72,7 +76,9 @@
 	/*memcpy(&a, c, 16*sizeof(GLfloat));
 	 */
 	a = *c;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for (i = 0; i < 4; i++)
 		for (j = 0; j < 4; j++) {
 			s = 0.0;
@@ -136,7 +142,9 @@
 void gl_M4_InvOrtho(M4* a, M4 b) {
 	GLint i, j;
 	GLfloat s;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for (i = 0; i < 3; i++)
 		for (j = 0; j < 3; j++)
 			a->m[i][j] = b.m[j][i];
@@ -147,7 +155,9 @@
 
 	for (i = 0; i < 3; i++) {
 		s = 0;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 		for (j = 0; j < 3; j++)
 			s -= b.m[j][i] * b.m[j][3];
 		a->m[i][3] = s;
@@ -162,7 +172,9 @@
 	GLfloat max, tmp, t;
 
 	/*  */
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 	for (i = 0; i < n * n; i++)
 		r[i] = 0;
 	for (i = 0; i < n; i++)
@@ -184,7 +196,9 @@
 
 		/* permutation des lignes j et k */
 		if (k != j) {
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 			for (i = 0; i < n; i++) {
 				tmp = m[j * n + i];
 				m[j * n + i] = m[k * n + i];
@@ -198,7 +212,9 @@
 
 		/* multiplication de la ligne j par 1/max */
 		max = 1 / max;
+#ifdef _OPENMP
 #pragma omp simd
+#endif
 		for (i = 0; i < n; i++) {
 			m[j * n + i] *= max;
 			r[j * n + i] *= max;
--- a/src/zpostprocess.c
+++ b/src/zpostprocess.c
@@ -5,7 +5,9 @@
 void glPostProcess(GLuint (*postprocess)(GLint x, GLint y, GLuint pixel, GLushort z)) {
 	GLint i, j;
 	GLContext* c = gl_get_context();
+#ifdef _OPENMP
 #pragma omp parallel for collapse(2)
+#endif
 	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)]);
--- a/src/zraster.c
+++ b/src/zraster.c
@@ -141,7 +141,9 @@
 
 #if TGL_FEATURE_MULTITHREADED_DRAWPIXELS == 1
 
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
 	for (sy = 0; sy < h; sy++)
 		for (sx = 0; sx < w; sx++) {
 			PIXEL col = d[sy * w + sx];