Mixed D&C fixes

This commit is contained in:
mazmazz 2018-12-26 23:31:55 -05:00
parent 1654aa34c5
commit c5c799006a
2 changed files with 144 additions and 67 deletions

View file

@ -17,7 +17,7 @@
#define NUMVERTEXNORMALS 162
// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and
// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and
// you'll have your normals.
float avertexnormals[NUMVERTEXNORMALS][3] = {
{-0.525731f, 0.000000f, 0.850651f},
@ -195,9 +195,9 @@ typedef struct
int numXYZ; // Number of vertices in each frame
int numST; // Number of texture coordinates in each frame.
int numTris; // Number of triangles in each frame
int numGLcmds; // Number of dwords (4 bytes) in the gl command list.
int numGLcmds; // Number of dwords (4 bytes) in the gl command list.
int numFrames; // Number of frames
int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names.
int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names.
int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates
int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles
int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames
@ -233,10 +233,36 @@ typedef struct
// Load the model
model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
{
useFloat = true;
model_t *retModel = NULL;
md2header_t *header;
size_t fileLen;
int i, j;
size_t namelen;
char *texturefilename;
const char *texPos;
char *buffer;
const float WUNITS = 1.0f;
float dataScale = WUNITS;
int t;
// MD2 currently does not work with tinyframes, so force useFloat = true
//
// <SSNTails>
// the UV coordinates in MD2 are not compatible with glDrawElements like MD3 is. So they need to be loaded as full float.
//
// MD2 is intended to be draw in triangle strips and fans
// not very compatible with a modern GL implementation, either
// so the idea would be to full float expand it, and put it in a vertex buffer object
// I'm sure there's a way to convert the UVs to 'tinyframes', but maybe that's a job for someone else.
// You'd have to decompress the model, then recompress, reindexing the triangles and weeding out duplicate coordinates
// I already have the decompression work done
useFloat = true;
FILE *f = fopen(fileName, "rb");
if (!f)
@ -244,13 +270,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0);
size_t fileLen;
//size_t fileLen;
int i, j;
//int i, j;
size_t namelen;
char *texturefilename;
const char *texPos = strchr(fileName, '/');
//size_t namelen;
//char *texturefilename;
texPos = strchr(fileName, '/');
if (texPos)
{
@ -276,7 +302,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
fseek(f, 0, SEEK_SET);
// read in file
char *buffer = malloc(fileLen);
buffer = malloc(fileLen);
fread(buffer, fileLen, 1, f);
fclose(f);
@ -286,8 +312,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->numMeshes = 1; // MD2 only has one mesh
retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0);
retModel->meshes[0].numFrames = header->numFrames;
const float WUNITS = 1.0f;
float dataScale = WUNITS;
// const float WUNITS = 1.0f;
// float dataScale = WUNITS;
// Tris and ST are simple structures that can be straight-copied
md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris];
@ -302,7 +328,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0);
int t;
// int t;
for (t = 0; t < retModel->numMaterials; t++)
{
retModel->materials[t].ambient[0] = 0.8f;
@ -370,14 +396,26 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
if (!useFloat) // Decompress to MD3 'tinyframe' space
{
byte *ptr;
md2triangle_t *trisPtr;
unsigned short *indexptr;
float *uvptr;
dataScale = 0.015624f; // 1 / 64.0f
retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0);
retModel->meshes[0].numVertices = header->numXYZ;
retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0);
byte *ptr = (byte*)frames;
ptr = (byte*)frames;
for (i = 0; i < header->numFrames; i++, ptr += header->framesize)
{
short *vertptr;
char *normptr;
// char *tanptr;
md2vertex_t *vertex;
md2frame_t *framePtr = (md2frame_t*)ptr;
retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0);
retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0);
@ -386,14 +424,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
// retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag);
retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0);
short *vertptr = retModel->meshes[0].tinyframes[i].vertices;
char *normptr = retModel->meshes[0].tinyframes[i].normals;
vertptr = retModel->meshes[0].tinyframes[i].vertices;
normptr = retModel->meshes[0].tinyframes[i].normals;
// char *tanptr = retModel->meshes[0].tinyframes[i].tangents;
// tanptr = retModel->meshes[0].tinyframes[i].tangents;
retModel->meshes[0].tinyframes[i].material = &retModel->materials[0];
framePtr++; // Advance to vertex list
md2vertex_t *vertex = (md2vertex_t*)framePtr;
vertex = (md2vertex_t*)framePtr;
framePtr--;
for (j = 0; j < header->numXYZ; j++, vertex++)
{
@ -412,9 +450,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
}
// This doesn't need to be done every frame!
md2triangle_t *trisPtr = tris;
unsigned short *indexptr = retModel->meshes[0].indices;
float *uvptr = (float*)retModel->meshes[0].uvs;
trisPtr = tris;
indexptr = retModel->meshes[0].indices;
uvptr = (float*)retModel->meshes[0].uvs;
for (j = 0; j < header->numTris; j++, trisPtr++)
{
*indexptr = trisPtr->meshIndex[0];
@ -434,12 +472,17 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
}
else // Full float loading method
{
md2triangle_t *trisPtr;
float *uvptr;
byte *ptr;
retModel->meshes[0].numVertices = header->numTris * 3;
retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0);
retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0);
md2triangle_t *trisPtr = tris;
float *uvptr = retModel->meshes[0].uvs;
trisPtr = tris;
uvptr = retModel->meshes[0].uvs;
for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++)
{
*uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth;
@ -450,15 +493,19 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
*uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight);
}
byte *ptr = (byte*)frames;
ptr = (byte*)frames;
for (i = 0; i < header->numFrames; i++, ptr += header->framesize)
{
float *vertptr, *normptr;
md2vertex_t *vertex;
md2frame_t *framePtr = (md2frame_t*)ptr;
retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0);
retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0);
// if (retModel->materials[0].lightmap)
// retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag);
float *vertptr, *normptr;
//float *vertptr, *normptr;
normptr = (float*)retModel->meshes[0].frames[i].normals;
vertptr = (float*)retModel->meshes[0].frames[i].vertices;
trisPtr = tris;
@ -466,7 +513,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->meshes[0].frames[i].material = &retModel->materials[0];
framePtr++; // Advance to vertex list
md2vertex_t *vertex = (md2vertex_t*)framePtr;
vertex = (md2vertex_t*)framePtr;
framePtr--;
for (j = 0; j < header->numTris; j++, trisPtr++)
{

View file

@ -1652,8 +1652,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
GLfloat diffuse[4];
float pol = 0.0f;
scale *= 0.5f;
float scalex = scale, scaley = scale, scalez = scale;
float scalex, scaley, scalez;
boolean useTinyFrames;
@ -1662,6 +1661,12 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
// Because Otherwise, scaling the screen negatively vertically breaks the lighting
GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f};
// Affect input model scaling
scale *= 0.5f;
scalex = scale;
scaley = scale;
scalez = scale;
if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length
{
UINT32 newtime = (duration - tics); // + 1;
@ -1779,11 +1784,15 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
}
else
{
short *vertPtr;
char *normPtr;
int j;
// Dangit, I soooo want to do this in a GLSL shader...
AllocLerpTinyBuffer(mesh->numVertices * sizeof(short) * 3);
short *vertPtr = vertTinyBuffer;
char *normPtr = normTinyBuffer;
int j = 0;
vertPtr = vertTinyBuffer;
normPtr = normTinyBuffer;
j = 0;
for (j = 0; j < mesh->numVertices * 3; j++)
{
@ -1816,10 +1825,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
}
else
{
float *vertPtr;
float *normPtr;
// Dangit, I soooo want to do this in a GLSL shader...
AllocLerpBuffer(mesh->numVertices * sizeof(float) * 3);
float *vertPtr = vertBuffer;
float *normPtr = normBuffer;
vertPtr = vertBuffer;
normPtr = normBuffer;
int j = 0;
for (j = 0; j < mesh->numVertices * 3; j++)
@ -1936,6 +1948,14 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
float xfix, yfix;
INT32 texsize = 2048;
const float blackBack[16] =
{
-16.0f, -16.0f, 6.0f,
-16.0f, 16.0f, 6.0f,
16.0f, 16.0f, 6.0f,
16.0f, -16.0f, 6.0f
};
// Use a power of two texture, dammit
if(screen_width <= 1024)
texsize = 1024;
@ -1949,13 +1969,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
pglDisable(GL_DEPTH_TEST);
pglDisable(GL_BLEND);
const float blackBack[16] =
{
-16.0f, -16.0f, 6.0f,
-16.0f, 16.0f, 6.0f,
16.0f, 16.0f, 6.0f,
16.0f, -16.0f, 6.0f
};
// const float blackBack[16]
pglEnableClientState(GL_VERTEX_ARRAY);
@ -1971,6 +1985,9 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
{
for(y=0;y<SCREENVERTS-1;y++)
{
float stCoords[8];
float vertCoords[12];
// Used for texture coordinates
// Annoying magic numbers to scale the square texture to
// a non-square screen..
@ -1979,7 +1996,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
float_nextx = (float)(x+1)/(xfix);
float_nexty = (float)(y+1)/(yfix);
float stCoords[8];
// float stCoords[8];
stCoords[0] = float_x;
stCoords[1] = float_y;
stCoords[2] = float_x;
@ -1991,7 +2008,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
pglTexCoordPointer(2, GL_FLOAT, 0, stCoords);
float vertCoords[12];
// float vertCoords[12];
vertCoords[0] = points[x][y][0];
vertCoords[1] = points[x][y][1];
vertCoords[2] = 4.4f;
@ -2101,14 +2118,6 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void)
float xfix, yfix;
INT32 texsize = 2048;
if(screen_width <= 1024)
texsize = 1024;
if(screen_width <= 512)
texsize = 512;
xfix = 1/((float)(texsize)/((float)((screen_width))));
yfix = 1/((float)(texsize)/((float)((screen_height))));
const float screenVerts[12] =
{
-1.0f, -1.0f, 1.0f,
@ -2118,6 +2127,18 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void)
};
float fix[8];
if(screen_width <= 1024)
texsize = 1024;
if(screen_width <= 512)
texsize = 512;
xfix = 1/((float)(texsize)/((float)((screen_width))));
yfix = 1/((float)(texsize)/((float)((screen_height))));
// const float screenVerts[12]
// float fix[8];
fix[0] = 0.0f;
fix[1] = 0.0f;
fix[2] = 0.0f;
@ -2151,6 +2172,24 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha)
INT32 fademaskdownloaded = tex_downloaded; // the fade mask that has been set
const float screenVerts[12] =
{
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
float fix[8];
const float defaultST[8] =
{
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f
};
(void)alpha;
// Use a power of two texture, dammit
@ -2162,15 +2201,9 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha)
xfix = 1/((float)(texsize)/((float)((screen_width))));
yfix = 1/((float)(texsize)/((float)((screen_height))));
const float screenVerts[12] =
{
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
// const float screenVerts[12]
float fix[8];
// float fix[8];
fix[0] = 0.0f;
fix[1] = 0.0f;
fix[2] = 0.0f;
@ -2207,13 +2240,7 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha)
pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
const float defaultST[8] =
{
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f
};
// const float defaultST[8]
pglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
@ -2304,6 +2331,9 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
FRGBAFloat clearColour;
INT32 texsize = 2048;
float off[12];
float fix[8];
if(screen_width <= 1024)
texsize = 1024;
if(screen_width <= 512)
@ -2325,7 +2355,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
yoff = newaspect / origaspect;
}
float off[12];
// float off[12];
off[0] = -xoff;
off[1] = -yoff;
off[2] = 1.0f;
@ -2339,7 +2369,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
off[10] = -yoff;
off[11] = 1.0f;
float fix[8];
// float fix[8];
fix[0] = 0.0f;
fix[1] = 0.0f;
fix[2] = 0.0f;