From 03916d75de18162fb7efb1bb6c6ad25b7b60b4ce Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 19 Jun 2014 13:58:49 +0200 Subject: [PATCH] - cleaned up MD3 rendering and merged RenderFrame and RenderFrameInterpolated into one function. --- src/gl/models/gl_models.cpp | 4 +-- src/gl/models/gl_models.h | 15 +++----- src/gl/models/gl_models_md2.cpp | 9 ++--- src/gl/models/gl_models_md3.cpp | 64 +++++++++------------------------ src/gl/models/gl_voxels.cpp | 15 ++------ 5 files changed, 28 insertions(+), 79 deletions(-) diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index 568a2e3f2..76e8006aa 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -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); } } } diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index a4effd51d..181784b9b 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -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; } }; diff --git a/src/gl/models/gl_models_md2.cpp b/src/gl/models/gl_models_md2.cpp index 46a7238a7..8fa8310f7 100644 --- a/src/gl/models/gl_models_md2.cpp +++ b/src/gl/models/gl_models_md2.cpp @@ -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 diff --git a/src/gl/models/gl_models_md3.cpp b/src/gl/models/gl_models_md3.cpp index bd1b4e972..6b380ea29 100644 --- a/src/gl/models/gl_models_md3.cpp +++ b/src/gl/models/gl_models_md3.cpp @@ -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; inumTriangles;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;inumSkins==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); } } diff --git a/src/gl/models/gl_voxels.cpp b/src/gl/models/gl_voxels.cpp index 3a04cb5ca..873390f9c 100644 --- a/src/gl/models/gl_voxels.cpp +++ b/src/gl/models/gl_voxels.cpp @@ -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); -} -