// Create per-CModel data for the model (and per-CModelDef data if necessary) void* PolygonSortModelRenderer::CreateModelData(CModel* model) { CModelDefPtr mdef = model->GetModelDef(); PSModelDef* psmdef = (PSModelDef*)mdef->GetRenderData(m); if (!psmdef) { psmdef = new PSModelDef(mdef); mdef->SetRenderData(m, psmdef); } return new PSModel(model); }
// Prepare for rendering models using this CModelDef void PolygonSortModelRenderer::PrepareModelDef(int streamflags, const CModelDefPtr& def) { if (streamflags & STREAM_UV0) { PSModelDef* psmdef = (PSModelDef*)def->GetRenderData(m); ENSURE(psmdef); u8* base = psmdef->m_Array.Bind(); GLsizei stride = (GLsizei)psmdef->m_Array.GetStride(); glTexCoordPointer(2, GL_FLOAT, stride, base + psmdef->m_UV.offset); } }
// Build modeldef data if necessary - we have no per-CModel data void* InstancingModelRenderer::CreateModelData(CModel* model) { CModelDefPtr mdef = model->GetModelDef(); IModelDef* imodeldef = (IModelDef*)mdef->GetRenderData(m); ENSURE(!model->IsSkinned()); if (!imodeldef) { imodeldef = new IModelDef(mdef); mdef->SetRenderData(m, imodeldef); } return NULL; }
// Build modeldef data if necessary - we have no per-CModel data CModelRData* InstancingModelRenderer::CreateModelData(const void* key, CModel* model) { CModelDefPtr mdef = model->GetModelDef(); IModelDef* imodeldef = (IModelDef*)mdef->GetRenderData(m); if (m->gpuSkinning) ENSURE(model->IsSkinned()); else ENSURE(!model->IsSkinned()); if (!imodeldef) { imodeldef = new IModelDef(mdef, m->gpuSkinning, m->calculateTangents); mdef->SetRenderData(m, imodeldef); } return new CModelRData(key); }
// Prepare UV coordinates for this modeldef void InstancingModelRenderer::PrepareModelDef(CShaderProgramPtr& shader, int streamflags, const CModelDefPtr& def) { m->imodeldef = (IModelDef*)def->GetRenderData(m); ENSURE(m->imodeldef); u8* base = m->imodeldef->m_Array.Bind(); GLsizei stride = (GLsizei)m->imodeldef->m_Array.GetStride(); m->imodeldefIndexBase = m->imodeldef->m_IndexArray.Bind(); if (streamflags & STREAM_POS) shader->VertexPointer(3, GL_FLOAT, stride, base + m->imodeldef->m_Position.offset); if (streamflags & STREAM_NORMAL) shader->NormalPointer(GL_FLOAT, stride, base + m->imodeldef->m_Normal.offset); if (streamflags & STREAM_UV0) shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, stride, base + m->imodeldef->m_UV.offset); shader->AssertPointersBound(); }
// Build model data (and modeldef data if necessary) void* ShaderModelRenderer::CreateModelData(CModel* model) { CModelDefPtr mdef = model->GetModelDef(); ShaderModelDef* shadermodeldef = (ShaderModelDef*)mdef->GetRenderData(m); if (!shadermodeldef) { shadermodeldef = new ShaderModelDef(mdef); mdef->SetRenderData(m, shadermodeldef); } // Build the per-model data ShaderModel* shadermodel = new ShaderModel; shadermodel->m_Position.type = GL_FLOAT; shadermodel->m_Position.elems = 3; shadermodel->m_Array.AddAttribute(&shadermodel->m_Position); shadermodel->m_UV.type = GL_FLOAT; shadermodel->m_UV.elems = 2; shadermodel->m_Array.AddAttribute(&shadermodel->m_UV); shadermodel->m_Normal.type = GL_FLOAT; shadermodel->m_Normal.elems = 3; shadermodel->m_Array.AddAttribute(&shadermodel->m_Normal); shadermodel->m_Array.SetNumVertices(mdef->GetNumVertices()); shadermodel->m_Array.Layout(); // Fill in static UV coordinates VertexArrayIterator<float[2]> UVit = shadermodel->m_UV.GetIterator<float[2]>(); ModelRenderer::BuildUV(mdef, UVit); return shadermodel; }
// Prepare UV coordinates for this modeldef void ShaderModelRenderer::PrepareModelDef(int UNUSED(streamflags), const CModelDefPtr& def) { m->shadermodeldef = (ShaderModelDef*)def->GetRenderData(m); ENSURE(m->shadermodeldef); }