[Scummvm-cvs-logs] CVS: residual bitmap.cpp,1.24,1.25 bitmap.h,1.7,1.8 driver_gl.cpp,1.16,1.17 driver_gl.h,1.8,1.9 engine.cpp,1.30,1.31 material.cpp,1.7,1.8 material.h,1.3,1.4 model.cpp,1.17,1.18 model.h,1.5,1.6

Pawel Kolodziejski aquadran at users.sourceforge.net
Mon Apr 19 02:57:05 CEST 2004


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1090

Modified Files:
	bitmap.cpp bitmap.h driver_gl.cpp driver_gl.h engine.cpp 
	material.cpp material.h model.cpp model.h 
Log Message:
moved opengl stuff into driver_gl

Index: bitmap.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/bitmap.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- bitmap.cpp	14 Apr 2004 23:04:32 -0000	1.24
+++ bitmap.cpp	19 Apr 2004 09:56:33 -0000	1.25
@@ -64,162 +64,21 @@
 	#endif
 	}	
 	
-	if (format_ == 1) {
-		hasTransparency_ = false;
-		num_tex_ = ((width_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
-			((height_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
-		tex_ids_ = new GLuint[num_tex_ * num_images_];
-		glGenTextures(num_tex_ * num_images_, tex_ids_);
-
-		char *texData = new char[4 * width_ * height_];
-
-		for (int pic = 0; pic < num_images_; pic++) {
-			// Convert data to 32-bit RGBA format
-			char *texDataPtr = texData;
-			uint16 *bitmapData = reinterpret_cast<uint16 *>(data_[pic]);
-			for (int i = 0; i < width_ * height_;
-			     i++, texDataPtr += 4, bitmapData++) {
-				uint16 pixel = *bitmapData;
-				int r = pixel >> 11;
-				texDataPtr[0] = (r << 3) | (r >> 2);
-				int g = (pixel >> 5) & 0x3f;
-				texDataPtr[1] = (g << 2) | (g >> 4);
-				int b = pixel & 0x1f;
-				texDataPtr[2] = (b << 3) | (b >> 2);
-				if (pixel == 0xf81f) { // transparent
-					texDataPtr[3] = 0;
-					hasTransparency_ = true;
-				}
-				else
-					texDataPtr[3] = 255;
-			}
-
-			for (int i = 0; i < num_tex_; i++) {
-				glBindTexture(GL_TEXTURE_2D, tex_ids_[num_tex_ * pic + i]);
-				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
-					     BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0,
-					     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-			}
-
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
-			glPixelStorei(GL_UNPACK_ROW_LENGTH, width_);
-
-			int cur_tex_idx = num_tex_ * pic;
-
-			for (int y = 0; y < height_; y += BITMAP_TEXTURE_SIZE) {
-				for (int x = 0; x < width_; x += BITMAP_TEXTURE_SIZE) {
-					int width  = (x + BITMAP_TEXTURE_SIZE >= width_)  ? (width_  - x) : BITMAP_TEXTURE_SIZE;
-					int height = (y + BITMAP_TEXTURE_SIZE >= height_) ? (height_ - y) : BITMAP_TEXTURE_SIZE;
-					glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
-					glTexSubImage2D(GL_TEXTURE_2D,
-							0,
-							0, 0,
-							width, height,
-							GL_RGBA,
-							GL_UNSIGNED_BYTE,
-							texData + (y * 4 * width_) + (4 * x));
-					cur_tex_idx++;
-				}
-			}
-		}
-
-		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-		delete [] texData;
-	} else {
-		for (int pic = 0; pic < num_images_; pic++) {
-			uint16 *zbufPtr = reinterpret_cast<uint16*>(data_[pic]);
-			for (int i = 0; i < (width_ * height_); i++) {
-				uint16 val = READ_LE_UINT16(data_[pic] + 2 * i);
-				zbufPtr[i] = 0xffff - ((uint32) val) * 0x10000 / 100 / (0x10000 - val);
-			}
-
-			// Flip the zbuffer image to match what GL expects
-			for (int y = 0; y < height_ / 2; y++) {
-				uint16 *ptr1 = zbufPtr + y * width_;
-				uint16 *ptr2 = zbufPtr + (height_ - 1 - y) * width_;
-				for (int x = 0; x < width_; x++, ptr1++, ptr2++) {
-					uint16 tmp = *ptr1;
-					*ptr1 = *ptr2;
-					*ptr2 = tmp;
-				}
-			}
-		}
-
-		tex_ids_ = NULL;
-	}
+	g_driver->createBitmap(this);
 }
 
 void Bitmap::draw() const {
 	if (curr_image_ == 0)
 		return;
 
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(0, 640, 480, 0, 0, 1);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-	glMatrixMode(GL_TEXTURE);
-	glLoadIdentity();
-	// A lot more may need to be put there : disabling Alpha test, blending, ...
-	// For now, just keep this here :-)
-	if (format_ == 1 && hasTransparency_) {
-		glEnable(GL_BLEND);
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	}
-	else
-		glDisable(GL_BLEND);
-	glDisable(GL_LIGHTING);
-	glEnable(GL_TEXTURE_2D);
-	if (format_ == 1) {		// Normal image
-		glDisable(GL_DEPTH_TEST);
-		glDepthMask(GL_FALSE);
-		glEnable(GL_SCISSOR_TEST);
-		glScissor(x_, 480 - (y_ + height_), width_, height_);
-		int cur_tex_idx = num_tex_ * (curr_image_ - 1);
-		for (int y = y_; y < (y_ + height_); y += BITMAP_TEXTURE_SIZE) {
-			for (int x = x_; x < (x_ + width_); x += BITMAP_TEXTURE_SIZE) {
-				glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
-				glBegin(GL_QUADS);
-				glTexCoord2f(0.0, 0.0);
-				glVertex2i(x, y);
-				glTexCoord2f(1.0, 0.0);
-				glVertex2i(x + BITMAP_TEXTURE_SIZE, y);
-				glTexCoord2f(1.0, 1.0);
-				glVertex2i(x + BITMAP_TEXTURE_SIZE, y + BITMAP_TEXTURE_SIZE);
-				glTexCoord2f(0.0, 1.0);
-				glVertex2i(x, y + BITMAP_TEXTURE_SIZE);
-				glEnd();
-				cur_tex_idx++;
-			}
-		}
-
-		glDisable(GL_SCISSOR_TEST);
-		glDisable(GL_TEXTURE_2D);
-		glDisable(GL_BLEND);
-		glDepthMask(GL_TRUE);
-		glEnable(GL_DEPTH_TEST);
-	} else if (format_ == 5) {	// ZBuffer image
-		// Only draw the manual zbuffer when we are not using screenblocks, and when enabled
-		if ((! ZBUFFER_GLOBAL) || SCREENBLOCKS_GLOBAL)
-			return;
-
-		g_driver->drawDepthBitmap(x_, y_, width_, height_, data_[curr_image_ - 1]);
-	}
+	g_driver->drawBitmap(this);
 }
 
 Bitmap::~Bitmap() {
 	for (int i = 0; i < num_images_; i++)
 		delete[] data_[i];
 	delete[] data_;
-	if (tex_ids_) {
-		glDeleteTextures(num_tex_ * num_images_, tex_ids_);
-		delete[] tex_ids_;
-	}
+	g_driver->destroyBitmap(this);
 }
 
 #define GET_BIT do { bit = bitstr_value & 1; \

Index: bitmap.h
===================================================================
RCS file: /cvsroot/scummvm/residual/bitmap.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- bitmap.h	22 Mar 2004 21:48:30 -0000	1.7
+++ bitmap.h	19 Apr 2004 09:56:33 -0000	1.8
@@ -44,7 +44,7 @@
 
 	~Bitmap();
 
-private:
+//private:
 	char **data_;
 	int num_images_, curr_image_;
 	int width_, height_, x_, y_;

Index: driver_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- driver_gl.cpp	15 Apr 2004 20:20:04 -0000	1.16
+++ driver_gl.cpp	19 Apr 2004 09:56:33 -0000	1.17
@@ -18,6 +18,9 @@
 #include "driver_gl.h"		// Driver interface
 #include "debug.h"		// error(), warning(), etc
 #include "font.h"		// builtin emergency font
+#include "screen.h"
+#include "colormap.h"
+#include "material.h"
 
 Driver *g_driver;
 
@@ -80,6 +83,7 @@
 }
 
 void Driver::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
+	glEnable(GL_TEXTURE_2D);
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
 	glTranslatef(pos.x(), pos.y(), pos.z());
@@ -90,6 +94,515 @@
 
 void Driver::finishActorDraw() {
 	glPopMatrix();
+	glDisable(GL_TEXTURE_2D);
+}
+
+
+void Driver::set3DMode() {
+	glMatrixMode(GL_MODELVIEW);
+	glEnable(GL_DEPTH_TEST);
+}
+
+void Driver::drawModel(const Model::Mesh *model) {
+	GLdouble modelView[500];
+	GLdouble projection[500];
+	GLint viewPort[500];
+
+	glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
+	glGetDoublev(GL_PROJECTION_MATRIX, projection);
+	glGetIntegerv(GL_VIEWPORT, viewPort);
+
+	// Yaz: debug
+	// this draw the model node in red
+	//glMatrixMode(GL_PROJECTION);
+	/*glPushMatrix();
+	glLoadIdentity();
+
+	GLdouble modelView[500];
+	GLdouble projection[500];
+	GLint viewPort[500];
+
+	glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
+	glGetDoublev( GL_PROJECTION_MATRIX, projection );
+	glGetIntegerv( GL_VIEWPORT, viewPort);
+
+	glDisable(GL_DEPTH_TEST);
+	glPointSize( 3.f );
+	glColor4f( 1.f, 0.f, 0.f, 1.f );
+	glDisable(GL_TEXTURE_2D );
+	glBegin( GL_POINTS );
+	glVertex3f( matrix_.pos_.x(), matrix_.pos_.y(), matrix_.pos_.z() );
+	glEnd();
+	glEnable(GL_DEPTH_TEST);
+	glPopMatrix();
+	glEnable(GL_TEXTURE_2D );*/
+
+	// Yaz: debug
+	// this draw the poly points
+
+	/*glPushMatrix();
+	glLoadIdentity();
+	glPointSize( 3.f );
+	glColor4f( 0.f, 1.f, 0.f, 1.f );
+	glDisable(GL_TEXTURE_2D );
+	{
+		GLdouble modelView[500];
+		GLdouble projection[500];
+		GLint viewPort[500];
+
+		glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
+		glGetDoublev( GL_PROJECTION_MATRIX, projection );
+		glGetIntegerv( GL_VIEWPORT, viewPort);
+	}
+
+	glBegin( GL_POINTS );
+
+	for (int i = 0; i < numFaces_; i++) {
+		Vector3d v;
+		Matrix4 tempMatrix = matrix_;
+		float* pVertices;
+		int j;
+
+		for( j =0; j< faces_[i].numVertices_; j++ ) {
+			pVertices = vertices_ + 3 * faces_[i].vertices_[j];
+
+			v.set( *(pVertices), *(pVertices+1), *(pVertices+2) );
+
+			tempMatrix.rot_.transform( &v );
+			v+= tempMatrix.pos_;
+
+			glVertex3f( v.x(), v.y(), v.z() );
+
+		}
+	}
+
+	glEnd();
+	glEnable(GL_DEPTH_TEST);
+	glPopMatrix();
+	glEnable(GL_TEXTURE_2D ); */
+
+	// Ender: HACK HACK HACK
+	// Mannys head isn't computed correctly, so bail out to prevent memory corruption.
+	// at least until it IS computed, or the DirtyScreen code has bounds checking :)
+	//if (strstr(name_, "m_head_1"))
+	//	return;
+
+	// Yaz: debug
+	// this compute the dirty rect for the mesh
+	glPushMatrix();
+	glLoadIdentity();
+
+	GLdouble top = 1000;
+	GLdouble right = -1000;
+	GLdouble left = 1000;
+	GLdouble bottom = -1000;
+
+	for (int i = 0; i < model->numFaces_; i++) {
+		Vector3d v;
+		Matrix4 tempMatrix = model->matrix_;
+		float* pVertices;
+		int j;
+		float bestDepth = 0;
+
+		for(j = 0; j < model->faces_[i].numVertices_; j++) {
+			GLdouble modelView[500];
+			GLdouble projection[500];
+			GLint viewPort[500];
+
+			glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
+			glGetDoublev(GL_PROJECTION_MATRIX, projection);
+			glGetIntegerv(GL_VIEWPORT, viewPort);
+
+			pVertices = model->vertices_ + 3 * model->faces_[i].vertices_[j];
+
+			v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));
+
+			tempMatrix.rot_.transform(&v);
+			v+= tempMatrix.pos_;
+
+			GLdouble winX;
+			GLdouble winY;
+			GLdouble winZ;
+
+			gluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ);
+
+			if(winX > right)
+				right = winX;
+			if(winX < left)
+				left = winX;
+			if(winY < top)
+				top = winY;
+			if(winY > bottom)
+				bottom = winY;
+
+			if(winZ > bestDepth )
+				bestDepth = winZ;
+		}
+
+		if (SCREENBLOCKS_GLOBAL)
+			screenBlocksAddRectangle((int)top, (int)right, (int)left, (int)bottom, (int)bestDepth);
+	}
+	/*
+	glDisable(GL_DEPTH_TEST);
+	glPointSize( 3.f );
+	glColor4f( 1.f, 1.f, 0.f, 1.f );
+	glDisable(GL_TEXTURE_2D );
+
+	glBegin(GL_LINES);
+
+	GLdouble objx;
+	GLdouble objy;
+	GLdouble objz;
+
+	// top
+	gluUnProject( left, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+	gluUnProject( right, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+
+	// bottom
+	gluUnProject( left, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+	gluUnProject( right, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+
+	// left
+	gluUnProject( left, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+	gluUnProject( left, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+
+	// right
+	gluUnProject( right, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+	gluUnProject( right, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
+	glVertex3f( objx, objy, objz );
+
+	glEnd(); 
+	glEnable(GL_DEPTH_TEST);
+	glEnable(GL_TEXTURE_2D ); 
+*/
+ 	glPopMatrix();
+}
+
+void Driver::updateMesh(const Model::Mesh *mesh) {
+	GLdouble modelView[500];
+	GLdouble projection[500];
+	GLint viewPort[500];
+
+	glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
+	glGetDoublev(GL_PROJECTION_MATRIX, projection);
+	glGetIntegerv(GL_VIEWPORT, viewPort);
+
+	GLdouble top = 1000;
+	GLdouble right = -1000;
+	GLdouble left = 1000;
+	GLdouble bottom = -1000;
+
+	for (int i = 0; i < mesh->numFaces_; i++) {
+		Vector3d v;
+		Matrix4 tempMatrix = mesh->matrix_;
+		float *pVertices;
+		int j;
+		float bestDepth = 0;
+
+		for (j = 0; j < mesh->faces_[i].numVertices_; j++) {
+			pVertices = mesh->vertices_ + 3 * mesh->faces_[i].vertices_[j];
+
+			v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));
+
+			tempMatrix.rot_.transform(&v);
+			v+= tempMatrix.pos_;
+
+			GLdouble winX;
+			GLdouble winY;
+			GLdouble winZ;
+
+			gluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ);
+
+			if(winX > right)
+				right = winX;
+			if(winX < left)
+				left = winX;
+			if(winY < top)
+				top = winY;
+			if(winY > bottom)
+				bottom = winY;
+
+			if(winZ > bestDepth)
+				bestDepth = winZ;
+
+		}
+
+		//screenBlocksAddRectangle(top, right, left, bottom, bestDepth);
+	}
+
+	glDisable(GL_DEPTH_TEST);
+	glPointSize(3.f);
+	glColor4f(1.f, 1.f, 0.f, 1.f);
+	glDisable(GL_TEXTURE_2D);
+}
+
+void Driver::drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts) {
+	glNormal3fv(face->normal_.coords_);
+	glBegin(GL_POLYGON);
+	for (int i = 0; i < face->numVertices_; i++) {
+		glNormal3fv(vertNormals + 3 * face->vertices_[i]);
+		if (face->texVertices_ != NULL)
+			glTexCoord2fv(textureVerts + 2 * face->texVertices_[i]);
+		glVertex3fv(vertices + 3 * face->vertices_[i]);
+	}
+	glEnd();
+}
+
+void Driver::drawHierachyNode(const Model::HierNode *node) {
+	if (node->hierVisible_) {
+		glMatrixMode(GL_MODELVIEW);
+		glPushMatrix();
+
+		glTranslatef(node->animPos_.x() / node->totalWeight_, node->animPos_.y() / node->totalWeight_, node->animPos_.z() / node->totalWeight_);
+		glRotatef(node->animYaw_ / node->totalWeight_, 0, 0, 1);
+		glRotatef(node->animPitch_ / node->totalWeight_, 1, 0, 0);
+		glRotatef(node->animRoll_ / node->totalWeight_, 0, 1, 0);
+
+		if (node->mesh_ != NULL && node->meshVisible_) {
+			glPushMatrix();
+			glTranslatef(node->pivot_.x(), node->pivot_.y(), node->pivot_.z());
+			node->mesh_->draw();
+			glMatrixMode(GL_MODELVIEW);
+			glPopMatrix();
+		}
+		if (node->child_ != NULL) {
+			node->child_->draw();
+			glMatrixMode(GL_MODELVIEW);
+		}
+		glPopMatrix();
+	}
+
+	if (node->sibling_ != NULL)
+		node->sibling_->draw();
+}
+
+void Driver::updateHierachyNode(const Model::HierNode *node) {
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+
+	glTranslatef(node->animPos_.x() / node->totalWeight_, node->animPos_.y() / node->totalWeight_, node->animPos_.z() / node->totalWeight_);
+	glRotatef(node->animYaw_ / node->totalWeight_, 0, 0, 1);
+	glRotatef(node->animPitch_ / node->totalWeight_, 1, 0, 0);
+	glRotatef(node->animRoll_ / node->totalWeight_, 0, 1, 0);
+
+	if (node->mesh_ != NULL) {
+		glPushMatrix();
+		glTranslatef(node->pivot_.x(), node->pivot_.y(), node->pivot_.z());
+		node->mesh_->matrix_ = node->pivotMatrix;
+		node->mesh_->update();
+
+		glMatrixMode(GL_MODELVIEW);
+		glPopMatrix();
+	}
+
+	if (node->child_ != NULL ) {
+		node->child_->setMatrix(node->matrix_);
+		node->child_->update();
+		glMatrixMode(GL_MODELVIEW);
+	}
+
+	glPopMatrix();
+}
+
+void Driver::createBitmap(Bitmap *bitmap) {
+	if (bitmap->format_ == 1) {
+		bitmap->hasTransparency_ = false;
+		bitmap->num_tex_ = ((bitmap->width_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
+			((bitmap->height_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
+		bitmap->tex_ids_ = new GLuint[bitmap->num_tex_ * bitmap->num_images_];
+		glGenTextures(bitmap->num_tex_ * bitmap->num_images_, bitmap->tex_ids_);
+
+		char *texData = new char[4 * bitmap->width_ * bitmap->height_];
+
+		for (int pic = 0; pic < bitmap->num_images_; pic++) {
+			// Convert data to 32-bit RGBA format
+			char *texDataPtr = texData;
+			uint16 *bitmapData = reinterpret_cast<uint16 *>(bitmap->data_[pic]);
+			for (int i = 0; i < bitmap->width_ * bitmap->height_; i++, texDataPtr += 4, bitmapData++) {
+				uint16 pixel = *bitmapData;
+				int r = pixel >> 11;
+				texDataPtr[0] = (r << 3) | (r >> 2);
+				int g = (pixel >> 5) & 0x3f;
+				texDataPtr[1] = (g << 2) | (g >> 4);
+				int b = pixel & 0x1f;
+				texDataPtr[2] = (b << 3) | (b >> 2);
+				if (pixel == 0xf81f) { // transparent
+					texDataPtr[3] = 0;
+					bitmap->hasTransparency_ = true;
+				} else {
+					texDataPtr[3] = 255;
+				}
+			}
+
+			for (int i = 0; i < bitmap->num_tex_; i++) {
+				glBindTexture(GL_TEXTURE_2D, bitmap->tex_ids_[bitmap->num_tex_ * pic + i]);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+				glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+				     BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0,
+				     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+			}
+
+			glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+			glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap->width_);
+
+			int cur_tex_idx = bitmap->num_tex_ * pic;
+
+			for (int y = 0; y < bitmap->height_; y += BITMAP_TEXTURE_SIZE) {
+				for (int x = 0; x < bitmap->width_; x += BITMAP_TEXTURE_SIZE) {
+					int width  = (x + BITMAP_TEXTURE_SIZE >= bitmap->width_)  ? (bitmap->width_  - x) : BITMAP_TEXTURE_SIZE;
+					int height = (y + BITMAP_TEXTURE_SIZE >= bitmap->height_) ? (bitmap->height_ - y) : BITMAP_TEXTURE_SIZE;
+					glBindTexture(GL_TEXTURE_2D, bitmap->tex_ids_[cur_tex_idx]);
+					glTexSubImage2D(GL_TEXTURE_2D,
+						0,
+						0, 0,
+						width, height,
+						GL_RGBA,
+						GL_UNSIGNED_BYTE,
+						texData + (y * 4 * bitmap->width_) + (4 * x));
+					cur_tex_idx++;
+				}
+			}
+		}
+
+		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+		delete [] texData;
+	} else {
+		for (int pic = 0; pic < bitmap->num_images_; pic++) {
+			uint16 *zbufPtr = reinterpret_cast<uint16 *>(bitmap->data_[pic]);
+			for (int i = 0; i < (bitmap->width_ * bitmap->height_); i++) {
+				uint16 val = READ_LE_UINT16(bitmap->data_[pic] + 2 * i);
+				zbufPtr[i] = 0xffff - ((uint32) val) * 0x10000 / 100 / (0x10000 - val);
+			}
+
+			// Flip the zbuffer image to match what GL expects
+			for (int y = 0; y < bitmap->height_ / 2; y++) {
+				uint16 *ptr1 = zbufPtr + y * bitmap->width_;
+				uint16 *ptr2 = zbufPtr + (bitmap->height_ - 1 - y) * bitmap->width_;
+				for (int x = 0; x < bitmap->width_; x++, ptr1++, ptr2++) {
+					uint16 tmp = *ptr1;
+					*ptr1 = *ptr2;
+					*ptr2 = tmp;
+				}
+			}
+		}
+		bitmap->tex_ids_ = NULL;
+	}
+}
+
+void Driver::drawBitmap(const Bitmap *bitmap) {
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, 640, 480, 0, 0, 1);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+	glMatrixMode(GL_TEXTURE);
+	glLoadIdentity();
+	// A lot more may need to be put there : disabling Alpha test, blending, ...
+	// For now, just keep this here :-)
+	if (bitmap->format_ == 1 && bitmap->hasTransparency_) {
+		glEnable(GL_BLEND);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	}
+	else
+		glDisable(GL_BLEND);
+	glDisable(GL_LIGHTING);
+	glEnable(GL_TEXTURE_2D);
+	if (bitmap->format_ == 1) {		// Normal image
+		glDisable(GL_DEPTH_TEST);
+		glDepthMask(GL_FALSE);
+		glEnable(GL_SCISSOR_TEST);
+		glScissor(bitmap->x_, 480 - (bitmap->y_ + bitmap->height_), bitmap->width_, bitmap->height_);
+		int cur_tex_idx = bitmap->num_tex_ * (bitmap->curr_image_ - 1);
+		for (int y = bitmap->y_; y < (bitmap->y_ + bitmap->height_); y += BITMAP_TEXTURE_SIZE) {
+			for (int x = bitmap->x_; x < (bitmap->x_ + bitmap->width_); x += BITMAP_TEXTURE_SIZE) {
+				glBindTexture(GL_TEXTURE_2D, bitmap->tex_ids_[cur_tex_idx]);
+				glBegin(GL_QUADS);
+				glTexCoord2f(0.0, 0.0);
+				glVertex2i(x, y);
+				glTexCoord2f(1.0, 0.0);
+				glVertex2i(x + BITMAP_TEXTURE_SIZE, y);
+				glTexCoord2f(1.0, 1.0);
+				glVertex2i(x + BITMAP_TEXTURE_SIZE, y + BITMAP_TEXTURE_SIZE);
+				glTexCoord2f(0.0, 1.0);
+				glVertex2i(x, y + BITMAP_TEXTURE_SIZE);
+				glEnd();
+				cur_tex_idx++;
+			}
+		}
+
+		glDisable(GL_SCISSOR_TEST);
+		glDisable(GL_TEXTURE_2D);
+		glDisable(GL_BLEND);
+		glDepthMask(GL_TRUE);
+		glEnable(GL_DEPTH_TEST);
+	} else if (bitmap->format_ == 5) {	// ZBuffer image
+		// Only draw the manual zbuffer when we are not using screenblocks, and when enabled
+		if ((!ZBUFFER_GLOBAL) || SCREENBLOCKS_GLOBAL)
+			return;
+
+		g_driver->drawDepthBitmap(bitmap->x_, bitmap->y_, bitmap->width_, bitmap->height_, bitmap->data_[bitmap->curr_image_ - 1]);
+	}
+}
+
+void Driver::destroyBitmap(Bitmap *bitmap) {
+	if (bitmap->tex_ids_) {
+		glDeleteTextures(bitmap->num_tex_ * bitmap->num_images_, bitmap->tex_ids_);
+		delete[] bitmap->tex_ids_;
+	}
+}
+
+void Driver::createMaterial(Material *material, const char *data, const CMap *cmap) {
+	material->textures_ = new GLuint[material->num_images_];
+	glGenTextures(material->num_images_, material->textures_);
+	char *texdata = new char[material->width_ * material->height_ * 4];
+	for (int i = 0; i < material->num_images_; i++) {
+		char *texdatapos = texdata;
+		for (int y = 0; y < material->height_; y++) {
+			for (int x = 0; x < material->width_; x++) {
+				int col = *(uint8 *)(data);
+				if (col == 0)
+					memset(texdatapos, 0, 4); // transparent
+				else {
+					memcpy(texdatapos, cmap->colors + 3 * *(uint8 *)(data), 3);
+					texdatapos[3] = '\xff'; // fully opaque
+				}
+				texdatapos += 4;
+				data++;
+			}
+		}
+		glBindTexture(GL_TEXTURE_2D, material->textures_[i]);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, material->width_, material->height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, texdata);
+		data += 24;
+	}
+	delete[] texdata;
+}
+
+void Driver::selectMaterial(const Material *material) {
+	glBindTexture(GL_TEXTURE_2D, material->textures_[material->curr_image_]);
+	glMatrixMode(GL_TEXTURE);
+	glLoadIdentity();
+	glScalef(1.0f / material->width_, 1.0f / material->height_, 1);
+}
+
+void Driver::destroyMaterial(Material *material) {
+	glDeleteTextures(material->num_images_, material->textures_);
+	delete[] material->textures_;
 }
 
 void Driver::drawDepthBitmap(int x, int y, int w, int h, char *data) {
@@ -197,8 +710,7 @@
 	glDepthMask(GL_FALSE);
 	glEnable(GL_SCISSOR_TEST);
 
-	glScissor(offsetX, 480 - (offsetY + _smushHeight),
-		  _smushWidth, _smushHeight);
+	glScissor(offsetX, 480 - (offsetY + _smushHeight), _smushWidth, _smushHeight);
 
 	int curTexIdx = 0;
 	for (int y = 0; y < _smushHeight; y += BITMAP_TEXTURE_SIZE) {
@@ -232,31 +744,31 @@
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
 	emergFont = glGenLists(128);
-	for (i=32;i<127;i++) {
+	for (i = 32; i < 127; i++) {
 		glNewList(emergFont + i, GL_COMPILE);
-		glBitmap(8, 13, 0, 2, 10, 0, font[i-32]);
+		glBitmap(8, 13, 0, 2, 10, 0, font[i - 32]);
 		glEndList();
 	}
 }
 
 // Draw text string using emergency font
 void Driver::drawEmergString(int x, int y, const char *text, const Color &fgColor) {
-        glMatrixMode(GL_PROJECTION);
-        glPushMatrix();
-        glLoadIdentity();
-        glOrtho(0, 640, 480, 0, 0, 1);
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+	glOrtho(0, 640, 480, 0, 0, 1);
 
-        glMatrixMode(GL_MODELVIEW);
-        glLoadIdentity();
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
 	glDisable(GL_DEPTH_TEST);
 
-        glColor3f(fgColor.red(), fgColor.green(), fgColor.blue());
-        glRasterPos2i(x, y);
+	glColor3f(fgColor.red(), fgColor.green(), fgColor.blue());
+	glRasterPos2i(x, y);
 
-        glListBase(emergFont);
-        //glCallLists(strlen(strrchr(text, '/')) - 1, GL_UNSIGNED_BYTE, strrchr(text, '/') + 1);
-        glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
+	glListBase(emergFont);
+	//glCallLists(strlen(strrchr(text, '/')) - 1, GL_UNSIGNED_BYTE, strrchr(text, '/') + 1);
+	glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
 
-        glMatrixMode( GL_PROJECTION );
-        glPopMatrix();
+	glMatrixMode( GL_PROJECTION );
+	glPopMatrix();
 }

Index: driver_gl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- driver_gl.h	15 Apr 2004 20:20:04 -0000	1.8
+++ driver_gl.h	19 Apr 2004 09:56:33 -0000	1.9
@@ -23,38 +23,58 @@
 #include "bits.h"
 #include "vector3d.h"
 #include "color.h"
+#include "model.h"
+#include "colormap.h"
+#include "bitmap.h"
 
 #define BITMAP_TEXTURE_SIZE 256
 
 class Driver {
-	public:
-		Driver(int screenW, int screenH, int screenBPP);
+public:
+	Driver(int screenW, int screenH, int screenBPP);
 
-		void setupCamera(float fov, float nclip, float fclip, float roll);
-		void positionCamera(Vector3d pos, Vector3d interest);
+	void setupCamera(float fov, float nclip, float fclip, float roll);
+	void positionCamera(Vector3d pos, Vector3d interest);
 
-		void clearScreen(); 
-		void flipBuffer();
+	void clearScreen(); 
+	void flipBuffer();
 
-		void startActorDraw(Vector3d pos, float yaw, float pitch, float roll);
-		void finishActorDraw();
+	void startActorDraw(Vector3d pos, float yaw, float pitch, float roll);
+	void finishActorDraw();
+	
+	void set3DMode();
 
-		void drawDepthBitmap(int x, int y, int w, int h, char *data);
-		void drawBitmap();
+	void drawHierachyNode(const Model::HierNode *node);
+	void drawModelFace(const Model::Face *face, float *vertices, float *vertNormals, float *textureVerts);
+	void drawModel(const Model::Mesh *model);
 
-		void drawEmergString(int x, int y, const char *text, const Color &fgColor);
-		void loadEmergFont();
+	void updateMesh(const Model::Mesh *mesh);
+	void updateHierachyNode(const Model::HierNode *node);
 
-		void prepareSmushFrame(int width, int height, byte *bitmap);
-		void drawSmushFrame(int offsetX, int offsetY);
 
-	private:
-		GLuint emergFont;
-		int _smushNumTex;
-		GLuint *_smushTexIds;
-		int _smushWidth;
-		int _smushHeight;
+	void createMaterial(Material *material, const char *data, const CMap *cmap);
+	void selectMaterial(const Material *material);
+	void destroyMaterial(Material *material);
+
+	void createBitmap(Bitmap *bitmap);
+	void drawBitmap(const Bitmap *bitmap);
+	void destroyBitmap(Bitmap *bitmap);
+
+	void drawDepthBitmap(int x, int y, int w, int h, char *data);
+	void drawBitmap();
+
+	void drawEmergString(int x, int y, const char *text, const Color &fgColor);
+	void loadEmergFont();
+
+	void prepareSmushFrame(int width, int height, byte *bitmap);
+	void drawSmushFrame(int offsetX, int offsetY);
+
+private:
+	GLuint emergFont;
+	int _smushNumTex;
+	GLuint *_smushTexIds;
+	int _smushWidth;
+	int _smushHeight;
 };
 
 extern Driver *g_driver;
-

Index: engine.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/engine.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- engine.cpp	15 Apr 2004 20:39:09 -0000	1.30
+++ engine.cpp	19 Apr 2004 09:56:33 -0000	1.31
@@ -132,21 +132,18 @@
 					g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY());
 			}
 
-			glMatrixMode(GL_MODELVIEW);
+			g_driver->set3DMode();
 
-			glEnable(GL_DEPTH_TEST);
 			if (currScene_ != NULL)
 				currScene_->setupCamera();
 
 			// Draw actors
 			if (!g_smush->isPlaying()) {
-				glEnable(GL_TEXTURE_2D);
 				for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) {
 					Actor *a = *i;
 					if (a->inSet(currScene_->name()) && a->visible())
 						a->draw();
 				}
-				glDisable(GL_TEXTURE_2D);
 				//screenBlocksDrawDebug();
 			}
 

