[Scummvm-git-logs] scummvm master -> 06b5c259d6d4df0211dde959da7342ef1de1bf01

aquadran aquadran at gmail.com
Wed Oct 27 20:15:41 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
06b5c259d6 TINYGL: Fixed index in arrays and expanded to other data types.


Commit: 06b5c259d6d4df0211dde959da7342ef1de1bf01
    https://github.com/scummvm/scummvm/commit/06b5c259d6d4df0211dde959da7342ef1de1bf01
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-10-27T22:11:59+02:00

Commit Message:
TINYGL: Fixed index in arrays and expanded to other data types.

Changed paths:
    graphics/tinygl/arrays.cpp
    graphics/tinygl/zgl.h


diff --git a/graphics/tinygl/arrays.cpp b/graphics/tinygl/arrays.cpp
index 2b82ef5756..e852505491 100644
--- a/graphics/tinygl/arrays.cpp
+++ b/graphics/tinygl/arrays.cpp
@@ -43,36 +43,109 @@ void glopArrayElement(GLContext *c, GLParam *param) {
 	if (states & COLOR_ARRAY) {
 		GLParam p[5];
 		int size = c->color_array_size;
-		i = idx * (size + c->color_array_stride);
-		p[1].f = c->color_array[i];
-		p[2].f = c->color_array[i + 1];
-		p[3].f = c->color_array[i + 2];
-		p[4].f = size > 3 ? c->color_array[i + 3] : 1.0f;
+		i = idx * size;
+		if (c->color_array_short) {
+			p[1].f = c->color_array_short[i];
+			p[2].f = c->color_array_short[i + 1];
+			p[3].f = c->color_array_short[i + 2];
+			p[4].f = size > 3 ? c->color_array_short[i + 3] : 1.0f;
+		} else if (c->color_array_int) {
+			p[1].f = c->color_array_int[i];
+			p[2].f = c->color_array_int[i + 1];
+			p[3].f = c->color_array_int[i + 2];
+			p[4].f = size > 3 ? c->color_array_int[i + 3] : 1.0f;
+		} else if (c->color_array_float) {
+			p[1].f = c->color_array_float[i];
+			p[2].f = c->color_array_float[i + 1];
+			p[3].f = c->color_array_float[i + 2];
+			p[4].f = size > 3 ? c->color_array_float[i + 3] : 1.0f;
+		} else if (c->color_array_double) {
+			p[1].f = (float)c->color_array_double[i];
+			p[2].f = (float)c->color_array_double[i + 1];
+			p[3].f = (float)c->color_array_double[i + 2];
+			p[4].f = size > 3 ? (float)c->color_array_double[i + 3] : 1.0f;
+		} else {
+			assert(0);
+		}
 		glopColor(c, p);
 	}
 	if (states & NORMAL_ARRAY) {
-		i = idx * (3 + c->normal_array_stride);
-		c->current_normal.X = c->normal_array[i];
-		c->current_normal.Y = c->normal_array[i + 1];
-		c->current_normal.Z = c->normal_array[i + 2];
-		c->current_normal.W = 0.0f; // NOTE: this used to be Z but assigning Z again seemed like a bug...
+		i = idx * 3;
+		c->current_normal.W = 0.0f;
+		if (c->normal_array_short) {
+			c->current_normal.X = c->normal_array_short[i];
+			c->current_normal.Y = c->normal_array_short[i + 1];
+			c->current_normal.Z = c->normal_array_short[i + 2];
+		} else if (c->normal_array_int) {
+			c->current_normal.X = c->normal_array_int[i];
+			c->current_normal.Y = c->normal_array_int[i + 1];
+			c->current_normal.Z = c->normal_array_int[i + 2];
+		} else if (c->normal_array_float) {
+			c->current_normal.X = c->normal_array_float[i];
+			c->current_normal.Y = c->normal_array_float[i + 1];
+			c->current_normal.Z = c->normal_array_float[i + 2];
+		} else if (c->normal_array_double) {
+			c->current_normal.X = c->normal_array_double[i];
+			c->current_normal.Y = c->normal_array_double[i + 1];
+			c->current_normal.Z = c->normal_array_double[i + 2];
+		} else {
+			assert(0);
+		}
 	}
 	if (states & TEXCOORD_ARRAY) {
 		int size = c->texcoord_array_size;
-		i = idx * (size + c->texcoord_array_stride);
-		c->current_tex_coord.X = c->texcoord_array[i];
-		c->current_tex_coord.Y = c->texcoord_array[i + 1];
-		c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f;
-		c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
+		i = idx * size;
+		if (c->texcoord_array_short) {
+			c->current_tex_coord.X = c->texcoord_array_short[i];
+			c->current_tex_coord.Y = c->texcoord_array_short[i + 1];
+			c->current_tex_coord.Z = size > 2 ? c->texcoord_array_short[i + 2] : 0.0f;
+			c->current_tex_coord.W = size > 3 ? c->texcoord_array_short[i + 3] : 1.0f;
+		} else if (c->texcoord_array_int) {
+			c->current_tex_coord.X = c->texcoord_array_int[i];
+			c->current_tex_coord.Y = c->texcoord_array_int[i + 1];
+			c->current_tex_coord.Z = size > 2 ? c->texcoord_array_int[i + 2] : 0.0f;
+			c->current_tex_coord.W = size > 3 ? c->texcoord_array_int[i + 3] : 1.0f;
+		} else if (c->texcoord_array_float) {
+			c->current_tex_coord.X = c->texcoord_array_float[i];
+			c->current_tex_coord.Y = c->texcoord_array_float[i + 1];
+			c->current_tex_coord.Z = size > 2 ? c->texcoord_array_float[i + 2] : 0.0f;
+			c->current_tex_coord.W = size > 3 ? c->texcoord_array_float[i + 3] : 1.0f;
+		} else if (c->texcoord_array_double) {
+			c->current_tex_coord.X = c->texcoord_array_double[i];
+			c->current_tex_coord.Y = c->texcoord_array_double[i + 1];
+			c->current_tex_coord.Z = size > 2 ? c->texcoord_array_double[i + 2] : 0.0f;
+			c->current_tex_coord.W = size > 3 ? c->texcoord_array_double[i + 3] : 1.0f;
+		} else {
+			assert(0);
+		}
 	}
 	if (states & VERTEX_ARRAY) {
 		GLParam p[5];
 		int size = c->vertex_array_size;
-		i = idx * (size + c->vertex_array_stride);
-		p[1].f = c->vertex_array[i];
-		p[2].f = c->vertex_array[i + 1];
-		p[3].f = size > 2 ? c->vertex_array[i + 2] : 0.0f;
-		p[4].f = size > 3 ? c->vertex_array[i + 3] : 1.0f;
+		i = idx * size;
+		if (c->vertex_array_short) {
+			p[1].f = c->vertex_array_short[i];
+			p[2].f = c->vertex_array_short[i + 1];
+			p[3].f = size > 2 ? c->vertex_array_short[i + 2] : 0.0f;
+			p[4].f = size > 3 ? c->vertex_array_short[i + 3] : 1.0f;
+		} else if (c->vertex_array_int) {
+			p[1].f = c->vertex_array_int[i];
+			p[2].f = c->vertex_array_int[i + 1];
+			p[3].f = size > 2 ? c->vertex_array_int[i + 2] : 0.0f;
+			p[4].f = size > 3 ? c->vertex_array_int[i + 3] : 1.0f;
+		} else if (c->vertex_array_float) {
+			p[1].f = c->vertex_array_float[i];
+			p[2].f = c->vertex_array_float[i + 1];
+			p[3].f = size > 2 ? c->vertex_array_float[i + 2] : 0.0f;
+			p[4].f = size > 3 ? c->vertex_array_float[i + 3] : 1.0f;
+		} else if (c->vertex_array_double) {
+			p[1].f = c->vertex_array_double[i];
+			p[2].f = c->vertex_array_double[i + 1];
+			p[3].f = size > 2 ? c->vertex_array_double[i + 2] : 0.0f;
+			p[4].f = size > 3 ? c->vertex_array_double[i + 3] : 1.0f;
+		} else {
+			assert(0);
+		}
 		glopVertex(c, p);
 	}
 }
