What do you have already? Is loading of assets already implemented?
Yes. I encapsulated
Assimp in classes. However, the Mesh class I wrote, for example, uses opengl commands, which I think isn't correct design. (this doesn't obey the
Single responsibility Principle)
class Mesh
{
public:
Mesh(aiMesh *mesh) : _mesh(mesh)
{
_hasNormals = _mesh->HasNormals();
_hasTextureCoords = (_mesh->mTextureCoords[0] != 0);
for(unsigned int i = 0; i < _mesh->mNumVertices; i++)
_vertices.push_back(glm::vec3(_mesh->mVertices[i].x, _mesh->mVertices[i].y, _mesh->mVertices[i].z));
if(_hasNormals)
for(unsigned int i = 0; i < _mesh->mNumVertices; i++)
_normals.push_back(glm::vec3(_mesh->mNormals[i].x, _mesh->mNormals[i].y, _mesh->mNormals[i].z));
if(_hasTextureCoords)
for(unsigned int i = 0; i < _mesh->mNumVertices; i++)
_textureCoords.push_back(glm::vec2(_mesh->mTextureCoords[0][i].x, _mesh->mTextureCoords[0][i].y));
for(unsigned int i = 0; i < _mesh->mNumFaces; i++)
{
aiFace face = _mesh->mFaces[i];
for(unsigned int j = 0; j < face.mNumIndices; j++)
_indices.push_back(face.mIndices[j]);
}
glGenVertexArrays(1, &_vao);
glGenBuffers(1, &_vbo);
glGenBuffers(1, &_ebo);
glBindVertexArray(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
//vertices
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * (_vertices.size() + _normals.size()) + sizeof(glm::vec2) * _textureCoords.size(), (const GLvoid*) _vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(0);
if(_hasNormals) { //normals
glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * _vertices.size(), sizeof(glm::vec3) * _normals.size(), (const GLvoid*) _normals.data());
glVertexAttribPointer(1, 3, GL_FLOAT, 0, 0, (const GLvoid*)(sizeof(glm::vec3) * _vertices.size()));
glEnableVertexAttribArray(1);
}
if(_hasTextureCoords) { //uvs
glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * (_vertices.size() + _normals.size()), sizeof(glm::vec2) * _textureCoords.size(), (const GLvoid*) _textureCoords.data());
glVertexAttribPointer(2, 3, GL_FLOAT, 0, 0, (const GLvoid*)(sizeof(glm::vec3) * (_vertices.size() + _normals.size())));
glEnableVertexAttribArray(2);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * _indices.size(), (const GLvoid*) _indices.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
This is bad. First I think I should encapsulate vertex buffers in a class called VBO or something. Accessing direct opengl commands like that is ugly.
Secondly I think that I should not call opengl commands in this class at all. It's only meaning should be to store mesh data (again, the Single responsibility Principle).
I should access this data in a higher level class and then mix it with opengl functions (can anyone approve this approach?). Anyway, like I said, I don't know where to begin. I don't want to write code that will turn out to be bad. That's why I tried viewing other engines' source codes, but they are very hard to understand (for me at least..).
Is a basic renderer already implemented?
Nope. My intention was to build a resource management system before implementing the renderer, that should rely on it.
I really want to start coding but I'm stuck too much time on the design. This is really depressing =[