Index: material.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/material.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- material.cpp	24 Feb 2004 21:09:53 -0000	1.7
+++ material.cpp	19 Apr 2004 09:56:33 -0000	1.8
@@ -20,17 +20,15 @@
 #include "colormap.h"
 #include "bits.h"
 #include "debug.h"
+#include "driver_gl.h"
 
-Material::Material(const char *filename, const char *data, int len,
-				const CMap &cmap) :
+Material::Material(const char *filename, const char *data, int len, const CMap &cmap) :
 		Resource(filename) {
 	if (len < 4 || memcmp(data, "MAT ", 4) != 0)
 		error("invalid magic loading texture\n");
 
 	num_images_ = READ_LE_UINT32(data + 12);
 	curr_image_ = 0;
-	textures_ = new GLuint[num_images_];
-	glGenTextures(num_images_, textures_);
 	width_ = READ_LE_UINT32(data + 76 + num_images_ * 40);
 	height_ = READ_LE_UINT32(data + 80 + num_images_ * 40);
 
@@ -39,44 +37,14 @@
 	}
 
 	data += 100 + num_images_ * 40;
-	char *texdata = new char[width_ * height_ * 4];
-	for (int i = 0; i < num_images_; i++) {
-		char *texdatapos = texdata;
-		for (int y = 0; y < height_; y++) {
-			for (int x = 0; x < width_; x++) {
-				int col = *(uint8 *)(data);
-				if (col == 0)
-					memset(texdatapos, 0, 4); // transparent
-				else {
-					memcpy(texdatapos, cmap.colors + 3 * *(uint8 *)(data), 3);
-					texdatapos[3] = '\xff'; // fully opaque
-				}
-				texdatapos += 4;
-				data++;
-			}
-		}
-		glBindTexture(GL_TEXTURE_2D, textures_[i]);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0,
-			GL_RGBA, GL_UNSIGNED_BYTE, texdata);
-		data += 24;
-	}
 