@@ -129,25 +202,105 @@ void glopDisableClientState(GLContext *c, GLParam *p) {
 
 void glopVertexPointer(GLContext *c, GLParam *p) {
 	c->vertex_array_size = p[1].i;
-	c->vertex_array_stride = p[2].i;
-	c->vertex_array = (float *)p[3].p;
+	c->vertex_array_stride = p[3].i;
+	c->vertex_array_int = nullptr;
+	c->vertex_array_short = nullptr;
+	c->vertex_array_float = nullptr;
+	c->vertex_array_double = nullptr;
+	switch (p[2].i) {
+	case TGL_SHORT:
+		c->vertex_array_short = (TGLshort *)p[4].p;
+		break;
+	case TGL_INT:
+		c->vertex_array_int = (TGLint *)p[4].p;
+		break;
+	case TGL_FLOAT:
+		c->vertex_array_float = (TGLfloat *)p[4].p;
+		break;
+	case TGL_DOUBLE:
+		c->vertex_array_double = (TGLdouble *)p[4].p;
+		break;
+	default:
+		assert(0);
+		break;
+	}
 }
 
 void glopColorPointer(GLContext *c, GLParam *p) {
 	c->color_array_size = p[1].i;
-	c->color_array_stride = p[2].i;
-	c->color_array = (float *)p[3].p;
+	c->color_array_stride = p[3].i;
+	c->color_array_int = nullptr;
+	c->color_array_short = nullptr;
+	c->color_array_float = nullptr;
+	c->color_array_double = nullptr;
+	switch (p[2].i) {
+	case TGL_SHORT:
+		c->color_array_short = (TGLshort *)p[4].p;
+		break;
+	case TGL_INT:
+		c->color_array_int = (TGLint *)p[4].p;
+		break;
+	case TGL_FLOAT:
+		c->color_array_float = (TGLfloat *)p[4].p;
+		break;
+	case TGL_DOUBLE:
+		c->color_array_double = (TGLdouble *)p[4].p;
+		break;
+	default:
+		assert(0);
+		break;
+	}
 }
 
 void glopNormalPointer(GLContext *c, GLParam *p) {
-	c->normal_array_stride = p[1].i;
-	c->normal_array = (float *)p[2].p;
+	c->normal_array_stride = p[2].i;
+	c->normal_array_int = nullptr;
+	c->normal_array_short = nullptr;
+	c->normal_array_float = nullptr;
+	c->normal_array_double = nullptr;
+	switch (p[1].i) {
+	case TGL_SHORT:
+		c->normal_array_short = (TGLshort *)p[3].p;
+		break;
+	case TGL_INT:
+		c->normal_array_int = (TGLint *)p[3].p;
+		break;
+	case TGL_FLOAT:
+		c->normal_array_float = (TGLfloat *)p[3].p;
+		break;
+	case TGL_DOUBLE:
+		c->normal_array_double = (TGLdouble *)p[3].p;
+		break;
+	default:
+		assert(0);
+		break;
+	}
 }
 
 void glopTexCoordPointer(GLContext *c, GLParam *p) {
 	c->texcoord_array_size = p[1].i;
-	c->texcoord_array_stride = p[2].i;
-	c->texcoord_array = (float *)p[3].p;
+	c->texcoord_array_stride = p[3].i;
+	c->texcoord_array_int = nullptr;
+	c->texcoord_array_short = nullptr;
+	c->texcoord_array_float = nullptr;
+	c->texcoord_array_double = nullptr;
+	switch (p[2].i) {
+	case TGL_SHORT:
+		c->texcoord_array_short = (TGLshort *)p[4].p;
+		break;
+	case TGL_INT:
+		c->texcoord_array_int = (TGLint *)p[4].p;
+		break;
+	case TGL_FLOAT:
+		c->texcoord_array_float = (TGLfloat *)p[4].p;
+		break;
+	case TGL_DOUBLE:
+		c->texcoord_array_double = (TGLdouble *)p[4].p;
+		break;
+	default:
+		assert(0);
+		break;
+	}
 }
 
 } // end of namespace TinyGL
