void PrelightPipeline::DrawQuad(const std::shared_ptr<Pass> &pass) { auto shader = m_CurrentShader; auto mesh = MeshUtil::Instance()->GetUnitQuad(); if (shader == nullptr) { LOGW << "Failed to draw full screen quad, shader not found!"; return; } shader->Bind(); shader->BindMesh(mesh); shader->BindCamera(m_CurrentCamera); for (unsigned int i = 0; i < pass->GetTextureCount(true); i++) { auto ptr = pass->GetTextureAt(i, true); shader->BindTexture(ptr->GetName(), ptr); } glDrawElements(GL_TRIANGLES, mesh->Indices.Data.size(), GL_UNSIGNED_INT, 0); shader->UnBind(); m_DrawCall++; }
//Create the buffers and store the mesh data in them void LoadMesh(MeshBuffers *buffers, MeshData *data, Vertex *vertices, unsigned int verticesCount, unsigned int *indices, unsigned int indicesCount) { data->VerticesCount = verticesCount; data->IndicesCount = indicesCount; data->Vertices = vertices; data->Indices = indices; //Use only with newer GLSL versions #if GLSL_VERSION == MODERN_VERSION //Generate a handle to a vertex array object glGenVertexArrays(1, &buffers->VAO); #endif //Generate a handle to a vertex buffer object glGenBuffers(1, &buffers->VBO); //Generate a handle to a element buffer object glGenBuffers(1, &buffers->EBO); //Bind the vertex array object (it will begin storing what is happening below BindMesh(buffers); //Create a Vertex buffer InitVBO(buffers, data); //Create an Element buffer InitEBO(buffers, data); //Unbind everything UnbindMesh(); }
//Draw the mesh void DrawMesh(Mesh *mesh) { //Bind the buffers BindMesh(&mesh->Buffers); BindTexture(&mesh->MeshTexture); //Draw the mesh glDrawElements(GL_TRIANGLES //Drawing type , mesh->Data.IndicesCount //Number of indices , GL_UNSIGNED_INT //Indices type , 0); //The location of the indices (NULL means to look for them in the buffer) //Unbind the buffers UnbindMesh(); UnbindTexture(); }
void PrelightPipeline::DrawRenderable(const std::shared_ptr<Pass> &pass, const std::shared_ptr<SceneNode> &node) { auto render = node->GetComponent<MeshRender>(); if (render == nullptr || !render->GetRenderable()) return; auto mesh = render->GetMesh(); auto material = render->GetMaterial(); auto shader = material->GetShaderForPass(pass->GetRenderIndex()); if (shader == nullptr) shader = pass->GetShader(material->GetShaderType()); if (shader == nullptr) { LOGW << "Failed to draw " << node->GetName() << ", data incomplete!"; return; } shader->Bind(); shader->BindCamera(m_CurrentCamera); shader->BindMatrix(Matrix4::WORLD_MATRIX, node->GetWorldMatrix()); shader->BindMesh(mesh); shader->BindMaterial(material); for (unsigned int i = 0; i < pass->GetTextureCount(true); i++) { auto ptr = pass->GetTextureAt(i, true); shader->BindTexture(ptr->GetName(), ptr); } glDrawElements(GL_TRIANGLES, mesh->Indices.Data.size(), GL_UNSIGNED_INT, 0); shader->UnBind(); m_DrawCall++; }