-	delete[] texdata;
+	g_driver->createMaterial(this, data, &cmap);
 }
 
 void Material::select() const {
-	glBindTexture(GL_TEXTURE_2D, textures_[curr_image_]);
-	glMatrixMode(GL_TEXTURE);
-	glLoadIdentity();
-	glScalef(1.0f / width_, 1.0f / height_, 1);
+	g_driver->selectMaterial(this);
 }
 
 Material::~Material() {
-	glDeleteTextures(num_images_, textures_);
-	delete[] textures_;
+	g_driver->destroyMaterial(this);
 }

Index: material.h
===================================================================
RCS file: /cvsroot/scummvm/residual/material.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- material.h	24 Feb 2004 21:09:53 -0000	1.3
+++ material.h	19 Apr 2004 09:56:33 -0000	1.4
@@ -41,7 +41,7 @@
 
 	~Material();
 
-private:
+//private:
 	int num_images_, curr_image_;
 	int width_, height_;
 	GLuint *textures_;

Index: model.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/model.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- model.cpp	14 Apr 2004 21:03:50 -0000	1.17
+++ model.cpp	19 Apr 2004 09:56:33 -0000	1.18
@@ -24,11 +24,10 @@
 #include "textsplit.h"
 #include <cstring>
 #include <SDL.h>
-#include <SDL_opengl.h>
 #include "screen.h"
+#include "driver_gl.h"
 
-Model::Model(const char *filename, const char *data, int len,
-			 const CMap &cmap) : Resource(filename) {
+Model::Model(const char *filename, const char *data, int len, const CMap &cmap) : Resource(filename) {
 	if (len >= 4 && std::memcmp(data, "LDOM", 4) == 0)
 		loadBinary(data, cmap);
 	else {
@@ -126,61 +125,7 @@
 }
 
 void Model::Mesh::update() {
-	GLdouble modelView[500];
-	GLdouble projection[500];
-	GLint viewPort[500];
-
-	glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
-	glGetDoublev( GL_PROJECTION_MATRIX, projection );
-	glGetIntegerv( GL_VIEWPORT, viewPort);
-
-	GLdouble top = 1000;
-	GLdouble right = -1000;
-	GLdouble left = 1000;
-	GLdouble bottom = -1000;
-
-	for (int i = 0; i < numFaces_; i++) {
-		Vector3d v;
-		Matrix4 tempMatrix = matrix_;
-		float* pVertices;
-		int j;
-		float bestDepth = 0;
-
-		for( j =0; j< faces_[i].numVertices_; j++ ) {
-			pVertices = vertices_ + 3 * faces_[i].vertices_[j];
-
-			v.set( *(pVertices), *(pVertices+1), *(pVertices+2) );
-
-			tempMatrix.rot_.transform( &v );
-			v+= tempMatrix.pos_;
-
-			GLdouble winX;
-			GLdouble winY;
-			GLdouble winZ;
-
-			gluProject( v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ);
-
-			if( winX > right )
-				right = winX;
-			if( winX < left )
-				left = winX;
-			if( winY < top )
-				top = winY;
-			if( winY > bottom )
-				bottom = winY;
-
-			if( winZ> bestDepth )
-				bestDepth = winZ;
-
-		}
-
-		//screenBlocksAddRectangle( top, right, left, bottom, bestDepth );
-	}
-
-	glDisable(GL_DEPTH_TEST);
-	glPointSize( 3.f );
-	glColor4f( 1.f, 1.f, 0.f, 1.f );
-	glDisable(GL_TEXTURE_2D );
+	g_driver->updateMesh(this);
 }
 
 void Model::Face::loadBinary(const char *&data, ResPtr<Material> *materials) {
@@ -222,55 +167,54 @@
 	delete[] texVertices_;
 }
 
-void Model::HierNode::loadBinary(const char *&data,
-	Model::HierNode *hierNodes,
-	const Geoset &g) {
-		memcpy(name_, data, 64);
-		flags_ = READ_LE_UINT32(data + 64);
-		type_ = READ_LE_UINT32(data + 72);
-		int meshNum = READ_LE_UINT32(data + 76);
-		if (meshNum < 0)
-			mesh_ = NULL;
-		else
-			mesh_ = g.meshes_ + meshNum;
-		depth_ = READ_LE_UINT32(data + 80);
-		int parentPtr = READ_LE_UINT32(data + 84);
-		numChildren_ = READ_LE_UINT32(data + 88);
-		int childPtr = READ_LE_UINT32(data + 92);
-		int siblingPtr = READ_LE_UINT32(data + 96);
-		pivot_ = get_vector3d(data + 100);
-		pos_ = get_vector3d(data + 112);
-		pitch_ = get_float(data + 124);
-		yaw_ = get_float(data + 128);
-		roll_ = get_float(data + 132);
-		animPos_ = pos_;
-		animPitch_ = pitch_;
-		animYaw_ = yaw_;
-		animRoll_ = roll_;
-		priority_ = -1;
-		totalWeight_ = 1;
+void Model::HierNode::loadBinary(const char *&data, Model::HierNode *hierNodes, const Geoset &g) {
+	memcpy(name_, data, 64);
+	flags_ = READ_LE_UINT32(data + 64);
+	type_ = READ_LE_UINT32(data + 72);
+	int meshNum = READ_LE_UINT32(data + 76);
+	if (meshNum < 0)
+		mesh_ = NULL;
+	else
+		mesh_ = g.meshes_ + meshNum;
+	depth_ = READ_LE_UINT32(data + 80);
+	int parentPtr = READ_LE_UINT32(data + 84);
+	numChildren_ = READ_LE_UINT32(data + 88);
+	int childPtr = READ_LE_UINT32(data + 92);
+	int siblingPtr = READ_LE_UINT32(data + 96);
+	pivot_ = get_vector3d(data + 100);
+	pos_ = get_vector3d(data + 112);
+	pitch_ = get_float(data + 124);
+	yaw_ = get_float(data + 128);
+	roll_ = get_float(data + 132);
+	animPos_ = pos_;
+	animPitch_ = pitch_;
+	animYaw_ = yaw_;
+	animRoll_ = roll_;
+	priority_ = -1;
+	totalWeight_ = 1;
 
-		data += 184;
+	data += 184;
 
-		if (parentPtr != 0) {
-			parent_ = hierNodes + READ_LE_UINT32(data);
-			data += 4;
-		} else
-			parent_ = NULL;
-		if (childPtr != 0) {
-			child_ = hierNodes + READ_LE_UINT32(data);
-			data += 4;
-		} else
-			child_ = NULL;
-		if (siblingPtr != 0) {
-			sibling_ = hierNodes + READ_LE_UINT32(data);
-			data += 4;
-		} else
-			sibling_ = NULL;
+	if (parentPtr != 0) {
+		parent_ = hierNodes + READ_LE_UINT32(data);
+		data += 4;
+	} else
+		parent_ = NULL;
+	if (childPtr != 0) {
+		child_ = hierNodes + READ_LE_UINT32(data);
+		data += 4;
+	} else
+		child_ = NULL;
+	if (siblingPtr != 0) {
+		sibling_ = hierNodes + READ_LE_UINT32(data);
+		data += 4;
+	} else
+		sibling_ = NULL;
 
-		meshVisible_ = hierVisible_ = true;
-		totalWeight_ = 1;
-	}
+	meshVisible_ = true;
+	hierVisible_ = true;
+	totalWeight_ = 1;
+}
 
 void Model::draw() const {
 	rootHierNode_->draw();
@@ -286,8 +230,7 @@
 		if (result[i].child_ != NULL)
 			result[i].child_ = result + (rootHierNode_[i].child_ - rootHierNode_);
 		if (result[i].sibling_ != NULL)
-			result[i].sibling_ = result + (rootHierNode_[i].sibling_ -
-		rootHierNode_);
+			result[i].sibling_ = result + (rootHierNode_[i].sibling_ - rootHierNode_);
 	}
 	return result;
 }
@@ -357,13 +300,13 @@
 		rootHierNode_[num].yaw_ = yaw;
 		rootHierNode_[num].roll_ = roll;
 		rootHierNode_[num].pivot_ = Vector3d(pivotx, pivoty, pivotz);
-
-		rootHierNode_[num].meshVisible_ =
+		rootHierNode_[num].meshVisible_ = true;
 		rootHierNode_[num].hierVisible_ = true;
 		rootHierNode_[num].totalWeight_ = 1;
 	}
