Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用C++;使用OpenGL将结构加载到成员为私有的VBO中_C++_Opengl - Fatal编程技术网

C++ 使用C++;使用OpenGL将结构加载到成员为私有的VBO中

C++ 使用C++;使用OpenGL将结构加载到成员为私有的VBO中,c++,opengl,C++,Opengl,能否将结构加载到成员变量为私有的vbo中 更新 由于我不确定如何提问具体的问题,所以这个问题没有样本,只是一般性的。下面的答案正是我想要的。但对于那些没有看到引发问题的代码的人来说: #ifndef POINT2D_H_INCLUDED #define POINT2D_H_INCLUDED #include <glext.h> namespace glext { /*! \class Point 2D class geometry based * \brief Th

能否将结构加载到成员变量为私有的vbo中

更新

由于我不确定如何提问具体的问题,所以这个问题没有样本,只是一般性的。下面的答案正是我想要的。但对于那些没有看到引发问题的代码的人来说:

#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
#如果包含NDEF点2D
#定义包含的点2D_H_
#包括
名称空间glext
{
/*!\class Point基于二维类几何体
*\brief此类定义了一个2D点\u 2D
*
*关于测试类的一些细节
*/
模板
类点2d
{
私人:
///有序对中的第一个元素
T_x;
///有序对中的第二个元素
T_y,;
公众:
/*!\brief默认构造函数将有序对中的两个元素都设置为0
*/  
点_2d();
/*!\brief构造函数将两个元素都设置为提供的参数
*/  
点2d(常数T&x、常数T&y);
/*!\brief copy构造函数将有序对中的两个元素都设置为0
*/  
点_2d(常数点_2d和rhs);
/*!\brief析构函数
*/
~point_2d();
/*!\short赋值使用复制交换习惯用法
*/ 
点2d和运算符=(点2d rhs);
/*!\x元素的简短设置器
*/ 
无效x(常数T&x);
/*!\y元素的简短设置器
*/
无效y(常数T&y);
/*!\x和y元素的简短设置器
*/
无效x_和y(常数T&x,常数T&y);
/*!\x和y的快速旋转将返回点的副本
*/
点_2d xy()常数;
/*!\x元素的简短swizzle返回点的副本。\u 2d
*/
点_2d xx()常数;
/*!\y元素的简短swizzle返回点的副本。\u 2d
*/
点_2d yy()常数;
/*!\y和x反转的快速旋转返回点的副本
*/
点_2d yx()常数;
/*!\x元素的简短getter返回对类型为T的x的引用
*/
T&x()常数;
/*!\y元素的简短getter返回对T类型y的引用
*/
T&y()常数;
};
模板
无效交换(点_2d和左侧、点_2d和右侧);
模板
布尔运算符(常数点2d和lhs,常数点2d和lhs);
模板
布尔运算符==(常数点2d&lhs,常数点2d&rhs);
模板
布尔运算符!=(常数点2d&lhs,常数点2d&rhs);
}
#包括“类型\点\二维\二维.inl”
#恩迪夫

这实际上与OpenGL或缓冲区对象无关。您要问的是复制具有私有成员的结构的二进制数据的结果是什么。也就是说,您可以通过
memcpy
获得什么

C++98/03仅在以下情况下允许这种内存布局合法。具有私有成员的类不是pod

要使
memcpy
起作用(这就是
glBufferSubData
最终的作用),您需要指定类型。因此,没有虚拟函数或非平凡成员。为了确保数据的实际布局(例如,这样才能实际工作),类型必须为


特别是对您来说,这意味着如果您有私有成员,那么所有(非静态)成员变量都必须是私有的。如果某些成员是公共的,而另一些成员是私有的,则会丢失标准布局。

这实际上与OpenGL或缓冲区对象无关。您要问的是复制具有私有成员的结构的二进制数据的结果是什么。也就是说,您可以通过
memcpy
获得什么

C++98/03仅在以下情况下允许这种内存布局合法。具有私有成员的类不是pod

要使
memcpy
起作用(这就是
glBufferSubData
最终的作用),您需要指定类型。因此,没有虚拟函数或非平凡成员。为了确保数据的实际布局(例如,这样才能实际工作),类型必须为


特别是对您来说,这意味着如果您有私有成员,那么所有(非静态)成员变量都必须是私有的。如果某些成员是公共的,而其他成员是私有的,则会丢失标准布局。

该结构是否具有用于检索数据的成员函数,或者是普通的旧数据?很高兴看到数据结构是如何声明的。该结构是否具有用于检索数据的成员函数,或者是普通的旧数据?很高兴看到数据结构是如何声明的。