bool ceDeviceGL20::BeginPass (ceRenderPass pass) { if (!_effectTechnique) { _program = 0; glUseProgram(0); return false; } _program = _effectTechnique->GetProgram(pass); if (!_program) { glUseProgram(0); return false; } _program->Bind (); _pass = pass; BindMatrices (); return true; }
void Shader::BindMeshData(const std::shared_ptr<Mesh> &mesh) { int posFlag = glGetAttribLocation(m_Program, mesh->Positions.Name.c_str()); int normalFlag = glGetAttribLocation(m_Program, mesh->Normals.Name.c_str()); int tangentFlag = glGetAttribLocation(m_Program, mesh->Tangents.Name.c_str()); int uvFlag = glGetAttribLocation(m_Program, mesh->UVs.Name.c_str()); glBindVertexArray(mesh->m_VAO); if (posFlag != -1) { if (!mesh->Positions.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->Positions.GetID()); glVertexAttribPointer(posFlag, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(posFlag); } else { FURYW << "Mesh " + mesh->GetName() + " Position data dirty!"; } } if (normalFlag != -1) { if (!mesh->Normals.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->Normals.GetID()); glVertexAttribPointer(normalFlag, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(normalFlag); } else { FURYW << "Mesh " + mesh->GetName() + " Normal data dirty!"; } } if (tangentFlag != -1) { if (!mesh->Tangents.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->Tangents.GetID()); glVertexAttribPointer(tangentFlag, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(tangentFlag); } else { FURYW << "Mesh" + mesh->GetName() + " Tangent data dirty!"; } } if (uvFlag != -1) { if (!mesh->UVs.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->UVs.GetID()); glVertexAttribPointer(uvFlag, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(uvFlag); } else { FURYW << "Mesh " + mesh->GetName() + " UV data dirty!"; } } if (mesh->IsSkinnedMesh()) { int idFlag = glGetAttribLocation(m_Program, mesh->IDs.Name.c_str()); int weightFlag = glGetAttribLocation(m_Program, mesh->Weights.Name.c_str()); if (idFlag != -1) { if (!mesh->IDs.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->IDs.GetID()); glVertexAttribIPointer(idFlag, 4, GL_UNSIGNED_INT, 0, 0); glEnableVertexAttribArray(idFlag); } else { FURYW << "Mesh " + mesh->GetName() + " ID data dirty!"; } } else { FURYW << "Can't find " << mesh->IDs.Name << " in " << m_Name; } if (weightFlag != -1) { if (!mesh->Weights.GetDirty()) { glBindBuffer(GL_ARRAY_BUFFER, mesh->Weights.GetID()); glVertexAttribPointer(weightFlag, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(weightFlag); } else { FURYW << "Mesh " + mesh->GetName() + " Weight data dirty!"; } } else { FURYW << "Can't find " << mesh->Weights.Name << " in " << m_Name; } if (idFlag != -1 && weightFlag != -1) { int jointCount = (int)mesh->GetJointCount(); if (jointCount > 35) { FURYW << "Max joint count 35!"; jointCount = 35; } std::vector<float> raw(jointCount * 16); for (int i = 0; i < jointCount; i++) { auto joint = mesh->GetJointAt(i); auto matrix = joint->GetFinalMatrix(); int index = i * 16; for (int j = 0; j < 16; j++) { raw[index + j] = matrix.Raw[j]; } } BindMatrices("bone_matrices", jointCount, &raw[0]); } } glBindBuffer(GL_ARRAY_BUFFER, 0); }