@@ -227,40 +380,40 @@ void tglDisableClientState(TGLenum array) {
 }
 
 void tglVertexPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
-	TinyGL::GLParam p[4];
-	assert(type == TGL_FLOAT);
+	TinyGL::GLParam p[5];
 	p[0].op = TinyGL::OP_VertexPointer;
 	p[1].i = size;
-	p[2].i = stride;
-	p[3].p = const_cast<void *>(pointer);
+	p[2].i = type;
+	p[3].i = stride;
+	p[4].p = const_cast<void *>(pointer);
 	gl_add_op(p);
 }
 
 void tglColorPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
-	TinyGL::GLParam p[4];
-	assert(type == TGL_FLOAT);
+	TinyGL::GLParam p[5];
 	p[0].op = TinyGL::OP_ColorPointer;
 	p[1].i = size;
-	p[2].i = stride;
-	p[3].p = const_cast<void *>(pointer);
+	p[2].i = type;
+	p[3].i = stride;
+	p[4].p = const_cast<void *>(pointer);
 	gl_add_op(p);
 }
 
 void tglNormalPointer(TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
-	TinyGL::GLParam p[3];
-	assert(type == TGL_FLOAT);
+	TinyGL::GLParam p[4];
 	p[0].op = TinyGL::OP_NormalPointer;
-	p[1].i = stride;
-	p[2].p = const_cast<void *>(pointer);
+	p[1].i = type;
+	p[2].i = stride;
+	p[3].p = const_cast<void *>(pointer);
 	gl_add_op(p);
 }
 
 void tglTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