-	if (! ts.eof())
-	warning("Unexpected junk at end of model text\n");
+
+	if (!ts.eof())
+		warning("Unexpected junk at end of model text\n");
 }
 
 void Model::Geoset::loadText(TextSplitter &ts, ResPtr<Material> *materials) {
@@ -449,8 +392,7 @@
 		for (int j = 0; j < verts; j++) {
 			int readlen2;
 			if (std::sscanf(ts.currentLine() + readlen, " %d, %d%n",
-				faces_[num].vertices_ + j,
-				faces_[num].texVertices_ + j, &readlen2) < 2)
+				faces_[num].vertices_ + j, faces_[num].texVertices_ + j, &readlen2) < 2)
 					error("Could not read vertex indices in line `%s'\n",
 			ts.currentLine());
 			readlen += readlen2;
@@ -468,31 +410,7 @@
 }
 
 void Model::HierNode::draw() const {
-	if (hierVisible_) {
-		glMatrixMode(GL_MODELVIEW);
-		glPushMatrix();
-
-		glTranslatef(animPos_.x() / totalWeight_, animPos_.y() / totalWeight_,
-			animPos_.z() / totalWeight_);
-		glRotatef(animYaw_ / totalWeight_, 0, 0, 1);
-		glRotatef(animPitch_ / totalWeight_, 1, 0, 0);
-		glRotatef(animRoll_ / totalWeight_, 0, 1, 0);
-
-		if (mesh_ != NULL && meshVisible_) {
-			glPushMatrix();
-			glTranslatef(pivot_.x(), pivot_.y(), pivot_.z());
-			mesh_->draw();
-			glMatrixMode(GL_MODELVIEW);
-			glPopMatrix();
-		}
-		if (child_ != NULL) {
-			child_->draw();
-			glMatrixMode(GL_MODELVIEW);
-		}
-		glPopMatrix();
-	}
-	if (sibling_ != NULL)
-		sibling_->draw();
+	g_driver->drawHierachyNode(this);
 }
 
 void Model::HierNode::addChild(HierNode *child) {
@@ -518,19 +436,8 @@
 }
 
 void Model::HierNode::update() {
-
-	glMatrixMode(GL_MODELVIEW);
-	glPushMatrix();
-
-	glTranslatef(animPos_.x() / totalWeight_, animPos_.y() / totalWeight_,
-		animPos_.z() / totalWeight_);
-	glRotatef(animYaw_ / totalWeight_, 0, 0, 1);
-	glRotatef(animPitch_ / totalWeight_, 1, 0, 0);
-	glRotatef(animRoll_ / totalWeight_, 0, 1, 0);
-
-
-	localMatrix_.pos_.set( animPos_.x() / totalWeight_, animPos_.y() / totalWeight_, animPos_.z() / totalWeight_ );
-	localMatrix_.rot_.buildFromPitchYawRoll( animPitch_ / totalWeight_, animYaw_ / totalWeight_, animRoll_ / totalWeight_);
+	localMatrix_.pos_.set(animPos_.x() / totalWeight_, animPos_.y() / totalWeight_, animPos_.z() / totalWeight_);
+	localMatrix_.rot_.buildFromPitchYawRoll(animPitch_ / totalWeight_, animYaw_ / totalWeight_, animRoll_ / totalWeight_);
 
 	matrix_ *= localMatrix_;
 
@@ -538,220 +445,17 @@
 
 	pivotMatrix.translate( pivot_.x(), pivot_.y(), pivot_.z() );
 
-	if( mesh_ != NULL ) {
-		glPushMatrix();
-		glTranslatef(pivot_.x(), pivot_.y(), pivot_.z());
-		mesh_->matrix_ = pivotMatrix;
-		mesh_->update();
-
-		glMatrixMode(GL_MODELVIEW);
-		glPopMatrix();
-	}
-
-	if( child_ != NULL ) {
-		child_->setMatrix( matrix_ );
-		child_->update();
-		glMatrixMode(GL_MODELVIEW);
-	}
-
-	glPopMatrix();
+	g_driver->updateHierachyNode(this);
 }
 
