hey guys i have a problem with the std::vector and i need your help. I am currently programming a rendering engine with the new vulkan api and i want to support different vertex layouts for different meshes. The problem is that std::vector::data() doesnt return the raw data i need. Here are my Vertex structs:
struct Vertex
{
};
struct VertexColor : public Vertex
{
public:
VertexColor(Vec3f pos, Vec3f col) : position(pos), color(col) {}
Vec3f position;
Vec3f color;
};
This is what i actually have and works:
std::vector<VertexColor> cubeVertexBuffer = {
VertexColor{ Vec3f( -1.0f, -1.0f, 1.0f ), Vec3f( 0.0f, 0.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, -1.0f, 1.0f ), Vec3f( 1.0f, 0.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, 1.0f, 1.0f ), Vec3f( 1.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, 1.0f, 1.0f ), Vec3f( 0.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, -1.0f, -1.0f), Vec3f( 0.0f, 0.0f, 1.0f ) },
VertexColor{ Vec3f( 1.0f, -1.0f, -1.0f ), Vec3f( 0.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, 1.0f, -1.0f ), Vec3f( 1.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, 1.0f, -1.0f ), Vec3f( 1.0f, 0.0f, 0.0f ) }
};
uint32_t size = 8 * sizeof(VertexColor);
Vertex* vertices = (Vertex*)malloc(size);
memcpy(vertices, cubeVertexBuffer.data(), size);
std::vector<uint32_t> cubeIndexBuffer = { 1,2,0, 2,3,0,
0,3,4, 3,7,4,
5,1,4, 1,0,4,
2,6,3, 6,7,3,
5,6,1, 6,2,1,
6,5,7, 5,4,7 };
Cube::cubeMesh = new Mesh(vertices, size, cubeIndexBuffer);
What i want:
std::vector<Vertex> cubeVertexBuffer = {
VertexColor{ Vec3f( -1.0f, -1.0f, 1.0f ), Vec3f( 0.0f, 0.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, -1.0f, 1.0f ), Vec3f( 1.0f, 0.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, 1.0f, 1.0f ), Vec3f( 1.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, 1.0f, 1.0f ), Vec3f( 0.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, -1.0f, -1.0f), Vec3f( 0.0f, 0.0f, 1.0f ) },
VertexColor{ Vec3f( 1.0f, -1.0f, -1.0f ), Vec3f( 0.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( 1.0f, 1.0f, -1.0f ), Vec3f( 1.0f, 1.0f, 0.0f ) },
VertexColor{ Vec3f( -1.0f, 1.0f, -1.0f ), Vec3f( 1.0f, 0.0f, 0.0f ) }
};
std::vector<uint32_t> cubeIndexBuffer = { 1,2,0, 2,3,0,
0,3,4, 3,7,4,
5,1,4, 1,0,4,
2,6,3, 6,7,3,
5,6,1, 6,2,1,
6,5,7, 5,4,7 };
Cube::cubeMesh = new Mesh(cubeVertexBuffer, cubeIndexBuffer);
As i mentioned i need the whole vertex data in a raw format contigously in memory for mapping to the gpu, but the .data() function with the std::vector doesnt return the "real data". I dont know how i can using inheritation with the std::vector to get the "raw data from the subclass" in it. Hope you can help me! Thanks
Aucun commentaire:
Enregistrer un commentaire