-	TinyGL::GLParam p[4];
-	assert(type == TGL_FLOAT);
+	TinyGL::GLParam p[5];
 	p[0].op = TinyGL::OP_TexCoordPointer;
 	p[1].i = size;
-	p[2].i = stride;
-	p[3].p = const_cast<void *>(pointer);
+	p[2].i = type;
+	p[3].i = stride;
+	p[4].p = const_cast<void *>(pointer);
 	gl_add_op(p);
 }
diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h
index 7e99fe8bd9..c956c0f5a9 100644
--- a/graphics/tinygl/zgl.h
+++ b/graphics/tinygl/zgl.h
@@ -349,15 +349,27 @@ struct GLContext {
 	GLVertex *vertex;
 
 	// opengl 1.1 arrays
-	float *vertex_array;
+	TGLshort *vertex_array_short;
+	TGLint *vertex_array_int;
+	TGLfloat *vertex_array_float;
+	TGLdouble *vertex_array_double;
 	int vertex_array_size;
 	int vertex_array_stride;
-	float *normal_array;
+	TGLshort *normal_array_short;
+	TGLint *normal_array_int;
+	TGLfloat *normal_array_float;
+	TGLdouble *normal_array_double;
 	int normal_array_stride;
-	float *color_array;
+	TGLshort *color_array_short;
+	TGLint *color_array_int;
+	TGLfloat *color_array_float;
+	TGLdouble *color_array_double;
 	int color_array_size;
 	int color_array_stride;
-	float *texcoord_array;
+	TGLshort *texcoord_array_short;
+	TGLint *texcoord_array_int;
+	TGLfloat *texcoord_array_float;
+	TGLdouble *texcoord_array_double;
 	int texcoord_array_size;
 	int texcoord_array_stride;
 	int client_states;




More information about the Scummvm-git-logs mailing list