-
 void Model::Mesh::draw() const {
 	for (int i = 0; i < numFaces_; i++)
 		faces_[i].draw(vertices_, vertNormals_, textureVerts_);
 
-	GLdouble modelView[500];
-	GLdouble projection[500];
-	GLint viewPort[500];
-
-	glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
-	glGetDoublev( GL_PROJECTION_MATRIX, projection );
-	glGetIntegerv( GL_VIEWPORT, viewPort);
-
-	// Yaz: debug
-	// this draw the model node in red
-	//glMatrixMode(GL_PROJECTION);
-	/*glPushMatrix();
-	glLoadIdentity();
-
-	GLdouble modelView[500];
-	GLdouble projection[500];
-	GLint viewPort[500];
-
-	glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
-	glGetDoublev( GL_PROJECTION_MATRIX, projection );
-	glGetIntegerv( GL_VIEWPORT, viewPort);
-
-	glDisable(GL_DEPTH_TEST);
-	glPointSize( 3.f );
-	glColor4f( 1.f, 0.f, 0.f, 1.f );
-	glDisable(GL_TEXTURE_2D );
-	glBegin( GL_POINTS );
-	glVertex3f( matrix_.pos_.x(), matrix_.pos_.y(), matrix_.pos_.z() );
-	glEnd();
-	glEnable(GL_DEPTH_TEST);
-	glPopMatrix();
-	glEnable(GL_TEXTURE_2D );*/
-
-	// Yaz: debug
-	// this draw the poly points
-
-	/*glPushMatrix();
-	glLoadIdentity();
-	glPointSize( 3.f );
-	glColor4f( 0.f, 1.f, 0.f, 1.f );
-	glDisable(GL_TEXTURE_2D );
-	{
-		GLdouble modelView[500];
-		GLdouble projection[500];
-		GLint viewPort[500];
-
-		glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
-		glGetDoublev( GL_PROJECTION_MATRIX, projection );
-		glGetIntegerv( GL_VIEWPORT, viewPort);
-	}
-
-	glBegin( GL_POINTS );
-
-	for (int i = 0; i < numFaces_; i++) {
-		Vector3d v;
-		Matrix4 tempMatrix = matrix_;
-		float* pVertices;
-		int j;
-
-		for( j =0; j< faces_[i].numVertices_; j++ ) {
-			pVertices = vertices_ + 3 * faces_[i].vertices_[j];
-
-			v.set( *(pVertices), *(pVertices+1), *(pVertices+2) );
-
-			tempMatrix.rot_.transform( &v );
-			v+= tempMatrix.pos_;
-
-			glVertex3f( v.x(), v.y(), v.z() );
-
-		}
-	}
-
-	glEnd();
-	glEnable(GL_DEPTH_TEST);
-	glPopMatrix();
-	glEnable(GL_TEXTURE_2D ); */
-
-	// Ender: HACK HACK HACK
-	// Mannys head isn't computed correctly, so bail out to prevent memory corruption.
-	// at least until it IS computed, or the DirtyScreen code has bounds checking :)
-	//if (strstr(name_, "m_head_1"))
-	//	return;
-
-	// Yaz: debug
-	// this compute the dirty rect for the mesh
-	glPushMatrix();
-	glLoadIdentity();
-
-	GLdouble top = 1000;
-	GLdouble right = -1000;
-	GLdouble left = 1000;
-	GLdouble bottom = -1000;
-
-	for (int i = 0; i < numFaces_; i++) {
-		Vector3d v;
-		Matrix4 tempMatrix = matrix_;
-		float* pVertices;
-		int j;
-		float bestDepth = 0;
-
-		for( j =0; j< faces_[i].numVertices_; j++ ) {
-			GLdouble modelView[500];
-			GLdouble projection[500];
-			GLint viewPort[500];
-
-			glGetDoublev( GL_MODELVIEW_MATRIX, modelView );
-			glGetDoublev( GL_PROJECTION_MATRIX, projection );
-			glGetIntegerv( GL_VIEWPORT, viewPort);
-
-			pVertices = vertices_ + 3 * faces_[i].vertices_[j];
-
-			v.set( *(pVertices), *(pVertices+1), *(pVertices+2) );
-
-			tempMatrix.rot_.transform( &v );
-			v+= tempMatrix.pos_;
-
-			GLdouble winX;
-			GLdouble winY;
-			GLdouble winZ;
-
-			gluProject( v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ);
-
-			if( winX > right )
-				right = winX;
-			if( winX < left )
-				left = winX;
-			if( winY < top )
-				top = winY;
-			if( winY > bottom )
-				bottom = winY;
-
-			if( winZ> bestDepth )
-				bestDepth = winZ;
-		}
-
-		if (SCREENBLOCKS_GLOBAL)
-			screenBlocksAddRectangle( (int)top, (int)right, (int)left, (int)bottom, (int)bestDepth );
-	}
-	/*
-	glDisable(GL_DEPTH_TEST);
-	glPointSize( 3.f );
-	glColor4f( 1.f, 1.f, 0.f, 1.f );
-	glDisable(GL_TEXTURE_2D );
-
-	glBegin(GL_LINES);
-
-	GLdouble objx;
-	GLdouble objy;
-	GLdouble objz;
-
-	// top
-	gluUnProject( left, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-	gluUnProject( right, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-
-	// bottom
-	gluUnProject( left, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-	gluUnProject( right, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-
-	// left
-	gluUnProject( left, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-	gluUnProject( left, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-
-	// right
-	gluUnProject( right, top, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-	gluUnProject( right, bottom, 1.f, modelView, projection, viewPort, &objx, &objy, &objz );
-	glVertex3f( objx, objy, objz );
-
-	glEnd(); 
-	glEnable(GL_DEPTH_TEST);
-	glEnable(GL_TEXTURE_2D ); 
-	*/
- 	glPopMatrix();
-	}
+	g_driver->drawModel(this);
+}
 
 void Model::Face::draw(float *vertices, float *vertNormals, float *textureVerts) const {
 	material_->select();
-	glNormal3fv(normal_.coords_);
-	glBegin(GL_POLYGON);
-	for (int i = 0; i < numVertices_; i++) {
-		glNormal3fv(vertNormals + 3 * vertices_[i]);
-		if (texVertices_ != NULL)
-			glTexCoord2fv(textureVerts + 2 * texVertices_[i]);
-		glVertex3fv(vertices + 3 * vertices_[i]);
-	}
-	glEnd();
+	g_driver->drawModelFace(this, vertices, vertNormals, textureVerts);
 }

Index: model.h
===================================================================
RCS file: /cvsroot/scummvm/residual/model.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- model.h	24 Feb 2004 22:43:32 -0000	1.5
+++ model.h	19 Apr 2004 09:56:34 -0000	1.6
@@ -67,7 +67,7 @@
 	HierNode *copyHierarchy();
 	int numNodes() const { return numHierNodes_; }
 
-private:
+//private:
 	struct Face {
 		void loadBinary(const char *&data, ResPtr<Material> *materials);
 		void draw(float *vertices, float *vertNormals, float *textureVerts) const;





More information about the Scummvm-git-logs mailing list