matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
492 stars 72 forks source link

Cannot access private member declared in class 'oglplus::Object<oglplus::BufferOps' #108

Closed jose-villegas closed 7 years ago

jose-villegas commented 9 years ago

I'm getting this error declaring a buffer object as a member in my class, for some reason this is only happening in a single class, I have buffers declared all over many classes in my current project but this is only happening for this class.

This is the file where I'm getting this error.

Yet the buffer objects in TerrainChunkGenerator don't give any problem, same with some other buffers I have declared in other classes

class TerrainChunk
{
    private:
        std::vector<glm::vec3> vertices;
        std::vector<glm::vec3> normals;
        std::vector<glm::vec2> texCoords;
        // mesh data gpu buffers
        std::array<Buffer, 4> buffer;
    public:
        TerrainChunk(std::vector<glm::vec3> &vertices,
                     std::vector<glm::vec3> &normals,
                     std::vector<glm::vec2> &texCoords);
        // chunk num vertices = chunkSizeExponent ^ 2 + 1
        ~TerrainChunk() {};
        void bindBufferData(Program &program);
        void bindBuffer(Program &program);
};

class TerrainChunksGenerator
{
    private:
        Context gl;
        // avoid creating indices again if mesh has the same configuration
        bool indicesCombinationGenerated = false;
        // indices combinations for different lod levels
        std::array<std::vector<unsigned int>, 3> indicesLoD;
        std::array<Buffer, 3> indicesBuffer;
    private:
        bool chunksGenerated = false;
        // helper for getting x, y from contiguos vectors
        glm::vec3 &getVertex(int x, int y);
        glm::vec2 &getTexCoord(int x, int y);
        glm::vec3 &getNormal(int x, int y);
        // mesh parameters data
        unsigned int chunkSize;
        unsigned int meshSize;
        unsigned int meshSizeExponent;
        unsigned int chunkSizeExponent;
        unsigned int restartIndexToken;
        // whole mesh data
        std::vector<glm::vec3> vertices;
        std::vector<glm::vec3> normals;
        std::vector<glm::vec2> texCoords;
        // collection of all mesh chunks
        std::vector<std::vector<TerrainChunk>> meshChunks;
    public:
        // generates all terrain chunks
        void generateChunks(std::vector<glm::vec3> &meshVertices,
                            std::vector<glm::vec3> &meshNormals,
                            std::vector<glm::vec2> &meshTexCoords,
                            unsigned int meshSizeExponent,
                            unsigned int chunkSizeExponent);
        // uploads all the chunks buffer objects to the gpu
        void bindBufferData(Program &program);

        TerrainChunk &MeshChunk(int i, int j) { return meshChunks[i][j]; }
        // creates indices combinations for
        // 3 Level of Detail levels
        void generateIndicesCombination();

        TerrainChunksGenerator() {};
        ~TerrainChunksGenerator();
};

This is using MSVC2013

matus-chochlik commented 9 years ago

Hi, Buffer is made non-copyable (because GL does not support object copying) by declaring the copy constructor private and You are getting this error probably because MSVC still does not use properly the move constructors or you are trying to copy the array of Buffers. Consider using Array<Buffer> or StaticGroup<Buffer, 3> instead of array<Buffer, 3>.

HTH

jose-villegas commented 9 years ago

I solved the issue chaning this in TerrainChunkGenerator

// collection of all mesh chunks
std::vector<std::vector<TerrainChunk>> meshChunks;

for this

// collection of all mesh chunks
std::vector<std::vector<TerrainChunk *>> meshChunks;

You are right that for some reason it's requesting the copy constructor. Array (the one provided by OGLPlus) didn't work either. But hey, the wrapper has been a bliss so far!

matus-chochlik commented 9 years ago

Thanks! I'll have a look at the problem with the move constructor in Array.