mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 20:43:15 +00:00
- cleaned up MD3 rendering and merged RenderFrame and RenderFrameInterpolated into one function.
This commit is contained in:
parent
59522f7065
commit
03916d75de
5 changed files with 28 additions and 79 deletions
|
@ -675,9 +675,9 @@ void gl_RenderFrameModels( const FSpriteModelFrame *smf,
|
|||
if (mdl!=NULL)
|
||||
{
|
||||
if ( smfNext && smf->modelframes[i] != smfNext->modelframes[i] )
|
||||
mdl->RenderFrameInterpolated(smf->skins[i], smf->modelframes[i], smfNext->modelframes[i], inter, translation);
|
||||
mdl->RenderFrame(smf->skins[i], smf->modelframes[i], smfNext->modelframes[i], inter, translation);
|
||||
else
|
||||
mdl->RenderFrame(smf->skins[i], smf->modelframes[i], translation);
|
||||
mdl->RenderFrame(smf->skins[i], smf->modelframes[i], NULL, 0.f, translation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,7 @@ public:
|
|||
|
||||
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0;
|
||||
virtual int FindFrame(const char * name) = 0;
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int translation=0) = 0;
|
||||
// [BB] Added RenderFrameInterpolated
|
||||
virtual void RenderFrameInterpolated(FTexture * skin, int frame, int frame2, double inter, int translation=0) = 0;
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0) = 0;
|
||||
virtual void MakeGLData() {}
|
||||
virtual void CleanGLData() {}
|
||||
|
||||
|
@ -140,8 +138,7 @@ public:
|
|||
|
||||
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length);
|
||||
virtual int FindFrame(const char * name);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int translation=0);
|
||||
virtual void RenderFrameInterpolated(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
|
||||
};
|
||||
|
||||
|
@ -222,7 +219,7 @@ class FMD3Model : public FModel
|
|||
MD3Frame * frames;
|
||||
MD3Surface * surfaces;
|
||||
|
||||
void RenderTriangles(MD3Surface * surf, MD3Vertex * vert);
|
||||
void RenderTriangles(MD3Surface * surf, MD3Vertex * vert, MD3Vertex *vert2, double inter);
|
||||
|
||||
public:
|
||||
FMD3Model() { }
|
||||
|
@ -230,8 +227,7 @@ public:
|
|||
|
||||
virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length);
|
||||
virtual int FindFrame(const char * name);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int translation=0);
|
||||
virtual void RenderFrameInterpolated(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
};
|
||||
|
||||
class FVoxelVertexBuffer;
|
||||
|
@ -293,8 +289,7 @@ public:
|
|||
void MakeGLData();
|
||||
void CleanGLData();
|
||||
virtual int FindFrame(const char * name);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int translation=0);
|
||||
virtual void RenderFrameInterpolated(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
virtual void RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation=0);
|
||||
FTexture *GetPaletteTexture() const { return mPalette; }
|
||||
};
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ void FDMDModel::RenderGLCommands(void *glCommands, unsigned int numVertices, FMo
|
|||
char *pos;
|
||||
FGLCommandVertex * v;
|
||||
int count;
|
||||
const bool interpolate = (vertices2 != NULL && inter != 0.);
|
||||
const bool interpolate = (vertices2 != NULL && inter != 0. && vertices != vertices2);
|
||||
|
||||
gl_RenderState.Apply();
|
||||
for(pos = (char*)glCommands; *pos;)
|
||||
|
@ -304,7 +304,7 @@ void FDMDModel::RenderGLCommands(void *glCommands, unsigned int numVertices, FMo
|
|||
}
|
||||
}
|
||||
|
||||
void FDMDModel::RenderFrameInterpolated(FTexture * skin, int frameno, int frameno2, double inter, int translation)
|
||||
void FDMDModel::RenderFrame(FTexture * skin, int frameno, int frameno2, double inter, int translation)
|
||||
{
|
||||
if (frameno >= info.numFrames || frameno2 >= info.numFrames) return;
|
||||
|
||||
|
@ -323,11 +323,6 @@ void FDMDModel::RenderFrameInterpolated(FTexture * skin, int frameno, int framen
|
|||
}
|
||||
|
||||
|
||||
void FDMDModel::RenderFrame(FTexture * skin, int frameno, int translation)
|
||||
{
|
||||
RenderFrameInterpolated(skin, frameno, frameno, 0., translation);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FMD2Model::Load
|
||||
|
|
|
@ -215,8 +215,10 @@ int FMD3Model::FindFrame(const char * name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void FMD3Model::RenderTriangles(MD3Surface * surf, MD3Vertex * vert)
|
||||
void FMD3Model::RenderTriangles(MD3Surface * surf, MD3Vertex * vert, MD3Vertex *vert2, double inter)
|
||||
{
|
||||
const bool interpolate = (vert2 != NULL && inter != 0. && vert != vert2);
|
||||
|
||||
gl_RenderState.Apply();
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(int i=0; i<surf->numTriangles;i++)
|
||||
|
@ -226,44 +228,24 @@ void FMD3Model::RenderTriangles(MD3Surface * surf, MD3Vertex * vert)
|
|||
int x = surf->tris[i].VertIndex[j];
|
||||
|
||||
glTexCoord2fv(&surf->texcoords[x].s);
|
||||
glVertex3f(vert[x].x, vert[x].z, vert[x].y);
|
||||
if (!interpolate)
|
||||
{
|
||||
glVertex3f(vert[x].x, vert[x].z, vert[x].y);
|
||||
}
|
||||
else
|
||||
{
|
||||
float interp[3];
|
||||
interp[0] = inter * vert[x].x + (1. - inter) * vert2[x].x;
|
||||
interp[1] = inter * vert[x].z + (1. - inter) * vert2[x].z;
|
||||
interp[2] = inter * vert[x].y + (1. - inter) * vert2[x].y;
|
||||
glVertex3fv(interp);
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void FMD3Model::RenderFrame(FTexture * skin, int frameno, int translation)
|
||||
{
|
||||
if (frameno>=numFrames) return;
|
||||
|
||||
MD3Frame * frame = &frames[frameno];
|
||||
|
||||
// I can't confirm correctness of this because no model I have tested uses this information
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glTranslatef(frame->origin[0], frame->origin[1], frame->origin[2]);
|
||||
|
||||
for(int i=0;i<numSurfaces;i++)
|
||||
{
|
||||
MD3Surface * surf = &surfaces[i];
|
||||
|
||||
// [BB] In case no skin is specified via MODELDEF, check if the MD3 has a skin for the current surface.
|
||||
// Note: Each surface may have a different skin.
|
||||
FTexture *surfaceSkin = skin;
|
||||
if (!surfaceSkin)
|
||||
{
|
||||
if (surf->numSkins==0) return;
|
||||
surfaceSkin = surf->skins[0];
|
||||
if (!surfaceSkin) return;
|
||||
}
|
||||
|
||||
FMaterial * tex = FMaterial::ValidateTexture(surfaceSkin);
|
||||
|
||||
tex->Bind(0, translation);
|
||||
RenderTriangles(surf, surf->vertices + frameno * surf->numVertices);
|
||||
}
|
||||
}
|
||||
|
||||
void FMD3Model::RenderFrameInterpolated(FTexture * skin, int frameno, int frameno2, double inter, int translation)
|
||||
void FMD3Model::RenderFrame(FTexture * skin, int frameno, int frameno2, double inter, int translation)
|
||||
{
|
||||
if (frameno>=numFrames || frameno2>=numFrames) return;
|
||||
|
||||
|
@ -285,22 +267,10 @@ void FMD3Model::RenderFrameInterpolated(FTexture * skin, int frameno, int framen
|
|||
|
||||
tex->Bind(0, translation);
|
||||
|
||||
MD3Vertex* verticesInterpolated = new MD3Vertex[surfaces[i].numVertices];
|
||||
MD3Vertex* vertices1 = surf->vertices + frameno * surf->numVertices;
|
||||
MD3Vertex* vertices2 = surf->vertices + frameno2 * surf->numVertices;
|
||||
|
||||
// [BB] Calculate the interpolated vertices by linear interpolation.
|
||||
for( int k = 0; k < surf->numVertices; k++ )
|
||||
{
|
||||
verticesInterpolated[k].x = (1-inter)*vertices1[k].x+ (inter)*vertices2[k].x;
|
||||
verticesInterpolated[k].y = (1-inter)*vertices1[k].y+ (inter)*vertices2[k].y;
|
||||
verticesInterpolated[k].z = (1-inter)*vertices1[k].z+ (inter)*vertices2[k].z;
|
||||
// [BB] Apparently RenderTriangles doesn't use nx, ny, nz, so don't interpolate them.
|
||||
}
|
||||
|
||||
RenderTriangles(surf, verticesInterpolated);
|
||||
|
||||
delete[] verticesInterpolated;
|
||||
RenderTriangles(surf, vertices1, vertices2, inter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -498,11 +498,11 @@ int FVoxelModel::FindFrame(const char * name)
|
|||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
// Voxels never interpolate between frames
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FVoxelModel::RenderFrame(FTexture * skin, int frame, int translation)
|
||||
void FVoxelModel::RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation)
|
||||
{
|
||||
FMaterial * tex = FMaterial::ValidateTexture(skin);
|
||||
tex->Bind(0, translation);
|
||||
|
@ -529,14 +529,3 @@ void FVoxelModel::RenderFrame(FTexture * skin, int frame, int translation)
|
|||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Voxels never interpolate between frames
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FVoxelModel::RenderFrameInterpolated(FTexture * skin, int frame, int frame2, double inter, int translation)
|
||||
{
|
||||
RenderFrame(skin, frame, translation);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue