Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ModelDef.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
/* | /* | ||||
* Defines a raw 3d model. | * Defines a raw 3d model. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "ModelDef.h" | #include "ModelDef.h" | ||||
#include "graphics/SkeletonAnimDef.h" | #include "graphics/SkeletonAnimDef.h" | ||||
#include "lib/sse.h" | |||||
#include "ps/FileIo.h" | #include "ps/FileIo.h" | ||||
#include "maths/Vector4D.h" | #include "maths/Vector4D.h" | ||||
#if HAVE_SSE | #if HAVE_SSE | ||||
# include <xmmintrin.h> | # include <xmmintrin.h> | ||||
#endif | #endif | ||||
CVector3D CModelDef::SkinPoint(const SModelVertex& vtx, | CVector3D CModelDef::SkinPoint(const SModelVertex& vtx, | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | CVector3D CModelDef::SkinNormal(const SModelVertex& vtx, | ||||
// (It's fairly common to only have one influence, so it seems sensible to | // (It's fairly common to only have one influence, so it seems sensible to | ||||
// optimise that case a bit.) | // optimise that case a bit.) | ||||
if (vtx.m_Blend.m_Bone[1] != 0xff) // if more than one influence | if (vtx.m_Blend.m_Bone[1] != 0xff) // if more than one influence | ||||
result.Normalize(); | result.Normalize(); | ||||
return result; | return result; | ||||
} | } | ||||
void CModelDef::SkinPointsAndNormals( | void(*CModelDef::SkinPointsAndNormals)( | ||||
size_t numVertices, | |||||
const VertexArrayIterator<CVector3D>& Position, | |||||
const VertexArrayIterator<CVector3D>& Normal, | |||||
const SModelVertex* vertices, | |||||
const size_t* blendIndices, | |||||
const CMatrix3D newPoseMatrices[]) {}; | |||||
static void fallback_SkinPointsAndNormals( | |||||
size_t numVertices, | size_t numVertices, | ||||
const VertexArrayIterator<CVector3D>& Position, | const VertexArrayIterator<CVector3D>& Position, | ||||
const VertexArrayIterator<CVector3D>& Normal, | const VertexArrayIterator<CVector3D>& Normal, | ||||
const SModelVertex* vertices, | const SModelVertex* vertices, | ||||
const size_t* blendIndices, | const size_t* blendIndices, | ||||
const CMatrix3D newPoseMatrices[]) | const CMatrix3D newPoseMatrices[]) | ||||
{ | { | ||||
// To avoid some performance overhead, get the raw vertex array pointers | // To avoid some performance overhead, get the raw vertex array pointers | ||||
Show All 18 Lines | if (vtx.m_Blend.m_Bone[1] != 0xff) // if more than one influence | ||||
norm.Normalize(); | norm.Normalize(); | ||||
memcpy(PositionData + PositionStride*j, &pos.X, 3*sizeof(float)); | memcpy(PositionData + PositionStride*j, &pos.X, 3*sizeof(float)); | ||||
memcpy(NormalData + NormalStride*j, &norm.X, 3*sizeof(float)); | memcpy(NormalData + NormalStride*j, &norm.X, 3*sizeof(float)); | ||||
} | } | ||||
} | } | ||||
#if HAVE_SSE | #if HAVE_SSE | ||||
void CModelDef::SkinPointsAndNormals_SSE( | static void sse_SkinPointsAndNormals_SSE( | ||||
vladislavbelov: `sse_*_SSE`? I don't think it's good. | |||||
StanAuthorUnsubmitted Done Inline ActionsRight will unify the names. Do you prefer prefix or suffix? Stan: Right will unify the names. Do you prefer prefix or suffix? | |||||
vladislavbelovUnsubmitted Done Inline ActionsSuffix without underscore. vladislavbelov: Suffix without underscore. | |||||
size_t numVertices, | size_t numVertices, | ||||
const VertexArrayIterator<CVector3D>& Position, | const VertexArrayIterator<CVector3D>& Position, | ||||
const VertexArrayIterator<CVector3D>& Normal, | const VertexArrayIterator<CVector3D>& Normal, | ||||
const SModelVertex* vertices, | const SModelVertex* vertices, | ||||
const size_t* blendIndices, | const size_t* blendIndices, | ||||
const CMatrix3D newPoseMatrices[]) | const CMatrix3D newPoseMatrices[]) | ||||
{ | { | ||||
// To avoid some performance overhead, get the raw vertex array pointers | // To avoid some performance overhead, get the raw vertex array pointers | ||||
▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
RenderDataMap::const_iterator it = m_RenderData.find(key); | RenderDataMap::const_iterator it = m_RenderData.find(key); | ||||
if (it != m_RenderData.end()) | if (it != m_RenderData.end()) | ||||
return it->second; | return it->second; | ||||
return 0; | return 0; | ||||
} | } | ||||
vladislavbelovUnsubmitted Done Inline ActionsUseless empty line. vladislavbelov: Useless empty line. | |||||
extern void ModelDefActivateFastImpl() | |||||
vladislavbelovUnsubmitted Done Inline ActionsWhy do you use extern for the implementation? vladislavbelov: Why do you use `extern` for the implementation? | |||||
StanAuthorUnsubmitted Done Inline Actions
Was done like this for Color iirc Stan: > Why do you use `extern` for the implementation?
Was done like this for Color iirc | |||||
vladislavbelovUnsubmitted Done Inline ActionsFollowing mistakes isn't a good practice. vladislavbelov: Following mistakes isn't a good practice. | |||||
{ | |||||
#if HAVE_SSE | |||||
if (HasSSE()) | |||||
{ | |||||
CModelDef::SkinPointsAndNormals = sse_SkinPointsAndNormals_SSE; | |||||
return; | |||||
} | |||||
#endif | |||||
CModelDef::SkinPointsAndNormals = fallback_SkinPointsAndNormals; | |||||
} |
Wildfire Games · Phabricator
sse_*_SSE? I don't think it's good.