[Scummvm-git-logs] scummvm master -> c1512a5c404174c3e780c48c785a6deec33244c9

aquadran noreply at scummvm.org
Mon Dec 6 23:58:19 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:
c1512a5c40 TINYGL: Eliminate passing context where possible


Commit: c1512a5c404174c3e780c48c785a6deec33244c9
    https://github.com/scummvm/scummvm/commit/c1512a5c404174c3e780c48c785a6deec33244c9
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-12-07T00:58:14+01:00

Commit Message:
TINYGL: Eliminate passing context where possible

Changed paths:
    graphics/tinygl/arrays.cpp
    graphics/tinygl/clear.cpp
    graphics/tinygl/clip.cpp
    graphics/tinygl/init.cpp
    graphics/tinygl/light.cpp
    graphics/tinygl/list.cpp
    graphics/tinygl/matrix.cpp
    graphics/tinygl/misc.cpp
    graphics/tinygl/select.cpp
    graphics/tinygl/specbuf.cpp
    graphics/tinygl/texture.cpp
    graphics/tinygl/vertex.cpp
    graphics/tinygl/zbuffer.cpp
    graphics/tinygl/zbuffer.h
    graphics/tinygl/zdirtyrect.cpp
    graphics/tinygl/zgl.h


diff --git a/graphics/tinygl/arrays.cpp b/graphics/tinygl/arrays.cpp
index a10fca52af..e11b4fb98c 100644
--- a/graphics/tinygl/arrays.cpp
+++ b/graphics/tinygl/arrays.cpp
@@ -37,17 +37,17 @@ namespace TinyGL {
 
 void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 	int offset;
-	int states = c->client_states;
+	int states = client_states;
 	int idx = param[1].i;
 
 	if (states & COLOR_ARRAY) {
 		GLParam p[5];
-		int size = c->color_array_size;
-		offset = idx * c->color_array_stride;
-		switch (c->color_array_type) {
+		int size = color_array_size;
+		offset = idx * color_array_stride;
+		switch (color_array_type) {
 		case TGL_UNSIGNED_BYTE:
 		case TGL_BYTE: {
-				TGLbyte *array = (TGLbyte *)c->color_array + offset;
+				TGLbyte *array = (TGLbyte *)color_array + offset;
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = array[2];
@@ -56,7 +56,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 			}
 		case TGL_UNSIGNED_INT:
 		case TGL_INT: {
-				TGLint *array = (TGLint *)((TGLbyte *)c->color_array + offset);
+				TGLint *array = (TGLint *)((TGLbyte *)color_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = array[2];
@@ -65,7 +65,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 			}
 		case TGL_UNSIGNED_SHORT:
 		case TGL_SHORT: {
-				TGLshort *array = (TGLshort *)((TGLbyte *)c->color_array + offset);
+				TGLshort *array = (TGLshort *)((TGLbyte *)color_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = array[2];
@@ -73,7 +73,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 				break;
 			}
 		case TGL_FLOAT: {
-				TGLfloat *array = (TGLfloat *)((TGLbyte *)c->color_array + offset);
+				TGLfloat *array = (TGLfloat *)((TGLbyte *)color_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = array[2];
@@ -81,7 +81,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 				break;
 			}
 		case TGL_DOUBLE: {
-				TGLdouble *array = (TGLdouble *)((TGLbyte *)c->color_array + offset);
+				TGLdouble *array = (TGLdouble *)((TGLbyte *)color_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = array[2];
@@ -91,38 +91,38 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 		default:
 			assert(0);
 		}
-		c->glopColor(c, p);
+		glopColor(c, p);
 	}
 	if (states & NORMAL_ARRAY) {
-		offset = idx * c->normal_array_stride;
-		c->current_normal.W = 0.0f;
-		switch (c->normal_array_type) {
+		offset = idx * normal_array_stride;
+		current_normal.W = 0.0f;
+		switch (normal_array_type) {
 		case TGL_FLOAT: {
-				TGLfloat *array = (TGLfloat *)((TGLbyte *)c->normal_array + offset);
-				c->current_normal.X = array[0];
-				c->current_normal.Y = array[1];
-				c->current_normal.Z = array[2];
+				TGLfloat *array = (TGLfloat *)((TGLbyte *)normal_array + offset);
+				current_normal.X = array[0];
+				current_normal.Y = array[1];
+				current_normal.Z = array[2];
 				break;
 			}
 		case TGL_DOUBLE: {
-				TGLdouble *array = (TGLdouble *)((TGLbyte *)c->normal_array + offset);
-				c->current_normal.X = array[0];
-				c->current_normal.Y = array[1];
-				c->current_normal.Z = array[2];
+				TGLdouble *array = (TGLdouble *)((TGLbyte *)normal_array + offset);
+				current_normal.X = array[0];
+				current_normal.Y = array[1];
+				current_normal.Z = array[2];
 				break;
 			}
 		case TGL_INT: {
-				TGLint *array = (TGLint *)((TGLbyte *)c->normal_array + offset);
-				c->current_normal.X = array[0];
-				c->current_normal.Y = array[1];
-				c->current_normal.Z = array[2];
+				TGLint *array = (TGLint *)((TGLbyte *)normal_array + offset);
+				current_normal.X = array[0];
+				current_normal.Y = array[1];
+				current_normal.Z = array[2];
 				break;
 			}
 		case TGL_SHORT: {
-				TGLshort *array = (TGLshort *)((TGLbyte *)c->normal_array + offset);
-				c->current_normal.X = array[0];
-				c->current_normal.Y = array[1];
-				c->current_normal.Z = array[2];
+				TGLshort *array = (TGLshort *)((TGLbyte *)normal_array + offset);
+				current_normal.X = array[0];
+				current_normal.Y = array[1];
+				current_normal.Z = array[2];
 			break;
 		}
 		default:
@@ -130,39 +130,39 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 		}
 	}
 	if (states & TEXCOORD_ARRAY) {
-		int size = c->texcoord_array_size;
-		offset = idx * c->texcoord_array_stride;
+		int size = texcoord_array_size;
+		offset = idx * texcoord_array_stride;
 		switch (c->texcoord_array_type) {
 		case TGL_FLOAT: {
-				TGLfloat *array = (TGLfloat *)((TGLbyte *)c->texcoord_array + offset);
-				c->current_tex_coord.X = array[0];
-				c->current_tex_coord.Y = array[1];
-				c->current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
-				c->current_tex_coord.W = size > 3 ? array[3] : 1.0f;
+				TGLfloat *array = (TGLfloat *)((TGLbyte *)texcoord_array + offset);
+				current_tex_coord.X = array[0];
+				current_tex_coord.Y = array[1];
+				current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
+				current_tex_coord.W = size > 3 ? array[3] : 1.0f;
 				break;
 			}
 		case TGL_DOUBLE: {
-				TGLdouble *array = (TGLdouble *)((TGLbyte *)c->texcoord_array + offset);
-				c->current_tex_coord.X = array[0];
-				c->current_tex_coord.Y = array[1];
-				c->current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
-				c->current_tex_coord.W = size > 3 ? array[3] : 1.0f;
+				TGLdouble *array = (TGLdouble *)((TGLbyte *)texcoord_array + offset);
+				current_tex_coord.X = array[0];
+				current_tex_coord.Y = array[1];
+				current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
+				current_tex_coord.W = size > 3 ? array[3] : 1.0f;
 				break;
 			}
 		case TGL_INT: {
-				TGLint *array = (TGLint *)((TGLbyte *)c->texcoord_array + offset);
-				c->current_tex_coord.X = array[0];
-				c->current_tex_coord.Y = array[1];
-				c->current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
-				c->current_tex_coord.W = size > 3 ? array[3] : 1.0f;
+				TGLint *array = (TGLint *)((TGLbyte *)texcoord_array + offset);
+				current_tex_coord.X = array[0];
+				current_tex_coord.Y = array[1];
+				current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
+				current_tex_coord.W = size > 3 ? array[3] : 1.0f;
 				break;
 			}
 		case TGL_SHORT: {
-				TGLshort *array = (TGLshort *)((TGLbyte *)c->texcoord_array + offset);
-				c->current_tex_coord.X = array[0];
-				c->current_tex_coord.Y = array[1];
-				c->current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
-				c->current_tex_coord.W = size > 3 ? array[3] : 1.0f;
+				TGLshort *array = (TGLshort *)((TGLbyte *)texcoord_array + offset);
+				current_tex_coord.X = array[0];
+				current_tex_coord.Y = array[1];
+				current_tex_coord.Z = size > 2 ? array[2] : 0.0f;
+				current_tex_coord.W = size > 3 ? array[3] : 1.0f;
 				break;
 			}
 		default:
@@ -171,11 +171,11 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 	}
 	if (states & VERTEX_ARRAY) {
 		GLParam p[5];
-		int size = c->vertex_array_size;
-		offset = idx * c->vertex_array_stride;
-		switch (c->vertex_array_type) {
+		int size = vertex_array_size;
+		offset = idx * vertex_array_stride;
+		switch (vertex_array_type) {
 		case TGL_FLOAT: {
-				TGLfloat *array = (TGLfloat *)((TGLbyte *)c->vertex_array + offset);
+				TGLfloat *array = (TGLfloat *)((TGLbyte *)vertex_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = size > 2 ? array[2] : 0.0f;
@@ -183,7 +183,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 				break;
 			}
 		case TGL_DOUBLE: {
-				TGLdouble *array = (TGLdouble *)((TGLbyte *)c->vertex_array + offset);
+				TGLdouble *array = (TGLdouble *)((TGLbyte *)vertex_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = size > 2 ? array[2] : 0.0f;
@@ -191,7 +191,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 				break;
 			}
 		case TGL_INT: {
-				TGLint *array = (TGLint *)((TGLbyte *)c->vertex_array + offset);
+				TGLint *array = (TGLint *)((TGLbyte *)vertex_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = size > 2 ? array[2] : 0.0f;
@@ -199,7 +199,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 				break;
 			}
 		case TGL_SHORT: {
-				TGLshort *array = (TGLshort *)((TGLbyte *)c->vertex_array + offset);
+				TGLshort *array = (TGLshort *)((TGLbyte *)vertex_array + offset);
 				p[1].f = array[0];
 				p[2].f = array[1];
 				p[3].f = size > 2 ? array[2] : 0.0f;
@@ -209,7 +209,7 @@ void GLContext::glopArrayElement(GLContext *c, GLParam *param) {
 		default:
 			assert(0);
 		}
-		c->glopVertex(c, p);
+		glopVertex(c, p);
 	}
 }
 
@@ -218,12 +218,12 @@ void GLContext::glopDrawArrays(GLContext *c, GLParam *p) {
 	GLParam begin[2];
 
 	begin[1].i = p[1].i;
-	c->glopBegin(c, begin);
+	glopBegin(c, begin);
 	for (int i = 0; i < p[3].i; i++) {
 		array_element[1].i = p[2].i + i;
 		glopArrayElement(c, array_element);
 	}
-	c->glopEnd(c, NULL);
+	glopEnd(c, NULL);
 }
 
 void GLContext::glopDrawElements(GLContext *c, GLParam *p) {
@@ -234,7 +234,7 @@ void GLContext::glopDrawElements(GLContext *c, GLParam *p) {
 	indices = (char *)p[4].p;
 	begin[1].i = p[1].i;
 
-	c->glopBegin(c, begin);
+	glopBegin(c, begin);
 	for (int i = 0; i < p[2].i; i++) {
 		switch (p[3].i) {
 		case TGL_UNSIGNED_BYTE:
@@ -252,33 +252,33 @@ void GLContext::glopDrawElements(GLContext *c, GLParam *p) {
 		}
 		glopArrayElement(c, array_element);
 	}
-	c->glopEnd(c, NULL);
+	glopEnd(c, NULL);
 }
 
 void GLContext::glopEnableClientState(GLContext *c, GLParam *p) {
-	c->client_states |= p[1].i;
+	client_states |= p[1].i;
 }
 
 void GLContext::glopDisableClientState(GLContext *c, GLParam *p) {
-	c->client_states &= p[1].i;
+	client_states &= p[1].i;
 }
 
 void GLContext::glopVertexPointer(GLContext *c, GLParam *p) {
-	c->vertex_array_size = p[1].i;
-	c->vertex_array_type = p[2].i;
-	c->vertex_array = p[4].p;
-	switch (c->vertex_array_type) {
+	vertex_array_size = p[1].i;
+	vertex_array_type = p[2].i;
+	vertex_array = p[4].p;
+	switch (vertex_array_type) {
 	case TGL_FLOAT:
-		c->vertex_array_stride = p[3].i != 0 ? p[3].i : c->vertex_array_size * sizeof(TGLfloat);
+		vertex_array_stride = p[3].i != 0 ? p[3].i : vertex_array_size * sizeof(TGLfloat);
 		break;
 	case TGL_DOUBLE:
-		c->vertex_array_stride = p[3].i != 0 ? p[3].i : c->vertex_array_size * sizeof(TGLdouble);
+		vertex_array_stride = p[3].i != 0 ? p[3].i : vertex_array_size * sizeof(TGLdouble);
 		break;
 	case TGL_INT:
-		c->vertex_array_stride = p[3].i != 0 ? p[3].i : c->vertex_array_size * sizeof(TGLint);
+		vertex_array_stride = p[3].i != 0 ? p[3].i : vertex_array_size * sizeof(TGLint);
 		break;
 	case TGL_SHORT:
-		c->vertex_array_stride = p[3].i != 0 ? p[3].i : c->vertex_array_size * sizeof(TGLshort);
+		vertex_array_stride = p[3].i != 0 ? p[3].i : vertex_array_size * sizeof(TGLshort);
 		break;
 	default:
 		assert(0);
@@ -287,27 +287,27 @@ void GLContext::glopVertexPointer(GLContext *c, GLParam *p) {
 }
 
 void GLContext::glopColorPointer(GLContext *c, GLParam *p) {
-	c->color_array_size = p[1].i;
-	c->color_array_type = p[2].i;
-	c->color_array = p[4].p;
-	switch (c->color_array_type) {
+	color_array_size = p[1].i;
+	color_array_type = p[2].i;
+	color_array = p[4].p;
+	switch (color_array_type) {
 	case TGL_BYTE:
 	case TGL_UNSIGNED_BYTE:
-		c->color_array_stride = p[3].i != 0 ? p[3].i : c->color_array_stride * sizeof(TGLbyte);
+		color_array_stride = p[3].i != 0 ? p[3].i : color_array_stride * sizeof(TGLbyte);
 		break;
 	case TGL_SHORT:
 	case TGL_UNSIGNED_SHORT:
-		c->color_array_stride = p[3].i != 0 ? p[3].i : c->color_array_stride * sizeof(TGLshort);
+		color_array_stride = p[3].i != 0 ? p[3].i : color_array_stride * sizeof(TGLshort);
 		break;
 	case TGL_INT:
 	case TGL_UNSIGNED_INT:
-		c->color_array_stride = p[3].i != 0 ? p[3].i : c->color_array_stride * sizeof(TGLint);
+		color_array_stride = p[3].i != 0 ? p[3].i : color_array_stride * sizeof(TGLint);
 		break;
 	case TGL_FLOAT:
-		c->color_array_stride = p[3].i != 0 ? p[3].i : c->color_array_stride * sizeof(TGLfloat);
+		color_array_stride = p[3].i != 0 ? p[3].i : color_array_stride * sizeof(TGLfloat);
 		break;
 	case TGL_DOUBLE:
-		c->color_array_stride = p[3].i != 0 ? p[3].i : c->color_array_stride * sizeof(TGLdouble);
+		color_array_stride = p[3].i != 0 ? p[3].i : color_array_stride * sizeof(TGLdouble);
 		break;
 	default:
 		assert(0);
@@ -316,20 +316,20 @@ void GLContext::glopColorPointer(GLContext *c, GLParam *p) {
 }
 
 void GLContext::glopNormalPointer(GLContext *c, GLParam *p) {
-	c->normal_array_type = p[1].i;
-	c->normal_array = p[3].p;
+	normal_array_type = p[1].i;
+	normal_array = p[3].p;
 	switch (p[1].i) {
 	case TGL_FLOAT:
-		c->normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLfloat);
+		normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLfloat);
 		break;
 	case TGL_DOUBLE:
-		c->normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLdouble);
+		normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLdouble);
 		break;
 	case TGL_INT:
-		c->normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLint);
+		normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLint);
 		break;
 	case TGL_SHORT:
-		c->normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLshort);
+		normal_array_stride = p[2].i != 0 ? p[2].i : 3 * sizeof(TGLshort);
 		break;
 	default:
 		assert(0);
@@ -338,21 +338,21 @@ void GLContext::glopNormalPointer(GLContext *c, GLParam *p) {
 }
 
 void GLContext::glopTexCoordPointer(GLContext *c, GLParam *p) {
-	c->texcoord_array_size = p[1].i;
-	c->texcoord_array_type = p[2].i;
-	c->texcoord_array = p[4].p;
-	switch (c->texcoord_array_type) {
+	texcoord_array_size = p[1].i;
+	texcoord_array_type = p[2].i;
+	texcoord_array = p[4].p;
+	switch (texcoord_array_type) {
 	case TGL_FLOAT:
-		c->texcoord_array_stride = p[3].i != 0 ? p[3].i : c->texcoord_array_size * sizeof(TGLfloat);
+		texcoord_array_stride = p[3].i != 0 ? p[3].i : texcoord_array_size * sizeof(TGLfloat);
 		break;
 	case TGL_DOUBLE:
-		c->texcoord_array_stride = p[3].i != 0 ? p[3].i : c->texcoord_array_size * sizeof(TGLdouble);
+		texcoord_array_stride = p[3].i != 0 ? p[3].i : texcoord_array_size * sizeof(TGLdouble);
 		break;
 	case TGL_INT:
-		c->texcoord_array_stride = p[3].i != 0 ? p[3].i : c->texcoord_array_size * sizeof(TGLint);
+		texcoord_array_stride = p[3].i != 0 ? p[3].i : texcoord_array_size * sizeof(TGLint);
 		break;
 	case TGL_SHORT:
-		c->texcoord_array_stride = p[3].i != 0 ? p[3].i : c->texcoord_array_size * sizeof(TGLshort);
+		texcoord_array_stride = p[3].i != 0 ? p[3].i : texcoord_array_size * sizeof(TGLshort);
 		break;
 	default:
 		assert(0);
diff --git a/graphics/tinygl/clear.cpp b/graphics/tinygl/clear.cpp
index 4e2c80cb45..56890b9d65 100644
--- a/graphics/tinygl/clear.cpp
+++ b/graphics/tinygl/clear.cpp
@@ -32,19 +32,19 @@
 namespace TinyGL {
 
 void GLContext::glopClearColor(GLContext *c, GLParam *p) {
-	c->clear_color = Vector4(p[1].f, p[2].f, p[3].f, p[4].f);
+	clear_color = Vector4(p[1].f, p[2].f, p[3].f, p[4].f);
 }
 
 void GLContext::glopClearDepth(GLContext *c, GLParam *p) {
-	c->clear_depth = p[1].f;
+	clear_depth = p[1].f;
 }
 
 void GLContext::glopClear(GLContext *c, GLParam *p) {
 	int mask = p[1].i;
-	int z = (int)(c->clear_depth * ((1 << ZB_Z_BITS) - 1));
-	int r = (int)(c->clear_color.X * 255);
-	int g = (int)(c->clear_color.Y * 255);
-	int b = (int)(c->clear_color.Z * 255);
+	int z = (int)(clear_depth * ((1 << ZB_Z_BITS) - 1));
+	int r = (int)(clear_color.X * 255);
+	int g = (int)(clear_color.Y * 255);
+	int b = (int)(clear_color.Z * 255);
 
 	issueDrawCall(new ClearBufferDrawCall(mask & TGL_DEPTH_BUFFER_BIT, z, mask & TGL_COLOR_BUFFER_BIT, r, g, b));
 }
diff --git a/graphics/tinygl/clip.cpp b/graphics/tinygl/clip.cpp
index 2f37aec22a..249f5c5118 100644
--- a/graphics/tinygl/clip.cpp
+++ b/graphics/tinygl/clip.cpp
@@ -40,14 +40,14 @@ namespace TinyGL {
 #define CLIP_ZMIN   (1 << 4)
 #define CLIP_ZMAX   (1 << 5)
 
-void GLContext::gl_transform_to_viewport(GLContext *c, GLVertex *v) {
+void GLContext::gl_transform_to_viewport(GLVertex *v) {
 	float winv;
 
 	// coordinates
 	winv = (float)(1.0 / v->pc.W);
-	v->zp.x = (int)(v->pc.X * winv * c->viewport.scale.X + c->viewport.trans.X);
-	v->zp.y = (int)(v->pc.Y * winv * c->viewport.scale.Y + c->viewport.trans.Y);
-	v->zp.z = (int)(v->pc.Z * winv * c->viewport.scale.Z + c->viewport.trans.Z);
+	v->zp.x = (int)(v->pc.X * winv * viewport.scale.X + viewport.trans.X);
+	v->zp.y = (int)(v->pc.Y * winv * viewport.scale.Y + viewport.trans.Y);
+	v->zp.z = (int)(v->pc.Z * winv * viewport.scale.Z + viewport.trans.Z);
 	// color
 	v->zp.r = (int)(v->color.X * ZB_POINT_RED_MAX);
 	v->zp.g = (int)(v->color.Y * ZB_POINT_GREEN_MAX);
@@ -55,13 +55,13 @@ void GLContext::gl_transform_to_viewport(GLContext *c, GLVertex *v) {
 	v->zp.a = (int)(v->color.W * ZB_POINT_ALPHA_MAX);
 
 	// texture
-	if (c->texture_2d_enabled) {
+	if (texture_2d_enabled) {
 		v->zp.s = (int)(v->tex_coord.X * ZB_POINT_ST_MAX);
 		v->zp.t = (int)(v->tex_coord.Y * ZB_POINT_ST_MAX);
 	}
 }
 
-void GLContext::gl_add_select1(GLContext *c, int z1, int z2, int z3) {
+void GLContext::gl_add_select1(int z1, int z2, int z3) {
 	int min, max;
 
 	min = max = z1;
@@ -74,17 +74,17 @@ void GLContext::gl_add_select1(GLContext *c, int z1, int z2, int z3) {
 	if (z3 > max)
 		max = z3;
 
-	c->gl_add_select(c, 0xffffffff - min, 0xffffffff - max);
+	gl_add_select(0xffffffff - min, 0xffffffff - max);
 }
 
 // point
 
-void GLContext::gl_draw_point(GLContext *c, GLVertex *p0) {
+void GLContext::gl_draw_point(GLVertex *p0) {
 	if (p0->clip_code == 0) {
-		if (c->render_mode == TGL_SELECT) {
-			c->gl_add_select(c, p0->zp.z, p0->zp.z);
+		if (render_mode == TGL_SELECT) {
+			gl_add_select(p0->zp.z, p0->zp.z);
 		} else {
-			c->fb->plot(&p0->zp);
+			fb->plot(&p0->zp);
 		}
 	}
 }
@@ -128,7 +128,7 @@ static inline int ClipLine1(float denom, float num, float *tmin, float *tmax) {
 	return 1;
 }
 
-void GLContext::gl_draw_line(GLContext *c, GLVertex *p1, GLVertex *p2) {
+void GLContext::gl_draw_line(GLVertex *p1, GLVertex *p2) {
 	float dx, dy, dz, dw, x1, y1, z1, w1;
 	float tmin, tmax;
 	GLVertex q1, q2;
@@ -138,13 +138,13 @@ void GLContext::gl_draw_line(GLContext *c, GLVertex *p1, GLVertex *p2) {
 	cc2 = p2->clip_code;
 
 	if ((cc1 | cc2) == 0) {
-		if (c->render_mode == TGL_SELECT) {
-			gl_add_select1(c, p1->zp.z, p2->zp.z, p2->zp.z);
+		if (render_mode == TGL_SELECT) {
+			gl_add_select1(p1->zp.z, p2->zp.z, p2->zp.z);
 		} else {
-			if (c->depth_test)
-				c->fb->fillLineZ(&p1->zp, &p2->zp);
+			if (depth_test)
+				fb->fillLineZ(&p1->zp, &p2->zp);
 			else
-				c->fb->fillLine(&p1->zp, &p2->zp);
+				fb->fillLine(&p1->zp, &p2->zp);
 		}
 	} else if ((cc1 & cc2) != 0) {
 		return;
@@ -166,15 +166,15 @@ void GLContext::gl_draw_line(GLContext *c, GLVertex *p1, GLVertex *p2) {
 				ClipLine1(-dy + dw, y1 - w1, &tmin, &tmax) &&
 				ClipLine1(dz + dw, -z1 - w1, &tmin, &tmax) &&
 				ClipLine1(-dz + dw, z1 - w1, &tmin, &tmax)) {
-			interpolate(c, &q1, p1, p2, tmin);
-			interpolate(c, &q2, p1, p2, tmax);
-			gl_transform_to_viewport(c, &q1);
-			gl_transform_to_viewport(c, &q2);
+			interpolate(this, &q1, p1, p2, tmin);
+			interpolate(this, &q2, p1, p2, tmax);
+			gl_transform_to_viewport(&q1);
+			gl_transform_to_viewport(&q2);
 
-			if (c->depth_test)
-				c->fb->fillLineZ(&q1.zp, &q2.zp);
+			if (depth_test)
+				fb->fillLineZ(&q1.zp, &q2.zp);
 			else
-				c->fb->fillLine(&q1.zp, &q2.zp);
+				fb->fillLine(&q1.zp, &q2.zp);
 		}
 	}
 }
@@ -231,10 +231,10 @@ static inline void updateTmp(GLContext *c, GLVertex *q, GLVertex *p0, GLVertex *
 
 	q->clip_code = gl_clipcode(q->pc.X, q->pc.Y, q->pc.Z, q->pc.W);
 	if (q->clip_code == 0)
-		c->gl_transform_to_viewport(c, q);
+		c->gl_transform_to_viewport(q);
 }
 
-void GLContext::gl_draw_triangle(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2) {
+void GLContext::gl_draw_triangle(GLVertex *p0, GLVertex *p1, GLVertex *p2) {
 	int co, c_and, cc[3], front;
 	float norm;
 
@@ -252,39 +252,39 @@ void GLContext::gl_draw_triangle(GLContext *c, GLVertex *p0, GLVertex *p1, GLVer
 			return;
 
 		front = norm < 0.0;
-		front = front ^ c->current_front_face;
+		front = front ^ current_front_face;
 
 		// back face culling
-		if (c->cull_face_enabled) {
+		if (cull_face_enabled) {
 			// most used case first */
-			if (c->current_cull_face == TGL_BACK) {
+			if (current_cull_face == TGL_BACK) {
 				if (front == 0)
 					return;
-				c->draw_triangle_front(c, p0, p1, p2);
-			} else if (c->current_cull_face == TGL_FRONT) {
+				draw_triangle_front(this, p0, p1, p2);
+			} else if (current_cull_face == TGL_FRONT) {
 				if (front != 0)
 					return;
-				c->draw_triangle_back(c, p0, p1, p2);
+				draw_triangle_back(this, p0, p1, p2);
 			} else {
 				return;
 			}
 		} else {
 			// no culling
 			if (front) {
-				c->draw_triangle_front(c, p0, p1, p2);
+				draw_triangle_front(this, p0, p1, p2);
 			} else {
-				c->draw_triangle_back(c, p0, p1, p2);
+				draw_triangle_back(this, p0, p1, p2);
 			}
 		}
 	} else {
 		c_and = cc[0] & cc[1] & cc[2];
 		if (c_and == 0) {
-			gl_draw_triangle_clip(c, p0, p1, p2, 0);
+			gl_draw_triangle_clip(p0, p1, p2, 0);
 		}
 	}
 }
 
-void GLContext::gl_draw_triangle_clip(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2, int clip_bit) {
+void GLContext::gl_draw_triangle_clip(GLVertex *p0, GLVertex *p1, GLVertex *p2, int clip_bit) {
 	int co, c_and, co1, cc[3], edge_flag_tmp, clip_mask;
 	GLVertex tmp1, tmp2, *q[3];
 	float tt;
@@ -295,7 +295,7 @@ void GLContext::gl_draw_triangle_clip(GLContext *c, GLVertex *p0, GLVertex *p1,
 
 	co = cc[0] | cc[1] | cc[2];
 	if (co == 0) {
-		c->gl_draw_triangle(c, p0, p1, p2);
+		gl_draw_triangle(p0, p1, p2);
 	} else {
 		c_and = cc[0] & cc[1] & cc[2];
 		// the triangle is completely outside
@@ -332,20 +332,20 @@ void GLContext::gl_draw_triangle_clip(GLContext *c, GLVertex *p0, GLVertex *p1,
 			}
 
 			tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
-			updateTmp(c, &tmp1, q[0], q[1], tt);
+			updateTmp(this, &tmp1, q[0], q[1], tt);
 
 			tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
-			updateTmp(c, &tmp2, q[0], q[2], tt);
+			updateTmp(this, &tmp2, q[0], q[2], tt);
 
 			tmp1.edge_flag = q[0]->edge_flag;
 			edge_flag_tmp = q[2]->edge_flag;
 			q[2]->edge_flag = 0;
-			gl_draw_triangle_clip(c, &tmp1, q[1], q[2], clip_bit + 1);
+			gl_draw_triangle_clip(&tmp1, q[1], q[2], clip_bit + 1);
 
 			tmp2.edge_flag = 1;
 			tmp1.edge_flag = 0;
 			q[2]->edge_flag = edge_flag_tmp;
-			gl_draw_triangle_clip(c, &tmp2, &tmp1, q[2], clip_bit + 1);
+			gl_draw_triangle_clip(&tmp2, &tmp1, q[2], clip_bit + 1);
 		} else {
 			// two points outside
 			if ((cc[0] & clip_mask) == 0) {
@@ -357,20 +357,20 @@ void GLContext::gl_draw_triangle_clip(GLContext *c, GLVertex *p0, GLVertex *p1,
 			}
 
 			tt = clip_proc[clip_bit](&tmp1.pc, &q[0]->pc, &q[1]->pc);
-			updateTmp(c, &tmp1, q[0], q[1], tt);
+			updateTmp(this, &tmp1, q[0], q[1], tt);
 
 			tt = clip_proc[clip_bit](&tmp2.pc, &q[0]->pc, &q[2]->pc);
-			updateTmp(c, &tmp2, q[0], q[2], tt);
+			updateTmp(this, &tmp2, q[0], q[2], tt);
 
 			tmp1.edge_flag = 1;
 			tmp2.edge_flag = q[2]->edge_flag;
-			gl_draw_triangle_clip(c, q[0], &tmp1, &tmp2, clip_bit + 1);
+			gl_draw_triangle_clip(q[0], &tmp1, &tmp2, clip_bit + 1);
 		}
 	}
 }
 
 void GLContext::gl_draw_triangle_select(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2) {
-	c->gl_add_select1(c, p0->zp.z, p1->zp.z, p2->zp.z);
+	c->gl_add_select1(p0->zp.z, p1->zp.z, p2->zp.z);
 }
 
 #ifdef TINYGL_PROFILE
diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp
index c0d1203937..0cecd92ed6 100644
--- a/graphics/tinygl/init.cpp
+++ b/graphics/tinygl/init.cpp
@@ -34,19 +34,19 @@ namespace TinyGL {
 
 GLContext *gl_ctx;
 
-void GLContext::initSharedState(GLContext *c) {
-	GLSharedState *s = &c->shared_state;
+void GLContext::initSharedState() {
+	GLSharedState *s = &shared_state;
 	s->lists = (GLList **)gl_zalloc(sizeof(GLList *) * MAX_DISPLAY_LISTS);
 	s->texture_hash_table = (GLTexture **)gl_zalloc(sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE);
 
-	c->alloc_texture(c, 0);
+	alloc_texture(0);
 }
 
-void GLContext::endSharedState(GLContext *c) {
-	GLSharedState *s = &c->shared_state;
+void GLContext::endSharedState() {
+	GLSharedState *s = &shared_state;
 
 	uint h = 0;
-	c->free_texture(c, h);
+	free_texture(h);
 	for (int i = 0; i < MAX_DISPLAY_LISTS; i++) {
 		// TODO
 	}
@@ -63,9 +63,7 @@ void createContext(int screenW, int screenH, Graphics::PixelFormat pixelFormat,
 }
 
 void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat, int textureSize, bool dirtyRectsEnable) {
-	GLContext *c = gl_ctx;
 	GLViewport *v;
-	assert(c);
 
 	if ((textureSize & (textureSize - 1)))
 		error("glInit: texture size not power of two: %d", textureSize);
@@ -73,20 +71,20 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
 	if (textureSize <= 1 || textureSize > 4096)
 		error("glInit: texture size not allowed: %d", textureSize);
 
-	c->_enableDirtyRectangles = dirtyRectsEnable;
+	_enableDirtyRectangles = dirtyRectsEnable;
 
-	FrameBuffer *zbuffer = c->fb = new TinyGL::FrameBuffer(screenW, screenH, pixelFormat);
+	FrameBuffer *zbuffer = fb = new TinyGL::FrameBuffer(screenW, screenH, pixelFormat);
 
-	c->fb->_textureSize = c->_textureSize = textureSize;
-	c->fb->_textureSizeMask = (textureSize - 1) << ZB_POINT_ST_FRAC_BITS;
-	c->renderRect = Common::Rect(0, 0, zbuffer->xsize, zbuffer->ysize);
+	fb->_textureSize = _textureSize = textureSize;
+	fb->_textureSizeMask = (textureSize - 1) << ZB_POINT_ST_FRAC_BITS;
+	renderRect = Common::Rect(0, 0, zbuffer->xsize, zbuffer->ysize);
 
 	// allocate GLVertex array
-	c->vertex_max = POLYGON_MAX_VERTEX;
-	c->vertex = (GLVertex *)gl_malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));
+	vertex_max = POLYGON_MAX_VERTEX;
+	vertex = (GLVertex *)gl_malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));
 
 	// viewport
-	v = &c->viewport;
+	v = &viewport;
 	v->xmin = 0;
 	v->ymin = 0;
 	v->xsize = zbuffer->xsize;
@@ -94,19 +92,19 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
 	v->updated = 1;
 
 	// shared state
-	c->initSharedState(c);
+	initSharedState();
 
 	// lists
 
-	c->exec_flag = 1;
-	c->compile_flag = 0;
-	c->print_flag = 0;
+	exec_flag = 1;
+	compile_flag = 0;
+	print_flag = 0;
 
-	c->in_begin = 0;
+	in_begin = 0;
 
 	// lights
 	for (int i = 0; i < T_MAX_LIGHTS; i++) {
-		GLLight *l = &c->lights[i];
+		GLLight *l = &lights[i];
 		l->ambient = Vector4(0, 0, 0, 1);
 		if (i == 0) {
 			l->diffuse = Vector4(1, 1, 1, 1);
@@ -131,15 +129,15 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
 		l->next = NULL;
 		l->prev = NULL;
 	}
-	c->first_light = NULL;
-	c->ambient_light_model = Vector4(0.2f, 0.2f, 0.2f, 1);
-	c->local_light_model = 0;
-	c->lighting_enabled = 0;
-	c->light_model_two_side = 0;
+	first_light = NULL;
+	ambient_light_model = Vector4(0.2f, 0.2f, 0.2f, 1);
+	local_light_model = 0;
+	lighting_enabled = 0;
+	light_model_two_side = 0;
 
 	// default materials */
 	for (int i = 0; i < 2; i++) {
-		GLMaterial *m = &c->materials[i];
+		GLMaterial *m = &materials[i];
 		m->emission = Vector4(0, 0, 0, 1);
 		m->ambient = Vector4(0.2f, 0.2f, 0.2f, 1);
 		m->diffuse = Vector4(0.8f, 0.8f, 0.8f, 1);
@@ -147,55 +145,55 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
 		m->has_specular = false;
 		m->shininess = 0;
 	}
-	c->current_color_material_mode = TGL_FRONT_AND_BACK;
-	c->current_color_material_type = TGL_AMBIENT_AND_DIFFUSE;
-	c->color_material_enabled = 0;
+	current_color_material_mode = TGL_FRONT_AND_BACK;
+	current_color_material_type = TGL_AMBIENT_AND_DIFFUSE;
+	color_material_enabled = 0;
 
 	// textures
-	c->glInitTextures(c);
+	glInitTextures();
 
 	// default state
-	c->current_color = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
+	current_color = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
 
-	c->current_normal = Vector4(1.0f, 0.0f, 0.0f, 0.0f);
+	current_normal = Vector4(1.0f, 0.0f, 0.0f, 0.0f);
 
-	c->current_edge_flag = 1;
+	current_edge_flag = 1;
 
-	c->current_tex_coord = Vector4(0.0f, 0.0f, 0.0f, 1.0f);
+	current_tex_coord = Vector4(0.0f, 0.0f, 0.0f, 1.0f);
 
-	c->polygon_mode_front = TGL_FILL;
-	c->polygon_mode_back = TGL_FILL;
+	polygon_mode_front = TGL_FILL;
+	polygon_mode_back = TGL_FILL;
 
-	c->current_front_face = 0; // 0 = GL_CCW  1 = GL_CW
-	c->current_cull_face = TGL_BACK;
-	c->current_shade_model = TGL_SMOOTH;
-	c->cull_face_enabled = 0;
+	current_front_face = 0; // 0 = GL_CCW  1 = GL_CW
+	current_cull_face = TGL_BACK;
+	current_shade_model = TGL_SMOOTH;
+	cull_face_enabled = 0;
 
 	// clear
-	c->clear_color = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
-	c->clear_depth = 1.0f;
+	clear_color = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
+	clear_depth = 1.0f;
 
 	// selection
-	c->render_mode = TGL_RENDER;
-	c->select_buffer = NULL;
-	c->name_stack_size = 0;
+	render_mode = TGL_RENDER;
+	select_buffer = NULL;
+	name_stack_size = 0;
 
 	// blending
-	c->fb->enableBlending(false);
+	fb->enableBlending(false);
 
 	// alpha test
-	c->fb->enableAlphaTest(false);
+	fb->enableAlphaTest(false);
 
 	// matrix
-	c->matrix_mode = 0;
+	matrix_mode = 0;
 
-	c->matrix_stack_depth_max[0] = MAX_MODELVIEW_STACK_DEPTH;
-	c->matrix_stack_depth_max[1] = MAX_PROJECTION_STACK_DEPTH;
-	c->matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH;
+	matrix_stack_depth_max[0] = MAX_MODELVIEW_STACK_DEPTH;
+	matrix_stack_depth_max[1] = MAX_PROJECTION_STACK_DEPTH;
+	matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH;
 
 	for (int i = 0; i < 3; i++) {
-		c->matrix_stack[i] = (Matrix4 *)gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(Matrix4));
-		c->matrix_stack_ptr[i] = c->matrix_stack[i];
+		matrix_stack[i] = (Matrix4 *)gl_zalloc(matrix_stack_depth_max[i] * sizeof(Matrix4));
+		matrix_stack_ptr[i] = matrix_stack[i];
 	}
 
 	tglMatrixMode(TGL_PROJECTION);
@@ -211,38 +209,38 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
 
 	tglDepthFunc(TGL_LESS);
 
-	c->matrix_model_projection_updated = 1;
+	matrix_model_projection_updated = 1;
 
 	// opengl 1.1 arrays
-	c->client_states = 0;
+	client_states = 0;
 
 	// opengl 1.1 polygon offset
-	c->offset_states = 0;
-	c->offset_factor = 0.0f;
-	c->offset_units = 0.0f;
+	offset_states = 0;
+	offset_factor = 0.0f;
+	offset_units = 0.0f;
 
 	// shadow mode
-	c->shadow_mode = 0;
+	shadow_mode = 0;
 
 	// clear the resize callback function pointer
-	c->gl_resize_viewport = NULL;
+	gl_resize_viewport = NULL;
 
 	// specular buffer
-	c->specbuf_first = NULL;
-	c->specbuf_used_counter = 0;
-	c->specbuf_num_buffers = 0;
+	specbuf_first = NULL;
+	specbuf_used_counter = 0;
+	specbuf_num_buffers = 0;
 
 	// depth test
-	c->depth_test = 0;
+	depth_test = 0;
 
-	c->color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0);
+	color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0);
 
 	const int kDrawCallMemory = 5 * 1024 * 1024;
 
-	c->_currentAllocatorIndex = 0;
-	c->_drawCallAllocator[0].initialize(kDrawCallMemory);
-	c->_drawCallAllocator[1].initialize(kDrawCallMemory);
-	c->_enableDirtyRectangles = true;
+	_currentAllocatorIndex = 0;
+	_drawCallAllocator[0].initialize(kDrawCallMemory);
+	_drawCallAllocator[1].initialize(kDrawCallMemory);
+	_enableDirtyRectangles = true;
 
 	TinyGL::Internal::tglBlitResetScissorRect();
 }
@@ -256,16 +254,14 @@ void destroyContext() {
 }
 
 void GLContext::deinit() {
-	GLContext *c = gl_get_context();
-
-	c->disposeDrawCallLists(c);
-	c->disposeResources(c);
+	disposeDrawCallLists();
+	disposeResources();
 
-	c->specbuf_cleanup(c);
+	specbuf_cleanup();
 	for (int i = 0; i < 3; i++)
-		gl_free(c->matrix_stack[i]);
-	c->endSharedState(c);
-	gl_free(c->vertex);
+		gl_free(matrix_stack[i]);
+	endSharedState();
+	gl_free(vertex);
 }
 
 } // end of namespace TinyGL
diff --git a/graphics/tinygl/light.cpp b/graphics/tinygl/light.cpp
index fc9b552367..c18e89f92f 100644
--- a/graphics/tinygl/light.cpp
+++ b/graphics/tinygl/light.cpp
@@ -42,9 +42,9 @@ void GLContext::glopMaterial(GLContext *c, GLParam *p) {
 		mode = TGL_BACK;
 	}
 	if (mode == TGL_FRONT)
-		m = &c->materials[0];
+		m = &materials[0];
 	else
-		m = &c->materials[1];
+		m = &materials[1];
 
 	switch (type) {
 	case TGL_EMISSION:
@@ -77,8 +77,8 @@ void GLContext::glopColorMaterial(GLContext *c, GLParam *p) {
 	int mode = p[1].i;
 	int type = p[2].i;
 
-	c->current_color_material_mode = mode;
-	c->current_color_material_type = type;
+	current_color_material_mode = mode;
+	current_color_material_type = type;
 }
 
 void GLContext::glopLight(GLContext *c, GLParam *p) {
@@ -89,7 +89,7 @@ void GLContext::glopLight(GLContext *c, GLParam *p) {
 
 	assert(light >= TGL_LIGHT0 && light < TGL_LIGHT0 + T_MAX_LIGHTS);
 
-	l = &c->lights[light - TGL_LIGHT0];
+	l = &lights[light - TGL_LIGHT0];
 
 	switch (type) {
 	case TGL_AMBIENT:
@@ -120,7 +120,7 @@ void GLContext::glopLight(GLContext *c, GLParam *p) {
 		l->spot_direction.X = v.X;
 		l->spot_direction.Y = v.Y;
 		l->spot_direction.Z = v.Z;
-		c->matrix_stack_ptr[0]->transform3x3(l->spot_direction, l->norm_spot_direction);
+		matrix_stack_ptr[0]->transform3x3(l->spot_direction, l->norm_spot_direction);
 		l->norm_spot_direction.normalize();
 		break;
 	case TGL_SPOT_EXPONENT:
@@ -153,13 +153,13 @@ void GLContext::glopLightModel(GLContext *c, GLParam *p) {
 
 	switch (pname) {
 	case TGL_LIGHT_MODEL_AMBIENT:
-		c->ambient_light_model = Vector4(p[2].f, p[3].f, p[4].f, p[5].f);
+		ambient_light_model = Vector4(p[2].f, p[3].f, p[4].f, p[5].f);
 		break;
 	case TGL_LIGHT_MODEL_LOCAL_VIEWER:
-		c->local_light_model = (int)p[2].f;
+		local_light_model = (int)p[2].f;
 		break;
 	case TGL_LIGHT_MODEL_TWO_SIDE:
-		c->light_model_two_side = (int)p[2].f;
+		light_model_two_side = (int)p[2].f;
 		break;
 	default:
 		warning("glopLightModel: illegal pname: 0x%x", pname);
@@ -176,21 +176,21 @@ static inline float clampf(float a, float min, float max) {
 		return a;
 }
 
-void GLContext::gl_enable_disable_light(GLContext *c, int light, int v) {
-	GLLight *l = &c->lights[light];
+void GLContext::gl_enable_disable_light(int light, int v) {
+	GLLight *l = &lights[light];
 	if (v && !l->enabled) {
 		l->enabled = 1;
-		if (c->first_light != l) {
-			l->next = c->first_light;
-			if (c->first_light)
-				c->first_light->prev = l;
-			c->first_light = l;
+		if (first_light != l) {
+			l->next = first_light;
+			if (first_light)
+				first_light->prev = l;
+			first_light = l;
 			l->prev = NULL;
 		}
 	} else if (!v && l->enabled) {
 		l->enabled = 0;
 		if (!l->prev)
-			c->first_light = l->next;
+			first_light = l->next;
 		else
 			l->prev->next = l->next;
 		if (l->next)
@@ -199,24 +199,24 @@ void GLContext::gl_enable_disable_light(GLContext *c, int light, int v) {
 }
 
 // non optimized lightening model
-void GLContext::gl_shade_vertex(GLContext *c, GLVertex *v) {
+void GLContext::gl_shade_vertex(GLVertex *v) {
 	float R, G, B, A;
 	GLMaterial *m;
 	GLLight *l;
 	Vector3 n, s, d;
 	float dist, tmp, att, dot, dot_spot, dot_spec;
-	int twoside = c->light_model_two_side;
+	int twoside = light_model_two_side;
 
-	m = &c->materials[0];
+	m = &materials[0];
 
 	n = v->normal;
 
-	R = m->emission.X + m->ambient.X * c->ambient_light_model.X;
-	G = m->emission.Y + m->ambient.Y * c->ambient_light_model.Y;
-	B = m->emission.Z + m->ambient.Z * c->ambient_light_model.Z;
+	R = m->emission.X + m->ambient.X * ambient_light_model.X;
+	G = m->emission.Y + m->ambient.Y * ambient_light_model.Y;
+	B = m->emission.Z + m->ambient.Z * ambient_light_model.Z;
 	A = clampf(m->diffuse.W, 0, 1);
 
-	for (l = c->first_light; l != NULL; l = l->next) {
+	for (l = first_light; l != NULL; l = l->next) {
 		float lR, lB, lG;
 
 		// ambient
@@ -273,7 +273,7 @@ void GLContext::gl_shade_vertex(GLContext *c, GLVertex *v) {
 				}
 
 				if (has_specular) {
-					if (c->local_light_model) {
+					if (local_light_model) {
 						Vector3 vcoord;
 						vcoord.X = v->ec.X;
 						vcoord.Y = v->ec.Y;
@@ -297,7 +297,7 @@ void GLContext::gl_shade_vertex(GLContext *c, GLVertex *v) {
 						// TODO: optimize
 						// testing specular buffer code
 						// dot_spec= pow(dot_spec,m->shininess)
-						specbuf = c->specbuf_get_buffer(c, m->shininess_i, m->shininess);
+						specbuf = specbuf_get_buffer(m->shininess_i, m->shininess);
 						tmp = dot_spec * SPECULAR_BUFFER_SIZE;
 						if (tmp > SPECULAR_BUFFER_SIZE)
 							idx = SPECULAR_BUFFER_SIZE;
@@ -318,10 +318,10 @@ void GLContext::gl_shade_vertex(GLContext *c, GLVertex *v) {
 		B += att * lB;
 	}
 
-	v->color.X = clampf(c->current_color.X * R, 0, 1);
-	v->color.Y = clampf(c->current_color.Y * G, 0, 1);
-	v->color.Z = clampf(c->current_color.Z * B, 0, 1);
-	v->color.W = c->current_color.W * A;
+	v->color.X = clampf(current_color.X * R, 0, 1);
+	v->color.Y = clampf(current_color.Y * G, 0, 1);
+	v->color.Z = clampf(current_color.Z * B, 0, 1);
+	v->color.W = current_color.W * A;
 }
 
 } // end of namespace TinyGL
diff --git a/graphics/tinygl/list.cpp b/graphics/tinygl/list.cpp
index 317270a06a..3b698578b7 100644
--- a/graphics/tinygl/list.cpp
+++ b/graphics/tinygl/list.cpp
@@ -127,15 +127,15 @@ static void gl_print_op(FILE *f, GLParam *p) {
 	fprintf(f, "\n");
 }
 
-static void gl_compile_op(GLContext *c, GLParam *p) {
+void GLContext::gl_compile_op(GLParam *p) {
 	int op, op_size;
 	GLParamBuffer *ob, *ob1;
 	int index;
 
 	op = p[0].op;
 	op_size = op_table_size[op];
-	index = c->current_op_buffer_index;
-	ob = c->current_op_buffer;
+	index = current_op_buffer_index;
+	ob = current_op_buffer;
 
 	// we should be able to add a NextBuffer opcode
 	if ((index + op_size) > (OP_BUFFER_MAX_SIZE - 2)) {
@@ -147,7 +147,7 @@ static void gl_compile_op(GLContext *c, GLParam *p) {
 		ob->ops[index].op = OP_NextBuffer;
 		ob->ops[index + 1].p = (void *)ob1;
 
-		c->current_op_buffer = ob1;
+		current_op_buffer = ob1;
 		ob = ob1;
 		index = 0;
 	}
@@ -156,7 +156,7 @@ static void gl_compile_op(GLContext *c, GLParam *p) {
 		ob->ops[index] = p[i];
 		index++;
 	}
-	c->current_op_buffer_index = index;
+	current_op_buffer_index = index;
 }
 
 void GLContext::gl_add_op(GLParam *p) {
@@ -164,13 +164,13 @@ void GLContext::gl_add_op(GLParam *p) {
 	int op;
 
 	op = p[0].op;
-	if (c->exec_flag) {
+	if (exec_flag) {
 		op_table_func[op](c, p);
 	}
-	if (c->compile_flag) {
-		gl_compile_op(c, p);
+	if (compile_flag) {
+		gl_compile_op(p);
 	}
-	if (c->print_flag) {
+	if (print_flag) {
 		gl_print_op(stderr, p);
 	}
 }
@@ -235,7 +235,7 @@ void tglEndList() {
 
 	// end of list
 	p[0].op = OP_EndList;
-	gl_compile_op(c, p);
+	c->gl_compile_op(p);
 
 	c->compile_flag = 0;
 	c->exec_flag = 1;
diff --git a/graphics/tinygl/matrix.cpp b/graphics/tinygl/matrix.cpp
index 1c3c773676..4cfdedd124 100644
--- a/graphics/tinygl/matrix.cpp
+++ b/graphics/tinygl/matrix.cpp
@@ -47,13 +47,13 @@ void GLContext::glopMatrixMode(GLContext *c, GLParam *p) {
 	int mode = p[1].i;
 	switch (mode) {
 	case TGL_MODELVIEW:
-		c->matrix_mode = 0;
+		matrix_mode = 0;
 		break;
 	case TGL_PROJECTION:
-		c->matrix_mode = 1;
+		matrix_mode = 1;
 		break;
 	case TGL_TEXTURE:
-		c->matrix_mode = 2;
+		matrix_mode = 2;
 		break;
 	default:
 		assert(0);
@@ -64,7 +64,7 @@ void GLContext::glopLoadMatrix(GLContext *c, GLParam *p) {
 	Matrix4 *m;
 	GLParam *q;
 
-	m = c->matrix_stack_ptr[c->matrix_mode];
+	m = matrix_stack_ptr[c->matrix_mode];
 	q = p + 1;
 
 	for (int i = 0; i < 4; i++) {
@@ -79,7 +79,7 @@ void GLContext::glopLoadMatrix(GLContext *c, GLParam *p) {
 }
 
 void GLContext::glopLoadIdentity(GLContext *c, GLParam *) {
-	c->matrix_stack_ptr[c->matrix_mode]->identity();
+	matrix_stack_ptr[matrix_mode]->identity();
 	gl_matrix_update(c);
 }
 
@@ -96,19 +96,19 @@ void GLContext::glopMultMatrix(GLContext *c, GLParam *p) {
 		q += 4;
 	}
 
-	*c->matrix_stack_ptr[c->matrix_mode] *= m;
+	*matrix_stack_ptr[matrix_mode] *= m;
 
 	gl_matrix_update(c);
 }
 
 
 void GLContext::glopPushMatrix(GLContext *c, GLParam *) {
-	int n = c->matrix_mode;
+	int n = matrix_mode;
 	Matrix4 *m;
 
-	assert((c->matrix_stack_ptr[n] - c->matrix_stack[n] + 1) < c->matrix_stack_depth_max[n]);
+	assert((matrix_stack_ptr[n] - matrix_stack[n] + 1) < matrix_stack_depth_max[n]);
 
-	m = ++c->matrix_stack_ptr[n];
+	m = ++matrix_stack_ptr[n];
 
 	m[0] = m[-1];
 
@@ -116,10 +116,10 @@ void GLContext::glopPushMatrix(GLContext *c, GLParam *) {
 }
 
 void GLContext::glopPopMatrix(GLContext *c, GLParam *) {
-	int n = c->matrix_mode;
+	int n = matrix_mode;
 
-	assert(c->matrix_stack_ptr[n] > c->matrix_stack[n]);
-	c->matrix_stack_ptr[n]--;
+	assert(matrix_stack_ptr[n] > matrix_stack[n]);
+	matrix_stack_ptr[n]--;
 	gl_matrix_update(c);
 }
 
@@ -190,18 +190,18 @@ void GLContext::glopRotate(GLContext *c, GLParam *p) {
 	}
 	}
 
-	*c->matrix_stack_ptr[c->matrix_mode] *= m;
+	*matrix_stack_ptr[matrix_mode] *= m;
 
 	gl_matrix_update(c);
 }
 
 void GLContext::glopScale(GLContext *c, GLParam *p) {
-	c->matrix_stack_ptr[c->matrix_mode]->scale(p[1].f, p[2].f, p[3].f);
+	matrix_stack_ptr[matrix_mode]->scale(p[1].f, p[2].f, p[3].f);
 	gl_matrix_update(c);
 }
 
 void GLContext::glopTranslate(GLContext *c, GLParam *p) {
-	c->matrix_stack_ptr[c->matrix_mode]->translate(p[1].f, p[2].f, p[3].f);
+	matrix_stack_ptr[matrix_mode]->translate(p[1].f, p[2].f, p[3].f);
 	gl_matrix_update(c);
 }
 
@@ -214,7 +214,7 @@ void GLContext::glopFrustum(GLContext *c, GLParam *p) {
 	float farp = p[6].f;
 	Matrix4 m = Matrix4::frustum(left, right, bottom, top, nearp, farp);
 
-	*c->matrix_stack_ptr[c->matrix_mode] *= m;
+	*matrix_stack_ptr[matrix_mode] *= m;
 
 	gl_matrix_update(c);
 }
diff --git a/graphics/tinygl/misc.cpp b/graphics/tinygl/misc.cpp
index 581a85eaa1..615fe0b243 100644
--- a/graphics/tinygl/misc.cpp
+++ b/graphics/tinygl/misc.cpp
@@ -40,13 +40,13 @@ void GLContext::glopViewport(GLContext *c, GLParam *p) {
 
 	// we may need to resize the zbuffer
 
-	if (c->viewport.xmin != xmin || c->viewport.ymin != ymin ||
-			c->viewport.xsize != xsize || c->viewport.ysize != ysize) {
+	if (viewport.xmin != xmin || viewport.ymin != ymin ||
+			viewport.xsize != xsize || viewport.ysize != ysize) {
 
 		xsize_req = xmin + xsize;
 		ysize_req = ymin + ysize;
 
-		if (c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
+		if (gl_resize_viewport && gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
 			error("glViewport: error while resizing display");
 		}
 
@@ -56,12 +56,12 @@ void GLContext::glopViewport(GLContext *c, GLParam *p) {
 			error("glViewport: size too small");
 		}
 
-		c->viewport.xmin = xmin;
-		c->viewport.ymin = ymin;
-		c->viewport.xsize = xsize;
-		c->viewport.ysize = ysize;
+		viewport.xmin = xmin;
+		viewport.ymin = ymin;
+		viewport.xsize = xsize;
+		viewport.ysize = ysize;
 
-		c->viewport.updated = 1;
+		viewport.updated = 1;
 	}
 }
 
@@ -71,63 +71,63 @@ void GLContext::glopEnableDisable(GLContext *c, GLParam *p) {
 
 	switch (code) {
 	case TGL_CULL_FACE:
-		c->cull_face_enabled = v;
+		cull_face_enabled = v;
 		break;
 	case TGL_LIGHTING:
-		c->lighting_enabled = v;
+		lighting_enabled = v;
 		break;
 	case TGL_COLOR_MATERIAL:
-		c->color_material_enabled = v;
+		color_material_enabled = v;
 		break;
 	case TGL_TEXTURE_2D:
-		c->texture_2d_enabled = v;
+		texture_2d_enabled = v;
 		break;
 	case TGL_NORMALIZE:
-		c->normalize_enabled = v;
+		normalize_enabled = v;
 		break;
 	case TGL_DEPTH_TEST:
-		c->depth_test = v;
-		c->fb->enableDepthTest(v);
+		depth_test = v;
+		fb->enableDepthTest(v);
 		break;
 	case TGL_ALPHA_TEST:
-		c->fb->enableAlphaTest(v);
+		fb->enableAlphaTest(v);
 		break;
 	case TGL_BLEND:
-		c->fb->enableBlending(v);
+		fb->enableBlending(v);
 		break;
 	case TGL_POLYGON_OFFSET_FILL:
 		if (v)
-			c->offset_states |= TGL_OFFSET_FILL;
+			offset_states |= TGL_OFFSET_FILL;
 		else
-			c->offset_states &= ~TGL_OFFSET_FILL;
+			offset_states &= ~TGL_OFFSET_FILL;
 		break;
 	case TGL_POLYGON_OFFSET_POINT:
 		if (v)
-			c->offset_states |= TGL_OFFSET_POINT;
+			offset_states |= TGL_OFFSET_POINT;
 		else
-			c->offset_states &= ~TGL_OFFSET_POINT;
+			offset_states &= ~TGL_OFFSET_POINT;
 		break;
 	case TGL_POLYGON_OFFSET_LINE:
 		if (v)
-			c->offset_states |= TGL_OFFSET_LINE;
+			offset_states |= TGL_OFFSET_LINE;
 		else
-			c->offset_states &= ~TGL_OFFSET_LINE;
+			offset_states &= ~TGL_OFFSET_LINE;
 		break;
 	case TGL_SHADOW_MASK_MODE:
 		if (v)
-			c->shadow_mode |= 1;
+			shadow_mode |= 1;
 		else
-			c->shadow_mode &= ~1;
+			shadow_mode &= ~1;
 		break;
 	case TGL_SHADOW_MODE:
 		if (v)
-			c->shadow_mode |= 2;
+			shadow_mode |= 2;
 		else
-			c->shadow_mode &= ~2;
+			shadow_mode &= ~2;
 		break;
 	default:
 		if (code >= TGL_LIGHT0 && code < TGL_LIGHT0 + T_MAX_LIGHTS) {
-			c->gl_enable_disable_light(c, code - TGL_LIGHT0, v);
+			gl_enable_disable_light(code - TGL_LIGHT0, v);
 		} else {
 			//warning("glEnableDisable: 0x%X not supported.", code);
 		}
@@ -138,33 +138,33 @@ void GLContext::glopEnableDisable(GLContext *c, GLParam *p) {
 void GLContext::glopBlendFunc(GLContext *c, GLParam *p) {
 	TGLenum sfactor = p[1].i;
 	TGLenum dfactor = p[2].i;
-	c->fb->setBlendingFactors(sfactor, dfactor);
+	fb->setBlendingFactors(sfactor, dfactor);
 }
 
 void GLContext::glopAlphaFunc(GLContext *c, GLParam *p) {
 	TGLenum func = p[1].i;
 	float ref = p[2].f;
-	c->fb->setAlphaTestFunc(func, (int)(ref * 255));
+	fb->setAlphaTestFunc(func, (int)(ref * 255));
 }
 
 void GLContext::glopDepthFunc(GLContext *c, GLParam *p) {
 	TGLenum func = p[1].i;
-	c->fb->setDepthFunc(func);
+	fb->setDepthFunc(func);
 }
 
 void GLContext::glopShadeModel(GLContext *c, GLParam *p) {
 	int code = p[1].i;
-	c->current_shade_model = code;
+	current_shade_model = code;
 }
 
 void GLContext::glopCullFace(GLContext *c, GLParam *p) {
 	int code = p[1].i;
-	c->current_cull_face = code;
+	current_cull_face = code;
 }
 
 void GLContext::glopFrontFace(GLContext *c, GLParam *p) {
 	int code = p[1].i;
-	c->current_front_face = code;
+	current_front_face = code;
 }
 
 void GLContext::glopPolygonMode(GLContext *c, GLParam *p) {
@@ -173,14 +173,14 @@ void GLContext::glopPolygonMode(GLContext *c, GLParam *p) {
 
 	switch (face) {
 	case TGL_BACK:
-		c->polygon_mode_back = mode;
+		polygon_mode_back = mode;
 		break;
 	case TGL_FRONT:
-		c->polygon_mode_front = mode;
+		polygon_mode_front = mode;
 		break;
 	case TGL_FRONT_AND_BACK:
-		c->polygon_mode_front = mode;
-		c->polygon_mode_back = mode;
+		polygon_mode_front = mode;
+		polygon_mode_back = mode;
 		break;
 	default:
 		assert(0);
@@ -192,16 +192,16 @@ void GLContext::glopHint(GLContext *, GLParam *) {
 }
 
 void GLContext::glopPolygonOffset(GLContext *c, GLParam *p) {
-	c->offset_factor = p[1].f;
-	c->offset_units = p[2].f;
+	offset_factor = p[1].f;
+	offset_units = p[2].f;
 }
 
 void GLContext::glopColorMask(GLContext *c, TinyGL::GLParam *p) {
-	c->color_mask = p[1].i;
+	color_mask = p[1].i;
 }
 
 void GLContext::glopDepthMask(GLContext *c, TinyGL::GLParam *p) {
-	c->fb->enableDepthWrite(p[1].i);
+	fb->enableDepthWrite(p[1].i);
 }
 
 } // end of namespace TinyGL
diff --git a/graphics/tinygl/select.cpp b/graphics/tinygl/select.cpp
index ccf769d109..19898497c9 100644
--- a/graphics/tinygl/select.cpp
+++ b/graphics/tinygl/select.cpp
@@ -78,61 +78,61 @@ void tglSelectBuffer(int size, unsigned int *buf) {
 }
 
 void GLContext::glopInitNames(GLContext *c, GLParam *) {
-	if (c->render_mode == TGL_SELECT) {
-		c->name_stack_size = 0;
-		c->select_hit = NULL;
+	if (render_mode == TGL_SELECT) {
+		name_stack_size = 0;
+		select_hit = NULL;
 	}
 }
 
 void GLContext::glopPushName(GLContext *c, GLParam *p) {
 	if (c->render_mode == TGL_SELECT) {
 		assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
-		c->name_stack[c->name_stack_size++] = p[1].i;
-		c->select_hit = NULL;
+		name_stack[c->name_stack_size++] = p[1].i;
+		select_hit = NULL;
 	}
 }
 
 void GLContext::glopPopName(GLContext *c, GLParam *) {
-	if (c->render_mode == TGL_SELECT) {
-		assert(c->name_stack_size > 0);
-		c->name_stack_size--;
-		c->select_hit = NULL;
+	if (render_mode == TGL_SELECT) {
+		assert(name_stack_size > 0);
+		name_stack_size--;
+		select_hit = NULL;
 	}
 }
 
 void GLContext::glopLoadName(GLContext *c, GLParam *p) {
-	if (c->render_mode == TGL_SELECT) {
-		assert(c->name_stack_size > 0);
-		c->name_stack[c->name_stack_size - 1] = p[1].i;
-		c->select_hit = NULL;
+	if (render_mode == TGL_SELECT) {
+		assert(name_stack_size > 0);
+		name_stack[name_stack_size - 1] = p[1].i;
+		select_hit = NULL;
 	}
 }
 
-void GLContext::gl_add_select(GLContext *c, unsigned int zmin, unsigned int zmax) {
+void GLContext::gl_add_select(unsigned int zmin, unsigned int zmax) {
 	unsigned int *ptr;
 	int n;
 
-	if (!c->select_overflow) {
-		if (!c->select_hit) {
-			n = c->name_stack_size;
-			if ((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) {
-				c->select_overflow = 1;
+	if (!select_overflow) {
+		if (!select_hit) {
+			n = name_stack_size;
+			if ((select_ptr - select_buffer + 3 + n) > select_size) {
+				select_overflow = 1;
 			} else {
-				ptr = c->select_ptr;
-				c->select_hit = ptr;
-				*ptr++ = c->name_stack_size;
+				ptr = select_ptr;
+				select_hit = ptr;
+				*ptr++ = name_stack_size;
 				*ptr++ = zmin;
 				*ptr++ = zmax;
 				for (int i = 0; i < n; i++)
-					*ptr++ = c->name_stack[i];
-				c->select_ptr = ptr;
-				c->select_hits++;
+					*ptr++ = name_stack[i];
+				select_ptr = ptr;
+				select_hits++;
 			}
 		} else {
-			if (zmin < c->select_hit[1])
-				c->select_hit[1] = zmin;
-			if (zmax > c->select_hit[2])
-				c->select_hit[2] = zmax;
+			if (zmin < select_hit[1])
+				select_hit[1] = zmin;
+			if (zmax > select_hit[2])
+				select_hit[2] = zmax;
 		}
 	}
 }
diff --git a/graphics/tinygl/specbuf.cpp b/graphics/tinygl/specbuf.cpp
index 3c52cd6a2e..5e52da86f7 100644
--- a/graphics/tinygl/specbuf.cpp
+++ b/graphics/tinygl/specbuf.cpp
@@ -40,9 +40,9 @@ static void calc_buf(GLSpecBuf *buf, const float shininess) {
 	}
 }
 
-GLSpecBuf *GLContext::specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess) {
+GLSpecBuf *GLContext::specbuf_get_buffer(const int shininess_i, const float shininess) {
 	GLSpecBuf *found, *oldest;
-	found = oldest = c->specbuf_first;
+	found = oldest = specbuf_first;
 	while (found && found->shininess_i != shininess_i) {
 		if (found->last_used < oldest->last_used) {
 			oldest = found;
@@ -50,33 +50,33 @@ GLSpecBuf *GLContext::specbuf_get_buffer(GLContext *c, const int shininess_i, co
 		found = found->next;
 	}
 	if (found) {
-		found->last_used = c->specbuf_used_counter++;
+		found->last_used = specbuf_used_counter++;
 		return found;
 	}
-	if (!oldest || c->specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
+	if (!oldest || specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
 		// create new buffer
 		GLSpecBuf *buf = (GLSpecBuf *)gl_malloc(sizeof(GLSpecBuf));
 		if (!buf)
 			error("could not allocate specular buffer");
-		c->specbuf_num_buffers++;
-		buf->next = c->specbuf_first;
-		c->specbuf_first = buf;
-		buf->last_used = c->specbuf_used_counter++;
+		specbuf_num_buffers++;
+		buf->next = specbuf_first;
+		specbuf_first = buf;
+		buf->last_used = specbuf_used_counter++;
 		buf->shininess_i = shininess_i;
 		calc_buf(buf, shininess);
 		return buf;
 	}
 	//overwrite the lru buffer
 	oldest->shininess_i = shininess_i;
-	oldest->last_used = c->specbuf_used_counter++;
+	oldest->last_used = specbuf_used_counter++;
 	calc_buf(oldest, shininess);
 	return oldest;
 }
 
-void GLContext::specbuf_cleanup(GLContext *c) {
+void GLContext::specbuf_cleanup() {
 	GLSpecBuf *buf, *next;
-	buf = c->specbuf_first;
-	for (int i = 0; i < c->specbuf_num_buffers; ++i) {
+	buf = specbuf_first;
+	for (int i = 0; i < specbuf_num_buffers; ++i) {
 		next = buf->next;
 		gl_free(buf);
 		buf = next;
diff --git a/graphics/tinygl/texture.cpp b/graphics/tinygl/texture.cpp
index 8f8afe978f..fcf9b04269 100644
--- a/graphics/tinygl/texture.cpp
+++ b/graphics/tinygl/texture.cpp
@@ -46,16 +46,16 @@ static GLTexture *find_texture(GLContext *c, uint h) {
 	return nullptr;
 }
 
-void GLContext::free_texture(GLContext *c, uint h) {
-	free_texture(c, find_texture(c, h));
+void GLContext::free_texture(uint h) {
+	free_texture(find_texture(this, h));
 }
 
-void GLContext::free_texture(GLContext *c, GLTexture *t) {
+void GLContext::free_texture(GLTexture *t) {
 	GLTexture **ht;
 	GLImage *im;
 
 	if (!t->prev) {
-		ht = &c->shared_state.texture_hash_table[t->handle % TEXTURE_HASH_TABLE_SIZE];
+		ht = &shared_state.texture_hash_table[t->handle % TEXTURE_HASH_TABLE_SIZE];
 		*ht = t->next;
 	} else {
 		t->prev->next = t->next;
@@ -74,12 +74,12 @@ void GLContext::free_texture(GLContext *c, GLTexture *t) {
 	gl_free(t);
 }
 
-GLTexture *GLContext::alloc_texture(GLContext *c, uint h) {
+GLTexture *GLContext::alloc_texture(uint h) {
 	GLTexture *t, **ht;
 
 	t = (GLTexture *)gl_zalloc(sizeof(GLTexture));
 
-	ht = &c->shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
+	ht = &shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE];
 
 	t->next = *ht;
 	t->prev = nullptr;
@@ -94,22 +94,22 @@ GLTexture *GLContext::alloc_texture(GLContext *c, uint h) {
 	return t;
 }
 
-void GLContext::glInitTextures(GLContext *c) {
-	c->texture_2d_enabled = 0;
-	c->current_texture = find_texture(c, 0);
-	c->maxTextureName = 0;
-	c->texture_mag_filter = TGL_LINEAR;
-	c->texture_min_filter = TGL_NEAREST_MIPMAP_LINEAR;
+void GLContext::glInitTextures() {
+	texture_2d_enabled = 0;
+	current_texture = find_texture(this, 0);
+	maxTextureName = 0;
+	texture_mag_filter = TGL_LINEAR;
+	texture_min_filter = TGL_NEAREST_MIPMAP_LINEAR;
 #if defined(SCUMM_LITTLE_ENDIAN)
-	c->colorAssociationList.push_back({Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), TGL_RGBA, TGL_UNSIGNED_BYTE});
-	c->colorAssociationList.push_back({Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),  TGL_RGB,  TGL_UNSIGNED_BYTE});
+	colorAssociationList.push_back({Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), TGL_RGBA, TGL_UNSIGNED_BYTE});
+	colorAssociationList.push_back({Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),  TGL_RGB,  TGL_UNSIGNED_BYTE});
 #else
-	c->colorAssociationList.push_back({Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), TGL_RGBA, TGL_UNSIGNED_BYTE});
-	c->colorAssociationList.push_back({Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),  TGL_RGB,  TGL_UNSIGNED_BYTE});
+	colorAssociationList.push_back({Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), TGL_RGBA, TGL_UNSIGNED_BYTE});
+	colorAssociationList.push_back({Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),  TGL_RGB,  TGL_UNSIGNED_BYTE});
 #endif
-	c->colorAssociationList.push_back({Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),  TGL_RGB,  TGL_UNSIGNED_SHORT_5_6_5});
-	c->colorAssociationList.push_back({Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0),  TGL_RGBA, TGL_UNSIGNED_SHORT_5_5_5_1});
-	c->colorAssociationList.push_back({Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),  TGL_RGBA, TGL_UNSIGNED_SHORT_4_4_4_4});
+	colorAssociationList.push_back({Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),  TGL_RGB,  TGL_UNSIGNED_SHORT_5_6_5});
+	colorAssociationList.push_back({Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0),  TGL_RGBA, TGL_UNSIGNED_SHORT_5_5_5_1});
+	colorAssociationList.push_back({Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),  TGL_RGBA, TGL_UNSIGNED_SHORT_4_4_4_4});
 }
 
 void GLContext::glopBindTexture(GLContext *c, GLParam *p) {
@@ -121,9 +121,9 @@ void GLContext::glopBindTexture(GLContext *c, GLParam *p) {
 
 	t = find_texture(c, texture);
 	if (!t) {
-		t = alloc_texture(c, texture);
+		t = alloc_texture(texture);
 	}
-	c->current_texture = t;
+	current_texture = t;
 }
 
 void GLContext::glopTexImage2D(GLContext *c, GLParam *p) {
@@ -147,13 +147,13 @@ void GLContext::glopTexImage2D(GLContext *c, GLParam *p) {
 	if (border != 0)
 		error("tglTexImage2D: invalid border");
 
-	if (c->current_texture == nullptr) {
+	if (current_texture == nullptr) {
 		return;
 	}
-	c->current_texture->versionNumber++;
-	im = &c->current_texture->images[level];
-	im->xsize = c->_textureSize;
-	im->ysize = c->_textureSize;
+	current_texture->versionNumber++;
+	im = &current_texture->images[level];
+	im->xsize = _textureSize;
+	im->ysize = _textureSize;
 	if (im->pixmap) {
 		delete im->pixmap;
 		im->pixmap = nullptr;
@@ -162,8 +162,8 @@ void GLContext::glopTexImage2D(GLContext *c, GLParam *p) {
 		unsigned int filter;
 		Graphics::PixelFormat pf;
 		bool found = false;
-		Common::Array<struct tglColorAssociation>::const_iterator it = c->colorAssociationList.begin();
-		for (; it != c->colorAssociationList.end(); it++) {
+		Common::Array<struct tglColorAssociation>::const_iterator it = colorAssociationList.begin();
+		for (; it != colorAssociationList.end(); it++) {
 			if (it->format == format &&
 			    it->type == type) {
 				pf = it->pf;
@@ -188,10 +188,10 @@ void GLContext::glopTexImage2D(GLContext *c, GLParam *p) {
 #endif
 		Graphics::PixelBuffer srcInternal(internalPf, width * height, DisposeAfterUse::YES);
 		srcInternal.copyBuffer(0, width * height, src);
-		if (width > c->_textureSize || height > c->_textureSize)
-			filter = c->texture_mag_filter;
+		if (width > _textureSize || height > _textureSize)
+			filter = texture_mag_filter;
 		else
-			filter = c->texture_min_filter;
+			filter = texture_min_filter;
 		switch (filter) {
 		case TGL_LINEAR_MIPMAP_NEAREST:
 		case TGL_LINEAR_MIPMAP_LINEAR:
@@ -199,14 +199,14 @@ void GLContext::glopTexImage2D(GLContext *c, GLParam *p) {
 			im->pixmap = new Graphics::BilinearTexelBuffer(
 				srcInternal,
 				width, height,
-				c->_textureSize
+				_textureSize
 			);
 			break;
 		default:
 			im->pixmap = new Graphics::NearestTexelBuffer(
 				srcInternal,
 				width, height,
-				c->_textureSize
+				_textureSize
 			);
 			break;
 		}
@@ -244,16 +244,16 @@ error:
 
 	switch (pname) {
 	case TGL_TEXTURE_WRAP_S:
-		c->texture_wrap_s = param;
+		texture_wrap_s = param;
 		break;
 	case TGL_TEXTURE_WRAP_T:
-		c->texture_wrap_t = param;
+		texture_wrap_t = param;
 		break;
 	case TGL_TEXTURE_MAG_FILTER:
 		switch (param) {
 		case TGL_NEAREST:
 		case TGL_LINEAR:
-			c->texture_mag_filter = param;
+			texture_mag_filter = param;
 			break;
 		default:
 			goto error;
@@ -267,7 +267,7 @@ error:
 		case TGL_NEAREST_MIPMAP_LINEAR:
 		case TGL_NEAREST:
 		case TGL_LINEAR:
-			c->texture_min_filter = param;
+			texture_min_filter = param;
 			break;
 		default:
 			goto error;
diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp
index 38f049a9cd..eecc6f977d 100644
--- a/graphics/tinygl/vertex.cpp
+++ b/graphics/tinygl/vertex.cpp
@@ -32,39 +32,39 @@
 namespace TinyGL {
 
 void GLContext::glopNormal(GLContext *c, GLParam *p) {
-	c->current_normal.X = p[1].f;
-	c->current_normal.Y = p[2].f;
-	c->current_normal.Z = p[3].f;
-	c->current_normal.W = 0.0f;
+	current_normal.X = p[1].f;
+	current_normal.Y = p[2].f;
+	current_normal.Z = p[3].f;
+	current_normal.W = 0.0f;
 }
 
 void GLContext::glopTexCoord(GLContext *c, GLParam *p) {
-	c->current_tex_coord.X = p[1].f;
-	c->current_tex_coord.Y = p[2].f;
-	c->current_tex_coord.Z = p[3].f;
-	c->current_tex_coord.W = p[4].f;
+	current_tex_coord.X = p[1].f;
+	current_tex_coord.Y = p[2].f;
+	current_tex_coord.Z = p[3].f;
+	current_tex_coord.W = p[4].f;
 }
 
 void GLContext::glopEdgeFlag(GLContext *c, GLParam *p) {
-	c->current_edge_flag = p[1].i;
+	current_edge_flag = p[1].i;
 }
 
 void GLContext::glopColor(GLContext *c, GLParam *p) {
-	c->current_color.X = p[1].f;
-	c->current_color.Y = p[2].f;
-	c->current_color.Z = p[3].f;
-	c->current_color.W = p[4].f;
+	current_color.X = p[1].f;
+	current_color.Y = p[2].f;
+	current_color.Z = p[3].f;
+	current_color.W = p[4].f;
 
-	if (c->color_material_enabled) {
+	if (color_material_enabled) {
 		GLParam q[7];
 		q[0].op = OP_Material;
-		q[1].i = c->current_color_material_mode;
-		q[2].i = c->current_color_material_type;
+		q[1].i = current_color_material_mode;
+		q[2].i = current_color_material_type;
 		q[3].f = p[1].f;
 		q[4].f = p[2].f;
 		q[5].f = p[3].f;
 		q[6].f = p[4].f;
-		c->glopMaterial(c, q);
+		glopMaterial(c, q);
 	}
 }
 
@@ -92,62 +92,62 @@ void GLContext::glopBegin(GLContext *c, GLParam *p) {
 	assert(c->in_begin == 0);
 
 	type = p[1].i;
-	c->begin_type = type;
-	c->in_begin = 1;
-	c->vertex_n = 0;
-	c->vertex_cnt = 0;
+	begin_type = type;
+	in_begin = 1;
+	vertex_n = 0;
+	vertex_cnt = 0;
 
-	if (c->matrix_model_projection_updated) {
-		if (c->lighting_enabled) {
+	if (matrix_model_projection_updated) {
+		if (lighting_enabled) {
 			// precompute inverse modelview
-			c->matrix_model_view_inv = *c->matrix_stack_ptr[0];
-			c->matrix_model_view_inv.invert();
-			c->matrix_model_view_inv.transpose();
+			matrix_model_view_inv = *matrix_stack_ptr[0];
+			matrix_model_view_inv.invert();
+			matrix_model_view_inv.transpose();
 		} else {
 			// precompute projection matrix
-			c->matrix_model_projection = (*c->matrix_stack_ptr[1]) * (*c->matrix_stack_ptr[0]);
+			matrix_model_projection = (*matrix_stack_ptr[1]) * (*matrix_stack_ptr[0]);
 			// test to accelerate computation
-			c->matrix_model_projection_no_w_transform = 0;
-			if (c->matrix_model_projection._m[3][0] == 0.0 && c->matrix_model_projection._m[3][1] == 0.0 && c->matrix_model_projection._m[3][2] == 0.0)
-				c->matrix_model_projection_no_w_transform = 1;
+			matrix_model_projection_no_w_transform = 0;
+			if (matrix_model_projection._m[3][0] == 0.0 && matrix_model_projection._m[3][1] == 0.0 && matrix_model_projection._m[3][2] == 0.0)
+				matrix_model_projection_no_w_transform = 1;
 		}
 
-		c->matrix_model_projection_updated = 0;
+		matrix_model_projection_updated = 0;
 	}
 	// test if the texture matrix is not Identity
-	c->apply_texture_matrix = !c->matrix_stack_ptr[2]->isIdentity();
+	apply_texture_matrix = !matrix_stack_ptr[2]->isIdentity();
 
 	// viewport
-	if (c->viewport.updated) {
+	if (viewport.updated) {
 		gl_eval_viewport(c);
-		c->viewport.updated = 0;
+		viewport.updated = 0;
 	}
 	// triangle drawing functions
-	if (c->render_mode == TGL_SELECT) {
-		c->draw_triangle_front = gl_draw_triangle_select;
-		c->draw_triangle_back = gl_draw_triangle_select;
+	if (render_mode == TGL_SELECT) {
+		draw_triangle_front = gl_draw_triangle_select;
+		draw_triangle_back = gl_draw_triangle_select;
 	} else {
-		switch (c->polygon_mode_front) {
+		switch (polygon_mode_front) {
 		case TGL_POINT:
-			c->draw_triangle_front = gl_draw_triangle_point;
+			draw_triangle_front = gl_draw_triangle_point;
 			break;
 		case TGL_LINE:
-			c->draw_triangle_front = gl_draw_triangle_line;
+			draw_triangle_front = gl_draw_triangle_line;
 			break;
 		default:
-			c->draw_triangle_front = gl_draw_triangle_fill;
+			draw_triangle_front = gl_draw_triangle_fill;
 			break;
 		}
 
 		switch (c->polygon_mode_back) {
 		case TGL_POINT:
-			c->draw_triangle_back = gl_draw_triangle_point;
+			draw_triangle_back = gl_draw_triangle_point;
 			break;
 		case TGL_LINE:
-			c->draw_triangle_back = gl_draw_triangle_line;
+			draw_triangle_back = gl_draw_triangle_line;
 			break;
 		default:
-			c->draw_triangle_back = gl_draw_triangle_fill;
+			draw_triangle_back = gl_draw_triangle_fill;
 			break;
 		}
 	}
@@ -195,27 +195,27 @@ void GLContext::glopVertex(GLContext *c, GLParam *p) {
 	GLVertex *v;
 	int n, cnt;
 
-	assert(c->in_begin != 0);
+	assert(in_begin != 0);
 
-	n = c->vertex_n;
-	cnt = c->vertex_cnt;
+	n = vertex_n;
+	cnt = vertex_cnt;
 	cnt++;
-	c->vertex_cnt = cnt;
+	vertex_cnt = cnt;
 
 	// quick fix to avoid crashes on large polygons
-	if (n >= c->vertex_max) {
+	if (n >= vertex_max) {
 		GLVertex *newarray;
-		c->vertex_max <<= 1;    // just double size
-		newarray = (GLVertex *)gl_malloc(sizeof(GLVertex) * c->vertex_max);
+		vertex_max <<= 1;    // just double size
+		newarray = (GLVertex *)gl_malloc(sizeof(GLVertex) * vertex_max);
 		if (!newarray) {
 			error("unable to allocate GLVertex array.");
 		}
-		memcpy(newarray, c->vertex, n * sizeof(GLVertex));
-		gl_free(c->vertex);
-		c->vertex = newarray;
+		memcpy(newarray, vertex, n * sizeof(GLVertex));
+		gl_free(vertex);
+		vertex = newarray;
 	}
 	// new vertex entry
-	v = &c->vertex[n];
+	v = &vertex[n];
 	n++;
 
 	v->coord.X = p[1].f;
@@ -227,40 +227,40 @@ void GLContext::glopVertex(GLContext *c, GLParam *p) {
 
 	// color
 
-	if (c->lighting_enabled) {
-		c->gl_shade_vertex(c, v);
+	if (lighting_enabled) {
+		gl_shade_vertex(v);
 	} else {
-		v->color = c->current_color;
+		v->color = current_color;
 	}
 
 	// tex coords
 
-	if (c->texture_2d_enabled) {
-		if (c->apply_texture_matrix) {
-			c->matrix_stack_ptr[2]->transform(c->current_tex_coord, v->tex_coord);
+	if (texture_2d_enabled) {
+		if (apply_texture_matrix) {
+			matrix_stack_ptr[2]->transform(current_tex_coord, v->tex_coord);
 		} else {
-			v->tex_coord = c->current_tex_coord;
+			v->tex_coord = current_tex_coord;
 		}
 	}
 	// precompute the mapping to the viewport
 	if (v->clip_code == 0)
-		c->gl_transform_to_viewport(c, v);
+		gl_transform_to_viewport(v);
 
 	// edge flag
 
-	v->edge_flag = c->current_edge_flag;
+	v->edge_flag = current_edge_flag;
 
-	c->vertex_n = n;
+	vertex_n = n;
 }
 
 void GLContext::glopEnd(GLContext *c, GLParam *) {
-	assert(c->in_begin == 1);
+	assert(in_begin == 1);
 
-	if (c->vertex_cnt > 0) {
-		c->issueDrawCall(new RasterizationDrawCall());
+	if (vertex_cnt > 0) {
+		issueDrawCall(new RasterizationDrawCall());
 	}
 
-	c->in_begin = 0;
+	in_begin = 0;
 }
 
 } // end of namespace TinyGL
diff --git a/graphics/tinygl/zbuffer.cpp b/graphics/tinygl/zbuffer.cpp
index 01cdd78091..ac1f370b43 100644
--- a/graphics/tinygl/zbuffer.cpp
+++ b/graphics/tinygl/zbuffer.cpp
@@ -89,8 +89,7 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelBuffer &fra
 
 	int size = this->xsize * this->ysize * sizeof(unsigned int);
 
-	this->_zbuf = (unsigned int *)gl_malloc(size);
-	memset(this->_zbuf, 0, size);
+	this->_zbuf = (unsigned int *)gl_zalloc(size);
 
 	this->frame_buffer_allocated = 0;
 	this->pbuf = frame_buffer;
@@ -118,8 +117,7 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &for
 
 	int size = this->xsize * this->ysize * sizeof(unsigned int);
 
-	this->_zbuf = (unsigned int *)gl_malloc(size);
-	memset(this->_zbuf, 0, size);
+	this->_zbuf = (unsigned int *)gl_zalloc(size);
 
 	byte *pixelBuffer = new byte[this->ysize * this->linesize];
 	this->pbuf.set(this->cmode, pixelBuffer);
diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h
index 7e333885ee..1c42e31b1b 100644
--- a/graphics/tinygl/zbuffer.h
+++ b/graphics/tinygl/zbuffer.h
@@ -46,7 +46,7 @@ namespace TinyGL {
 
 #define ZB_POINT_ST_FRAC_BITS 14
 #define ZB_POINT_ST_FRAC_SHIFT     (ZB_POINT_ST_FRAC_BITS - 1)
-#define ZB_POINT_ST_MAX            ( (c->_textureSize << ZB_POINT_ST_FRAC_BITS) - 1 )
+#define ZB_POINT_ST_MAX            ( (_textureSize << ZB_POINT_ST_FRAC_BITS) - 1 )
 
 #define ZB_POINT_RED_BITS         16
 #define ZB_POINT_RED_FRAC_BITS    8
diff --git a/graphics/tinygl/zdirtyrect.cpp b/graphics/tinygl/zdirtyrect.cpp
index 0fdaddca93..9eb95093bf 100644
--- a/graphics/tinygl/zdirtyrect.cpp
+++ b/graphics/tinygl/zdirtyrect.cpp
@@ -35,10 +35,9 @@
 namespace TinyGL {
 
 void GLContext::issueDrawCall(DrawCall *drawCall) {
-	TinyGL::GLContext *c = TinyGL::gl_get_context();
-	if (c->_enableDirtyRectangles && drawCall->getDirtyRegion().isEmpty())
+	if (_enableDirtyRectangles && drawCall->getDirtyRegion().isEmpty())
 		return;
-	c->_drawCallsQueue.push_back(drawCall);
+	_drawCallsQueue.push_back(drawCall);
 }
 
 #if TGL_DIRTY_RECT_SHOW
@@ -78,16 +77,16 @@ struct DirtyRectangle {
 	}
 };
 
-void GLContext::disposeResources(GLContext *c) {
+void GLContext::disposeResources() {
 	// Dispose textures and resources.
 	bool allDisposed = true;
 	do {
 		allDisposed = true;
 		for (int i = 0; i < TEXTURE_HASH_TABLE_SIZE; i++) {
-			GLTexture *t = c->shared_state.texture_hash_table[i];
+			GLTexture *t = shared_state.texture_hash_table[i];
 			while (t) {
 				if (t->disposed) {
-					c->free_texture(c, t);
+					free_texture(t);
 					allDisposed = false;
 					break;
 				}
@@ -100,16 +99,16 @@ void GLContext::disposeResources(GLContext *c) {
 	TinyGL::Internal::tglCleanupImages();
 }
 
-void GLContext::disposeDrawCallLists(GLContext *c) {
+void GLContext::disposeDrawCallLists() {
 	typedef Common::List<DrawCall *>::const_iterator DrawCallIterator;
-	for (DrawCallIterator it = c->_previousFrameDrawCallsQueue.begin(); it != c->_previousFrameDrawCallsQueue.end(); ++it) {
+	for (DrawCallIterator it = _previousFrameDrawCallsQueue.begin(); it != _previousFrameDrawCallsQueue.end(); ++it) {
 		delete *it;
 	}
-	c->_previousFrameDrawCallsQueue.clear();
-	for (DrawCallIterator it = c->_drawCallsQueue.begin(); it != c->_drawCallsQueue.end(); ++it) {
+	_previousFrameDrawCallsQueue.clear();
+	for (DrawCallIterator it = _drawCallsQueue.begin(); it != _drawCallsQueue.end(); ++it) {
 		delete *it;
 	}
-	c->_drawCallsQueue.clear();
+	_drawCallsQueue.clear();
 }
 
 static inline void _appendDirtyRectangle(const DrawCall &call, Common::List<DirtyRectangle> &rectangles, int r, int g, int b) {
@@ -118,16 +117,16 @@ static inline void _appendDirtyRectangle(const DrawCall &call, Common::List<Dirt
 		rectangles.push_back(DirtyRectangle(dirty_region, r, g, b));
 }
 
-void GLContext::presentBufferDirtyRects(GLContext *c) {
+void GLContext::presentBufferDirtyRects() {
 	typedef Common::List<DrawCall *>::const_iterator DrawCallIterator;
 	typedef Common::List<DirtyRectangle>::iterator RectangleIterator;
 
 	Common::List<DirtyRectangle> rectangles;
 
-	DrawCallIterator itFrame = c->_drawCallsQueue.begin();
-	DrawCallIterator endFrame = c->_drawCallsQueue.end();
-	DrawCallIterator itPrevFrame = c->_previousFrameDrawCallsQueue.begin();
-	DrawCallIterator endPrevFrame = c->_previousFrameDrawCallsQueue.end();
+	DrawCallIterator itFrame = _drawCallsQueue.begin();
+	DrawCallIterator endFrame = _drawCallsQueue.end();
+	DrawCallIterator itPrevFrame = _previousFrameDrawCallsQueue.begin();
+	DrawCallIterator endPrevFrame = _previousFrameDrawCallsQueue.end();
 
 	// Compare draw calls.
 	for ( ; itPrevFrame != endPrevFrame && itFrame != endFrame;
@@ -189,12 +188,12 @@ void GLContext::presentBufferDirtyRects(GLContext *c) {
 	}
 
 	for (RectangleIterator it1 = rectangles.begin(); it1 != rectangles.end(); ++it1) {
-		(*it1).rectangle.clip(c->renderRect);
+		(*it1).rectangle.clip(renderRect);
 	}
 
 	if (!rectangles.empty()) {
 		// Execute draw calls.
-		for (DrawCallIterator it = c->_drawCallsQueue.begin(); it != c->_drawCallsQueue.end(); ++it) {
+		for (DrawCallIterator it = _drawCallsQueue.begin(); it != _drawCallsQueue.end(); ++it) {
 			Common::Rect drawCallRegion = (*it)->getDirtyRegion();
 			for (RectangleIterator itRect = rectangles.begin(); itRect != rectangles.end(); ++itRect) {
 				Common::Rect dirtyRegion = (*itRect).rectangle;
@@ -209,8 +208,8 @@ void GLContext::presentBufferDirtyRects(GLContext *c) {
 		// blue rectangles are rectangle merged from other rectangles
 		// red rectangles are original dirty rects
 
-		bool blendingEnabled = c->fb->isBlendingEnabled();
-		bool alphaTestEnabled = c->fb->isAlphaTestEnabled();
+		bool blendingEnabled = fb->isBlendingEnabled();
+		bool alphaTestEnabled = fb->isAlphaTestEnabled();
 		c->fb->enableBlending(false);
 		c->fb->enableAlphaTest(false);
 
@@ -218,47 +217,47 @@ void GLContext::presentBufferDirtyRects(GLContext *c) {
 			DebugDrawRectangle((*it).rectangle, (*it).r, (*it).g, (*it).b);
 		}
 
-		c->fb->enableBlending(blendingEnabled);
-		c->fb->enableAlphaTest(alphaTestEnabled);
+		fb->enableBlending(blendingEnabled);
+		fb->enableAlphaTest(alphaTestEnabled);
 #endif
 	}
 
 	// Dispose not necessary draw calls.
-	for (DrawCallIterator it = c->_previousFrameDrawCallsQueue.begin(); it != c->_previousFrameDrawCallsQueue.end(); ++it) {
+	for (DrawCallIterator it = _previousFrameDrawCallsQueue.begin(); it !=  _previousFrameDrawCallsQueue.end(); ++it) {
 		delete *it;
 	}
 
-	c->_previousFrameDrawCallsQueue = c->_drawCallsQueue;
-	c->_drawCallsQueue.clear();
+	_previousFrameDrawCallsQueue = _drawCallsQueue;
+	_drawCallsQueue.clear();
 
 
-	c->disposeResources(c);
+	disposeResources();
 
-	c->_currentAllocatorIndex = (c->_currentAllocatorIndex + 1) & 0x1;
-	c->_drawCallAllocator[c->_currentAllocatorIndex].reset();
+	_currentAllocatorIndex = (_currentAllocatorIndex + 1) & 0x1;
+	_drawCallAllocator[_currentAllocatorIndex].reset();
 }
 
-void GLContext::presentBufferSimple(GLContext *c) {
+void GLContext::presentBufferSimple() {
 	typedef Common::List<DrawCall *>::const_iterator DrawCallIterator;
 
-	for (DrawCallIterator it = c->_drawCallsQueue.begin(); it != c->_drawCallsQueue.end(); ++it) {
+	for (DrawCallIterator it = _drawCallsQueue.begin(); it != _drawCallsQueue.end(); ++it) {
 		(*it)->execute(true);
 		delete *it;
 	}
 
-	c->_drawCallsQueue.clear();
+	_drawCallsQueue.clear();
 
-	c->disposeResources(c);
+	disposeResources();
 
-	c->_drawCallAllocator[c->_currentAllocatorIndex].reset();
+	_drawCallAllocator[_currentAllocatorIndex].reset();
 }
 
 void presentBuffer() {
 	TinyGL::GLContext *c = TinyGL::gl_get_context();
 	if (c->_enableDirtyRectangles) {
-		c->presentBufferDirtyRects(c);
+		c->presentBufferDirtyRects();
 	} else {
-		c->presentBufferSimple(c);
+		c->presentBufferSimple();
 	}
 }
 
@@ -310,7 +309,7 @@ void RasterizationDrawCall::computeDirtyRegion() {
 		for (int i = 0; i < _vertexCount; i++) {
 			TinyGL::GLVertex *v = &_vertex[i];
 			if (v->clip_code)
-				c->gl_transform_to_viewport(c, v);
+				c->gl_transform_to_viewport(v);
 			left =   MIN(left,   v->clip_code & 0x1 ?    0 : v->zp.x);
 			right =  MAX(right,  v->clip_code & 0x2 ? xmax : v->zp.x);
 			bottom = MAX(bottom, v->clip_code & 0x4 ? ymax : v->zp.y);
@@ -351,25 +350,25 @@ void RasterizationDrawCall::execute(bool restoreState) const {
 	switch (c->begin_type) {
 	case TGL_POINTS:
 		for(int i = 0; i < cnt; i++) {
-			c->gl_draw_point(c, &c->vertex[i]);
+			c->gl_draw_point(&c->vertex[i]);
 		}
 		break;
 	case TGL_LINES:
 		for(int i = 0; i < cnt / 2; i++) {
-			c->gl_draw_line(c, &c->vertex[i * 2], &c->vertex[i * 2 + 1]);
+			c->gl_draw_line(&c->vertex[i * 2], &c->vertex[i * 2 + 1]);
 		}
 		break;
 	case TGL_LINE_LOOP:
-		c->gl_draw_line(c, &c->vertex[cnt - 1], &c->vertex[0]);
+		c->gl_draw_line(&c->vertex[cnt - 1], &c->vertex[0]);
 		// Fall through...
 	case TGL_LINE_STRIP:
 		for(int i = 0; i < cnt - 1; i++) {
-			c->gl_draw_line(c, &c->vertex[i], &c->vertex[i + 1]);
+			c->gl_draw_line(&c->vertex[i], &c->vertex[i + 1]);
 		}
 		break;
 	case TGL_TRIANGLES:
 		for(int i = 0; i < cnt; i += 3) {
-			c->gl_draw_triangle(c, &c->vertex[i], &c->vertex[i + 1], &c->vertex[i + 2]);
+			c->gl_draw_triangle(&c->vertex[i], &c->vertex[i + 1], &c->vertex[i + 2]);
 		}
 		break;
 	case TGL_TRIANGLE_STRIP:
@@ -377,10 +376,10 @@ void RasterizationDrawCall::execute(bool restoreState) const {
 			// needed to respect triangle orientation
 			switch (cnt & 1) {
 			case 0:
-				c->gl_draw_triangle(c, &c->vertex[2], &c->vertex[1], &c->vertex[0]);
+				c->gl_draw_triangle(&c->vertex[2], &c->vertex[1], &c->vertex[0]);
 				break;
 			case 1:
-				c->gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
+				c->gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
 				break;
 			}
 			cnt--;
@@ -389,22 +388,22 @@ void RasterizationDrawCall::execute(bool restoreState) const {
 		break;
 	case TGL_TRIANGLE_FAN:
 		for(int i = 1; i < cnt; i += 2) {
-			c->gl_draw_triangle(c, &c->vertex[0], &c->vertex[i], &c->vertex[i + 1]);
+			c->gl_draw_triangle(&c->vertex[0], &c->vertex[i], &c->vertex[i + 1]);
 		}
 		break;
 	case TGL_QUADS:
 		for(int i = 0; i < cnt; i += 4) {
 			c->vertex[i + 2].edge_flag = 0;
-			c->gl_draw_triangle(c, &c->vertex[i], &c->vertex[i + 1], &c->vertex[i + 2]);
+			c->gl_draw_triangle(&c->vertex[i], &c->vertex[i + 1], &c->vertex[i + 2]);
 			c->vertex[i + 2].edge_flag = 1;
 			c->vertex[i + 0].edge_flag = 0;
-			c->gl_draw_triangle(c, &c->vertex[i], &c->vertex[i + 2], &c->vertex[i + 3]);
+			c->gl_draw_triangle(&c->vertex[i], &c->vertex[i + 2], &c->vertex[i + 3]);
 		}
 		break;
 	case TGL_QUAD_STRIP:
 		for( ; n >= 4; n -= 2) {
-			c->gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
-			c->gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]);
+			c->gl_draw_triangle(&c->vertex[0], &c->vertex[1], &c->vertex[2]);
+			c->gl_draw_triangle(&c->vertex[1], &c->vertex[3], &c->vertex[2]);
 			for (int i = 0; i < 2; i++) {
 				c->vertex[i] = c->vertex[i + 2];
 			}
@@ -412,7 +411,7 @@ void RasterizationDrawCall::execute(bool restoreState) const {
 		break;
 	case TGL_POLYGON: {
 		for (int i = c->vertex_cnt; i >= 3; i--) {
-			c->gl_draw_triangle(c, &c->vertex[i - 1], &c->vertex[0], &c->vertex[i - 2]);
+			c->gl_draw_triangle(&c->vertex[i - 1], &c->vertex[0], &c->vertex[i - 2]);
 		}
 		break;
 	}
diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h
index 3fd9bf4fda..cfe744d70e 100644
--- a/graphics/tinygl/zgl.h
+++ b/graphics/tinygl/zgl.h
@@ -415,47 +415,46 @@ public:
 	#include "graphics/tinygl/opinfo.h"
 
 	void gl_add_op(GLParam *p);
+	void gl_compile_op(GLParam *p);
 
-	void gl_transform_to_viewport(GLContext *c, GLVertex *v);
-	void gl_draw_triangle(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2);
-	void gl_draw_line(GLContext *c, GLVertex *p0, GLVertex *p1);
-	void gl_draw_point(GLContext *c, GLVertex *p0);
+	void gl_transform_to_viewport(GLVertex *v);
+	void gl_draw_triangle(GLVertex *p0, GLVertex *p1, GLVertex *p2);
+	void gl_draw_line(GLVertex *p0, GLVertex *p1);
+	void gl_draw_point(GLVertex *p0);
 
 	static void gl_draw_triangle_point(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2);
 	static void gl_draw_triangle_line(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2);
 	static void gl_draw_triangle_fill(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2);
 	static void gl_draw_triangle_select(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2);
-	void gl_draw_triangle_clip(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2, int clip_bit);
+	void gl_draw_triangle_clip(GLVertex *p0, GLVertex *p1, GLVertex *p2, int clip_bit);
 
-	void gl_add_select(GLContext *c, unsigned int zmin, unsigned int zmax);
-	void gl_add_select1(GLContext *c, int z1, int z2, int z3);
-	void gl_enable_disable_light(GLContext *c, int light, int v);
-	void gl_shade_vertex(GLContext *c, GLVertex *v);
+	void gl_add_select(unsigned int zmin, unsigned int zmax);
+	void gl_add_select1(int z1, int z2, int z3);
+	void gl_enable_disable_light(int light, int v);
+	void gl_shade_vertex(GLVertex *v);
 
-	void glInitTextures(GLContext *c);
-	void glEndTextures(GLContext *c);
-	GLTexture *alloc_texture(GLContext *c, uint h);
-	void free_texture(GLContext *c, uint h);
-	void free_texture(GLContext *c, GLTexture *t);
+	void glInitTextures();
+	void glEndTextures();
+	GLTexture *alloc_texture(uint h);
+	void free_texture(uint h);
+	void free_texture(GLTexture *t);
 
 	void gl_resizeImage(Graphics::PixelBuffer &dest, int xsize_dest, int ysize_dest,
 				const Graphics::PixelBuffer &src, int xsize_src, int ysize_src);
-	void gl_resizeImageNoInterpolate(Graphics::PixelBuffer &dest, int xsize_dest, int ysize_dest,
-					 const Graphics::PixelBuffer &src, int xsize_src, int ysize_src);
+	void gl_resizeImageNoInterpolate(Graphics::PixelBuffer &dest, int xsize_dest, int ysize_dest, const Graphics::PixelBuffer &src, int xsize_src, int ysize_src);
 
 	void issueDrawCall(DrawCall *drawCall);
+	void disposeResources();
+	void disposeDrawCallLists();
 
-	void disposeResources(GLContext *c);
-	void disposeDrawCallLists(GLContext *c);
-
-	void presentBufferDirtyRects(GLContext *c);
-	void presentBufferSimple(GLContext *c);
+	void presentBufferDirtyRects();
+	void presentBufferSimple();
 	
-	GLSpecBuf *specbuf_get_buffer(GLContext *c, const int shininess_i, const float shininess);
-	void specbuf_cleanup(GLContext *c); // free all memory used
+	GLSpecBuf *specbuf_get_buffer(const int shininess_i, const float shininess);
+	void specbuf_cleanup();
 
-	void initSharedState(GLContext *c);
-	void endSharedState(GLContext *c);
+	void initSharedState();
+	void endSharedState();
 
 	void init(int screenW, int screenH, Graphics::PixelFormat pixelFormat, int textureSize, bool dirtyRectsEnable = true);
 	void deinit();




More information about the Scummvm-git-logs mailing list