In my code I have the following:
struct alignas(16) sphere
{
glm::vec4 center;
glm::vec4 color;
float radius;
};
sphere* m_sphere_ptr;
m_sphere_ptr = static_cast<sphere*>(glMapNamedBufferRange(m_sphere_buffer, 0, m_spheres.size() * sizeof(sphere), GL_MAP_WRITE_BIT));
auto sphere_x_offset { 5.0f };
for (int index{ 0 }; index < m_spheres.size(); ++index)
{
float sphere_x { static_cast<float>(index) / m_spheres.size()};
m_sphere_ptr[index].center = glm::vec4{ sphere_x + sphere_x_offset, -1, -5, 0 };
m_sphere_ptr[index].color = m_spheres[index].color;
m_sphere_ptr[index].radius = m_spheres[index].radius;
}
glUnmapNamedBuffer(m_sphere_buffer);
I want to change the sphere* m_sphere_ptr
into a smart pointer. However, if I create it like: std::unique_ptr<sphere> m_sphere_ptr;
(and do not change any of my other code) I get a compilation error that m_sphere_ptr
is not an array type.
Is there a safe way for me to index and and write to m_sphere_ptr
when it is a unique pointer?
For reference glMapNamedBufferRange
returns a void *
which is why it is cast.