1 Star 0 Fork 1

波波/Gut

forked from 2144/Gut 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Mesh.cpp 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
2144 提交于 2023-08-14 11:11 . Signed-off-by: 2144 719577252@qq.com
#include "Mesh.h"
void VertexArray::Bind()
{
glBindVertexArray(VAO);
}
void VertexArrayNoIndice::DrawArrays() const
{
glBindVertexArray(this->VAO);
glDrawArrays(this->faceType, 0, vertexNum);
glBindVertexArray(0);
}
bool VertexArrayIndice::CreateFromDesc(const VertexArrayIndiceDesc& desc)
{
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, desc.vertexStride * desc.vertexNum, desc.vertexheader, desc.usage);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, desc.indiceNum* desc.indiceStride, desc.indiceHeader, desc.usage);
for(int i=0;i<desc.numLayout;i++)
{
const auto& l = desc.layout[i];
glEnableVertexAttribArray(l.index);
if (l.type == GL_FLOAT) {
glVertexAttribPointer(l.index, l.size, l.type, l.normalized,
desc.vertexStride, (void*)l.offset);
}
else if (l.type == GL_INT) {
glVertexAttribIPointer(l.index, l.size, l.type, desc.vertexStride, (void*)l.offset);
}
}
glBindVertexArray(0);
this->numIndices = desc.indiceNum;
this->faceType = desc.face;
this->indiceStride = desc.indiceStride;
if (desc.indiceStride == 2)
{
this->indiceType = GL_UNSIGNED_SHORT;
}
else if (desc.indiceStride == 4)
{
this->indiceType = GL_UNSIGNED_INT;
}
else if (desc.indiceStride == 1)
{
this->indiceType = GL_UNSIGNED_BYTE;
}
else
{
return false;
}
glBindVertexArray(0);
return true;
}
void VertexArrayIndice::Draw() const
{
glBindVertexArray(VAO);
glDrawElements(this->faceType, this->numIndices, this->indiceType, (void*)(this->startIndex * this->indiceStride));
glBindVertexArray(0);
}
void VertexArrayIndice::DrawInstanced(unsigned int count) const
{
glBindVertexArray(VAO);
glDrawElementsInstanced(this->faceType, this->numIndices, this->indiceType, 0, count);
glBindVertexArray(0);
}
bool VertexArrayNoIndice::CreateFromDesc(const VertexArrayNoIndiceDesc& desc)
{
bool gr = true;
unsigned int VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, desc.vertexStride * desc.vertexNum, desc.vertexheader, desc.usage);
for (int i = 0; i < desc.numLayout; i++)
{
const auto& l = desc.layout[i];
glEnableVertexAttribArray(l.index);
if (l.type == GL_FLOAT) {
glVertexAttribPointer(l.index, l.size, l.type, l.normalized,
desc.vertexStride, (void*)l.offset);
}
else if (l.type == GL_INT) {
glVertexAttribIPointer(l.index, l.size, l.type, desc.vertexStride, (void*)l.offset);
}
}
glBindVertexArray(0);
this->vertexNum = desc.vertexNum;
return true;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bobo110/gut.git
git@gitee.com:bobo110/gut.git
bobo110
gut
Gut
master

搜索帮助