22 #include "precompiled.h"
59 std::vector<VertexArray::Attribute>
m_UVs;
69 : m_IndexArray(GL_STATIC_DRAW), m_Array(GL_STATIC_DRAW)
71 size_t numVertices = mdef->GetNumVertices();
81 m_UVs.resize(mdef->GetNumUVsPerVertex());
82 for (
size_t i = 0; i < mdef->GetNumUVsPerVertex(); i++)
84 m_UVs[i].type = GL_FLOAT;
100 if (calculateTangents)
109 int numVertexAttrs = 3 + 3 + 4 + 2 * mdef->GetNumUVsPerVertex();
117 std::vector<float> newVertices;
118 newVertices.reserve(numVertexAttrs * numVertices * 2);
124 int newNumVert = newVertices.size() / numVertexAttrs;
126 std::vector<int> remapTable(newNumVert);
127 std::vector<float> vertexDataOut(newNumVert * numVertexAttrs);
130 int numVertices2 =
WeldMesh(&remapTable[0], &vertexDataOut[0],
131 &newVertices[0], newNumVert, numVertexAttrs);
151 for (
int i = 0; i < numVertices2; i++)
153 int q = numVertexAttrs * i;
155 Position[i] =
CVector3D(vertexDataOut[q + 0], vertexDataOut[q + 1], vertexDataOut[q + 2]);
158 Normal[i] =
CVector3D(vertexDataOut[q + 0], vertexDataOut[q + 1], vertexDataOut[q + 2]);
161 Tangent[i] =
CVector4D(vertexDataOut[q + 0], vertexDataOut[q + 1], vertexDataOut[q + 2],
162 vertexDataOut[q + 3]);
167 for (
size_t j = 0; j < 4; ++j)
169 BlendJoints[i][j] = (
u8)vertexDataOut[q + 0 + 2 * j];
170 BlendWeights[i][j] = (
u8)vertexDataOut[q + 1 + 2 * j];
175 for (
size_t j = 0; j < mdef->GetNumUVsPerVertex(); j++)
178 UVit[i][0] = vertexDataOut[q + 0 + 2 * j];
179 UVit[i][1] = vertexDataOut[q + 1 + 2 * j];
195 for (
size_t j = 0; j < mdef->GetNumFaces(); ++j)
197 Indices[idxidx++] = remapTable[j * 3 + 0];
198 Indices[idxidx++] = remapTable[j * 3 + 1];
199 Indices[idxidx++] = remapTable[j * 3 + 2];
217 for (
size_t i = 0; i < mdef->GetNumUVsPerVertex(); i++)
227 for (
size_t i = 0; i < numVertices; ++i)
230 for (
size_t j = 0; j < 4; ++j)
293 mdef->SetRenderData(
m, imodeldef);
341 shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, stride, base +
m->
imodeldef->
m_UVs[0].offset);
344 shader->TexCoordPointer(GL_TEXTURE1, 2, GL_FLOAT, stride, base +
m->
imodeldef->
m_UVs[1].offset);
353 shader->AssertPointersBound();
374 size_t numFaces = mdldef->GetNumFaces();
380 glDrawElements(GL_TRIANGLES, (GLsizei)numFaces*3, GL_UNSIGNED_SHORT,
m->
imodeldefIndexBase);
void UpdateModelData(CModel *model, CModelRData *data, int updateflags)
UpdateModelData: Calculate per-model data for each frame.
static void BuildUV(const CModelDefPtr &mdef, const VertexArrayIterator< float[2]> &UV, int UVset)
BuildUV: Copy UV coordinates into the given vertex array.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
VertexArray::Attribute m_BlendWeights
CModelRData * CreateModelData(const void *key, CModel *model)
CreateModelData: Create internal data for one model.
VertexArray::Attribute m_Position
Position and normals are static.
VertexArrayIterator< u16 > GetIterator() const
Gets the iterator over the (only) attribute in this array, i.e. a u16.
static void CopyPositionAndNormals(const CModelDefPtr &mdef, const VertexArrayIterator< CVector3D > &Position, const VertexArrayIterator< CVector3D > &Normal)
CopyPositionAndNormals: Copy unanimated object-space vertices and normals into the given vertex array...
IModelDef * imodeldef
Previously prepared modeldef.
InstancingModelRenderer(bool gpuSkinning, bool calculateTangents)
VertexArray::Attribute m_Tangent
void AddAttribute(Attribute *attr)
VertexArray m_Array
Static per-CModel vertex array.
A VertexArray that is specialised to handle 16-bit array indices.
const CMatrix3D * GetAnimatedBoneMatrices()
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
void BeginPass(int streamflags)
BeginPass: Setup global OpenGL state for this ModelVertexRenderer.
InstancingModelRendererInternals * m
bool IsSkinned()
Return whether this is a skinned/skeletal model.
void RenderModel(const CShaderProgramPtr &shader, int streamflags, CModel *model, CModelRData *data)
RenderModel: Invoke the rendering commands for the given model.
~InstancingModelRenderer()
static void BuildIndices(const CModelDefPtr &mdef, const VertexArrayIterator< u16 > &Indices)
BuildIndices: Create the indices array for the given CModelDef.
void SetNumVertices(size_t num)
IModelDef(const CModelDefPtr &mdef, bool gpuSkinning, bool calculateTangents)
int WeldMesh(int *piRemapTable, float *pfVertexDataOut, const float pfVertexDataIn[], const int iNrVerticesIn, const int iFloatsPerVert)
Copyright (C) 2011 by Morten S.
VertexArrayIterator< T > GetIterator() const
void PrepareModelDef(const CShaderProgramPtr &shader, int streamflags, const CModelDef &def)
PrepareModelDef: Setup OpenGL state for rendering of models that use the given CModelDef object as ba...
static void GenTangents(const CModelDefPtr &mdef, std::vector< float > &newVertices, bool gpuSkinning)
GenTangents: Generate tangents for the given CModelDef.
std::vector< VertexArray::Attribute > m_UVs
The number of UVs is determined by the model.
VertexArray::Attribute m_Normal
Class CModelRData: Render data that is maintained per CModel.
VertexArray::Attribute m_BlendJoints
u8 * imodeldefIndexBase
Index base for imodeldef.
const CModelDefPtr & GetModelDef()
static void Unbind()
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it...
shared_ptr< CShaderProgram > CShaderProgramPtr
CModelDefRPrivate * GetRenderData(const void *key) const
size_t GetNumUVsPerVertex() const
size_t GetNumVertices() const
boost::shared_ptr< CModelDef > CModelDefPtr
void EndPass(int streamflags)
EndPass: Cleanup OpenGL state set up by BeginPass.
VertexIndexArray m_IndexArray
Indices are the same for all models, so share them.