#include "screen.h" #include unsigned short int dataTemp[640*480]; screenBlockDataStruct screenBlockData[NUM_SCREEN_BLOCK_WIDTH][NUM_SCREEN_BLOCK_HEIGHT]; void screenBlocksReset() { int i; int j; for( i = 0; i < NUM_SCREEN_BLOCK_WIDTH; i++ ) { for( j = 0; j < NUM_SCREEN_BLOCK_HEIGHT; j++ ) { screenBlockData[i][j].isDirty = false; } } } float getZbufferBlockDepth( char* zbuffer, int x, int y ) { unsigned short int buffer[SCREEN_BLOCK_WIDTH * SCREEN_BLOCK_HEIGHT]; char* readPtr; char* writePtr; int i; int j; writePtr = (char*)buffer; for( i = 0; i <16; i++) { readPtr = zbuffer + (y*16+i) * 640 + (x*16); for(j=0; j<16; j++) { *(writePtr++) = *(readPtr++); *(writePtr++) = *(readPtr++); } } unsigned short int bDepth = 0xFFFF; for( i = 0; i buffer[i]) bDepth = buffer[i]; } return ((float)bDepth/65535); } void screenBlocksInit(char* zbuffer) { int i; int j; memcpy( dataTemp, zbuffer, 640*480*2); for( i = 0; i < NUM_SCREEN_BLOCK_WIDTH; i++ ) { for( j = 0; j < NUM_SCREEN_BLOCK_HEIGHT; j++ ) { screenBlockData[i][j].isDirty = false; screenBlockData[i][j].depth = getZbufferBlockDepth( zbuffer, i, j ); } } } void screenBlocksInitEmpty() { int i; int j; for( i = 0; i < NUM_SCREEN_BLOCK_WIDTH; i++ ) { for( j = 0; j < NUM_SCREEN_BLOCK_HEIGHT; j++ ) { screenBlockData[i][j].isDirty = false; screenBlockData[i][j].depth = 1.f; } } } void screenBlocksAddRectangle( int top, int right, int left, int bottom, float depth ) { // clip the rectange to the screen size int tempHeight = bottom-top; top = 480-bottom; bottom = top + tempHeight; if(top<0) top = 0; if(top>=SCREEN_HEIGHT) top = SCREEN_HEIGHT-1; if(bottom<0) bottom = 0; if(bottom>=SCREEN_HEIGHT) bottom = SCREEN_HEIGHT-1; if(left<0) left = 0; if(left>=SCREEN_WIDTH) left = SCREEN_WIDTH-1; if(right<0) right = 0; if(right>=SCREEN_WIDTH) right = SCREEN_WIDTH-1; // exit in case of bad rectangle if((left > right) || (top > bottom)) return; int firstLeft; int firstTop; int width; int height; firstLeft = left / 16; firstTop = top /16; width = (right - left) / 16; if((right-left)%16) width++; height = (bottom - top) / 16; if((bottom - top)%16) height++; // temp hack width++; height++; int i; int j; for(i=firstLeft; i