你可以将结构加载到成员变量是私有的vbo中吗?
UPDATE
问题是通用的没有样本,因为我不知道如何询问具体问题.下面的答案正确到我想要的地步.但对于那些浪费时间来看这个问题的代码来说:
#ifndef POINT2D_H_INCLUDED
#define POINT2D_H_INCLUDED
#include <glext.h>
namespace glext
{
/*! \class Point 2D class geometry based
* \brief This class defines a 2D point_2d
*
* Some details about the Test class
*/
template <typename T>
class point_2d
{
private:
/// The first element in the ordered pair
T _x;
/// The second element in the ordered pair
T _y;
public:
/*! \brief default constructor sets both elements in ordered pair to 0
*/
point_2d();
/*! \brief constructor sets both elements to the paramaters provided
*/
point_2d(const T &x, const T &y);
/*! \brief copy constructor sets both elements in ordered pair to 0
*/
point_2d(const point_2d &rhs);
/*! \brief destructor
*/
~point_2d();
/*! \brief assignment uses copy-swap idiom
*/
point_2d &operator=(point_2d rhs);
/*! \brief setter for x element
*/
void x(const T &x);
/*! \brief setter for y element
*/
void y(const T &y);
/*! \brief setter for both x and y element
*/
void x_and_y(const T &x, const T &y);
/*! \brief swizzle for both x and y returns a copy of a point_2d
*/
point_2d xy() const;
/*! \brief swizzle for x element returns a copy of a point_2d
*/
point_2d xx() const;
/*! \brief swizzle for y element returns a copy of a point_2d
*/
point_2d yy() const;
/*! \brief swizzle for reverse of y and x returns a copy of a point_2d
*/
point_2d yx() const;
/*! \brief getter for x element returns a reference to x of type T
*/
T& x() const;
/*! \brief getter for y element returns a reference to y of type T
*/
T& y() const;
};
template <typename T>
void swap(point_2d<T> &lhs, point_2d<T> &rhs);
template <typename T>
bool operator<(const point_2d<T> &lhs, const point_2d<T> &rhs);
template <typename T>
bool operator>(const point_2d<T> &lhs, const point_2d<T> &lhs);
template <typename T>
bool operator==(const point_2d<T> &lhs, const point_2d<T> &rhs);
template <typename T>
bool operator!=(const point_2d<T> &lhs, const point_2d<T> &rhs);
}
#include "type_point_2d_2d.inl"
#endif
Run Code Online (Sandbox Code Playgroud)
这实际上与OpenGL或缓冲对象无关.你问的是用私有成员复制结构的二进制数据的结果是什么.也就是说,你得到了什么memcpy.
如果对象是POD(普通旧数据)类型,则 C++ 98/03仅允许这种内存布局合法.具有私有成员的类不是POD.
C++ 11放松了这些规则.为了memcpy工作(这是glBufferSubData最终的工作),您需要类型可以轻松复制.所以没有虚拟功能或非平凡成员.为了确保数据的实际布局(offsetof例如,实际上将工作),类型必须是标准布局.
特别适合您,这意味着如果您有私有成员,那么所有(非静态)成员变量必须是私有的.如果某些成员是公开的而其他成员是私人的,则会丢失标准布局